/* ------------------------------ Buttons ------------------------------ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 36px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  user-select: none;
  transition: background var(--fast), border-color var(--fast), color var(--fast),
    box-shadow var(--fast), transform var(--fast);
}

.btn:active:not(:disabled) {
  transform: translateY(0.5px) scale(0.995);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn svg {
  width: 16px;
  height: 16px;
  flex: none;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-contrast);
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  box-shadow: var(--shadow-sm);
}

.btn-secondary {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: var(--text-muted);
}

.btn-ghost {
  color: var(--text-secondary);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-2);
  color: var(--text);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover:not(:disabled) {
  filter: brightness(0.92);
}

.btn-danger-ghost {
  color: var(--danger);
}

.btn-danger-ghost:hover:not(:disabled) {
  background: var(--danger-soft);
}

.btn-icon {
  width: 36px;
  padding: 0;
}

.btn-icon.btn-sm {
  width: 30px;
}

.btn-sm {
  height: 30px;
  padding: 0 10px;
  font-size: 12.5px;
  border-radius: var(--radius-sm);
}

.btn-sm svg {
  width: 14px;
  height: 14px;
}

.btn-lg {
  height: 42px;
  padding: 0 18px;
  font-size: 14.5px;
}

.btn-block {
  width: 100%;
}

.btn[aria-pressed="true"],
.btn.is-active {
  background: var(--accent-soft);
  color: var(--accent);
}

/* ------------------------------ Inputs ------------------------------ */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
}

.hint {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.55;
}

.error-text {
  font-size: 12px;
  color: var(--danger);
  min-height: 0;
}

.input,
.textarea,
.select {
  width: 100%;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 13.5px;
  transition: border-color var(--fast), box-shadow var(--fast), background var(--fast);
}

.textarea {
  height: auto;
  min-height: 96px;
  padding: 10px 12px;
  resize: vertical;
  line-height: 1.6;
}

.select {
  appearance: none;
  padding-right: 34px;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
    linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) 16px, calc(100% - 11px) 16px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  cursor: pointer;
}

.input::placeholder,
.textarea::placeholder {
  color: var(--text-muted);
}

.input:focus,
.textarea:focus,
.select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.input:disabled,
.textarea:disabled,
.select:disabled {
  background: var(--surface-2);
  color: var(--text-muted);
  cursor: not-allowed;
}

.input-group {
  position: relative;
  display: flex;
  align-items: center;
}

.input-group > svg {
  position: absolute;
  left: 12px;
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  pointer-events: none;
}

.input-group > .input {
  padding-left: 36px;
}

.input-group .input-action {
  position: absolute;
  right: 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
}

.input-group .input-action:hover {
  background: var(--surface-2);
  color: var(--text);
}

.input-group .input-action svg {
  width: 16px;
  height: 16px;
}

.input-group > .input.has-action {
  padding-right: 40px;
}

/* ------------------------------ Switch ------------------------------ */

.switch {
  position: relative;
  display: inline-flex;
  flex: none;
  width: 38px;
  height: 22px;
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
  z-index: 1;
}

.switch-track {
  width: 100%;
  height: 100%;
  border-radius: var(--radius-pill);
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  transition: background var(--fast), border-color var(--fast);
}

.switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  transition: transform 300ms var(--ease-spring), box-shadow var(--fast),
    background var(--fast);
}

.switch input:checked + .switch-track {
  background: var(--accent);
  border-color: var(--accent);
}

.switch input:checked + .switch-track::after {
  transform: translateX(16px);
}

.switch input:focus-visible + .switch-track {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ------------------------------ Segmented ------------------------------ */

.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.segmented button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 28px;
  padding: 0 11px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-size: 12.5px;
  font-weight: 600;
  transition: background var(--fast), color var(--fast), box-shadow var(--fast),
    transform var(--fast);
}

.segmented button:active {
  transform: scale(0.97);
}

.segmented button svg {
  width: 14px;
  height: 14px;
}

.segmented button:hover {
  color: var(--text);
}

.segmented button.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* ------------------------------ Avatar ------------------------------ */

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
  user-select: none;
  overflow: hidden;
}

.avatar-sm {
  width: 26px;
  height: 26px;
  font-size: 11px;
}

.avatar-lg {
  width: 56px;
  height: 56px;
  font-size: 20px;
}

.avatar-xl {
  width: 76px;
  height: 76px;
  font-size: 28px;
}

/* ------------------------------ Badge / kbd ------------------------------ */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 20px;
  padding: 0 7px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
}

.badge-accent {
  background: var(--accent-soft);
  color: var(--accent);
}

.badge-success {
  background: var(--success-soft);
  color: var(--success);
}

.badge-danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.badge-warning {
  background: var(--warning-soft);
  color: var(--warning);
}

.kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-secondary);
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
}

/* ------------------------------ Divider ------------------------------ */

.divider {
  height: 1px;
  background: var(--border);
  border: 0;
  margin: 0;
}

/* ------------------------------ Modal ------------------------------ */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--overlay);
  backdrop-filter: blur(0px);
  -webkit-backdrop-filter: blur(0px);
  opacity: 0;
  visibility: hidden;
  transition: opacity 240ms var(--ease-soft), visibility 240ms var(--ease-soft),
    backdrop-filter 320ms var(--ease-soft), -webkit-backdrop-filter 320ms var(--ease-soft);
}

.modal-backdrop.is-open {
  opacity: 1;
  visibility: visible;
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
}

.modal {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 460px;
  max-height: min(86vh, 780px);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  transform: translateY(20px) scale(0.955);
  opacity: 0;
  transition: transform 380ms var(--ease-spring), opacity 240ms var(--ease-soft);
  overflow: hidden;
}

.modal-backdrop.is-open .modal {
  transform: translateY(0) scale(1);
  opacity: 1;
}

.modal-lg {
  max-width: 620px;
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 22px 14px;
}

.modal-title {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.modal-subtitle {
  margin-top: 3px;
  font-size: 12.5px;
  color: var(--text-muted);
  line-height: 1.5;
}

.modal-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 30px;
  height: 30px;
  margin: -4px -6px 0 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
}

.modal-close:hover {
  background: var(--surface-2);
  color: var(--text);
}

.modal-close svg {
  width: 17px;
  height: 17px;
}

.modal-body {
  padding: 4px 22px 22px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  background: var(--bg-elevated);
}

.modal-footer .footer-spacer {
  margin-right: auto;
}

/* ------------------------------ Menu / dropdown ------------------------------ */

.menu {
  position: absolute;
  z-index: 120;
  min-width: 210px;
  padding: 5px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  animation: menu-in 170ms var(--ease-spring);
}

@keyframes menu-in {
  from {
    opacity: 0;
    transform: translateY(-6px) scale(0.96);
  }
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  height: 34px;
  padding: 0 9px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font-size: 13px;
  text-align: left;
  white-space: nowrap;
}

.menu-item svg {
  width: 15px;
  height: 15px;
  color: var(--text-muted);
  flex: none;
}

.menu-item:hover {
  background: var(--surface-2);
}

.menu-item:hover svg {
  color: var(--text);
}

.menu-item.danger {
  color: var(--danger);
}

.menu-item.danger svg {
  color: var(--danger);
}

.menu-item.danger:hover {
  background: var(--danger-soft);
}

.menu-item .menu-shortcut {
  margin-left: auto;
  color: var(--text-muted);
  font-size: 11px;
}

.menu-sep {
  height: 1px;
  margin: 5px 6px;
  background: var(--border);
}

/* ------------------------------ Toast ------------------------------ */

.toast-stack {
  position: fixed;
  left: 50%;
  bottom: 26px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 9px;
  max-width: min(90vw, 480px);
  padding: 10px 15px 10px 12px;
  border-radius: var(--radius);
  background: var(--text);
  color: var(--bg);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  animation: toast-in 300ms var(--ease-spring);
}

.toast svg {
  width: 16px;
  height: 16px;
  flex: none;
}

.toast.success svg {
  color: var(--success);
}

.toast.error svg {
  color: #ff8a80;
}

.toast.info svg {
  color: #9ec1ff;
}

.toast.is-leaving {
  animation: toast-out 180ms var(--ease) forwards;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.94);
  }
}

@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateY(10px) scale(0.96);
  }
}

/* ------------------------------ Spinner ------------------------------ */

.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.spinner-lg {
  width: 28px;
  height: 28px;
  border-width: 2.5px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ------------------------------ Empty state ------------------------------ */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 56px 24px;
  text-align: center;
  color: var(--text-muted);
}

.empty-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  margin-bottom: 2px;
  border-radius: var(--radius-lg);
  background: var(--surface-2);
  color: var(--text-muted);
}

.empty-icon svg {
  width: 24px;
  height: 24px;
}

.empty-title {
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}

.empty-desc {
  max-width: 280px;
  font-size: 12.5px;
  line-height: 1.6;
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* ------------------------------ Skeleton ------------------------------ */

.skeleton {
  border-radius: var(--radius-sm);
  background: linear-gradient(
    90deg,
    var(--surface-2) 25%,
    var(--surface-3) 37%,
    var(--surface-2) 63%
  );
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
}

@keyframes shimmer {
  0% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0 50%;
  }
}

/* ------------------------------ Tooltip ------------------------------ */

[data-tooltip] {
  position: relative;
}

/* Hover tooltips are intentionally disabled — aria-label covers accessibility. */

/* ------------------------------ Misc ------------------------------ */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-secondary);
  transition: background var(--fast), color var(--fast), transform var(--fast);
}

.icon-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

.icon-btn:active {
  transform: scale(0.92);
}

.icon-btn svg {
  width: 17px;
  height: 17px;
}

.icon-btn.is-active {
  background: var(--accent-soft);
  color: var(--accent);
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.spread {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ------------------------------ Auth helpers ------------------------------ */

.auth-alert {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 12.5px;
  line-height: 1.5;
}

.auth-alert svg {
  width: 15px;
  height: 15px;
  margin-top: 1px;
  flex: none;
}

.auth-alert.error {
  border-color: color-mix(in srgb, var(--danger) 26%, transparent);
  background: var(--danger-soft);
  color: var(--danger);
}

.auth-alert.success {
  border-color: color-mix(in srgb, var(--success) 26%, transparent);
  background: var(--success-soft);
  color: var(--success);
}

/* Password strength meter */

.strength {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  margin-top: 6px;
}

.strength span {
  height: 4px;
  border-radius: var(--radius-pill);
  background: var(--surface-3);
  transition: background var(--fast);
}

.strength[data-level="1"] span:nth-child(-n + 1) {
  background: var(--danger);
}

.strength[data-level="2"] span:nth-child(-n + 2) {
  background: var(--warning);
}

.strength[data-level="3"] span:nth-child(-n + 3) {
  background: #e0b100;
}

.strength[data-level="4"] span {
  background: var(--success);
}

.strength-label {
  margin-top: 5px;
  font-size: 11.5px;
  color: var(--text-muted);
}

/* ------------------------------ Utility animations ------------------------------ */

.fade-in {
  animation: fade-in 240ms var(--ease);
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

.slide-up {
  animation: slide-up 260ms var(--ease);
}

@keyframes slide-up {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}