:root {
  color-scheme: light;
  --brand: #c8402a;          /* Alpha Living warm red — chrome only, never data */
  --brand-ink: #ffffff;
  --charcoal: #45403d;       /* Alpha Living grey (replaces black) */
  --bg: #f6f4f2;
  --surface: #fdfcfb;
  --surface-2: #f1eeeb;
  --border: #e4dfdb;
  --text: #2a2624;
  --text-2: #5a5450;
  --text-3: #7c7570;
  --btn: #45403d; --btn-ink: #ffffff;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --target: #7c7570;
  --grid: #ebe7e3;
  --good: #0ca30c;  --good-ink: #006300;  --good-bg: #e6f4e6;
  --warn: #fab219;  --warn-ink: #7a5200;  --warn-bg: #fdf3dc;
  --bad: #d03b3b;   --bad-ink: #a12a2a;   --bad-bg: #fbe8e8;
  --focus: #2a78d6;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-brand: "Rubik", var(--font);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --brand: #e0573f; --charcoal: #e6e1dc;
    --bg: #141211; --surface: #1c1a19; --surface-2: #252220; --border: #36322f;
    --text: #f0ece8; --text-2: #c6bfb8; --text-3: #9c958e;
    --btn: #e6e1dc; --btn-ink: #1c1a19;
    --series-1: #3987e5; --series-2: #d95926; --target: #9c958e; --grid: #2d2a28;
    --good-ink: #7fd67f; --good-bg: #16301a; --warn-ink: #f5c35a; --warn-bg: #33290f; --bad-ink: #f08a8a; --bad-bg: #3a1a1a;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --brand: #e0573f; --charcoal: #e6e1dc;
  --bg: #141211; --surface: #1c1a19; --surface-2: #252220; --border: #36322f;
  --text: #f0ece8; --text-2: #c6bfb8; --text-3: #9c958e;
  --btn: #e6e1dc; --btn-ink: #1c1a19;
  --series-1: #3987e5; --series-2: #d95926; --target: #9c958e; --grid: #2d2a28;
  --good-ink: #7fd67f; --good-bg: #16301a; --warn-ink: #f5c35a; --warn-bg: #33290f; --bad-ink: #f08a8a; --bad-bg: #3a1a1a;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 var(--font); }
a { color: var(--series-1); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
code { font-size: 12px; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
code.break { word-break: break-all; }
.wrap { max-width: 1280px; margin: 0 auto; padding: 0 16px; }
main.wrap { padding-top: 22px; padding-bottom: 40px; }
h1 { font: 600 22px/1.25 var(--font-brand); margin: 0 0 4px; letter-spacing: -0.01em; color: var(--text); }
h2 { font-size: 16px; margin: 0 0 10px; }
h3 { font-size: 14px; margin: 0 0 8px; }
p { margin: 0 0 10px; }
.muted { color: var(--text-2); }
.small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Alpha Living frame ---------- */
.cr-top { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 10px 16px; background: var(--surface); border-top: 4px solid var(--brand); border-bottom: 1px solid var(--border); }
.cr-brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--charcoal); }
.cr-brand img { display: block; }
.cr-brand-txt { display: flex; flex-direction: column; line-height: 1.05; font-family: var(--font-brand); }
.cr-brand-txt b { font-weight: 700; font-size: 15px; letter-spacing: .02em; }
.cr-brand-txt small { font-size: 11px; color: var(--text-3); letter-spacing: .04em; text-transform: uppercase; }
.cr-crumb { color: var(--text-3); font-size: 20px; font-weight: 300; }
.cr-client { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--text); font-weight: 600; }
.cr-logo-chip { display: inline-flex; align-items: center; justify-content: center; height: 30px; min-width: 30px; padding: 3px 7px; border-radius: 7px; background: #fff; border: 1px solid var(--border); box-shadow: inset 0 -2px 0 var(--client-accent); }
.cr-logo-chip img { max-height: 20px; max-width: 90px; display: block; }
.cr-logo-chip.lg { height: 44px; min-width: 44px; padding: 5px 10px; }
.cr-logo-chip.lg img { max-height: 30px; max-width: 120px; }
.cr-logo-initial { font-weight: 700; color: #45403d; }
.cr-user { margin-left: auto; display: flex; gap: 6px; font-size: 13px; color: var(--text-2); }
.cr-user a { color: var(--text-2); text-decoration: none; }
.cr-user a:hover { color: var(--text); text-decoration: underline; }
.cr-nav { background: var(--surface); border-bottom: 1px solid var(--border); }
.cr-nav .wrap { display: flex; flex-wrap: wrap; gap: 2px; align-items: center; }
.cr-nav a { color: var(--text-2); text-decoration: none; padding: 10px 12px 8px; border-bottom: 2px solid transparent; font-weight: 500; }
.cr-nav a:hover { color: var(--text); }
.cr-nav a.on { color: var(--text); border-bottom-color: var(--client-accent); font-weight: 600; }
.cr-nav-sep { width: 1px; height: 18px; background: var(--border); margin: 0 6px; }
.cr-nav-toggle { display: none; margin-left: auto; background: transparent; color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 4px 10px; font: inherit; }
/* two-level client menu */
.cr-nav-2 .cr-nav-top a { font-size: 15px; }
.cr-nav-m { display: none; }
.cr-nav-action { margin-left: auto; padding: 6px 14px; border-bottom: 1px solid var(--btn) !important; color: var(--btn-ink) !important; font-size: 13.5px !important; }
.cr-nav-sub { background: var(--surface-2); border-top: 1px solid var(--border); }
.cr-nav-sub .wrap { display: flex; flex-wrap: wrap; gap: 2px; }
.cr-nav-sub a { font-size: 13.5px; padding: 8px 12px 6px; }
@media (max-width: 860px) {
  .cr-nav-toggle { display: block; }
  .cr-nav-sub { display: none; }
  .cr-nav-m { display: flex; flex-direction: column; padding-left: 14px; margin-bottom: 4px; }
  .cr-nav-m a { font-size: 14px; padding: 7px 12px; }
  .cr-nav-2 .cr-nav-top > a.on { border-left-color: transparent; }
  .cr-nav-action { margin: 8px 12px; align-self: flex-start; }
  .cr-user { flex-basis: 100%; margin: 0; }
  .cr-nav { display: none; }
  .cr-nav.open { display: block; }
  .cr-nav .wrap { flex-direction: column; align-items: stretch; }
  .cr-nav a { border-bottom: 0; border-left: 3px solid transparent; }
  .cr-nav a.on { border-left-color: var(--client-accent); }
  .cr-nav-sep { width: 100%; height: 1px; margin: 4px 0; }
}
.cr-foot { color: var(--text-3); font-size: 12px; padding-bottom: 24px; display: flex; align-items: center; gap: 6px; }
.login { max-width: 400px; margin: 30px auto; }
.login-brand { text-align: center; margin-bottom: 4px; }
.login-brand img { max-width: 100%; height: auto; }
.notice-brand { border-left-color: var(--brand); }

/* hub home */
.client-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 380px), 1fr)); }
.client-card { background: var(--surface); border: 1px solid var(--border); border-top: 3px solid var(--client-accent); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; }
.client-card-head { display: flex; align-items: center; gap: 12px; text-decoration: none; color: var(--text); }
.client-card-head b { font-size: 17px; display: block; }
.client-card-head small { color: var(--text-2); display: block; }
.client-open { margin-left: auto; font-size: 20px; color: var(--text-3); }
.client-card-head:hover .client-open { color: var(--text); }
.client-counts { display: flex; flex-wrap: wrap; gap: 6px; }
.kpi-list { width: 100%; border-collapse: collapse; }
.kpi-list td { padding: 6px 4px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.kpi-list td small { display: block; color: var(--text-3); font-size: 11px; }
.kpi-list tr:last-child td { border-bottom: 0; }
.kpi-list td:first-child { width: 26px; }
.dot { display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; border-radius: 50%; font-size: 11px; font-weight: 700; }
.dot-good { background: var(--good-bg); color: var(--good-ink); }
.dot-warn { background: var(--warn-bg); color: var(--warn-ink); }
.dot-bad { background: var(--bad-bg); color: var(--bad-ink); }
.dot-none { background: var(--surface-2); color: var(--text-3); }

/* users */
.row-between { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px; align-items: flex-start; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.actions select { width: auto; }
.access { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 10px; }
.access-chip { display: inline-flex; align-items: center; gap: 4px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 2px 4px 2px 10px; font-size: 12px; }
.chip-x { border: 0; background: transparent; color: var(--text-2); cursor: pointer; font-size: 15px; line-height: 1; padding: 0 5px; }
.access-add select { width: auto; padding: 4px 6px; font-size: 12px; }
.pw-form { display: flex; gap: 6px; margin-top: 10px; max-width: 360px; }
.steps { padding-left: 18px; margin: 0; }
label.check { flex-direction: row !important; align-items: center; gap: 8px; }
.check input { width: auto; }

/* flash */
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid var(--border); background: var(--surface); }
.flash-ok { border-color: var(--good); background: var(--good-bg); color: var(--good-ink); }
.flash-err { border-color: var(--bad); background: var(--bad-bg); color: var(--bad-ink); }
.flash-warn { border-color: var(--warn); background: var(--warn-bg); color: var(--warn-ink); }

/* cards & layout */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.stack > * + * { margin-top: 16px; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.section-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 12px; margin: 26px 0 10px; }
.section-head h2 { margin: 0; font-size: 15px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-2); }
.section-head .period { font-size: 13px; color: var(--text-2); }
.grid { display: grid; gap: 14px; }
.grid-5 { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); }
.cols-2 { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr)); }

/* filters */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.filters label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-2); min-width: 160px; flex: 1 1 160px; max-width: 260px; }

/* forms */
label { font-weight: 500; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 7px 9px; width: 100%; }
input[type=checkbox], input[type=radio] { width: auto; }
textarea { min-height: 70px; }
.form-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); align-items: end; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.form-grid .wide { grid-column: 1 / -1; }
.hint { font-size: 12px; color: var(--text-3); font-weight: 400; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600; border-radius: 6px; padding: 8px 14px; border: 1px solid var(--btn); background: var(--btn); color: var(--btn-ink); cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-danger { background: transparent; color: var(--bad-ink); border-color: var(--bad); }
.btn-sm { padding: 4px 9px; font-size: 12px; font-weight: 500; }
.inline { display: inline; }

/* tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; color: var(--text-2); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.r, th.r { text-align: right; }
tbody tr:hover td { background: var(--surface-2); }

/* KPI tiles */
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 14px 10px; display: flex; flex-direction: column; min-width: 0; }
.tile-h { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.tile-label { font-weight: 600; font-size: 13px; }
.tile-freq { font-size: 11px; color: var(--text-3); text-transform: uppercase; letter-spacing: .05em; }
.tile-v { font-size: 30px; font-weight: 650; letter-spacing: -0.02em; line-height: 1.15; margin-top: 6px; font-variant-numeric: tabular-nums; }
.tile-v .unit { font-size: 15px; font-weight: 500; color: var(--text-2); margin-left: 2px; }
.tile-sub { font-size: 12px; color: var(--text-2); margin-top: 2px; min-height: 18px; }
.tile-t { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; font-size: 12px; color: var(--text-2); margin-top: 8px; }
.tile-chart { position: relative; height: 92px; margin-top: 10px; }
.tile-chart.tall { height: 200px; }
.tile-help { font-size: 11.5px; color: var(--text-3); margin: 8px 0 0; }
.tile-flag { margin-top: 8px; font-size: 12px; padding: 6px 8px; border-radius: 6px; background: var(--warn-bg); color: var(--warn-ink); }

.rag { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.rag-good { background: var(--good-bg); color: var(--good-ink); }
.rag-warn { background: var(--warn-bg); color: var(--warn-ink); }
.rag-bad { background: var(--bad-bg); color: var(--bad-ink); }
.rag-none { background: var(--surface-2); color: var(--text-3); font-weight: 500; }

.pill { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); }
.pill-good { background: var(--good-bg); color: var(--good-ink); }
.pill-bad { background: var(--bad-bg); color: var(--bad-ink); }
.pill-warn { background: var(--warn-bg); color: var(--warn-ink); }

.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--text-2); margin-top: 8px; }
.legend i { display: inline-block; width: 12px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 5px; }
.legend i.dash { background: repeating-linear-gradient(90deg, var(--target) 0 4px, transparent 4px 7px); }

.notice { border-left: 3px solid var(--warn); background: var(--surface); padding: 10px 14px; border-radius: 0 8px 8px 0; margin-bottom: 10px; }
.notice ul { margin: 4px 0 0; padding-left: 18px; }
.score-big { font-size: 34px; font-weight: 700; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: 13px; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; }
.empty { padding: 30px; text-align: center; color: var(--text-2); }
.foot { color: var(--text-3); font-size: 12px; padding-bottom: 24px; }

.login { max-width: 380px; margin: 60px auto; }
.sev-error { color: var(--bad-ink); font-weight: 600; }
.sev-warning { color: var(--warn-ink); font-weight: 600; }
.sev-mismatch { color: var(--series-2); font-weight: 600; }
.sev-note { color: var(--text-2); font-weight: 600; }

@media print {
  .cr-top, .cr-nav, .cr-foot, .no-print, .filters { display: none !important; }
  body { background: #fff; color: #000; }
  .card, .table-wrap { border-color: #ccc; }
  main.wrap { padding: 0; }
}
.grid-5 .tile-label { display: block; min-height: 2.6em; }
.tabs { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 14px; border-bottom: 1px solid var(--border); }
.tabs a { padding: 8px 12px; color: var(--text-2); text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.on { color: var(--text); border-bottom-color: var(--client-accent); font-weight: 600; }
.grid-5 .tile-label { display: block; min-height: 2.6em; }
/* drop-down list behind a KPI tile */
.tile-list { margin-top: 10px; border-top: 1px solid var(--border); padding-top: 8px; }
.tile-list summary { cursor: pointer; font-size: 12.5px; font-weight: 600; color: var(--series-1); list-style: none; display: flex; align-items: center; gap: 6px; }
.tile-list summary::-webkit-details-marker { display: none; }
.tile-list summary::before { content: "▸"; font-size: 11px; transition: transform .15s; }
.tile-list[open] summary::before { transform: rotate(90deg); }
.tile-list[data-empty] summary { color: var(--text-3); cursor: default; pointer-events: none; }
.tile-list[data-empty] summary::before { content: ""; }
.tile-list ul { list-style: none; margin: 8px 0 0; padding: 0; max-height: 280px; overflow-y: auto; }
.tile-list li { padding: 6px 2px; border-bottom: 1px solid var(--border); font-size: 12.5px; line-height: 1.35; }
.tile-list li:last-child { border-bottom: 0; }
.tile-list li b { display: block; font-weight: 600; }
.tile-list li span { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; color: var(--text-2); font-size: 12px; }
@media print { .tile-list ul { max-height: none; } }
/* record pages (pipeline, clients) */
.records-summary { margin: 14px 0 10px; color: var(--text-2); font-size: 13px; }
.funnel { display: grid; gap: 6px; padding: 14px 16px; margin-bottom: 8px; }
.funnel-row { display: grid; grid-template-columns: minmax(120px, 190px) 1fr minmax(70px, auto); gap: 10px; align-items: center; text-decoration: none; color: var(--text); font-size: 13px; padding: 2px 0; border-radius: 6px; }
.funnel-row:hover .funnel-label { text-decoration: underline; }
.funnel-bar { height: 16px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.funnel-bar i { display: block; height: 100%; background: var(--series-1); border-radius: 0 4px 4px 0; }
.funnel-n { color: var(--text-2); white-space: nowrap; }
.funnel-n b { color: var(--text); margin-right: 2px; }
.records-group { margin-top: 18px; }
.records-group > summary { display: flex; align-items: center; gap: 8px; cursor: pointer; list-style: none; margin-bottom: 8px; }
.records-group > summary::-webkit-details-marker { display: none; }
.records-group > summary::before { content: "▸"; color: var(--text-3); font-size: 12px; transition: transform .15s; }
.records-group[open] > summary::before { transform: rotate(90deg); }
.records-group > summary h2 { margin: 0; font-size: 15px; }
.records-group.review > summary h2 { color: var(--warn-ink); }
table.records td { font-size: 12.5px; max-width: 280px; }
table.records td b { font-size: 13px; }
.nowrap { white-space: nowrap; }
@media (max-width: 600px) { .funnel-row { grid-template-columns: 1fr auto; } .funnel-bar { grid-column: 1 / -1; grid-row: 2; } }
@media print { .records-group > summary::before { display: none; } }
table.records .clamp { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; min-width: 90px; }
@media print { table.records .clamp { -webkit-line-clamp: unset; display: block; } }
/* summary stats (team, changes, scorecard) */
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 14px 0; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; text-decoration: none; color: var(--text); }
.stat b { font-size: 24px; font-weight: 650; line-height: 1.15; }
.stat span { font-size: 12px; color: var(--text-2); }
.stat-warn { background: var(--warn-bg); border-color: transparent; }
.stat-warn b, .stat-warn span { color: var(--warn-ink); }
a.stat:hover { border-color: var(--series-1); }
tr.muted td { color: var(--text-3); }
/* changes page */
.chg-list { list-style: none; margin: 0; padding: 0; }
.chg-list li { padding: 8px 12px; border-bottom: 1px solid var(--border); font-size: 13px; line-height: 1.4; }
.chg-list li:last-child { border-bottom: 0; }
.chg-list li .chg-meta { color: var(--text-2); font-size: 12px; }
.chg-from { color: var(--text-3); text-decoration: line-through; }
.chg-arrow { color: var(--text-3); margin: 0 4px; }
.chg-to { font-weight: 600; }
.chg-up { color: var(--good-ink, #1f7a3d); }
.chg-down { color: var(--bad-ink, #b3261e); }
/* scorecard */
table.scorecard td, table.scorecard th { white-space: nowrap; }
table.scorecard td.rag-good { background: var(--good-bg, #e6f4ea); }
table.scorecard td.rag-warn { background: var(--warn-bg); }
table.scorecard td.rag-bad { background: var(--bad-bg, #fce8e6); }
table.scorecard th:first-child, table.scorecard td:first-child { position: sticky; left: 0; background: var(--surface); z-index: 1; white-space: normal; min-width: 160px; }
table.scorecard th:first-child { background: var(--surface-2); }
table.scorecard tr.sc-section td { background: var(--surface-2); font-weight: 600; font-size: 12px; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; }
.notice-warn { background: var(--warn-bg); color: var(--warn-ink); }
.notice-warn summary { cursor: pointer; }
.notice-warn a { color: inherit; text-decoration: underline; }
.notice-warn ul { margin: 8px 0 0; padding-left: 18px; font-size: 13px; }
@media (min-width: 1000px) { .grid-6 { grid-template-columns: repeat(3, 1fr); } }
tr.row-on td { background: var(--warn-bg) !important; }
