/*
 * ISOTHERM — design system.
 *
 * One rule governs every colour decision: COLOUR MEANS TEMPERATURE. The interface is achromatic —
 * ink on cool survey paper — and the thermal ramp is spent only on measurements. A rage click is
 * red because it is the hot end of a scale, not because red looks urgent. Anything chromatic on
 * the page is data.
 *
 * That rule is what makes this read as an instrument rather than a dashboard. Break it and it
 * becomes a SaaS template with a nice font.
 */

:root {
    /* Paper: the cool grey-green of a printed survey quad, not warm cream. */
    --paper:      #eef1ee;
    --sheet:      #fafbf9;
    --sheet-sunk: #e7ebe7;

    --ink:   #16201d;
    --ink-2: #4a5852;
    --ink-3: #86958d;

    --rule:      #c9d2cb;
    --graticule: #dde3dd;

    /* The thermal ramp. Data only. Never chrome. */
    --t-cold: #2f6ba3;
    --t-cool: #3d9bb5;
    --t-mid:  #5aa96a;
    --t-warm: #d99a2b;   /* dead clicks: warm, not yet burning */
    --t-hot:  #c8412c;   /* rage: the top of the scale */

    --focus: #16201d;

    --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
    --sans: "IBM Plex Sans", ui-sans-serif, system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-font-smoothing: antialiased; scroll-behavior: smooth; }

body {
    margin: 0;
    font-family: var(--sans);
    font-size: 14px;
    line-height: 1.55;
    color: var(--ink);
    background-color: var(--paper);
    /* The graticule. Every survey sheet is printed on one; it sits under the content rather than
       decorating it, so it reads as substrate, not texture. */
    background-image:
        linear-gradient(var(--graticule) 1px, transparent 1px),
        linear-gradient(90deg, var(--graticule) 1px, transparent 1px);
    background-size: 32px 32px;
    background-position: -1px -1px;
}

/* ── Type ─────────────────────────────────────────────────────────────────
   Headings and every numeral are mono, uppercase, letterspaced: the register of chart marginalia
   and plotter output. Prose stays in the sans. Inverting the usual mono-is-for-code convention is
   the point — this is an instrument's voice, not a blog's. */

h1, h2, .eyebrow, th, .btn, label.field {
    font-family: var(--mono);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

h1 { font-size: 15px; margin: 0; }
h2 { font-size: 11px; margin: 0 0 14px; color: var(--ink-2); }

.eyebrow { font-size: 10px; color: var(--ink-3); letter-spacing: 0.14em; }

.num, .stat-value { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.prose { color: var(--ink-2); max-width: 68ch; }
.muted { color: var(--ink-3); }

a { color: var(--ink); text-decoration: none; border-bottom: 1px solid var(--rule); }
a:hover { border-bottom-color: var(--ink); }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ── Chrome ───────────────────────────────────────────────────────────── */

.masthead {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 28px;
    height: 56px;
    background: var(--sheet);
    border-bottom: 1px solid var(--ink);
}

.brand {
    display: flex;
    align-items: center;
    gap: 9px;
    font-family: var(--mono);
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    font-size: 13px;
    border: 0;
}

.crumb { font-family: var(--mono); font-size: 12px; color: var(--ink-3); }
.crumb a { border-bottom: 0; color: var(--ink-2); }
.crumb a:hover { color: var(--ink); border-bottom: 1px solid var(--ink); }

.spacer { flex: 1; }

/* ── Panels ───────────────────────────────────────────────────────────── */

.panel {
    background: var(--sheet);
    border: 1px solid var(--rule);
    padding: 20px;
    margin-bottom: 20px;
}
.panel > h2:first-child { margin-top: 0; }

.cols { display: grid; gap: 20px; }
@media (min-width: 900px) { .cols.two { grid-template-columns: 1fr 1fr; } }

/* ── Tables: a gazetteer, not a data grid ─────────────────────────────── */

table { width: 100%; border-collapse: collapse; }

th {
    font-size: 10px;
    color: var(--ink-3);
    text-align: left;
    padding: 0 14px 8px 0;
    border-bottom: 1px solid var(--ink);
}
td {
    padding: 12px 14px 12px 0;
    border-bottom: 1px solid var(--graticule);
    vertical-align: middle;
}
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--sheet-sunk); }
th:last-child, td:last-child { padding-right: 0; text-align: right; }
td.num, th.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ── Readings: colour = temperature, and only ever temperature ─────────── */

.reading {
    font-family: var(--mono);
    font-variant-numeric: tabular-nums;
    font-weight: 500;
    font-size: 12px;
    display: inline-flex;
    align-items: baseline;
    gap: 5px;
}
.reading::before { content: ""; width: 7px; height: 7px; border-radius: 50%; align-self: center; }
.reading.rage::before { background: var(--t-hot); }
.reading.dead::before { background: var(--t-warm); }
.reading.zero { color: var(--ink-3); }
.reading.zero::before { background: var(--rule); }

/* ── Controls ─────────────────────────────────────────────────────────── */

.btn {
    display: inline-block;
    font-size: 11px;
    background: var(--ink);
    color: var(--sheet);
    border: 1px solid var(--ink);
    padding: 9px 15px;
    cursor: pointer;
    line-height: 1.2;
    text-decoration: none;
}
.btn:hover { background: #000; color: var(--sheet); border-bottom-color: #000; }

.btn.quiet { background: transparent; color: var(--ink-2); border-color: var(--rule); }
.btn.quiet:hover { background: var(--sheet-sunk); color: var(--ink); border-color: var(--rule); }

.btn.link {
    background: none; border: 0; padding: 2px 0;
    color: var(--ink-3); text-transform: none; letter-spacing: 0;
    font-family: var(--sans); font-size: 12px;
    text-decoration: underline; text-decoration-color: var(--rule);
    cursor: pointer;
}
.btn.link:hover { color: var(--t-hot); background: none; }

input, select, textarea {
    font-family: var(--sans);
    font-size: 13px;
    color: var(--ink);
    background: var(--sheet);
    border: 1px solid var(--rule);
    padding: 8px 10px;
    border-radius: 0;
}
input::placeholder { color: var(--ink-3); }
input:focus, select:focus { outline: 2px solid var(--focus); outline-offset: -1px; border-color: var(--ink); }

select {
    font-family: var(--mono);
    font-size: 12px;
    appearance: none;
    padding-right: 26px;
    background-image: linear-gradient(45deg, transparent 50%, var(--ink-2) 50%), linear-gradient(135deg, var(--ink-2) 50%, transparent 50%);
    background-position: calc(100% - 14px) 52%, calc(100% - 9px) 52%;
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
}

form.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
label.field { display: block; font-size: 10px; color: var(--ink-3); margin-bottom: 6px; }

/* ── Code ─────────────────────────────────────────────────────────────── */

.snippet {
    font-family: var(--mono);
    font-size: 12.5px;
    background: var(--paper);
    border: 1px solid var(--rule);
    border-left: 3px solid var(--ink);
    padding: 14px 16px;
    overflow-x: auto;
    white-space: pre;
    color: var(--ink);
    margin: 0;
}

/* ── Tags, notices, empty states ──────────────────────────────────────── */

.tag {
    font-family: var(--mono);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 3px 7px;
    border: 1px solid var(--rule);
    color: var(--ink-2);
    background: var(--paper);
}
.tag.exclude { border-color: var(--t-hot); color: var(--t-hot); }

.notice {
    font-size: 13px;
    background: var(--sheet);
    border: 1px solid var(--ink);
    border-left: 3px solid var(--t-mid);
    padding: 11px 15px;
    margin-bottom: 20px;
}

.empty {
    padding: 44px 20px;
    text-align: center;
    color: var(--ink-3);
    border: 1px dashed var(--rule);
}
.empty strong { display: block; color: var(--ink); font-weight: 500; margin-bottom: 4px; }

/* ── Page header ──────────────────────────────────────────────────────── */

main { padding: 28px; max-width: 1360px; margin: 0 auto; }

.page-head { margin-bottom: 24px; }
.page-head h1 { margin-bottom: 6px; }

/* Only headers that carry actions become a row. Making every .page-head flex turns the eyebrow
   and the heading into siblings on one line, which is wrong everywhere else. */
.page-head.split { display: flex; align-items: flex-end; gap: 20px; flex-wrap: wrap; }
.page-head.split .actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }

.tabs { display: flex; gap: 2px; margin-bottom: 20px; border-bottom: 1px solid var(--rule); }
.tabs a {
    font-family: var(--mono);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--ink-3);
    padding: 9px 14px;
    border: 0;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
}
.tabs a:hover { color: var(--ink); border-bottom-color: var(--rule); }
.tabs a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--ink); }

/* ── Modal ────────────────────────────────────────────────────────────────
   A native <dialog>: focus is trapped, Escape closes it, and the backdrop is inert — all of which
   a hand-rolled div has to reimplement and usually gets wrong for keyboard users. */

dialog {
    padding: 0;
    border: 1px solid var(--ink);
    background: var(--sheet);
    color: var(--ink);
    max-width: min(760px, calc(100vw - 32px));
    width: 100%;
    max-height: calc(100vh - 64px);
}
dialog::backdrop { background: rgba(22, 32, 29, .38); }

dialog .modal-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--rule);
}
dialog .modal-head h2 { margin: 0; }
dialog .modal-body { padding: 20px; overflow-y: auto; }
dialog .modal-close {
    margin-left: auto;
    background: none;
    border: 1px solid var(--rule);
    color: var(--ink-2);
    font-family: var(--mono);
    font-size: 14px;
    line-height: 1;
    padding: 6px 9px;
    cursor: pointer;
}
dialog .modal-close:hover { background: var(--sheet-sunk); color: var(--ink); }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
