:root {
  color-scheme: light;
  --bg: #eef1f5;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e4e7ec;
  --text: #101828;
  --text-body: #344054;
  --text-muted: #667085;
  --text-faint: #98a2b3;
  --accent: #3fa9e0;
  --accent-strong: #1f7fb8;
  --gold: #f2b92b;
  --pink: #e23a7b;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.06);
  --grid: #eef0f3;
  /* chart series (validated: light surface) */
  --series-income: #2b8fcb;
  --series-costs: #d6336f;
  --series-best: #b07d10;
  --series-res: #b07d10;
  /* status tints */
  --good: #067647;
  --good-bg: #ecfdf3;
  --warn: #93370d;
  --warn-bg: #fffaeb;
  --bad: #c01048;
  --bad-bg: #fff1f3;
  --info: #175c8a;
  --info-bg: #eff8ff;
  --neutral-bg: #f2f4f7;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
/* Always reserve the scrollbar's space so pages don't shift sideways between short and long tabs. */
html { overflow-y: scroll; scrollbar-gutter: stable; }
body {
  background: var(--bg);
  color: var(--text-body);
  font: 15px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { color: var(--text); margin: 0; line-height: 1.25; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
a { color: var(--accent-strong); }
.muted { color: var(--text-muted); }
.tiny { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.strike { text-decoration: line-through; color: var(--text-faint); }
[hidden] { display: none !important; }

/* brand stripe */
.stripe { display: flex; flex-direction: column; gap: 3px; }
.stripe span { display: block; height: 3px; border-radius: 2px; }
.stripe span:nth-child(1) { background: #3fa9e0; }
.stripe span:nth-child(2) { background: #f2b92b; }
.stripe span:nth-child(3) { background: #e23a7b; }
.topstripe { display: flex; height: 4px; }
.topstripe span { flex: 1; }
.topstripe span:nth-child(1) { background: #3fa9e0; }
.topstripe span:nth-child(2) { background: #f2b92b; }
.topstripe span:nth-child(3) { background: #e23a7b; }

/* header */
.header { background: var(--surface); border-bottom: 1px solid var(--border); }
.header-inner { max-width: 1480px; margin: 0 auto; padding: 14px 16px 0; }
.header-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 12px; margin-right: auto; min-width: 0; }
.brand .stripe { width: 28px; }
.brand-sub { font-size: 13px; color: var(--text-muted); }
.role-badge { font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 999px; background: var(--neutral-bg); color: var(--text-body); }
.inline-select[class*="role-"] { font-weight: 600; border-color: transparent; }
.kpi-label .badge { text-transform: none; letter-spacing: 0; font-size: 12px; }
.nav { display: flex; gap: 4px; margin-top: 12px; overflow-x: auto; }
.nav a {
  padding: 10px 14px; text-decoration: none; color: var(--text-muted); font-weight: 600; font-size: 14px;
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.nav a:hover { color: var(--text); }
.nav a.active { color: var(--text); border-bottom-color: var(--accent); }

main.page { max-width: 1480px; margin: 0 auto; padding: 20px 16px 48px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head p { margin: 4px 0 0; }

/* cards & grid */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); padding: 18px; min-width: 0; }
.card + .card, .grid + .card, .card + .grid, .grid + .grid, .callout + .grid, .callout + .card { margin-top: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head p { margin: 2px 0 0; font-size: 13px; color: var(--text-muted); }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 900px) { .grid-2 { grid-template-columns: minmax(0, 1fr); } }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); padding: 14px 16px; }
.kpi-label { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.kpi-value { font-size: 26px; font-weight: 700; color: var(--text); margin-top: 4px; font-variant-numeric: tabular-nums; line-height: 1.15; }
.kpi-sub { font-size: 12.5px; color: var(--text-muted); margin-top: 4px; }
.kpi-value .pos { color: var(--good); }
.kpi-value .neg { color: var(--bad); }

/* callouts */
.callout { border-left: 4px solid var(--accent); background: var(--info-bg); color: var(--text-body); padding: 10px 14px; border-radius: 6px; font-size: 14px; margin: 16px 0 0; }
.callout strong { color: var(--text); }
.callout-warn { border-color: var(--gold); background: var(--warn-bg); }
.callout-bad { border-color: var(--pink); background: var(--bad-bg); }
.callout-good { border-color: #12b76a; background: var(--good-bg); }

/* tables */
.table-wrap { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 9px 8px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .03em; background: var(--surface-2); position: sticky; top: 0; white-space: nowrap; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
tbody tr:hover { background: var(--surface-2); }
tr.clickable { cursor: pointer; }
tfoot td { font-weight: 700; color: var(--text); border-bottom: 0; }
td .sub { display: block; font-size: 12px; color: var(--text-muted); }
.cost-note { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }
.cell-notes { min-width: 140px; max-width: 220px; white-space: pre-wrap; color: var(--text-muted); font-size: 13px; }

/* badges */
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px; white-space: nowrap; background: var(--neutral-bg); color: var(--text-body); }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
:root {
  --st-active: #067647;
  --st-active-bg: #dcfae6;
  --st-signed_up: #175cd3;
  --st-signed_up-bg: #d1e9ff;
  --st-interested: #b54708;
  --st-interested-bg: #fef0c7;
  --st-contacted: #0e7090;
  --st-contacted-bg: #cff9fe;
  --st-not_contacted: #475467;
  --st-not_contacted-bg: #eaecf0;
  --st-not_interested: #c01048;
  --st-not_interested-bg: #ffe4e8;
}
.st-active { background: var(--st-active-bg); color: var(--st-active); }
.st-signed_up { background: var(--st-signed_up-bg); color: var(--st-signed_up); }
.st-interested { background: var(--st-interested-bg); color: var(--st-interested); }
.st-contacted { background: var(--st-contacted-bg); color: var(--st-contacted); }
.st-not_contacted { background: var(--st-not_contacted-bg); color: var(--st-not_contacted); }
.st-not_interested { background: var(--st-not_interested-bg); color: var(--st-not_interested); }
.inline-select[class*="st-"] { font-weight: 600; border-color: transparent; }
.inline-select option { background: var(--surface); color: var(--text); font-weight: 400; }
tr.group-row td { background: var(--surface-2); padding: 11px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; line-height: 1; }
tr.group-row td > * { vertical-align: middle; }
tr.group-row:hover { background: transparent; }
tr.group-row .group-count { display: inline-block; margin-left: 8px; font-size: 12.5px; color: var(--text-muted); font-weight: 600; }
.type-tag { font-size: 12px; color: var(--text-muted); }

/* forms & buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-weight: 600; font-size: 14px; padding: 8px 14px; border-radius: 6px; cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn-danger { color: var(--bad); }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-muted); }
.btn-ghost:hover { color: var(--text); background: var(--surface-2); }
label { display: block; font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
input, select, textarea {
  width: 100%; font: inherit; font-size: 14px; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
input:disabled, select:disabled, textarea:disabled { background: var(--surface-2); color: var(--text-body); }
textarea { min-height: 90px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.form-grid .full { grid-column: 1 / -1; }
.hint { font-size: 12px; color: var(--text-muted); margin-top: 3px; }
@media (max-width: 640px) { .form-grid { grid-template-columns: minmax(0, 1fr); } }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar input[type=search] { flex: 1 1 220px; width: auto; }
.toolbar select { width: auto; flex: 0 1 auto; }
.inline-select { width: auto; padding: 3px 6px; font-size: 13px; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.inline-form input, .inline-form select { width: auto; flex: 1 1 160px; }
.table-input { padding: 5px 8px; min-width: 90px; }

/* modal */
dialog { border: 1px solid var(--border); border-radius: 12px; padding: 0; width: min(720px, calc(100vw - 32px)); max-height: calc(100vh - 32px); background: var(--surface); color: var(--text-body); box-shadow: 0 20px 50px rgba(16,24,40,.25); }
dialog::backdrop { background: rgba(16, 24, 40, .45); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 18px; overflow-y: auto; max-height: calc(100vh - 180px); }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 14px 18px; border-top: 1px solid var(--border); }
.modal-foot .spacer { margin-right: auto; }

/* charts */
.chart-box { position: relative; height: 340px; }
.chart-box.short { height: 280px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; color: var(--text-body); margin-bottom: 10px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { display: inline-block; width: 18px; height: 0; border-top: 2px solid; }
.legend i.dash { border-top-style: dashed; }
.legend i.box { width: 10px; height: 10px; border: 0; border-radius: 2px; }
details.table-view { margin-top: 10px; font-size: 13px; }
details.table-view summary { cursor: pointer; color: var(--text-muted); font-weight: 600; }
details.table-view .table-wrap { margin-top: 8px; max-height: 320px; overflow: auto; }

/* misc */
.area-card h2 { display: flex; align-items: center; gap: 8px; }
.activity { list-style: none; margin: 0; padding: 0; font-size: 14px; }
.activity li { display: flex; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--border); }
.activity li:last-child { border-bottom: 0; }
.activity time { color: var(--text-faint); font-size: 12.5px; white-space: nowrap; min-width: 92px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-size: 14px; font-weight: 600; box-shadow: 0 8px 24px rgba(0,0,0,.2); z-index: 100; max-width: calc(100vw - 32px); }
.toast.error { background: var(--pink); color: #fff; }
.empty { padding: 24px; text-align: center; color: var(--text-muted); }
/* Sticky footer: the page is a column and the main area grows, so the footer sits at the bottom of short pages. */
body:not(.login-page) { min-height: 100vh; display: flex; flex-direction: column; }
body:not(.login-page) > main.page { flex: 1 0 auto; width: 100%; }
.footer { flex-shrink: 0; background: var(--bg); border-top: 1px solid var(--border); font-size: 11px; color: var(--text-faint); text-align: center; }
.footer-inner { max-width: 1480px; margin: 0 auto; padding: 12px 16px 14px; }
.footer p { margin: 0; }
.stack > * + * { margin-top: 8px; }
.split { display: flex; gap: 8px; flex-wrap: wrap; }

/* login */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(440px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; }
.login-stripe { height: 6px; }
.login-head { display: flex; justify-content: center; align-items: center; padding: 32px 24px; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.login-body { padding: 28px 32px 28px; }
.login-body h1 { font-size: 22px; text-align: center; }
.login-body > p.muted { text-align: center; margin: 6px 0 0; }
.login-body form { margin-top: 20px; display: grid; gap: 10px; }
.login-body .callout { margin: 0; }
.login-body .tiny { margin: 16px 0 0; text-align: center; }
.login-version { margin: 20px 0 0; text-align: center; font-size: 12px; color: var(--text-faint); }
.user-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.grid > .card { margin-top: 0; }
th.col-name { min-width: 200px; }
.cell-contact { min-width: 130px; max-width: 210px; overflow-wrap: anywhere; }
.brand-home { display: block; border-radius: 4px; }
.brand-logo { display: block; height: 36px; width: auto; }
.brand-divider { width: 1px; align-self: stretch; background: var(--border); }
.login-logo { display: block; width: 200px; max-width: 100%; height: auto; }
@media (max-width: 560px) {
  .brand-logo { height: 28px; }
  .brand-divider, .brand-sub { display: none; }
  .brand h1 { font-size: 16px; }
}
.cell-site .sub { white-space: nowrap; }
.me { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; color: var(--text); }
.notice { width: 100%; max-width: 1480px; margin: 0 auto; padding: 16px 16px 0; }
.notice .callout { margin: 0; }
.notice .callout { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.cred { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; background: var(--info-bg); border-left: 4px solid var(--accent); border-radius: 6px; padding: 14px 16px; }
.cred-val { font: 600 22px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--text); letter-spacing: .03em; overflow-wrap: anywhere; }
@media (max-width: 560px) { .cred { grid-template-columns: minmax(0, 1fr); } #me-name { display: none; } }
.version { margin-top: 4px; color: var(--text-faint); }
.link-btn { background: none; border: 0; padding: 0; font: inherit; color: var(--text-muted); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.link-btn:hover { color: var(--text); }
.changelog h3 { font-size: 15px; margin: 18px 0 6px; }
.changelog h3:first-of-type { margin-top: 4px; }
.changelog ul { margin: 0; padding-left: 20px; }
.changelog li { margin: 4px 0; font-size: 14px; }
.changelog p { margin: 0 0 8px; font-size: 13.5px; }

.role-legend { display: grid; gap: 10px; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); font-size: 13.5px; color: var(--text-muted); }
.role-legend > div { display: grid; grid-template-columns: 84px 1fr; align-items: center; gap: 12px; }
.role-legend .badge { justify-self: start; }
/* role colours (after .badge so they win) */
.role-admin { background: #ebe9fe; color: #5925dc; }
.role-user { background: #d1e9ff; color: #175cd3; }
.role-viewer { background: #eaecf0; color: #475467; }
