/*
 * The moderation dashboard (ARCHITECTURE.md §9.4, §9.6, §10.4).
 *
 * Read at a glance, between answering questions on stream. Two rules drive the visual design:
 *   - Platform is carried by an icon AND a word, never by colour alone. Colour is reinforcement.
 *   - Nothing animates except the two things that must be noticed: a row arriving and a row
 *     leaving. Everything else holding still is what makes those two legible.
 */

:root {
    --bg: #14161a;
    --surface: #1c1f26;
    --surface-2: #232730;
    --line: #2e333d;
    --text: #e6e8ec;
    --muted: #949aa6;
    --twitch: #9146ff;
    --youtube: #ff4d4d;
    --ok: #3fb950;
    --no: #f0883e;
    --danger: #e5534b;
    /*
     * Its own variable rather than reusing --danger, even though both are red. A highlighted
     * question is the opposite of a problem — it is the one being answered — and the two will
     * want tuning in opposite directions the first time they are seen side by side.
     */
    --highlight: #e5484d;
    --star: #e5484d;
}

* { box-sizing: border-box; }

/*
 * A fixed shell: the page does not scroll, the four lists do (§9.4).
 *
 * That is what lets the vertical split be a proportion rather than a consequence. With the page
 * scrolling there is no height for "65%" to be 65% of, and a question arriving in NEW would
 * lengthen the page and push DISCARDED further down — the movement this layout exists to
 * prevent (D25).
 */
html { height: 100%; }

body {
    margin: 0;
    height: 100dvh;
    overflow: hidden;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.45 "Segoe UI", system-ui, sans-serif;
}

main {
    max-width: 1400px;
    height: 100%;
    margin: 0 auto;
    padding: 0 16px 16px;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* ── The two columns, each split in two ─────────────────────────────────────────────── */

/*
 * Equal widths rather than a wider NEW. The two lists are read in opposite directions — NEW is
 * scanned for something worth keeping, ACCEPTED is worked from the top — and giving either more
 * room implies a priority that changes through a stream (§9.4).
 *
 * "Equal" has to be enforced twice, and the two clamps below do different jobs. One unbreakable
 * 400-character question used to make its column 2410 px wide against the other's 623 px and
 * push the document sideways to 3166 px. All the numbers here are measured, not reasoned about
 * — `tools/layout-check.html`, which exists because jsdom has no layout engine and every test
 * in this repository was structurally unable to see any of it.
 *
 *   - `minmax(0, 1fr)` rather than a bare `1fr`, which means `minmax(auto, 1fr)` and floors the
 *     track at its content's width. On its own this keeps the two columns **equal** — and lets
 *     the content spill out of them: skew 0, document 3215 px wide.
 *   - `min-width: 0` on `.column` and `.panel` (below). A grid item has an automatic minimum of
 *     its own content too, so the track clamp alone only moves the problem inwards. On its own
 *     this fixes **both** symptoms, which makes it the load-bearing half.
 *
 * Keeping the redundant one is deliberate: it is what holds the columns to the same width if a
 * descendant ever reintroduces a minimum the clamps do not reach, and that failure is the
 * disorienting one — a queue that is visibly lopsided is harder to read than one that scrolls.
 */
.columns {
    flex: 1 1 auto;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 24px;
}

/*
 * Each column owns its own split. That is the whole reason this is two columns of two rather
 * than one 2×2 grid: shared rows would mean opening DISCARDED also moved ANSWERED, and the two
 * are consulted for unrelated reasons at unrelated moments.
 *
 * Closed, the bottom row is `auto` — one line of heading. Nothing below it can be pushed
 * anywhere by the length of the list above, because the top row is what absorbs the remainder.
 */
.column {
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
    gap: 12px;
    min-height: 0;
    min-width: 0;
}

/*
 * Open: roughly 65/35. fr rather than percentages, so the gap comes out of the total before
 * the ratio is applied and the two rows cannot sum to more than the column.
 */
.column.open { grid-template-rows: minmax(0, 65fr) minmax(0, 35fr); }

/*
 * One column below the width where two would each be too narrow for a question plus its action
 * row. §9.6 requires the platform badge and the actions to survive a narrow viewport, and they
 * cannot at half of 900px.
 */
@media (max-width: 900px) {
    /*
     * The shell unwinds. A fixed split on a phone would divide a short screen into four scroll
     * areas of a few centimetres each, which is worse than scrolling one page.
     */
    html, body { height: auto; overflow: visible; }
    main { height: auto; display: block; padding-bottom: 96px; }

    /*
     * Stacking the column wrappers puts each history directly under the list it came from:
     * NEW, DISCARDED, ACCEPTED, ANSWERED. That order is what the wrappers are for.
     */
    .columns { display: block; }
    .column { display: block; }

    .panel { margin: 16px 0; }
    .panel > .questions,
    .history-body > .questions { overflow: visible; }

    /* Fingers, not a mouse (§9.6). */
    .q-actions button,
    .disclosure { min-height: 44px; }
}

/* ── Top bar and indicators ─────────────────────────────────────────────────────────── */

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 10px 0;
    background: var(--bg);
    border-bottom: 1px solid var(--line);
}

.brand { font-weight: 700; letter-spacing: 0.02em; }
.topbar .who { margin-left: auto; color: var(--muted); font-size: 13px; }
.topbar form { margin: 0; }

/*
 * Muted until there is something to clear, and unmistakably red once there is. It sits two
 * elements from "Sign out", so the disabled state is doing real work: the only destructive
 * control on the page should not look pressable when pressing it does nothing.
 */
.topbar #clear-dashboard:disabled {
    background: none;
    border-color: var(--line);
    color: var(--muted);
    opacity: 0.6;
    cursor: not-allowed;
}

.indicators { display: flex; gap: 8px; }

.ind {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 9px;
    border: 1px solid var(--line);
    border-radius: 999px;
    font-size: 12px;
    white-space: nowrap;
}

/* Grey is the resting state, not a warning: a Twitch-only day looks exactly like this (D13). */
.ind-idle { color: var(--muted); }
.ind-unknown { color: var(--muted); border-style: dashed; }
.ind-live { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 45%, transparent); }

.ind-error {
    color: var(--danger);
    border-color: var(--danger);
    background: color-mix(in srgb, var(--danger) 12%, transparent);
}

.banner {
    margin: 12px 0;
    padding: 10px 12px;
    border: 1px solid var(--danger);
    border-radius: 6px;
    background: color-mix(in srgb, var(--danger) 12%, transparent);
    font-size: 14px;
}

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

.panel {
    margin: 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
}

/* The scroll lives on the list, so a heading stays put while its rows move under it. */
.panel > .questions,
.history-body > .questions {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
}

.panel h2 {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0 0 8px;
    font-size: 14px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
}

.count {
    padding: 1px 8px;
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--text);
    font-size: 12px;
}

.toggle {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    text-transform: none;
    letter-spacing: 0;
    font-weight: 400;
    cursor: pointer;
}

.legend { margin: 0 0 8px; font-size: 12px; color: var(--muted); }
.empty { margin: 8px 0; color: var(--muted); font-size: 14px; }

/*
 * The two history sections (§9.4).
 *
 * Quieter than the list above, and closed by default so the working list gets nearly the whole
 * column. Closed it is one line, and the count on that line is the entire message: a section
 * that has been shut for weeks still has to say whether there is anything behind it.
 */
.panel.history {
    padding-top: 12px;
    border-top: 1px solid var(--line);
}

.column:not(.open) .history-body { display: none; }

.history-body {
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.disclosure {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 2px 0;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    text-transform: inherit;
    letter-spacing: inherit;
    text-align: left;
    cursor: pointer;
}

.disclosure:focus-visible { outline: 2px solid var(--twitch); outline-offset: 2px; }
.caret { display: inline-block; width: 1em; color: var(--muted); }

#expand-discarded { margin-top: 4px; flex: 0 0 auto; }

/*
 * ANSWERED rows are one line, and carry no buttons.
 *
 * The list is consulted, not worked — "did we already cover that?" — so the full text lives in
 * the tooltip. A row that wrapped to three lines would turn a reference into a second queue
 * competing with the real one above it, and undo belongs to the ten-second toast (D22).
 */
.answered .q { cursor: default; }

/*
 * One line of question, truncated. The row itself is the same three-part card as NEW and
 * ACCEPTED — head, content, metadata — so the age sits in the same corner in all three and
 * means the same thing in all three.
 */
.answered .q-text {
    margin-top: 4px;
    overflow-wrap: normal;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.answered .attribution { margin-top: 2px; }

/* ── Question rows ──────────────────────────────────────────────────────────────────── */

.questions { list-style: none; margin: 0; padding: 0; }
.questions:focus-visible { outline: 2px solid var(--twitch); outline-offset: 4px; }

.q {
    margin: 0 0 8px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-left: 3px solid var(--line);
    border-radius: 6px;
    background: var(--surface);
    transition: opacity 150ms ease, background 400ms ease;
}

.q.compact { padding: 7px 10px; font-size: 13px; opacity: 0.8; }
.q.selected { border-left-color: var(--twitch); background: var(--surface-2); }
/*
 * The one row the streamer is on. It has to win against every other signal in the list at a
 * glance from across a desk, so it takes all four borders and a tinted background rather than
 * the single accent edge every other state uses — and the ★ stays, because colour alone is
 * never the sole carrier of meaning here (§10.4, D30).
 */
.q.highlighted {
    border-color: var(--highlight);
    background: color-mix(in srgb, var(--highlight) 16%, var(--surface));
}

/* The only two animations on the page: a row appearing and a row going away (§9.4, D25). */
.q.arrived { background: color-mix(in srgb, var(--ok) 14%, var(--surface)); }
.q.leaving { opacity: 0; }

/*
 * One line, and it never becomes two.
 *
 * It used to wrap: with `flex-wrap: wrap` a long author name pushed the age onto a second line,
 * which changed the row's height and moved every row below it — the shift under the cursor D25
 * spent a whole section preventing, arriving from the one direction nobody had checked.
 *
 * So nothing wraps, and the priority when space runs out is explicit. The badge and the
 * [offline] chip never shrink, because §10.4 says no compact mode may drop them and a narrow
 * viewport is a compact mode. The age never shrinks either, because it is a fixed column. The
 * author is the only thing that gives, and it gives by truncating.
 */
.q-head { display: flex; align-items: center; gap: 8px; flex-wrap: nowrap; }
.q-text { margin-top: 6px; overflow-wrap: anywhere; }

.q-head .badge,
.q-head .chip,
.q-head .pos,
.q-head .star { flex: 0 0 auto; }

.pos { color: var(--muted); font-variant-numeric: tabular-nums; }

.author {
    color: var(--muted);
    font-size: 13px;
    /* min-width: 0 is what actually permits the shrink — without it a flex item refuses to go
       below its content width and the ellipsis never appears. */
    flex: 0 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.age { color: var(--muted); font-size: 12px; }

/*
 * A fixed column, right-aligned, with tabular figures: "9 min" to "10 min" must not move
 * anything, and neither must "59 min" to "1 h" (§9.4, D25). Width is set from the longest
 * string the formatter can produce, which is "just now" — wider than any number it will ever
 * show, which is the point.
 *
 * Scoped to .q-head so the discarded rows, whose age sits inline inside .attribution, keep
 * reading as a sentence rather than acquiring a column of their own.
 */
.q-head .age {
    margin-left: auto;
    flex: 0 0 4.5rem;
    text-align: right;
    font-variant-numeric: tabular-nums;
}
.star { color: var(--star); }

.attribution { margin-top: 6px; color: var(--muted); font-size: 12px; }

.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 1px 7px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}

.badge-twitch { background: color-mix(in srgb, var(--twitch) 22%, transparent); color: #c4a2ff; }
.badge-youtube { background: color-mix(in srgb, var(--youtube) 20%, transparent); color: #ff9b9b; }

.chip {
    padding: 1px 6px;
    border: 1px solid var(--line);
    border-radius: 4px;
    font-size: 11px;
    color: var(--muted);
}

.chip-dup { cursor: help; }

.q-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.q-actions button:disabled { opacity: 0.35; cursor: not-allowed; }

.history { margin-top: 8px; border-top: 1px solid var(--line); padding-top: 6px; }
.history ul { list-style: none; margin: 0; padding: 0; font-size: 12px; color: var(--muted); }
.history li { padding: 2px 0; }
.history .arrival { color: var(--text); }
.history .detail { font-style: italic; }

/* ── Buttons ────────────────────────────────────────────────────────────────────────── */

.btn {
    padding: 4px 10px;
    border: 1px solid var(--line);
    border-radius: 5px;
    background: var(--surface-2);
    color: var(--text);
    font: inherit;
    font-size: 13px;
    cursor: pointer;
}

.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn-ok { color: var(--ok); }
.btn-no { color: var(--no); }
.btn-quiet { background: none; border-color: transparent; color: var(--muted); }
.btn-danger { color: #fff; background: var(--danger); border-color: var(--danger); }

.btn-twitch {
    display: inline-block;
    padding: 10px 18px;
    background: var(--twitch);
    border-color: var(--twitch);
    color: #fff;
    font-size: 15px;
    text-decoration: none;
}

.danger {
    margin: 40px 0 0;
    padding-top: 16px;
    border-top: 1px solid var(--line);
    display: flex;
    gap: 8px;
}

/* ── The "n new" pill ───────────────────────────────────────────────────────────────── */

.pill {
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translateX(-50%);
    z-index: 30;
    padding: 6px 14px;
    border: 1px solid var(--twitch);
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--text);
    font: inherit;
    font-size: 13px;
    cursor: pointer;
}

/* ── Toasts ─────────────────────────────────────────────────────────────────────────── */

.toasts {
    position: fixed;
    right: 16px;
    bottom: 16px;
    z-index: 40;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--surface-2);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
    font-size: 13px;
}

.toast-error {
    border-color: var(--danger);
    background: color-mix(in srgb, var(--danger) 18%, var(--surface-2));
}

/* ── Clear confirmation ─────────────────────────────────────────────────────────────── */

dialog {
    max-width: 460px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
}

dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog h3 { margin-top: 0; }
dialog code { padding: 1px 5px; border-radius: 4px; background: var(--surface-2); }

dialog input {
    width: 100%;
    padding: 7px 9px;
    border: 1px solid var(--line);
    border-radius: 5px;
    background: var(--bg);
    color: var(--text);
    font: inherit;
}

dialog menu { display: flex; justify-content: flex-end; gap: 8px; margin: 14px 0 0; padding: 0; }

/* ── Disconnected ───────────────────────────────────────────────────────────────────── */

/*
 * Visibly inert. REST would still succeed, but against a list already known to be stale, so the
 * page stops taking input rather than letting a moderator act on a view it cannot vouch for
 * (§9.3.1).
 */
body.disconnected .questions { opacity: 0.55; }

/* ── Login ──────────────────────────────────────────────────────────────────────────── */

.login { max-width: 420px; margin: 18vh auto 0; text-align: center; }
.login h1 { margin-bottom: 24px; letter-spacing: 0.02em; }
.login-note { margin-top: 28px; color: var(--muted); font-size: 13px; text-align: left; }

.login-error {
    margin-bottom: 18px;
    padding: 10px 12px;
    border: 1px solid var(--danger);
    border-radius: 6px;
    background: color-mix(in srgb, var(--danger) 12%, transparent);
    text-align: left;
}
