/* PEXim component library — UI migration Phase 2 (docs/ui-migration/04-plan.md).
 *
 * Ported from the mock's single <style> block (docs/ui-migration/mock/target.html),
 * with every hex literal replaced by a token from tokens.css. Nothing here may
 * contain a colour literal; see internal/web/AGENTS.md § Tokens.
 *
 * LOAD ORDER: tokens.css -> components.css -> app.css / admin.css / style.css.
 * The page sheets load LAST on purpose: where a name collides (.btn, .card),
 * the page sheet's own variants (.btn-primary, .card-header) still win, and a
 * page can still override one property without an !important war.
 *
 * Sections: UI-201 controls · UI-202 inputs · UI-203 badges · UI-204 cards and
 * metrics · UI-205 tables and lists · UI-209 guidance · UI-211 navigation ·
 * UI-213 utilities · density.
 */

/* ================================================================== *
 * UI-201 — buttons and controls
 * ================================================================== */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--fg);
    border-radius: var(--r);
    padding: 8px 14px;
    font-family: var(--sans);
    font-weight: 600;
    font-size: 13.5px;
    line-height: 1.4;
    cursor: pointer;
    white-space: nowrap;
    text-decoration: none;
}
.btn:hover { background: var(--input); text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }

.btn.pri { background: var(--primary); border-color: var(--primary); color: var(--on-primary); font-weight: 700; }
.btn.pri:hover { background: var(--primary-dk); border-color: var(--primary-dk); color: var(--on-primary); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; border-radius: 8px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--input); }
/* .danger = a destructive action drawn as a normal button (red label);
   .destruct = the confirmed, filled version. Both from the mock. */
.btn.danger { color: var(--danger); }
.btn.destruct { background: var(--danger); border-color: var(--danger); color: var(--on-primary); font-weight: 700; }
.btn.destruct:hover { background: var(--danger); opacity: .9; }
.btn.full { width: 100%; justify-content: center; }

/* ui/file — hidden native input, .btn label, chosen name, image preview. */
.file { display: inline-flex; align-items: center; gap: 10px; min-width: 0; max-width: 100%; }
.file input:focus-visible + .btn { outline: 2px solid var(--primary); outline-offset: 2px; }
.file-name { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.file-preview { width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--border); object-fit: cover; }

.icon-btn {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--card);
    display: grid;
    place-items: center;
    color: var(--fg-2);
    cursor: pointer;
}
.icon-btn:hover { background: var(--input); }
.icon-btn svg { width: 17px; height: 17px; }

/* Segmented control. The children are <button> or <a>. */
.seg {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    background: var(--card);
}
.seg button,
.seg a {
    border: 0;
    background: transparent;
    padding: 6px 12px;
    font-family: var(--sans);
    font-size: 12.5px;
    font-weight: 600;
    color: var(--muted);
    cursor: pointer;
    text-decoration: none;
}
.seg button.on,
.seg a.on { background: var(--primary-soft); color: var(--primary); }

/* Toggle switch. Presentational only — pair it with a real checkbox or a
   button[aria-pressed] so it is reachable without a mouse. */
.sw {
    width: 40px;
    height: 22px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--muted-2) 45%, var(--card));
    position: relative;
    border: 0;
    cursor: pointer;
    flex: none;
}
.sw::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--card);
    transition: left .15s;
}
.sw.on { background: var(--primary); }
.sw.on::after { left: 20px; }

/* Multi-select option, and its pill variant. */
.opts {
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    width: 100%;
}
.opt {
    border: 1.5px solid var(--border);
    background: var(--card);
    border-radius: 10px;
    padding: 12px 14px;
    text-align: left;
    cursor: pointer;
    font-family: var(--sans);
    font-size: 13.5px;
    font-weight: 600;
    color: var(--fg-2);
    display: flex;
    gap: 10px;
    align-items: center;
}
.opt:hover { border-color: var(--primary); }
.opt.on { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }
.opt i {
    width: 17px;
    height: 17px;
    border-radius: 5px;
    border: 1.5px solid var(--border);
    flex: none;
    display: grid;
    place-items: center;
    color: var(--on-primary);
    font-style: normal;
    font-size: 11px;
}
.opt.on i { background: var(--primary); border-color: var(--primary); }
.opt.chip { padding: 7px 11px; font-size: 12.5px; border-width: 1px; border-radius: 999px; }
.opt.chip i { width: 11px; height: 11px; border-radius: 3px; font-size: 8px; }
/* An option the deployment cannot offer (a switched-off asset type, UI-411).
   It stays visible and labelled: a missing option reads as "the product does
   not do this", which is a different claim. */
.opt[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }
.opt[aria-disabled="true"]:hover { border-color: var(--border); }

/* ================================================================== *
 * UI-202 — inputs
 * ================================================================== */

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--fg-2); }
.field .hint { font-size: 11.5px; color: var(--muted); }
.field .err { font-size: 11.5px; font-weight: 600; color: var(--danger); }

.inp {
    border: 1px solid var(--border);
    background: var(--input);
    border-radius: 8px;
    padding: 9px 12px;
    width: 100%;
    font-family: var(--sans);
    font-size: 13.5px;
    color: var(--fg);
}
.inp:focus { outline: 2px solid var(--primary); outline-offset: 0; background: var(--card); }
textarea.inp { min-height: 88px; resize: vertical; line-height: 1.5; }
select.inp { appearance: none; padding-right: 30px; cursor: pointer; }
/* Error state. aria-invalid is the state, the red border is its rendering —
   no separate .is-invalid class to keep in sync. */
.inp[aria-invalid="true"] { border-color: var(--danger); background: var(--danger-bg); }
.inp[aria-invalid="true"]:focus { outline-color: var(--danger); }

/* A labelled row with a control on the right (Preferences, Settings). */
.toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
}
.toggle:last-child { border-bottom: 0; }
.toggle b { display: block; font-size: 13.5px; }
.toggle span { font-size: 12.5px; color: var(--muted); }

/* ================================================================== *
 * UI-203 — badges
 * ================================================================== */

.bdg {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 600;
    white-space: nowrap;
}
.bdg.live { background: var(--success-bg); color: var(--success); }
.bdg.open { background: var(--primary-soft); color: var(--primary); }
.bdg.paused { background: var(--warn-bg); color: var(--warn); }
.bdg.closed,
.bdg.neutral { background: var(--neutral-bg); color: var(--fg-2); }
.bdg.type { background: var(--card); border: 1px solid var(--border); color: var(--fg-2); font-weight: 500; }
.bdg.disc { background: var(--disc-bg); color: var(--disc-fg); }
/* Beyond the mock: the urgency tone .tile.gate already uses, as a badge —
   UI-304 restyles the "read-only demo" / "org pending" banners on it. */
.bdg.gate { background: var(--gate-bg); color: var(--gate-fg); }
/* Red: a rejected org, a blocked user, a dead feed. Lived in admin.css
   until UI-420, so /app pages that emit Kind "danger" (feed coverage,
   status) rendered it neutral. */
.bdg.danger { background: var(--danger-bg); color: var(--danger); }
.bdg.dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* Challenge visibility. */
.bdg.vis.pub { background: var(--success-bg); color: var(--success); }
.bdg.vis.inv { background: var(--warn-bg); color: var(--warn); }
.bdg.vis.pri { background: var(--disc-bg); color: var(--disc-fg); }

/* ================================================================== *
 * UI-204 — cards, tiles, metric grids
 * ================================================================== */

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 18px 20px;
}
/* A whole card that is one link (the market zone cards). */
a.card { display: block; color: inherit; text-decoration: none; }
a.card:hover { border-color: var(--primary); }
/* .pad0: the card is a frame for a full-bleed table or list. */
.card.pad0 { padding: 0; overflow: hidden; overflow-x: auto; }
.card-h {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}
.card-h h3 { font-size: 14.5px; }

/* UI-430/431: the one vertical rhythm. Every block stacked in .page — and in
   any container marked .stack — sits var(--gap-card) below the one before it.
   Owl selector with margin-top, not flex gap: margins collapse, so an empty
   htmx target or a component's own bottom margin (.tiles, .ph) never doubles
   the gap. Do not space a card with the mb-N or mt-N utilities; add .stack to its
   parent. Utilities stay for spacing inside a card.
   "~ after a rendered element", not "+ after any element": a page's own
   <link>/<script> (its "head" block, emitted inside .page on /admin) must not
   push the first card down. */
.page > :not(link, script, style, template) ~ *,
.stack > :not(link, script, style, template) ~ * { margin-top: var(--gap-card); }

/* Auto-fit grids. Self-contained (they carry display+gap) so they do not need
   a .grid companion. Same gap as the stack. */
.g2, .g3, .g4 { display: grid; gap: var(--gap-card); }
.g2 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.g3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.g4 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

.tiles {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); /* 150, not the mock's 170: six tiles (agent view) fit one row at 1280 */
    margin-bottom: var(--gap-card);
}
.tile {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px 16px;
}
.tile .l { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; }
.tile .v {
    font-family: var(--head);
    font-size: 24px;
    font-weight: 600;
    line-height: 1.2;
    margin-top: 6px;
    color: var(--fg);
    font-variant-numeric: tabular-nums;
}
.tile .v small { font-size: 13px; font-weight: 500; color: var(--muted); font-family: var(--sans); margin-left: 3px; }
.tile .d { font-size: 12px; margin-top: 4px; color: var(--muted); }
.tile.hi { background: var(--primary-soft); border-color: var(--hi-bd); }
.tile.hi .v { color: var(--primary); }
.tile.gate { background: var(--gate-bg); border-color: var(--gate-bd); }
.tile.gate .v { color: var(--gate-fg); }

.delta {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-weight: 700;
    font-size: 13px;
    border-radius: 6px;
    padding: 2px 8px;
}
/* Signed figures (mock .pos/.neg). */
.pos, .tile .v.pos { color: var(--success); }
.neg, .tile .v.neg { color: var(--danger); }

.delta.up { background: var(--success-bg); color: var(--success); }
.delta.dn { background: var(--danger-bg); color: var(--danger); }

/* ================================================================== *
 * UI-205 — tables and lists
 * ================================================================== */

.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th {
    text-align: left;
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--muted);
    font-weight: 700;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    background: var(--input);
    white-space: nowrap;
}
.tbl td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl td b { font-weight: 600; }
.tbl td .bdg,
.tbl td.small,
.tbl td b { white-space: nowrap; }
/* UI-430: the agent cell. Name and "you" pill stay on one line; a caption
   div under them may wrap. The mock gives its Agent column min-width 220px. */
.tbl .who { white-space: nowrap; min-width: 200px; }
.tbl .who > div { white-space: normal; }
.tbl .who .bdg { flex: none; vertical-align: 1px; }
.tbl tbody tr.row:hover { background: var(--input); cursor: pointer; }
.tbl tr.mine td { background: var(--primary-soft); }
/* Group header row: an environment above its indented agent rows. */
.tbl tr.grp td { background: var(--input); font-size: 12.5px; padding: 8px 14px; }
.tbl tr.grp td b { font-family: var(--mono); font-size: 12.5px; }
.tbl tfoot td { border-top: 1px solid var(--border); background: var(--input); font-weight: 600; }
.tbl .r, .tbl th.r { text-align: right; }
/* UI-431: the row-action column of a table wider than its card stays pinned
   to the right edge of the scroller (.card.pad0 / .table-wrap). It repaints
   the row's own background so the cells scrolling under it stay hidden, and
   a soft shadow marks the seam. Put .col-act on the last <th> and <td>. */
.tbl .col-act {
    position: sticky;
    right: 0;
    background: var(--card);
    box-shadow: -8px 0 8px -8px rgba(0, 0, 0, .28);
    white-space: nowrap;
}
.tbl th.col-act, .tbl tr.grp td.col-act { background: var(--input); }
.tbl tr.mine td.col-act { background: var(--primary-soft); }
.tbl tbody tr.row:hover td.col-act { background: var(--input); }
/* On a phone a pinned column of several buttons covers the row it belongs to
   (admin users: five buttons, wider than the screen). Let it scroll with the row. */
@media (max-width: 480px) {
    .tbl .col-act { position: static; box-shadow: none; }
}

/* A long table that scrolls inside its card with the header pinned
   (intraday contracts, UI-420). */
.tbl-scroll { max-height: 520px; overflow: auto; }
.tbl-scroll .tbl th { position: sticky; top: 0; z-index: 1; }

/* The strip above a .card.pad0 table: title left, filters right. */
.tbl-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    gap: 10px;
    flex-wrap: wrap;
}
.tbl-bar .filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.tbl-bar .inp { width: 200px; padding: 6px 10px; font-size: 12.5px; }

/* Standalone filter bar above a board. */
.fbar {
    display: flex;
    gap: 16px;
    align-items: center;
    flex-wrap: wrap;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 14px;
    margin-bottom: 14px;
}
.fbar .fg { display: flex; gap: 7px; align-items: center; }
.fbar .fl { font-size: 10.5px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 700; }
.fbar .sp { margin-left: auto; font-size: 12px; color: var(--muted); }
label.chk { display: flex; gap: 7px; align-items: center; font-size: 12.5px; color: var(--fg-2); }

.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty h3 { margin-bottom: 6px; color: var(--fg); font-size: 15px; }
.empty p { margin: 0 0 14px; font-size: 13px; }
.empty p:last-child { margin-bottom: 0; }

/* UI-308: Preferences > "Show onboarding checklist". The strip is server-
   rendered on every page that has one; switching it off is a per-browser
   preference, so CSS hides it from an attribute the pre-paint script sets. */
:root[data-checklist="0"] .check { display: none; }

/* Section heading between boards. */
.sec { display: flex; align-items: baseline; gap: 10px; margin: 22px 0 10px; }
.sec h2 { font-size: 15px; }
.sec span { font-size: 12px; color: var(--muted); }
.sec .sp { margin-left: auto; font-size: 12px; color: var(--muted); }

/* ================================================================== *
 * UI-209 — guidance: tip, costline, kv, code, checklist
 * ================================================================== */

.tip {
    background: var(--tip-bg);
    border: 1px solid var(--tip-bd);
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 12.5px;
    color: var(--tip-fg);
    margin-bottom: 16px;
}
.tip b { font-weight: 700; }
/* An error is not guidance — it is the reason a form did not go through
   (auth screens, the help drawer's Support form). */
.tip.err { background: var(--danger-bg); border-color: var(--danger-bd); color: var(--danger); }

/* "What this will cost" strip at the end of every wizard. */
.costline {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    background: var(--primary-soft);
    border: 1px solid var(--hi-bd);
    border-radius: 10px;
    padding: 11px 14px;
    margin-top: 16px;
    font-size: 12.5px;
    flex-wrap: wrap;
}
.costline b { font-family: var(--head); font-size: 15px; color: var(--primary); }
.costline .why { color: var(--muted); font-size: 11.5px; }

.kv { display: grid; grid-template-columns: 150px 1fr; gap: 8px 16px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; }
@media (max-width: 560px) { .kv { grid-template-columns: 1fr; gap: 2px 0; } }

/* Code block on a permanently dark surface, so its foreground is --on-dark
   rather than --fg (which flips with the theme). */
.code {
    background: var(--navy);
    color: var(--on-dark);
    border-radius: 10px;
    padding: 14px 16px;
    font-family: var(--mono);
    font-size: 12.5px;
    line-height: 1.6;
    overflow: auto;
    position: relative;
}
.code pre { margin: 0; font: inherit; white-space: pre; }
.code .cl {
    position: absolute;
    top: 12px;
    left: 16px;
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--muted-2);
}
.code .cl + pre { margin-top: 16px; }
.code .cp {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(255, 255, 255, .1);
    border: 0;
    color: var(--on-dark);
    font-family: var(--sans);
    font-size: 11px;
    border-radius: 6px;
    padding: 3px 8px;
    cursor: pointer;
}
.code .cp:hover { background: rgba(255, 255, 255, .18); }

/* Onboarding checklist strip. */
.check {
    background: linear-gradient(90deg, var(--primary-soft), var(--card) 70%);
    border: 1px solid var(--hi-bd);
    border-radius: 12px;
    padding: 14px 18px;
    display: flex;
    align-items: center;
    gap: 22px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}
.check h3 { font-size: 14px; margin-bottom: 2px; }
.check .steps { display: flex; gap: 18px; flex: 1; flex-wrap: wrap; }
.check .st { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--fg-2); text-decoration: none; }
.check .st i {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-style: normal;
    font-size: 11px;
    font-weight: 700;
    border: 1.5px solid var(--border);
    color: var(--muted);
}
.check .st.done i { background: var(--success); border-color: var(--success); color: var(--on-primary); }
.check .st.cur { color: var(--primary); }
.check .st.cur i { border-color: var(--primary); color: var(--primary); }
.check .x { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 12px; }

/* ================================================================== *
 * UI-211 — navigation: tabs, page header, back link, breadcrumbs
 * ================================================================== */

.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow: auto; }
.tabs a {
    padding: 9px 14px;
    font-weight: 600;
    font-size: 13.5px;
    color: var(--muted);
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    white-space: nowrap;
    text-decoration: none;
}
.tabs a:hover { text-decoration: none; color: var(--fg); }
.tabs a.on { color: var(--primary); border-bottom-color: var(--primary); }

.ph {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: var(--gap-card);
    flex-wrap: wrap;
}
.ph h1 { font-size: 24px; font-weight: 700; margin: 0; }
.ph p { margin: 4px 0 0; color: var(--muted); font-size: 13.5px; }
.ph .acts { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.back { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); margin-bottom: 8px; text-decoration: none; }
.back:hover { color: var(--fg); }
.back svg { width: 14px; height: 14px; }

.crumbs { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); min-width: 0; flex-wrap: wrap; }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--fg); }
.crumbs b { color: var(--fg); font-family: var(--head); font-weight: 600; font-size: 15px; }

/* ================================================================== *
 * UI-213 / UI-417 — the utility scale
 *
 * A 4px Tailwind-like scale, defined here ONCE for /app, /admin, auth and
 * the landing pages (every layout loads this sheet). Until UI-417 app.css
 * and style.css each carried their own, differently valued copy of
 * text-sm / mt-6 / …; those are gone. Only steps templates actually use
 * are listed: an unused utility is dead CSS the contract test cannot see.
 * ================================================================== */

.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 4px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }
.pb-4 { padding-bottom: 16px; }
.px-1 { padding-left: 4px; padding-right: 4px; }
.p-4 { padding: 16px; }
.flex { display: flex; }
.flex-1 { flex: 1; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.text-xs { font-size: 11px; }
.text-sm { font-size: 13px; }
.text-lg { font-size: 16px; }
.text-muted { color: var(--muted); }

.text-right { text-align: right; }
.text-center { text-align: center; }
.text-capitalize { text-transform: capitalize; }
.text-link { color: var(--primary); }
.font-semibold { font-weight: 600; }
.mono { font-family: var(--mono); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 200px; }
.hidden { display: none; }
.icon-sm { width: 18px; height: 18px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }
/* A reading-width column for form pages (actual generation, preferences). */
.narrow { max-width: 720px; }

/* ================================================================== *
 * Density (UI-105) — :root[data-dense="1"], from the mock.
 * ================================================================== */

:root[data-dense="1"] .tbl td { padding: 5px 14px; }
:root[data-dense="1"] .tbl th { padding: 6px 14px; }
:root[data-dense="1"] .tbl tr.grp td { padding: 5px 14px; }
:root[data-dense="1"] .card { padding: 12px 14px; }
:root[data-dense="1"] .card.pad0 { padding: 0; }
:root[data-dense="1"] .tile { padding: 10px 12px; }
:root[data-dense="1"] .tbl-bar { padding: 7px 14px; }
:root[data-dense="1"] .fbar { padding: 7px 14px; }
:root[data-dense="1"] .tiles,
:root[data-dense="1"] .g2,
:root[data-dense="1"] .g3,
:root[data-dense="1"] .g4 { gap: 10px; }

/* ================================================================== *
 * UI-206 — toast
 *
 * One host per document (components/ui/toast.html, mounted by the three
 * layouts). static/ui.js sets the text, the kind class and .show.
 * ================================================================== */

.toast {
    position: fixed;
    bottom: 62px;
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    background: var(--navy);
    color: var(--on-dark);
    padding: 10px 18px;
    border-radius: 999px;
    font-size: 12.5px;
    font-weight: 600;
    z-index: 60;
    box-shadow: var(--shadow);
    max-width: min(92vw, 560px);
    text-align: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity .15s ease, transform .15s ease;
}
.toast.show { opacity: 1; visibility: visible; transform: translateX(-50%) translateY(0); }
.toast.ok { background: var(--success); color: var(--on-primary); }
.toast.err { background: var(--danger); color: var(--on-primary); }
:root[data-theme="dark"] .toast { border: 1px solid var(--border); }

/* ================================================================== *
 * UI-207 — scrim, confirm modal — and UI-208's glossary popover, which
 * sits in the same centred overlay.
 *
 * .scrim is display:grid, which beats the UA's [hidden]{display:none};
 * the override below is what actually keeps a hidden overlay hidden.
 * ================================================================== */

.scrim {
    position: fixed;
    inset: 0;
    background: var(--scrim);
    z-index: 50;
    display: grid;
    place-items: center;
    padding: 20px;
}
.scrim[hidden] { display: none; }

.modal {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 22px;
    max-width: 450px;
    width: 100%;
    box-shadow: var(--shadow);
}
.modal h3 { font-size: 16px; margin-bottom: 8px; }
.modal p { font-size: 13.5px; color: var(--muted); margin: 0 0 18px; line-height: 1.55; }
.modal .macts { display: flex; justify-content: flex-end; gap: 8px; }

/* ================================================================== *
 * UI-208 — glossary "(i)" button and its popover
 * ================================================================== */

.info {
    display: inline-grid;
    place-items: center;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 1px solid var(--muted-2);
    background: transparent;
    color: var(--muted);
    font: 700 10px/1 var(--sans);
    cursor: pointer;
    vertical-align: 2px;
    margin-left: 6px;
    padding: 0;
    flex: none;
}
.info:hover { border-color: var(--primary); color: var(--primary); }
h1 .info { width: 18px; height: 18px; font-size: 11px; vertical-align: 4px; }
th .info { margin-left: 4px; vertical-align: 0; }

.ipop {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 18px 20px;
    max-width: 420px;
    width: 100%;
    box-shadow: var(--shadow);
}
.ipop h3 { font-size: 15px; margin-bottom: 8px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.ipop p { font-size: 13.5px; color: var(--fg-2); margin: 0 0 8px; line-height: 1.55; }
.ipop p:last-child { margin-bottom: 0; }

/* ================================================================== *
 * UI-210 — wizard step rail
 *
 * The page owns the .wiz grid; ui/wizard renders the <ol> rail only, so
 * the step body stays where the page can write it (same slot rule as
 * ui/ph).
 * ================================================================== */

.wiz { display: grid; grid-template-columns: 220px 1fr; gap: 24px; }
@media (max-width: 760px) { .wiz { grid-template-columns: 1fr; } }

.wiz-steps { list-style: none; margin: 0; padding: 0; }
.wiz-steps li { display: flex; gap: 10px; align-items: center; padding: 10px 0; font-size: 13.5px; color: var(--muted); font-weight: 500; }
.wiz-steps li i {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 1.5px solid var(--border);
    display: grid;
    place-items: center;
    font-style: normal;
    font-size: 11.5px;
    font-weight: 700;
    flex: none;
}
.wiz-steps li a { color: inherit; text-decoration: none; }
.wiz-steps li a:hover { color: var(--primary); }
.wiz-steps li.done { color: var(--fg); }
.wiz-steps li.done i { background: var(--success); color: var(--on-primary); border-color: var(--success); }
.wiz-steps li.cur { color: var(--primary); font-weight: 700; }
.wiz-steps li.cur i { border-color: var(--primary); color: var(--primary); }

/* ================================================================== *
 * UI-212 — chart wrapper
 *
 * The card a chart canvas lives in: title + unit on top, the canvas in
 * the middle, source / "View as table" at the foot. The canvas itself is
 * themed by static/charts_theme.js, not from here.
 * ================================================================== */

.chart { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; }
.chart .ch { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.chart .ch h3 { font-size: 14px; }
.chart .ch .u { font-size: 12px; color: var(--muted); }
.chart .cv { width: 100%; height: 240px; }
.chart .cv.tall { height: 360px; }
/* Canvas sparklines on the market pages (UI-420). The canvas is drawn by page
   JS from peximChartTokens(); these boxes only size and caption it. */
.spark { position: relative; height: 40px; min-width: 110px; }
.spark canvas { display: block; }
.spark-note { height: 40px; display: grid; place-items: center; font-size: 11.5px; color: var(--muted); font-style: italic; }
.spark-note.err { color: var(--danger); }
.spark-vol { font-size: 10px; color: var(--muted); white-space: nowrap; }
.spark-tip {
    position: absolute; top: -4px; z-index: 10; pointer-events: none; white-space: nowrap;
    background: var(--card); border: 1px solid var(--border); border-radius: 4px;
    padding: 3px 6px; font-size: 10.5px; line-height: 1.3; color: var(--fg); box-shadow: var(--shadow);
}
@media (max-width: 600px) { .chart .cv.tall { height: 260px; } }
.chart .src { font-size: 11px; color: var(--muted-2); margin-top: 8px; display: flex; justify-content: space-between; gap: 10px; }
.chart .src a { color: var(--muted-2); }
.chart .src a:hover { color: var(--primary); }

/* ================================================================== *
 * UI-601 — asset topology (app/partials/asset_topo.html)
 *
 * An inline SVG the server draws from the asset spec. Every paint is a
 * token, so the diagram follows the theme with no JS. The .k-* stroke
 * says what a box is: grid, battery, solar, wind, generator, load.
 * ================================================================== */

.topo { background: var(--bg); border: 1px dashed var(--border); border-radius: 12px; padding: 10px; }
.topo svg { width: 100%; height: auto; display: block; max-width: 560px; margin: 0 auto; font-family: var(--sans); }
.topo .box { fill: var(--card); stroke: var(--border); stroke-width: 1.5; }
.topo .k-grid { stroke: var(--c-afrrc); }
.topo .k-bat { stroke: var(--primary); }
.topo .k-pv { stroke: var(--c-imb); }
.topo .k-wind { stroke: var(--c-da); }
.topo .k-gen { stroke: var(--c-fcr); }
.topo .k-load { stroke: var(--c-id); }
.topo .ln { stroke: var(--muted-2); stroke-width: 1.5; }
.topo .bus { fill: var(--fg-2); }
.topo .t { fill: var(--fg); font-size: 12px; font-weight: 700; text-anchor: middle; }
.topo .s { fill: var(--muted); font-size: 10.5px; text-anchor: middle; }
.topo .bl { fill: var(--muted); font-size: 10.5px; }
