/* Capital Chambers Group: shared design system for the desk, client portal and mobile app.
   Brand sheet: Navy #2F3878, Gold #C9A227, Ink #1B2038, Grey #6B7185.
   Century Schoolbook for headings and the wordmark, Lato for body copy and UI. */
:root {
  --navy: #2F3878;
  --navy-deep: #252C60;
  --gold: #C9A227;
  --brand-ink: #1B2038;
  --brand-grey: #6B7185;

  --bg: #F4F5F9;
  --surface: #FFFFFF;
  --surface-2: #F8F9FC;
  --ink: #1B2038;
  --ink-2: #454B66;
  --muted: #6B7185;
  --line: #E0E3EC;
  --accent: #2F3878;
  --accent-hover: #252C60;
  --accent-soft: #E9EBF6;
  --accent-ink: #FFFFFF;
  --highlight: #C9A227;          /* gold: rules, markers, active states (never body text on white) */
  --highlight-soft: #FAF3DC;
  --side-bg: #2F3878;
  --side-ink: #D9DCEF;
  --side-muted: #A9AED3;
  --side-active: rgba(255,255,255,.12);

  --good: #1D7A3E; --good-bg: #E3F3E8;
  --warn: #8A6200; --warn-bg: #FBF0D2;
  --serious: #A64A1F; --serious-bg: #FBE6DC;
  --bad: #B42D2D; --bad-bg: #FBE3E3;
  --neutral-bg: #ECEEF4;

  --series-1: #2F3878;
  --series-2: #B8901B;
  --grid: #E6E8EF;

  --serif: "Century Schoolbook", "New Century Schoolbook", "TeX Gyre Schola", "C059", "Century Schoolbook L", Georgia, "Times New Roman", serif;
  --font: "Lato", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(27,32,56,.05), 0 4px 16px rgba(27,32,56,.05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11142A; --surface: #1B2038; --surface-2: #171B33; --ink: #ECEEF6; --ink-2: #BCC1D8; --muted: #9298B3; --line: #2E3456;
    --accent: #A3ACEB; --accent-hover: #BCC3F2; --accent-soft: #272E5A; --accent-ink: #11142A;
    --highlight: #D9B43A; --highlight-soft: #3A3218;
    --side-bg: #0D1024; --side-ink: #D9DCEF; --side-muted: #8E94B8; --side-active: rgba(255,255,255,.08);
    --good: #6BCB8B; --good-bg: #16301F; --warn: #E8BE54; --warn-bg: #352A10; --serious: #F09A73; --serious-bg: #3A2216;
    --bad: #F08080; --bad-bg: #3A1A1E; --neutral-bg: #252A47;
    --series-1: #8F9AE6; --series-2: #D9B43A; --grid: #2A3052;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #11142A; --surface: #1B2038; --surface-2: #171B33; --ink: #ECEEF6; --ink-2: #BCC1D8; --muted: #9298B3; --line: #2E3456;
  --accent: #A3ACEB; --accent-hover: #BCC3F2; --accent-soft: #272E5A; --accent-ink: #11142A;
  --highlight: #D9B43A; --highlight-soft: #3A3218;
  --side-bg: #0D1024; --side-ink: #D9DCEF; --side-muted: #8E94B8; --side-active: rgba(255,255,255,.08);
  --good: #6BCB8B; --good-bg: #16301F; --warn: #E8BE54; --warn-bg: #352A10; --serious: #F09A73; --serious-bg: #3A2216;
  --bad: #F08080; --bad-bg: #3A1A1E; --neutral-bg: #252A47;
  --series-1: #8F9AE6; --series-2: #D9B43A; --grid: #2A3052;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { text-wrap: balance; margin: 0; line-height: 1.2; font-family: var(--serif); font-weight: 400; color: var(--ink); }
h3 { font-size: 15px; }
.num, td.r, th.r { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--highlight); outline-offset: 2px; }
.eyebrow { font: 700 11px/1.2 var(--font); letter-spacing: .18em; text-transform: uppercase; color: var(--highlight); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- logo lockup ---------- */
.lockup { display: inline-flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.lockup svg { width: 34px; height: auto; flex: none; display: block; }
.lockup .wm { display: grid; line-height: 1; }
.lockup .wm b { font: 400 15px/1 var(--serif); letter-spacing: .14em; white-space: nowrap; }
.lockup .wm small { font: 400 9.5px/1 var(--serif); letter-spacing: .62em; margin-top: 5px; opacity: .9; }
.lockup.lg svg { width: 52px; }
.lockup.lg .wm b { font-size: 22px; }
.lockup.lg .wm small { font-size: 12px; letter-spacing: .9em; margin-top: 8px; }
.mark-navy { color: var(--navy); }
:root[data-theme="dark"] .mark-navy { color: #fff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .mark-navy { color: #fff; } }

/* ---------- app shell: sidebar on wide screens, scrolling tab strip on phones ---------- */
.app { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: 100vh; }
.side { background: var(--side-bg); color: var(--side-ink); padding: 22px 14px; display: flex; flex-direction: column; gap: 20px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.side .lockup { color: #fff; padding: 0 6px; }
.side .lockup .wm b { font-size: 13.5px; }
.side .lockup .wm small { font-size: 8.5px; letter-spacing: .55em; }
.side .tag { font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--gold); padding: 0 6px; margin-top: -8px; font-weight: 700; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav .grp { font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase; color: var(--side-muted); padding: 10px 10px 3px; font-weight: 700; }
.nav a { color: var(--side-ink); text-decoration: none; padding: 6px 10px; border-radius: 8px; display: flex; justify-content: space-between; align-items: center; font-weight: 400; border-left: 3px solid transparent; }
.nav a:hover { background: var(--side-active); }
.nav a[aria-current="page"] { background: var(--side-active); color: #fff; border-left-color: var(--gold); font-weight: 700; }
.nav .count { font-size: 11.5px; background: rgba(255,255,255,.16); padding: 1px 7px; border-radius: 99px; font-weight: 700; }
.nav .count.hot { background: var(--gold); color: var(--brand-ink); }
.side-foot { margin-top: auto; font-size: 12px; color: var(--side-muted); display: grid; gap: 8px; padding: 0 6px; }
.side-foot .btn { background: transparent; color: var(--side-ink); border-color: rgba(255,255,255,.25); }
.live { display: inline-flex; align-items: center; gap: 7px; }
.live i { width: 8px; height: 8px; border-radius: 50%; background: #4cc27a; box-shadow: 0 0 0 3px rgba(76,194,122,.22); }
.live.off i { background: var(--gold); box-shadow: 0 0 0 3px rgba(201,162,39,.22); }

main { padding: 26px clamp(16px, 3vw, 40px) 64px; min-width: 0; display: grid; gap: 20px; align-content: start; }
.topbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; justify-content: space-between; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.topbar h1 { font-size: 28px; }
.topbar p { margin: 4px 0 0; color: var(--ink-2); font-size: 14px; max-width: 70ch; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- controls ---------- */
.btn { border: 1px solid var(--line); background: var(--surface); padding: 8px 15px; border-radius: 8px; cursor: pointer; font-weight: 700; font-size: 14px; text-decoration: none; color: var(--ink); display: inline-flex; align-items: center; gap: 6px; justify-content: center; }
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.gold { background: var(--gold); border-color: var(--gold); color: var(--brand-ink); }
.btn.danger { color: var(--bad); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn.block { width: 100%; }
.banner { background: var(--highlight-soft); border: 1px solid var(--line); border-left: 3px solid var(--highlight); border-radius: var(--radius); padding: 10px 14px; font-size: 14px; display: flex; gap: 12px; flex-wrap: wrap; align-items: center; justify-content: space-between; }
.banner.bad { background: var(--serious-bg); border-left-color: var(--serious); }

/* ---------- tiles and cards ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 190px), 1fr)); gap: 12px; }
.tiles.six { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: grid; gap: 4px; box-shadow: var(--shadow); align-content: start; }
.tile .k { font-size: 12.5px; color: var(--ink-2); font-weight: 700; letter-spacing: .02em; }
.tile .v { font-size: 25px; font-weight: 700; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.tile .s { font-size: 12.5px; color: var(--muted); }
.tile.lead { border-top: 3px solid var(--highlight); }
.tile.hero { background: var(--navy); color: #fff; border-color: var(--navy); }
.tile.hero .k, .tile.hero .s { color: #C9CDEA; }
.meter { height: 6px; background: var(--neutral-bg); border-radius: 99px; overflow: hidden; margin-top: 4px; }
.meter > i { display: block; height: 100%; background: var(--highlight); border-radius: 99px; }
.tile.hero .meter { background: rgba(255,255,255,.18); }

.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 360px), 1fr)); gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; display: grid; gap: 12px; min-width: 0; align-content: start; box-shadow: var(--shadow); }
.card h2 { font-size: 19px; }
.card .sub, .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.card-head { display: flex; justify-content: space-between; gap: 10px; align-items: start; flex-wrap: wrap; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th { text-align: left; font-weight: 700; font-size: 12px; letter-spacing: .03em; color: var(--ink-2); background: var(--surface-2); padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--accent-soft); }
td .small, .small { display: block; color: var(--muted); font-size: 12.5px; }
tfoot td { font-weight: 700; background: var(--surface-2); }
.empty { padding: 28px; text-align: center; color: var(--muted); }

.pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 700; white-space: nowrap; background: var(--neutral-bg); color: var(--ink-2); }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.good { background: var(--good-bg); color: var(--good); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.serious { background: var(--serious-bg); color: var(--serious); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.info { background: var(--accent-soft); color: var(--accent); }

.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filters input, .filters select { padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 4px 12px; font-size: 13px; cursor: pointer; font-weight: 700; color: var(--ink-2); }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* ---------- charts ---------- */
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart text { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart .gridl { stroke: var(--grid); stroke-width: 1; }
.chart .base { stroke: var(--muted); stroke-width: 1; }
.chart .hit { fill: transparent; cursor: default; }
.chart .bar:hover { opacity: .8; }
.tip { position: fixed; pointer-events: none; background: var(--brand-ink); color: #fff; font-size: 12.5px; padding: 6px 9px; border-radius: 6px; z-index: 50; white-space: nowrap; display: none; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--brand-ink); color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 14px; z-index: 60; display: none; max-width: calc(100vw - 32px); border-left: 3px solid var(--gold); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--ink-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.bars { display: grid; gap: 8px; }
.hbar { display: grid; grid-template-columns: minmax(90px, 160px) 1fr auto; gap: 10px; align-items: center; font-size: 13.5px; }
.hbar .track { height: 12px; background: var(--neutral-bg); border-radius: 0 4px 4px 0; overflow: hidden; }
.hbar .fill { height: 100%; border-radius: 0 4px 4px 0; background: var(--series-1); }
.hbar .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.kv { display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; font-size: 14px; margin: 0; }
.kv dt { color: var(--ink-2); }
.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; font-weight: 700; }
.kv .tot { border-top: 1px solid var(--line); padding-top: 6px; font-weight: 700; color: var(--ink); }

/* ---------- dialogs and forms ---------- */
dialog { border: 1px solid var(--line); border-radius: 14px; padding: 0; width: min(660px, calc(100vw - 24px)); max-height: calc(100vh - 32px); background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(17,20,42,.3); }
dialog::backdrop { background: rgba(17, 20, 42, .6); }
.dlg { display: grid; gap: 14px; padding: 22px; }
.dlg-head { display: flex; justify-content: space-between; align-items: start; gap: 12px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.dlg-head h2 { font-size: 21px; }
.x { border: 0; background: none; font-size: 24px; line-height: 1; cursor: pointer; color: var(--muted); padding: 2px 6px; }
.form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form .full { grid-column: 1 / -1; }
label.f { display: grid; gap: 4px; font-size: 13px; font-weight: 700; color: var(--ink-2); align-content: start; }
label.f input, label.f select, label.f textarea { padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); font-size: 15px; color: var(--ink); width: 100%; font-weight: 400; }
label.f input:focus, label.f select:focus, label.f textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
label.f .hint { font-weight: 400; color: var(--muted); font-size: 12px; }
.preview { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.dlg-foot { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; padding-top: 4px; }
.err { color: var(--bad); font-size: 13.5px; margin: 0; }
.err:empty { display: none; }
.drop { border: 1.5px dashed var(--line); border-radius: var(--radius); padding: 16px; text-align: center; color: var(--muted); font-size: 13.5px; cursor: pointer; display: grid; gap: 4px; }
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); color: var(--ink); }
.drop input { display: none; }

/* ---------- messages ---------- */
.thread { display: flex; flex-direction: column; gap: 10px; max-height: 460px; overflow-y: auto; padding: 4px; }
.msg { max-width: 78%; padding: 9px 13px; border-radius: 12px; font-size: 14px; background: var(--neutral-bg); align-self: flex-start; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.me { align-self: flex-end; background: var(--accent); color: var(--accent-ink); }
.msg .meta { display: block; font-size: 11.5px; opacity: .75; margin-top: 4px; }
.composer { display: flex; gap: 8px; align-items: end; }
.composer textarea { flex: 1; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); min-height: 44px; resize: vertical; }

/* ---------- sign-in ---------- */
.login { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.login-art { background: var(--navy); color: #fff; padding: 48px; display: flex; flex-direction: column; justify-content: space-between; gap: 24px; position: relative; overflow: hidden; }
.login-art .lockup { color: #fff; }
.login-art h1 { color: #fff; font-size: clamp(28px, 3.4vw, 42px); max-width: 15ch; }
.login-art p { color: #C9CDEA; max-width: 40ch; }
.login-art .ghost-mark { position: absolute; right: -80px; bottom: -60px; width: 380px; opacity: .07; color: #fff; }
.login-art .rule { width: 56px; height: 3px; background: var(--gold); margin: 16px 0; }
.login-form { display: grid; place-items: center; padding: 32px 20px; }
.login-form form { width: min(380px, 100%); display: grid; gap: 14px; }
.login-form h2 { font-size: 26px; }
@media (max-width: 760px) {
  .login { grid-template-columns: 1fr; }
  .login-art { padding: 28px 20px; }
  .login-art .ghost-mark { width: 220px; }
}

@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .tiles, .tiles.six { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tile { padding: 12px; }
  .tile .v { font-size: 20px; }
  .hbar { grid-template-columns: minmax(70px, 110px) 1fr auto; }
  .side { position: sticky; top: 0; z-index: 20; height: auto; padding: 10px 12px; gap: 8px; flex-direction: column; }
  .side .tag { display: none; }
  .nav { flex-direction: row; overflow-x: auto; gap: 4px; padding-bottom: 2px; }
  .nav .grp { display: none; }
  .nav a { white-space: nowrap; padding: 7px 11px; border-left: 0; border-bottom: 2px solid transparent; border-radius: 6px; }
  .nav a[aria-current="page"] { border-bottom-color: var(--gold); }
  .nav .count { margin-left: 6px; }
  .side-foot { display: none; }
  .form { grid-template-columns: minmax(0, 1fr); }
  .topbar h1 { font-size: 24px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
