/* ==========================================================================
   MailSpace design system
   1. Tokens (light + dark)      5. Forms
   2. Base                       6. Feedback: badges, alerts, toasts, skeletons
   3. Typography helpers         7. Overlays: modals, menus, tooltips
   4. Buttons                    8. Auth pages + error page
   Page-specific styles live in home.css (landing) and app.css (app pages).
   ========================================================================== */

/* ---------- 1. Tokens ---------- */
:root,
:root[data-theme="light"] {
  color-scheme: light;

  --bg: #F7F9FF;
  --bg-2: #EEF2FF;
  --surface: #FFFFFF;
  --surface-2: #F8FAFE;        /* quiet fill inside white surfaces */
  --surface-hover: #F2F6FE;
  --elevated: #FFFFFF;         /* menus, modals, compose */

  --primary: #2459D6;          /* links, active states */
  --primary-2: #3978EE;
  --primary-btn: #2459D6;      /* filled buttons (white text on it) */
  --primary-btn-hover: #1D4CBF;
  --primary-soft: #E3ECFF;
  --primary-softer: #F0F5FF;
  --primary-ring: rgba(36, 89, 214, .28);
  --navy: #142B50;

  --text: #172B4D;
  --text-2: #64748B;
  --text-3: #8592A6;
  --border: #E3E9F2;
  --border-strong: #D2DBE9;

  --success: #16A36A;
  --success-text: #0E8155;
  --success-soft: #E2F6EC;
  --warning: #E9A23B;
  --warning-text: #9A5F07;
  --warning-soft: #FDF2DE;
  --error: #D94A55;
  --error-text: #BD3440;
  --error-soft: #FCE8EA;

  --shadow-xs: 0 1px 2px rgba(20, 43, 80, .06);
  --shadow-sm: 0 1px 2px rgba(20, 43, 80, .05), 0 2px 8px rgba(20, 43, 80, .05);
  --shadow-md: 0 2px 6px rgba(20, 43, 80, .05), 0 12px 28px -6px rgba(20, 43, 80, .12);
  --shadow-lg: 0 4px 12px rgba(20, 43, 80, .06), 0 32px 64px -16px rgba(30, 64, 150, .22);
  --backdrop: rgba(17, 33, 66, .32);

  --avatar-sat: 62%;
  --avatar-light: 92%;
  --avatar-ink: 38%;
}

:root[data-theme="dark"] {
  color-scheme: dark;

  --bg: #0B1220;
  --bg-2: #101B2D;
  --surface: #16243A;
  --surface-2: #132036;
  --surface-hover: #1A2A44;
  --elevated: #1B2C45;

  --primary: #5B91FF;
  --primary-2: #91B5FF;
  --primary-btn: #346DE0;
  --primary-btn-hover: #4079EC;
  --primary-soft: rgba(91, 145, 255, .16);
  --primary-softer: rgba(91, 145, 255, .08);
  --primary-ring: rgba(91, 145, 255, .38);
  --navy: #0A1324;

  --text: #F1F5FC;
  --text-2: #A6B5C9;
  --text-3: #7D8EA6;
  --border: #293A53;
  --border-strong: #354A68;

  --success: #35C78A;
  --success-text: #4FD69B;
  --success-soft: rgba(53, 199, 138, .14);
  --warning: #F2B65B;
  --warning-text: #F5C477;
  --warning-soft: rgba(242, 182, 91, .14);
  --error: #F17882;
  --error-text: #F58D96;
  --error-soft: rgba(241, 120, 130, .14);

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3), 0 2px 8px rgba(0, 0, 0, .2);
  --shadow-md: 0 2px 6px rgba(0, 0, 0, .3), 0 14px 30px -6px rgba(0, 0, 0, .45);
  --shadow-lg: 0 4px 14px rgba(0, 0, 0, .35), 0 36px 70px -16px rgba(0, 0, 0, .6);
  --backdrop: rgba(3, 8, 18, .6);

  --avatar-sat: 45%;
  --avatar-light: 26%;
  --avatar-ink: 80%;
}

:root {
  --font-body: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "Cascadia Code", "SF Mono", Menlo, Consolas, monospace;

  --r-xs: 6px;
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-xl: 22px;
  --r-full: 999px;

  --ease: cubic-bezier(.2, .7, .2, 1);
  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --t-fast: 160ms;
  --t-med: 220ms;
  --t-slow: 320ms;

  --control-h: 40px;
}

/* Colour transitions only while the theme is switching, so pages never animate on load */
.theme-switching,
.theme-switching *,
.theme-switching *::before,
.theme-switching *::after {
  transition: background-color 300ms ease, border-color 300ms ease, color 300ms ease,
              fill 300ms ease, stroke 300ms ease, box-shadow 300ms ease !important;
}

/* ---------- 2. Base ---------- */
*,
*::before,
*::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "cv11", "ss01";
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  color: var(--text);
  margin: 0;
  line-height: 1.2;
  letter-spacing: -0.02em;
  font-weight: 700;
  text-wrap: balance;
}

p { margin: 0; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
img, svg { display: block; }
button { font: inherit; color: inherit; }
code, kbd { font-family: var(--font-mono); font-size: .9em; }

::selection { background: var(--primary-soft); color: var(--text); }

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}

.hidden { display: none !important; }

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: 12px; top: -48px; z-index: 200;
  padding: 8px 14px; border-radius: var(--r-sm);
  background: var(--primary-btn); color: #fff; font-weight: 600;
  transition: top var(--t-fast) var(--ease);
}
.skip-link:focus { top: 12px; text-decoration: none; }

/* Icons from the sprite */
.i {
  width: 20px; height: 20px;
  flex: none;
  display: inline-block;
  vertical-align: middle;
}
.i-sm { width: 16px; height: 16px; }
.i-lg { width: 24px; height: 24px; }

/* Brand */
.brand {
  display: inline-flex; align-items: center; gap: 10px;
  color: var(--text);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.12rem;
  letter-spacing: -0.03em;
}
.brand:hover { text-decoration: none; }
.brand .logo { width: 42px; height: 35px; }
.auth-side .logo { filter: drop-shadow(0 2px 6px rgba(10, 25, 80, .45)); }
/* Logo (inline SVG) — colours that change with the theme */
.logo { width: 38px; height: 32px; flex: none; overflow: visible; }
.logo .l-env { stroke: #C3D0F4; }
.logo .lp-a { stop-color: #8FA8FF; }
.logo .lp-b { stop-color: #5B7CFF; }
.logo .l-fold { fill: #3E5FE0; }
:root[data-theme="dark"] .logo .l-env, .on-dark .logo .l-env { stroke: transparent; }
:root[data-theme="dark"] .logo .lp-a, .on-dark .logo .lp-a { stop-color: #FFFFFF; }
:root[data-theme="dark"] .logo .lp-b, .on-dark .logo .lp-b { stop-color: #DCE4FF; }
:root[data-theme="dark"] .logo .l-fold, .on-dark .logo .l-fold { fill: #9DB2FF; }
:root[data-theme="dark"] .logo, .on-dark .logo { filter: drop-shadow(0 0 6px rgba(80, 130, 255, .45)); }
.brand-space {
  background: linear-gradient(90deg, #1E9BFF 0%, #4F7BFF 55%, #8B5CF6 100%);
  -webkit-background-clip: text; background-clip: text;
  color: transparent;
}
.auth-side .brand-space { background: linear-gradient(90deg, #CFE8FF, #E6DCFF); -webkit-background-clip: text; background-clip: text; }


/* ---------- 3. Typography helpers ---------- */
.muted { color: var(--text-2); }
.subtle { color: var(--text-3); }
.small { font-size: .86rem; }
.mono { font-family: var(--font-mono); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }

/* ---------- 4. Buttons ---------- */
.btn {
  --btn-bg: var(--surface);
  --btn-fg: var(--text);
  --btn-border: var(--border-strong);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: var(--control-h);
  padding: 0 16px;
  border: 1px solid var(--btn-border);
  border-radius: var(--r-sm);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-weight: 600;
  font-size: .9rem;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  text-decoration: none;
  transition: background-color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease),
              color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease),
              transform 120ms var(--ease);
}
.btn:hover { text-decoration: none; background: var(--surface-hover); }
.btn:active:not(:disabled) { transform: scale(.975); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }

.btn-primary {
  --btn-bg: var(--primary-btn);
  --btn-fg: #fff;
  --btn-border: transparent;
  box-shadow: 0 1px 2px rgba(20, 43, 80, .12), inset 0 1px 0 rgba(255, 255, 255, .14);
}
.btn-primary:hover { background: var(--primary-btn-hover); }

.btn-soft {
  --btn-bg: var(--primary-soft);
  --btn-fg: var(--primary);
  --btn-border: transparent;
}
.btn-soft:hover { background: var(--primary-soft); filter: brightness(.97); }
:root[data-theme="dark"] .btn-soft:hover { filter: brightness(1.15); }

.btn-ghost {
  --btn-bg: transparent;
  --btn-border: transparent;
  --btn-fg: var(--text-2);
}
.btn-ghost:hover { color: var(--text); }

.btn-danger {
  --btn-bg: var(--surface);
  --btn-fg: var(--error-text);
  --btn-border: var(--border-strong);
}
.btn-danger:hover { background: var(--error-soft); border-color: transparent; }
.btn-danger-solid {
  --btn-bg: var(--error);
  --btn-fg: #fff;
  --btn-border: transparent;
}
.btn-danger-solid:hover { background: var(--error); filter: brightness(.93); }
:root[data-theme="dark"] .btn-danger-solid { --btn-bg: #C9414D; }

.btn-sm { height: 32px; padding: 0 12px; font-size: .84rem; gap: 6px; border-radius: 7px; }
.btn-lg { height: 50px; padding: 0 24px; font-size: 1rem; border-radius: var(--r-md); }
.btn-block { width: 100%; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 38px; height: 38px;
  flex: none;
  padding: 0;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  transition: background-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease), transform 120ms var(--ease);
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); }
.icon-btn:active { transform: scale(.92); }
.icon-btn:disabled { opacity: .4; cursor: not-allowed; }
.icon-btn-sm { width: 32px; height: 32px; }

.btn .spinner { width: 16px; height: 16px; border-width: 2px; }
.btn-primary .spinner { border-color: rgba(255, 255, 255, .35); border-top-color: #fff; }

/* Theme toggle (sun / moon swap) */
.theme-toggle { position: relative; overflow: hidden; }
.theme-toggle .i { position: absolute; transition: transform 400ms var(--ease-out), opacity 250ms ease; }
.theme-toggle .i-sun { transform: rotate(-90deg) scale(.5); opacity: 0; }
:root[data-theme="dark"] .theme-toggle .i-sun { transform: none; opacity: 1; }
:root[data-theme="dark"] .theme-toggle .i-moon { transform: rotate(90deg) scale(.5); opacity: 0; }

/* ---------- 5. Forms ---------- */
.field { display: grid; gap: 6px; margin-bottom: 16px; }
.field > label, .label {
  font-size: .86rem;
  font-weight: 600;
  color: var(--text);
}
.hint { font-size: .8rem; color: var(--text-2); }

.input, .select, .textarea {
  width: 100%;
  height: 44px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: .95rem;
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease), background-color var(--t-fast);
}
.textarea { height: auto; padding: 12px 14px; resize: vertical; line-height: 1.6; }
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--text-3); }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-ring);
}
.input[aria-invalid="true"] { border-color: var(--error); }
.input[aria-invalid="true"]:focus { box-shadow: 0 0 0 4px var(--error-soft); }

.select {
  appearance: none;
  padding-right: 38px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748B' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9.5 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px;
  cursor: pointer;
}

.input-group {
  display: flex; align-items: stretch;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
  overflow: hidden;
}
.input-group:focus-within { border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-ring); }
.input-group .input { border: 0; box-shadow: none !important; border-radius: 0; min-width: 0; }
.input-group .addon {
  display: flex; align-items: center;
  padding: 0 14px;
  background: var(--surface-2);
  border-left: 1px solid var(--border);
  color: var(--text-2);
  font-size: .92rem;
  white-space: nowrap;
}
.input-group .icon-btn { align-self: center; margin-right: 4px; }

/* Segmented choice (account type, theme) */
.choice-grid { display: grid; gap: 10px; }
.choice {
  position: relative;
  display: flex; align-items: flex-start; gap: 12px;
  padding: 14px 16px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  background: var(--surface);
  cursor: pointer;
  transition: border-color var(--t-fast), background-color var(--t-fast), box-shadow var(--t-fast);
}
.choice:hover { border-color: var(--text-3); }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice .choice-dot {
  flex: none;
  width: 18px; height: 18px; margin-top: 2px;
  border: 1.5px solid var(--border-strong);
  border-radius: 50%;
  transition: border-color var(--t-fast), border-width var(--t-fast);
}
.choice:has(input:checked) { border-color: var(--primary); background: var(--primary-softer); }
.choice:has(input:checked) .choice-dot { border: 5.5px solid var(--primary); }
.choice:has(input:focus-visible) { box-shadow: 0 0 0 4px var(--primary-ring); }
.choice strong { display: block; font-size: .92rem; }
.choice span.small { color: var(--text-2); }

/* ---------- 6. Feedback ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  height: 24px;
  padding: 0 10px;
  border-radius: var(--r-full);
  font-size: .76rem;
  font-weight: 600;
  white-space: nowrap;
  background: var(--surface-2);
  color: var(--text-2);
  border: 1px solid var(--border);
}
.badge::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.badge.no-dot::before { display: none; }
.badge-success { background: var(--success-soft); color: var(--success-text); border-color: transparent; }
.badge-warning { background: var(--warning-soft); color: var(--warning-text); border-color: transparent; }
.badge-error { background: var(--error-soft); color: var(--error-text); border-color: transparent; }
.badge-info { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.badge-pending::before { animation: pulse-dot 1.6s ease-in-out infinite; }

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .35; transform: scale(.7); }
}

.alert {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 14px;
  border-radius: var(--r-sm);
  font-size: .9rem;
  line-height: 1.5;
  border: 1px solid transparent;
  animation: alert-in var(--t-med) var(--ease-out);
}
.alert .i { margin-top: 1px; }
.alert-error { background: var(--error-soft); color: var(--error-text); }
.alert-success { background: var(--success-soft); color: var(--success-text); }
.alert-info { background: var(--primary-softer); color: var(--text); border-color: var(--primary-soft); }
.alert-info .i { color: var(--primary); }
.alert-warning { background: var(--warning-soft); color: var(--warning-text); }
@keyframes alert-in { from { opacity: 0; transform: translateY(-4px); } }

.spinner {
  width: 22px; height: 22px;
  border: 2.5px solid var(--primary-soft);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .75s linear infinite;
  flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton {
  display: block;
  border-radius: var(--r-xs);
  background: linear-gradient(90deg, var(--surface-2) 0%, var(--surface-hover) 40%, var(--surface-2) 80%);
  background-size: 300% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -50% 0; } }

/* Toasts (bottom centre on mobile, bottom left on desktop) */
.toast-stack {
  position: fixed;
  left: 24px; bottom: 24px;
  z-index: 300;
  display: grid; gap: 8px;
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 10px;
  min-width: 240px; max-width: 420px;
  padding: 12px 14px 12px 16px;
  border-radius: var(--r-md);
  background: var(--navy);
  color: #F1F5FC;
  font-size: .9rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  animation: toast-in 280ms var(--ease-out);
}
:root[data-theme="dark"] .toast { background: #22365A; border: 1px solid var(--border-strong); }
.toast .i { color: #7FA7FF; }
.toast.success .i { color: #4FD69B; }
.toast.error .i { color: #FF98A0; }
.toast.leaving { animation: toast-out 200ms ease forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px) scale(.97); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px) scale(.97); } }

/* Empty states */
.empty {
  display: grid; justify-items: center; align-content: center; gap: 6px;
  padding: 48px 24px;
  text-align: center;
  animation: fade-up var(--t-slow) var(--ease-out);
}
.empty-art {
  position: relative;
  display: grid; place-items: center;
  width: 76px; height: 76px;
  margin-bottom: 10px;
  border-radius: 24px;
  background: var(--primary-soft);
  color: var(--primary);
}
.empty-art::after {
  content: "";
  position: absolute; inset: -10px;
  border-radius: 30px;
  border: 1px dashed var(--border-strong);
}
.empty-art .i { width: 32px; height: 32px; }
.empty h3 { font-size: 1.05rem; }
.empty p { color: var(--text-2); font-size: .9rem; max-width: 300px; }
.empty .btn { margin-top: 12px; }

@keyframes fade-up { from { opacity: 0; transform: translateY(8px); } }
@keyframes fade-in { from { opacity: 0; } }

/* Avatar with initials */
.avatar {
  --h: 220;
  display: inline-grid; place-items: center;
  width: 36px; height: 36px;
  flex: none;
  border-radius: 50%;
  background: hsl(var(--h) var(--avatar-sat) var(--avatar-light));
  color: hsl(var(--h) 55% var(--avatar-ink));
  font-weight: 700;
  font-size: .82rem;
  letter-spacing: .01em;
  text-transform: uppercase;
  user-select: none;
}
.avatar-sm { width: 28px; height: 28px; font-size: .72rem; }
.avatar-lg { width: 44px; height: 44px; font-size: .95rem; }

/* ---------- 7. Overlays ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  z-index: 250;
  display: grid; place-items: center;
  padding: 20px;
  background: var(--backdrop);
  backdrop-filter: blur(3px);
  animation: fade-in var(--t-med) ease;
}
.modal-backdrop.closing { animation: fade-out 180ms ease forwards; }
.modal {
  width: min(480px, 100%);
  max-height: calc(100dvh - 40px);
  overflow: auto;
  border-radius: var(--r-lg);
  background: var(--elevated);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  animation: modal-in 260ms var(--ease-out);
}
.modal-backdrop.closing .modal { animation: modal-out 180ms ease forwards; }
.modal-wide { width: min(620px, 100%); }
.modal-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: 22px 24px 0;
}
.modal-head h2 { font-size: 1.2rem; }
.modal-head p { margin-top: 4px; color: var(--text-2); font-size: .9rem; }
.modal-body { padding: 18px 24px; }
.modal-foot {
  display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 10px;
  padding: 0 24px 22px;
}
.modal-icon {
  display: grid; place-items: center;
  width: 44px; height: 44px;
  margin-bottom: 14px;
  border-radius: 14px;
  background: var(--error-soft); color: var(--error-text);
}
@keyframes fade-out { to { opacity: 0; } }
@keyframes modal-in { from { opacity: 0; transform: translateY(14px) scale(.97); } }
@keyframes modal-out { to { opacity: 0; transform: translateY(8px) scale(.98); } }

/* Dropdown menus */
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 8px);
  z-index: 120;
  min-width: 240px;
  padding: 6px;
  border-radius: var(--r-md);
  background: var(--elevated);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  transform-origin: top right;
  opacity: 0; visibility: hidden;
  transform: translateY(-4px) scale(.98);
  transition: opacity 200ms var(--ease), transform 200ms var(--ease-out), visibility 0s linear 200ms;
}
.menu.open {
  opacity: 1; visibility: visible; transform: none;
  transition: opacity 200ms var(--ease), transform 200ms var(--ease-out);
}
.menu-head { padding: 10px 12px 12px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.menu-head strong { display: block; font-size: .92rem; }
.menu-head span { font-size: .82rem; color: var(--text-2); word-break: break-all; }
.menu-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  padding: 9px 12px;
  border: 0; border-radius: var(--r-sm);
  background: none;
  color: var(--text);
  font-size: .9rem;
  text-align: left;
  cursor: pointer;
  transition: background-color var(--t-fast);
}
.menu-item:hover { background: var(--surface-hover); text-decoration: none; }
.menu-item .i { color: var(--text-2); width: 18px; height: 18px; }
.menu-sep { height: 1px; margin: 6px 0; background: var(--border); }

/* Tooltips: <button data-tip="Refresh"> */
[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip);
  position: absolute; left: 50%; top: calc(100% + 6px);
  z-index: 140;
  padding: 5px 9px;
  border-radius: 6px;
  background: var(--navy);
  color: #F1F5FC;
  font-size: .74rem;
  font-weight: 500;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -3px);
  transition: opacity 140ms ease, transform 140ms ease;
}
:root[data-theme="dark"] [data-tip]::after { background: #2A4066; }
@media (hover: hover) {
  [data-tip]:hover::after { opacity: 1; transform: translate(-50%, 0); transition-delay: 350ms; }
}

/* ---------- 8. Auth pages ---------- */
.auth-page {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr);
  background: var(--bg);
}
.auth-side {
  position: relative;
  overflow: hidden;
  display: flex; flex-direction: column; justify-content: space-between;
  padding: 40px 48px;
  background:
    radial-gradient(120% 80% at 0% 0%, #3978EE 0%, transparent 60%),
    radial-gradient(90% 70% at 100% 100%, #1B3F8F 0%, transparent 70%),
    #2459D6;
  color: #fff;
}
:root[data-theme="dark"] .auth-side {
  background:
    radial-gradient(120% 80% at 0% 0%, #1E3F86 0%, transparent 60%),
    radial-gradient(90% 70% at 100% 100%, #0E1E3D 0%, transparent 70%),
    #13284F;
}
.auth-side .brand { color: #fff; }
.auth-side .waves { position: absolute; inset: auto 0 0 0; width: 100%; height: 55%; opacity: .5; pointer-events: none; }
.auth-side .dots {
  position: absolute; right: 36px; top: 110px;
  width: 160px; height: 120px;
  background-image: radial-gradient(rgba(255, 255, 255, .35) 1.2px, transparent 1.4px);
  background-size: 14px 14px;
  pointer-events: none;
}
.auth-quote { position: relative; max-width: 420px; }
.auth-quote h2 { color: #fff; font-size: clamp(1.6rem, 2.4vw, 2.2rem); font-weight: 800; letter-spacing: -0.03em; line-height: 1.15; }
.auth-quote p { margin-top: 14px; color: rgba(255, 255, 255, .78); font-size: 1rem; }
.auth-points { position: relative; display: grid; gap: 12px; margin: 26px 0 0; padding: 0; list-style: none; }
.auth-points li { display: flex; gap: 10px; align-items: center; color: rgba(255, 255, 255, .9); font-size: .94rem; }
.auth-points .i { color: #A9C6FF; }
.auth-side-foot { position: relative; color: rgba(255, 255, 255, .6); font-size: .82rem; }

.auth-main {
  position: relative;
  display: flex; flex-direction: column;
  padding: 28px 40px;
}
.auth-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.auth-top .brand { visibility: hidden; }
.auth-card {
  width: 100%; max-width: 410px;
  margin: auto;
  padding: 40px 0;
  animation: fade-up 450ms var(--ease-out);
}
.auth-card h1 { font-size: 1.9rem; font-weight: 800; letter-spacing: -0.03em; }
.auth-card > p.muted { margin: 8px 0 28px; }
.auth-card form .btn-block { margin-top: 8px; }
.auth-switch { margin-top: 24px; text-align: center; color: var(--text-2); font-size: .92rem; }
.auth-card .alert { margin-bottom: 18px; }
.address-preview {
  display: flex; align-items: center; gap: 8px;
  margin-top: 2px;
  padding: 10px 12px;
  border-radius: var(--r-sm);
  background: var(--primary-softer);
  border: 1px dashed var(--primary-soft);
  font-size: .86rem;
  color: var(--text-2);
}
.address-preview strong { color: var(--primary); font-weight: 600; word-break: break-all; }
.address-preview .i { color: var(--primary); }

.strength { display: flex; gap: 4px; margin-top: 4px; }
.strength span { flex: 1; height: 4px; border-radius: 4px; background: var(--border); transition: background-color var(--t-med); }
.strength[data-level="1"] span:nth-child(-n+1) { background: var(--error); }
.strength[data-level="2"] span:nth-child(-n+2) { background: var(--warning); }
.strength[data-level="3"] span:nth-child(-n+3) { background: var(--success); }
.strength[data-level="4"] span { background: var(--success); }

@media (max-width: 900px) {
  .auth-page { grid-template-columns: 1fr; }
  .auth-side { display: none; }
  .auth-top .brand { visibility: visible; }
  .auth-main { padding: 18px 20px; min-height: 100dvh; }
  .auth-card { padding: 28px 0 40px; }
}

/* Error page */
.error-page {
  min-height: 100dvh;
  display: grid; place-items: center;
  padding: 24px;
  text-align: center;
  background:
    radial-gradient(60% 50% at 50% 0%, var(--primary-soft), transparent 70%),
    var(--bg);
}
.error-page .code {
  font-family: var(--font-display);
  font-size: clamp(5rem, 18vw, 9rem);
  font-weight: 800;
  letter-spacing: -0.06em;
  line-height: 1;
  color: transparent;
  -webkit-text-stroke: 2px var(--primary);
  opacity: .9;
}
.error-page h1 { margin-top: 12px; font-size: 1.6rem; }
.error-page p { margin: 10px auto 26px; max-width: 380px; color: var(--text-2); }
.error-page .actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* Reduced motion: keep state changes, drop movement */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
    scroll-behavior: auto !important;
  }
}

@media (max-width: 640px) {
  .toast-stack { left: 12px; right: 12px; bottom: 16px; }
  .toast { min-width: 0; max-width: none; }
  .modal-backdrop { align-items: end; padding: 0; }
  .modal { width: 100%; max-width: none; border-radius: var(--r-xl) var(--r-xl) 0 0; animation-name: sheet-in; }
  .modal-backdrop.closing .modal { animation-name: sheet-out; }
  .modal-foot .btn { flex: 1; }
}
@keyframes sheet-in { from { transform: translateY(40px); opacity: 0; } }
@keyframes sheet-out { to { transform: translateY(40px); opacity: 0; } }

.notice {
  background: #fff7e6;
  border: 1px solid #fde68a;
  border-radius: 8px;
  padding: 10px 12px;
  margin-top: 14px;
  color: #92400e;
}

.recovery-details { margin-bottom: 18px; border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.recovery-details summary { cursor: pointer; font-weight: 600; font-size: .9rem; }
.recovery-details[open] summary { margin-bottom: 6px; }
.recovery-details .small { color: var(--text-2); font-weight: 400; }