/*
  Pulse. Lead style: Restrained product. Densest screen first (the overview), built in greyscale;
  colour is status only (red / amber / green dots) plus one blue for links, focus and the "usual" line.
  Type 11 12 13 14 16 20 28 40 · space 2 4 6 8 12 16 20 24 32 48 64 · radius 6 · 0.15s ease-out.
  Signature: each store's hourly bars against the 4-week "usual" line.
*/
:root {
  --f-sans: "Inter", ui-sans-serif, system-ui, sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, monospace;
  --fs-11: 11px; --fs-12: 12px; --fs-13: 13px; --fs-14: 14px; --fs-16: 16px; --fs-20: 20px; --fs-28: 28px; --fs-40: 40px;
  --s-2: 2px; --s-4: 4px; --s-6: 6px; --s-8: 8px; --s-12: 12px; --s-16: 16px; --s-20: 20px; --s-24: 24px; --s-32: 32px; --s-48: 48px; --s-64: 64px;
  --r: 6px;
  --page: oklch(97.6% 0.004 250);
  --card: oklch(99.4% 0.003 250);
  --line: oklch(89.5% 0.006 250);
  --line-soft: oklch(93.5% 0.005 250);
  --t1: oklch(22% 0.012 250);
  --t2: oklch(40% 0.012 250);
  --t3: oklch(52% 0.01 250);
  --t4: oklch(66% 0.008 250);
  --bar: oklch(46% 0.012 250);
  --accent: #2F86E0;
  --red: oklch(57% 0.19 27);
  --red-bg: oklch(96% 0.025 27);
  --amber: oklch(70% 0.15 70);
  --amber-bg: oklch(97% 0.03 80);
  --green: oklch(62% 0.14 150);
  --ease: cubic-bezier(0.25, 1, 0.5, 1);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --page: oklch(17% 0.008 250);
    --card: oklch(20.5% 0.009 250);
    --line: oklch(30% 0.012 250);
    --line-soft: oklch(25% 0.01 250);
    --t1: oklch(95% 0.005 250);
    --t2: oklch(80% 0.008 250);
    --t3: oklch(66% 0.01 250);
    --t4: oklch(52% 0.01 250);
    --bar: oklch(74% 0.01 250);
    --red-bg: oklch(26% 0.05 27);
    --amber-bg: oklch(27% 0.04 70);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--page); color: var(--t2);
  font: 450 var(--fs-14)/1.5 var(--f-sans); letter-spacing: -0.006em;
  font-feature-settings: "cv11", "ss01", "tnum";
}
a { color: var(--accent); text-decoration: none; transition: color 0.15s var(--ease); }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { color: var(--t1); margin: 0; font-weight: 640; letter-spacing: -0.012em; }
h1 { font-size: var(--fs-20); }
h2 { font-size: var(--fs-16); margin: 0 0 var(--s-12); }
h3 { font-size: var(--fs-16); }
h4 { font-size: var(--fs-12); color: var(--t3); font-weight: 560; margin-bottom: var(--s-6); }
small { font-size: var(--fs-12); }
.muted { color: var(--t3); }
.num, .big, .kpis dd, .count { font-family: var(--f-mono); font-variant-numeric: tabular-nums; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Top bar */
.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: var(--s-24);
  padding: var(--s-8) var(--s-24); background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { display: inline-flex; align-items: center; gap: var(--s-8); font-weight: 680; color: var(--t1); font-size: var(--fs-16); }
.brand svg { width: 18px; height: 18px; fill: none; stroke: var(--accent); stroke-width: 2; }
.top nav { display: flex; gap: var(--s-4); overflow-x: auto; flex: 1; }
.top nav a { color: var(--t3); padding: var(--s-6) var(--s-8); border-radius: var(--r); white-space: nowrap; font-size: var(--fs-13); }
.top nav a:hover { color: var(--t1); text-decoration: none; background: var(--page); }
.top nav a.on { color: var(--t1); background: var(--page); font-weight: 560; }
.topright { display: flex; align-items: center; gap: var(--s-16); font-size: var(--fs-13); white-space: nowrap; }

.btn {
  font: 560 var(--fs-13)/1 var(--f-sans); color: var(--card); background: var(--t1);
  border: 0; border-radius: var(--r); padding: var(--s-8) var(--s-12); cursor: pointer; transition: opacity 0.15s var(--ease);
}
.btn:hover { opacity: 0.86; }
.btn[disabled] { opacity: 0.5; cursor: default; }

main { padding: var(--s-24); max-width: 1680px; margin: 0 auto; }
section { margin-bottom: var(--s-32); }

/* Alerts: a ruled list, not cards */
.alerts h2 { display: flex; align-items: center; gap: var(--s-8); }
.count { font-size: var(--fs-12); color: var(--t3); font-weight: 500; }
.allclear { display: flex; align-items: center; gap: var(--s-8); color: var(--t3); margin: 0 0 var(--s-24); }
.alist { list-style: none; margin: 0 0 var(--s-24); padding: 0; border-top: 1px solid var(--line); }
.alist li > a, .alist li > span {
  display: grid; grid-template-columns: 14px minmax(110px, 160px) minmax(200px, 1.2fr) 2fr 90px; gap: var(--s-12); align-items: baseline;
  padding: var(--s-8) var(--s-12); border-bottom: 1px solid var(--line); color: var(--t2);
}
.alist li > span { grid-template-columns: 14px minmax(220px, 1.2fr) 2fr 90px; }
.alist li.red > * { background: var(--red-bg); }
.alist li > a:hover { text-decoration: none; filter: brightness(0.98); }
.astore { color: var(--t1); font-weight: 600; }
.atitle { color: var(--t1); font-weight: 560; }
.adetail { color: var(--t3); font-size: var(--fs-13); }
.aage { color: var(--t4); font-size: var(--fs-12); text-align: right; }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 9999px; background: var(--t4); margin-right: var(--s-6); vertical-align: 1px; flex: none; }
.dot.red { background: var(--red); }
.dot.amber { background: var(--amber); }
.dot.ok { background: var(--green); }
.dot.muted, .dot.unknown { background: var(--line); }

/* Store grid */
.grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s-16); }
.store { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: var(--s-16) var(--s-16) var(--s-12); min-width: 0; }
.store > header { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--s-4) var(--s-12); margin-bottom: var(--s-12); }
.store > header a:hover { text-decoration: none; }
.store > header h3:hover { color: var(--accent); }
.store .meta { color: var(--t3); font-size: var(--fs-12); display: inline-flex; align-items: center; flex-wrap: wrap; gap: 0 var(--s-4); }
.pill { margin-left: auto; font-size: var(--fs-11); font-weight: 600; padding: var(--s-2) var(--s-8); border-radius: 9999px; }
.pill.red { background: var(--red-bg); color: var(--red); }
.rev .big { font-size: var(--fs-28); color: var(--t1); font-weight: 500; letter-spacing: -0.02em; margin-right: var(--s-8); }
.sub { color: var(--t3); font-size: var(--fs-12); margin: var(--s-2) 0 var(--s-8); }
.d { font-family: var(--f-mono); font-size: var(--fs-13); color: var(--t3); }
.d.up { color: var(--green); }
.d.down { color: var(--red); }

.hc { display: block; width: 100%; height: auto; }
.hc.mini { height: 54px; margin: var(--s-4) 0 var(--s-12); }
.hc .bar { fill: var(--bar); }
.hc .avg { fill: none; stroke: var(--accent); stroke-width: 1.5; stroke-dasharray: 3 3; vector-effect: non-scaling-stroke; }
.hc text { fill: var(--t4); font: 10px var(--f-mono); }

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--s-8); margin: 0 0 var(--s-8); padding: var(--s-8) 0; border-top: 1px solid var(--line-soft); border-bottom: 1px solid var(--line-soft); }
.kpis.wide { grid-template-columns: repeat(3, minmax(0, 1fr)); border: 0; padding: 0; gap: var(--s-12) var(--s-16); margin-top: var(--s-16); }
.kpis dt { font-size: var(--fs-11); color: var(--t3); }
.kpis dd { margin: 0; color: var(--t1); font-size: var(--fs-16); font-weight: 500; }
.kpis dd small { font-family: var(--f-sans); color: var(--t3); font-size: var(--fs-11); font-weight: 450; }
.kpis .warn dd { color: var(--red); }
.reason { font-size: var(--fs-12); color: var(--t2); margin: 0 0 var(--s-8); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.reason span { color: var(--t3); margin-right: var(--s-4); }
.adsmini { width: 100%; border-collapse: collapse; font-size: var(--fs-12); }
.adsmini th { text-align: left; font-weight: 500; color: var(--t2); padding: var(--s-4) 0; }
.adsmini td { padding: var(--s-4) 0 var(--s-4) var(--s-8); color: var(--t2); }
.adsmini td:last-child { text-align: right; }
.age { color: var(--t4); font-size: var(--fs-11); white-space: nowrap; }
.age.bad { color: var(--amber); font-weight: 600; }

/* Store page */
.shead { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-12) var(--s-24); margin-bottom: var(--s-24); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.seg a { padding: var(--s-6) var(--s-12); color: var(--t3); font-size: var(--fs-13); }
.seg a + a { border-left: 1px solid var(--line); }
.seg a.on { background: var(--t1); color: var(--card); }
.seg a:hover { text-decoration: none; }
.split { display: grid; grid-template-columns: minmax(300px, 0.8fr) 1.6fr; gap: var(--s-32); align-items: start; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: var(--s-24); }
.head-stats .big { font-size: var(--fs-40); color: var(--t1); font-weight: 500; letter-spacing: -0.022em; margin-right: var(--s-12); line-height: 1; }
.chart { margin: 0; }
.chart .hc { height: 180px; }
figcaption { font-size: var(--fs-12); color: var(--t3); display: flex; align-items: center; gap: var(--s-6); margin-top: var(--s-8); }
.key { display: inline-block; width: 12px; height: 8px; margin-left: var(--s-8); }
.key.bar { background: var(--bar); border-radius: 1.5px; }
.key.avg { border-top: 2px dashed var(--accent); height: 0; }

.groups { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: var(--s-24); margin-bottom: var(--s-16); }
.groups ol { list-style: none; margin: 0; padding: 0; }
.groups li { display: flex; justify-content: space-between; gap: var(--s-8); padding: var(--s-4) 0; border-bottom: 1px solid var(--line-soft); font-size: var(--fs-13); }
.groups li span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.groups li b { font-family: var(--f-mono); font-weight: 500; color: var(--t1); }

.tbl { width: 100%; border-collapse: collapse; font-size: var(--fs-13); background: var(--card); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.tbl th, .tbl td { text-align: left; padding: var(--s-6) var(--s-12); border-bottom: 1px solid var(--line-soft); vertical-align: top; }
.tbl thead th { font-size: var(--fs-11); font-weight: 560; color: var(--t3); background: var(--page); white-space: nowrap; }
.tbl tbody th { font-weight: 560; color: var(--t1); white-space: nowrap; }
.tbl tr:last-child td, .tbl tr:last-child th { border-bottom: 0; }
.tbl .num { text-align: right; white-space: nowrap; }
.reason-cell { color: var(--t2); max-width: 520px; }
.tag { font-size: var(--fs-11); color: var(--t3); border: 1px solid var(--line); border-radius: 9999px; padding: 0 var(--s-6); }
.status { font-size: var(--fs-12); }
.st-failed .status { color: var(--red); font-weight: 600; }
.st-pending .status, .st-on-hold .status { color: var(--amber); }
.note { font-size: var(--fs-12); color: var(--t3); margin: var(--s-8) 0 0; max-width: 90ch; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-32); }
.cols > div > h2 + * { margin-bottom: var(--s-24); }
.flash { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: var(--s-8) var(--s-12); }
.row { display: flex; gap: var(--s-8); flex-wrap: wrap; margin: var(--s-8) 0 var(--s-16); }
input[type=password], input[name=code], input[inputmode] {
  font: 450 var(--fs-14) var(--f-sans); color: var(--t1); background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: var(--s-8) var(--s-12); min-width: 260px;
}

/* Login */
body.login { display: grid; place-items: center; min-height: 100vh; padding: var(--s-16); }
.loginbox { width: 100%; max-width: 360px; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: var(--s-32) var(--s-24); display: grid; gap: var(--s-12); }
.loginbox label { font-size: var(--fs-13); color: var(--t2); }
.loginbox input { width: 100%; min-width: 0; }
.loginbox .btn { padding: var(--s-12); }
.loginbox .err { color: var(--red); margin: 0; }
.loginbox .key { font-family: var(--f-mono); color: var(--t1); letter-spacing: 0.04em; margin: 0; }
#qr { justify-self: center; padding: var(--s-8); background: oklch(99% 0 0); border-radius: var(--r); }

@media (max-width: 1280px) { .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } .groups { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 860px) {
  main { padding: var(--s-16); }
  .top { flex-wrap: wrap; gap: var(--s-8); padding: var(--s-8) var(--s-16); }
  .top nav { order: 3; flex-basis: 100%; }
  .topright .muted:first-child { display: none; }
  .grid, .split, .cols { grid-template-columns: 1fr; }
  .groups { grid-template-columns: 1fr 1fr; }
  .alist li > a, .alist li > span { grid-template-columns: 14px 1fr; }
  .alist .adetail, .alist .aage { grid-column: 2; text-align: left; }
  .tbl { display: block; overflow-x: auto; }
  .head-stats .big { font-size: var(--fs-28); }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
