/* TowerPulse — application styles.
 *
 * Served from our own origin: the CSP allows no external stylesheet host, and
 * script-src has no CDN (see infra/caddy/Caddyfile).
 *
 * Two rules the review UI depends on:
 *  - Confidence is never carried by colour alone. Every chip pairs its colour
 *    with a glyph and a title, so an amber value is visible to a colour-blind
 *    reviewer and in a printed export review (doc 06 §1.2).
 *  - The review screen must be usable without a mouse (doc 06 §5), so focus is
 *    always visible and never removed.
 */

:root {
    /* Cellnex green as the primary. */
    --green:        #00843d;
    --green-dark:   #006330;
    --amber:        #b8860b;
    --amber-bg:     #fdf6e3;
    --ink:          #1a1d1a;
    --ink-muted:    #5c635c;
    --line:         #d9ded9;
    --bg:           #ffffff;
    --bg-sunken:    #f6f8f6;
    --radius:       6px;
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
    :root {
        --green:      #3fbf74;
        --green-dark: #2ea15e;
        --amber:      #e0a92b;
        --amber-bg:   #2d2716;
        --ink:        #e8ece8;
        --ink-muted:  #a3aca3;
        --line:       #333a33;
        --bg:         #141714;
        --bg-sunken:  #1c201c;
    }
}

*, *::before, *::after { box-sizing: border-box; }

body {
    margin: 0;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    color: var(--ink);
    background: var(--bg);
}

/* Focus is never removed — the review queue is cleared with the keyboard. */
:focus-visible {
    outline: 2px solid var(--green);
    outline-offset: 2px;
}

.visually-hidden {
    position: absolute; width: 1px; height: 1px;
    padding: 0; margin: -1px; overflow: hidden;
    clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link {
    position: absolute; left: -9999px; top: 0;
    background: var(--green); color: #fff; padding: .6rem 1rem; z-index: 100;
}
.skip-link:focus { left: 0; }

/* ------------------------------------------------------------------ topbar */
.topbar {
    display: flex; align-items: center; gap: 1rem;
    padding: .6rem 1rem;
    border-bottom: 1px solid var(--line);
    background: var(--bg-sunken);
}
.brand { font-weight: 650; color: var(--green); text-decoration: none; font-size: 1.05rem; }
.global-search { flex: 1 1 auto; max-width: 34rem; }
.global-search input {
    width: 100%; padding: .45rem .7rem;
    border: 1px solid var(--line); border-radius: var(--radius);
    background: var(--bg); color: inherit; font: inherit;
}
.user-menu { display: flex; align-items: center; gap: .7rem; font-size: .85rem; }
.user-email { color: var(--ink-muted); }
.role-pill {
    border: 1px solid var(--line); border-radius: 99px;
    padding: .1rem .55rem; font-size: .75rem; color: var(--ink-muted);
}
.inline { display: inline; }
.btn-link {
    background: none; border: 0; padding: 0; font: inherit;
    color: var(--green); cursor: pointer; text-decoration: underline;
}

/* Staging must never be mistaken for production. */
.env-badge {
    font-size: .7rem; font-weight: 700; letter-spacing: .06em;
    padding: .15rem .5rem; border-radius: var(--radius);
    background: var(--amber); color: #1a1d1a;
}
.env-badge.env-dev { background: var(--ink-muted); color: #fff; }

/* --------------------------------------------------------------- main nav */
.mainnav {
    display: flex; align-items: center; justify-content: space-between;
    border-bottom: 1px solid var(--line); padding: 0 1rem;
}
.mainnav ul { display: flex; gap: .25rem; list-style: none; margin: 0; padding: 0; }
.mainnav a {
    display: block; padding: .6rem .9rem;
    color: var(--ink-muted); text-decoration: none;
    border-bottom: 2px solid transparent;
}
.mainnav a:hover { color: var(--ink); }
.mainnav a[aria-current="page"] {
    color: var(--green); border-bottom-color: var(--green); font-weight: 600;
}
.release-indicator { font-size: .75rem; color: var(--ink-muted); font-family: var(--mono); }

.content { padding: 1.25rem 1rem 4rem; max-width: 84rem; margin: 0 auto; }

/* ---------------------------------------------------------- minimal layout */
.layout-minimal { display: flex; flex-direction: column; min-height: 100vh; }
.layout-minimal .brand { display: block; margin-bottom: 1.5rem; font-size: 1.3rem; }
.card-narrow {
    width: 100%; max-width: 26rem; margin: auto; padding: 2rem 1.5rem;
}
.minimal-footer {
    padding: 1rem; text-align: center; font-size: .75rem; color: var(--ink-muted);
}
.layout-minimal .env-badge { position: absolute; top: 1rem; right: 1rem; }

.lede { font-size: 1.02rem; }
.muted { color: var(--ink-muted); }
.small { font-size: .82rem; }

/* -------------------------------------------------------------- forms */
.stack { display: flex; flex-direction: column; gap: .7rem; margin: 1.2rem 0; }
.stack label { font-weight: 600; font-size: .88rem; }
.stack input[type="email"], .stack input[type="text"] {
    padding: .6rem .7rem; font: inherit;
    border: 1px solid var(--line); border-radius: var(--radius);
    background: var(--bg); color: inherit;
}
.btn-primary, .btn-secondary {
    display: inline-block; padding: .6rem 1.1rem;
    border-radius: var(--radius); font: inherit; font-weight: 600;
    cursor: pointer; text-decoration: none; text-align: center;
}
.btn-primary { background: var(--green); color: #fff; border: 1px solid var(--green); }
.btn-primary:hover { background: var(--green-dark); }
.btn-secondary { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn-large { padding: .8rem 1.4rem; font-size: 1.05rem; }

/* ------------------------------------------------------------ trace chips */
/* Colour is never the only signal: ● green, ▲ amber, plus a title. */
.chip-dot { font-size: .8em; line-height: 1; vertical-align: baseline; cursor: help; }
.chip-green { color: var(--green); }
.chip-amber { color: var(--amber); }

tr.is-amber, .is-amber { background: var(--amber-bg); }

.trace-panel {
    position: fixed; right: 0; top: 0; bottom: 0; width: min(30rem, 92vw);
    background: var(--bg); border-left: 1px solid var(--line);
    padding: 1rem; overflow-y: auto; box-shadow: -2px 0 12px rgb(0 0 0 / .08);
}
.trace-panel[hidden] { display: none; }

/* ------------------------------------------------------------------ misc */
code, pre, .mono { font-family: var(--mono); font-size: .9em; }
.error-detail {
    background: var(--bg-sunken); border: 1px solid var(--line);
    border-radius: var(--radius); padding: .8rem; overflow-x: auto;
}

/* Wide content scrolls inside its own container; the page never scrolls
   sideways. */
.table-scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: .45rem .6rem; border-bottom: 1px solid var(--line); }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-muted); }

/* ===================================================== sites and coverage */

.page-head { margin-bottom: 1rem; }
.page-head h1 { margin: 0 0 .2rem; font-size: 1.4rem; }
.page-head p { margin: 0; }

.breadcrumb { font-size: .85rem; color: var(--ink-muted); margin-bottom: .6rem; }
.breadcrumb a { color: var(--green); }

/* --------------------------------------------------------------- filters */
.filters { margin: 0 0 1rem; }
.filter-row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.filter-row input[type="search"] { min-width: 18rem; }
.filter-row input, .filter-row select {
    padding: .4rem .55rem; font: inherit;
    border: 1px solid var(--line); border-radius: var(--radius);
    background: var(--bg); color: inherit;
}

/* ----------------------------------------------------------------- table */
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: var(--bg-sunken); }
.sites td { white-space: nowrap; }
.sites td.small { white-space: normal; }

.pagination {
    display: flex; gap: 1rem; align-items: center;
    justify-content: center; padding: 1rem 0;
}

.empty {
    padding: 2.5rem 1rem; text-align: center; color: var(--ink-muted);
    background: var(--bg-sunken); border: 1px dashed var(--line);
    border-radius: var(--radius);
}

/* ------------------------------------------------------------ traced value */
.traced { white-space: nowrap; }
.traced .unit { color: var(--ink-muted); font-size: .85em; margin-left: .15em; }
.chip-link { text-decoration: none; margin-left: .25em; }

.state-pill {
    font-size: .7rem; text-transform: uppercase; letter-spacing: .04em;
    border: 1px solid var(--line); border-radius: 99px;
    padding: .05rem .4rem; color: var(--ink-muted); margin-left: .3em;
}
.state-pill.state-released { color: var(--green); border-color: var(--green); }

/* ------------------------------------------------------------------ tabs */
.tabs { display: flex; gap: .2rem; border-bottom: 1px solid var(--line); margin: 1rem 0 1.2rem; }
.tabs a {
    padding: .5rem .85rem; text-decoration: none; color: var(--ink-muted);
    border-bottom: 2px solid transparent;
}
.tabs a[aria-current="page"] {
    color: var(--green); border-bottom-color: var(--green); font-weight: 600;
}

/* --------------------------------------------------------- detail layout */
.detail-grid {
    display: grid; gap: 1.5rem;
    grid-template-columns: repeat(auto-fit, minmax(17rem, 1fr));
    margin-bottom: 2rem;
}
.detail-grid h2, section > h2 { font-size: .95rem; margin: 0 0 .5rem; }

.facts { display: grid; grid-template-columns: max-content 1fr; gap: .3rem .8rem; margin: 0; }
.facts dt { color: var(--ink-muted); font-size: .85rem; }
.facts dd { margin: 0; }

/* -------------------------------------------------------------- coverage */
.coverage .bar-col { width: 11rem; }
.bar {
    display: flex; height: .55rem; width: 8rem;
    background: var(--line); border-radius: 99px; overflow: hidden;
}
/* Two segments rather than one: an attribute present everywhere but amber is
   a different situation from one that is simply absent, and a single bar
   cannot say which. */
.bar-green { background: var(--green); }
.bar-amber { background: var(--amber); }

/* ------------------------------------------------------------ trace panel */
.trace-head { border-bottom: 1px solid var(--line); padding-bottom: .8rem; margin-bottom: .8rem; }
.trace-close {
    float: right; background: none; border: 0; font-size: 1.4rem;
    line-height: 1; cursor: pointer; color: var(--ink-muted);
}
.trace-field { margin: 0; font-size: .8rem; text-transform: uppercase;
               letter-spacing: .05em; color: var(--ink-muted); }
.trace-value { margin: .1rem 0; font-size: 1.25rem; font-weight: 600; }
.trace-reason { margin: .3rem 0; color: var(--amber); font-size: .85rem; }
.trace-meta { margin: .2rem 0 0; font-size: .8rem; color: var(--ink-muted); }

.trace-section { margin-bottom: 1.4rem; }
.trace-section h3 {
    font-size: .78rem; text-transform: uppercase; letter-spacing: .06em;
    color: var(--ink-muted); margin: 0 0 .4rem;
}
.trace-section dl { display: grid; grid-template-columns: max-content 1fr; gap: .25rem .7rem; margin: 0; }
.trace-section dt { color: var(--ink-muted); font-size: .8rem; }
.trace-section dd { margin: 0; word-break: break-word; }
.trace-section .raw {
    background: var(--bg-sunken); padding: .15rem .35rem; border-radius: 3px;
}

.trace-inputs, .trace-review { margin: .3rem 0 0; padding-left: 1.1rem; }
.trace-inputs li, .trace-review li { margin-bottom: .25rem; font-size: .87rem; }
.trace-review .comment { margin: .15rem 0 0; color: var(--ink-muted); }
.trace-foot { border-top: 1px solid var(--line); padding-top: .6rem; }
.warn { color: var(--amber); }


/* ============================================ dashboard, review, ingest */

/* ------------------------------------------------------------- notices */
/* Each notice names a condition and links to where it is acted on. Colour
   is paired with a border and wording, never carrying the meaning alone. */
.notice {
    padding: .6rem .8rem; border-radius: var(--radius);
    border: 1px solid var(--line); background: var(--bg-sunken);
    margin: 0 0 .8rem;
}
.notice-warn { border-color: var(--amber); background: var(--amber-bg); }
.notice-good { border-color: var(--green); }
.notice-info { border-color: var(--line); }

/* ------------------------------------------------------------- stat row */
.stat-row { display: flex; flex-wrap: wrap; gap: .8rem; margin: 0 0 1.5rem; }
.stat {
    display: flex; flex-direction: column; gap: .1rem;
    padding: .7rem 1.1rem; min-width: 8rem;
    border: 1px solid var(--line); border-radius: var(--radius);
    background: var(--bg-sunken); text-decoration: none; color: inherit;
}
.stat:hover { border-color: var(--green); }
.stat-static:hover { border-color: var(--line); }
.stat-value { font-size: 1.5rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat-label { font-size: .78rem; color: var(--ink-muted); }

ul.plain { list-style: none; margin: 0; padding: 0; }
ul.plain li { display: flex; justify-content: space-between; padding: .25rem 0; }
.count {
    background: var(--bg-sunken); border: 1px solid var(--line);
    border-radius: 99px; padding: 0 .45rem; font-size: .78rem;
    font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------- review queue */
.reason-counters { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: 1rem; }
.reason-counters a {
    display: inline-flex; align-items: center; gap: .4rem;
    padding: .35rem .7rem; border: 1px solid var(--line);
    border-radius: 99px; text-decoration: none; color: var(--ink-muted);
    font-size: .85rem;
}
.reason-counters a.is-active { border-color: var(--green); color: var(--green); font-weight: 600; }

.btn-small { padding: .25rem .6rem; font-size: .82rem; }

/* -------------------------------------------------------- review task */
.review-head { display: flex; justify-content: space-between; align-items: flex-start; }
.reason-pill {
    margin: 0; padding: .25rem .7rem; border-radius: 99px;
    background: var(--amber-bg); border: 1px solid var(--amber);
    color: var(--amber); font-size: .8rem;
}

.review-grid {
    display: grid; gap: 1.5rem;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    align-items: start;
}
@media (max-width: 60rem) { .review-grid { grid-template-columns: 1fr; } }

.field-name { margin: .2rem 0 0; font-size: 1rem; color: var(--ink-muted); }
.value-big { margin: .1rem 0 .5rem; font-size: 2rem; font-weight: 650; }
.value-big .unit { font-size: .55em; color: var(--ink-muted); margin-left: .25em; }

/* The trace panel is reused inline here rather than as a drawer: on this
   screen it is the primary content, not a detail. */
.review-trace { border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem; }
.review-trace .trace-panel { position: static; width: auto; box-shadow: none; border: 0; padding: 0; }

.review-source h3 {
    font-size: .78rem; text-transform: uppercase; letter-spacing: .06em;
    color: var(--ink-muted); margin: 0 0 .4rem;
}
.source-excerpt {
    border: 1px solid var(--line); border-radius: var(--radius);
    max-height: 28rem; overflow: auto; background: var(--bg-sunken);
}

/* --------------------------------------------------------- decision bar */
/* Sticky, because the reviewer's hands stay here while their eyes move. */
.decision-bar {
    position: sticky; bottom: 0; z-index: 5;
    display: flex; align-items: flex-start; gap: .6rem; flex-wrap: wrap;
    padding: .8rem 0; margin-top: 1.5rem;
    border-top: 1px solid var(--line); background: var(--bg);
}
.decision-bar .spacer { flex: 1 1 auto; }
.correct-box, .reject-box { position: relative; }
.correct-box summary, .reject-box summary { list-style: none; cursor: pointer; }
.correct-box summary::-webkit-details-marker { display: none; }
.correct-fields {
    position: absolute; bottom: 100%; left: 0; margin-bottom: .4rem;
    display: flex; flex-direction: column; gap: .4rem;
    padding: .8rem; min-width: 20rem;
    background: var(--bg); border: 1px solid var(--line);
    border-radius: var(--radius); box-shadow: 0 -2px 12px rgb(0 0 0 / .1);
}
.correct-fields input {
    padding: .45rem .6rem; font: inherit;
    border: 1px solid var(--line); border-radius: var(--radius);
    background: var(--bg); color: inherit;
}
.key {
    display: inline-block; margin-left: .35em; padding: 0 .3em;
    border: 1px solid currentColor; border-radius: 3px;
    font-size: .72em; opacity: .75; font-family: var(--mono);
}

/* -------------------------------------------------------- source viewer */
.file-name { font-size: 1.1rem; word-break: break-all; }
.xpath-banner {
    padding: .4rem .6rem; background: var(--bg-sunken);
    border-left: 3px solid var(--green); word-break: break-all;
}
.source-view {
    border: 1px solid var(--line); border-radius: var(--radius);
    max-height: 70vh; overflow: auto; background: var(--bg-sunken);
}
.source-view pre { margin: 0; padding: .5rem 0; }
.source-view code { font-size: .82rem; line-height: 1.45; }
.src-line { display: block; padding: 0 .6rem; white-space: pre; }
.src-no {
    display: inline-block; width: 4rem; margin-right: .8rem;
    color: var(--ink-muted); user-select: none; text-align: right;
}
/* The focused line is marked by a border as well as a fill, so it survives
   being printed and is visible to a colour-blind reviewer. */
.src-line.is-focus {
    background: var(--amber-bg);
    border-left: 3px solid var(--amber);
    padding-left: calc(.6rem - 3px);
}

/* --------------------------------------------------------------- admin */
.inline-form { display: inline-flex; gap: .3rem; align-items: center; }
.inline-form input[type="text"] {
    padding: .2rem .45rem; font: inherit; font-size: .85rem;
    border: 1px solid var(--line); border-radius: var(--radius);
    background: var(--bg); color: inherit; max-width: 12rem;
}
.inline-form select {
    padding: .2rem .35rem; font-size: .85rem;
    border: 1px solid var(--line); border-radius: var(--radius);
    background: var(--bg); color: inherit;
}
td.actions { white-space: nowrap; display: flex; gap: .35rem; flex-wrap: wrap; }

.invite-box {
    padding: 1rem; margin-bottom: 1.5rem;
    background: var(--bg-sunken); border: 1px solid var(--line);
    border-radius: var(--radius);
}
.invite-box h2 { margin-top: 0; }
