:root {
    color-scheme: light dark;
    --bg: #f3f1ea;
    --surface: #fffdf8;
    --surface-2: #ebe7dc;
    --ink: #1d211d;
    --muted: #687068;
    --line: #d9d5ca;
    --accent: #315d49;
    --accent-strong: #244638;
    --accent-soft: #dce9df;
    --warning: #a35f12;
    --danger: #a13e35;
    --shadow: 0 16px 40px rgb(31 38 31 / .07);
    --radius: 18px;
    font-family: ui-rounded, "SF Pro Rounded", "SF Pro Display", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); }
body { margin: 0; color: var(--ink); background: radial-gradient(circle at 10% -10%, rgb(202 222 207 / .6), transparent 32rem), var(--bg); }
a { color: inherit; }
button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }
img { display: block; max-width: 100%; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: .5rem; font-size: clamp(2rem, 4vw, 3.7rem); letter-spacing: -.045em; line-height: 1.02; }
h2 { margin-bottom: .4rem; font-size: 1.25rem; letter-spacing: -.02em; }
h3 { margin-bottom: .2rem; font-size: 1rem; }

.site-header { position: sticky; z-index: 10; top: 0; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 2rem; min-height: 72px; padding: .7rem clamp(1rem, 4vw, 3.5rem); border-bottom: 1px solid rgb(83 91 83 / .14); background: rgb(250 249 244 / .88); backdrop-filter: blur(18px); }
.brand { display: inline-flex; align-items: center; gap: .65rem; color: var(--ink); font-weight: 760; text-decoration: none; }
.brand-mark { display: grid; width: 35px; height: 39px; place-items: center; color: white; border-radius: 5px 5px 10px 10px; background: var(--accent); box-shadow: inset 0 -5px rgb(0 0 0 / .1); }
.site-header nav { display: flex; gap: .25rem; }
.site-header nav a { padding: .65rem .8rem; color: var(--muted); border-radius: 10px; font-size: .9rem; font-weight: 650; text-decoration: none; }
.site-header nav a:hover, .site-header nav a.active { color: var(--ink); background: var(--surface-2); }

.page { width: min(1480px, 100%); margin: 0 auto; padding: clamp(1.5rem, 4vw, 3.8rem); }
.auth-page { display: grid; min-height: 100vh; place-items: center; }
.page-heading { display: flex; align-items: end; justify-content: space-between; gap: 2rem; margin-bottom: 2rem; }
.page-heading.compact h1 { font-size: clamp(2rem, 3.5vw, 3rem); }
.page-heading p, .muted { color: var(--muted); }
.eyebrow { margin-bottom: .45rem; color: var(--accent); font-size: .72rem; font-weight: 800; letter-spacing: .16em; text-transform: uppercase; }
.subtitle { margin-bottom: .6rem; color: var(--muted); font-size: clamp(1.1rem, 2vw, 1.45rem); }
.byline { color: var(--muted); font-size: 1.05rem; }
.back-link { display: inline-block; margin-bottom: 1.5rem; color: var(--accent); font-weight: 700; text-decoration: none; }
.review-navigation { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem; }
.review-navigation .back-link { margin: 0; }
.review-navigation > div { display: flex; gap: .5rem; }

.button { display: inline-flex; min-height: 42px; align-items: center; justify-content: center; padding: .65rem 1rem; color: #fff; border: 1px solid var(--accent); border-radius: 11px; background: var(--accent); font-weight: 720; text-decoration: none; }
.button:hover { border-color: var(--accent-strong); background: var(--accent-strong); }
.button:disabled { cursor: not-allowed; opacity: .45; }
.button.confirm { background: #477c5e; }
.button.danger { color: #fff; border-color: var(--danger); background: var(--danger); }
.button.danger:hover { border-color: #7f2f29; background: #7f2f29; }
.button.quiet { color: var(--ink); border-color: var(--line); background: transparent; }
.button.quiet:hover { background: var(--surface-2); }
.button.small { min-height: 36px; padding: .45rem .75rem; font-size: .86rem; }
.flash { margin-bottom: 1.4rem; padding: .85rem 1rem; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); box-shadow: var(--shadow); }
.flash.success { color: var(--accent-strong); border-color: #a9c6b2; background: var(--accent-soft); }
.flash.error { color: var(--danger); border-color: #ddb7b3; background: #f9e5e2; }

.panel { min-width: 0; padding: clamp(1.1rem, 2.5vw, 1.6rem); border: 1px solid var(--line); border-radius: var(--radius); background: rgb(255 253 248 / .9); box-shadow: var(--shadow); }
.section-heading { display: flex; align-items: start; justify-content: space-between; gap: 1rem; margin-bottom: 1.3rem; }
.section-heading > span, .record-id { color: var(--muted); font-family: ui-monospace, "SFMono-Regular", monospace; font-size: .72rem; }

.metrics, .metric-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-bottom: 2rem; }
.metric { padding: 1.25rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.metric { color: inherit; text-decoration: none; }
.metric strong { display: block; margin-bottom: .3rem; font-size: 2rem; letter-spacing: -.04em; }
.metric span, .metric small { display: block; color: var(--muted); font-size: .78rem; }
.metric.accent { border-color: #a8c9b3; background: var(--accent-soft); }
.metric.danger { border-color: #ddb7b3; }
.dashboard-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 1rem; }
.recent-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.split-layout { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, .75fr); align-items: start; gap: 1.5rem; }
.split-layout > section:first-child { min-width: 0; }
.section-heading > h2 { margin: 0; }
.section-heading > a { color: var(--accent); font-size: .82rem; font-weight: 700; }
.cover-row { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: .9rem; }
.cover-card { display: grid; align-content: start; gap: .4rem; color: inherit; text-decoration: none; }
.cover-card img, .cover-placeholder { display: grid; width: 100%; aspect-ratio: 2 / 3; place-items: center; object-fit: cover; color: white; border-radius: 8px 8px 13px 13px; background: var(--accent); box-shadow: 0 10px 22px rgb(31 38 31 / .14); }
.cover-card strong { overflow: hidden; font-size: .75rem; line-height: 1.25; text-overflow: ellipsis; white-space: nowrap; }
.cover-card small { color: var(--muted); font-size: .68rem; }
.issue-summary-list { display: grid; }
.issue-summary { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: .65rem; padding: .75rem 0; border-top: 1px solid var(--line); text-decoration: none; }
.issue-summary:first-child { padding-top: 0; border-top: 0; }
.issue-summary span:nth-child(2) { display: grid; text-transform: capitalize; }
.issue-summary small { color: var(--muted); font-size: .68rem; }
.severity-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.severity-dot.warning { background: var(--warning); }
.severity-dot.error { background: var(--danger); }

.filter-bar { display: grid; grid-template-columns: minmax(230px, 2fr) repeat(4, minmax(120px, 1fr)) auto auto; align-items: end; gap: .8rem; margin-bottom: 1.8rem; padding: 1rem; border: 1px solid var(--line); border-radius: var(--radius); background: rgb(255 253 248 / .72); }
label { display: grid; gap: .4rem; color: var(--muted); font-size: .78rem; font-weight: 700; }
input, select, textarea { width: 100%; min-height: 42px; padding: .65rem .72rem; color: var(--ink); border: 1px solid var(--line); border-radius: 10px; outline: none; background: var(--surface); }
textarea { min-height: 100px; resize: vertical; }
input:focus, select:focus, textarea:focus, .button:focus-visible, a:focus-visible { border-color: var(--accent); outline: 3px solid rgb(49 93 73 / .18); outline-offset: 1px; }
.catalogue-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: clamp(.8rem, 2vw, 1.4rem); }
.book-card { overflow: hidden; color: inherit; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: 0 8px 24px rgb(31 38 31 / .05); text-decoration: none; transition: transform .16s ease, box-shadow .16s ease; }
.book-card:hover { transform: translateY(-3px); box-shadow: 0 16px 38px rgb(31 38 31 / .12); }
.book-cover { position: relative; display: grid; overflow: hidden; aspect-ratio: 2 / 2.65; place-items: center; color: white; background: linear-gradient(145deg, var(--accent), #152f26); font-size: 2rem; }
.book-cover img { width: 100%; height: 100%; object-fit: cover; }
.issue-count { position: absolute; top: .55rem; right: .55rem; min-width: 27px; padding: .25rem; text-align: center; border-radius: 100px; background: var(--danger); box-shadow: 0 3px 8px rgb(0 0 0 / .25); font-size: .72rem; }
.book-card-body { padding: .9rem; }
.book-card-body h2 { overflow: hidden; margin-bottom: .25rem; font-size: 1rem; line-height: 1.25; }
.book-card-body > p { overflow: hidden; margin-bottom: .7rem; color: var(--muted); font-size: .8rem; text-overflow: ellipsis; white-space: nowrap; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip { padding: .28rem .48rem; border-radius: 999px; color: var(--accent-strong); background: var(--accent-soft); font-size: .67rem; font-weight: 750; text-transform: capitalize; }
.chip.subtle { color: var(--muted); background: var(--surface-2); }
.chip.state-active { color: #fff; background: var(--accent); }
.chip.state-completed, .chip.state-verified { color: #28513a; background: #d7eadc; }
.chip.state-needs_review, .chip.state-unknown_legacy { color: #874f0f; background: #f7e4c7; }
.chip.removed { color: #7f2f29; background: #f9e5e2; }
.pagination { display: flex; justify-content: center; gap: 1.5rem; margin-top: 2rem; color: var(--muted); }
.pagination a { color: var(--accent); font-weight: 700; }
.empty-state { padding: 5rem 2rem; text-align: center; border: 1px dashed var(--line); border-radius: var(--radius); }
.empty-icon { display: block; margin-bottom: 1rem; font-size: 3rem; }

.book-hero { display: grid; grid-template-columns: 190px minmax(0, 1fr); align-items: end; gap: clamp(1.5rem, 4vw, 3rem); margin-bottom: 2rem; }
.detail-cover { display: grid; overflow: hidden; aspect-ratio: 2 / 3; place-items: center; color: white; border-radius: 10px 10px 18px 18px; background: linear-gradient(145deg, var(--accent), #152f26); box-shadow: 0 25px 45px rgb(31 38 31 / .2); font-size: 3rem; }
.detail-cover img { width: 100%; height: 100%; object-fit: cover; }
.book-hero-copy { padding-bottom: .3rem; }
.book-hero-copy .chips { margin-bottom: 1rem; }
.removed-work-panel { display: flex; align-items: center; justify-content: space-between; gap: 2rem; }
.hero-stats { display: flex; flex-wrap: wrap; gap: 1.5rem; margin-top: 1.5rem; }
.hero-stats div { display: grid; }
.hero-stats strong { font-size: 1.3rem; }
.hero-stats span { color: var(--muted); font-size: .75rem; }
.detail-layout { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, .72fr); align-items: start; gap: 1rem; }
.detail-main, .detail-aside { display: grid; min-width: 0; gap: 1rem; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-grid .wide { grid-column: 1 / -1; }
.form-actions { display: flex; justify-content: flex-end; }
.form-actions { gap: .6rem; }
.configuration-note { display: inline-block; margin-left: .8rem; color: var(--muted); }
.classification-editor { border: 1px solid var(--line); border-radius: 14px; padding: 1rem; min-width: 0; }
.classification-editor legend { font-weight: 750; padding: 0 .35rem; }
.classification-editor > label { max-width: 22rem; }
.genre-picker { border-top: 1px solid var(--line); margin-top: 1rem; padding-top: .8rem; }
.genre-picker summary { cursor: pointer; font-weight: 700; }
.genre-picker summary small { color: var(--muted); font-weight: 500; margin-left: .35rem; }
.genre-options { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: .55rem; margin-top: .8rem; }
.genre-option { align-items: center; border: 1px solid var(--line); border-radius: 10px; display: flex; flex-direction: row !important; gap: .55rem !important; padding: .6rem .7rem; }
.genre-option input { margin: 0; width: auto; }
.enrichment-panel { border-color: #9ebaa7; background: linear-gradient(145deg, var(--accent-soft), var(--surface) 55%); }
.proposal-grid { display: grid; grid-template-columns: 145px 1fr; gap: 1.4rem; }
.proposal-cover { display: grid; overflow: hidden; aspect-ratio: 2 / 3; place-items: center; color: var(--muted); border-radius: 8px 8px 14px 14px; background: var(--surface-2); font-size: .75rem; }
.proposal-cover img { width: 100%; height: 100%; object-fit: cover; }
.proposal-values { display: grid; grid-template-columns: 1fr 1fr; margin: 1rem 0; }
.proposal-values div { padding: .55rem 0; }
.proposal-values dt { color: var(--muted); font-size: .7rem; text-transform: uppercase; }
.proposal-values dd { margin: .2rem 0 0; }
.proposal-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1rem; }
.stack-list { display: grid; }
.stack-list > article { padding: 1rem 0; border-top: 1px solid var(--line); }
.stack-list > article:first-child { padding-top: 0; border-top: 0; }
.stack-list > article:last-child { padding-bottom: 0; }
.copy-row, .run-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 1rem; }
.copy-row p, .run-row p { margin-bottom: .25rem; color: var(--muted); font-size: .84rem; }
.metadata-line { display: flex; flex-wrap: wrap; gap: .4rem .9rem; color: var(--muted); font-size: .72rem; }
.inline-form, .rating-form { display: flex; align-items: end; gap: .5rem; }
.inline-form label, .rating-form label { min-width: 128px; }
.run-row { grid-template-columns: minmax(180px, 1.4fr) minmax(150px, .7fr) auto; }
.run-status { display: flex; align-items: center; gap: .8rem; }
.status-dot { width: 9px; height: 9px; flex: none; border-radius: 50%; background: var(--muted); }
.status-dot.state-active { background: #218851; box-shadow: 0 0 0 4px #d7eadc; }
.status-dot.state-completed { background: var(--accent); }
.status-dot.state-abandoned, .status-dot.state-unknown_legacy { background: var(--warning); }
.run-numbers { display: flex; gap: 1rem; color: var(--muted); font-size: .75rem; }
.run-numbers strong { color: var(--ink); }
.aside-panel h2 { margin-bottom: 1rem; }
.issue-list { display: grid; gap: .5rem; }
.issue-list a { display: grid; grid-template-columns: auto 1fr; gap: .3rem .5rem; padding: .7rem; border-radius: 10px; background: var(--surface-2); text-decoration: none; }
.issue-list small { grid-column: 2; color: var(--muted); text-transform: capitalize; }
.severity { align-self: start; padding: .15rem .35rem; border-radius: 5px; color: var(--muted); background: var(--surface); font-size: .6rem; font-weight: 800; text-transform: uppercase; }
.severity.error { color: var(--danger); background: #f9e5e2; }
.severity.warning { color: var(--warning); background: #f7e4c7; }
details { padding: .7rem 0; border-top: 1px solid var(--line); }
details summary { cursor: pointer; font-size: .84rem; font-weight: 700; }
.ignore-control { margin-top: 1.2rem; }
.ignore-control form { padding-top: .8rem; }
.source-meta { margin: .5rem 0; color: var(--muted); font-size: .72rem; }
pre { overflow: auto; max-height: 320px; padding: .8rem; border-radius: 8px; background: #20251f; color: #edf3ea; font-size: .68rem; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }
.audit-list { display: grid; gap: .7rem; }
.audit-list div { display: grid; }
.audit-list span { color: var(--muted); font-size: .7rem; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .83rem; }
th { color: var(--muted); font-size: .7rem; letter-spacing: .06em; text-align: left; text-transform: uppercase; }
th, td { padding: .7rem .5rem; border-bottom: 1px solid var(--line); }
tbody tr:last-child td { border-bottom: 0; }
.numeric { text-align: right; }

.auth-card { width: min(440px, 100%); padding: 2rem; border: 1px solid var(--line); border-radius: 22px; background: var(--surface); box-shadow: var(--shadow); }
.auth-card .brand-mark, .auth-logo { display: grid; width: 44px; height: 50px; margin-bottom: 1.5rem; place-items: center; color: white; border-radius: 6px 6px 12px 12px; background: var(--accent); font-size: 1.2rem; font-weight: 800; }
.auth-card form { display: grid; gap: 1rem; }
.auth-card .button { width: 100%; }
.review-list, .history-list { display: grid; gap: .7rem; }
.review-row, .history-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; align-items: center; gap: 1rem; padding: 1rem; color: inherit; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); text-decoration: none; }
.review-body { display: grid; }
.review-body small { color: var(--muted); text-transform: capitalize; }
.severity-icon { display: grid; width: 32px; height: 32px; place-items: center; border-radius: 50%; color: var(--muted); background: var(--surface-2); font-weight: 800; }
.severity-icon.error { color: var(--danger); background: #f9e5e2; }
.severity-icon.warning { color: var(--warning); background: #f7e4c7; }
.history-row { grid-template-columns: 56px minmax(0, 1fr) auto; }
.mini-cover { display: grid; overflow: hidden; width: 56px; aspect-ratio: 2 / 3; place-items: center; color: white; border-radius: 5px 5px 9px 9px; background: var(--accent); text-decoration: none; }
.mini-cover img { width: 100%; height: 100%; object-fit: cover; }
.history-main { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.history-main h2 { margin: .3rem 0; }
.history-main h2 a { text-decoration: none; }
.history-main p { margin: 0; color: var(--muted); font-size: .8rem; }
.date-range { flex: none; }
.segmented { display: inline-flex; gap: .2rem; margin-bottom: 1.5rem; padding: .25rem; border-radius: 12px; background: var(--surface-2); }
.segmented a { padding: .5rem .75rem; color: var(--muted); border-radius: 9px; font-size: .78rem; font-weight: 700; text-decoration: none; }
.segmented a.active { color: var(--ink); background: var(--surface); box-shadow: 0 2px 8px rgb(31 38 31 / .08); }
.detail-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1rem; }
.stack { display: grid; gap: 1rem; }
.data-list { margin: 0; }
.data-list div { display: grid; grid-template-columns: minmax(120px, .45fr) 1fr; gap: 1rem; padding: .7rem 0; border-top: 1px solid var(--line); }
.data-list div:first-child { border-top: 0; }
.data-list dt { color: var(--muted); font-size: .72rem; text-transform: capitalize; }
.data-list dd { margin: 0; overflow-wrap: anywhere; }
.source-panel { margin-top: 1rem; }
.review-filters { grid-template-columns: repeat(3, minmax(140px, 1fr)) auto auto; }

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

@media (prefers-color-scheme: dark) {
    :root { --bg: #151915; --surface: #1d221d; --surface-2: #292f29; --ink: #f0f0e8; --muted: #a5ada5; --line: #373e37; --accent: #72a887; --accent-strong: #8dbb9d; --accent-soft: #273d2f; --shadow: 0 16px 40px rgb(0 0 0 / .18); }
    body { background: radial-gradient(circle at 10% -10%, rgb(44 77 57 / .65), transparent 32rem), var(--bg); }
    .site-header { background: rgb(21 25 21 / .9); }
    .panel, .filter-bar { background: rgb(29 34 29 / .9); }
    .button { color: #102018; }
    .chip.state-active { color: #102018; }
    .flash.error { background: #3d2422; }
}

@media (max-width: 1100px) {
    .filter-bar { grid-template-columns: repeat(3, 1fr); }
    .search-field { grid-column: span 2; }
    .catalogue-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .metrics, .metric-grid { grid-template-columns: repeat(2, 1fr); }
    .cover-row { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 820px) {
    .site-header { grid-template-columns: auto auto; gap: .7rem; }
    .site-header nav { grid-column: 1 / -1; grid-row: 2; overflow-x: auto; order: 3; }
    .site-header > form { justify-self: end; }
    .detail-layout, .dashboard-grid, .split-layout { grid-template-columns: 1fr; }
    .catalogue-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .run-row { grid-template-columns: 1fr 1fr; }
    .rating-form { grid-column: 1 / -1; }
}

@media (max-width: 560px) {
    .page { padding: 1.2rem; }
    .site-header { padding: .65rem 1rem; }
    .site-header nav a { padding: .55rem .6rem; white-space: nowrap; }
    .site-header .button.quiet { min-height: 36px; padding: .4rem .65rem; }
    .filter-bar { grid-template-columns: 1fr 1fr; }
    .search-field { grid-column: 1 / -1; }
    .catalogue-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .book-hero { grid-template-columns: 105px 1fr; align-items: center; gap: 1rem; }
    .book-hero h1 { font-size: 1.8rem; }
    .book-hero .subtitle { font-size: .95rem; }
    .hero-stats { grid-column: 1 / -1; gap: .8rem; }
    .hero-stats div { min-width: 60px; }
    .form-grid, .copy-row, .run-row { grid-template-columns: 1fr; }
    .form-grid .wide, .rating-form { grid-column: auto; }
    .inline-form, .rating-form { width: 100%; }
    .inline-form label, .rating-form label { min-width: 0; flex: 1; }
    .metrics, .metric-grid { grid-template-columns: 1fr 1fr; gap: .65rem; }
    .recent-grid { grid-template-columns: repeat(2, 1fr); }
    .detail-columns { grid-template-columns: 1fr; }
    .review-row { grid-template-columns: auto minmax(0, 1fr) auto; }
    .review-row > span:last-child { display: none; }
    .history-row { grid-template-columns: 45px 1fr; }
    .mini-cover { width: 45px; }
    .history-row > form { grid-column: 2; }
    .history-main { display: grid; }
    .segmented { overflow-x: auto; width: 100%; }
    .segmented a { white-space: nowrap; }
    .review-navigation { align-items: start; }
    .review-navigation > div { display: grid; }
    .proposal-grid { grid-template-columns: 95px 1fr; }
    .proposal-values { grid-template-columns: 1fr; }
    .form-actions { display: grid; }
    .removed-work-panel { align-items: stretch; flex-direction: column; }
}

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