/* Gloman portal design system.
 * Brand (GlomanBrain email layout): ink band, magenta "signal" rule, indigo links.
 * Light theme only. All text colours >= 4.5:1 on their background (ratios noted). */

:root {
  /* colour */
  --ink: #07060d;            /* top band, figures */
  --text: #16131e;           /* body text: 17.9:1 on white */
  --muted: #555067;          /* secondary text: 7.4:1 on white, 6.8:1 on --page */
  --page: #f3f2f6;           /* cool grey page, white surfaces sit on it */
  --surface: #ffffff;
  --rule: #dcd9e4;           /* hairlines, input borders on surface */
  --rule-strong: #8f89a1;    /* input borders: 3.4:1, non-text UI contrast >= 3:1 */
  --signal: #ff3ea5;         /* magenta: brand rule, active tab, primary button (ink text 6.6:1) */
  --signal-hover: #ff6ab9;
  --link: #363b7e;           /* indigo: 10.6:1 on white */
  --link-hover: #24285c;
  --focus: #363b7e;
  --on-ink: #ffffff;
  --on-ink-muted: #c8c3d6;   /* 11.6:1 on --ink */
  --danger: #a4161a;         /* 7.3:1 on white */
  --danger-bg: #fdecec;
  --ok: #1d6b40;             /* 6.4:1 on white */
  --ok-bg: #e9f5ee;
  --note-bg: #fff3d6;
  --note: #6b4a00;           /* 7.3:1 on --note-bg */

  /* type: system stack, 1.25 modular scale from 16px */
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial,
          "Noto Sans", sans-serif;
  --mono: ui-monospace, "Cascadia Mono", "Segoe UI Mono", Menlo, Consolas, monospace;
  --fs-xs: 0.8125rem;  /* 13 */
  --fs-sm: 0.875rem;   /* 14 */
  --fs-md: 1rem;       /* 16 */
  --fs-lg: 1.25rem;    /* 20 */
  --fs-xl: 1.5625rem;  /* 25 */
  --fs-2xl: 1.953rem;  /* 31 */
  --fs-fig: 2.441rem;  /* 39: KPI figures */

  /* space: 4px base */
  --s1: 0.25rem;
  --s2: 0.5rem;
  --s3: 0.75rem;
  --s4: 1rem;
  --s5: 1.5rem;
  --s6: 2rem;
  --s7: 3rem;

  /* radius: hierarchy, not one value everywhere */
  --r-control: 4px;
  --r-panel: 8px;

  --bar-h: 3.5rem;
  --content-max: 76rem;

  /* charts (read by static/js/charts.js): categorical series, all >= 3:1 on white */
  --series-1: #363b7e;       /* indigo (link colour) */
  --series-2: #d4237f;       /* deep magenta (signal, darkened for fills on white) */
  --series-3: #1c7c8c;       /* teal */
  --series-4: #c58a0e;       /* amber */
  --series-5: #7a58b0;       /* violet */
  --series-6: #3e8a5a;       /* green */
  --series-7: #4f86c6;       /* sky */
  --series-8: #8f89a1;       /* grey */
  --compare-line: #16131e;   /* dashed comparison line over bars */
  --total-fill: rgba(54, 59, 126, 0.12);
  --live-fill: rgba(255, 62, 165, 0.18);
  --live-ghost: #a39db5;     /* last week's line on the ink panel */
  --live-grid: rgba(255, 255, 255, 0.09);
}

/* ---- base ---------------------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--page);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--fs-md);
  line-height: 1.5;
}

[x-cloak] { display: none !important; }

h1, h2, h3 { color: var(--ink); line-height: 1.2; margin: 0 0 var(--s4); }
h1 { font-size: var(--fs-2xl); font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: var(--fs-lg); font-weight: 650; letter-spacing: -0.01em; }
h3 { font-size: var(--fs-md); font-weight: 650; }
p { margin: 0 0 var(--s4); max-width: 70ch; }

a { color: var(--link); text-underline-offset: 0.18em; }
a:hover { color: var(--link-hover); }

code {
  font-family: var(--mono);
  font-size: 0.9em;
  background: var(--page);
  border: 1px solid var(--rule);
  border-radius: var(--r-control);
  padding: 0.1em 0.35em;
  overflow-wrap: anywhere;
}

/* Figures line up in columns everywhere numbers appear. */
.num, td, .kpi-value { font-variant-numeric: tabular-nums; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: var(--s4);
  top: -3rem;
  z-index: 50;
  background: var(--surface);
  color: var(--link);
  padding: var(--s2) var(--s3);
  border-radius: var(--r-control);
}
.skip-link:focus { top: var(--s2); }

/* ---- top bar ------------------------------------------------------------------------- */

.topbar {
  background: var(--ink);
  color: var(--on-ink);
  border-bottom: 3px solid var(--signal);   /* the brand's signal rule */
  position: relative;
  z-index: 20;
}

.topbar-inner {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: 0 var(--s5);
  min-height: var(--bar-h);
  display: flex;
  align-items: center;
  gap: var(--s5);
}

.topbar :focus-visible { outline-color: var(--signal); }

.wordmark {
  display: inline-flex;
  align-items: center;
  flex: none;
  border-radius: var(--r-control);
}
.wordmark img { display: block; height: 1.6rem; width: auto; }

.topbar-context {
  display: flex;
  align-items: center;
  gap: var(--s2);
  min-width: 0;
  padding-left: var(--s4);
  border-left: 1px solid #3a3550;
  color: var(--on-ink);
  font-weight: 600;
  font-size: var(--fs-sm);
}
.topbar-context .client-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 16rem;
}
.role-badge {
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--ink);
  background: var(--signal);
  border-radius: 999px;
  padding: 0.05rem 0.55rem;
}

/* tabs sit on the signal rule: the active one is a magenta block flush with it */
.tabs {
  display: flex;
  align-self: stretch;
  gap: var(--s1);
  margin: 0;
  padding: 0;
  list-style: none;
}
.tabs li { display: flex; }
.tab {
  display: flex;
  align-items: center;
  gap: var(--s2);
  padding: 0 var(--s3);
  color: var(--on-ink-muted);
  text-decoration: none;
  font-size: var(--fs-sm);
  font-weight: 600;
  border-bottom: 4px solid transparent;
  margin-bottom: -3px;               /* overlap the bar's bottom border */
}
a.tab:hover { color: var(--on-ink); border-bottom-color: #5b5470; }
.tab[aria-current="page"] {
  color: var(--on-ink);
  border-bottom-color: var(--signal);
}
.tab.is-disabled { cursor: default; color: #a39db5; }   /* 7.3:1 on ink */
.soon {
  font-size: 0.6875rem;
  font-weight: 600;
  color: #d9d4e6;
  border: 1px solid #5b5470;
  border-radius: 999px;
  padding: 0 0.4rem;
  line-height: 1.35;
}

.topbar-end {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--s2);
}

/* dropdowns (Alpine "dropdown" component) */
.menu { position: relative; }
.menu-trigger {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  min-height: 2.25rem;
  padding: 0 var(--s3);
  background: transparent;
  color: var(--on-ink);
  border: 1px solid #3a3550;
  border-radius: var(--r-control);
  font: inherit;
  font-size: var(--fs-sm);
  font-weight: 600;
  cursor: pointer;
  max-width: 14rem;
}
.menu-trigger:hover { border-color: #6d6585; }
.menu-trigger .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.caret {
  width: 0; height: 0; flex: none;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid currentColor;
}
.menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + var(--s2));
  min-width: 13rem;
  max-height: 70vh;
  overflow-y: auto;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--rule);
  border-radius: var(--r-panel);
  box-shadow: 0 12px 32px -8px rgba(7, 6, 13, 0.35);
  padding: var(--s2);
  z-index: 30;
}
.menu-panel.align-start { left: 0; right: auto; }
.menu-panel :focus-visible { outline-color: var(--focus); }
.menu-heading {
  margin: 0;
  padding: var(--s2) var(--s3);
  font-size: var(--fs-xs);
  color: var(--muted);
}
.menu-item {
  display: block;
  width: 100%;
  padding: var(--s2) var(--s3);
  border: 0;
  border-radius: var(--r-control);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: var(--fs-sm);
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}
.menu-item:hover { background: var(--page); color: var(--ink); }
.menu-item[aria-current="true"], .menu-item[aria-current="page"] { font-weight: 650; color: var(--ink); }
.menu-item[aria-current="true"]::before, .menu-item[aria-current="page"]::before {
  content: "";
  display: inline-block;
  width: 6px; height: 6px;
  margin: 0 var(--s2) 0.1em 0;
  background: var(--signal);
  vertical-align: middle;
}
.menu-item.is-disabled { color: var(--muted); cursor: default; }
.menu-item .soon { color: var(--muted); border-color: var(--rule-strong); }
.menu-item.is-disabled:hover { background: transparent; }
.menu-sep { height: 1px; background: var(--rule); margin: var(--s2) 0; border: 0; }
.menu-panel form { margin: 0; }
.tabs-plain { list-style: none; margin: 0; padding: 0; }

.nav-toggle { display: none; }

/* impersonation banner: admin viewing a client's pages */
.viewing-as {
  background: var(--note-bg);
  color: var(--note);
  border-bottom: 1px solid #ecd9a6;
  font-size: var(--fs-sm);
}
.viewing-as .inner {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--s2) var(--s5);
  display: flex;
  flex-wrap: wrap;
  gap: var(--s2) var(--s4);
  align-items: center;
}
.viewing-as a, .viewing-as button.linklike { color: var(--note); font-weight: 650; }

/* ---- page frame ---------------------------------------------------------------------- */

.page {
  flex: 1;
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--s6) var(--s5) var(--s7);
}
.page-head { margin-bottom: var(--s5); }
.page-head h1 { margin-bottom: var(--s1); }
.page-head .lede { color: var(--muted); margin: 0; }

.site-foot {
  color: var(--muted);
  font-size: var(--fs-xs);
  border-top: 1px solid var(--rule);
}
.site-foot .inner {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--s4) var(--s5);
}
.site-foot p { margin: 0; }

/* ---- surfaces ------------------------------------------------------------------------ */

.panel {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-panel);
  padding: var(--s5);
}
.panel + .panel { margin-top: var(--s5); }
.panel > :last-child { margin-bottom: 0; }
.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s2) var(--s4);
  margin-bottom: var(--s4);
}
.panel-head h2 { margin: 0; }
.panel-head .status { font-size: var(--fs-sm); color: var(--muted); }

.stack > * + * { margin-top: var(--s5); }

/* KPI strip: figures first, label under; the figure is the loudest thing on a page */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
  gap: 1px;
  background: var(--rule);
  border: 1px solid var(--rule);
  border-radius: var(--r-panel);
  overflow: hidden;
  margin: 0 0 var(--s5);
}
.kpi {
  background: var(--surface);
  padding: var(--s4) var(--s5) var(--s5);
  margin: 0;
  min-width: 0;
}
.kpi-label { font-size: var(--fs-sm); color: var(--muted); margin: 0 0 var(--s2); }
.kpi-value {
  font-size: var(--fs-fig);
  font-weight: 750;
  letter-spacing: -0.03em;
  line-height: 1.05;
  color: var(--ink);
  margin: 0;
}
.kpi-unit { font-size: var(--fs-lg); font-weight: 600; letter-spacing: 0; margin-left: 0.2em; }
.kpi-meta { font-size: var(--fs-sm); color: var(--muted); margin: var(--s2) 0 0; }
.kpi.is-live { box-shadow: inset 0 3px 0 var(--signal); }
.delta-up { color: var(--ok); }
.delta-down { color: var(--danger); }

/* tables */
.table-wrap { overflow-x: auto; position: relative; } /* contains visually-hidden (absolute) labels */
table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
th, td { padding: var(--s2) var(--s3); text-align: left; border-bottom: 1px solid var(--rule); }
th { color: var(--muted); font-weight: 600; white-space: nowrap; }
td.num, th.num { text-align: right; }
tfoot td { font-weight: 700; color: var(--ink); border-bottom: 0; border-top: 2px solid var(--ink); }

/* ---- messages ------------------------------------------------------------------------ */

.flash, .alert {
  border-radius: var(--r-control);
  padding: var(--s3) var(--s4);
  margin: 0 0 var(--s5);
  font-size: var(--fs-sm);
  border-left: 4px solid;
  max-width: none;
}
.flash { background: var(--ok-bg); color: var(--ok); border-color: var(--ok); }
.alert-error { background: var(--danger-bg); color: var(--danger); border-color: var(--danger); }
.alert-note { background: var(--note-bg); color: var(--note); border-color: #c9962a; }

/* ---- forms --------------------------------------------------------------------------- */

.form { display: grid; gap: var(--s4); max-width: 26rem; }
.field { display: grid; gap: var(--s1); }
.field label { font-size: var(--fs-sm); font-weight: 600; color: var(--ink); }
.field .hint { font-size: var(--fs-xs); color: var(--muted); }

input[type="text"], input[type="password"], input[type="email"], input[type="number"],
input[type="search"], input[type="date"], input[type="datetime-local"], select, textarea {
  width: 100%;
  min-height: 2.75rem;
  padding: var(--s2) var(--s3);
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--rule-strong);
  border-radius: var(--r-control);
}
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 0;
  border-color: var(--focus);
}
input.code-input {
  font-family: var(--mono);
  font-size: var(--fs-lg);
  letter-spacing: 0.3em;
  max-width: 12rem;
  font-variant-numeric: tabular-nums;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  min-height: 2.75rem;
  padding: 0 var(--s5);
  font: inherit;
  font-weight: 700;
  font-size: var(--fs-sm);
  border-radius: var(--r-control);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
}
.btn-primary { background: var(--signal); color: var(--ink); }
.btn-primary:hover { background: var(--signal-hover); color: var(--ink); }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--rule-strong); }
.btn-secondary:hover { border-color: var(--ink); color: var(--ink); }
.btn-danger { background: var(--surface); color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger-bg); }
.btn-quiet {
  background: transparent;
  color: var(--link);
  padding: 0 var(--s2);
  text-decoration: underline;
  text-underline-offset: 0.18em;
}
.btn-quiet:hover { color: var(--link-hover); }
.btn-block { width: 100%; }
.form-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s3); }

button.linklike {
  background: none; border: 0; padding: 0;
  font: inherit; color: var(--link); text-decoration: underline; cursor: pointer;
}

/* htmx: we set includeIndicatorStyles=false (CSP), so the indicator rules live here */
.htmx-indicator { opacity: 0; transition: opacity 150ms ease-in; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }

/* ---- sign-in (bare layout) ----------------------------------------------------------- */

.auth {
  flex: 1;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: clamp(var(--s5), 8vh, 6rem) var(--s4) var(--s7);
}
.auth-card {
  width: 100%;
  max-width: 25rem;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-panel);
  padding: var(--s6);
  box-shadow: 0 1px 0 var(--rule);
}
.auth-card h1 { font-size: var(--fs-xl); margin-bottom: var(--s2); }
.auth-card .lede { color: var(--muted); font-size: var(--fs-sm); margin-bottom: var(--s5); }
.auth-card .form { max-width: none; }
.auth-foot {
  margin: var(--s5) 0 0;
  padding-top: var(--s4);
  border-top: 1px solid var(--rule);
  font-size: var(--fs-sm);
  color: var(--muted);
}
.auth-foot form { display: inline; }

/* account page: two columns of settings on wide screens */
.settings {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 24rem), 1fr));
  gap: var(--s5);
  align-items: start;
}
.settings .panel + .panel { margin-top: 0; }
.secret-block { display: grid; gap: var(--s2); margin-bottom: var(--s4); }
.secret-block dt { font-size: var(--fs-xs); color: var(--muted); }
.secret-block dd { margin: 0 0 var(--s2); }
.state-line { display: flex; align-items: center; gap: var(--s2); font-weight: 600; }
.state-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--rule-strong); flex: none; }
.state-dot.on { background: var(--ok); }

/* ---- client pages -------------------------------------------------------------------- */

.page-head-split {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--s2) var(--s5);
}
.as-of {
  margin: 0;
  font-size: var(--fs-sm);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.as-of time { color: var(--ink); font-weight: 650; }

/* Live: the one ink surface below the top bar, a monitor-style strip with the on-air figure
   on the left and today's curve against last week's on the right. */
.live-panel {
  display: grid;
  grid-template-columns: minmax(13rem, 17rem) 1fr;
  gap: var(--s5);
  background: var(--ink);
  color: var(--on-ink);
  border-radius: var(--r-panel);
  padding: var(--s5);
  margin: 0 0 var(--s5);
  border-top: 3px solid var(--signal);
}
.live-figure { display: flex; flex-direction: column; justify-content: center; min-width: 0; }
.live-label {
  display: flex;
  align-items: center;
  gap: var(--s2);
  margin: 0 0 var(--s2);
  font-size: var(--fs-sm);
  font-weight: 650;
  color: var(--on-ink-muted);
  letter-spacing: 0;
}
.on-air {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--signal);
  box-shadow: 0 0 0 0 rgba(255, 62, 165, 0.6);
  animation: on-air 2.4s ease-out infinite;
}
@keyframes on-air {
  0% { box-shadow: 0 0 0 0 rgba(255, 62, 165, 0.55); }
  70%, 100% { box-shadow: 0 0 0 9px rgba(255, 62, 165, 0); }
}
@media (prefers-reduced-motion: reduce) { .on-air { animation: none; } }
.live-value {
  margin: 0;
  font-size: clamp(2.6rem, 5vw, 3.6rem);
  font-weight: 750;
  letter-spacing: -0.035em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  color: var(--on-ink);
}
.live-value .kpi-unit { color: var(--on-ink-muted); }
.live-meta { margin: var(--s3) 0 0; font-size: var(--fs-xs); color: var(--on-ink-muted); }
.live-chart { min-width: 0; display: flex; flex-direction: column; gap: var(--s2); }

.legend {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: var(--s1) var(--s4);
  font-size: var(--fs-xs);
}
.live-panel .legend { color: var(--on-ink-muted); }
.legend li { display: inline-flex; align-items: center; gap: var(--s2); }
.swatch { display: inline-block; width: 16px; height: 0; border-top: 2px solid; flex: none; vertical-align: middle; }
.swatch-live { border-top-color: var(--signal); border-top-width: 3px; }
.swatch-ghost { border-top: 2px dashed var(--live-ghost); }
.panel .swatch-ghost { border-top-color: var(--compare-line); margin-right: var(--s2); }
.swatch-block {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 2px;
  background: var(--signal);
  margin-right: var(--s2);
  vertical-align: -0.05em;
}

.chart-box { position: relative; min-width: 0; }
.chart-box canvas { display: block; width: 100%; }
.chart-box canvas[hidden] { display: none; }
.chart-live { height: 13rem; }
.chart-months { height: 15rem; }
.chart-consumption { height: 20rem; }
.chart-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  margin: 0;
  max-width: none;
  font-size: var(--fs-sm);
  color: var(--muted);
  border: 1px dashed var(--rule-strong);
  border-radius: var(--r-control);
}
.chart-empty[hidden] { display: none; }
.live-panel .chart-empty { color: var(--on-ink-muted); border-color: #3a3550; }

/* KPI extras */
.kpi .kpi-label { font-weight: 500; letter-spacing: 0; }
.kpi-value .fig, .live-value .fig { font-variant-numeric: tabular-nums; }
.kpi-compare {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 var(--s2);
  margin: var(--s3) 0 0;
  padding-top: var(--s3);
  border-top: 1px solid var(--rule);
  font-size: var(--fs-sm);
}
.kpi-vs { color: var(--muted); }
.delta { font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.delta-flat { color: var(--muted); }

.overview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 26rem), 1fr));
  gap: var(--s5);
  align-items: start;
}
.overview-grid .panel + .panel { margin-top: 0; }

/* data tables: row labels left, figures right, a share meter in between */
.data-table th[scope="row"] { color: var(--text); font-weight: 600; white-space: normal; }
.data-table tbody tr:hover { background: #faf9fc; }
.data-table td.num, .data-table th.num { white-space: nowrap; }
.data-table tfoot th[scope="row"] {
  font-weight: 700;
  color: var(--ink);
  border-bottom: 0;
  border-top: 2px solid var(--ink);
}
.results-notice { margin: 0 0 var(--s4); }
.empty-row { text-align: center; color: var(--muted); padding: var(--s5) var(--s3); }
.table-note { margin: var(--s3) 0 0; font-size: var(--fs-xs); color: var(--muted); }
.row-key {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 2px;
  margin-right: var(--s2);
  vertical-align: -0.05em;
  background: var(--series-1);
}
.row-key[data-series="1"] { background: var(--series-2); }
.row-key[data-series="2"] { background: var(--series-3); }
.row-key[data-series="3"] { background: var(--series-4); }
.row-key[data-series="4"] { background: var(--series-5); }
.row-key[data-series="5"] { background: var(--series-6); }
.row-key[data-series="6"] { background: var(--series-7); }
.row-key[data-series="7"] { background: var(--series-8); }

.share { display: inline-flex; align-items: center; justify-content: flex-end; gap: var(--s2); }
.share-text { min-width: 3.6em; text-align: right; }
.share-bar {
  width: 4.5rem;
  height: 6px;
  border: 0;
  border-radius: 3px;
  background: var(--page);
  -webkit-appearance: none;
  appearance: none;
}
.share-bar::-webkit-meter-bar { background: var(--page); border: 0; border-radius: 3px; height: 6px; }
.share-bar::-webkit-meter-optimum-value,
.share-bar::-webkit-meter-suboptimum-value,
.share-bar::-webkit-meter-even-less-good-value { background: var(--series-1); border-radius: 3px; }
.share-bar::-moz-meter-bar { background: var(--series-1); border-radius: 3px; }

details.as-table { margin-top: var(--s4); font-size: var(--fs-sm); }
details.as-table summary { cursor: pointer; color: var(--link); font-weight: 600; }
details.as-table[open] summary { margin-bottom: var(--s2); }

/* consumption filters */
.filters {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-panel);
  padding: var(--s4) var(--s5);
  margin: 0 0 var(--s5);
  display: grid;
  gap: var(--s4);
}
.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s3) var(--s4);
  align-items: flex-end;
}
.filter-row > .field { flex: 1 1 11rem; max-width: 16rem; }
.field-pair { display: flex; gap: var(--s3); flex: 2 1 18rem; max-width: 22rem; }
.field-pair .field { flex: 1; }
.filter-groups {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s2);
  padding-top: var(--s4);
  border-top: 1px solid var(--rule);
}
.filter-heading { font-size: var(--fs-sm); font-weight: 600; color: var(--ink); margin-right: var(--s2); }
.filter-group { border: 0; margin: 0; padding: 0; min-width: 0; position: relative; }
.filter-group:disabled { opacity: 0.45; }
.filter-group:disabled summary { cursor: not-allowed; }
details.filter > summary {
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  min-height: 2.5rem;
  padding: 0 var(--s3);
  border: 1px solid var(--rule-strong);
  border-radius: 999px;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--ink);
  background: var(--surface);
  cursor: pointer;
  user-select: none;
}
details.filter > summary::-webkit-details-marker { display: none; }
details.filter > summary::after {
  content: "";
  width: 0; height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid currentColor;
}
details.filter[open] > summary { border-color: var(--ink); }
details.filter > summary:hover { border-color: var(--ink); }
.filter-count { font-weight: 500; color: var(--muted); font-variant-numeric: tabular-nums; }
.filter-options {
  position: absolute;
  left: 0;
  top: calc(100% + var(--s1));
  z-index: 15;
  min-width: 15rem;
  max-width: min(24rem, calc(100vw - 2rem));
  max-height: 18rem;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-panel);
  box-shadow: 0 12px 32px -8px rgba(7, 6, 13, 0.3);
  padding: var(--s2);
}
.check {
  display: flex;
  align-items: flex-start;
  gap: var(--s2);
  padding: var(--s2);
  border-radius: var(--r-control);
  font-size: var(--fs-sm);
  cursor: pointer;
}
.check:hover { background: var(--page); }
.check input { margin: 0.2em 0 0; width: 1rem; height: 1rem; accent-color: var(--series-1); flex: none; }
.check-label { overflow-wrap: anywhere; }
.check-note { display: block; font-size: var(--fs-xs); color: var(--muted); }
.filter-none { margin: 0; padding: var(--s2); font-size: var(--fs-sm); color: var(--muted); }
.filter-clear { font-size: var(--fs-sm); margin-left: auto; }
.filter-hint { margin: 0; font-size: var(--fs-xs); color: var(--muted); }

/* results */
.results { transition: opacity 150ms ease-in; }
.results.htmx-request { opacity: 0.55; }
.result-head { margin: 0 0 var(--s5); }
.result-total {
  display: inline-block;
  min-width: min(100%, 20rem);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-panel);
  padding: var(--s4) var(--s5);
  box-shadow: inset 0 3px 0 var(--series-1);
}
.result-total .kpi-label { font-weight: 500; }
.results-error p { margin: 0; }
.results-error p + p { margin-top: var(--s2); }
.results-error a { color: var(--danger); font-weight: 650; }
.chart-panel .panel-head .status { display: inline-flex; align-items: center; }

/* ---- admin pages --------------------------------------------------------------------- */

h4 { color: var(--ink); line-height: 1.2; margin: 0; font-size: var(--fs-md); font-weight: 650; }
.muted { color: var(--muted); }
.crumb { margin: 0 0 var(--s2); font-size: var(--fs-sm); }

/* badges: text always says what it means, colour only reinforces it (4.5:1 or better) */
.badge {
  display: inline-block;
  padding: 0.1rem 0.55rem;
  font-size: var(--fs-xs);
  font-weight: 650;
  line-height: 1.5;
  border: 1px solid var(--rule-strong);
  border-radius: 999px;
  background: var(--page);
  color: var(--text);
  vertical-align: baseline;
}
.badge-warn { background: var(--note-bg); color: var(--note); border-color: #c9962a; }
.badge-info { background: #eceefa; color: var(--link); border-color: #b9bde0; }
.badges { display: flex; flex-wrap: wrap; gap: var(--s1) var(--s2); }
.badges .muted { font-size: var(--fs-sm); }
.warn-line { margin: var(--s1) 0 0; }

.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: var(--s4);
  margin-bottom: var(--s5);
}
.stat {
  display: flex;
  flex-direction: column;
  gap: var(--s1);
  padding: var(--s4) var(--s5);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-panel);
  color: var(--text);
  text-decoration: none;
}
a.stat:hover { border-color: var(--ink); }
.stat-value { font-size: var(--fs-xl); font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat-label { font-size: var(--fs-sm); color: var(--muted); }
.stat-warn { box-shadow: inset 0 3px 0 #c9962a; }

/* narrow screens scroll the table sideways instead of crushing its columns */
.admin-table { min-width: 38rem; }
.admin-table th[scope="row"] a { font-weight: 650; }
.admin-table code { margin-left: var(--s1); }
.admin-table td { vertical-align: top; }
.admin-table th[scope="row"] { vertical-align: top; }

.form-wide { max-width: 40rem; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr)); gap: var(--s4); }
.field-error {
  margin: var(--s1) 0 0;
  padding: var(--s1) var(--s3);
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--danger);
  background: var(--danger-bg);
  border-left: 3px solid var(--danger);
  border-radius: var(--r-control);
}
input[aria-invalid="true"] { border-color: var(--danger); border-width: 2px; }

.toggles { display: grid; gap: var(--s3); }
.toggle { display: flex; align-items: flex-start; gap: var(--s3); cursor: pointer; }
.toggle input { width: 1.125rem; height: 1.125rem; margin: 0.2rem 0 0; flex: none; accent-color: var(--link); }
.toggle-title { display: block; font-weight: 600; color: var(--ink); font-size: var(--fs-sm); }
.toggle .hint { display: block; font-size: var(--fs-xs); color: var(--muted); }

.inline-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--s3); margin: 0; }
.inline-form .field { flex: 1 1 14rem; min-width: 0; }
.inline-form > p { flex: 1 1 100%; margin: 0; }
.inline-form input[type="text"], .inline-form select { min-height: 2.5rem; }
.admin-table .inline-form { flex-wrap: nowrap; align-items: center; }
.admin-table .inline-form input[type="text"] { min-width: 10rem; }
.btn-compact { min-height: 2.5rem; padding: 0 var(--s4); }

/* structure tree: category panels hold services, services hold their sources */
.structure { margin-top: var(--s6); }
.structure-head { align-items: baseline; margin-bottom: var(--s3); }
.structure .panel { margin-top: var(--s4); }
.structure .panel + .panel { margin-top: var(--s4); }
.category > .panel-head { padding-bottom: var(--s3); border-bottom: 2px solid var(--ink); }
.category > .panel-head h3 { font-size: var(--fs-lg); margin: 0; }
.service { padding: var(--s4) 0; border-bottom: 1px solid var(--rule); }
.service-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--s1) var(--s4); margin-bottom: var(--s2); }
.service-head .status { font-size: var(--fs-xs); color: var(--muted); }
.service-empty { margin: 0 0 var(--s2); font-size: var(--fs-sm); }
.service .table-wrap { margin-bottom: var(--s2); }

.tools { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s4); align-items: flex-start; }
.tools-category { padding-top: var(--s4); }
.tool { flex: 0 1 auto; }
.tool[open] { flex: 1 1 100%; padding: var(--s3) var(--s4); background: var(--page); border-radius: var(--r-control); }
.tool > summary {
  display: inline-block;
  padding: var(--s1) 0;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--link);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 0.18em;
}
.tool > summary:hover { color: var(--link-hover); }
.tool > summary:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.tool-danger > summary { color: var(--danger); }
.tool[open] > summary { margin-bottom: var(--s2); }
.tool > p { font-size: var(--fs-sm); margin: 0; }
.tool .inline-form > p { margin-bottom: var(--s1); }

/* sources, inflation, prices, costs: dense tables with the row's controls in their cells */
select[aria-invalid="true"] { border-color: var(--danger); border-width: 2px; }
.badge-plain { background: var(--surface); color: var(--ink); }
.cell-note { margin: var(--s1) 0 0; font-size: var(--fs-xs); color: var(--muted); }
.admin-table .key { margin-left: 0; font-size: var(--fs-xs); color: var(--muted); }
.admin-table .host { font-weight: 600; color: var(--ink); overflow-wrap: anywhere; }
.admin-table select, .admin-table input[type="text"] { min-height: 2.25rem; max-width: 16rem; }
.admin-table .tool .inline-form { flex-wrap: wrap; min-width: 16rem; }
.admin-table .tool[open] { padding: var(--s2) var(--s3); }
.admin-table .tool .inline-form > p { font-size: var(--fs-sm); }
.row-error td { padding-top: 0; border-top: 0; }
.toggle-inline { align-self: center; align-items: center; }
.toggle-inline input { margin: 0; }
.sources-table { min-width: 60rem; }

/* accounts: checkbox groups and the one-time password */
.account-form .field { align-content: start; }
fieldset.field { border: 0; padding: 0; margin: 0; min-width: 0; }
fieldset.field legend { padding: 0; margin-bottom: var(--s2); font-size: var(--fs-sm); font-weight: 600; color: var(--ink); }
fieldset.field .toggles { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s5); }
.one-time { border-left: 4px solid var(--signal); }
.one-time-value { margin: var(--s2) 0 var(--s3); }
.one-time-value code {
  display: inline-block;
  padding: var(--s2) var(--s3);
  font-size: 1.25rem;
  letter-spacing: 0.04em;
  background: var(--page);
  border: 1px dashed var(--rule-strong);
  border-radius: var(--r-control);
  user-select: all;
  overflow-wrap: anywhere;
}
.view-as-form { margin: 0; }
.page-head .view-as-form { margin-top: var(--s3); }
.viewing-as form { margin: 0; }
.lock-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s2); }
.lock-list li { display: flex; flex-wrap: wrap; gap: var(--s1) var(--s3); align-items: baseline; }

/* collectors and diagnostic volumes */
.config-list { list-style: none; margin: var(--s3) 0 0; padding: 0; display: grid; gap: var(--s1); }
.badge-ok { background: var(--ok-bg); color: var(--ok); border-color: #9fcfb3; }
.collector-table { min-width: 58rem; }
.collector-table th[scope="row"] code { margin-left: 0; white-space: nowrap; }
.collector-table .when { white-space: nowrap; }
.collector-table .err { min-width: 16rem; max-width: 26rem; overflow-wrap: anywhere; }
.collector-table .badge { white-space: nowrap; }
.collector-table .badge + .badge { margin-top: var(--s1); }
.volumes-table { min-width: 34rem; }

/* ---- responsive ---------------------------------------------------------------------- */

/* the admin bar has eleven tabs: they collapse into the Menu button earlier than the client bar's */
.topbar--admin .topbar-context { flex: none; }
@media (max-width: 78rem) {
  .topbar--admin .tabs-desktop { display: none; }
  .topbar--admin .nav-toggle { display: block; }
  .topbar--admin .menu-panel.nav-panel {
    position: fixed;
    left: 0; right: 0;
    top: calc(var(--bar-h) + 3px);
    border-radius: 0;
    border-width: 0 0 1px;
    max-height: calc(100vh - var(--bar-h));
  }
}

@media (max-width: 52rem) {
  .topbar-inner { gap: var(--s3); padding: 0 var(--s4); }
  .tabs-desktop { display: none; }
  .nav-toggle { display: block; }
  .menu-panel.nav-panel {
    position: fixed;
    left: 0; right: 0;
    top: calc(var(--bar-h) + 3px);
    border-radius: 0;
    border-width: 0 0 1px;
    max-height: calc(100vh - var(--bar-h));
  }
  .topbar-context .client-name { max-width: 9rem; }
  .page { padding: var(--s5) var(--s4) var(--s6); }
  .viewing-as .inner, .site-foot .inner { padding-left: var(--s4); padding-right: var(--s4); }
  .live-panel { grid-template-columns: 1fr; gap: var(--s4); padding: var(--s4); }
  .filters { padding: var(--s4); }
}

@media (max-width: 40rem) {
  .filter-row > .field, .field-pair { flex: 1 1 100%; max-width: none; }
  .share-bar { display: none; }
  .chart-consumption { height: 16rem; }
  .chart-live { height: 11rem; }
  .filter-clear { margin-left: 0; }
  .result-total { display: block; }
  .data-table th, .data-table td { padding-left: var(--s2); padding-right: var(--s2); }
  .data-table th[scope="row"] { min-width: 8rem; }
  /* filter panels open full width under the pills instead of off-screen */
  .filter-groups { position: relative; }
  .filter-group { position: static; }
  .filter-options { left: 0; right: 0; max-width: none; min-width: 0; }
}

@media (max-width: 30rem) {
  .topbar-context { display: none; }
  .menu-trigger .label { max-width: 6.5rem; }
  .panel { padding: var(--s4); }
  .auth-card { padding: var(--s5) var(--s4); }
  h1 { font-size: var(--fs-xl); }
  .kpi-value { font-size: var(--fs-2xl); }
}

/* sources: grouped mapping view */
.view-switch { margin: var(--s3) 0; color: var(--muted); font-size: var(--fs-sm); }
.groups-table { min-width: 46rem; }
.group-members { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s1); }
.group-members .cell-note { display: inline; }
.save-bar {
  position: sticky; bottom: 0; display: flex; flex-wrap: wrap; align-items: center;
  gap: var(--s3); padding: var(--s3) 0; background: var(--page); border-top: 1px solid var(--rule);
}
.save-bar .status { flex: 1 1 18rem; }

/* admin client page: compact structure */
.structure-links { margin: 0 0 var(--s3); }
.category > summary { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: var(--s2); cursor: pointer; list-style: none; }
.category > summary::-webkit-details-marker { display: none; }
.category > summary h3 { display: inline; margin: 0; }
.category > summary::before { content: "\25B8"; margin-right: var(--s2); color: var(--muted); }
.category[open] > summary::before { content: "\25BE"; }
.structure-table { min-width: 44rem; }
.host-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s1); }
.row-menu > summary { cursor: pointer; color: var(--link); font-weight: 600; font-size: var(--fs-sm); }
.row-menu > :not(summary) { margin-top: var(--s3); }
.category-menu { margin-top: var(--s3); }
.danger-zone { border-top: 1px solid var(--rule); padding-top: var(--s3); }
.add-row td { background: var(--page); }
