/* Frostpeak Panel — components (ui.js) + shell pages (login, account, 404) */

/* ---------- Icon ---------- */
.icon { display: inline-block; vertical-align: middle; flex-shrink: 0; }

/* ---------- Buttons ---------- */
.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: 40px;
  padding: 0 var(--space-4);
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  font-size: var(--text-sm);
  line-height: var(--leading-sm);
  font-weight: 600;
  white-space: nowrap;
  text-decoration: none;
  user-select: none;
  transition: background-color var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
}
.btn:hover { text-decoration: none; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; }
.btn-sm { height: 32px; padding: 0 var(--space-3); border-radius: var(--radius-sm); }
.btn-icon { width: 40px; padding: 0; }
.btn-icon.btn-sm { width: 32px; }

.btn-primary { background: var(--primary-button); color: var(--primary-foreground); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); color: var(--primary-foreground); }

.btn-secondary { background: var(--secondary); color: var(--foreground); }
.btn-secondary:hover:not(:disabled) { background: var(--secondary-hover); color: var(--foreground); }

.btn-outline { background: transparent; border-color: var(--input); color: var(--foreground); }
.btn-outline:hover:not(:disabled) { border-color: var(--input-hover); background: var(--nav-hover-bg); color: var(--foreground); }

.btn-danger { background: var(--danger); color: #ffffff; }
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); color: #ffffff; }

.btn-ghost { background: transparent; color: var(--nav-foreground); }
.btn-ghost:hover:not(:disabled) { background: var(--nav-hover-bg); color: var(--foreground); }

.btn-link {
  height: auto;
  min-height: 24px;
  padding: 0 2px;
  background: transparent;
  color: var(--link);
}
.btn-link:hover:not(:disabled) { color: var(--link-hover); text-decoration: underline; }

.btn.is-busy { color: transparent !important; }
.btn.is-busy > :not(.btn-spinner) { visibility: hidden; }
.btn-spinner {
  position: absolute;
  inset: 0;
  margin: auto;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #ffffff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
/* Light-coloured buttons (and every button of the light theme but primary/danger) need a dark spinner. */
.btn-secondary .btn-spinner,
.btn-outline .btn-spinner,
.btn-ghost .btn-spinner,
.btn-link .btn-spinner {
  border-color: color-mix(in srgb, var(--foreground) 30%, transparent);
  border-top-color: var(--foreground);
}

.btn-group { display: flex; flex-wrap: wrap; gap: var(--space-2); }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 1.625rem;
  padding: 0 8px;
  border: 1px solid var(--neutral-badge-border);
  border-radius: var(--radius-pill);
  background: var(--neutral-badge-bg);
  color: var(--neutral-badge-fg);
  font-size: var(--text-sm);
  line-height: var(--leading-sm);
  font-weight: 600;
  white-space: nowrap;
  vertical-align: middle;
}
.stack > .badge, .stack-sm > .badge, .stack-lg > .badge { align-self: flex-start; }
.badge-dot::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}
.badge-success { background: var(--success-bg); border-color: var(--success-border); color: var(--success-strong); }
.badge-success.badge-dot::before { background: var(--success); }
.badge-warning { background: var(--warning-bg); border-color: var(--warning-border); color: var(--warning-strong); }
.badge-warning.badge-dot::before { background: var(--warning); }
.badge-danger { background: var(--danger-bg); border-color: var(--danger-border); color: var(--danger-pale); }
.badge-danger.badge-dot::before { background: var(--danger-light); }
.badge-info { background: var(--info-bg); border-color: var(--info-border); color: var(--info-strong); }
.badge-info.badge-dot::before { background: var(--info); }

.count-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  padding: 0 7px;
  border-radius: var(--radius-pill);
  background: var(--secondary);
  color: var(--nav-selected-foreground);
  font-size: var(--text-counter);
  line-height: var(--leading-counter);
  font-weight: 700;
  letter-spacing: 0;
}

/* ---------- Cards ---------- */
.card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--card);
}
.card-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 56px;
  padding: var(--space-3) var(--space-4) 0;
}
.card-title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  font-size: var(--text-lg);
  line-height: var(--leading-lg);
  font-weight: 600;
  letter-spacing: var(--tracking-tight);
}
.card-action {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 4px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--link);
  font-size: var(--text-sm);
  line-height: var(--leading-sm);
  font-weight: 600;
  white-space: nowrap;
}
.card-action:hover { color: var(--link-hover); text-decoration: underline; }
.card-body { padding: var(--space-4); min-width: 0; flex: 1 1 auto; }
.card-footer {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border);
}
.card-flush > .card-body { padding: 0; }

/* Rows inside cards (icon square + title + subtitle + trailing) */
.list { list-style: none; margin: 0; padding: 0; }
.list-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 56px;
  padding: var(--space-2) 0;
}
.list-row + .list-row { border-top: 1px solid var(--border); }
.list-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-control);
  background: var(--muted);
  color: var(--nav-selected-foreground);
  flex-shrink: 0;
}
.list-main { flex: 1 1 auto; min-width: 0; }
.list-title { font-size: var(--text-sm); line-height: var(--leading-sm); color: var(--foreground); font-weight: 600; }
.list-sub { font-size: var(--text-sm); line-height: var(--leading-sm); color: var(--muted-foreground); }

/* ---------- Page header ---------- */
.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
}
.page-header-text { min-width: 0; display: flex; flex-direction: column; gap: var(--space-1); }
.page-title { font-size: var(--text-3xl); line-height: 2.5rem; font-weight: 600; letter-spacing: var(--tracking-tight); }
.page-title:focus { outline: none; }
.page-subtitle { color: var(--muted-foreground); font-size: var(--text-md); line-height: var(--leading-md); }
.page-actions { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }

@media (max-width: 899.98px) {
  .page-title { font-size: var(--text-2xl); line-height: 2.25rem; }
}

/* ---------- Stat tile ---------- */
.stat-tile {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  min-width: 0;
  padding: var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--card);
}
.stat-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-control);
  background: var(--muted);
  color: var(--nav-selected-foreground);
  flex-shrink: 0;
}
.stat-body { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.stat-label { color: var(--muted-foreground); font-size: var(--text-sm); line-height: var(--leading-sm); font-weight: 600; }
.stat-value { font-size: var(--text-xl); line-height: 2rem; font-weight: 600; letter-spacing: var(--tracking-tight); font-variant-numeric: tabular-nums; }
.stat-sub { color: var(--muted-foreground); font-size: var(--text-sm); line-height: var(--leading-sm); }
.tone-success .stat-value { color: var(--success-strong); }
.tone-success .stat-icon { background: var(--success-bg); color: var(--success); }
.tone-warning .stat-value { color: var(--warning-strong); }
.tone-warning .stat-icon { background: var(--warning-bg); color: var(--warning); }
.tone-danger .stat-value { color: var(--danger-pale); }
.tone-danger .stat-icon { background: var(--danger-bg); color: var(--danger-light); }
.tone-info .stat-value { color: var(--info-strong); }
.tone-info .stat-icon { background: var(--info-bg); color: var(--info); }

/* ---------- Progress bar ---------- */
.progress { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.progress-head { display: flex; justify-content: space-between; gap: var(--space-2); font-size: var(--text-sm); line-height: var(--leading-sm); color: var(--muted-foreground); }
.progress-track {
  position: relative;
  height: 8px;
  border-radius: var(--radius-pill);
  background: var(--muted);
  overflow: hidden;
}
.progress-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  border-radius: inherit;
  background: var(--info);
  transition: width 300ms ease;
}
.progress-success .progress-fill { background: var(--success); }
.progress-warning .progress-fill { background: var(--warning); }
.progress-danger .progress-fill { background: var(--danger-light); }
.progress-neutral .progress-fill { background: var(--input-hover); }

/* ---------- Table ---------- */
.table-wrap {
  position: relative; /* keeps .sr-only cells inside the scroll container */
  width: 100%;
  overflow-x: auto;
  border-radius: var(--radius-control);
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
  line-height: var(--leading-sm);
}
.table th {
  padding: 10px var(--space-4);
  border-bottom: 1px solid var(--border);
  color: var(--muted-foreground);
  font-size: var(--text-sm);
  line-height: var(--leading-sm);
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
}
.table td {
  padding: 10px var(--space-4);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: color-mix(in srgb, var(--muted) 55%, transparent); }
.table .align-right { text-align: right; }
.table .align-center { text-align: center; }
.table-empty td {
  padding: var(--space-8) var(--space-4);
  color: var(--muted-foreground);
  text-align: center;
}
.table-empty:hover td { background: transparent !important; }

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: var(--space-1);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  height: 40px;
  padding: 0 var(--space-3);
  border: 0;
  background: transparent;
  color: var(--nav-foreground);
  font-size: var(--text-sm);
  font-weight: 500;
  white-space: nowrap;
  border-radius: var(--radius-control) var(--radius-control) 0 0;
}
.tab:hover { color: var(--nav-hover-foreground); background: var(--nav-hover-bg); }
.tab[aria-selected="true"] { color: var(--foreground); font-weight: 600; }
.tab[aria-selected="true"]::after {
  content: "";
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: -1px;
  height: 2px;
  border-radius: 2px;
  background: var(--primary);
}
.tab .count-pill { height: 20px; min-width: 20px; padding: 0 6px; }
/* Phones: wrap the tabs instead of hiding the last ones behind an invisible horizontal scroll. */
@media (max-width: 599px) {
  .tabs { flex-wrap: wrap; overflow-x: visible; }
}

/* ---------- Form controls ---------- */
.input,
.select,
.textarea {
  width: 100%;
  height: 40px;
  padding: 0 var(--space-3);
  border: 1px solid var(--input);
  border-radius: var(--radius-control);
  background: var(--input-background);
  color: var(--foreground);
  font-size: var(--text-sm);
  line-height: var(--leading-sm);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.textarea { height: auto; min-height: 96px; padding: var(--space-2) var(--space-3); resize: vertical; }
.input::placeholder, .textarea::placeholder { color: var(--muted-foreground); opacity: 1; }
.input:hover:not(:disabled), .select:hover:not(:disabled), .textarea:hover:not(:disabled) { border-color: var(--input-hover); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--ring); box-shadow: 0 0 0 1px var(--ring); }
.input:disabled, .select:disabled, .textarea:disabled, .input[readonly] { opacity: 0.65; cursor: not-allowed; }
.input[readonly] { cursor: default; }
.input[aria-invalid="true"], .select[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--danger-light); }
.input-mono { font-family: var(--font-mono); letter-spacing: 0.02em; }

.select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 36px;
  cursor: pointer;
  background-image: var(--select-chevron);
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px 16px;
}
.select option { background: var(--popover); color: var(--foreground); }
.select-sm, .input-sm { height: 32px; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label { font-size: var(--text-sm); line-height: var(--leading-sm); font-weight: 600; color: var(--nav-selected-foreground); }
.field-required { color: var(--danger-light); margin-left: 2px; }
.field-help { font-size: var(--text-sm); line-height: var(--leading-sm); color: var(--muted-foreground); }
.field-error {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--text-sm);
  line-height: var(--leading-sm);
  color: var(--danger-light);
  font-weight: 600;
}
.form { display: flex; flex-direction: column; gap: var(--space-4); }
.form-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; align-items: center; }

/* Toggle switch */
.toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 32px;
  cursor: pointer;
  font-size: var(--text-sm);
  line-height: var(--leading-sm);
  color: var(--foreground);
}
.toggle-input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  margin: 0;
}
.toggle-track {
  position: relative;
  width: 40px;
  height: 22px;
  border: 1px solid var(--input);
  border-radius: var(--radius-pill);
  background: var(--input-background);
  flex-shrink: 0;
  transition: background-color var(--transition-fast), border-color var(--transition-fast);
}
.toggle-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--muted-foreground);
  transition: transform var(--transition-fast), background-color var(--transition-fast);
}
.toggle-input:checked + .toggle-track { background: var(--primary-button); border-color: var(--primary-button); }
.toggle-input:checked + .toggle-track::after { transform: translateX(18px); background: #ffffff; }
.toggle-input:focus-visible + .toggle-track { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.toggle.is-disabled { opacity: 0.55; cursor: not-allowed; }

/* ---------- Callouts ---------- */
.callout {
  display: flex;
  gap: var(--space-3);
  align-items: flex-start;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--info-border);
  border-radius: var(--radius-control);
  background: var(--info-bg);
  color: var(--foreground);
  font-size: var(--text-sm);
  line-height: var(--leading-sm);
}
.callout > .icon { margin-top: 2px; color: var(--info); }
.callout-title { font-weight: 600; }
.callout-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.callout-success { border-color: var(--success-border); background: var(--success-bg); }
.callout-success > .icon { color: var(--success); }
.callout-warning { border-color: var(--warning-border); background: var(--warning-bg); }
.callout-warning > .icon { color: var(--warning); }
.callout-danger { border-color: var(--danger-border); background: var(--danger-bg); }
.callout-danger > .icon { color: var(--danger-light); }

/* ---------- Empty state ---------- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--space-2);
  padding: var(--space-8) var(--space-4);
}
.empty-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  margin-bottom: var(--space-2);
  border-radius: var(--radius-card);
  background: var(--muted);
  color: var(--nav-selected-foreground);
}
.empty-title { font-size: var(--text-md); font-weight: 600; }
.empty-message { max-width: 420px; color: var(--muted-foreground); font-size: var(--text-sm); line-height: var(--leading-sm); }
.empty-state .btn { margin-top: var(--space-2); }

/* ---------- Spinner & skeleton ---------- */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--secondary);
  border-top-color: var(--info);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
}
.spinner-sm { width: 14px; height: 14px; }
.spinner-lg { width: 32px; height: 32px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton { display: flex; flex-direction: column; gap: 10px; }
.skeleton-line {
  height: 14px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--muted) 0%, var(--skeleton-highlight) 50%, var(--muted) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}
.skeleton-line:nth-child(3n + 1) { width: 92%; }
.skeleton-line:nth-child(3n + 2) { width: 76%; }
.skeleton-line:nth-child(3n) { width: 58%; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }

/* ---------- Modal (native <dialog>) ---------- */
html.has-modal { overflow: hidden; }
.modal {
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: var(--card);
  color: var(--foreground);
  box-shadow: var(--shadow-modal);
  overflow: hidden;
}
.modal[open] { display: flex; flex-direction: column; }
.modal-sm { width: min(400px, calc(100vw - 32px)); }
.modal-lg { width: min(760px, calc(100vw - 32px)); }
.modal::backdrop { background: var(--backdrop); }
.modal-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-4) var(--space-2) var(--space-5);
}
.modal-title { flex: 1 1 auto; font-size: var(--text-lg); line-height: var(--leading-lg); font-weight: 600; letter-spacing: var(--tracking-tight); }
.modal-body {
  padding: var(--space-2) var(--space-5) var(--space-4);
  overflow-y: auto;
  font-size: var(--text-sm);
  line-height: var(--leading-sm);
  color: var(--nav-selected-foreground);
}
.modal-body > * + * { margin-top: var(--space-3); }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  flex-wrap: wrap;
  padding: var(--space-3) var(--space-5) var(--space-4);
  border-top: 1px solid var(--border);
}
@media (max-width: 480px) {
  .modal-footer .btn { flex: 1 1 auto; }
}

/* ---------- Toasts ---------- */
.toast-region {
  position: fixed;
  right: var(--space-4);
  bottom: var(--space-4);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  width: min(380px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-2) var(--space-3) var(--space-4);
  border: 1px solid var(--info-border);
  border-radius: var(--radius-control);
  background: var(--popover);
  box-shadow: var(--shadow-popover);
  color: var(--foreground);
  font-size: var(--text-sm);
  line-height: var(--leading-sm);
  pointer-events: auto;
  animation: toast-in 160ms ease-out;
}
.toast > .icon { margin-top: 2px; color: var(--info); }
.toast-message { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.toast-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  margin: -4px 0;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted-foreground);
}
.toast-close:hover { background: var(--muted); color: var(--foreground); }
.toast-success { border-color: var(--success-border); }
.toast-success > .icon { color: var(--success); }
.toast-warning { border-color: var(--warning-border); }
.toast-warning > .icon { color: var(--warning); }
.toast-danger { border-color: var(--danger-border); }
.toast-danger > .icon { color: var(--danger-light); }
.toast.is-leaving { opacity: 0; transform: translateY(6px); transition: opacity 150ms ease, transform 150ms ease; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

@media (max-width: 480px) {
  .toast-region { left: var(--space-4); right: var(--space-4); width: auto; }
}

/* ---------- Avatar (initials) ---------- */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--secondary);
  color: #ffffff;
  font-size: 0.8125rem; /* avatar initials (decorative, aria-hidden) */
  font-weight: 700;
  letter-spacing: 0;
  flex-shrink: 0;
  user-select: none;
  transition: box-shadow var(--transition-fast);
}
.avatar-sm { width: 24px; height: 24px; font-size: 0.625rem; }
.avatar-lg { width: 44px; height: 44px; font-size: 1rem; }
.avatar-square { border-radius: var(--radius-sm); }
/* Eight hues, all dark enough for white text (>= 4.5:1). */
.avatar-c0 { background: #1f5fbf; }
.avatar-c1 { background: #0e7a5a; }
.avatar-c2 { background: #8a3fbf; }
.avatar-c3 { background: #b03a5b; }
.avatar-c4 { background: #9a5b00; }
.avatar-c5 { background: #2c6e8f; }
.avatar-c6 { background: #5b5fc7; }
.avatar-c7 { background: #4f6b2a; }

/* ---------- Key/value list ---------- */
.kv { display: grid; grid-template-columns: minmax(120px, max-content) 1fr; gap: var(--space-2) var(--space-6); margin: 0; font-size: var(--text-sm); line-height: var(--leading-sm); }
.kv dt { color: var(--muted-foreground); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 480px) {
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dd { margin-bottom: var(--space-2); }
}

/* ---------- Error state (router) ---------- */
.route-error { max-width: 640px; margin: var(--space-8) auto; }

/* =========================================================
   Shell pages
   ========================================================= */

/* Login */
.auth-page {
  position: relative;
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - var(--banner-height));
  padding: var(--space-8) var(--space-4);
  overflow: hidden;
  background:
    radial-gradient(ellipse 80% 60% at 50% -10%, var(--auth-glow), transparent 70%),
    radial-gradient(ellipse 60% 40% at 90% 110%, rgba(75, 178, 246, 0.10), transparent 70%),
    var(--background);
}
.auth-page::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(var(--auth-grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--auth-grid) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse 70% 60% at 50% 40%, #000 30%, transparent 75%);
  -webkit-mask-image: radial-gradient(ellipse 70% 60% at 50% 40%, #000 30%, transparent 75%);
  pointer-events: none;
}
.auth-card {
  position: relative;
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
  padding: var(--space-8);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  background: color-mix(in srgb, var(--card) 92%, transparent);
  box-shadow: var(--shadow-card);
}
.auth-brand { display: flex; align-items: center; gap: var(--space-3); }
.auth-brand .brand-logo { width: 40px; height: 40px; }
.auth-brand .brand-name { font-size: var(--text-xl); }
.auth-heading { display: flex; flex-direction: column; gap: var(--space-1); }
.auth-heading h1 { font-size: var(--text-2xl); line-height: 2.25rem; }
.auth-heading p { color: var(--muted-foreground); font-size: var(--text-sm); line-height: var(--leading-sm); }
.auth-card .btn-primary { width: 100%; }
.auth-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  color: var(--muted-foreground);
  font-size: var(--text-sm);
  line-height: var(--leading-sm);
  text-align: center;
}
.otp-input { font-family: var(--font-mono); font-size: var(--text-xl); letter-spacing: 0.4em; text-align: center; height: 3rem; }

.password-wrap { position: relative; }
.password-wrap .input { padding-right: 44px; }
.password-reveal {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted-foreground);
}
.password-reveal:hover { color: var(--foreground); background: var(--muted); }

@media (max-width: 480px) {
  .auth-card { padding: var(--space-6) var(--space-5); }
}

/* Account */
.account-grid {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: start;
}
.account-grid > .span-2 { grid-column: 1 / -1; }
@media (max-width: 1000px) {
  .account-grid { grid-template-columns: minmax(0, 1fr); }
}
.account-identity { display: flex; align-items: center; gap: var(--space-4); margin-bottom: var(--space-4); }
.account-identity-name { font-size: var(--text-lg); font-weight: 600; line-height: var(--leading-lg); }
.account-forced { max-width: 560px; width: 100%; margin: 0 auto; }

.totp-setup { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: var(--space-6); align-items: start; }
@media (max-width: 640px) {
  .totp-setup { grid-template-columns: minmax(0, 1fr); justify-items: start; }
}
.qr-box {
  width: fit-content;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  background: #ffffff;
  line-height: 0;
}
.qr-svg { width: 184px; height: 184px; }
.qr-svg path, .qr-svg rect { shape-rendering: crispEdges; }
.secret-row { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.secret-value {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--input-background);
  overflow-wrap: anywhere;
  user-select: all;
}
.steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: var(--space-1); font-size: var(--text-sm); line-height: var(--leading-sm); color: var(--nav-selected-foreground); }

/* Not found */
.not-found {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--space-4);
  padding: var(--space-10) var(--space-4);
}
.not-found-bare { min-height: calc(100vh - var(--banner-height)); justify-content: center; }
.not-found-code {
  font-family: var(--font-mono);
  font-size: 72px;
  line-height: 1;
  font-weight: 600;
  background: var(--gradient-name);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.not-found p { color: var(--muted-foreground); max-width: 440px; }
.not-found-path { font-family: var(--font-mono); color: var(--nav-selected-foreground); overflow-wrap: anywhere; }

/* Touch screens: link-style buttons get a 40 px tall target too. */
@media (pointer: coarse) {
  .btn-link { min-height: 40px; }
}

/* ---------- Disabled button + reason ---------- */
.btn-with-reason { display: inline-flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; }
.btn-reason { color: var(--muted-foreground); font-size: var(--text-sm); line-height: var(--leading-sm); }

/* ---------- Help tip (« ? » bubble) ---------- */
.help-tip { display: inline-flex; vertical-align: middle; }
.help-tip-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  margin: -8px -6px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--link);
  font-size: var(--text-sm);
  font-weight: 700;
  line-height: 1;
  flex-shrink: 0;
}
/* The visible disc is 22 px; the button keeps a 40 × 40 touch target. */
.help-tip-btn::before {
  content: "";
  position: absolute;
  width: 1.375rem;
  height: 1.375rem;
  border: 1.5px solid currentColor;
  border-radius: 50%;
}
.help-tip-btn:hover,
.help-tip-btn[aria-expanded="true"] { color: var(--link-hover); }
.help-tip-btn[aria-expanded="true"]::before { background: color-mix(in srgb, var(--link) 16%, transparent); }
.help-tip-bubble {
  position: fixed;
  z-index: var(--z-toast);
  width: max-content;
  max-width: min(280px, calc(100vw - 16px));
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  background: var(--popover);
  box-shadow: var(--shadow-popover);
  color: var(--foreground);
  font-size: var(--text-sm);
  line-height: var(--leading-sm);
  font-weight: 400;
  text-align: left;
  text-transform: none;
  letter-spacing: normal;
  white-space: normal;
  overflow-wrap: anywhere;
}
.label-with-help { display: inline-flex; align-items: center; gap: var(--space-2); }

/* ---------- Page help dialog ---------- */
.help-dialog-terms { display: flex; flex-direction: column; gap: var(--space-2); margin: 0; }
.help-dialog-terms dt { font-weight: 600; color: var(--foreground); }
.help-dialog-terms dd { margin: 0 0 var(--space-1); color: var(--nav-selected-foreground); }
.help-dialog-subtitle { font-size: var(--text-md); line-height: var(--leading-md); }
.help-dialog-contact {
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-control);
  background: var(--muted);
  overflow-wrap: anywhere;
}

/* ---------- Login: forgotten password ---------- */
.forgot { display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-2); margin-top: calc(-1 * var(--space-2)); }
.forgot-command {
  display: block;
  margin-top: var(--space-1);
  padding: var(--space-2);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  user-select: all;
}

/* ---------- Password strength ---------- */
.pw-strength { display: flex; flex-direction: column; gap: var(--space-1); }
.pw-strength-text { display: flex; gap: var(--space-2); flex-wrap: wrap; font-size: var(--text-sm); line-height: var(--leading-sm); color: var(--muted-foreground); }
.pw-strength-level { font-weight: 600; color: var(--foreground); }

/* ---------- Two-factor guide ---------- */
.totp-intro { font-size: var(--text-md); line-height: var(--leading-md); color: var(--foreground); }
.totp-guide { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-4); counter-reset: totp-step; }
.totp-step { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: var(--space-3); align-items: start; }
.totp-step-mark {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-control);
  background: var(--info-bg);
  border: 1px solid var(--info-border);
  color: var(--info);
}
.totp-step-num {
  position: absolute;
  top: -8px;
  left: -8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.25rem;
  height: 1.25rem;
  padding: 0 4px;
  border-radius: var(--radius-pill);
  background: var(--primary-button);
  color: var(--primary-foreground);
  font-size: var(--text-counter);
  line-height: 1;
  font-weight: 700;
}
.totp-step-body { display: flex; flex-direction: column; gap: var(--space-2); min-width: 0; font-size: var(--text-sm); line-height: var(--leading-sm); color: var(--nav-selected-foreground); }
.totp-step-title { font-size: var(--text-md); line-height: var(--leading-md); font-weight: 600; color: var(--foreground); }
.totp-status { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.totp-manual summary { cursor: pointer; width: fit-content; color: var(--link); font-weight: 600; min-height: 24px; }
.totp-manual summary:hover { color: var(--link-hover); }
.totp-manual[open] summary { margin-bottom: var(--space-2); }

/* ---------- Display preferences (theme, text size) ---------- */
.choice-group { margin: 0; padding: 0; border: 0; min-width: 0; display: flex; flex-direction: column; gap: var(--space-2); }
.choice-group legend { padding: 0; margin-bottom: var(--space-2); font-size: var(--text-sm); line-height: var(--leading-sm); font-weight: 600; color: var(--nav-selected-foreground); }
.choice-options { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.choice {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 40px;
  padding: 0 var(--space-4);
  border: 1px solid var(--input);
  border-radius: var(--radius-control);
  background: var(--input-background);
  color: var(--foreground);
  font-size: var(--text-sm);
  line-height: var(--leading-sm);
  font-weight: 500;
  cursor: pointer;
}
.choice:hover { border-color: var(--input-hover); }
.choice input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; }
.choice:has(input:checked) { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 14%, var(--input-background)); font-weight: 600; }
.choice:has(input:focus-visible) { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.choice-check { display: none; color: var(--link); }
.choice:has(input:checked) .choice-check { display: inline-flex; }

/* Menu radio items (user menu: display settings) */
.menu-group-label { padding: var(--space-2) 10px var(--space-1); color: var(--muted-foreground); font-size: var(--text-sm); line-height: var(--leading-sm); font-weight: 600; }
.menu-radio-row { display: flex; gap: var(--space-1); padding: 0 6px var(--space-1); flex-wrap: wrap; }
.menu-radio {
  flex: 1 1 auto;
  min-height: 36px;
  padding: 0 var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--nav-foreground);
  font-size: var(--text-sm);
  font-weight: 500;
}
.menu-radio:hover, .menu-radio:focus-visible { background: var(--nav-hover-bg); color: var(--nav-hover-foreground); }
.menu-radio[aria-checked="true"] { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 14%, transparent); color: var(--foreground); font-weight: 600; }
@media (pointer: coarse) {
  .menu-radio { min-height: 40px; }
}

/* ---------- Account: connected devices ---------- */
/* Cards up to 1180 px: with the sidebar, narrower screens leave the 5 columns too little room. */
.device-cell { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
.device-name { display: flex; flex-direction: column; gap: var(--space-1); min-width: 0; }
@media (max-width: 1180px) {
  .devices-table table,
  .devices-table tbody,
  .devices-table tr,
  .devices-table td { display: block; width: 100%; }
  .devices-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
  .devices-table tr { padding: var(--space-3) 0; border-bottom: 1px solid var(--border); }
  .devices-table tbody tr:last-child { border-bottom: 0; }
  .devices-table td { padding: var(--space-1) 0; border-bottom: 0; text-align: left; }
  .devices-table td[data-label]:not([data-label=""])::before {
    content: attr(data-label);
    display: block;
    color: var(--muted-foreground);
    font-size: var(--text-sm);
    font-weight: 600;
  }
  .devices-table .align-right { text-align: left; }
  .devices-table tbody tr:hover td { background: transparent; }
}
.device-mobile-label { display: none; }
@media (max-width: 1180px) {
  .devices-table thead .help-tip { display: none; }
  .devices-table .device-mobile-label { display: inline-flex; color: var(--muted-foreground); font-size: var(--text-sm); font-weight: 600; }
}
.account-grid .stack > :empty { display: none; }
