:root {
  --bg: #0b0f1a;
  --bg-2: #121828;
  --panel: #161d2e;
  --panel-2: #1d2740;
  --panel-3: #232f4d;
  --border: #26324c;
  --border-soft: #1e293f;
  --text: #eaf0fb;
  --text-2: #c2ccde;
  --muted: #8592ab;
  --muted-2: #5f6d86;
  --brand: #5b8def;
  --brand-2: #7aa5ff;
  --brand-3: #4a7ae0;
  --safe: #2fce87;
  --review: #f5c451;
  --remove: #f2606d;
  --unknown: #8592ab;
  --catchall: #f2954b;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 10px 40px rgba(0,0,0,.45);
  --shadow-sm: 0 2px 10px rgba(0,0,0,.25);
  --ring: 0 0 0 3px rgba(91,141,239,.25);
  --skeleton: linear-gradient(90deg, var(--panel-2) 25%, var(--panel-3) 37%, var(--panel-2) 63%);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background:
    radial-gradient(900px 500px at 85% -5%, rgba(91,141,239,.10) 0%, transparent 55%),
    radial-gradient(1100px 600px at 10% -10%, rgba(47,206,135,.06) 0%, transparent 55%),
    var(--bg);
  background-color: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: var(--brand-2); text-decoration: none; transition: color .15s; }
a:hover { color: var(--brand); }
button { font-family: inherit; cursor: pointer; }
::selection { background: rgba(91,141,239,.35); }

/* scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--panel-3); border-radius: 10px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: #33436b; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- Auth ---------- */
.auth-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px;
}
.auth-card {
  width: 100%; max-width: 410px; background: linear-gradient(180deg, var(--panel) 0%, var(--bg-2) 100%);
  border: 1px solid var(--border); border-radius: 18px; padding: 34px; box-shadow: var(--shadow);
}
.auth-card h2 { font-size: 20px; font-weight: 700; letter-spacing: -.01em; }
.brand-lg { font-size: 26px; font-weight: 800; margin: 0 0 6px; letter-spacing: -.02em; }
.brand-lg span { color: var(--brand); }
.tagline { color: var(--muted); margin: 0 0 26px; font-size: 13.5px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 7px; font-weight: 500; }
.field input {
  width: 100%; padding: 11px 13px; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text); font-size: 14px; transition: border-color .15s, box-shadow .15s;
}
.field input::placeholder { color: var(--muted-2); }
.field input:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 11px 17px; border-radius: var(--radius-sm); border: 1px solid transparent;
  background: linear-gradient(180deg, var(--brand-2) 0%, var(--brand) 100%);
  color: #fff; font-weight: 600; font-size: 14px; letter-spacing: .01em;
  box-shadow: 0 2px 8px rgba(74,122,224,.35); transition: transform .08s, box-shadow .15s, background .15s, opacity .15s;
}
.btn:hover { box-shadow: 0 4px 16px rgba(74,122,224,.5); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .6; cursor: default; box-shadow: none; }
.btn.block { width: 100%; }
.btn.ghost { background: var(--panel-2); border-color: var(--border); color: var(--text-2); box-shadow: none; }
.btn.ghost:hover { background: var(--panel-3); color: var(--text); }
.btn.sm { padding: 7px 13px; font-size: 12.5px; }
.btn.danger { background: transparent; border-color: rgba(242,96,109,.5); color: var(--remove); box-shadow: none; }
.btn.danger:hover { background: rgba(242,96,109,.12); }
.switch-link { text-align: center; margin-top: 18px; color: var(--muted); font-size: 13px; }
.error { color: var(--remove); font-size: 13px; margin: 8px 0; min-height: 18px; }

/* ---------- Layout ---------- */
.shell { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.sidebar {
  background: linear-gradient(180deg, var(--bg-2) 0%, var(--bg) 100%);
  border-right: 1px solid var(--border-soft); padding: 22px 16px; display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand { font-size: 19px; font-weight: 800; padding: 4px 10px 22px; letter-spacing: -.02em; display: flex; align-items: center; gap: 9px; }
.brand span { color: var(--brand); }
.brand::before {
  content: ""; width: 26px; height: 26px; border-radius: 8px; flex: 0 0 26px;
  background: linear-gradient(135deg, var(--brand-2), var(--safe));
  box-shadow: 0 2px 10px rgba(91,141,239,.5);
}
.nav a {
  display: flex; align-items: center; gap: 11px; padding: 10px 13px; border-radius: 10px;
  color: var(--muted); font-weight: 500; margin-bottom: 3px; cursor: pointer;
  transition: background .15s, color .15s; font-size: 14px;
}
.nav a .nav-ic {
  flex: 0 0 18px; width: 18px; height: 18px; display: grid; place-items: center; opacity: .85;
}
.nav a:hover { background: var(--panel); color: var(--text); }
.nav a.active {
  background: linear-gradient(180deg, var(--brand-2), var(--brand));
  color: #fff; box-shadow: 0 2px 12px rgba(74,122,224,.4);
}
.nav a.active .nav-ic { opacity: 1; }
.sidebar-footer { margin-top: auto; padding: 14px 10px 4px; border-top: 1px solid var(--border-soft); }
.credits-badge { font-size: 12px; color: var(--muted); }
.credits-badge b { color: var(--safe); font-size: 18px; font-weight: 700; display: block; margin-top: 2px; }

.main { padding: 32px 38px; overflow-y: auto; height: 100vh; max-width: 1400px; }
.page-title { font-size: 24px; font-weight: 800; margin: 0 0 5px; letter-spacing: -.02em; }
.page-sub { color: var(--muted); margin: 0 0 26px; font-size: 14px; }

/* ---------- Cards & grid ---------- */
.grid { display: grid; gap: 18px; }
.cols-2 { grid-template-columns: 1fr 1fr; }
.cols-3 { grid-template-columns: repeat(3, 1fr); }
.cols-4 { grid-template-columns: repeat(4, 1fr); }
.card {
  background: linear-gradient(180deg, var(--panel) 0%, var(--bg-2) 120%);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 22px;
  box-shadow: var(--shadow-sm);
}
.card h3 { margin: 0 0 14px; font-size: 15px; font-weight: 700; letter-spacing: -.01em; }
.stat { font-size: 30px; font-weight: 800; letter-spacing: -.02em; margin-top: 2px; }
.stat-label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }

/* stat cards get a subtle accent */
.grid.cols-4 > .card { position: relative; overflow: hidden; }
.grid.cols-4 > .card::after {
  content: ""; position: absolute; top: 0; left: 0; width: 3px; height: 100%;
  background: linear-gradient(180deg, var(--brand-2), transparent);
}

/* ---------- Skeleton loading ---------- */
.skeleton {
  border-radius: var(--radius-sm);
  background: var(--skeleton); background-size: 400% 100%;
  animation: skeleton 1.3s ease-in-out infinite;
}
.skeleton-line { height: 12px; margin-bottom: 10px; }
.skeleton-line.short { width: 40%; }
.skeleton-card { height: 96px; border-radius: var(--radius); }
@keyframes skeleton { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
@media (prefers-reduced-motion: reduce) {
  .skeleton { animation: none; }
  * { scroll-behavior: auto; }
}

/* ---------- Upload ---------- */
.dropzone {
  border: 2px dashed var(--border); border-radius: var(--radius); padding: 48px;
  text-align: center; color: var(--muted); background: var(--bg-2); transition: .18s; cursor: pointer;
}
.dropzone:hover { border-color: var(--brand-3); }
.dropzone.drag { border-color: var(--brand); background: var(--panel-2); color: var(--text); box-shadow: var(--ring); }
.dropzone strong { color: var(--text); }

/* ---------- Table ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--border-soft); font-size: 13px; }
th { color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
tbody tr { transition: background .12s; }
tbody tr:hover { background: var(--panel-2); }
tbody tr:last-child td { border-bottom: none; }
.email-cell { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 700; text-transform: capitalize; letter-spacing: .02em;
}
.badge.safe { background: rgba(47,206,135,.16); color: var(--safe); }
.badge.review { background: rgba(245,196,81,.16); color: var(--review); }
.badge.remove { background: rgba(242,96,109,.16); color: var(--remove); }
.badge.unknown { background: rgba(133,146,171,.16); color: var(--unknown); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.safe { background: var(--safe); }
.dot.review { background: var(--review); }
.dot.remove { background: var(--remove); }
.dot.unknown { background: var(--unknown); }
.dot.catchall { background: var(--catchall); }

/* ---------- Score ring ---------- */
.ring-wrap { display: flex; align-items: center; gap: 24px; }
.ring { position: relative; width: 124px; height: 124px; flex: 0 0 124px; }
.ring svg { transform: rotate(-90deg); }
.ring circle:last-child { transition: stroke-dasharray .6s cubic-bezier(.4,0,.2,1); }
.ring .val { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring .val b { font-size: 28px; font-weight: 800; letter-spacing: -.02em; }
.ring .val small { color: var(--muted); font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; margin-top: 2px; }

/* ---------- Metric bars ---------- */
.metric { margin-bottom: 15px; }
.metric:last-child { margin-bottom: 0; }
.metric .row { display: flex; justify-content: space-between; margin-bottom: 6px; font-size: 13px; }
.metric .row span:last-child { font-weight: 700; font-variant-numeric: tabular-nums; }
.bar { height: 8px; background: var(--bg); border-radius: 999px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--brand); border-radius: 999px; transition: width .6s cubic-bezier(.4,0,.2,1); }

/* ---------- Signals ---------- */
.signal { display: flex; align-items: center; gap: 9px; padding: 6px 0; font-size: 13px; }
.signal .ic {
  width: 20px; height: 20px; flex: 0 0 20px; border-radius: 6px; display: grid; place-items: center;
  font-size: 11px; font-weight: 700;
}
.signal.pass .ic { color: var(--safe); background: rgba(47,206,135,.14); }
.signal.warn .ic { color: var(--review); background: rgba(245,196,81,.14); }
.signal.fail .ic { color: var(--remove); background: rgba(242,96,109,.14); }
.signal.info .ic { color: var(--muted); background: rgba(133,146,171,.14); }

.reasons { background: var(--bg); border: 1px solid var(--border-soft); border-radius: var(--radius-sm); padding: 14px 16px; margin-top: 12px; }
.reasons li { margin-bottom: 7px; color: var(--text-2); }
.reasons li:last-child { margin-bottom: 0; }
.recommendation {
  border-left: 3px solid var(--brand); padding: 12px 16px; background: var(--panel-2);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0; margin-top: 14px; font-size: 13.5px;
}

/* ---------- Misc ---------- */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 18px; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.pill { padding: 4px 11px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--border-soft); font-size: 12px; color: var(--text-2); }
.progress-outer { height: 12px; background: var(--bg); border-radius: 999px; overflow: hidden; border: 1px solid var(--border-soft); }
.progress-inner { height: 100%; background: linear-gradient(90deg, var(--brand-2), var(--brand)); transition: width .4s; border-radius: 999px; }
.empty { text-align: center; color: var(--muted); padding: 56px 20px; }
.list-row {
  display: flex; align-items: center; gap: 16px; padding: 16px 18px; background: var(--panel);
  border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 12px; cursor: pointer;
  transition: border-color .15s, transform .1s, box-shadow .15s;
}
.list-row:hover { border-color: var(--brand-3); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.mini-score {
  font-weight: 800; font-size: 18px; width: 44px; height: 44px; flex: 0 0 44px; border-radius: 11px;
  display: grid; place-items: center; background: var(--bg); border: 1px solid var(--border-soft);
}
select, .toolbar input {
  padding: 9px 12px; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text); font-size: 13px; transition: border-color .15s, box-shadow .15s;
}
select:focus, .toolbar input:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring); }
code.key { background: var(--bg); border: 1px solid var(--border-soft); padding: 8px 12px; border-radius: 7px; font-size: 12px; word-break: break-all; }
pre.reasons code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; line-height: 1.6; color: var(--text-2); }
.hist-table td { font-variant-numeric: tabular-nums; }
.delta-up { color: var(--safe); font-weight: 600; }
.delta-down { color: var(--remove); font-weight: 600; }
.toast {
  position: fixed; bottom: 26px; right: 26px; background: var(--panel-2); border: 1px solid var(--border);
  padding: 13px 20px; border-radius: 12px; box-shadow: var(--shadow); z-index: 100; font-size: 13.5px;
  animation: toast-in .25s cubic-bezier(.2,.8,.2,1);
}
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 50;
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 20px; overflow-y: auto;
}
.modal-card {
  width: 100%; background: linear-gradient(180deg, var(--panel) 0%, var(--bg-2) 100%);
  border: 1px solid var(--border); border-radius: 16px; padding: 28px; box-shadow: var(--shadow);
  margin: auto;
}

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; overflow-x: auto; align-items: center; }
  .sidebar .brand { padding: 4px 10px; white-space: nowrap; }
  .nav { display: flex; }
  .nav a { margin-bottom: 0; white-space: nowrap; }
  .sidebar-footer { margin-top: 0; margin-left: auto; border-top: none; border-left: 1px solid var(--border-soft); }
  .main { padding: 22px 18px; height: auto; }
  .cols-4, .cols-3, .cols-2 { grid-template-columns: 1fr; }
}

/* ---------- Landing ---------- */
.landing {
  min-height: 100vh; display: grid; grid-template-columns: 1.1fr 420px; gap: 56px;
  align-items: center; max-width: 1160px; margin: 0 auto; padding: 48px 28px;
}
.hero-lead { font-size: 30px; font-weight: 800; margin: 10px 0 12px; letter-spacing: -.03em; line-height: 1.15; }
.hero-sub { color: var(--muted); font-size: 16px; max-width: 48ch; margin: 0 0 34px; }
.feature-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.feature { display: flex; gap: 13px; align-items: flex-start; }
.feature-ic {
  flex: 0 0 38px; width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center;
  background: rgba(91,141,239,.14); color: var(--brand-2); font-weight: 700; font-size: 16px;
  border: 1px solid rgba(91,141,239,.25);
}
.feature b { display: block; margin-bottom: 3px; font-size: 14px; }
.feature .muted { font-size: 13px; line-height: 1.5; }
.landing .auth-card { margin: 0; }
@media (max-width: 900px) {
  .landing { grid-template-columns: 1fr; gap: 32px; padding: 32px 20px; }
  .feature-grid { grid-template-columns: 1fr 1fr; }
  .hero-lead { font-size: 24px; }
}
@media (max-width: 560px) {
  .feature-grid { grid-template-columns: 1fr; }
}

/* ---------- Capability banner ---------- */
.banner-warn {
  background: rgba(245,196,81,.10); border: 1px solid rgba(245,196,81,.35);
  color: #f5d98a; border-radius: 12px; padding: 14px 18px; margin-bottom: 22px;
  font-size: 13px; line-height: 1.6; display: flex; gap: 10px; align-items: flex-start;
}
.banner-warn::before { content: "⚠"; font-size: 15px; flex: 0 0 auto; }
.banner-warn b { color: #ffe9b0; }
.banner-warn code { background: rgba(0,0,0,.35); padding: 1px 6px; border-radius: 4px; }

/* ---------- MailHealth AI (agent) ---------- */
.agent-wrap { display: flex; flex-direction: column; height: calc(100vh - 64px); max-width: 860px; }
.agent-head { margin-bottom: 14px; }
.agent-title { font-size: 22px; font-weight: 800; letter-spacing: -.02em; display: flex; align-items: center; gap: 10px; }
.agent-glyph { filter: saturate(1.2); }
.agent-sub { color: var(--muted); margin: 6px 0 0; font-size: 13.5px; max-width: 640px; }

.agent-quick { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }
.agent-chip {
  padding: 8px 13px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text-2); font-size: 12.5px; font-weight: 500;
  transition: background .15s, color .15s, border-color .15s;
}
.agent-chip:hover { background: var(--panel-3); color: var(--text); border-color: var(--brand-3); }

.agent-thread {
  flex: 1; overflow-y: auto; padding: 16px; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--bg-2); display: flex; flex-direction: column; gap: 16px;
}
.agent-empty { color: var(--muted); font-size: 13px; text-align: center; margin: auto; max-width: 560px; }

.agent-msg { display: flex; gap: 12px; align-items: flex-start; }
.agent-msg.user { justify-content: flex-end; }
.agent-msg.user .agent-body {
  background: linear-gradient(180deg, var(--brand-2), var(--brand)); color: #fff;
  border-radius: 14px 14px 4px 14px; max-width: 80%;
}
.agent-avatar {
  flex: 0 0 30px; width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
  font-size: 11px; font-weight: 800; color: #fff;
  background: linear-gradient(135deg, var(--brand-2), var(--safe));
  box-shadow: 0 2px 8px rgba(91,141,239,.4);
}
.agent-body {
  background: var(--panel); border: 1px solid var(--border-soft); border-radius: 14px 14px 14px 4px;
  padding: 12px 14px; max-width: 78%; box-shadow: var(--shadow-sm);
}
.agent-msg.user .agent-body { border: none; }
.agent-text { font-size: 13.5px; line-height: 1.55; }
.agent-verified { color: var(--safe); }
.agent-reco { color: var(--brand-2); }

.agent-steps { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.agent-step {
  font-size: 11px; padding: 3px 9px; border-radius: 999px; color: var(--muted);
  background: var(--panel-2); border: 1px solid var(--border-soft);
}
.agent-step.done { color: var(--safe); border-color: rgba(47,206,135,.35); }
.agent-step.wait { color: var(--review); border-color: rgba(245,196,81,.35); }
.agent-step.fail { color: var(--remove); border-color: rgba(242,96,109,.35); }
.agent-step:not(.done):not(.wait):not(.fail)::after {
  content: ""; display: inline-block; width: 4px; height: 4px; margin-left: 6px; border-radius: 50%;
  background: var(--muted); animation: agentPulse 1s infinite ease-in-out;
}
@keyframes agentPulse { 0%,100% { opacity: .3; } 50% { opacity: 1; } }

.agent-sources { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.agent-source { font-size: 10.5px; color: var(--safe); background: rgba(47,206,135,.12); padding: 2px 8px; border-radius: 6px; }
.agent-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.agent-actions:empty { display: none; }
.agent-meta { margin-top: 10px; font-size: 10.5px; color: var(--muted-2); font-family: ui-monospace, Menlo, monospace; }

.agent-composer { display: flex; gap: 10px; margin-top: 14px; }
.agent-composer input {
  flex: 1; padding: 12px 14px; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text); font-size: 14px;
}
.agent-composer input:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring); }

.agent-confirm .agent-confirm-head { font-size: 15px; font-weight: 800; margin-bottom: 10px; }
.agent-confirm.danger .agent-confirm-head { color: var(--remove); }
.agent-confirm-body { font-size: 14px; color: var(--text); }
.agent-confirm-warn { color: var(--remove); font-size: 12.5px; margin-top: 8px; }
