/* BuddySpaceHub — design prototype stylesheet.
   Token system: see design plan in HANDOFF response.
   Color  — ink-900 #16302E, harbor #1C7A6E, brass #C47A1E, paper #EEF1EF, plum #6B4FA0 (module-only)
   Type   — Source Serif 4 (display/wordmark) · IBM Plex Sans Thai (UI/body, bilingual) · IBM Plex Mono (figures)
   Layout — left rail nav (desktop/tablet) collapsing to bottom tab bar (phone); card-grid content; icon+label status chips, never color alone */

:root {
  /* ---- surfaces & ink (light) ---- */
  --bg: #EEF1EF;
  --surface: #FFFFFF;
  --surface-raised: #FFFFFF;
  --surface-sunken: #E4E9E6;
  --border: #D7DEDB;
  --border-strong: #BFC9C5;
  --ink-900: #16302E;
  --ink-700: #3B4F4C;
  --ink-500: #5A716D;
  --ink-400: #7E938F;
  --ink-200: #AFC0BC;

  /* ---- brand ---- */
  --brand-900: #0F2B27;
  --brand-700: #1C7A6E;
  --brand-600: #228F81;
  --brand-100: #DCEEEA;
  --accent-600: #C47A1E;
  --accent-100: #F6E4C8;

  /* ---- module identity (validated categorical: CVD ΔE ≥ 10.7, normal ≥ 21, contrast ≥ 3:1 vs surface) ---- */
  --mod-storage: #0E8A77;
  --mod-market: #C47A1E;
  --mod-apartment: #6B4FA0;

  /* ---- semantic status (reserved — never reused as decoration) ---- */
  --tone-good: #2F8F5B;
  --tone-good-bg: #E3F3E9;
  --tone-warn: #B9860A;
  --tone-warn-bg: #FBF0D8;
  --tone-critical: #C23B3B;
  --tone-critical-bg: #FAE3E1;
  --tone-info: #3B6FC9;
  --tone-info-bg: #E4EBFA;
  --tone-neutral: #6B7470;
  --tone-neutral-bg: #E7EAE8;

  /* ---- type ---- */
  --font-display: "Source Serif 4", "Noto Serif Thai", Georgia, serif;
  --font-ui: "IBM Plex Sans Thai", "IBM Plex Sans", -apple-system, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Consolas, monospace;

  /* ---- scale ---- */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 24px; --sp-6: 32px; --sp-7: 48px;
  --radius-s: 8px; --radius-m: 12px; --radius-l: 16px;
  --shadow-card: 0 1px 2px rgba(22,48,46,.06), 0 1px 1px rgba(22,48,46,.04);
  --shadow-pop: 0 8px 24px rgba(22,48,46,.16), 0 2px 6px rgba(22,48,46,.08);

  color-scheme: light dark;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0F1716;
    --surface: #17221F;
    --surface-raised: #1C2825;
    --surface-sunken: #0C1211;
    --border: #2B3A37;
    --border-strong: #3A4C48;
    --ink-900: #EAF0EE;
    --ink-700: #BFCCC8;
    --ink-500: #93A6A2;
    --ink-400: #6F8681;
    --ink-200: #46605B;

    --brand-900: #BFE8E0;
    --brand-700: #2FBFA8;
    --brand-600: #3FD4BB;
    --brand-100: #16302E;
    --accent-600: #E0973A;
    --accent-100: #3A2B16;

    --mod-storage: #1F9F89;
    --mod-market: #C97A1E;
    --mod-apartment: #8A6AC0;

    --tone-good: #3FB573; --tone-good-bg: #15291D;
    --tone-warn: #E0B22E; --tone-warn-bg: #2E2611;
    --tone-critical: #E0615A; --tone-critical-bg: #2E1716;
    --tone-info: #6D9BF0; --tone-info-bg: #15213A;
    --tone-neutral: #8A9490; --tone-neutral-bg: #202A27;

    --shadow-card: 0 1px 2px rgba(0,0,0,.4), 0 1px 1px rgba(0,0,0,.3);
    --shadow-pop: 0 8px 28px rgba(0,0,0,.55), 0 2px 8px rgba(0,0,0,.4);
  }
}
:root[data-theme="dark"] {
  --bg: #0F1716; --surface: #17221F; --surface-raised: #1C2825; --surface-sunken: #0C1211;
  --border: #2B3A37; --border-strong: #3A4C48;
  --ink-900: #EAF0EE; --ink-700: #BFCCC8; --ink-500: #93A6A2; --ink-400: #6F8681; --ink-200: #46605B;
  --brand-900: #BFE8E0; --brand-700: #2FBFA8; --brand-600: #3FD4BB; --brand-100: #16302E;
  --accent-600: #E0973A; --accent-100: #3A2B16;
  --mod-storage: #1F9F89; --mod-market: #C97A1E; --mod-apartment: #8A6AC0;
  --tone-good: #3FB573; --tone-good-bg: #15291D;
  --tone-warn: #E0B22E; --tone-warn-bg: #2E2611;
  --tone-critical: #E0615A; --tone-critical-bg: #2E1716;
  --tone-info: #6D9BF0; --tone-info-bg: #15213A;
  --tone-neutral: #8A9490; --tone-neutral-bg: #202A27;
  --shadow-card: 0 1px 2px rgba(0,0,0,.4), 0 1px 1px rgba(0,0,0,.3);
  --shadow-pop: 0 8px 28px rgba(0,0,0,.55), 0 2px 8px rgba(0,0,0,.4);
}

/* ---------- reset ---------- */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink-900);
  font: 15px/1.5 var(--font-ui);
  -webkit-font-smoothing: antialiased;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
img { max-width: 100%; }
[hidden] { display: none !important; }
button { font: inherit; }
a { color: var(--brand-700); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 600; text-wrap: balance; margin: 0; color: var(--ink-900); }
table { border-collapse: collapse; width: 100%; }
:focus-visible { outline: 2px solid var(--brand-600); outline-offset: 2px; border-radius: 4px; }
.tnum { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; } }

/* ---------- icons (inline currentColor strokes, no icon font) ---------- */
.ic { width: 1em; height: 1em; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: -0.15em; flex: none; }

/* ---------- app shell ---------- */
#app { max-width: 1400px; margin: 0 auto; min-height: 100%; }
.shell { display: flex; min-height: 100vh; min-height: 100dvh; }

.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 30;
  display: flex; align-items: center; gap: var(--sp-3);
  height: 60px; padding: 0 var(--sp-4);
  background: var(--surface); border-bottom: 1px solid var(--border);
  grid-column: 1 / -1;
}
.brand-mark { display: flex; align-items: center; gap: var(--sp-2); font-family: var(--font-display); font-weight: 700; font-size: 18px; color: var(--ink-900); white-space: nowrap; }
.brand-mark .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--brand-700); }
.brand-mark .sub { font-family: var(--font-ui); font-weight: 500; font-size: 10.5px; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-400); }

.top-spacer { flex: 1; }

.org-switch { display: flex; align-items: center; gap: var(--sp-2); }
.select {
  appearance: none; background: var(--surface-sunken); border: 1px solid var(--border);
  color: var(--ink-900); border-radius: var(--radius-s); padding: 7px 30px 7px 12px; font-size: 13.5px;
  font-family: var(--font-ui); cursor: pointer;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='6'><path d='M1 1l4 4 4-4' stroke='%235A716D' stroke-width='1.6' fill='none' stroke-linecap='round'/></svg>");
  background-repeat: no-repeat; background-position: right 10px center;
}
.view-toggle { display: flex; background: var(--surface-sunken); border: 1px solid var(--border); border-radius: 999px; padding: 3px; gap: 2px; }
.view-toggle button { border: none; background: none; padding: 6px 14px; border-radius: 999px; font-size: 13px; font-weight: 500; color: var(--ink-500); cursor: pointer; }
.view-toggle button.active { background: var(--brand-700); color: #fff; }
.theme-btn {
  display: inline-flex; align-items: center; gap: 6px; flex: none; cursor: pointer;
  background: var(--surface-sunken); border: 1px solid var(--border-strong); color: var(--ink-700);
  border-radius: 999px; padding: 7px 13px 7px 11px; font-size: 12.5px; font-weight: 600; font-family: var(--font-ui);
}
.theme-btn:hover { background: var(--border); }
.theme-btn .ic { width: 15px; height: 15px; }
.demo-pill {
  display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 600;
  letter-spacing: .02em; color: var(--accent-600); background: var(--accent-100);
  border-radius: 999px; padding: 4px 10px;
}

.disclaimer {
  grid-column: 1 / -1; background: var(--accent-100); color: var(--ink-900);
  font-size: 12.5px; text-align: center; padding: 6px var(--sp-4);
  border-bottom: 1px solid var(--border);
}
.disclaimer b { color: var(--accent-600); }

/* side nav */
.rail {
  width: 232px; flex: none; background: var(--surface); border-right: 1px solid var(--border);
  padding: var(--sp-4) var(--sp-3); display: flex; flex-direction: column; gap: var(--sp-1);
  position: sticky; top: calc(60px + env(safe-area-inset-top, 0px)); height: calc(100vh - 60px); overflow-y: auto;
}
.rail-section-label { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-400); padding: var(--sp-3) var(--sp-3) var(--sp-1); }
.rail a {
  display: flex; align-items: center; gap: var(--sp-3); padding: 9px var(--sp-3); border-radius: var(--radius-s);
  color: var(--ink-700); font-size: 14px; font-weight: 500; text-decoration: none;
}
.rail a:hover { background: var(--surface-sunken); text-decoration: none; }
.rail a.active { background: var(--brand-100); color: var(--brand-700); }
.rail a .ic { width: 18px; height: 18px; }

.main { flex: 1; min-width: 0; padding: var(--sp-5); display: flex; flex-direction: column; gap: var(--sp-5); }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-4); flex-wrap: wrap; }
.page-head .eyebrow { font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-400); margin-bottom: 2px; }
.page-head h1 { font-size: 24px; }
.page-head p.lede { color: var(--ink-500); font-size: 13.5px; margin: var(--sp-1) 0 0; max-width: 56ch; }

/* bottom tab bar (phone) */
.tabbar { display: none; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border-radius: var(--radius-s); border: 1px solid transparent; cursor: pointer;
  font-weight: 600; font-size: 13.5px; padding: 9px 16px; line-height: 1.2;
  transition: background .12s, border-color .12s;
}
.btn .ic { width: 15px; height: 15px; }
.btn-primary { background: var(--brand-700); color: #fff; }
.btn-primary:hover { background: var(--brand-600); }
.btn-accent { background: var(--accent-600); color: #fff; }
.btn-ghost { background: transparent; border-color: var(--border-strong); color: var(--ink-700); }
.btn-ghost:hover { background: var(--surface-sunken); }
.btn-danger { background: transparent; border-color: var(--tone-critical); color: var(--tone-critical); }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-block { width: 100%; }
.iconbtn { width: 34px; height: 34px; flex: none; border-radius: var(--radius-s); border: 1px solid var(--border); background: var(--surface); color: var(--ink-500); display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.iconbtn:hover { background: var(--surface-sunken); }

/* ---------- cards / grid ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-m); box-shadow: var(--shadow-card); }
.card-pad { padding: var(--sp-4); }
.card-head { display: flex; align-items: center; justify-content: space-between; padding: var(--sp-4); border-bottom: 1px solid var(--border); gap: var(--sp-3); }
.card-head h2 { font-size: 15px; font-family: var(--font-ui); font-weight: 600; }
.card-head .hint { font-size: 12px; color: var(--ink-400); font-weight: 400; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: var(--sp-3); }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-m);
  padding: var(--sp-4); display: flex; flex-direction: column; gap: 6px; box-shadow: var(--shadow-card);
}
.kpi .label { font-size: 12.5px; color: var(--ink-500); font-weight: 500; display: flex; align-items: center; gap: 6px; }
.kpi .value { font-family: var(--font-mono); font-size: 25px; font-weight: 500; letter-spacing: -0.01em; }
.kpi .delta { font-size: 12px; font-weight: 600; display: flex; align-items: center; gap: 4px; }
.kpi .delta.good { color: var(--tone-good); } .kpi .delta.warn { color: var(--tone-warn); } .kpi .delta.critical { color: var(--tone-critical); }

/* ---------- status chips (icon + text — never color alone) ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600;
  padding: 3px 9px 3px 7px; border-radius: 999px; white-space: nowrap; line-height: 1.4;
}
.chip .ic { width: 12px; height: 12px; }
.chip.good { background: var(--tone-good-bg); color: var(--tone-good); }
.chip.warn { background: var(--tone-warn-bg); color: var(--tone-warn); }
.chip.critical { background: var(--tone-critical-bg); color: var(--tone-critical); }
.chip.info { background: var(--tone-info-bg); color: var(--tone-info); }
.chip.neutral { background: var(--tone-neutral-bg); color: var(--tone-neutral); }

.mod-badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; padding: 3px 8px; border-radius: 6px; }
.mod-badge.storage { background: color-mix(in srgb, var(--mod-storage) 14%, transparent); color: var(--mod-storage); }
.mod-badge.market { background: color-mix(in srgb, var(--mod-market) 14%, transparent); color: var(--mod-market); }
.mod-badge.apartment { background: color-mix(in srgb, var(--mod-apartment) 14%, transparent); color: var(--mod-apartment); }
.mod-badge .ic { width: 12px; height: 12px; }

/* ---------- tables ---------- */
.tablewrap { overflow-x: auto; }
.table { font-size: 13.5px; }
.table th { text-align: left; font-size: 11.5px; font-weight: 600; letter-spacing: .03em; text-transform: uppercase; color: var(--ink-400); padding: 10px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr.clickable:hover { background: var(--surface-sunken); }
.table .amount { font-family: var(--font-mono); text-align: right; font-variant-numeric: tabular-nums; }
.table th.amount-h { text-align: right; }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--ink-700); }
.field .help { font-size: 11.5px; color: var(--ink-400); }
.input, .textarea, select.input {
  font-family: var(--font-ui); font-size: 14px; padding: 9px 12px; border-radius: var(--radius-s);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--ink-900); width: 100%;
}
.input:focus, .textarea:focus { outline: 2px solid var(--brand-600); outline-offset: 1px; border-color: transparent; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--sp-3); }
.form-row-full { grid-column: 1 / -1; }

/* ---------- space map ---------- */
.map-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-3); }
.legend { display: flex; flex-wrap: wrap; gap: var(--sp-3); font-size: 12px; color: var(--ink-500); }
.legend .item { display: flex; align-items: center; gap: 6px; }
.legend .swatch { width: 10px; height: 10px; border-radius: 3px; }

/* Space map — deliberately a traffic-light board (free=green / taken=red), like a
   restaurant table POS, not the financial "occupied=good" framing used in chips
   elsewhere. Icon is kept inside every tile too, so status never relies on color alone. */
.map-stats { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.map-stat { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-m); padding: 10px 14px; box-shadow: var(--shadow-card); flex: 1; min-width: 130px; }
.map-stat .swatch-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.map-stat .n { font-family: var(--font-mono); font-size: 19px; font-weight: 600; line-height: 1; }
.map-stat .l { font-size: 11.5px; color: var(--ink-500); }

.space-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: var(--sp-3); }
.space-cell {
  position: relative; aspect-ratio: 1; border-radius: var(--radius-m); border: 2px solid transparent;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 4px; cursor: pointer; font-family: var(--font-mono); padding: 4px; color: #fff;
  transition: transform .1s, box-shadow .1s;
}
.space-cell .code { font-size: 14px; font-weight: 700; color: inherit; }
.space-cell .sub { font-size: 9.5px; opacity: .85; color: inherit; }
.space-cell .ic { width: 18px; height: 18px; }
.space-cell.tone-good { background: var(--tone-good); }
.space-cell.tone-warn { background: var(--tone-warn); }
.space-cell.tone-info { background: var(--tone-info); }
.space-cell.tone-critical { background: var(--tone-critical); }
.space-cell .fix-badge {
  position: absolute; top: -7px; right: -7px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--ink-900); color: #fff; display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--surface);
}
.space-cell .fix-badge .ic { width: 11px; height: 11px; stroke: #fff; }
.space-cell:hover { box-shadow: var(--shadow-pop); transform: translateY(-1px); }
.space-cell.selected { outline: 2px solid var(--brand-700); outline-offset: 2px; }

/* edit-layout mode */
.space-cell.editable { cursor: grab; border: 2px dashed rgba(255,255,255,.65); }
.space-cell.editable:active { cursor: grabbing; }
.space-cell .tile-del {
  position: absolute; top: -8px; left: -8px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--ink-900); color: #fff; border: 2px solid var(--surface); display: flex;
  align-items: center; justify-content: center; cursor: pointer; padding: 0;
}
.space-cell .tile-del .ic { width: 11px; height: 11px; stroke: #fff; }
.space-cell.add-tile {
  background: transparent; border: 2px dashed var(--border-strong); color: var(--ink-400);
}
.space-cell.add-tile:hover { background: var(--surface-sunken); color: var(--ink-700); }
.edit-banner { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap; background: var(--accent-100); border-radius: var(--radius-m); padding: 10px 14px; font-size: 13px; }

.map-list { display: flex; flex-direction: column; gap: 6px; }
.map-list-row {
  display: flex; align-items: center; gap: var(--sp-3); padding: 10px 12px; border: 1px solid var(--border);
  border-radius: var(--radius-s); background: var(--surface); cursor: pointer; font-size: 13.5px;
}
.map-list-row:hover { background: var(--surface-sunken); }

/* ---------- panels / drawers / modals ---------- */
.overlay { position: fixed; inset: 0; background: rgba(15,23,22,.45); z-index: 50; display: flex; justify-content: flex-end; }
.overlay.center { justify-content: center; align-items: center; }
.drawer { width: min(420px, 100%); height: 100%; background: var(--surface); box-shadow: var(--shadow-pop); display: flex; flex-direction: column; overflow-y: auto; padding-bottom: env(safe-area-inset-bottom, 0px); }
.modal { width: min(480px, calc(100% - 32px)); max-height: 90vh; overflow-y: auto; background: var(--surface); border-radius: var(--radius-l); box-shadow: var(--shadow-pop); }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: var(--sp-4); border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); }
.panel-head h3 { font-size: 16px; }
.panel-body { padding: var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-4); }
.panel-foot { padding: var(--sp-4); border-top: 1px solid var(--border); display: flex; gap: var(--sp-2); justify-content: flex-end; position: sticky; bottom: 0; background: var(--surface); }

.kv-list { display: flex; flex-direction: column; gap: 10px; }
.kv-row { display: flex; justify-content: space-between; gap: var(--sp-3); font-size: 13.5px; }
.kv-row .k { color: var(--ink-500); } .kv-row .v { font-weight: 600; text-align: right; }

/* ---------- empty / loading / error / expired / pending states (first-class, not afterthought) ---------- */
.state-block { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--sp-3); text-align: center; padding: var(--sp-7) var(--sp-4); color: var(--ink-500); }
.state-block .ic-big { width: 40px; height: 40px; color: var(--ink-400); }
.state-block h3 { font-size: 15px; color: var(--ink-700); }
.state-block p { font-size: 13px; max-width: 42ch; margin: 0; }
.state-block.error .ic-big { color: var(--tone-critical); }
.state-block.pending .ic-big { color: var(--tone-warn); }

.skeleton { background: linear-gradient(90deg, var(--surface-sunken) 25%, var(--border) 37%, var(--surface-sunken) 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; border-radius: var(--radius-s); }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
.skel-line { height: 14px; margin-bottom: 8px; }
.skel-card { height: 92px; border-radius: var(--radius-m); }

.session-banner { grid-column: 1/-1; background: var(--tone-critical-bg); color: var(--tone-critical); padding: 10px var(--sp-4); font-size: 13px; display: flex; align-items: center; gap: 8px; justify-content: center; font-weight: 600; }

/* ---------- toasts ---------- */
.toasts { position: fixed; bottom: calc(var(--sp-4) + env(safe-area-inset-bottom, 0px)); right: var(--sp-4); z-index: 80; display: flex; flex-direction: column; gap: 8px; max-width: min(340px, calc(100vw - 32px)); }
.toast { background: var(--ink-900); color: var(--bg); padding: 11px 14px; border-radius: var(--radius-s); font-size: 13px; box-shadow: var(--shadow-pop); display: flex; align-items: flex-start; gap: 8px; }
.toast.good { background: var(--tone-good); color: #fff; }
.toast.critical { background: var(--tone-critical); color: #fff; }

/* ---------- charts (small, per dataviz skill: thin marks, legend, tabular labels) ---------- */
.chart-legend { display: flex; gap: var(--sp-4); font-size: 12px; color: var(--ink-500); margin-bottom: var(--sp-2); }
.chart-legend .item { display: flex; align-items: center; gap: 6px; }
.chart-legend .swatch { width: 10px; height: 10px; border-radius: 2px; }
.bars-chart { display: flex; align-items: flex-end; gap: var(--sp-4); height: 150px; padding-top: var(--sp-3); }
.bars-chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bars-chart .bargroup { display: flex; gap: 4px; align-items: flex-end; width: 100%; justify-content: center; height: 100%; }
.bars-chart .bar { width: 12px; border-radius: 3px 3px 0 0; position: relative; }
.bars-chart .bar.billed { background: var(--ink-200); }
.bars-chart .bar.collected { background: var(--brand-700); }
.bars-chart .m-label { font-size: 11px; color: var(--ink-400); }

.sparkbar { display: flex; align-items: flex-end; gap: 3px; height: 28px; }
.sparkbar i { flex: 1; background: var(--brand-700); border-radius: 2px 2px 0 0; min-height: 2px; }

/* ---------- misc ---------- */
.flex { display: flex; } .flex-col { display: flex; flex-direction: column; } .gap-2 { gap: 8px; } .gap-3 { gap: 12px; }
.muted { color: var(--ink-500); } .small { font-size: 12px; }
.divider { height: 1px; background: var(--border); margin: var(--sp-2) 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
.progress-track { height: 6px; background: var(--surface-sunken); border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--brand-700); border-radius: 999px; }

/* ---------- responsive ---------- */
@media (max-width: 980px) {
  .topbar { gap: var(--sp-2); }
  .top-spacer { min-width: 0; }
  .brand-mark .sub, .demo-pill { display: none; }
  .org-switch .select { max-width: 210px; overflow: hidden; text-overflow: ellipsis; }
  .rail { width: 76px; }
  .rail a span.label { display: none; }
  .rail a { justify-content: center; }
  .rail-section-label { display: none; }
  .form-grid { grid-template-columns: 1fr; }
}
@media (max-width: 680px) {
  .rail { display: none; }
  .tabbar {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
    background: var(--surface); border-top: 1px solid var(--border);
    padding: 6px max(10px, env(safe-area-inset-right, 0px)) calc(6px + env(safe-area-inset-bottom, 0px)) max(10px, env(safe-area-inset-left, 0px));
    justify-content: space-around;
  }
  .tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 10.5px; color: var(--ink-400); text-decoration: none; padding: 4px 8px; border-radius: 8px; }
  .tabbar a.active { color: var(--brand-700); }
  .tabbar .ic { width: 19px; height: 19px; }
  .main { padding: var(--sp-3); padding-bottom: calc(70px + env(safe-area-inset-bottom, 0px)); }
  .topbar { height: auto; min-height: 60px; padding: 8px var(--sp-3); gap: 6px var(--sp-2); flex-wrap: wrap; justify-content: space-between; }
  .top-spacer { display: none; }
  .brand-mark { flex: 1 1 auto; min-width: 0; font-size: 16px; }
  .theme-btn { order: 1; }
  .org-switch { order: 2; flex: 1 1 45%; min-width: 0; }
  .org-switch .select { width: 100%; min-width: 0; max-width: none; }
  .view-toggle { order: 3; flex: 0 0 auto; }
  .view-toggle button { padding: 6px 8px; font-size: 12px; }
  .brand-mark .sub { display: none; }
  .demo-pill { display: none; }
  .theme-btn span.label { display: none; }
  .theme-btn { padding: 7px; }
  .org-switch .select { font-size: 12.5px; padding: 6px 24px 6px 9px; text-overflow: ellipsis; overflow: hidden; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
  .page-head h1 { font-size: 20px; }
  .drawer { width: 100%; }
}
