/* CPN v2. One stylesheet, no build step. Colours are tokens so dark mode is a second set of values. */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dde1e7;
  --text: #1b2330;
  --muted: #5f6b7c;
  --accent: #2f5fd0;
  --accent-text: #ffffff;
  --accent-soft: #e6edfb;
  --good: #1f8a4c;
  --good-soft: #e1f4e8;
  --bad: #c0392b;
  --bad-soft: #fbe7e4;
  --warn-soft: #fdf3d7;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 2px 8px rgba(20, 30, 50, .04);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b;
    --surface: #1a1f28;
    --surface-2: #232a36;
    --border: #303948;
    --text: #e6e9ef;
    --muted: #98a3b5;
    --accent: #7ea2f5;
    --accent-text: #0e1420;
    --accent-soft: #24304a;
    --good: #5fd08c;
    --good-soft: #1a3526;
    --bad: #f08a7c;
    --bad-soft: #43221e;
    --warn-soft: #3d3418;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.6rem; margin: 0 0 .25rem; line-height: 1.25; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.num { font-variant-numeric: tabular-nums; text-align: right; }
.nowrap { white-space: nowrap; }

/* -- layout ------------------------------------------------------------------ */

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.topbar-inner {
  max-width: 1180px; margin: 0 auto; padding: 0 16px;
  display: flex; align-items: center; gap: 4px; min-height: 52px; flex-wrap: wrap;
}
.brand { font-weight: 700; color: var(--text); margin-right: 16px; letter-spacing: .02em; }
.brand:hover { text-decoration: none; }
.nav a {
  display: inline-block; padding: 6px 10px; border-radius: 6px; color: var(--muted); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.on { color: var(--accent); background: var(--accent-soft); }
.spacer { flex: 1; }

main { max-width: 1180px; margin: 0 auto; padding: 24px 16px 64px; }
main.narrow { max-width: 460px; }

.page-head { display: flex; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head > div:first-child { flex: 1; min-width: 240px; }
.crumbs { font-size: .85rem; color: var(--muted); margin-bottom: 4px; }

.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid.side { grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); }
@media (max-width: 860px) { .grid.side { grid-template-columns: 1fr; } }
.stack > * + * { margin-top: 16px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); min-width: 0;
}
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.empty { color: var(--muted); padding: 12px 0; }

/* -- controls ---------------------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  font: inherit; font-weight: 500; line-height: 1.2;
  padding: 7px 12px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { background: var(--bad-soft); }
.btn.sm { padding: 3px 8px; font-size: .85rem; }
.btn.link { border: 0; background: none; color: var(--accent); padding: 0; }
.btn:disabled { opacity: .5; cursor: default; }

label { display: block; font-weight: 500; font-size: .88rem; margin-bottom: 3px; }
input[type=text], input[type=email], input[type=number], input[type=date], input[type=file],
input:not([type]), select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 6px; padding: 6px 9px; width: 100%; max-width: 100%;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
textarea { min-height: 70px; resize: vertical; }
.field { margin-bottom: 12px; }
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 0 12px; }
.inline-form { display: inline; }
.help { color: var(--muted); font-size: .82rem; margin-top: 2px; }
input[type=range] { width: 100%; accent-color: var(--accent); }
input.tight, select.tight { padding: 3px 6px; }

/* -- tables ------------------------------------------------------------------ */

.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; }
table.compact th, table.compact td { padding: 3px 8px; font-size: .85rem; }

/* -- small pieces ------------------------------------------------------------ */

.badge {
  display: inline-block; font-size: .75rem; font-weight: 600; padding: 1px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }

.flash { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 14px; border: 1px solid var(--border); background: var(--surface); }
.flash.error { background: var(--bad-soft); border-color: transparent; color: var(--bad); }
.flash.success { background: var(--good-soft); border-color: transparent; color: var(--good); }
.flash.warning { background: var(--warn-soft); border-color: transparent; }

.secret {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .88rem;
  background: var(--surface-2); padding: 8px 10px; border-radius: 6px; word-break: break-all; user-select: all;
}

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; }
.stat { background: var(--surface-2); border-radius: var(--radius); padding: 10px 12px; }
.stat b { display: block; font-size: 1.35rem; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: .82rem; }

/* Horizontal bar drawn in CSS: <div class="bar"><i style="width:42%"></i></div> */
.bar { background: var(--surface-2); border-radius: 4px; height: 10px; min-width: 60px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.bar.good > i { background: var(--good); }
.barrow { display: grid; grid-template-columns: minmax(90px, 200px) 1fr 52px; gap: 8px; align-items: center; padding: 2px 0; font-size: .9rem; }
.barrow > :first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.share { display: flex; height: 26px; border-radius: 6px; overflow: hidden; background: var(--surface-2); }
.share > span { display: block; min-width: 2px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 8px; font-size: .88rem; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: baseline; }

.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip {
  display: inline-block; padding: 1px 7px; border-radius: 4px; font-size: .82rem;
  background: var(--surface-2); border-left: 3px solid var(--border); white-space: nowrap;
}
.chip.win { background: var(--good-soft); border-left-color: var(--good); }

/* Slate colours, shared by CSS and the charts (see cpn.js). */
.s0 { --c: #2f6fde; } .s1 { --c: #e0782a; } .s2 { --c: #1f9d6b; } .s3 { --c: #b04ad0; }
.s4 { --c: #d0a01f; } .s5 { --c: #d0456a; } .s6 { --c: #2aa7c0; } .s7 { --c: #7a8a2a; }
.sx { --c: #9aa3b0; }
.dot[class*=" s"], .share > span[class^="s"] { background: var(--c); }
.chip[class*=" s"] { border-left-color: var(--c); }
.card.slate { border-top: 3px solid var(--c); }

.chart { width: 100%; height: 320px; }
.chart.tall { height: 460px; }
.chart.short { height: 220px; }

.progress { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; max-width: 360px; }
.progress > i { display: block; height: 100%; background: var(--accent); transition: width .4s; }

details > summary { cursor: pointer; font-weight: 500; }
details[open] > summary { margin-bottom: 8px; }
pre { background: var(--surface-2); padding: 10px; border-radius: 6px; overflow-x: auto; font-size: .82rem; margin: 0; }

.rounds td.elected { background: var(--good-soft); color: var(--good); font-weight: 600; }
.rounds td.out { background: var(--bad-soft); color: var(--bad); }
.rounds td.gone { color: var(--muted); opacity: .45; }
.rounds th.sticky, .rounds td.sticky { position: sticky; left: 0; background: var(--surface); z-index: 1; }

.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 2px 10px; max-height: 260px; overflow-y: auto; padding: 4px; border: 1px solid var(--border); border-radius: 6px; }
.checks label { font-weight: 400; margin: 0; display: flex; gap: 6px; align-items: center; }
.checks input { width: auto; }

.cohort-head { grid-template-columns: 2fr 110px 2fr auto; align-items: end; }
@media (max-width: 600px) { .cohort-head { grid-template-columns: 1fr 1fr; } }

.scroll { max-height: 440px; overflow-y: auto; padding-right: 6px; }

[x-cloak] { display: none !important; }
.sticky-side { position: sticky; top: 68px; }
