/* Mobile first: this is read on a phone most days, so the phone layout is the
   base and the wider breakpoints are the additions. */
:root {
  color-scheme: light;
  --surface-0: #f4f3f0;
  --surface-1: #fcfcfb;
  --surface-2: #eceae5;
  --border:    #e2e0da;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #82817b;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --seq-450:  #2a78d6;
  --good:     #0ca30c;
  --warning:  #fab219;
  --critical: #d03b3b;
  --nav-h: 60px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-0: #111110;
    --surface-1: #1a1a19;
    --surface-2: #242320;
    --border:    #35342f;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #8f8e85;
    --series-1: #3987e5;
    --series-2: #d95926;
    --seq-450:  #3987e5;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-0: #111110; --surface-1: #1a1a19; --surface-2: #242320;
  --border: #35342f; --text-primary: #fff; --text-secondary: #c3c2b7;
  --text-muted: #8f8e85; --series-1: #3987e5; --series-2: #d95926; --seq-450: #3987e5;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: ui-sans-serif, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--surface-0);
  color: var(--text-primary);
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
  font-size: 16px;
  line-height: 1.5;
}
.wrap { max-width: 1100px; margin: 0 auto; padding: 0 16px; }

/* ---- top bar ---- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--surface-0) 88%, transparent);
  backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 14px 16px calc(14px + env(safe-area-inset-top)) 16px;
  padding-top: calc(14px + env(safe-area-inset-top));
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
}
.topbar h1 { font-size: 17px; margin: 0; letter-spacing: -0.01em; }
.topbar .meta { font-size: 12px; color: var(--text-muted); white-space: nowrap; }

/* ---- bottom nav (phone) ---- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: color-mix(in srgb, var(--surface-1) 94%, transparent);
  backdrop-filter: saturate(160%) blur(12px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; height: var(--nav-h); text-decoration: none;
  color: var(--text-muted); font-size: 11px; font-weight: 500;
}
.tabbar a.active { color: var(--series-1); }
.tabbar svg { width: 21px; height: 21px; stroke-width: 1.9; fill: none; stroke: currentColor;
              stroke-linecap: round; stroke-linejoin: round; }

@media (min-width: 760px) {
  body { padding-bottom: 32px; }
  .tabbar {
    position: static; border-top: none; background: none; backdrop-filter: none;
    grid-template-columns: repeat(4, max-content); gap: 6px;
    max-width: 1100px; margin: 12px auto -4px; padding: 0 16px;
  }
  .tabbar a {
    flex-direction: row; height: auto; padding: 8px 14px; border-radius: 999px;
    font-size: 14px; gap: 8px;
  }
  .tabbar a.active { background: var(--surface-2); }
  .tabbar svg { width: 17px; height: 17px; }
}

/* ---- content ---- */
main { padding-top: 18px; }
section { margin-bottom: 26px; }
h2 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em;
     color: var(--text-secondary); margin: 0 0 10px; font-weight: 600; }
.card { background: var(--surface-1); border: 1px solid var(--border);
        border-radius: 14px; padding: 16px; }
.card + .card { margin-top: 12px; }

/* ---- KPI tiles: two up on a phone ---- */
.tiles { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; }
@media (min-width: 560px) { .tiles { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 860px) { .tiles { grid-template-columns: repeat(4, 1fr); } }
.tile { background: var(--surface-1); border: 1px solid var(--border);
        border-radius: 14px; padding: 14px; }
.tile .label { font-size: 11.5px; color: var(--text-muted); margin-bottom: 5px;
               white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .value { font-size: 23px; font-weight: 650; letter-spacing: -0.02em;
               font-variant-numeric: tabular-nums; }
.tile .delta { font-size: 11.5px; margin-top: 3px; font-variant-numeric: tabular-nums; }
.tile .median { color: var(--text-muted); }
.tile .hint { font-size: 11px; color: var(--text-muted); margin-top: 7px;
              line-height: 1.35; }
.h2-note { text-transform: none; letter-spacing: 0; font-weight: 400;
           color: var(--text-muted); }

/* ---- charts ---- */
.charts { display: grid; gap: 12px; }
@media (min-width: 860px) { .charts.two { grid-template-columns: 1fr 1fr; } }
.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 10px;
          font-size: 12.5px; color: var(--text-secondary); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }
/* The viewBox is ~520 units wide; letting it stretch past ~760px blows the
   axis text up with it, so cap the width and centre what is left. */
svg.chart { display: block; width: 100%; max-width: 760px; margin-inline: auto;
            height: auto; overflow: visible; touch-action: pan-y; }
.axis text { font-size: 11px; fill: var(--text-muted); }
.gridline { stroke: var(--border); stroke-dasharray: 2 3; }

/* ---- tables: scroll sideways rather than squeeze on a phone ---- */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch;
                margin: 0 -16px; padding: 0 16px; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px;
        font-variant-numeric: tabular-nums; min-width: 460px; }
th, td { text-align: right; padding: 10px 8px; border-bottom: 1px solid var(--border);
         white-space: nowrap; }
th:first-child, td:first-child { text-align: left; position: sticky; left: 0;
         background: var(--surface-1); }
th { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
     color: var(--text-secondary); font-weight: 600; }
tbody tr:last-child td { border-bottom: none; }
.bar-wrap { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.bar-track { flex: 0 0 56px; height: 6px; border-radius: 3px;
             background: color-mix(in srgb, var(--text-muted) 18%, transparent); }
.bar-fill { display: block; height: 6px; border-radius: 3px; background: var(--seq-450); }

/* ---- advice ---- */
.advice-item { display: flex; gap: 11px; padding: 14px 0;
               border-bottom: 1px solid var(--border); }
.advice-item:first-child { padding-top: 0; }
.advice-item:last-child { border-bottom: none; padding-bottom: 0; }
.pill { flex: none; font-size: 9.5px; font-weight: 700; letter-spacing: 0.06em;
        padding: 3px 7px; border-radius: 999px; height: fit-content;
        text-transform: uppercase; margin-top: 2px; }
.pill.act { background: color-mix(in srgb, var(--critical) 16%, transparent);
            color: var(--critical); }
.pill.watch { background: color-mix(in srgb, var(--warning) 22%, transparent);
              color: color-mix(in srgb, var(--warning) 62%, var(--text-primary)); }
.advice-body .topic { font-weight: 650; font-size: 14.5px; margin-bottom: 3px; }
.advice-body .finding { font-size: 13.5px; color: var(--text-secondary); }
.advice-body .evidence { font-size: 12px; color: var(--text-muted); margin-top: 5px; }

/* ---- login ---- */
.login-wrap { min-height: 82vh; display: flex; align-items: center; justify-content: center;
              padding: 24px 16px; }
.login-card { width: 100%; max-width: 360px; }
.login-card h1 { font-size: 20px; margin: 0 0 4px; }
.login-card p.sub { margin: 0 0 20px; color: var(--text-muted); font-size: 13.5px; }
label { display: block; font-size: 12.5px; color: var(--text-secondary); margin-bottom: 6px; }
input[type=password], input[type=text] {
  width: 100%; padding: 13px 14px; font-size: 16px; /* 16px stops iOS zooming on focus */
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-0); color: var(--text-primary);
}
button {
  width: 100%; margin-top: 14px; padding: 13px 16px; font-size: 15px; font-weight: 600;
  border: none; border-radius: 10px; background: var(--series-1); color: #fff;
  cursor: pointer; min-height: 46px;
}
button.secondary { background: var(--surface-2); color: var(--text-primary); }
.error { margin-top: 12px; font-size: 13px; color: var(--critical); }
.empty { color: var(--text-muted); font-size: 14px; padding: 8px 0; }

.tooltip { position: fixed; pointer-events: none; opacity: 0; transition: opacity .12s;
           background: var(--surface-1); border: 1px solid var(--border);
           border-radius: 9px; padding: 8px 10px; font-size: 12.5px; z-index: 60;
           box-shadow: 0 6px 22px rgba(0,0,0,.16); font-variant-numeric: tabular-nums; }
.tooltip .tt-date { color: var(--text-muted); margin-bottom: 4px; }
.tooltip .tt-row { display: flex; gap: 12px; justify-content: space-between; }
.footnote { font-size: 11.5px; color: var(--text-muted); text-align: center;
            margin: 26px 0 8px; }

/* ---- filter row: scrolls sideways on a phone rather than wrapping ---- */
.filters { display: flex; gap: 10px; overflow-x: auto; -webkit-overflow-scrolling: touch;
           margin: 0 -16px 18px; padding: 0 16px 4px; }
.filter { flex: none; }
.filter label { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.05em;
                margin-bottom: 4px; }
select {
  font-size: 15px; padding: 9px 30px 9px 12px; min-height: 42px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-1); color: var(--text-primary);
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'><path d='M1 1l5 5 5-5' fill='none' stroke='%2382817b' stroke-width='1.8' stroke-linecap='round'/></svg>");
  background-repeat: no-repeat; background-position: right 10px center;
  background-size: 11px 7px;   /* without this the chevron scales to the box */
}
.filter-note { font-size: 12.5px; color: var(--text-muted); margin: -8px 0 16px; }
tfoot td { font-weight: 650; border-top: 1px solid var(--border); border-bottom: none; }
td a { color: var(--series-1); text-decoration: none; }
td a:active { opacity: .6; }
