/* Colour scheme: navy, royal blue, mint, yellow, magenta and sky (series colours validated for light and dark) */
:root {
  color-scheme: light dark;
  --brand: #1d3a8a;
  --brand-2: #3b5bdb;
  --focus: #1d3a8a;
  --bg: linear-gradient(180deg, #e6ebf7 0%, #f0f2f8 40%, #f3f4f8 100%);
  --surface: #ffffff;
  --surface-2: #f2f4fb;
  --text: #0f1e4a;
  --text-2: #435079;
  --text-3: #55608a;
  --border: rgba(15, 30, 74, 0.1);
  --grid: #e1e3ec;
  --axis: #c3c7d6;
  --series-1: #3b5bdb;
  --series-2: #d99a00;
  --series-3: #1fa37a;
  --series-4: #b0529f;
  --series-5: #4795ef;
  --good: #1fa37a;
  --warn: #f5c242;
  --serious: #b0529f;
  --crit: #d03b3b;
  --good-text: #0b7a58;
  --crit-text: #a82424;
  --skel-a: #e4e8f4;
  --skel-b: #f4f6fc;
  --shadow: 0 1px 2px rgba(15, 30, 74, 0.06), 0 6px 18px rgba(15, 30, 74, 0.05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --brand: #9bb0ff;
    --brand-2: #6b8cff;
    --focus: #b9c7ff;
    --bg: linear-gradient(180deg, #0f1a42 0%, #0b1331 40%, #090f26 100%);
    --surface: #131c3d;
    --surface-2: #1b2650;
    --text: #eef2ff;
    --text-2: #c5cde6;
    --text-3: #aab4d6;
    --border: rgba(255, 255, 255, 0.1);
    --grid: #252d4d;
    --axis: #343d63;
    --series-1: #5578ee;
    --series-2: #c08a10;
    --series-3: #1c9e75;
    --series-4: #c264b2;
    --series-5: #4592ee;
    --good: #3ecf9f;
    --good-text: #3ecf9f;
    --crit-text: #ff8a8a;
    --skel-a: #1b2650;
    --skel-b: #26336a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 18px rgba(0, 0, 0, 0.25);
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg) fixed;
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-variant-numeric: tabular-nums;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
.noscript { padding: 24px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Sign in ---------- */
.signin { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.card {
  width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 24px; padding: 28px 24px; box-shadow: var(--shadow);
}
.logo {
  width: 52px; height: 52px; border-radius: 14px; margin-bottom: 14px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2)); display: grid; place-items: center;
}
.logo svg { width: 28px; height: 28px; }
h1 { font-size: 1.35rem; margin: 0 0 6px; }
.muted { color: var(--text-2); }
.field { display: block; margin: 16px 0 0; }
.field span { display: block; font-size: 0.85rem; color: var(--text-2); margin-bottom: 6px; }
.field input {
  width: 100%; min-height: 48px; padding: 10px 14px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface-2); transition: border-color var(--t-med) var(--ease);
}
.field input:focus { border-color: var(--brand); }
.field input.bad { border-color: var(--crit); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 20px;
  border-radius: 14px; border: 0; background: linear-gradient(135deg, var(--brand), color-mix(in srgb, var(--brand) 70%, var(--brand-2)));
  color: #fff; font-weight: 600; width: 100%; margin-top: 18px; text-decoration: none;
}
@media (prefers-color-scheme: dark) { .btn { color: #0b1230; } }
.btn[disabled] { opacity: 0.65; cursor: default; }
.btn.ghost { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn.small { min-height: 44px; width: auto; margin-top: 0; padding: 0 14px; }
.msg { margin-top: 14px; font-size: 0.92rem; min-height: 1.3em; }
.msg.err { color: var(--crit-text); }
.msg.ok { color: var(--good-text); }
details.alt { margin-top: 20px; font-size: 0.92rem; }
details.alt summary { cursor: pointer; color: var(--text-2); min-height: 44px; display: flex; align-items: center; }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; }

/* ---------- Shell ---------- */
.topbar {
  position: sticky; top: calc(8px + env(safe-area-inset-top)); z-index: 20; margin: calc(8px + env(safe-area-inset-top)) 12px 0;
  display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 14px; border-radius: 18px;
}
.topbar .title { font-weight: 700; line-height: 1.15; flex: 1; min-width: 0; }
.topbar .title small { display: block; font-weight: 400; color: var(--text-2); font-size: 0.78rem; }
.iconbtn {
  width: 44px; height: 44px; border-radius: 14px; border: 1px solid var(--border); background: var(--surface-2);
  display: grid; place-items: center; color: var(--text);
}
.iconbtn svg { width: 20px; height: 20px; }
.menu {
  position: fixed; right: 14px; top: calc(70px + env(safe-area-inset-top)); z-index: 30; min-width: 210px; padding: 8px;
}
.menu button, .menu a {
  display: flex; align-items: center; width: 100%; min-height: 44px; padding: 0 12px; border-radius: 12px;
  border: 0; background: transparent; text-align: left; text-decoration: none; color: var(--text);
}
.menu button:hover, .menu a:hover { background: var(--surface-2); }
main { max-width: 1080px; margin: 0 auto; padding: 14px 12px calc(110px + env(safe-area-inset-bottom)); }
.grid { display: grid; gap: 12px; }
@media (min-width: 760px) {
  .cols-2 { grid-template-columns: 1fr 1fr; }
  .cols-3 { grid-template-columns: repeat(3, 1fr); }
  .cols-4 { grid-template-columns: repeat(4, 1fr); }
}
section { scroll-margin-top: 90px; margin-bottom: 26px; }
h2 { font-size: 0.8rem; letter-spacing: 0.07em; text-transform: uppercase; color: var(--text-2); margin: 6px 4px 10px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.tile .label { font-size: 0.85rem; color: var(--text-2); display: flex; justify-content: space-between; gap: 8px; }
.tile .big { font-size: 2rem; font-weight: 700; line-height: 1.15; margin: 6px 0 2px; letter-spacing: -0.01em; }
.tile .sub { font-size: 0.85rem; color: var(--text-2); }
.tile.hero .big { font-size: 2.4rem; }
.neg { color: var(--crit-text); }
.pos { color: var(--good-text); }
.spark { display: block; width: 100%; height: 44px; margin-top: 10px; }
.spark path { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.spark circle { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }
.spark-note { font-size: 0.78rem; color: var(--text-3); margin-top: 8px; }
details.more { margin-top: 12px; border-top: 1px solid var(--border); }
details.more summary { min-height: 44px; display: flex; align-items: center; cursor: pointer; color: var(--text-2); font-size: 0.88rem; }
.rows { list-style: none; margin: 0; padding: 0; }
.rows li { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-top: 1px solid var(--border); font-size: 0.92rem; }
.rows li:first-child { border-top: 0; }
.rows li span:first-child { min-width: 0; overflow-wrap: anywhere; }
.age { display: flex; height: 14px; border-radius: 7px; overflow: hidden; gap: 2px; margin: 12px 0 6px; background: var(--surface-2); }
.age i { display: block; min-width: 3px; }
.age i.a1 { background: var(--warn); } .age i.a2 { background: var(--serious); } .age i.a3 { background: var(--crit); } .age i.a4 { background: #8f1f1f; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 0.8rem; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend b { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.dot-1 { background: var(--series-1); } .dot-2 { background: var(--series-2); }
.dot-a1 { background: var(--warn); } .dot-a2 { background: var(--serious); } .dot-a3 { background: var(--crit); } .dot-a4 { background: #8f1f1f; }

/* ---------- Charts ---------- */
.chart-wrap { position: relative; }
.chart-wrap svg { width: 100%; height: auto; display: block; touch-action: pan-y; }
.chart-wrap .gridline { stroke: var(--grid); stroke-width: 1; }
.chart-wrap .axisline { stroke: var(--axis); stroke-width: 1; }
.chart-wrap text { fill: var(--text-2); font-size: 11px; }
.bar-1 { fill: var(--series-1); } .bar-2 { fill: var(--series-2); }
.hit { fill: transparent; outline: none; }
.hit:hover, .hit:focus-visible { fill: color-mix(in srgb, var(--brand) 10%, transparent); }
.tip {
  position: absolute; z-index: 5; pointer-events: none; padding: 10px 12px; border-radius: 14px; font-size: 0.85rem; min-width: 150px;
}
.tip b { display: block; margin-bottom: 4px; }
.tip div { display: flex; justify-content: space-between; gap: 14px; }
.toggle-table { margin-top: 10px; }
table.data { width: 100%; border-collapse: collapse; font-size: 0.88rem; margin-top: 10px; }
table.data th, table.data td { text-align: right; padding: 8px 6px; border-top: 1px solid var(--border); }
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data th { color: var(--text-2); font-weight: 600; }

/* ---------- Courses ---------- */
.counts { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 12px; }
@media (min-width: 760px) { .counts { grid-template-columns: repeat(4, 1fr); } }
.course { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 12px 0; border-top: 1px solid var(--border); align-items: center; }
.course:first-child { border-top: 0; }
.course .name { font-weight: 600; overflow-wrap: anywhere; }
.course .meta { font-size: 0.85rem; color: var(--text-2); grid-column: 1; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px 5px 8px; border-radius: 999px; font-size: 0.82rem; font-weight: 600;
  background: var(--surface-2); border: 1px solid var(--border); white-space: nowrap; grid-row: 1 / span 2; grid-column: 2;
}
.chip svg { width: 14px; height: 14px; flex: none; }
.ic-good { fill: var(--good); } .ic-warn { fill: var(--warn); } .ic-crit { fill: var(--crit); } .ic-mute { fill: var(--text-3); }

/* ---------- Footer, tabs, toast ---------- */
.sources { display: grid; gap: 8px; }
.src { display: flex; gap: 10px; align-items: flex-start; font-size: 0.9rem; }
.src svg { width: 16px; height: 16px; margin-top: 3px; flex: none; }
.src small { display: block; color: var(--text-2); }
.errbox { margin-top: 10px; padding: 12px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--border); font-size: 0.9rem; }
.tabs {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(10px + env(safe-area-inset-bottom)); z-index: 20;
  display: flex; padding: 5px; border-radius: 22px; width: min(420px, calc(100% - 24px));
}
.tabs .ind { position: absolute; top: 5px; bottom: 5px; border-radius: 17px; background: color-mix(in srgb, var(--brand) 18%, transparent); transition: transform var(--t-med) var(--ease), width var(--t-med) var(--ease); }
.tabs a { position: relative; flex: 1; min-height: 44px; display: grid; place-items: center; text-decoration: none; color: var(--text); font-size: 0.82rem; font-weight: 600; border-radius: 17px; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 40; padding: 12px 16px; border-radius: 16px; font-size: 0.9rem; max-width: calc(100% - 32px); }
.setup-list { list-style: none; margin: 0; padding: 0; }
.setup-list li { display: flex; gap: 12px; padding: 14px 0; border-top: 1px solid var(--border); }
.setup-list li:first-child { border-top: 0; }
.setup-list svg { width: 20px; height: 20px; flex: none; margin-top: 2px; }
.setup-list .t { font-weight: 600; }
.setup-list .d { font-size: 0.88rem; color: var(--text-2); margin-top: 2px; overflow-wrap: anywhere; }
code { background: var(--surface-2); padding: 2px 6px; border-radius: 6px; font-size: 0.85em; overflow-wrap: anywhere; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

.ic-mute-o { fill: none; stroke: var(--text-3); stroke-width: 1.6; stroke-linecap: round; }
a.plain { color: inherit; text-underline-offset: 3px; }

/* ---------- Period selector and comparison chips ---------- */
.periods { position: relative; display: flex; gap: 2px; padding: 4px; margin: 4px 0 6px; border-radius: 16px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); overflow-x: auto; scrollbar-width: none; }
.periods::-webkit-scrollbar { display: none; }
.periods .ind { position: absolute; top: 4px; bottom: 4px; left: 0; border-radius: 12px; background: color-mix(in srgb, var(--brand-2) 16%, transparent); transition: transform var(--t-med) var(--ease), width var(--t-med) var(--ease); pointer-events: none; }
.periods button { position: relative; flex: 1 1 0; min-width: 0; min-height: 44px; padding: 0 4px; border: 0; background: transparent; color: var(--text); font: inherit; font-size: 0.84rem; font-weight: 600; border-radius: 12px; cursor: pointer; white-space: nowrap; }
.periods button[aria-pressed="true"] { color: var(--brand); }
.periods-note { margin: 0 2px 10px; font-size: 0.82rem; color: var(--text-2); }
.cmps { display: grid; gap: 4px; margin-top: 8px; }
.cmp { display: flex; align-items: center; gap: 6px; font-size: 0.82rem; color: var(--text-2); line-height: 1.3; }
.cmp b { font-weight: 700; white-space: nowrap; }
.cmp svg { width: 14px; height: 14px; flex: none; }
.cmp.good b { color: var(--good-text); } .cmp.bad b { color: var(--crit-text); } .cmp.flat b { color: var(--text-2); }
.cmp.good svg { fill: var(--good); } .cmp.bad svg { fill: var(--crit); } .cmp.flat svg { fill: var(--text-3); }
.cmp.none { color: var(--text-3); }
.grid.cols-3 .tile .cmps, .grid.cols-4 .tile .cmps { margin-top: 10px; }
.mini-table { width: 100%; border-collapse: collapse; font-size: 0.86rem; margin-top: 8px; }
.mini-table th, .mini-table td { text-align: left; padding: 6px 4px; border-top: 1px solid var(--border); }
.mini-table th { color: var(--text-2); font-weight: 600; }
