/* ===== Design tokens ===== */
:root {
  --bg: #f5f6fb;
  --surface: #ffffff;
  --surface-2: #f8f9fc;
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --line: #e6e8f0;
  --line-2: #eef0f6;
  --brand: #5b4fe9;
  --brand-ink: #ffffff;
  --brand-soft: #eeecfe;
  --accent: #14b8a6;
  --grad: linear-gradient(135deg, #6d5efc 0%, #4f46e5 45%, #0ea5a4 100%);
  --good: #15803d; --good-soft: #e8f7ee;
  --warn: #b45309; --warn-soft: #fdf3e2;
  --bad: #c62828;  --bad-soft: #fdecec;
  --info: #1d4ed8; --info-soft: #e8efff;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 8px 24px -12px rgba(15, 23, 42, .12);
  --shadow-lg: 0 24px 60px -20px rgba(15, 23, 42, .35);
  --r-sm: 8px; --r: 12px; --r-lg: 18px;
  --side-w: 248px;
  --side-bg: #0f1226;
  --side-ink: #c7cbe0;
  --side-ink-strong: #ffffff;
  --side-hover: rgba(255, 255, 255, .06);
  --side-active: rgba(124, 115, 255, .18);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0e1a; --surface: #131729; --surface-2: #171c31; --ink: #e8eaf4; --ink-2: #c3c8db; --muted: #8a91a8;
    --line: #242a42; --line-2: #1d2238; --brand: #8b80ff; --brand-ink: #0b0e1a; --brand-soft: #231f4d;
    --good: #4ade80; --good-soft: #10291b; --warn: #fbbf24; --warn-soft: #2d2410; --bad: #f87171; --bad-soft: #321616;
    --info: #93b4ff; --info-soft: #162143;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px -12px rgba(0, 0, 0, .6);
    --side-bg: #080a14;
    color-scheme: dark;
  }
}

/* ===== Base ===== */
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: "Heebo", "Segoe UI", Arial, sans-serif; background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.55; -webkit-font-smoothing: antialiased; }
.hidden { display: none !important; }
h1 { font-size: 26px; font-weight: 800; letter-spacing: -.01em; margin: 0; }
h2 { font-size: 17px; font-weight: 700; margin: 28px 0 12px; }
small, .muted { color: var(--muted); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
::selection { background: var(--brand-soft); }

/* ===== Forms ===== */
label { display: block; margin-bottom: 14px; font-weight: 600; font-size: 13.5px; color: var(--ink-2); }
input, select, textarea {
  display: block; width: 100%; margin-top: 6px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--r-sm);
  font: inherit; font-weight: 400; background: var(--surface); color: var(--ink); transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }
textarea { min-height: 140px; font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 13px; direction: ltr; text-align: left; line-height: 1.5; }
input[type=checkbox] { display: inline-block; width: 16px; height: 16px; margin: 0 0 0 8px; vertical-align: -3px; accent-color: var(--brand); }
input[type=file] { padding: 8px; background: var(--surface-2); }

/* ===== Buttons ===== */
button, .btn {
  font: inherit; font-weight: 600; font-size: 14px; cursor: pointer; border-radius: 10px; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); padding: 9px 16px; display: inline-flex; align-items: center; gap: 8px; transition: transform .08s, box-shadow .15s, background .15s, border-color .15s;
  box-shadow: var(--shadow-sm); white-space: nowrap;
}
button:hover { border-color: #cfd3e3; background: var(--surface-2); }
button:active { transform: translateY(1px); }
button.primary { background: var(--grad); color: #fff; border-color: transparent; box-shadow: 0 6px 16px -6px rgba(79, 70, 229, .55); }
button.primary:hover { filter: brightness(1.06); }
button.danger { color: var(--bad); }
button.danger:hover { background: var(--bad-soft); border-color: transparent; }
button.link { background: none; border: 0; box-shadow: none; color: var(--brand); padding: 0; }
button:disabled { opacity: .55; cursor: default; transform: none; }
button svg, .nav svg { flex: none; }
.error { color: var(--bad); min-height: 1em; font-size: 14px; }

/* ===== Auth ===== */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth-hero { background: var(--grad); color: #fff; padding: 56px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.auth-hero::before, .auth-hero::after { content: ""; position: absolute; border-radius: 50%; background: rgba(255, 255, 255, .08); }
.auth-hero::before { width: 520px; height: 520px; top: -180px; left: -160px; }
.auth-hero::after { width: 380px; height: 380px; bottom: -140px; right: -100px; }
.auth-hero > * { position: relative; }
.auth-hero h2 { font-size: 38px; line-height: 1.2; font-weight: 800; margin: 0 0 16px; max-width: 460px; }
.auth-hero p { font-size: 17px; opacity: .9; max-width: 440px; margin: 0; }
.auth-points { display: grid; gap: 14px; margin-top: 36px; }
.auth-points div { display: flex; gap: 12px; align-items: center; font-size: 15px; }
.auth-points span { width: 30px; height: 30px; border-radius: 9px; background: rgba(255, 255, 255, .16); display: grid; place-items: center; flex: none; }
.auth-side { display: flex; align-items: center; justify-content: center; padding: 32px 20px; }
.auth-card { width: 100%; max-width: 400px; }
.auth-card h1 { margin-bottom: 6px; }
.auth-card .sub { color: var(--muted); margin: 0 0 24px; }
.tabs { display: flex; gap: 4px; padding: 4px; background: var(--line-2); border-radius: 12px; margin-bottom: 22px; }
.tabs button { flex: 1; justify-content: center; border: 0; box-shadow: none; background: transparent; color: var(--muted); }
.tabs button.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }
.auth-card form button.primary { width: 100%; justify-content: center; padding: 12px; font-size: 15px; margin-top: 6px; }

/* ===== Shell ===== */
.shell { display: grid; grid-template-columns: var(--side-w) 1fr; min-height: 100vh; background: linear-gradient(to left, var(--side-bg) var(--side-w), var(--bg) var(--side-w)); }
.nav { background: var(--side-bg); color: var(--side-ink); padding: 20px 14px; display: flex; flex-direction: column; gap: 2px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 22px; color: var(--side-ink-strong); }
.brand-mark { width: 36px; height: 36px; border-radius: 11px; background: var(--grad); display: grid; place-items: center; box-shadow: 0 6px 18px -6px rgba(109, 94, 252, .8); flex: none; }
.brand-name { font-weight: 800; font-size: 16px; line-height: 1.2; }
.brand-sub { font-size: 12px; color: var(--side-ink); opacity: .75; }
.nav-group { font-size: 11.5px; letter-spacing: .06em; color: var(--side-ink); opacity: .55; padding: 14px 12px 6px; font-weight: 700; }
.nav nav a { display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: 10px; color: var(--side-ink); font-size: 14.5px; font-weight: 500; position: relative; }
.nav nav a:hover { background: var(--side-hover); color: var(--side-ink-strong); text-decoration: none; }
.nav nav a.active { background: var(--side-active); color: var(--side-ink-strong); font-weight: 700; }
.nav nav a.active::before { content: ""; position: absolute; right: -14px; top: 8px; bottom: 8px; width: 3px; border-radius: 3px 0 0 3px; background: #8b80ff; }
.nav-foot { margin-top: auto; padding-top: 14px; border-top: 1px solid rgba(255, 255, 255, .08); display: flex; align-items: center; gap: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: rgba(255, 255, 255, .1); color: #fff; display: grid; place-items: center; font-weight: 700; flex: none; }
.who { flex: 1; min-width: 0; font-size: 13px; }
.who b { display: block; color: var(--side-ink-strong); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; opacity: .7; direction: ltr; text-align: right; }
.nav-foot button { background: transparent; border: 0; box-shadow: none; color: var(--side-ink); padding: 8px; }
.nav-foot button:hover { background: var(--side-hover); color: #fff; }
.topbar { display: none; }
main { padding: 32px 40px 64px; max-width: 1180px; width: 100%; }

/* ===== Page parts ===== */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-head p { margin: 6px 0 0; color: var(--muted); }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 22px; box-shadow: var(--shadow); }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.grid-2 { display: grid; gap: 16px; grid-template-columns: 2fr 1fr; }

/* Stats */
.stat { display: flex; flex-direction: column; gap: 4px; position: relative; overflow: hidden; }
.stat .ico { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); margin-bottom: 10px; }
.stat .ico.good { background: var(--good-soft); color: var(--good); }
.stat .ico.warn { background: var(--warn-soft); color: var(--warn); }
.stat .ico.info { background: var(--info-soft); color: var(--info); }
.stat .n { font-size: 28px; font-weight: 800; letter-spacing: -.02em; line-height: 1.1; }
.stat .l { color: var(--muted); font-size: 13.5px; }
.meter { height: 8px; background: var(--line-2); border-radius: 99px; overflow: hidden; margin-top: 10px; }
.meter i { display: block; height: 100%; background: var(--grad); border-radius: 99px; }

/* Chart */
.chart-card h3 { margin: 0; font-size: 16px; }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-left: 6px; vertical-align: -1px; }
.chart { width: 100%; height: auto; display: block; margin-top: 12px; direction: ltr; }
.chart text { fill: var(--muted); font-size: 11px; font-family: inherit; }
.chart .grid-line { stroke: var(--line-2); }
.chart .bar-sent { fill: var(--brand); opacity: .85; }
.chart .bar-sent:hover { opacity: 1; }
.chart .bar-problem { fill: var(--bad); }
.chart .line-open { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot-open { fill: var(--surface); stroke: var(--accent); stroke-width: 2; }

/* Steps (onboarding) */
.steps { display: grid; gap: 10px; }
.step { display: flex; gap: 12px; align-items: flex-start; padding: 12px; border-radius: 12px; border: 1px solid var(--line-2); background: var(--surface-2); }
.step .num { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; font-weight: 700; background: var(--line); color: var(--ink-2); flex: none; }
.step.done .num { background: var(--good); color: #fff; }
.step b { display: block; font-size: 14px; }
.step small { font-size: 12.5px; }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
.table-wrap table { border: 0; }
th, td { text-align: right; padding: 13px 16px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
th { font-size: 12.5px; color: var(--muted); font-weight: 600; background: var(--surface-2); letter-spacing: .01em; }
tbody tr, table tr:not(:first-child) { transition: background .12s; }
table tr:not(:first-child):hover td { background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
td a { font-weight: 600; }
td.ltr, .ltr { direction: ltr; text-align: left; font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 12.5px; word-break: break-all; }
th.ltr { font-family: inherit; }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 600; background: var(--line-2); color: var(--ink-2); white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--info-soft); color: var(--info); }

/* Empty state */
.empty { text-align: center; padding: 48px 20px; border: 1.5px dashed var(--line); border-radius: var(--r-lg); background: var(--surface); }
.empty .ico { width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center; margin: 0 auto 14px; background: var(--brand-soft); color: var(--brand); }
.empty b { display: block; font-size: 16px; margin-bottom: 4px; }
.empty p { color: var(--muted); margin: 0 auto 16px; max-width: 420px; }

/* Banners, modal, toast */
.banner { display: flex; gap: 10px; align-items: flex-start; padding: 14px 16px; border-radius: var(--r); margin-bottom: 20px; background: var(--warn-soft); color: var(--warn); font-weight: 500; }
.modal { position: fixed; inset: 0; background: rgba(10, 12, 28, .45); backdrop-filter: blur(6px); display: flex; align-items: flex-start; justify-content: center; padding: 56px 16px; overflow-y: auto; z-index: 30; animation: fade .15s ease; }
.modal-card { width: 100%; max-width: 620px; box-shadow: var(--shadow-lg); animation: pop .18s ease; }
.modal-card h2 { margin-top: 0; }
.toast { position: fixed; bottom: 24px; left: 24px; display: flex; gap: 10px; align-items: center; background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 12px; z-index: 40; box-shadow: var(--shadow-lg); font-weight: 500; animation: rise .2s ease; }
.copy { font-size: 12px; padding: 3px 10px; margin-inline-start: 6px; border-radius: 7px; box-shadow: none; }
.keybox { padding: 16px; background: var(--brand-soft); border: 1px solid transparent; border-radius: var(--r); }
.keybox .ltr { font-size: 14px; color: var(--ink); }
iframe { box-shadow: var(--shadow); }
.loading { display: flex; gap: 10px; align-items: center; color: var(--muted); padding: 40px 0; }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2.5px solid var(--line); border-top-color: var(--brand); animation: spin .7s linear infinite; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
#view > * { animation: rise .25s ease both; }

/* ===== Mobile ===== */
@media (max-width: 900px) {
  .auth { grid-template-columns: 1fr; }
  .auth-hero { padding: 32px 24px; }
  .auth-hero h2 { font-size: 28px; }
  .auth-points { display: none; }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 800px) {
  .shell { grid-template-columns: 1fr; }
  .nav { position: fixed; inset: 0 0 0 auto; width: 280px; z-index: 25; transform: translateX(100%); transition: transform .2s ease; box-shadow: var(--shadow-lg); }
  .shell.menu-open .nav { transform: none; }
  .shell.menu-open::after { content: ""; position: fixed; inset: 0; background: rgba(10, 12, 28, .45); z-index: 20; }
  .topbar { display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
  .topbar b { flex: 1; }
  main { padding: 20px 16px 48px; }
  .shell { background: var(--bg); }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .stat { padding: 16px; }
  .stat .n { font-size: 22px; }
  .stat .ico { width: 34px; height: 34px; margin-bottom: 6px; }
  h1 { font-size: 22px; }
  th, td { padding: 11px 12px; }
}

/* Views without a page-head */
#view > h1 { margin-bottom: 20px; }
#view > h1 + p.muted { margin: -12px 0 20px; }
#view > form.card, #view > .card.row { margin-bottom: 16px; }
.page-head h1 small { font-size: 15px; font-weight: 500; color: var(--muted); }
.page-head > .row { gap: 8px; }
.auth-hero small { color: rgba(255, 255, 255, .8); }
