/* Color tokens follow the app's Palette.swift; --bg and the soft status colors are admin-only. */
@font-face { font-family: "Inter"; font-weight: 400; font-display: swap; src: url("/static/fonts/Inter-Regular.ttf") format("truetype"); }
@font-face { font-family: "Inter"; font-weight: 500; font-display: swap; src: url("/static/fonts/Inter-Medium.ttf") format("truetype"); }
@font-face { font-family: "Inter"; font-weight: 600; font-display: swap; src: url("/static/fonts/Inter-SemiBold.ttf") format("truetype"); }
@font-face { font-family: "Source Serif 4"; font-weight: 400; font-display: swap; src: url("/static/fonts/SourceSerif4-Regular.ttf") format("truetype"); }

:root {
    color-scheme: light;
    --bg: #f6f8fe;
    --paper: #ffffff;
    --surface: #fafbff;
    --tint: #f1f4fe;
    --ink: #18191e;
    --secondary: #4a525c;
    --muted: #687383;
    --rule: #e4eafb;
    --border: #cdd5ee;
    --navy: #1a2149;
    --accent: #4338ca;
    --accent-soft: #ecebfd;
    --error: #b42318;
    --error-soft: #fdecea;
    --success: #0f6b3f;
    --success-soft: #e4f5ec;
    --warn: #8a5a00;
    --warn-soft: #fdf3dc;
    --switch-on: #0f6b3f;
    --action-fill: linear-gradient(135deg, #1a2149 0%, #24337f 58%, #312e81 100%);
    --action-ink: #ffffff;
    --shadow-sm: 0 1px 2px rgb(26 33 73 / 0.05);
    --shadow-md: 0 1px 2px rgb(26 33 73 / 0.04), 0 8px 24px -8px rgb(26 33 73 / 0.12);
    --shadow-lg: 0 24px 64px -16px rgb(26 33 73 / 0.35);
    --serif: "Source Serif 4", "Iowan Old Style", Georgia, serif;
    --sans: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --radius: 14px;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --bg: #0b101e;
        --paper: #111829;
        --surface: #151d33;
        --tint: #1a2445;
        --ink: #eef0ff;
        --secondary: #bcc5e8;
        --muted: #a6b1d8;
        --rule: #222d52;
        --border: #384a8f;
        --navy: #eef0ff;
        --accent: #c7d2fe;
        --accent-soft: #232c5e;
        --error: #ffb5ad;
        --error-soft: #3a1b22;
        --success: #8fe0b4;
        --success-soft: #12322a;
        --warn: #ffd98a;
        --warn-soft: #382c14;
        --switch-on: #2f9e6b;
        --action-fill: linear-gradient(135deg, #faf7ff 0%, #d8d3ff 52%, #aebeff 100%);
        --action-ink: #0e1321;
        --shadow-sm: none;
        --shadow-md: 0 8px 24px -8px rgb(0 0 0 / 0.5);
        --shadow-lg: 0 24px 64px -16px rgb(0 0 0 / 0.7);
    }
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0b101e;
    --paper: #111829;
    --surface: #151d33;
    --tint: #1a2445;
    --ink: #eef0ff;
    --secondary: #bcc5e8;
    --muted: #a6b1d8;
    --rule: #222d52;
    --border: #384a8f;
    --navy: #eef0ff;
    --accent: #c7d2fe;
    --accent-soft: #232c5e;
    --error: #ffb5ad;
    --error-soft: #3a1b22;
    --success: #8fe0b4;
    --success-soft: #12322a;
    --warn: #ffd98a;
    --warn-soft: #382c14;
    --switch-on: #2f9e6b;
    --action-fill: linear-gradient(135deg, #faf7ff 0%, #d8d3ff 52%, #aebeff 100%);
    --action-ink: #0e1321;
    --shadow-sm: none;
    --shadow-md: 0 8px 24px -8px rgb(0 0 0 / 0.5);
    --shadow-lg: 0 24px 64px -16px rgb(0 0 0 / 0.7);
}

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

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font: 14.5px/1.5 var(--sans);
    font-feature-settings: "cv11", "ss01";
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { margin: 0; font-size: 26px; font-weight: 600; line-height: 1.2; letter-spacing: -0.02em; text-wrap: balance; }
h2 { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: -0.005em; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.icon { flex: none; display: block; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Shell */
.shell { display: grid; grid-template-columns: 256px minmax(0, 1fr); min-height: 100vh; }
main { padding: 40px 44px 72px; max-width: 1200px; width: 100%; margin: 0 auto; }

.sidebar {
    position: sticky; top: 0; height: 100vh;
    display: flex; flex-direction: column; gap: 24px;
    padding: 20px 14px 16px;
    background: var(--paper);
    border-right: 1px solid var(--rule);
}
.brand { display: flex; align-items: center; gap: 11px; padding: 4px 8px; color: var(--navy); font-weight: 600; line-height: 1.2; letter-spacing: -0.01em; }
.brand:hover { text-decoration: none; }
.brand small { display: block; margin-top: 1px; color: var(--muted); font-weight: 500; font-size: 12px; letter-spacing: 0; }
.brand img { width: 36px; height: 36px; border-radius: 10px; box-shadow: var(--shadow-sm); flex: none; }

.nav { display: grid; gap: 2px; }
.nav-label { margin: 0 0 6px; padding: 0 10px; font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.nav a {
    display: flex; align-items: center; gap: 11px;
    padding: 9px 10px; border-radius: 9px;
    color: var(--secondary); font-weight: 500;
    transition: background 0.12s, color 0.12s;
}
.nav a:hover { background: var(--tint); color: var(--ink); text-decoration: none; }
.nav a[aria-current] { background: var(--accent-soft); color: var(--accent); }
.nav a .count { margin-left: auto; min-width: 24px; padding: 1px 7px; border-radius: 999px; background: var(--tint); color: var(--muted); font-size: 12px; text-align: center; font-variant-numeric: tabular-nums; }
.nav a[aria-current] .count { background: var(--paper); color: var(--accent); }

.sidebar-foot { margin-top: auto; display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.theme { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; padding: 3px; border-radius: 10px; background: var(--tint); }
.theme button { display: grid; place-items: center; height: 30px; border: 0; border-radius: 8px; background: none; color: var(--muted); cursor: pointer; }
.theme button:hover { color: var(--ink); }
.theme button[aria-pressed="true"] { background: var(--paper); color: var(--accent); box-shadow: var(--shadow-sm); }
.account { display: flex; align-items: center; gap: 10px; padding: 10px 8px 2px; border-top: 1px solid var(--rule); }
.avatar { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--action-fill); color: var(--action-ink); font-size: 13px; font-weight: 600; text-transform: uppercase; flex: none; }
.account-text { min-width: 0; flex: 1; line-height: 1.3; }
.account-text span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; font-weight: 500; }
.account-text small { color: var(--muted); font-size: 12px; }

.sidebar .menu-toggle { display: none; }

/* Page head */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 28px; }
.page-head p { margin: 6px 0 0; max-width: 60ch; }
.head-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.crumbs { display: flex; align-items: center; gap: 4px; margin: 0 0 8px !important; font-size: 13px; color: var(--muted); }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--accent); }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 36px 0 14px; }
.section-head .muted { font-weight: 400; }

/* Surfaces */
.card { background: var(--paper); border: 1px solid var(--rule); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--rule); }
.card-head a { font-size: 13px; font-weight: 500; }
.card-body { padding: 20px; }

.empty { display: grid; justify-items: center; gap: 10px; padding: 56px 24px; color: var(--muted); text-align: center; }
.empty .glyph { width: 52px; height: 52px; border-radius: 16px; }
.empty strong { color: var(--ink); font-size: 16px; font-weight: 600; }
.empty p { margin: 0 0 6px; max-width: 42ch; }

.glyph { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 11px; background: var(--accent-soft); color: var(--accent); flex: none; }
.glyph.action { background: var(--success-soft); color: var(--success); }
.glyph.warn { background: var(--warn-soft); color: var(--warn); }
.glyph.small { width: 30px; height: 30px; border-radius: 9px; }

/* Dashboard */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.stat { display: grid; gap: 14px; padding: 18px 20px 20px; color: inherit; transition: border-color 0.12s, box-shadow 0.12s, transform 0.12s; }
a.stat:hover { border-color: var(--border); box-shadow: var(--shadow-md); transform: translateY(-1px); text-decoration: none; }
.stat-top { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 13px; font-weight: 500; }
.stat strong { display: block; font-family: var(--serif); font-size: 34px; font-weight: 400; line-height: 1; color: var(--navy); font-variant-numeric: tabular-nums; }
.stat small { display: block; margin-top: 8px; color: var(--muted); font-size: 13px; }

.meter { height: 6px; border-radius: 999px; background: var(--tint); overflow: hidden; }
.meter > i { display: block; height: 100%; border-radius: inherit; background: var(--action-fill); }
.meter.action > i { background: var(--success); }

.columns { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); gap: 16px; margin-top: 16px; align-items: start; }
.stack { display: grid; gap: 16px; }

.coverage { list-style: none; margin: 0; padding: 0; }
.coverage li { display: grid; grid-template-columns: 38px minmax(0, 1fr) auto; align-items: center; gap: 14px; padding: 14px 20px; border-bottom: 1px solid var(--rule); }
.coverage li:last-child { border-bottom: 0; }
.coverage .title { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 7px; }
.coverage .title a { color: var(--ink); font-weight: 500; }
.coverage .title span { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; }

.publish { display: grid; gap: 14px; }
.publish .version { display: flex; align-items: center; gap: 10px; }
.publish .version strong { font-size: 15px; font-weight: 600; }
.copy-field { display: flex; align-items: center; gap: 4px; padding: 4px 4px 4px 12px; border: 1px solid var(--rule); border-radius: 10px; background: var(--surface); }
.copy-field code { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12.5px; color: var(--secondary); }

.feed { list-style: none; margin: 0; padding: 6px 0; }
.feed li a { display: grid; gap: 3px; padding: 10px 20px; color: inherit; }
.feed li a:hover { background: var(--surface); text-decoration: none; }
.feed .line { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.feed small { color: var(--muted); font-size: 12.5px; }

.notice { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 16px; padding: 14px 16px; border: 1px solid var(--warn-soft); border-radius: var(--radius); background: var(--warn-soft); color: var(--warn); }
.notice .icon { margin-top: 1px; }
.notice p { margin: 0; color: var(--ink); }
.notice a { font-weight: 500; }

/* Toast */
.flash {
    position: fixed; top: 20px; right: 20px; z-index: 40;
    display: flex; align-items: center; gap: 10px;
    max-width: min(420px, calc(100vw - 40px)); margin: 0; padding: 12px 12px 12px 14px;
    border: 1px solid var(--rule); border-radius: 12px;
    background: var(--paper); color: var(--ink); box-shadow: var(--shadow-md);
    font-weight: 500;
    animation: toast-in 0.25s ease-out;
}
.flash.leaving { opacity: 0; transform: translateY(-6px); transition: opacity 0.2s, transform 0.2s; }
.flash-success .icon { color: var(--success); }
.flash-error .icon { color: var(--error); }
.flash-info .icon { color: var(--accent); }
.flash .icon-button { margin-left: 4px; }
.flash.inline { position: static; max-width: none; box-shadow: none; animation: none; border-color: var(--error-soft); background: var(--error-soft); color: var(--error); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } }

/* Tables */
.table-card { position: relative; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 14px 16px; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--rule); }
th:first-child, td:first-child { padding-left: 20px; }
th:last-child, td:last-child { padding-right: 20px; }
th { padding-top: 11px; padding-bottom: 11px; background: var(--surface); font-size: 11.5px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); white-space: nowrap; }
th.num { text-align: right; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr { transition: background 0.1s; }
tbody tr:hover { background: var(--surface); }
.cell { display: flex; align-items: center; gap: 12px; min-width: 0; }
.cell > div { min-width: 0; }
.cell a { color: var(--ink); }
.cell a:hover { color: var(--accent); text-decoration: none; }
.cell strong { font-weight: 600; }
.cell small { display: block; color: var(--muted); font-size: 13px; }
td.clip { max-width: 420px; }
td.clip a { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; color: var(--ink); line-height: 1.45; }
td.clip a:hover { color: var(--accent); text-decoration: none; }
td small { display: block; color: var(--muted); font-size: 13px; }
td.actions { white-space: nowrap; text-align: right; }
td.actions > * { display: inline-flex; vertical-align: middle; }
td.actions form { display: inline-flex; }
.order { display: inline-grid; place-items: center; min-width: 26px; height: 26px; padding: 0 6px; border-radius: 8px; background: var(--tint); color: var(--secondary); font-size: 12.5px; font-weight: 500; font-variant-numeric: tabular-nums; }

.tag { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; background: var(--tint); color: var(--secondary); font-size: 12.5px; font-weight: 500; white-space: nowrap; }
.tag.on, .tag.off, .tag.warn { padding-left: 8px; }
.tag.on::before, .tag.off::before, .tag.warn::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.tag.on { background: var(--success-soft); color: var(--success); }
.tag.off { color: var(--muted); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }

/* Buttons */
.button {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 38px; padding: 0 14px;
    border: 1px solid var(--border); border-radius: 10px;
    background: var(--paper); color: var(--ink); box-shadow: var(--shadow-sm);
    font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap;
    transition: background 0.12s, filter 0.12s, border-color 0.12s;
}
.button:hover { background: var(--tint); text-decoration: none; }
.button:active { transform: translateY(0.5px); }
.button.primary { background: var(--action-fill); border-color: transparent; color: var(--action-ink); }
.button.primary:hover { filter: brightness(1.15); }
.button.danger { color: var(--error); }
.button.danger:hover { background: var(--error-soft); border-color: var(--error); }
.button.danger.solid { background: var(--error); border-color: var(--error); color: var(--paper); }
.button.danger.solid:hover { filter: brightness(1.1); }
.button.wide { width: 100%; min-height: 44px; }
.icon-button { display: inline-grid; place-items: center; width: 32px; height: 32px; padding: 0; border: 0; border-radius: 8px; background: none; color: var(--muted); cursor: pointer; }
.icon-button:hover { background: var(--tint); color: var(--accent); text-decoration: none; }
.icon-button.danger:hover { background: var(--error-soft); color: var(--error); }
.link { padding: 0; border: 0; background: none; color: var(--accent); font: inherit; cursor: pointer; }
.link:hover { text-decoration: underline; }

/* Forms */
.editor { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 28px; align-items: start; }
.editor.single { grid-template-columns: minmax(0, 720px); }
.form { display: grid; gap: 22px; padding: 28px; }
.form-section { display: grid; gap: 18px; padding-top: 22px; border-top: 1px solid var(--rule); }
.form-section > h2 { margin-bottom: -4px; }
.form footer { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px -28px -28px; padding: 16px 28px; border-top: 1px solid var(--rule); border-radius: 0 0 var(--radius) var(--radius); background: var(--surface); }
.form footer .spacer { flex: 1; }
.row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.field { display: grid; gap: 7px; margin: 0; padding: 0; border: 0; min-width: 0; }
.field > span, .field > legend { display: flex; align-items: baseline; gap: 8px; font-weight: 500; padding: 0; }
.field > legend { margin-bottom: 8px; }
.field small { color: var(--muted); font-weight: 400; font-size: 13px; }
.field .counter { margin-left: auto; font-variant-numeric: tabular-nums; font-size: 12px; }
.field .counter.near { color: var(--warn); }
.field b { font-weight: 500; }
.field em { display: flex; align-items: center; gap: 6px; color: var(--error); font-style: normal; font-size: 13px; }
input[type="text"], input[type="email"], input[type="password"], input[type="url"],
input[type="number"], input[type="search"], select, textarea {
    width: 100%; min-height: 42px; padding: 9px 12px;
    border: 1px solid var(--border); border-radius: 10px;
    background: var(--paper); color: var(--ink); font: inherit;
    transition: border-color 0.12s, box-shadow 0.12s;
}
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 0.7; }
input:hover, select:hover, textarea:hover { border-color: var(--accent); }
input:focus, select:focus, textarea:focus { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
select { appearance: none; padding-right: 38px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23687383' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; }
textarea { font-family: var(--serif); font-size: 17px; line-height: 1.6; resize: vertical; min-height: 180px; }
.invalid input, .invalid textarea, .invalid select { border-color: var(--error); box-shadow: 0 0 0 3px var(--error-soft); }

.cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.option { position: relative; display: flex; gap: 12px; align-items: flex-start; padding: 14px; border: 1px solid var(--border); border-radius: 12px; cursor: pointer; transition: border-color 0.12s, background 0.12s; }
.option:hover { border-color: var(--accent); }
.option input { position: absolute; opacity: 0; }
.option:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 1px var(--accent); }
.option:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.option:has(input:disabled) { opacity: 0.5; cursor: not-allowed; }
.option strong { display: block; font-weight: 600; }
.option small { display: block; margin-top: 2px; color: var(--muted); font-size: 13px; }

.switch { display: flex; gap: 14px; align-items: center; justify-content: space-between; padding: 14px 16px; border: 1px solid var(--rule); border-radius: 12px; background: var(--surface); cursor: pointer; }
.switch strong { display: block; font-weight: 500; }
.switch small { display: block; color: var(--muted); font-size: 13px; }
.switch input { appearance: none; position: relative; flex: none; width: 42px; height: 24px; margin: 0; border-radius: 999px; background: var(--border); cursor: pointer; transition: background 0.15s; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgb(0 0 0 / 0.25); transition: transform 0.15s; }
.switch input:checked { background: var(--switch-on); }
.switch input:checked::after { transform: translateX(18px); }

form[data-kind="read"] .for-action, form[data-kind="action"] .for-read { display: none; }
div.for-read, div.for-action { display: grid; gap: 18px; }

/* Filters */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 7px; padding: 6px 12px; border: 1px solid var(--rule); border-radius: 999px; background: var(--paper); color: var(--secondary); font-size: 13px; font-weight: 500; }
.chip:hover { border-color: var(--border); color: var(--ink); text-decoration: none; }
.chip span { color: var(--muted); font-variant-numeric: tabular-nums; }
.chip[aria-current] { border-color: transparent; background: var(--action-fill); color: var(--action-ink); }
.chip[aria-current] span { color: inherit; opacity: 0.75; }
.search { position: relative; flex: 1; min-width: 220px; max-width: 340px; }
.search .icon { position: absolute; top: 50%; left: 12px; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search input { min-height: 38px; padding-left: 38px; border-radius: 999px; }
.result-note { margin: 0 0 12px; color: var(--muted); font-size: 13px; }

.pager { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-top: 16px; }
.pager p { margin: 0; font-size: 13px; font-variant-numeric: tabular-nums; }
.pager-links { display: flex; align-items: center; gap: 4px; }
.pager-links > a:not(.icon-button) { display: grid; place-items: center; min-width: 32px; height: 32px; padding: 0 8px; border-radius: 8px; color: var(--secondary); font-size: 13px; font-weight: 500; font-variant-numeric: tabular-nums; }
.pager-links > a:not(.icon-button):hover { background: var(--tint); color: var(--ink); text-decoration: none; }
.pager-links > a[aria-current] { background: var(--action-fill); color: var(--action-ink); }
.pager-links > a[aria-current]:hover { background: var(--action-fill); color: var(--action-ink); }
.pager-links .back .icon { transform: rotate(180deg); }
.pager-links [aria-disabled] { opacity: 0.35; pointer-events: none; }
.pager-links .gap { min-width: 24px; text-align: center; color: var(--muted); }

/* Detail pages */
.details { display: grid; margin: 0; }
.details > div { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 16px; padding: 13px 20px; border-bottom: 1px solid var(--rule); }
.details > div:last-child { border-bottom: 0; }
.details dt { color: var(--muted); }
.details dd { margin: 0; overflow-wrap: anywhere; }

/* Phone preview: mirrors PassageView and ActionPromptView. */
.preview-pane { position: sticky; top: 24px; display: grid; gap: 12px; justify-items: center; }
.preview-pane > small { color: var(--muted); font-size: 12px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; }
.phone { width: 100%; max-width: 320px; padding: 10px; border-radius: 44px; background: var(--navy); box-shadow: var(--shadow-lg); }
:root[data-theme="dark"] .phone { background: #2a3566; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .phone { background: #2a3566; } }
.phone-screen { display: flex; flex-direction: column; height: 620px; padding: 18px 22px 20px; border-radius: 35px; background: var(--paper); }
.phone-scroll { flex: 1; min-height: 0; overflow-y: auto; scrollbar-width: none; mask-image: linear-gradient(#000 calc(100% - 24px), transparent); padding-bottom: 24px; }
.phone-scroll::-webkit-scrollbar { display: none; }
.phone-bar { flex: none; display: flex; align-items: center; gap: 8px; margin-bottom: 26px; color: var(--navy); font-size: 13px; font-weight: 500; }
.phone-bar img { width: 22px; height: 22px; border-radius: 6px; }
.phone-meta { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 14px; font-size: 11px; color: var(--muted); }
.kicker { margin: 0; font-size: 11px; font-weight: 500; letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); }
.phone-title { margin: 0; font-size: 22px; font-weight: 500; line-height: 1.22; letter-spacing: -0.015em; overflow-wrap: anywhere; }
.phone-source { margin: 8px 0 0; font-size: 11px; color: var(--secondary); text-decoration: underline; text-decoration-color: var(--border); text-underline-offset: 2px; }
.phone-passages { display: grid; gap: 16px; margin-top: 22px; }
.phone-passages p { margin: 0; font-family: var(--serif); font-size: 17.5px; line-height: 1.5; white-space: pre-line; overflow-wrap: anywhere; }
.phone-byline { margin: 20px 0 0; font-size: 11px; line-height: 1.5; color: var(--secondary); }
.phone-prompt { margin: 22px 0 0; padding: 12px 14px; border-radius: 12px; background: var(--tint); font-size: 12.5px; color: var(--secondary); }
.phone-prompt b { display: block; margin-bottom: 2px; font-size: 10.5px; font-weight: 500; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.phone-actions { flex: none; display: grid; gap: 8px; padding-top: 8px; }
.phone-actions span { display: grid; place-items: center; height: 42px; border: 1px solid var(--border); border-radius: 12px; font-size: 13px; font-weight: 500; }
.phone-actions span:last-child { border-color: transparent; background: var(--action-fill); color: var(--action-ink); }
.phone [hidden] { display: none !important; }
.phone .placeholder { color: var(--muted); opacity: 0.6; }

.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 28px; align-items: start; }

/* Dialog */
dialog.confirm { width: min(420px, calc(100vw - 32px)); padding: 24px; border: 1px solid var(--rule); border-radius: 18px; background: var(--paper); color: var(--ink); box-shadow: var(--shadow-lg); }
dialog.confirm::backdrop { background: rgb(11 16 30 / 0.55); backdrop-filter: blur(3px); }
dialog.confirm[open] { animation: dialog-in 0.18s ease-out; }
dialog.confirm .glyph { margin-bottom: 14px; background: var(--error-soft); color: var(--error); }
dialog.confirm h2 { font-size: 17px; }
dialog.confirm p { margin: 6px 0 22px; color: var(--secondary); }
dialog.confirm menu { display: flex; justify-content: flex-end; gap: 8px; margin: 0; padding: 0; }
@keyframes dialog-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } }

/* Sign-in and error pages */
.auth { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); min-height: 100vh; background: var(--paper); }
.auth-art {
    position: relative; overflow: hidden;
    display: flex; flex-direction: column; justify-content: space-between; gap: 40px;
    padding: 44px 52px;
    background: radial-gradient(120% 90% at 20% 10%, #33409a 0%, #1a2149 48%, #0e1330 100%);
    color: #eef0ff;
}
.auth-art::after { content: ""; position: absolute; right: -180px; bottom: -180px; width: 520px; height: 520px; border-radius: 50%; border: 56px solid rgb(199 210 254 / 0.08); box-shadow: 0 0 0 90px rgb(199 210 254 / 0.04); }
.auth-art .brand { padding: 0; color: #fff; }
.auth-art .brand small { color: #aebeff; }
.auth-art blockquote { position: relative; z-index: 1; margin: 0; max-width: 24ch; font-family: var(--serif); font-size: clamp(26px, 3vw, 36px); line-height: 1.3; }
.auth-art cite { display: block; margin-top: 18px; font: 500 13px/1.5 var(--sans); color: #aebeff; }
.auth-art p { position: relative; z-index: 1; margin: 0; max-width: 40ch; color: #bcc5e8; font-size: 13px; }
.auth-form { display: grid; place-items: center; padding: 32px 24px; }
.auth-card { display: grid; gap: 18px; width: 100%; max-width: 360px; }
.auth-card h1 { font-size: 24px; }
.auth-card p { margin: 0; }
.auth-card .brand { display: none; padding: 0; margin-bottom: 8px; }

.centered { display: grid; place-items: center; min-height: 100vh; padding: 24px; }
.error-card { display: grid; justify-items: center; gap: 10px; max-width: 420px; padding: 40px 32px; text-align: center; }
.error-card .glyph { width: 52px; height: 52px; border-radius: 16px; margin-bottom: 6px; }
.error-card p { margin: 0 0 12px; }

@media (max-width: 1080px) {
    .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .columns, .editor, .detail-grid { grid-template-columns: minmax(0, 1fr); }
    .preview-pane { position: static; }
}

@media (max-width: 820px) {
    .shell { grid-template-columns: minmax(0, 1fr); }
    .sidebar { position: sticky; z-index: 30; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 0; padding: 10px 16px; border-right: 0; border-bottom: 1px solid var(--rule); }
    .brand { padding: 0; }
    .sidebar .menu-toggle { display: inline-grid; margin-left: auto; }
    .sidebar .nav, .sidebar-foot { display: none; width: 100%; }
    .sidebar.open .nav { display: grid; margin-top: 12px; }
    .sidebar.open .sidebar-foot { display: grid; margin-top: 12px; }
    .nav-label { display: none; }
    main { padding: 24px 16px 56px; }
    .row, .cards { grid-template-columns: minmax(0, 1fr); }
    .page-head { flex-direction: column; align-items: flex-start; }
    .details > div { grid-template-columns: minmax(0, 1fr); gap: 2px; }
    .form { padding: 20px; }
    .form footer { margin: 6px -20px -20px; padding: 14px 20px; }
    .search { max-width: none; flex-basis: 100%; }
    .toolbar { align-items: stretch; }
    .chips { flex-wrap: nowrap; max-width: 100%; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 2px 16px; }
    .chips::-webkit-scrollbar { display: none; }
    .chip { white-space: nowrap; }
    td.clip { min-width: 260px; }
    .auth { grid-template-columns: minmax(0, 1fr); }
    .auth-art { display: none; }
    .auth-card .brand { display: flex; }
    .flash { top: 12px; right: 12px; left: 12px; max-width: none; }
}

@media (max-width: 520px) {
    .stats { grid-template-columns: minmax(0, 1fr); }
}

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