/* Xweather usage stats. Palette = the validated dataviz reference palette (light + dark steps).
   Product colours: slot 1 Weather API (blue), slot 2 Raster Maps (orange), slot 3 MapsGL (aqua).
   Text never wears a series colour; identity is carried by dots, bars and lines. */

:root {
  color-scheme: light;
  --page: #f4f4f1;
  --surface-1: #fcfcfb;
  --surface-2: #f6f6f3;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.08);
  --border-strong: rgba(11, 11, 11, 0.14);
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04), 0 2px 8px rgba(11, 11, 11, 0.04);
  --wash: rgba(42, 120, 214, 0.08);
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --critical: #d03b3b;
  --link: #1c5cab;
  --meter-track: #cde2fb;
  --sidebar: #111827;
  --sidebar-ink: #c9cdd6;
  --sidebar-ink-strong: #ffffff;
  --sidebar-hover: rgba(255, 255, 255, 0.07);
  --sidebar-active: rgba(255, 255, 255, 0.12);
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* Dark: chosen steps for the dark surface (not an inversion). OS setting unless a theme is picked. */
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d; --surface-1: #1a1a19; --surface-2: #222220;
    --text-primary: #ffffff; --text-secondary: #c3c2b7; --text-muted: #898781;
    --grid: #2c2c2a; --axis: #383835;
    --border: rgba(255, 255, 255, 0.08); --border-strong: rgba(255, 255, 255, 0.14);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    --wash: rgba(57, 135, 229, 0.16);
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
    --good-text: #0ca30c; --link: #86b6ef; --meter-track: #184f95;
    --sidebar: #0b0b0b; --sidebar-active: rgba(255, 255, 255, 0.10);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface-1: #1a1a19; --surface-2: #222220;
  --text-primary: #ffffff; --text-secondary: #c3c2b7; --text-muted: #898781;
  --grid: #2c2c2a; --axis: #383835;
  --border: rgba(255, 255, 255, 0.08); --border-strong: rgba(255, 255, 255, 0.14);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  --wash: rgba(57, 135, 229, 0.16);
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
  --good-text: #0ca30c; --link: #86b6ef; --meter-track: #184f95;
  --sidebar: #0b0b0b; --sidebar-active: rgba(255, 255, 255, 0.10);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--page); color: var(--text-primary); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }
small { font-weight: 400; color: var(--text-secondary); }
.muted { color: var(--text-secondary); }
.small { font-size: 12px; }
.pad { padding: 10px 16px; margin: 0; }
.nowrap { white-space: nowrap; }
.mono { font-family: var(--mono); font-size: 0.9em; letter-spacing: -0.01em; }
.icon { flex: none; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 8px; vertical-align: 1px; background: var(--axis); }
.dot.slot-1, .slot-1 > .label .dot, .slot-1 .plan-head .dot { background: var(--series-1); }
.dot.slot-2, .slot-2 > .label .dot { background: var(--series-2); }
.dot.slot-3, .slot-3 > .label .dot { background: var(--series-3); }

/* ---------- layout */
.sidebar { position: fixed; inset: 0 auto 0 0; width: 232px; background: var(--sidebar); color: var(--sidebar-ink);
  display: flex; flex-direction: column; padding: 18px 12px; z-index: 20; }
.brand { display: flex; gap: 10px; align-items: center; color: var(--sidebar-ink-strong); padding: 4px 8px 18px; }
.brand:hover { text-decoration: none; }
.brand .logo { width: 34px; height: 34px; border-radius: 9px; background: var(--series-1); color: #fff;
  display: grid; place-items: center; }
.brand b { display: block; font-size: 15px; }
.brand small { display: block; color: inherit; opacity: .7; font-size: 12px; margin-top: -2px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.nav-group { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #8b93a3; padding: 14px 10px 6px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--sidebar-ink);
  background: none; border: 0; font: inherit; width: 100%; text-align: left; cursor: pointer; position: relative; }
.nav-item:hover { background: var(--sidebar-hover); color: var(--sidebar-ink-strong); text-decoration: none; }
.nav-item.active { background: var(--sidebar-active); color: var(--sidebar-ink-strong); font-weight: 600; }
.nav-item.active::before { content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--series-1); }
.nav-item.active[data-product="maps"]::before { background: var(--series-2); }
.nav-item.active[data-product="mapsgl"]::before { background: var(--series-3); }
.sidebar-foot { margin-top: auto; border-top: 1px solid rgba(255, 255, 255, 0.08); padding-top: 10px; }
.sidebar-foot form { margin: 0; }

.shell { margin-left: 232px; min-height: 100vh; display: flex; flex-direction: column; }
.login-page .shell { margin-left: 0; }
main { padding: 4px 28px 32px; max-width: 1680px; width: 100%; }
footer { color: var(--text-muted); font-size: 12px; padding: 8px 28px 28px; margin-top: auto; }

.pagebar { display: flex; align-items: center; gap: 20px; padding: 22px 28px 8px; flex-wrap: wrap; }
.pagebar .titles { min-width: 0; flex: 1; }
.pagebar h1 { font-size: 24px; font-weight: 650; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.pagebar h1 .dot { width: 12px; height: 12px; margin-right: 0; }
.pagebar .sub { margin: 4px 0 0; color: var(--text-secondary); font-size: 13px; }
.search { position: relative; display: flex; align-items: center; }
.search .icon { position: absolute; left: 10px; color: var(--text-muted); pointer-events: none; }
.search input[type=search] { width: 340px; padding-left: 34px; }

/* ---------- controls */
input, button { font: inherit; color: inherit; }
input[type=search], input[type=date], input[type=password], input.dim {
  background: var(--surface-1); border: 1px solid var(--border-strong); border-radius: 8px; padding: 7px 10px; height: 36px; }
input:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--series-1); outline-offset: 2px; }
button.primary { background: var(--series-1); color: #fff; border: 0; border-radius: 8px; padding: 9px 14px; cursor: pointer; font-weight: 600; }
.ghost { display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 12px; border-radius: 8px; color: var(--text-secondary);
  border: 1px solid transparent; background: none; cursor: pointer; white-space: nowrap; }
.ghost:hover { background: var(--surface-1); border-color: var(--border); color: var(--text-primary); text-decoration: none; }

.filters { position: sticky; top: 0; z-index: 10; display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  padding: 10px 28px; background: color-mix(in srgb, var(--page) 88%, transparent); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.filters .push { margin-left: auto; }
.filters .date { display: inline-flex; align-items: center; gap: 6px; color: var(--text-secondary); position: relative; }
.filters .date .icon { position: absolute; left: 10px; pointer-events: none; }
.filters .date input { padding-left: 34px; }
.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); }
.seg a { display: inline-flex; align-items: center; height: 28px; padding: 0 12px; border-radius: 7px; color: var(--text-secondary);
  font-weight: 500; position: relative; }
.seg a:hover { color: var(--text-primary); text-decoration: none; }
.seg a.on { background: var(--surface-1); color: var(--text-primary); font-weight: 650; box-shadow: var(--shadow); }
.chip { display: inline-flex; gap: 6px; align-items: center; background: var(--wash); border-radius: 999px; padding: 4px 6px 4px 12px; }
.chip a { display: grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; }
.chip a:hover { background: var(--surface-1); text-decoration: none; }

/* ---------- cards & grid */
.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin: 0 0 16px;
  box-shadow: var(--shadow); min-width: 0; }
.card.flush { padding: 0; overflow: hidden; }
.card.empty { padding: 32px; text-align: center; color: var(--text-secondary); }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--grid); }
.card-head h3 { font-size: 14px; font-weight: 650; }
.grid { display: grid; gap: 16px; margin-bottom: 16px; }
.grid .card { margin: 0; }
.grid.one { grid-template-columns: 1fr; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(480px, 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid.split { grid-template-columns: minmax(340px, 4fr) minmax(520px, 7fr); }
.grid.overview-row { grid-template-columns: 1.15fr 1.15fr 1fr; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; margin: 26px 0 10px; gap: 12px; }
.section-head:first-child { margin-top: 4px; }
.section-head h2 { font-size: 16px; font-weight: 650; }
.section-head h2 small { font-size: 12.5px; margin-left: 6px; }
.section-links { display: flex; gap: 4px; margin: -6px 0 8px -12px; }
.notice { background: var(--wash); border-radius: 10px; padding: 10px 14px; margin: 0 0 16px; color: var(--text-secondary); font-size: 13px; }
.scroll { max-height: 520px; overflow: auto; }
.scroll.short { max-height: 320px; }
.scroll.tall { max-height: 70vh; }

/* ---------- tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 18px; }
.tiles.three { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.tile { display: flex; flex-direction: column; background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); color: inherit; min-width: 0; position: relative; }
a.tile:hover { text-decoration: none; border-color: var(--border-strong); }
.tile.wide { grid-column: span 2; }
.tile .label { color: var(--text-secondary); font-size: 12.5px; font-weight: 500; }
.tile .value { font-size: 28px; font-weight: 650; letter-spacing: -0.02em; margin-top: 4px; line-height: 1.15; }
.tile .value.crit-text { color: var(--critical); }
.tile .delta { font-size: 12px; color: var(--text-muted); margin-top: 6px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.tile .foot { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }
.pill { font-weight: 650; border-radius: 999px; padding: 1px 8px; font-size: 11.5px; }
.pill.up { color: var(--good-text); background: color-mix(in srgb, var(--good) 14%, transparent); }
.pill.down { color: var(--critical); background: color-mix(in srgb, var(--critical) 12%, transparent); }
.tile .spark { position: relative; height: 40px; margin-top: 10px; }
.tile .spark canvas { position: absolute; inset: 0; }
.tile .codes { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 8px; font-size: 13px; }
.tile .codes b { font-weight: 650; }

/* ---------- charts */
figure.chart { margin: 0; display: flex; flex-direction: column; }
figure.chart figcaption { display: flex; flex-direction: column; margin-bottom: 10px; }
figure.chart .title { font-weight: 650; font-size: 14px; }
figure.chart .sub { color: var(--text-secondary); font-size: 12px; }
figure.chart .plot { position: relative; height: 220px; }
figure.chart.wide .plot { height: 280px; }
figure.chart.tall .plot, figure.chart.hbar .plot { height: auto; }
details.tableview { margin-top: 10px; font-size: 12.5px; }
details.tableview summary { color: var(--text-muted); cursor: pointer; width: max-content; }
details.tableview summary:hover { color: var(--text-secondary); }
details.tableview div { max-height: 260px; overflow: auto; margin-top: 6px; }

/* ---------- tables */
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
th { color: var(--text-muted); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap;
  position: sticky; top: 0; background: var(--surface-2); z-index: 1; }
th.n, td.n { text-align: right; }
tbody tr:hover td { background: var(--surface-2); }
tr.selected td { background: var(--wash); }
tr.over td:first-child { box-shadow: inset 3px 0 0 var(--critical); }
table.sortable th { cursor: pointer; user-select: none; }
table.sortable th:hover { color: var(--text-primary); }
table.sortable th[aria-sort=ascending]::after { content: " ↑"; }
table.sortable th[aria-sort=descending]::after { content: " ↓"; }
.badge { display: inline-block; font-size: 11.5px; font-weight: 500; border-radius: 6px; padding: 1px 7px; background: var(--surface-2);
  border: 1px solid var(--border); color: var(--text-secondary); white-space: nowrap; }
.badge.muted { opacity: .8; }

.meter { display: inline-block; width: 72px; height: 6px; border-radius: 3px; background: var(--meter-track); vertical-align: middle; overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--series-1); border-radius: 3px; }
.meter.warn span { background: var(--warning); }
.meter.crit span { background: var(--critical); }
.status { font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.status.good { color: var(--good-text); }
.status.warn { color: var(--text-primary); }
.status.crit { color: var(--critical); }

/* ---------- client page */
.plans { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; margin-bottom: 8px; }
.plans .card { margin: 0; }
.plan { border-top: 3px solid var(--axis); }
.plan.slot-1 { border-top-color: var(--series-1); }
.plan.slot-2 { border-top-color: var(--series-2); }
.plan.slot-3 { border-top-color: var(--series-3); }
.plan-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.plan-head h3 { font-size: 15px; }
.plan .big { font-size: 24px; font-weight: 650; letter-spacing: -0.02em; }
.plan .big small { font-size: 13px; letter-spacing: 0; }
.meter-row { display: flex; gap: 8px; align-items: center; margin: 6px 0 4px; font-size: 13px; }
.meter-row .meter { width: 140px; height: 8px; border-radius: 4px; }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 12px 0 0; font-size: 13px; }
dl.kv dt { color: var(--text-secondary); }
dl.kv dd { margin: 0; }

/* ---------- loading */
.progress { position: fixed; inset: 0 0 auto 0; height: 3px; z-index: 50; overflow: hidden; pointer-events: none; opacity: 0; transition: opacity .2s; }
.progress span { position: absolute; inset: 0 auto 0 0; width: 40%; background: var(--series-1); border-radius: 0 3px 3px 0;
  animation: progress 1.1s ease-in-out infinite; }
@keyframes progress { 0% { left: -40%; } 100% { left: 100%; } }
html.is-loading .progress { opacity: 1; }
html.is-loading main, html.is-loading .filters { transition: opacity .25s .15s; opacity: .45; pointer-events: none; }
html.is-loading { cursor: progress; }
.is-pending { color: transparent !important; }
.is-pending::after { content: ""; position: absolute; left: 50%; top: 50%; width: 14px; height: 14px; margin: -7px 0 0 -7px;
  border: 2px solid var(--text-muted); border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--axis); border-right-color: var(--series-1); border-radius: 50%; animation: spin .7s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-card { display: flex; gap: 12px; align-items: center; justify-content: center; color: var(--text-secondary); min-height: inherit; }
.partial { margin-bottom: 16px; }
.partial > .loading-card { min-height: 160px; }
.loading-card.error { color: var(--critical); }
.toast { position: fixed; right: 20px; bottom: 20px; max-width: 360px; background: var(--sidebar); color: #fff; border-radius: 10px;
  padding: 12px 16px; font-size: 13px; box-shadow: 0 8px 24px rgba(0,0,0,.25); opacity: 0; transform: translateY(8px);
  transition: opacity .2s, transform .2s; pointer-events: none; z-index: 60; }
.toast.show { opacity: 1; transform: none; }

/* ---------- login */
.login-page main { display: grid; place-items: center; min-height: 80vh; }
form.login { width: 380px; display: flex; flex-direction: column; gap: 14px; padding: 28px; }
form.login .brand { color: var(--text-primary); padding: 0 0 4px; }
form.login label { display: flex; flex-direction: column; gap: 6px; font-weight: 500; }

/* ---------- responsive */
@media (max-width: 1200px) {
  .grid.overview-row, .grid.split { grid-template-columns: 1fr 1fr; }
  .grid.overview-row > :last-child { grid-column: span 2; }
  .grid.split { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .sidebar { position: static; width: auto; flex-direction: row; align-items: center; padding: 8px 12px; overflow-x: auto; }
  .sidebar nav { flex-direction: row; }
  .nav-group, .brand small, .nav-item span { display: none; }
  .nav-item.active::before { display: none; }
  .sidebar-foot { margin: 0 0 0 auto; border: 0; padding: 0; display: flex; }
  .brand { padding: 0 8px 0 0; }
  .shell { margin-left: 0; }
  main, .pagebar, .filters, footer { padding-left: 16px; padding-right: 16px; }
  .grid.two, .grid.three, .grid.overview-row { grid-template-columns: 1fr; }
  .grid.overview-row > :last-child { grid-column: auto; }
  .search input[type=search] { width: 100%; }
  .tile.wide { grid-column: auto; }
}
@media (prefers-reduced-motion: reduce) {
  .progress span, .spinner, .is-pending::after { animation-duration: 3s; }
}

.truncate { max-width: 280px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* Line/column charts in a row stretch to the tallest card instead of leaving a gap. */
.overview-row figure.chart:not(.hbar) .plot { flex: 1 1 auto; min-height: 220px; height: auto; }

/* ---------- combined accesses (overview) */
.card.combined { padding: 18px 20px 20px; }
.combined-head { display: flex; gap: 12px; align-items: baseline; flex-wrap: wrap; margin-bottom: 14px; }
.combined-head h2 { font-size: 15px; font-weight: 650; }
.combined-body { display: grid; grid-template-columns: 1fr 1fr; gap: 20px 48px; }
.mix-label { color: var(--text-secondary); font-size: 12.5px; font-weight: 500; }
.mix-value { font-size: 34px; font-weight: 650; letter-spacing: -0.02em; line-height: 1.1; margin: 4px 0 12px; }
.mix-value.hero { font-size: 52px; }
.stack { display: flex; gap: 2px; height: 10px; border-radius: 5px; overflow: hidden; background: var(--surface-2); }
.stack span { min-width: 2px; }
.stack .seg-1 { background: var(--series-1); }
.stack .seg-2 { background: var(--series-2); }
.stack .seg-3 { background: var(--series-3); }
.mix-legend { list-style: none; display: flex; flex-wrap: wrap; gap: 4px 20px; padding: 0; margin: 10px 0 0; font-size: 13px; }
.mix-legend b { font-weight: 650; margin-left: 4px; }
@media (max-width: 900px) { .combined-body { grid-template-columns: 1fr; } }
