/* =========================================================================
   CommonRoom AI — Operations Console
   Design system. Mobile-first; the desktop layout is a progressive upgrade.
   Chart colours are the validated purple ordinal ramp + the reserved status
   palette (status colours always ship with an icon and a label, never alone).
   ========================================================================= */

/* ------------------------------------------------------------------ tokens */
:root {
  color-scheme: light;

  /* brand — purple, per the product's purple-themed experience */
  --b-50:  #f6f3ff;
  --b-100: #ede7ff;
  --b-200: #ddd2ff;
  --b-300: #c3aefd;
  --b-400: #a17ef9;
  --b-500: #8250ee;
  --b-600: #6f36e0;
  --b-700: #5c27c2;
  --b-800: #4a1f9c;
  --b-900: #331466;

  /* surfaces & ink */
  --plane:        #f4f3f7;
  --surface:      #ffffff;
  --surface-2:    #faf9fd;
  --surface-sunk: #f0eef6;
  --ink:          #17151f;
  --ink-2:        #56526a;
  --ink-3:        #837e97;
  --line:         #e5e2ee;
  --line-strong:  #d3cfe2;
  --ring:         rgba(23,21,31,.08);

  /* validated ordinal ramp (light, surface #ffffff) */
  --viz-1: #b49bfc;
  --viz-2: #9b7bf8;
  --viz-3: #8250ee;
  --viz-4: #6429ce;
  --viz-track: #ece9f6;

  /* reserved status palette */
  --good:     #0ca30c;
  --warning:  #fab219;
  --serious:  #ec835a;
  --critical: #d03b3b;
  --info:     #2a78d6;
  --good-ink:     #046104;
  --warning-ink:  #7a5300;
  --serious-ink:  #94441f;
  --critical-ink: #9e2020;
  --info-ink:     #1a4f8f;

  --good-bg:     #e8f6e8;
  --warning-bg:  #fdf3dc;
  --serious-bg:  #fdeee7;
  --critical-bg: #fbe9e9;
  --info-bg:     #e8f1fc;
  --neutral-bg:  #efedf5;

  --r-sm: 8px; --r: 12px; --r-lg: 16px; --r-xl: 22px;
  --sh-1: 0 1px 2px rgba(23,21,31,.06), 0 1px 1px rgba(23,21,31,.04);
  --sh-2: 0 4px 16px rgba(23,21,31,.08), 0 1px 3px rgba(23,21,31,.05);
  --sh-3: 0 18px 48px rgba(23,21,31,.18), 0 2px 8px rgba(23,21,31,.08);

  --nav-h: 62px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
html[data-theme="dark"] {
  color-scheme: dark;
  --plane:        #0c0b10;
  --surface:      #17161c;
  --surface-2:    #1e1d25;
  --surface-sunk: #121118;
  --ink:          #f7f5ff;
  --ink-2:        #b6b1c9;
  --ink-3:        #837e97;
  --line:         #2a2833;
  --line-strong:  #3a3746;
  --ring:         rgba(255,255,255,.10);

  --viz-1: #ddd6fe;
  --viz-2: #a78bfa;
  --viz-3: #8b5cf6;
  --viz-4: #7c3aed;
  --viz-track: #26232f;

  --good-ink:     #4bc94b;
  --warning-ink:  #f5c04a;
  --serious-ink:  #f0a184;
  --critical-ink: #ef6d6d;
  --info-ink:     #6ba6ea;

  --good-bg:     #122b12;
  --warning-bg:  #2e2410;
  --serious-bg:  #2f1d15;
  --critical-bg: #2e1414;
  --info-bg:     #12233a;
  --neutral-bg:  #22202b;

  --sh-1: 0 1px 2px rgba(0,0,0,.5);
  --sh-2: 0 4px 16px rgba(0,0,0,.5);
  --sh-3: 0 18px 48px rgba(0,0,0,.6);
}

/* -------------------------------------------------------------- base reset */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; font-family: var(--font);
  background: var(--plane); color: var(--ink);
  -webkit-font-smoothing: antialiased;
  font-size: 15px; line-height: 1.5;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--b-600); text-decoration: none; }
a:hover { text-decoration: underline; }
html[data-theme="dark"] a { color: var(--b-300); }
h1,h2,h3,h4 { margin: 0; font-weight: 650; letter-spacing: -.015em; line-height: 1.25; }
h1 { font-size: 24px; } h2 { font-size: 18px; } h3 { font-size: 15px; }
p { margin: 0 0 10px; }
::selection { background: var(--b-200); color: var(--b-900); }
:focus-visible { outline: 2px solid var(--b-500); outline-offset: 2px; border-radius: 6px; }

.tnum { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: .9em; }
.muted { color: var(--ink-3); }
.dim { color: var(--ink-2); }
.small { font-size: 13px; }
.xs { font-size: 12px; }
.strong { font-weight: 650; }
.center { text-align: center; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hide { display: none !important; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.between { justify-content: space-between; }
.col { display: flex; flex-direction: column; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.gap-4 { gap: 4px; } .gap-6 { gap: 6px; } .gap-8 { gap: 8px; } .gap-16 { gap: 16px; }
.mt-4{margin-top:4px}.mt-8{margin-top:8px}.mt-12{margin-top:12px}.mt-16{margin-top:16px}.mt-24{margin-top:24px}
.mb-8{margin-bottom:8px}.mb-12{margin-bottom:12px}.mb-16{margin-bottom:16px}

/* ------------------------------------------------------------- app shell */
#app { min-height: 100%; }
.shell { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px calc(10px + env(safe-area-inset-top, 0px));
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line);
}
.topbar .title { font-size: 17px; font-weight: 680; letter-spacing: -.02em; }
.topbar .sub { font-size: 12px; color: var(--ink-3); margin-top: -2px; }

.brandmark {
  width: 34px; height: 34px; border-radius: 10px; flex: 0 0 34px;
  background: linear-gradient(145deg, var(--b-500), var(--b-700));
  display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 15px;
  box-shadow: 0 2px 8px rgba(111,54,224,.35);
}

.main { flex: 1; padding: 14px 14px calc(var(--nav-h) + var(--safe-b) + 24px); }
.page-head { margin-bottom: 14px; }
.page-head h1 { font-size: 22px; }
.page-head .lede { color: var(--ink-2); font-size: 13.5px; margin-top: 4px; }

/* bottom nav (mobile) */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(180%) blur(16px);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.tabbar button {
  background: none; border: 0; padding: 8px 2px 9px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  color: var(--ink-3); font-size: 10.5px; font-weight: 560; letter-spacing: .01em;
  min-height: var(--nav-h);
  justify-content: center;
}
.tabbar button .ic { font-size: 19px; line-height: 1; }
.tabbar button[aria-current="page"] { color: var(--b-600); }
html[data-theme="dark"] .tabbar button[aria-current="page"] { color: var(--b-300); }
.tabbar button[aria-current="page"] .ic { transform: translateY(-1px); }

.sidebar { display: none; }

/* ------------------------------------------------------------------ cards */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); box-shadow: var(--sh-1);
}
.card + .card { margin-top: 12px; }
.card-head { padding: 14px 16px 0; display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.card-head h2, .card-head h3 { font-size: 14.5px; font-weight: 650; }
.card-head .hint { font-size: 12.5px; color: var(--ink-3); margin-top: 3px; }
.card-body { padding: 14px 16px; }
.card-foot { padding: 12px 16px; border-top: 1px solid var(--line); background: var(--surface-2); border-radius: 0 0 var(--r-lg) var(--r-lg); }
.section-title { font-size: 12px; font-weight: 680; letter-spacing: .07em; text-transform: uppercase; color: var(--ink-3); margin: 22px 0 10px; }
.section-title:first-child { margin-top: 0; }

/* ------------------------------------------------------------------- grid */
.grid { display: grid; gap: 12px; }
.g2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.g3 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.g4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.g3.compact { grid-template-columns: repeat(3, minmax(0,1fr)); }
.g3.compact .stat { padding: 10px 9px; }
.g3.compact .val { font-size: 17px; letter-spacing: -.02em; }
.g3.compact .lab { font-size: 10.5px; }

/* ------------------------------------------------------------- stat tiles */
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  padding: 12px 13px; box-shadow: var(--sh-1); min-width: 0;
}
.stat .lab { font-size: 11.5px; color: var(--ink-3); font-weight: 560; letter-spacing: .01em; display: flex; align-items: center; gap: 5px; }
.stat .val { font-size: 23px; font-weight: 690; letter-spacing: -.03em; margin-top: 3px; font-variant-numeric: tabular-nums; }
.stat .val.sm { font-size: 19px; }
.stat .sub { font-size: 11.5px; color: var(--ink-3); margin-top: 2px; }
.stat.accent { background: linear-gradient(150deg, var(--b-600), var(--b-800)); border-color: transparent; color: #fff; }
.stat.accent .lab, .stat.accent .sub { color: rgba(255,255,255,.78); }

/* ------------------------------------------------------------------ badge */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 620;
  background: var(--neutral-bg); color: var(--ink-2); white-space: nowrap;
}
.badge .dot { font-size: 10px; line-height: 1; }
.badge.good     { background: var(--good-bg);     color: var(--good-ink); }
.badge.warning  { background: var(--warning-bg);  color: var(--warning-ink); }
.badge.serious  { background: var(--serious-bg);  color: var(--serious-ink); }
.badge.critical { background: var(--critical-bg); color: var(--critical-ink); }
.badge.info     { background: var(--info-bg);     color: var(--info-ink); }
.badge.brand    { background: var(--b-100); color: var(--b-700); }
html[data-theme="dark"] .badge.brand { background: #241a3d; color: var(--b-300); }
.badge.lg { font-size: 12.5px; padding: 5px 11px; }

/* ---------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  padding: 9px 14px; border-radius: 10px; font-size: 14px; font-weight: 600;
  min-height: 40px; transition: transform .06s ease, background .12s ease, border-color .12s ease;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.985); }
.btn[disabled] { opacity: .45; pointer-events: none; }
.btn.primary { background: var(--b-600); border-color: var(--b-600); color: #fff; box-shadow: 0 1px 3px rgba(111,54,224,.35); }
.btn.primary:hover { background: var(--b-700); border-color: var(--b-700); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--surface-sunk); }
.btn.danger { color: var(--critical-ink); border-color: color-mix(in srgb, var(--critical) 35%, transparent); }
.btn.danger:hover { background: var(--critical-bg); }
.btn.sm { padding: 6px 11px; min-height: 32px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

.fab {
  position: fixed; right: 16px; bottom: calc(var(--nav-h) + var(--safe-b) + 16px); z-index: 45;
  width: 54px; height: 54px; border-radius: 18px; border: 0;
  background: var(--b-600); color: #fff; font-size: 26px; line-height: 1;
  box-shadow: 0 8px 24px rgba(111,54,224,.42);
  display: grid; place-items: center;
}
.fab:active { transform: scale(.94); }

/* ----------------------------------------------------------------- inputs */
.field { display: block; margin-bottom: 14px; }
.field > .lab { display: block; font-size: 12.5px; font-weight: 620; color: var(--ink-2); margin-bottom: 5px; }
.field > .hint { font-size: 12px; color: var(--ink-3); margin-top: 5px; }
.input, .select, .textarea {
  width: 100%; background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: 10px; padding: 10px 12px; font-size: 15px; min-height: 42px;
  transition: border-color .12s ease, box-shadow .12s ease;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--b-500); box-shadow: 0 0 0 3px color-mix(in srgb, var(--b-500) 18%, transparent);
}
.textarea { min-height: 120px; resize: vertical; font-family: var(--mono); font-size: 13px; line-height: 1.55; }
.select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--ink-3) 50%), linear-gradient(135deg, var(--ink-3) 50%, transparent 50%); background-position: calc(100% - 17px) 18px, calc(100% - 12px) 18px; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 34px; }
.inline-fields { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
.checkline { display: flex; gap: 10px; align-items: flex-start; padding: 9px 0; }
.checkline input[type=checkbox] { width: 19px; height: 19px; accent-color: var(--b-600); margin-top: 1px; flex: 0 0 auto; }

.segmented { display: inline-flex; background: var(--surface-sunk); border-radius: 10px; padding: 3px; gap: 2px; overflow-x: auto; max-width: 100%; }
.segmented button { border: 0; background: none; padding: 7px 13px; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--ink-2); white-space: nowrap; }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--sh-1); }

.chiprow { display: flex; gap: 7px; overflow-x: auto; padding-bottom: 4px; margin: 0 -14px; padding-left: 14px; padding-right: 14px; scrollbar-width: none; }
.chiprow::-webkit-scrollbar { display: none; }
.chip { border: 1px solid var(--line-strong); background: var(--surface); border-radius: 999px; padding: 6px 13px; font-size: 13px; font-weight: 580; white-space: nowrap; color: var(--ink-2); }
.chip[aria-pressed="true"] { background: var(--b-600); border-color: var(--b-600); color: #fff; }

/* ---------------------------------------------------------------- avatars */
.av {
  width: 34px; height: 34px; border-radius: 11px; flex: 0 0 auto;
  display: grid; place-items: center; font-size: 12.5px; font-weight: 700; color: #fff;
  background: var(--b-600); letter-spacing: .02em;
}
.av.sm { width: 26px; height: 26px; border-radius: 9px; font-size: 10.5px; }
.av.lg { width: 52px; height: 52px; border-radius: 16px; font-size: 18px; }
.av.ghost { background: var(--surface-sunk); color: var(--ink-3); border: 1px dashed var(--line-strong); }

/* ------------------------------------------------------------------ lists */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { border-top: 1px solid var(--line); }
.list > li:first-child { border-top: 0; }
.row-item {
  display: flex; align-items: center; gap: 11px; width: 100%;
  padding: 12px 16px; background: none; border: 0; text-align: left; min-height: 60px;
}
.row-item:hover { background: var(--surface-2); }
.row-item .t { font-size: 14px; font-weight: 600; line-height: 1.35; }
.row-item .s { font-size: 12.5px; color: var(--ink-3); margin-top: 2px; display: flex; gap: 7px; align-items: center; flex-wrap: wrap; }
.row-item .chev { color: var(--ink-3); font-size: 17px; flex: 0 0 auto; }

.empty { text-align: center; padding: 34px 20px; color: var(--ink-3); }
.empty .ic { font-size: 32px; opacity: .5; }
.empty .t { font-weight: 620; color: var(--ink-2); margin-top: 8px; font-size: 14.5px; }
.empty .s { font-size: 13px; margin-top: 4px; }

/* ------------------------------------------------------------------- meter */
.meter { height: 8px; border-radius: 99px; background: var(--viz-track); overflow: hidden; display: flex; }
.meter > span { display: block; height: 100%; }
.meter > span + span { box-shadow: -2px 0 0 var(--surface); }
.meter .m-spent { background: var(--viz-4); }
.meter .m-committed { background: var(--viz-2); }
.meter .m-over { background: var(--critical); }
.meter.thin { height: 6px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--ink-2); }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: 5px; vertical-align: -1px; }

/* progress ring */
.ring { --p: 0; width: 42px; height: 42px; border-radius: 50%; flex: 0 0 auto;
  background: conic-gradient(var(--viz-4) calc(var(--p) * 1%), var(--viz-track) 0);
  display: grid; place-items: center; position: relative; }
.ring::after { content: ""; position: absolute; inset: 4px; border-radius: 50%; background: var(--surface); }
.ring b { position: relative; z-index: 1; font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------ table */
.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.tbl th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); font-weight: 680; padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.tbl td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.tbl tr:last-child td { border-bottom: 0; }
table.tbl td.num, table.tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.tbl tbody tr:hover { background: var(--surface-2); }

/* ------------------------------------------------------------------ sheet */
.scrim { position: fixed; inset: 0; background: rgba(12,11,16,.55); z-index: 60; animation: fade .16s ease; }
@keyframes fade { from { opacity: 0 } }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 61;
  background: var(--surface); border-radius: 22px 22px 0 0;
  max-height: 92dvh; display: flex; flex-direction: column;
  box-shadow: var(--sh-3); animation: up .22s cubic-bezier(.22,1,.36,1);
}
@keyframes up { from { transform: translateY(18px); opacity: .6 } }
.sheet-grip { width: 38px; height: 4px; border-radius: 99px; background: var(--line-strong); margin: 9px auto 3px; flex: 0 0 auto; }
.sheet-head { padding: 6px 16px 12px; border-bottom: 1px solid var(--line); display: flex; align-items: flex-start; gap: 10px; flex: 0 0 auto; }
.sheet-head h2 { font-size: 17px; }
.sheet-head .hint { font-size: 12.5px; color: var(--ink-3); margin-top: 3px; }
.sheet-body { padding: 16px; overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; }
.sheet-foot { padding: 12px 16px calc(12px + var(--safe-b)); border-top: 1px solid var(--line); display: flex; gap: 9px; background: var(--surface-2); flex: 0 0 auto; }
.sheet-foot .btn { flex: 1; }
.x-btn { border: 0; background: var(--surface-sunk); width: 32px; height: 32px; border-radius: 50%; color: var(--ink-2); font-size: 17px; display: grid; place-items: center; flex: 0 0 auto; }

/* ------------------------------------------------------------------- misc */
.callout { border-radius: var(--r); padding: 12px 14px; font-size: 13px; line-height: 1.5; border: 1px solid transparent; }
.callout.info    { background: var(--info-bg); color: var(--info-ink); border-color: color-mix(in srgb, var(--info) 22%, transparent); }
.callout.warn    { background: var(--warning-bg); color: var(--warning-ink); border-color: color-mix(in srgb, var(--warning) 30%, transparent); }
.callout.danger  { background: var(--critical-bg); color: var(--critical-ink); border-color: color-mix(in srgb, var(--critical) 25%, transparent); }
.callout.brand   { background: var(--b-50); color: var(--b-800); border-color: var(--b-200); }
html[data-theme="dark"] .callout.brand { background: #1b1430; color: var(--b-200); border-color: #2f2450; }
.callout b { font-weight: 700; }

.clause { font-size: 11px; font-weight: 640; color: var(--b-700); background: var(--b-50); border: 1px solid var(--b-200); padding: 1px 6px; border-radius: 5px; white-space: nowrap; }
html[data-theme="dark"] .clause { background: #1e1735; color: var(--b-300); border-color: #322553; }

.md { font-size: 14px; line-height: 1.62; color: var(--ink-2); }
.md h2 { font-size: 14px; margin: 16px 0 6px; color: var(--ink); }
.md h2:first-child { margin-top: 0; }
.md ul { margin: 6px 0; padding-left: 20px; }
.md li { margin: 3px 0; }
.md p { margin: 0 0 8px; }
.md code { background: var(--surface-sunk); padding: 1px 5px; border-radius: 5px; font-family: var(--mono); font-size: .88em; }

.divider { height: 1px; background: var(--line); margin: 16px 0; border: 0; }

.timeline { list-style: none; margin: 0; padding: 0 0 0 20px; position: relative; }
.timeline::before { content: ""; position: absolute; left: 5px; top: 6px; bottom: 6px; width: 2px; background: var(--line); border-radius: 2px; }
.timeline > li { position: relative; padding: 0 0 16px; }
.timeline > li::before { content: ""; position: absolute; left: -19px; top: 5px; width: 10px; height: 10px; border-radius: 50%; background: var(--viz-3); box-shadow: 0 0 0 2px var(--surface); }
.timeline > li:last-child { padding-bottom: 0; }

.bar-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: baseline; padding: 10px 0; }
.bar-row .nm { font-size: 13.5px; font-weight: 600; }
.bar-row .vl { font-size: 12.5px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.bar-row .meter { grid-column: 1 / -1; margin-top: 2px; }
.bar-row + .bar-row { border-top: 1px solid var(--line); }

.spark { display: block; width: 100%; height: 44px; overflow: visible; }
.chart { display: block; width: 100%; overflow: visible; }
.grid-line { stroke: var(--line); stroke-width: 1; }
.axis-label { fill: var(--ink-3); font-size: 10.5px; font-family: var(--font); }
.chart-tip { position: absolute; pointer-events: none; background: var(--ink); color: var(--surface); font-size: 12px; padding: 6px 9px; border-radius: 8px; box-shadow: var(--sh-2); white-space: nowrap; z-index: 5; transform: translate(-50%, -130%); }
html[data-theme="dark"] .chart-tip { background: var(--surface-2); color: var(--ink); border: 1px solid var(--line-strong); }

.toast-wrap { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + var(--safe-b) + 20px); z-index: 90; display: flex; flex-direction: column; gap: 8px; width: min(420px, calc(100vw - 28px)); }
.toast { background: var(--ink); color: var(--surface); padding: 11px 14px; border-radius: 12px; font-size: 13.5px; box-shadow: var(--sh-3); display: flex; gap: 9px; align-items: center; animation: up .2s ease; }
html[data-theme="dark"] .toast { background: var(--surface-2); color: var(--ink); border: 1px solid var(--line-strong); }
.toast.good { background: var(--good-ink); color: #fff; }
.toast.bad { background: var(--critical-ink); color: #fff; }

/* ------------------------------------------------------------------- auth */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 24px 18px; background:
  radial-gradient(1100px 520px at 12% -8%, color-mix(in srgb, var(--b-300) 34%, transparent), transparent 62%),
  radial-gradient(900px 460px at 100% 0%, color-mix(in srgb, var(--b-500) 22%, transparent), transparent 60%), var(--plane); }
.auth-card { width: min(430px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-xl); box-shadow: var(--sh-3); padding: 26px 22px; }
.auth-logo { display: flex; align-items: center; gap: 11px; margin-bottom: 18px; }
.auth-logo .brandmark { width: 42px; height: 42px; border-radius: 13px; font-size: 17px; }
.auth h1 { font-size: 20px; }
.auth .lede { color: var(--ink-2); font-size: 13.5px; margin: 4px 0 18px; }
.role-pick { display: grid; gap: 8px; }
.role-pick button { display: flex; gap: 11px; align-items: center; text-align: left; padding: 11px 12px; border: 1px solid var(--line-strong); background: var(--surface); border-radius: 12px; }
.role-pick button:hover { border-color: var(--b-400); background: var(--b-50); }
html[data-theme="dark"] .role-pick button:hover { background: #1b1430; }
.role-pick .t { display: block; font-size: 14px; font-weight: 640; }
.role-pick .s { display: block; font-size: 12px; color: var(--ink-3); margin-top: 1px; }

/* -------------------------------------------------------------- print/PDF */
@media print {
  .topbar, .tabbar, .fab, .sidebar, .no-print { display: none !important; }
  body { background: #fff; }
  .main { padding: 0; }
  .card { box-shadow: none; break-inside: avoid; }
}

/* ------------------------------------------------------------- ≥ 720px */
@media (min-width: 720px) {
  .g3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
  .g4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
  .sheet { left: 50%; right: auto; bottom: auto; top: 50%; transform: translate(-50%,-50%);
           width: min(680px, calc(100vw - 48px)); border-radius: 20px; max-height: 86dvh; animation: pop .18s ease; }
  @keyframes pop { from { transform: translate(-50%,-48%) scale(.97); opacity: .5 } }
  .sheet-grip { display: none; }
  .sheet-head { padding-top: 16px; }
  .sheet-foot { padding-bottom: 14px; }
  .stat .val { font-size: 26px; }
}

/* ------------------------------------------------------------ ≥ 1000px */
@media (min-width: 1000px) {
  :root { --nav-h: 0px; }
  .shell { flex-direction: row; }
  .tabbar { display: none; }
  .fab { display: none; }
  .sidebar {
    display: flex; flex-direction: column; gap: 3px;
    width: 246px; flex: 0 0 246px; padding: 16px 12px;
    background: var(--surface); border-right: 1px solid var(--line);
    position: sticky; top: 0; height: 100vh; overflow-y: auto;
  }
  .sidebar .brandrow { display: flex; gap: 10px; align-items: center; padding: 4px 8px 16px; }
  .sidebar .brandrow .t { font-size: 15px; font-weight: 700; letter-spacing: -.02em; }
  .sidebar .brandrow .s { font-size: 11.5px; color: var(--ink-3); }
  .sidebar nav { display: flex; flex-direction: column; gap: 2px; }
  .sidebar nav button {
    display: flex; align-items: center; gap: 11px; padding: 9px 11px; border: 0; background: none;
    border-radius: 10px; font-size: 14px; font-weight: 570; color: var(--ink-2); text-align: left; width: 100%;
  }
  .sidebar nav button .ic { font-size: 16px; width: 20px; text-align: center; }
  .sidebar nav button:hover { background: var(--surface-sunk); color: var(--ink); }
  .sidebar nav button[aria-current="page"] { background: var(--b-50); color: var(--b-700); font-weight: 640; }
  html[data-theme="dark"] .sidebar nav button[aria-current="page"] { background: #1e1735; color: var(--b-300); }
  .sidebar .spacer { flex: 1; }
  .sidebar .userbox { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 8px; }

  .content { flex: 1; min-width: 0; display: flex; flex-direction: column; }
  .topbar { padding: 14px 28px; }
  .main { padding: 22px 28px 60px; max-width: 1240px; width: 100%; }
  .page-head h1 { font-size: 25px; }
  .g2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .split { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); gap: 14px; align-items: start; }
  .split > * + * { margin-top: 0; }
  .card + .card { margin-top: 14px; }
  .toast-wrap { bottom: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
