:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #16202c;
  --muted: #5d6b7a;
  --line: #dde2e8;
  --brand: #152f4e;
  --brand-2: #24507f;
  --link: #1d5fa6;
  --ok: #1d7a46;       --ok-bg: #e3f4ea;
  --warn: #9a5b00;     --warn-bg: #fdf1dc;
  --crit: #b3261e;     --crit-bg: #fbe4e2;
  --data: #4b4fb0;     --data-bg: #e9eafb;
  --neutral: #55606c;  --neutral-bg: #eceff2;
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141a; --surface: #161d25; --surface-2: #1d2630; --text: #e4e9ef; --muted: #93a1b0;
    --line: #2a3541; --brand: #8fb4dd; --brand-2: #6d9ccf; --link: #7fb2ea;
    --ok: #62c98f; --ok-bg: #173325; --warn: #f0b75a; --warn-bg: #3a2d14;
    --crit: #f08a82; --crit-bg: #3d1c1a; --data: #a3a6f2; --data-bg: #25264a;
    --neutral: #a3adb8; --neutral-bg: #242d37;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-size: 12px; background: var(--surface-2); padding: 1px 4px; border-radius: 4px; }
h1 { font-size: 22px; margin: 0 0 2px; }
h2 { font-size: 16px; margin: 24px 0 10px; }
h3 { font-size: 14px; margin: 16px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.err { color: var(--crit); }
.inline { display: inline; }

.topbar { display: flex; align-items: center; gap: 24px; padding: 0 20px; height: 52px;
  background: var(--brand); color: #fff; position: sticky; top: 0; z-index: 20; }
@media (prefers-color-scheme: dark) { .topbar { background: #10263f; } }
.brand { color: #fff; font-weight: 650; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand-mark { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 6px;
  background: #fff; color: #152f4e; font-size: 11px; font-weight: 800; }
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.nav a { color: #cfdcec; padding: 6px 10px; border-radius: 6px; white-space: nowrap; }
.nav a:hover { background: rgba(255,255,255,.08); text-decoration: none; }
.nav a.active { color: #fff; background: rgba(255,255,255,.14); }
.userbox { display: flex; gap: 12px; align-items: center; white-space: nowrap; }
.userbox a, .userbox .linklike { color: #cfdcec; }
.readonly-note { background: var(--surface-2); color: var(--muted); font-size: 12px; padding: 4px 20px; border-bottom: 1px solid var(--line); }

.page { padding: 20px; max-width: 1680px; margin: 0 auto; }
.foot { text-align: center; font-size: 12px; padding: 24px; }
.pagehead { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 14px; }
.crumbs { margin: 0 0 2px; font-size: 12px; color: var(--muted); }
.flash { background: var(--ok-bg); color: var(--ok); padding: 8px 12px; border-radius: var(--radius); margin-bottom: 12px; }
.error { background: var(--crit-bg); color: var(--crit); padding: 8px 12px; border-radius: var(--radius); margin-bottom: 12px; }
.empty { color: var(--muted); padding: 14px; text-align: center; }

.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface);
  color: var(--text); padding: 6px 12px; border-radius: 6px; font: inherit; cursor: pointer; }
.btn:hover { border-color: var(--brand-2); text-decoration: none; }
.btn-primary { background: var(--brand-2); border-color: var(--brand-2); color: #fff; }
.btn-ghost { background: transparent; }
.btn-small { padding: 2px 8px; font-size: 12px; }
.linklike { background: none; border: 0; padding: 0; font: inherit; color: var(--link); cursor: pointer; }
.linklike.danger { color: var(--crit); }

.monthnav { display: flex; gap: 6px; align-items: center; }
select, input, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line);
  border-radius: 6px; padding: 6px 8px; }
input[type=checkbox] { padding: 0; }

.syncbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 16px; }
.syncitem { display: flex; gap: 8px; flex-wrap: wrap; align-items: baseline; font-size: 12px; padding: 6px 10px;
  border-radius: 6px; border: 1px solid var(--line); background: var(--surface); }
.syncitem.is-ok { border-color: color-mix(in srgb, var(--ok) 35%, var(--line)); }
.syncitem.is-ok strong::before { content: "●"; color: var(--ok); margin-right: 5px; }
.syncitem.is-warn { border-color: var(--warn); background: var(--warn-bg); }
.syncitem.is-warn strong::before { content: "●"; color: var(--warn); margin-right: 5px; }
.syncitem.is-off { background: var(--data-bg); color: var(--data); border-color: transparent; }

.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(145px, 1fr)); gap: 10px; margin-bottom: 8px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px;
  display: flex; flex-direction: column; gap: 2px; border-top: 3px solid var(--line); }
.kpi-label { font-size: 12px; color: var(--muted); }
.kpi-value { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 11px; color: var(--muted); }
.kpi-ok { border-top-color: var(--ok); }
.kpi-attention { border-top-color: var(--warn); }
.kpi-critical { border-top-color: var(--crit); }
.kpi-data { border-top-color: var(--data); }
.kpis-compact .kpi-value { font-size: 18px; }
.count { font-size: 12px; background: var(--surface-2); padding: 1px 8px; border-radius: 10px; color: var(--muted); vertical-align: middle; }

.tablewrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table.grid { border-collapse: separate; border-spacing: 0; width: 100%; font-variant-numeric: tabular-nums; }
.grid th, .grid td { padding: 6px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; white-space: nowrap; }
.grid thead th { position: sticky; top: 0; background: var(--surface-2); font-size: 12px; font-weight: 600; color: var(--muted); z-index: 2; }
.grid thead th[data-sort] { cursor: pointer; user-select: none; }
.grid thead th[data-sort]:hover { color: var(--text); }
.grid thead th.sorted-asc::after { content: " ▲"; font-size: 9px; }
.grid thead th.sorted-desc::after { content: " ▼"; font-size: 9px; }
.grid td.num, .grid th.num { text-align: right; }
.grid tbody tr:hover td { background: color-mix(in srgb, var(--surface-2) 70%, transparent); }
.grid tr.section th { background: var(--surface); color: var(--brand); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; padding-top: 12px; }
.grid.compact td, .grid.compact th { padding: 4px 8px; }
.grid td.name { white-space: normal; min-width: 260px; max-width: 380px; }
.grid .sub { font-size: 11px; color: var(--muted); display: flex; gap: 4px; flex-wrap: wrap; }
td.num .sub { justify-content: flex-end; }
.sticky-col { position: sticky; left: 0; background: var(--surface); z-index: 1; }
thead .sticky-col { z-index: 3; background: var(--surface-2); }
tr.is-paused td { color: var(--muted); }
td.neg { color: var(--crit); }
.sub.neg { color: var(--crit); }
td.pos { color: var(--warn); }
td.warn { color: var(--warn); font-weight: 600; }
td.crit { color: var(--crit); font-weight: 600; }

.chip { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 10px; white-space: nowrap; }
.chip-ok { background: var(--ok-bg); color: var(--ok); }
.chip-attention { background: var(--warn-bg); color: var(--warn); }
.chip-critical_under, .chip-critical_over { background: var(--crit-bg); color: var(--crit); }
.chip-neutral { background: var(--neutral-bg); color: var(--neutral); }
.chip-data { background: var(--data-bg); color: var(--data); }
.tag { font-size: 10px; padding: 0 5px; border-radius: 4px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.tag-warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }

.bar { display: inline-block; width: 44px; height: 6px; background: var(--surface-2); border-radius: 3px; vertical-align: middle; overflow: hidden; margin-left: 4px; }
.bar-fill { display: block; height: 100%; width: 0; background: var(--brand-2); }
.bar.over .bar-fill { background: var(--crit); }

.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin: 14px 0 8px; }
.filterbar { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.filterbar input[type=search] { min-width: 220px; }
.fchip { border: 1px solid var(--line); background: var(--surface); color: var(--muted); border-radius: 14px; padding: 3px 10px; font: inherit; font-size: 12px; cursor: pointer; }
.fchip.active { background: var(--brand-2); border-color: var(--brand-2); color: #fff; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 16px; }
.card h2 { margin-top: 0; }
.card.narrow { max-width: 520px; }
.cols { display: grid; grid-template-columns: minmax(320px, 1fr) minmax(360px, 1.2fr); gap: 16px; }
@media (max-width: 980px) { .cols { grid-template-columns: 1fr; } }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.platformcard.is-ok { border-top: 3px solid var(--ok); }
.platformcard.is-warn { border-top: 3px solid var(--warn); }
.platformcard.is-off { border-top: 3px solid var(--data); }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-variant-numeric: tabular-nums; }
.form fieldset { border: 0; padding: 0; margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
form.form:not(:has(fieldset)) { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.form label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.form label.wide { grid-column: 1 / -1; }
.form .btn { justify-self: start; }
.check { display: inline-flex !important; flex-direction: row !important; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.row-gap { display: flex; gap: 16px; flex-wrap: wrap; align-items: center; }
ul.plain { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.sug { margin: 2px 0; }
.picker { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; align-items: end; }
.picker label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.picker-results { grid-column: 1 / -1; max-height: 320px; overflow: auto; border: 1px solid var(--line); border-radius: 6px; padding: 6px; }
.picker-results label { flex-direction: row; gap: 8px; align-items: baseline; color: var(--text); font-size: 13px; padding: 3px 4px; border-radius: 4px; }
.picker-results label:hover { background: var(--surface-2); }
.accountform { display: flex; gap: 6px; align-items: center; }

.loginpage { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; }
.login .brand { color: var(--brand); font-size: 18px; }
.login .brand-mark { background: var(--brand); color: #fff; }
.login label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.login p { margin: 0; }

@media (max-width: 720px) {
  .topbar { height: auto; flex-wrap: wrap; padding: 8px 16px; gap: 8px; }
  .page { padding: 16px; }
  .form fieldset, form.form:not(:has(fieldset)), .picker { grid-template-columns: 1fr; }
  .grid td.name { min-width: 200px; }
}

.targetcard .targethead { display: flex; align-items: center; gap: 12px; }
.targetcard .targethead h2 { margin: 0; }
.bigfour { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; margin: 12px 0; }
.bigfour .big { display: flex; flex-direction: column; gap: 3px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); }
.bigfour .kpi-value { font-size: 24px; }
.bigfour .small-value { font-size: 17px; }
.kpi-value.neg { color: var(--crit); }
.facts-inline { grid-template-columns: max-content 1fr max-content 1fr; }
@media (max-width: 900px) { .facts-inline { grid-template-columns: max-content 1fr; } }

/* ---- Plan vs actual (simplified operational view) ------------------------------------ */
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.ovhead { display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap; margin: 4px 0 18px; }
.ovhead h1 { font-size: 24px; }
.ovnote { margin: 0; color: var(--muted); font-size: 13px; }
.ovnote .err { font-weight: 600; }

.ovfilters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 16px; margin-bottom: 24px; }
.ovfilters label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.ovfilters select, .ovfilters input { min-width: 150px; }
.seg { display: inline-flex; margin-left: auto; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg a { padding: 6px 14px; color: var(--muted); font-size: 13px; }
.seg a + a { border-left: 1px solid var(--line); }
.seg a:hover { text-decoration: none; color: var(--text); }
.seg a.active { background: var(--brand-2); color: #fff; }

.ovsum { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-bottom: 28px; }
.ovcard { background: var(--surface); border-radius: 12px; padding: 18px 22px; box-shadow: 0 1px 2px rgba(16, 24, 40, .06); }
.ovcard h2 { margin: 0 0 12px; font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.ovcard dl { display: grid; grid-template-columns: 1fr 1fr auto; gap: 12px; margin: 0; align-items: end; }
.ovcard dt { font-size: 12px; color: var(--muted); }
.ovcard dd { margin: 2px 0 0; font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ovcard .big dd { font-size: 30px; font-weight: 700; }
.ovcard .big { text-align: right; }

.sig i { font-style: normal; font-size: .7em; margin-left: 3px; vertical-align: .12em; }
.sig-bad { color: var(--crit); }
.sig-good { color: var(--ok); }
.sig-quiet { color: var(--muted); }

.ovtable { overflow-x: auto; background: var(--surface); border-radius: 12px; box-shadow: 0 1px 2px rgba(16, 24, 40, .06); }
table.ov th, table.ov td { padding: 10px 14px; border-bottom: 1px solid color-mix(in srgb, var(--line) 60%, transparent); vertical-align: middle; }
table.ov thead th { background: var(--surface); position: static; font-size: 12px; }
table.ov thead tr.groups th { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; text-align: center; padding-bottom: 2px; border-bottom: 0; color: var(--text); }
table.ov thead tr.groups th.name, table.ov thead tr.groups th:nth-child(2) { text-align: left; vertical-align: bottom; letter-spacing: 0; text-transform: none; font-size: 12px; color: var(--muted); padding-bottom: 10px; }
table.ov thead tr:last-child th { border-bottom: 1px solid var(--line); }
table.ov .gs { border-left: 1px solid color-mix(in srgb, var(--line) 70%, transparent); }
table.ov td.name, table.ov th.name { white-space: normal; min-width: 240px; max-width: 360px; position: sticky; left: 0; background: var(--surface); z-index: 1; }
table.ov td.name a { color: var(--text); }
table.ov td.name a:hover { color: var(--link); }
table.ov tbody tr:hover td, table.ov tbody tr:hover th { background: var(--surface-2); }
table.ov tr.client th, table.ov tr.client td { font-weight: 700; background: var(--surface-2); padding-top: 12px; padding-bottom: 12px; }
table.ov tr.client th a { color: var(--brand); }
table.ov tr.is-outside td { color: var(--muted); font-style: italic; }
table.ov tr.is-outside td.name a { color: var(--muted); }
table.ov tr.is-idle td { color: var(--muted); }
.details-head { margin-top: 44px; padding-top: 16px; border-top: 1px solid var(--line); font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }

@media (max-width: 1100px) {
  .ovsum { grid-template-columns: 1fr; }
  .ovcard dl { grid-template-columns: 1fr 1fr 1fr; }
}
@media (max-width: 720px) {
  .seg { margin-left: 0; }
  .ovfilters select, .ovfilters input { min-width: 0; width: 100%; }
  .ovfilters label { flex: 1 1 140px; }
  .ovcard dd { font-size: 17px; }
  .ovcard .big dd { font-size: 24px; }
  table.ov td.name, table.ov th.name { min-width: 160px; }
  table.ov th, table.ov td { padding: 8px 10px; }
}
table.ov td.name .sect { display: block; font-size: 11px; color: var(--muted); letter-spacing: .02em; }

/* account breakdown under the card actuals: our account + client account = total */
.ovcard .bd { list-style: none; margin: 14px 0 0; padding: 10px 0 0; border-top: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
  display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.ovcard .bd li { display: flex; justify-content: space-between; gap: 12px; }
.ovcard .bd li b { font-weight: 600; color: var(--text); }
.ovcard .bd .v { font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--text); }
.ovcard .bd li.sum { margin-top: 2px; padding-top: 4px; border-top: 1px dashed var(--line); font-weight: 600; color: var(--text); }

/* CLIENT -> PLATFORM -> ACCOUNT sections */
table.ov tr.plat th { background: var(--surface); color: var(--brand); font-size: 11px; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; padding-top: 18px; padding-bottom: 6px; }
table.ov tr.acct th, table.ov tr.acct td { font-weight: 600; background: color-mix(in srgb, var(--surface-2) 55%, var(--surface)); }
table.ov tr.acct th .own { display: block; font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--brand-2); }
table.ov tr.ptotal th, table.ov tr.ptotal td { font-weight: 700; border-top: 2px solid var(--line); background: var(--surface); }
table.ov tr.r td.name { padding-left: 26px; }

/* sortable headers: whole header is the link, subtle arrow only when active */
table.ov th.sortable a { color: inherit; display: inline-flex; align-items: center; gap: 3px; cursor: pointer; }
table.ov th.sortable a:hover, table.ov th.sortable a:focus-visible { color: var(--text); text-decoration: none; }
table.ov th.sortable a:focus-visible { outline: 2px solid var(--brand-2); outline-offset: 2px; border-radius: 3px; }
table.ov th.num.sortable a { justify-content: flex-end; }
table.ov th .si { font-size: 10px; opacity: .35; }
table.ov th.sortable a:hover .si { opacity: .7; }
table.ov th.sorted a { color: var(--text); }
table.ov th.sorted .si { opacity: 1; color: var(--brand-2); }

/* inline plan editing */
button.pe { font: inherit; color: inherit; background: none; border: 0; padding: 1px 3px; margin: -1px -3px; cursor: text;
  border-radius: 4px; border-bottom: 1px dashed transparent; font-variant-numeric: tabular-nums; }
button.pe:hover, button.pe:focus-visible { border-bottom-color: var(--brand-2); background: var(--surface-2); outline: none; }
tr.is-adhoc button.pe { color: var(--link); }
input.pe-input { width: 96px; text-align: right; padding: 2px 6px; font: inherit; }
input.pe-input.invalid { border-color: var(--crit); }
.pe-msg { display: block; font-size: 11px; color: var(--crit); white-space: normal; max-width: 180px; margin-left: auto; }
td.saving { opacity: .6; }

/* ad hoc (promoted posts) inside an account section */
table.ov tr.adh th { font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
  padding: 10px 14px 4px 26px; background: var(--surface); }
.ovcard .plansplit { margin: 10px 0 0; font-size: 12px; color: var(--muted); }
.ovcard .plansplit b { color: var(--text); font-weight: 600; }

/* lifetime / project budgets */
.projects { margin-bottom: 36px; }
.phead { font-size: 15px; margin: 8px 0 14px; }
.phead .muted { font-weight: 400; font-size: 13px; }
.pcards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; margin-bottom: 20px; }
.pcard .pperiod { margin: -6px 0 12px; font-size: 12px; color: var(--muted); }
.pcard.total { background: color-mix(in srgb, var(--surface-2) 45%, var(--surface)); }
.warnt { color: var(--warn); }
table.pt .unit { font-size: 10px; color: var(--muted); }
table.pt tr.camp td { font-size: 12px; color: var(--muted); padding-top: 3px; padding-bottom: 3px; border-bottom: 0; }
table.pt tr.camp td.name { padding-left: 42px; }
.pcard .pmeta { margin: 10px 0 0; font-size: 12px; color: var(--muted); }
.pcard .pmeta b { color: var(--text); font-weight: 600; }
.nodata { color: var(--warn); font-style: italic; font-size: 12px; }
.phead.sub { font-size: 14px; margin: 26px 0 10px; }
.pall { margin: 18px 0 0; font-size: 13px; color: var(--muted); }
.pall b { color: var(--text); }
