/* benjaminr.ca admin panel. Brand: navy #0A1640, madder #8B1A1A, Archivo headings, Inter text.
   Chart colours follow the data-viz rules: one blue for "this period", a grey for context (validated: 3:1 on the
   surface, colour-blind and normal-vision separation), hairline grid, values in text colours, never in series colours. */
:root {
  color-scheme: light;
  --page: #f4f5f8; --surface: #ffffff; --raised: #f8f9fb; --ink: #141a2e; --ink-2: #4a5168; --muted: #6f768b;
  --grid: #e7e9ef; --axis: #c9cdd8; --border: rgba(20, 26, 46, .10); --navy: #0A1640; --navy-2: #13235A; --accent: #8B1A1A; --accent-ink: #fff;
  --link: #1c5cab; --series-1: #2a78d6; --series-ctx: #878da0; --wash: rgba(42, 120, 214, .10); --good: #006300; --bad: #b42318;
  --focus: #2a78d6; --shadow: 0 1px 2px rgba(20, 26, 46, .06), 0 4px 16px rgba(20, 26, 46, .05);
  --font-head: "Archivo", system-ui, sans-serif; --font-body: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0b1020; --surface: #141a2e; --raised: #1a2138; --ink: #eef0f6; --ink-2: #b8bdcc; --muted: #8f95a8;
    --grid: #232a42; --axis: #343c58; --border: rgba(255, 255, 255, .10); --link: #86b6ef;
    --series-1: #3987e5; --series-ctx: #646b86; --wash: rgba(57, 135, 229, .14); --good: #0ca30c; --bad: #e66767; --focus: #86b6ef;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0b1020; --surface: #141a2e; --raised: #1a2138; --ink: #eef0f6; --ink-2: #b8bdcc; --muted: #8f95a8;
  --grid: #232a42; --axis: #343c58; --border: rgba(255, 255, 255, .10); --link: #86b6ef;
  --series-1: #3987e5; --series-ctx: #646b86; --wash: rgba(57, 135, 229, .14); --good: #0ca30c; --bad: #e66767; --focus: #86b6ef;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--page); color: var(--ink); font: 400 15px/1.5 var(--font-body); -webkit-font-smoothing: antialiased; }
a { color: var(--link); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
h1, h2, h3 { font-family: var(--font-head); line-height: 1.2; margin: 0; letter-spacing: -.01em; }
.sr { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
button, input, select, textarea { font: inherit; color: inherit; }

/* Shell: navy sidebar, content beside it */
.shell { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; background: linear-gradient(to right, var(--navy) 236px, transparent 236px); }
.side { background: var(--navy); color: #fff; display: flex; flex-direction: column; padding: 20px 14px; position: sticky; top: 0; height: 100vh; }
.brand { display: grid; gap: 8px; padding: 4px 8px 22px; color: #fff; text-decoration: none; }
.brand img { width: 160px; height: auto; display: block; }
.brand span { font: 600 .66rem var(--font-body); letter-spacing: .16em; text-transform: uppercase; color: rgba(255, 255, 255, .55); }
.nav { display: grid; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 11px; padding: 9px 10px; border-radius: 8px; color: rgba(255, 255, 255, .78); text-decoration: none; font-weight: 500; }
.nav a svg { width: 18px; height: 18px; flex: none; opacity: .85; }
.nav a:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.nav a[aria-current="page"] { background: rgba(255, 255, 255, .12); color: #fff; }
.nav .soon { margin-left: auto; font-size: .66rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: rgba(255, 255, 255, .55); border: 1px solid rgba(255, 255, 255, .25); border-radius: 999px; padding: 1px 7px; }
.side-foot { margin-top: auto; padding: 14px 10px 0; border-top: 1px solid rgba(255, 255, 255, .12); font-size: .82rem; color: rgba(255, 255, 255, .7); }
.side-foot b { display: block; color: #fff; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-foot button { margin-top: 8px; background: none; border: 1px solid rgba(255, 255, 255, .3); color: #fff; border-radius: 6px; padding: 5px 10px; cursor: pointer; font-size: .82rem; }
.side-foot button:hover { background: rgba(255, 255, 255, .08); }
.menu { display: none; }

.main { min-width: 0; padding: 26px 32px 60px; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.head h1 { font-size: 1.6rem; font-weight: 800; }
.head p { margin: 4px 0 0; color: var(--ink-2); font-size: .92rem; }

/* Filters: one row above everything they scope */
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px; margin: 0 0 18px; }
.seg { display: inline-flex; padding: 3px; background: var(--surface); border: 1px solid var(--border); border-radius: 9px; }
.seg button { border: 0; background: none; padding: 6px 12px; border-radius: 6px; cursor: pointer; color: var(--ink-2); font-weight: 500; font-size: .88rem; }
.seg button:hover { background: var(--raised); }
.seg button[aria-pressed="true"] { background: var(--navy); color: #fff; }
.filters .label { font-size: .78rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-right: -8px; }
.live { display: inline-flex; align-items: center; gap: 8px; font-size: .88rem; color: var(--ink-2); margin-left: auto; }
.live i { width: 8px; height: 8px; border-radius: 50%; background: #0ca30c; box-shadow: 0 0 0 3px rgba(12, 163, 12, .18); }

/* Cards and the grid */
.grid { display: grid; gap: 16px; }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); padding: 18px 20px; min-width: 0; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card h2 { font-size: 1rem; font-weight: 700; }
.card-head p, .note { margin: 2px 0 0; color: var(--muted); font-size: .84rem; }
.card-head a, .more { font-size: .86rem; font-weight: 500; white-space: nowrap; }
.refetch { opacity: .55; transition: opacity .2s; }

/* Stat tiles */
.tiles { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); padding: 14px 16px; min-width: 0; }
.tile .k { font-size: .82rem; color: var(--ink-2); }
.tile .v { font: 600 1.6rem/1.2 var(--font-body); margin-top: 4px; letter-spacing: -.01em; }
.tile .d { font-size: .8rem; margin-top: 4px; color: var(--muted); display: flex; align-items: center; gap: 4px; }
.tile .d.up { color: var(--good); }
.tile .d.down { color: var(--bad); }
.tile .d svg { width: 12px; height: 12px; }

/* Line chart */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .base { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { stroke: none; }
.chart .cross { stroke: var(--axis); stroke-width: 1; }
.chart .dot { stroke: var(--surface); stroke-width: 2; }
.chart:focus-visible { outline-offset: 6px; border-radius: 4px; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: .82rem; color: var(--ink-2); margin: 0 0 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 14px; height: 2px; border-radius: 2px; display: inline-block; }
.tip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 6px 20px rgba(0, 0, 0, .12);
  padding: 8px 10px; font-size: .8rem; min-width: 150px; z-index: 5; }
.tip .t { color: var(--muted); margin-bottom: 4px; }
.tip .r { display: flex; align-items: center; gap: 8px; }
.tip .r i { width: 12px; height: 2px; border-radius: 2px; }
.tip .r b { font-weight: 600; color: var(--ink); min-width: 32px; }
.tip .r span { color: var(--ink-2); }

/* Bar lists: label, a thin bar from one baseline, the value at its tip */
.bars { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.bars li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; align-items: center; font-size: .9rem; }
.bars .name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bars .name small { color: var(--muted); margin-left: 6px; }
.bars .val { font-variant-numeric: tabular-nums; color: var(--ink); font-weight: 600; font-size: .86rem; }
.bars .track { grid-column: 1 / -1; display: block; height: 8px; }
.bars .fill { display: block; height: 8px; background: var(--series-1); border-radius: 0 4px 4px 0; min-width: 2px; }

/* Tables */
.table-wrap { overflow-x: auto; margin: 0 -20px; padding: 0 20px; }
table { border-collapse: collapse; width: 100%; font-size: .88rem; }
caption { text-align: left; }
th { text-align: left; font-size: .74rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--grid); vertical-align: bottom; }
td.nw { white-space: nowrap; }
td { padding: 9px 10px; border-bottom: 1px solid var(--grid); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; }
td.n { white-space: nowrap; }
td .path { display: block; color: var(--muted); font-size: .78rem; overflow-wrap: anywhere; }
td .cellbar { display: block; height: 4px; margin-top: 6px; background: var(--series-1); border-radius: 0 2px 2px 0; opacity: .85; }
details.tv { margin-top: 10px; font-size: .86rem; }
details.tv summary { cursor: pointer; color: var(--link); font-weight: 500; }
details.tv table { margin-top: 8px; }

/* States */
.empty { padding: 28px 8px; text-align: center; color: var(--ink-2); }
.empty h2 { font-size: 1.05rem; margin-bottom: 6px; color: var(--ink); }
.empty p { margin: 0 auto 14px; max-width: 520px; }
.btn { display: inline-flex; align-items: center; gap: 8px; border: 1.5px solid transparent; border-radius: 7px; padding: 8px 14px; font-weight: 600; font-size: .88rem; cursor: pointer; text-decoration: none; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: none; border-color: var(--axis); color: var(--ink); }
.btn-ghost:hover { background: var(--raised); }
.btn[disabled] { opacity: .6; cursor: wait; }
.msg { padding: 10px 12px; border-radius: 8px; font-size: .88rem; margin: 10px 0 0; }
.msg.err { background: color-mix(in srgb, var(--bad) 12%, transparent); color: var(--ink); border: 1px solid color-mix(in srgb, var(--bad) 35%, transparent); }
.msg.ok { background: color-mix(in srgb, var(--good) 12%, transparent); color: var(--ink); border: 1px solid color-mix(in srgb, var(--good) 35%, transparent); }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: .84rem; font-weight: 600; }
.status i { width: 8px; height: 8px; border-radius: 50%; }
.status.on i { background: #0ca30c; }
.status.off i { background: var(--axis); }

/* Settings forms */
.form { display: grid; gap: 12px; max-width: 640px; }
.form label { display: grid; gap: 5px; font-size: .86rem; font-weight: 600; }
.form label span { font-weight: 400; color: var(--muted); }
.form input, .form textarea { width: 100%; padding: 9px 11px; border: 1px solid var(--axis); border-radius: 8px; background: var(--surface); }
.form textarea { min-height: 110px; font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; }
.form .row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.steps { margin: 12px 0 0; font-size: .88rem; color: var(--ink-2); }
.steps summary { cursor: pointer; color: var(--link); font-weight: 500; }
.steps ol { padding-left: 20px; margin: 8px 0 0; }
.steps li { margin-bottom: 6px; }
code { font: 12.5px ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--raised); padding: 1px 5px; border-radius: 4px; overflow-wrap: anywhere; }

/* 3D map: the app in a sandboxed frame, filling the space */
.mapbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.mapframe { width: 100%; height: calc(100vh - 150px); min-height: 520px; border: 1px solid var(--border); border-radius: 12px; background: #0A1640; display: block; }

/* Research */
.ideas { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-top: 16px; }
.idea { border: 1px dashed var(--axis); border-radius: 12px; padding: 16px; }
.idea h3 { font-size: .95rem; margin-bottom: 6px; }
.idea p { margin: 0; color: var(--ink-2); font-size: .86rem; }

/* Sign-in screen */
.gate { min-height: 100vh; display: grid; place-items: center; background: var(--navy); color: #fff; padding: 24px; }
.gate .box { text-align: center; max-width: 380px; }
.gate img { width: 200px; margin-bottom: 20px; }
.gate p { color: rgba(255, 255, 255, .75); }

@media (max-width: 1180px) { .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); background: none; }
  .side { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 20; transform: translateX(-100%); transition: transform .2s; }
  .shell.open .side { transform: none; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .35); }
  .menu { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 7px 10px; cursor: pointer; margin-bottom: 14px; }
  .main { padding: 16px 16px 48px; }
  .cols-2, .ideas { grid-template-columns: minmax(0, 1fr); }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .live { margin-left: 0; }
  .mapframe { height: calc(100vh - 170px); }
}
@media (prefers-reduced-motion: reduce) { .side { transition: none; } }
