/* ---------- Design tokens ---------- */
:root {
  color-scheme: light;
  --bg: #f4f5f7; --surface: #ffffff; --surface-2: #f8f9fa; --surface-3: #eef0f3;
  --border: #e0e3e8; --border-strong: #c9ced6;
  --text: #16191d; --text-2: #4b525c; --muted: #737a84;
  --accent: #2a78d6; --accent-ink: #1c5cab; --accent-soft: #e6f0fc; --on-accent: #ffffff;
  --nav-bg: #0f2742; --nav-text: #c9d6e6; --nav-active: #ffffff; --nav-hover: #1a3a5e;
  --good: #1f8a4c; --good-soft: #e3f4ea; --warn: #a86400; --warn-soft: #fdf1dc;
  --bad: #c43b3a; --bad-soft: #fbe7e6; --info: #5a5f68; --info-soft: #eceef1;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --seq-ink-lo: #16191d; --seq-ink-hi: #ffffff;
  --seq-1: #cde2fb; --seq-2: #9ec5f4; --seq-3: #6da7ec; --seq-4: #3987e5; --seq-5: #256abf; --seq-6: #184f95;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .18);
  --radius: 10px; --radius-sm: 6px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111315; --surface: #1a1c1f; --surface-2: #202327; --surface-3: #282c31;
    --border: #2f3338; --border-strong: #41464d;
    --text: #f0efec; --text-2: #c3c2b7; --muted: #9a9b97;
    --accent: #3987e5; --accent-ink: #86b6ef; --accent-soft: #17304d; --on-accent: #ffffff;
    --nav-bg: #0b1726; --nav-text: #a9b8ca; --nav-active: #ffffff; --nav-hover: #15273d;
    --good: #4cc27f; --good-soft: #15301f; --warn: #e0a740; --warn-soft: #33270f; --bad: #ef7372; --bad-soft: #3a1918; --info: #b5b8bd; --info-soft: #2a2d31;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --seq-ink-lo: #ffffff; --seq-ink-hi: #111315;
    --seq-ink-lo: #ffffff; --seq-ink-hi: #111315;
  --seq-1: #104281; --seq-2: #184f95; --seq-3: #1c5cab; --seq-4: #2a78d6; --seq-5: #5598e7; --seq-6: #9ec5f4;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4); --shadow-lg: 0 12px 32px rgba(0, 0, 0, .5);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111315; --surface: #1a1c1f; --surface-2: #202327; --surface-3: #282c31;
  --border: #2f3338; --border-strong: #41464d;
  --text: #f0efec; --text-2: #c3c2b7; --muted: #9a9b97;
  --accent: #3987e5; --accent-ink: #86b6ef; --accent-soft: #17304d; --on-accent: #ffffff;
  --nav-bg: #0b1726; --nav-text: #a9b8ca; --nav-active: #ffffff; --nav-hover: #15273d;
  --good: #4cc27f; --good-soft: #15301f; --warn: #e0a740; --warn-soft: #33270f; --bad: #ef7372; --bad-soft: #3a1918; --info: #b5b8bd; --info-soft: #2a2d31;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --seq-ink-lo: #ffffff; --seq-ink-hi: #111315;
  --seq-1: #104281; --seq-2: #184f95; --seq-3: #1c5cab; --seq-4: #2a78d6; --seq-5: #5598e7; --seq-6: #9ec5f4;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4); --shadow-lg: 0 12px 32px rgba(0, 0, 0, .5);
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 22px; } h2 { font-size: 17px; } h3 { font-size: 15px; } h4 { font-size: 13px; }
.muted { color: var(--muted); } .small { font-size: 12px; } .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.boot { padding: 40px; color: var(--muted); }
hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Layout ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.nav { background: var(--nav-bg); color: var(--nav-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.nav .brand { padding: 18px 18px 14px; color: #fff; border-bottom: 1px solid rgba(255,255,255,.08); }
.nav .brand b { display: block; font-size: 15px; }
.nav .brand span { font-size: 11px; opacity: .7; }
.nav .grp { padding: 14px 18px 4px; font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; opacity: .55; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 18px; color: var(--nav-text); font-size: 13.5px; border-left: 3px solid transparent; }
.nav a:hover { background: var(--nav-hover); text-decoration: none; color: #fff; }
.nav a.active { color: var(--nav-active); background: var(--nav-hover); border-left-color: var(--accent); font-weight: 600; }
.nav a .badge { margin-left: auto; }
.nav svg { width: 16px; height: 16px; flex: none; opacity: .85; }
.nav .foot { margin-top: auto; padding: 14px 18px; font-size: 11px; opacity: .55; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 14px; padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.topbar .study { min-width: 0; }
.topbar .study b { display: block; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .study span { font-size: 11.5px; color: var(--muted); }
.topbar .user { margin-left: auto; display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-ink); display: grid; place-items: center; font-weight: 700; font-size: 12px; }
.menu-btn { display: none; }
.content { padding: 22px 24px 60px; max-width: 1480px; width: 100%; }
.page-head { display: flex; align-items: flex-end; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); font-size: 13px; margin-top: 3px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.crumbs { font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.crumbs a { color: var(--muted); }

/* ---------- Surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card > .hd { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card > .hd .sub { color: var(--muted); font-size: 12px; }
.card > .hd .right { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.card > .bd { padding: 16px; }
.card > .bd.flush { padding: 0; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } .g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-side { grid-template-columns: 320px minmax(0, 1fr); align-items: start; }
.stack > * + * { margin-top: 16px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---------- KPI tiles ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .lbl { font-size: 12px; color: var(--muted); }
.kpi .val { font-size: 28px; font-weight: 650; letter-spacing: -.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .hint { font-size: 12px; color: var(--text-2); margin-top: 2px; }
a.kpi:hover { border-color: var(--accent); text-decoration: none; }

/* ---------- Buttons & inputs ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 7px 13px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font: 500 13px var(--font); cursor: pointer; white-space: nowrap; min-height: 34px; }
.btn:hover { background: var(--surface-3); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.good { background: var(--good); border-color: var(--good); color: #fff; }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, var(--border)); }
.btn.danger.solid { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-3); }
.btn.sm { padding: 3px 9px; min-height: 28px; font-size: 12.5px; }
.btn.xs { padding: 1px 7px; min-height: 24px; font-size: 12px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.icon-btn { border: 0; background: transparent; color: var(--muted); cursor: pointer; padding: 4px 6px; border-radius: 5px; font-size: 14px; line-height: 1; }
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
input[type=text], input[type=number], input[type=date], input[type=password], input[type=email], input[type=search], select, textarea {
  font: 14px var(--font); color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 7px 10px; min-height: 36px; width: 100%; max-width: 100%;
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[disabled], select[disabled], textarea[disabled] { background: var(--surface-2); color: var(--text-2); }
input[type=checkbox], input[type=radio] { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }
label.chk { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; }
.field-row { display: grid; gap: 4px; margin-bottom: 12px; }
.field-row > label { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.form-grid .full { grid-column: 1 / -1; }

/* ---------- Badges / status ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 1px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: var(--info-soft); color: var(--info); white-space: nowrap; line-height: 18px; }
.badge.blue { background: var(--accent-soft); color: var(--accent-ink); }
.badge.good, .st-approved { background: var(--good-soft); color: var(--good); }
.badge.warn, .st-pending { background: var(--warn-soft); color: var(--warn); }
.badge.bad, .st-rejected { background: var(--bad-soft); color: var(--bad); }
.st-draft { background: var(--info-soft); color: var(--info); }
.nav .badge { background: var(--accent); color: #fff; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }

/* ---------- Tables ---------- */
.tbl-wrap { overflow: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; font-weight: 600; color: var(--text-2); font-size: 12px; background: var(--surface-2); position: sticky; top: 0; z-index: 1; }
.tbl th, .tbl td { padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tbody tr:hover { background: var(--surface-2); }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl th.sortable { cursor: pointer; user-select: none; }
.tbl th.sortable:hover { color: var(--text); }
.tbl tr.clickable { cursor: pointer; }
.tbl .empty { text-align: center; color: var(--muted); padding: 30px; }

/* ---------- Casebook matrix ---------- */
.matrix { border-collapse: separate; border-spacing: 0; font-size: 12.5px; }
.matrix th, .matrix td { border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); padding: 0; text-align: center; }
.matrix thead th { background: var(--surface-2); padding: 8px 6px; font-weight: 600; font-size: 12px; position: sticky; top: 0; z-index: 2; min-width: 88px; }
.matrix tbody th { text-align: left; padding: 6px 12px; font-weight: 500; background: var(--surface); position: sticky; left: 0; z-index: 1; white-space: nowrap; }
.matrix thead th:first-child { left: 0; z-index: 3; text-align: left; padding-left: 12px; }
.cell { display: flex; align-items: center; justify-content: center; height: 34px; width: 100%; cursor: pointer; border: 0; background: transparent; font: inherit; color: inherit; }
.cell:hover { background: var(--accent-soft); }
.cell.na { cursor: default; color: var(--border-strong); }
.cell.na:hover { background: transparent; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 1px 7px; border-radius: 4px; font-size: 11px; font-weight: 600; }
.chip.new { color: var(--muted); border: 1px dashed var(--border-strong); background: transparent; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-2); align-items: center; }
.legend .sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: 5px; vertical-align: -1px; }

/* ---------- CRF data entry ---------- */
.crf-layout { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 16px; align-items: start; }
.crf-side { position: sticky; top: 70px; }
.sec { margin-bottom: 16px; }
.sec > .hd h3 { font-size: 14.5px; }
.sec-desc { font-size: 12.5px; color: var(--muted); margin: -4px 0 10px; }
.fld { display: grid; grid-template-columns: minmax(200px, 38%) minmax(0, 1fr); gap: 6px 18px; padding: 10px 0; border-bottom: 1px dashed var(--border); align-items: start; }
.fld:last-child { border-bottom: 0; }
.fld.wide { grid-template-columns: 1fr; }
.fld > .lbl { font-size: 13.5px; color: var(--text); padding-top: 7px; }
.fld > .lbl .req { color: var(--bad); margin-left: 2px; }
.fld > .lbl .help { display: block; font-size: 12px; color: var(--muted); margin-top: 3px; line-height: 1.4; }
.fld .ctl { min-width: 0; }
.fld .unit { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.fld .inline { display: flex; align-items: center; gap: 8px; }
.fld .inline input[type=number] { max-width: 180px; }
.fld .inline input[type=date] { max-width: 190px; }
.fld.err .ctl input, .fld.err .ctl select, .fld.err .ctl textarea { border-color: var(--bad); }
.fld .errmsg { color: var(--bad); font-size: 12px; margin-top: 4px; }
.fld.changed > .lbl::before { content: ''; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--warn); margin-right: 6px; vertical-align: 2px; }
.choices { display: flex; flex-wrap: wrap; gap: 6px; }
.choices.vertical { flex-direction: column; align-items: flex-start; }
.choice { display: inline-flex; align-items: center; gap: 7px; padding: 6px 11px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); cursor: pointer; background: var(--surface); font-size: 13px; user-select: none; min-height: 34px; }
.choice:hover { border-color: var(--accent); }
.choice.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
.choice.disabled { cursor: default; opacity: .85; }
.choice.disabled:hover { border-color: var(--border-strong); }
.choice.on.disabled:hover { border-color: var(--accent); }
.choices.vertical .choice { width: 100%; }
.scale .choice { min-width: 44px; justify-content: center; padding: 5px 8px; }
.calc-val { font-weight: 650; font-size: 15px; padding: 7px 0; font-variant-numeric: tabular-nums; }
.subtable { width: 100%; border-collapse: collapse; }
.subtable th { font-size: 12px; color: var(--text-2); text-align: left; padding: 4px 6px; font-weight: 600; }
.subtable td { padding: 4px 6px; vertical-align: top; }
.subtable input, .subtable select { min-height: 32px; padding: 5px 8px; font-size: 13px; }
.date-flags { display: flex; gap: 10px; margin-top: 4px; font-size: 12px; color: var(--text-2); }
.status-banner { display: flex; gap: 12px; align-items: center; padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; border: 1px solid; }
.status-banner.pending { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.status-banner.approved { background: var(--good-soft); border-color: color-mix(in srgb, var(--good) 35%, transparent); }
.status-banner.rejected { background: var(--bad-soft); border-color: color-mix(in srgb, var(--bad) 35%, transparent); }
.status-banner.draft { background: var(--info-soft); border-color: var(--border); }
.steps { list-style: none; margin: 0; padding: 0; }
.steps li { display: grid; grid-template-columns: 22px 1fr; gap: 10px; padding-bottom: 14px; position: relative; }
.steps li::before { content: ''; position: absolute; left: 10px; top: 22px; bottom: 0; width: 2px; background: var(--border); }
.steps li:last-child::before { display: none; }
.steps .marker { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; font-weight: 700; background: var(--surface-3); color: var(--muted); border: 2px solid var(--border); z-index: 1; }
.steps li.done .marker { background: var(--good); color: #fff; border-color: var(--good); }
.steps li.current .marker { background: var(--warn-soft); color: var(--warn); border-color: var(--warn); }
.steps li.rejected .marker { background: var(--bad); color: #fff; border-color: var(--bad); }
.steps .t { font-weight: 600; font-size: 13px; }
.steps .d { font-size: 12px; color: var(--muted); }
.timeline { list-style: none; margin: 0; padding: 0; font-size: 12.5px; }
.timeline li { padding: 8px 0; border-bottom: 1px solid var(--border); }
.timeline li:last-child { border-bottom: 0; }
.timeline .when { color: var(--muted); font-size: 11.5px; }
.chg { font-size: 12px; color: var(--text-2); margin-top: 3px; }
.chg code { background: var(--surface-3); padding: 0 4px; border-radius: 3px; font-size: 11.5px; }
.toc a { display: block; padding: 5px 10px; border-radius: 5px; font-size: 13px; color: var(--text-2); }
.toc a:hover { background: var(--surface-3); text-decoration: none; }
.toc a .n { float: right; color: var(--muted); font-size: 11.5px; }
.sticky-actions { position: sticky; bottom: 0; background: var(--surface); border-top: 1px solid var(--border); padding: 12px 16px; display: flex; gap: 8px; flex-wrap: wrap; z-index: 5; border-radius: 0 0 var(--radius) var(--radius); }

/* ---------- Designer ---------- */
.designer { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 16px; align-items: start; }
.form-list a { display: flex; align-items: center; gap: 8px; padding: 7px 12px; color: var(--text); border-radius: 6px; font-size: 13px; }
.form-list a:hover { background: var(--surface-3); text-decoration: none; }
.form-list a.active { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
.form-list a.inactive { opacity: .5; }
.form-list .code { font-family: ui-monospace, Menlo, monospace; font-size: 11px; color: var(--muted); margin-left: auto; }
.ds-sec { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 14px; background: var(--surface); }
.ds-sec > .hd { display: flex; gap: 8px; align-items: center; padding: 10px 12px; background: var(--surface-2); border-bottom: 1px solid var(--border); border-radius: var(--radius) var(--radius) 0 0; flex-wrap: wrap; }
.ds-sec > .hd input { max-width: 380px; font-weight: 600; }
.ds-field { display: grid; grid-template-columns: 26px minmax(0, 1fr) 150px 140px auto; gap: 10px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--border); font-size: 13px; }
.ds-field:last-child { border-bottom: 0; }
.ds-field:hover { background: var(--surface-2); }
.ds-field .lab { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.ds-field .lab small { display: block; color: var(--muted); font-size: 11.5px; }
.ds-field .ty { font-size: 12px; color: var(--text-2); }
.ds-field .flags { display: flex; gap: 4px; flex-wrap: wrap; }
.ds-field .ops { display: flex; gap: 2px; }
.ds-field .idx { color: var(--muted); font-size: 11.5px; text-align: right; }
.ds-empty { padding: 18px; text-align: center; color: var(--muted); font-size: 13px; }
.sched th.vh { writing-mode: vertical-rl; transform: rotate(180deg); white-space: nowrap; padding: 8px 4px; height: 130px; }
.sched td { text-align: center; }
.perm-matrix td, .perm-matrix th { text-align: center; }
.perm-matrix td:first-child, .perm-matrix th:first-child { text-align: left; }

/* ---------- Query / analytics ---------- */
.filters .frow { display: grid; grid-template-columns: minmax(0, 1.4fr) 120px minmax(0, 1fr) 30px; gap: 6px; margin-bottom: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chips .choice { padding: 3px 9px; min-height: 28px; font-size: 12.5px; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 9px 14px; color: var(--text-2); border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 500; white-space: nowrap; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--accent-ink); border-bottom-color: var(--accent); font-weight: 600; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 8px; }
.stat-grid div { background: var(--surface-2); border-radius: 6px; padding: 8px 10px; }
.stat-grid b { display: block; font-size: 16px; font-variant-numeric: tabular-nums; }
.stat-grid span { font-size: 11px; color: var(--muted); }

/* ---------- Charts ---------- */
.chart { width: 100%; position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .axis text, .chart .lbl-txt { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart .grid line { stroke: var(--border); stroke-width: 1; }
.chart .baseline { stroke: var(--border-strong); }
.hbars { display: grid; gap: 8px; }
.hbar { display: grid; grid-template-columns: minmax(80px, 34%) minmax(0, 1fr) 54px; gap: 10px; align-items: center; font-size: 12.5px; }
.hbar .name { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar .track { height: 16px; position: relative; display: flex; gap: 2px; }
.hbar .fill { height: 100%; border-radius: 0 4px 4px 0; min-width: 2px; }
.hbar .seg { height: 100%; min-width: 2px; }
.hbar .seg:first-child { border-radius: 0; }
.hbar .seg:last-child { border-radius: 0 4px 4px 0; }
.hbar .v { text-align: right; font-variant-numeric: tabular-nums; color: var(--text); font-weight: 600; }
.heat td.hc { text-align: center; font-size: 12px; font-variant-numeric: tabular-nums; padding: 6px 4px; min-width: 56px; border: 2px solid var(--surface); }
.tooltip { position: fixed; z-index: 1000; pointer-events: none; background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); border-radius: 8px; padding: 8px 10px; font-size: 12px; box-shadow: var(--shadow-lg); opacity: 0; transition: opacity .08s; max-width: 280px; }
.tooltip.on { opacity: 1; }
.tooltip .tt-h { font-weight: 600; margin-bottom: 4px; }
.tooltip .tt-r { display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.tooltip .tt-r b { font-variant-numeric: tabular-nums; }

/* ---------- Modal / toast ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(10, 15, 25, .45); display: grid; place-items: center; z-index: 500; padding: 16px; }
.modal { background: var(--surface); border-radius: 12px; box-shadow: var(--shadow-lg); width: min(560px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; border: 1px solid var(--border); }
.modal.lg { width: min(900px, 100%); } .modal.xl { width: min(1200px, 100%); }
.modal .hd { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.modal .hd .x { margin-left: auto; }
.modal .bd { padding: 18px; overflow: auto; }
.modal .ft { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.toasts { position: fixed; right: 18px; bottom: 18px; display: grid; gap: 8px; z-index: 900; }
.toast { background: var(--text); color: var(--surface); padding: 10px 14px; border-radius: 8px; font-size: 13px; box-shadow: var(--shadow-lg); max-width: 380px; }
.toast.bad { background: var(--bad); color: #fff; }
.toast.good { background: var(--good); color: #fff; }
.alert { padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 12px; background: var(--info-soft); color: var(--text-2); }
.alert.bad { background: var(--bad-soft); color: var(--bad); }
.alert.warn { background: var(--warn-soft); color: var(--warn); }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-art { background: linear-gradient(150deg, #0f2742, #1c5cab); color: #e9f1fb; padding: 48px; display: flex; flex-direction: column; justify-content: center; }
.login-art h1 { font-size: 28px; color: #fff; margin-bottom: 12px; }
.login-art p { opacity: .85; max-width: 520px; line-height: 1.6; }
.login-art ul { padding-left: 18px; opacity: .9; line-height: 1.9; }
.login-box { display: grid; place-items: center; padding: 32px 16px; }
.login-box .card { width: min(400px, 100%); }
.demo-users { font-size: 12px; margin-top: 10px; }
.demo-users button { margin: 2px; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .crf-layout { grid-template-columns: 1fr; } .crf-side { position: static; }
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .designer, .g-side { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .nav { position: fixed; left: 0; top: 0; bottom: 0; width: 250px; z-index: 100; transform: translateX(-100%); transition: transform .2s; }
  .nav.open { transform: none; }
  .menu-btn { display: inline-flex; }
  .content { padding: 16px 16px 60px; }
  .topbar { padding: 10px 16px; }
  .topbar .user .nm { display: none; }
  .g2, .g3, .g4 { grid-template-columns: 1fr; }
  .fld { grid-template-columns: 1fr; }
  .fld > .lbl { padding-top: 0; }
  .form-grid { grid-template-columns: 1fr; }
  .login-wrap { grid-template-columns: 1fr; } .login-art { display: none; }
  .ds-field { grid-template-columns: 22px minmax(0, 1fr) auto; } .ds-field .ty, .ds-field .flags { display: none; }
  .filters .frow { grid-template-columns: 1fr 1fr; }
}
