/* Sparring design system: tokens, shell, components. Module CSS lives in /css/<module>.css.
   Fonts: Inter when it is installed, else the system UI font. Nothing is loaded from a CDN.
   A custom workspace accent overrides the --accent* and --hero-* tokens from public/lib/brand.js. */
:root {
  --bg: #ffffff; --bg-soft: #f8fafc; --bg-sunk: #f1f5f9; --surface: #ffffff;
  --border: #e5e7eb; --border-strong: #cbd5e1;
  --text: #0f172a; --text-2: #475569; --text-3: #5b6779;
  --accent: #2563eb; --accent-text: #1d4ed8; --accent-soft: #eff6ff; --accent-ring: #93c5fd; --on-accent: #ffffff;
  --good: #047857; --good-soft: #ecfdf5; --warn: #b45309; --warn-soft: #fffbeb; --bad: #b91c1c; --bad-soft: #fef2f2;
  /* fills that carry white text (>= 4.5:1); --bad / --accent-text are tuned as text colours */
  --accent-fill: #2563eb; --bad-fill: #b91c1c;
  --btn: #0f172a; --btn-text: #ffffff;
  --hero-a: #1d4ed8; --hero-b: #38bdf8;
  --shadow: 0 1px 2px rgb(15 23 42 / .05), 0 8px 24px rgb(15 23 42 / .06);
  --radius: 14px; --sidebar: 248px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0f17; --bg-soft: #111827; --bg-sunk: #0f1623; --surface: #111827;
    --border: #1f2937; --border-strong: #374151;
    --text: #f1f5f9; --text-2: #cbd5e1; --text-3: #94a3b8;
    --accent: #2563eb; --accent-text: #93c5fd; --accent-soft: #172554; --accent-ring: #1d4ed8; --on-accent: #ffffff;
    --good: #34d399; --good-soft: #052e22; --warn: #fbbf24; --warn-soft: #2b1d05; --bad: #f87171; --bad-soft: #2d0b0b;
    --accent-fill: #2563eb; --bad-fill: #dc2626;
    --btn: #f8fafc; --btn-text: #0b0f17; --hero-a: #1e3a8a; --hero-b: #0369a1;
    --shadow: 0 1px 2px rgb(0 0 0 / .4), 0 8px 24px rgb(0 0 0 / .3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b0f17; --bg-soft: #111827; --bg-sunk: #0f1623; --surface: #111827;
  --border: #1f2937; --border-strong: #374151;
  --text: #f1f5f9; --text-2: #cbd5e1; --text-3: #94a3b8;
  --accent: #2563eb; --accent-text: #93c5fd; --accent-soft: #172554; --accent-ring: #1d4ed8; --on-accent: #ffffff;
  --good: #34d399; --good-soft: #052e22; --warn: #fbbf24; --warn-soft: #2b1d05; --bad: #f87171; --bad-soft: #2d0b0b;
  --accent-fill: #2563eb; --bad-fill: #dc2626;
  --btn: #f8fafc; --btn-text: #0b0f17; --hero-a: #1e3a8a; --hero-b: #0369a1;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent-text); }
h1, h2, h3, h4 { margin: 0; letter-spacing: -0.02em; line-height: 1.25; }
p { margin: 0; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em; background: var(--bg-sunk); padding: 1px 5px; border-radius: 5px; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--text-3); font-size: 13px; }
.pad { padding: 16px; }
.center-pad { display: grid; place-items: center; padding: 64px 16px; text-align: center; gap: 12px; }
svg { width: 18px; height: 18px; flex: none; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; overflow-y: auto; border-right: 1px solid var(--border); background: var(--bg-soft); display: flex; flex-direction: column; padding: 14px 12px; gap: 4px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); padding: 6px 8px 14px; min-width: 0; }
.brand img { width: 28px; height: 28px; border-radius: 8px; object-fit: contain; flex: none; }
.brand-name { font-weight: 800; font-size: 18px; letter-spacing: -0.03em; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.skip-link { position: absolute; left: 8px; top: -60px; z-index: 100; background: var(--surface); color: var(--accent-text); border: 1px solid var(--border-strong); padding: 8px 14px; border-radius: 10px; font-weight: 600; text-decoration: none; box-shadow: var(--shadow); }
.skip-link:focus { top: 8px; }
.nav-group { margin-top: 10px; }
.nav-group-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); padding: 6px 10px; }
.nav-link { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; color: var(--text-2); text-decoration: none; font-weight: 500; font-size: 14px; }
.nav-link:hover { background: var(--bg-sunk); color: var(--text); }
.nav-link[aria-current="page"] { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.nav-link .badge { margin-left: auto; }
.sidebar-foot { margin-top: auto; border-top: 1px solid var(--border); padding-top: 10px; display: flex; align-items: center; gap: 10px; }
.sidebar-foot .who { flex: 1; min-width: 0; }
.sidebar-foot .who b { display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.main { min-width: 0; }
.main-inner { max-width: 1200px; margin: 0 auto; padding: 28px 28px 72px; }
.topbar { display: none; }
.scrim { display: none; }
@media (max-width: 999px) {
  .shell { grid-template-columns: 1fr; }
  /* closed drawer: off-screen AND hidden, so its links aren't invisible Tab stops (visibility waits for the slide) */
  .sidebar { position: fixed; z-index: 40; left: 0; top: 0; width: min(300px, 86vw); transform: translateX(-100%); visibility: hidden; transition: transform .2s ease, visibility 0s linear .2s; box-shadow: var(--shadow); }
  .shell.nav-open .sidebar { transform: none; visibility: visible; transition: transform .2s ease; }
  .shell.nav-open .scrim { display: block; position: fixed; inset: 0; z-index: 35; background: rgb(0 0 0 / .35); }
  .topbar { display: flex; position: sticky; top: 0; z-index: 30; align-items: center; gap: 10px; height: 56px; padding: 0 12px; min-width: 0; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); }
  .main-inner { padding: 18px 16px 64px; }
}
.banner { margin-bottom: 16px; padding: 12px 16px; border-radius: 12px; background: var(--warn-soft); color: var(--warn); font-size: 14px; border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent); }

/* ---------- page pieces ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { font-size: 26px; font-weight: 800; }
.page-head p { margin-top: 4px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; }
.card.soft { background: var(--bg-soft); }
.card h3 { font-size: 16px; font-weight: 700; margin-bottom: 8px; }
.card p { color: var(--text-2); }
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(min(100%, 360px), 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: grid; gap: 12px; }
.divider { height: 1px; background: var(--border); margin: 16px 0; }
.empty-state { text-align: center; padding: 48px 20px; border: 1px dashed var(--border-strong); border-radius: var(--radius); color: var(--text-2); display: grid; gap: 8px; justify-items: center; }
.empty-state svg { width: 32px; height: 32px; color: var(--text-3); }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 9px 15px; border-radius: 11px; border: 1px solid var(--border-strong); background: var(--surface); font-weight: 600; font-size: 14px; text-decoration: none; color: var(--text); white-space: nowrap; }
.btn:hover { border-color: var(--accent-ring); }
.btn.primary { background: var(--btn); color: var(--btn-text); border-color: var(--btn); }
.btn.danger { background: var(--bad-fill); color: #fff; border-color: var(--bad-fill); }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 9px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.icon-btn { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; border: 0; background: transparent; color: var(--text-2); }
.icon-btn:hover { background: var(--bg-sunk); color: var(--text); }
.linkbtn { background: none; border: 0; color: var(--accent-text); font-weight: 600; font-size: 13px; padding: 4px; }

/* ---------- chips, tags, badges ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 7px; padding: 8px 14px; border-radius: 12px; font-size: 14px; font-weight: 500; border: 1px solid var(--border-strong); background: var(--surface); }
.chip svg { width: 16px; height: 16px; color: var(--text-2); }
.chip:hover { border-color: var(--accent-ring); }
.chip[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-text); box-shadow: 0 0 0 1px var(--accent) inset; }
.chip[aria-pressed="true"] svg { color: var(--accent-text); }
.chip[disabled] { opacity: .5; cursor: not-allowed; border-style: dashed; }
.tag { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px; background: var(--bg-sunk); border: 1px solid var(--border); color: var(--text-2); white-space: nowrap; }
.badge { font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 999px; background: var(--accent-fill); color: var(--on-accent); }
.ai-badge { font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 6px; background: #0f766e; color: #fff; letter-spacing: .02em; }
.pill { font-size: 12px; font-weight: 700; padding: 2px 9px; border-radius: 999px; white-space: nowrap; display: inline-flex; align-items: center; gap: 4px; }
.pill.good, .good-text { color: var(--good); } .pill.good { background: var(--good-soft); }
.pill.warn { background: var(--warn-soft); color: var(--warn); } .pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.neutral { background: var(--bg-sunk); color: var(--text-2); }

/* ---------- avatars ---------- */
.avatar { --size: 46px; width: var(--size); height: var(--size); border-radius: 50%; display: inline-grid; place-items: center; flex: none; overflow: hidden;
  font-weight: 700; font-size: calc(var(--size) * .36); color: #fff; letter-spacing: -0.02em;
  background: linear-gradient(135deg, hsl(var(--h) 62% 48%), hsl(calc(var(--h) + 40) 62% 34%)); }
.avatar img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- forms ---------- */
.form-grid { display: grid; gap: 14px 16px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }
.field { display: grid; gap: 6px; min-width: 0; }
.field-label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.field-hint { font-size: 12px; color: var(--text-3); font-weight: 400; }
input[type=text], input[type=email], input[type=number], input[type=url], input[type=search], input[type=date], input[type=datetime-local], input[type=password], input:not([type]), select, textarea {
  width: 100%; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); min-width: 0; }
textarea { resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; }
.check input { margin-top: 3px; width: 16px; height: 16px; accent-color: var(--accent); }
.check .field-hint { display: block; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin: 0; min-width: 0; }
legend { font-weight: 700; padding: 0 6px; }
.search { position: relative; }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--text-3); }
.search input { padding-left: 36px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--text-3); padding: 10px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--bg-soft); }
.table td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.link-row { cursor: pointer; } .link-row:hover td { background: var(--bg-soft); }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.tab { display: inline-flex; align-items: center; gap: 6px; padding: 9px 14px; border: 0; background: none; color: var(--text-2); font-weight: 600; font-size: 14px; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab[aria-selected="true"] { color: var(--accent-text); border-bottom-color: var(--accent); }
.tab .count { font-size: 12px; color: var(--text-3); }

/* ---------- modal & toast ---------- */
dialog.modal { border: 0; padding: 0; border-radius: 18px; background: var(--surface); color: var(--text); width: min(560px, calc(100vw - 24px)); box-shadow: 0 24px 60px rgb(0 0 0 / .3); }
dialog.modal.wide { width: min(880px, calc(100vw - 24px)); }
dialog.modal::backdrop { background: rgb(15 23 42 / .45); }
.modal-inner { display: flex; flex-direction: column; max-height: min(86vh, 900px); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px 8px; }
.modal-head h2 { font-size: 18px; }
.modal-body { padding: 8px 18px 16px; overflow-y: auto; display: grid; gap: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #0f172a; color: #fff; padding: 12px 18px; border-radius: 12px; font-size: 14px; z-index: 100; max-width: min(560px, calc(100vw - 32px)); box-shadow: 0 10px 30px rgb(0 0 0 / .25); }
.toast.err { background: #b91c1c; }
.spinner { width: 38px; height: 38px; border-radius: 50%; border: 4px solid var(--border); border-top-color: var(--accent); animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- metrics & score ---------- */
.metrics { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.metric { border: 1px solid var(--border); border-radius: 12px; padding: 10px 12px; background: var(--bg-soft); }
.metric .v { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.metric .k { font-size: 12px; color: var(--text-2); font-weight: 600; }
.metric .t { font-size: 11px; color: var(--text-3); }
.metric.ok .v, .good { color: var(--good); } .metric.meh .v, .warn { color: var(--warn); } .metric.bad .v, .bad { color: var(--bad); }
.bar:not(rect) { height: 6px; border-radius: 6px; background: var(--border); overflow: hidden; flex: 1; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 6px; }

/* ---------- sign-in ---------- */
.signin { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(600px 300px at 50% 0%, var(--accent-soft), transparent 70%), var(--bg); }
.signin-card { width: min(420px, 100%); text-align: center; display: grid; gap: 16px; padding: 36px 28px; border: 1px solid var(--border); border-radius: 22px; background: var(--surface); box-shadow: var(--shadow); }
.signin-card img { width: 52px; height: 52px; margin: 0 auto; border-radius: 14px; }
.btn-lark { display: inline-flex; align-items: center; justify-content: center; gap: 10px; padding: 13px 18px; border-radius: 12px; background: #3370ff; color: #fff; font-weight: 700; text-decoration: none; font-size: 15px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}
