/* ---------- Tokens ---------- */
:root {
  --font: "Inter", "Segoe UI Variable Text", "Segoe UI", -apple-system, "SF Pro Text", system-ui, Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: "Inter", "Segoe UI Variable Display", "Segoe UI", -apple-system, "SF Pro Display", system-ui, Roboto, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SF Mono", Consolas, "Liberation Mono", monospace;

  --bg: #eef1fa;
  --blob-1: rgba(129, 140, 248, .55);
  --blob-2: rgba(244, 114, 182, .38);
  --blob-3: rgba(34, 211, 238, .40);
  --glass: rgba(255, 255, 255, .58);
  --glass-strong: rgba(255, 255, 255, .86);
  --glass-border: rgba(255, 255, 255, .75);
  --glass-hover: rgba(255, 255, 255, .78);
  --line: rgba(15, 23, 42, .08);
  --field: rgba(255, 255, 255, .75);
  --text: #0f172a;
  --muted: #5b6478;
  --faint: #8a93a8;
  --accent: #4f46e5;
  --accent-2: #06b6d4;
  --accent-soft: rgba(79, 70, 229, .10);
  --ok: #059669;
  --warn: #d97706;
  --danger: #e11d48;
  --danger-soft: rgba(225, 29, 72, .10);
  --ring-track: rgba(15, 23, 42, .08);
  --shadow: 0 1px 1px rgba(15, 23, 42, .03), 0 8px 24px -6px rgba(30, 41, 90, .14), inset 0 1px 0 rgba(255, 255, 255, .6);
  --shadow-lg: 0 24px 64px -12px rgba(30, 41, 90, .35);
  --radius: 20px;
  --radius-sm: 12px;
  color-scheme: light;
}
/* Dark theme is opt-in only (data-theme="dark" on <html>); the portal is light by default. */
@media all {
  :root[data-theme="dark"] {
    --bg: #080b18;
    --blob-1: rgba(99, 102, 241, .35);
    --blob-2: rgba(192, 38, 211, .22);
    --blob-3: rgba(6, 182, 212, .22);
    --glass: rgba(22, 27, 48, .55);
    --glass-strong: rgba(24, 29, 52, .92);
    --glass-border: rgba(255, 255, 255, .08);
    --glass-hover: rgba(36, 42, 70, .7);
    --line: rgba(255, 255, 255, .07);
    --field: rgba(255, 255, 255, .04);
    --text: #e8ebf6;
    --muted: #9aa3bd;
    --faint: #6f7893;
    --accent: #818cf8;
    --accent-2: #22d3ee;
    --accent-soft: rgba(129, 140, 248, .14);
    --ok: #34d399;
    --warn: #fbbf24;
    --danger: #fb7185;
    --danger-soft: rgba(251, 113, 133, .12);
    --ring-track: rgba(255, 255, 255, .08);
    --shadow: 0 1px 1px rgba(0, 0, 0, .2), 0 8px 28px -8px rgba(0, 0, 0, .5), inset 0 1px 0 rgba(255, 255, 255, .05);
    --shadow-lg: 0 24px 64px -12px rgba(0, 0, 0, .7);
    color-scheme: dark;
  }
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14.5px/1.55 var(--font);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "cv11", "ss01";
  min-height: 100vh;
}
/* Soft colour blobs behind the glass */
body::before {
  content: "";
  position: fixed;
  inset: -20vmax;
  z-index: -1;
  background:
    radial-gradient(38vmax 38vmax at 18% 12%, var(--blob-1), transparent 70%),
    radial-gradient(34vmax 34vmax at 88% 18%, var(--blob-2), transparent 70%),
    radial-gradient(40vmax 40vmax at 70% 92%, var(--blob-3), transparent 70%);
  filter: blur(10px);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { font-family: var(--font-display); letter-spacing: -.02em; margin: 0; }
h1 { font-size: clamp(24px, 3.4vw, 34px); font-weight: 700; line-height: 1.15; }
h2 { font-size: 16px; font-weight: 650; }
p { margin: 0; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
svg.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Glass surfaces ---------- */
.glass {
  background: var(--glass);
  -webkit-backdrop-filter: blur(22px) saturate(170%);
  backdrop-filter: blur(22px) saturate(170%);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ---------- Top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 20; padding: 12px 16px 0; }
.topbar-inner { max-width: 1120px; margin: 0 auto; padding: 10px 12px 10px 16px; display: flex; align-items: center; gap: 10px; border-radius: 18px; }
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--font-display); font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.brand-mark { width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent-2)); box-shadow: 0 6px 16px -6px var(--accent); }
.brand-mark svg.icon { width: 17px; height: 17px; }
.brand-logo { width: 32px; height: 32px; border-radius: 10px; object-fit: cover; flex: none; box-shadow: 0 6px 16px -8px rgba(15, 23, 42, .4); }
.login .brand-logo { width: 104px; height: 104px; border-radius: 24px; }
.brand-name { font-size: 15px; color: var(--muted); font-weight: 650; letter-spacing: .01em; }
.spacer { flex: 1; }
.user-chip { display: flex; align-items: center; gap: 8px; padding: 4px 12px 4px 4px; border-radius: 999px; background: var(--field); border: 1px solid var(--line); font-size: 13px; font-weight: 550; }
.avatar { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 12px; background: linear-gradient(135deg, var(--accent), var(--accent-2)); flex: none; }

/* ---------- Page ---------- */
.page { max-width: 1120px; margin: 0 auto; padding: 28px 16px 72px; display: grid; gap: 18px; }
.hero { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding: 6px 4px 4px; }
.eyebrow { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 650; letter-spacing: .08em; text-transform: uppercase; color: var(--accent); margin-bottom: 8px; }
.hero p { margin-top: 6px; color: var(--muted); }

.segmented { display: inline-flex; gap: 4px; padding: 4px; border-radius: 14px; flex-wrap: wrap; }
.segmented button { border: 0; background: transparent; box-shadow: none; padding: 7px 14px; border-radius: 10px; font-weight: 600; color: var(--muted); }
.segmented button:hover { background: var(--glass-hover); color: var(--text); }
.segmented button.active { background: var(--glass-strong); color: var(--text); box-shadow: 0 2px 8px -2px rgba(15, 23, 42, .15); }

/* ---------- Stat cards with rings ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 18px; }
.stat { display: flex; align-items: center; gap: 18px; padding: 20px 22px; }
.stat-text { min-width: 0; }
.stat-label { color: var(--muted); font-size: 13px; font-weight: 550; }
.stat-value { font-family: var(--font-display); font-size: 24px; font-weight: 700; letter-spacing: -.02em; margin: 2px 0 2px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stat-value small { font-size: 14px; font-weight: 600; color: var(--faint); }
.stat-sub { color: var(--faint); font-size: 12.5px; }

.ring { position: relative; flex: none; display: grid; place-items: center; }
.ring svg { display: block; }
.ring-track { fill: none; stroke: var(--ring-track); }
.ring-arc { fill: none; transition: stroke-dashoffset 1.1s cubic-bezier(.22, 1, .36, 1); filter: drop-shadow(0 2px 6px rgba(79, 70, 229, .25)); }
.ring-center { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--font-display); font-weight: 700; font-size: 18px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.ring.sm .ring-center { font-size: 10.5px; font-weight: 700; color: var(--muted); }
.ring .g1 { stop-color: var(--accent); }
.ring .g2 { stop-color: var(--accent-2); }
.ring.warn .g1 { stop-color: #f59e0b; }
.ring.warn .g2 { stop-color: #f97316; }
.ring.full .g1 { stop-color: #f43f5e; }
.ring.full .g2 { stop-color: #e11d48; }
.ring.none .ring-track { stroke-dasharray: 2 5; }

/* ---------- Panels ---------- */
.panel { overflow: hidden; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--line); }
.panel-title { display: flex; align-items: center; gap: 10px; }
.panel-title .icon-tile { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 650; background: var(--accent-soft); color: var(--accent); font-variant-numeric: tabular-nums; }
.chip.danger { background: var(--danger-soft); color: var(--danger); }
.two { display: grid; grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); gap: 18px; align-items: start; }

/* Mailbox list */
.mbox-list { display: grid; }
.mbox { display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; align-items: center; gap: 14px; padding: 14px 22px; border-bottom: 1px solid var(--line); transition: background .15s; }
.mbox:last-child { border-bottom: 0; }
.mbox:hover { background: var(--glass-hover); }
.mbox .avatar { width: 38px; height: 38px; font-size: 14px; border-radius: 12px; }
.mbox-addr { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mbox-meta { color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.mbox-actions { display: flex; gap: 6px; }

/* Simple rows (databases, settings) */
.rows { display: grid; }
.row { display: flex; align-items: center; gap: 12px; padding: 13px 22px; border-bottom: 1px solid var(--line); min-width: 0; }
.row:last-child { border-bottom: 0; }
.row-label { color: var(--muted); font-size: 13px; width: 120px; flex: none; }
.row-value { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .icon-tile { width: 32px; height: 32px; border-radius: 10px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); flex: none; }
.panel-foot { padding: 16px 22px 20px; border-top: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

.empty { padding: 40px 22px; text-align: center; color: var(--muted); display: grid; justify-items: center; gap: 10px; }
.empty .icon-tile { width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.empty .icon-tile svg.icon { width: 22px; height: 22px; }

/* ---------- Buttons ---------- */
button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 15px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--field); color: var(--text);
  font: inherit; font-weight: 600; font-size: 13.5px; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .08s, box-shadow .15s;
}
button:hover, .btn:hover { background: var(--glass-strong); text-decoration: none; }
button:active, .btn:active { transform: translateY(1px); }
button:focus-visible, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary, .btn.primary {
  border-color: transparent; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 8px 20px -8px var(--accent);
}
button.primary:hover, .btn.primary:hover { filter: brightness(1.07); background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
button.danger { color: var(--danger); }
button.danger:hover { background: var(--danger-soft); border-color: transparent; }
button.danger.solid { background: var(--danger); color: #fff; border-color: transparent; }
button.ghost, .btn.ghost { background: transparent; border-color: transparent; }
button.ghost:hover, .btn.ghost:hover { background: var(--glass-hover); }
button.icon-btn, .btn.icon-btn { padding: 8px 10px; }
button.block { width: 100%; padding: 12px 16px; }
button:disabled { opacity: .55; cursor: progress; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions.end { justify-content: flex-end; }

/* ---------- Forms ---------- */
label.field { display: block; margin-bottom: 16px; }
label.field > span { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; }
label.field > small { display: block; color: var(--faint); margin-top: 6px; font-size: 12px; }
input, select {
  width: 100%; padding: 11px 13px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--field); color: var(--text); font: inherit;
  transition: border-color .15s, box-shadow .15s;
}
input::placeholder { color: var(--faint); }
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.input-group { display: flex; gap: 6px; align-items: stretch; }
.input-group input { flex: 1; min-width: 0; }
.input-group .suffix { display: flex; align-items: center; padding: 0 12px; border-radius: var(--radius-sm); background: var(--accent-soft); color: var(--accent); font-weight: 600; white-space: nowrap; }
.alert { padding: 11px 14px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 13px; }
.alert.error { background: var(--danger-soft); color: var(--danger); }
.alert.info { background: var(--accent-soft); color: var(--accent); }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px 16px; }
.login { width: 100%; max-width: 400px; padding: 32px 28px 28px; }
.login .brand { flex-direction: column; gap: 14px; text-align: center; margin-bottom: 6px; }
.login .brand-mark { width: 52px; height: 52px; border-radius: 16px; }
.login .brand-mark svg.icon { width: 26px; height: 26px; }
.login h1 { font-size: 24px; text-align: center; }
.login .lead { text-align: center; color: var(--muted); margin: 6px 0 24px; }

/* ---------- Modal & toasts ---------- */
.modal-back { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 16px; background: rgba(8, 11, 24, .35); -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); animation: fade .15s ease-out; }
.modal { width: 100%; max-width: 460px; max-height: 92vh; overflow: auto; padding: 24px; background: var(--glass-strong); box-shadow: var(--shadow-lg); animation: pop .2s cubic-bezier(.22, 1, .36, 1); }
.modal h2 { font-size: 19px; margin-bottom: 18px; overflow-wrap: anywhere; }
.modal p { margin-bottom: 16px; }
.modal .actions { margin-top: 4px; }
#toasts { position: fixed; right: 16px; bottom: 16px; z-index: 50; display: grid; gap: 8px; }
.toast { display: flex; align-items: center; gap: 10px; max-width: 380px; padding: 12px 16px; border-radius: 14px; font-size: 13.5px; font-weight: 550; background: var(--glass-strong); border: 1px solid var(--glass-border); box-shadow: var(--shadow-lg); -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px); animation: pop .2s cubic-bezier(.22, 1, .36, 1); }
.toast .icon { color: var(--ok); }
.toast.error .icon { color: var(--danger); }
.loading { padding: 40px; text-align: center; color: var(--muted); }
.spinner { width: 16px; height: 16px; border: 2px solid var(--ring-track); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; vertical-align: -3px; margin-right: 8px; }
.skeleton { height: 92px; border-radius: var(--radius); background: linear-gradient(90deg, var(--glass) 0%, var(--glass-hover) 50%, var(--glass) 100%); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; border: 1px solid var(--glass-border); }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.98); } }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- Setup guide ---------- */
.modal.wide { max-width: 640px; }
.guide-tabs { margin-bottom: 14px; background: var(--field); border: 1px solid var(--line); }
.guide-tabs button { gap: 6px; }
.guide-hint { font-size: 13px; margin-bottom: 12px; }
.steps { list-style: none; counter-reset: step; margin: 0 0 18px; padding: 0; display: grid; gap: 10px; }
.steps li { counter-increment: step; display: grid; grid-template-columns: 28px 1fr; gap: 12px; align-items: start; line-height: 1.6; }
.steps li::before {
  content: counter(step); width: 28px; height: 28px; border-radius: 9px; display: grid; place-items: center;
  font-weight: 700; font-size: 13px; color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent-2));
}
.steps li > div { padding-top: 2px; }
.kbd { font-family: var(--mono); font-size: 12.5px; padding: 1px 7px; border-radius: 7px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.guide-more { border: 1px solid var(--line); border-radius: var(--radius-sm); margin-bottom: 12px; background: var(--field); overflow: hidden; }
.guide-more summary { cursor: pointer; padding: 11px 14px; font-weight: 600; font-size: 13.5px; }
.guide-more .rows { border-top: 1px solid var(--line); }
.guide-more .row { padding: 9px 14px; }
.tips { margin: 0; padding: 4px 14px 12px 32px; display: grid; gap: 8px; font-size: 13.5px; color: var(--muted); }
.tips strong { color: var(--text); }
.settings-rows .row-label { width: 132px; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .lbl { display: none; }
}
@media (max-width: 640px) {
  .topbar { padding: 8px 8px 0; }
  .user-chip .who { display: none; }
  .user-chip { padding: 4px; }
  .page { padding: 20px 12px 56px; gap: 14px; }
  .hero > button { width: 100%; }
  .stat { padding: 16px 18px; }
  .mbox { grid-template-columns: auto minmax(0, 1fr) auto; padding: 14px 16px; }
  .mbox-actions { grid-column: 1 / -1; justify-content: flex-end; }
  .panel-head, .row, .panel-foot { padding-left: 16px; padding-right: 16px; }
  .row-label { width: 96px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
