@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=Space+Grotesk:wght@500;600;700&display=swap');

:root {
  --canvas: #f5f3ee;
  --surface: #fffefa;
  --surface-muted: #eceae3;
  --border: #e2ded4;
  --border-strong: #c9c1b4;
  --ink: #202321;
  --muted: #716f68;
  --subtle: #99958c;
  --teal: #0f5f72;
  --teal-deep: #0a485a;
  --teal-soft: #e0f1f3;
  --gold: #e6a14c;
  --green: #1d6f52;
  --green-soft: #e3f2e9;
  --amber: #a86118;
  --amber-soft: #faecd8;
  --red: #a63a3a;
  --red-soft: #fae5e3;
  --shadow: 0 18px 48px rgba(48, 42, 32, .07);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-width: 320px; background: var(--canvas); overflow-x: hidden; }
body { margin: 0; color: var(--ink); background: var(--canvas); font-family: 'DM Sans', 'Avenir Next', sans-serif; font-size: 15px; line-height: 1.5; overflow-x: hidden; }
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid rgba(230, 161, 76, .75); outline-offset: 3px; }

.app-shell { display: flex; min-height: 100vh; }
.sidebar { position: sticky; top: 0; width: 256px; height: 100vh; min-height: 100vh; max-height: 100vh; padding: 34px 20px 22px; display: flex; flex-direction: column; overflow-y: auto; background: #ebe9e2; border-right: 1px solid var(--border); }
.brand { display: inline-flex; align-items: center; gap: 11px; width: max-content; font-family: 'Space Grotesk', sans-serif; letter-spacing: -.03em; }
.brand-mark { display: grid; width: 34px; height: 34px; place-items: center; color: white; background: var(--teal); border-radius: 11px; font-size: 22px; font-weight: 700; transform: rotate(-8deg); }
.brand strong, .brand span span { display: block; }
.brand strong { font-size: 16px; line-height: 1.05; }
.brand span span { color: var(--muted); font-size: 13px; letter-spacing: -.01em; }
.sidebar-section-label { margin: 68px 12px 14px; color: var(--subtle); font-size: 11px; font-weight: 700; letter-spacing: .13em; text-transform: uppercase; }
.nav-list { display: grid; gap: 5px; }
.nav-item, .account-link { display: flex; align-items: center; gap: 12px; min-height: 46px; padding: 0 12px; border-radius: var(--radius-md); color: var(--muted); font-weight: 600; transition: .18s ease; }
.nav-item:hover, .account-link:hover { color: var(--ink); background: rgba(255,255,255,.55); }
.nav-item.is-active { color: var(--teal-deep); background: var(--teal-soft); }
.nav-icon { width: 20px; color: currentColor; font-size: 20px; text-align: center; }
.sidebar-footer { margin-top: auto; padding-top: 24px; }
.privacy-note { display: flex; align-items: flex-start; gap: 9px; margin: 0 5px 18px; padding: 14px 12px; color: var(--muted); background: rgba(255,255,255,.45); border: 1px solid rgba(226,222,212,.75); border-radius: var(--radius-md); font-size: 12px; }
.privacy-note strong, .privacy-note small { display: block; }
.privacy-note strong { margin-bottom: 2px; color: var(--ink); font-size: 12px; }
.privacy-note small { line-height: 1.35; }
.status-dot { width: 8px; height: 8px; margin-top: 5px; flex: 0 0 auto; background: var(--green); border-radius: 50%; box-shadow: 0 0 0 4px var(--green-soft); }
.account-link { padding: 8px 10px; color: var(--ink); }
.account-link > span:nth-child(2) { flex: 1; }
.avatar { display: grid; width: 30px; height: 30px; place-items: center; color: white; background: var(--teal-deep); border-radius: 50%; font-family: 'Space Grotesk', sans-serif; font-size: 12px; font-weight: 700; }
.avatar-small { width: 28px; height: 28px; }
.mobile-topbar { display: none; }
.nav-backdrop { display: none; }

.main-content { min-width: 0; flex: 1; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 24px; height: 92px; padding: 0 clamp(24px, 5vw, 72px); border-bottom: 1px solid var(--border); background: rgba(245,243,238,.82); }
.global-search { display: flex; align-items: center; gap: 11px; width: min(100%, 460px); height: 45px; padding: 0 13px; color: var(--muted); background: rgba(255,255,255,.7); border: 1px solid var(--border); border-radius: var(--radius-md); }
.global-search input { width: 100%; min-width: 0; color: var(--ink); background: transparent; border: 0; outline: 0; }
.global-search input::placeholder { color: var(--subtle); }
kbd { padding: 3px 7px; color: var(--subtle); background: var(--surface-muted); border: 1px solid var(--border); border-radius: 5px; font-size: 11px; white-space: nowrap; }
.topbar-actions { display: flex; align-items: center; gap: 20px; color: var(--muted); font-size: 13px; font-weight: 600; }
.household-label { display: flex; align-items: center; gap: 9px; white-space: nowrap; }
.icon-button { position: relative; display: inline-grid; width: 40px; height: 40px; place-items: center; color: var(--muted); background: transparent; border: 1px solid transparent; border-radius: var(--radius-md); font-size: 20px; }
.icon-button:hover { color: var(--ink); background: var(--surface); border-color: var(--border); }
.notification-dot { position: absolute; top: 8px; right: 8px; width: 6px; height: 6px; background: var(--gold); border: 2px solid var(--canvas); border-radius: 50%; }
.view { width: min(1180px, 100%); margin: 0 auto; padding: clamp(28px, 5vw, 60px) clamp(24px, 5vw, 72px) 80px; }
@keyframes view-enter { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.view.is-entering { animation: view-enter .26s ease both; }
@media (prefers-reduced-motion: reduce) { .view.is-entering { animation: none; } }

.eyebrow { margin: 0 0 9px; color: var(--teal); font-size: 12px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; }
h1, h2, h3, p { margin-top: 0; }
h1, h2, h3 { font-family: 'Space Grotesk', sans-serif; letter-spacing: -.04em; line-height: 1.15; }
h1 { margin-bottom: 12px; font-size: clamp(30px, 4vw, 44px); }
h2 { margin-bottom: 7px; font-size: 24px; }
h3 { margin-bottom: 6px; font-size: 17px; }
.lede { max-width: 620px; margin-bottom: 0; color: var(--muted); font-size: 16px; }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 34px; }
.page-heading > div:first-child { min-width: 0; }
.actions { display: flex; align-items: center; gap: 10px; }
.primary-button, .secondary-button, .text-button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 17px; border-radius: var(--radius-md); font-weight: 700; transition: .18s ease; }
.primary-button { color: white; background: var(--teal); border: 1px solid var(--teal); }
.primary-button:hover { background: var(--teal-deep); border-color: var(--teal-deep); transform: translateY(-1px); }
.secondary-button { color: var(--ink); background: var(--surface); border: 1px solid var(--border); }
.secondary-button:hover { border-color: var(--border-strong); background: white; }
.text-button { min-height: auto; padding: 6px 0; color: var(--teal); background: transparent; border: 0; }

.hero-grid { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(260px, .8fr); gap: 18px; margin-bottom: 42px; }
.hero-card { position: relative; overflow: hidden; min-height: 254px; padding: 32px; color: white; background: var(--teal-deep); border-radius: var(--radius-xl); }
.hero-card::after { position: absolute; right: -50px; bottom: -80px; width: 245px; height: 245px; border: 1px solid rgba(255,255,255,.16); border-radius: 50%; box-shadow: 0 0 0 26px rgba(255,255,255,.04), 0 0 0 52px rgba(255,255,255,.035); content: ''; }
.hero-card > * { position: relative; z-index: 1; }
.hero-card .eyebrow { color: #a9dce2; }
.hero-card h2 { max-width: 460px; margin-bottom: 13px; font-size: clamp(27px, 3.5vw, 38px); }
.hero-card p { max-width: 430px; margin-bottom: 28px; color: #d8edef; }
.hero-card .primary-button { color: var(--teal-deep); background: white; border-color: white; }
.hero-card .primary-button:hover { background: #eefafa; border-color: #eefafa; }
.stats-card { display: flex; flex-direction: column; justify-content: space-between; padding: 27px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-xl); }
.stats-card .stat-number { color: var(--teal-deep); font-family: 'Space Grotesk', sans-serif; font-size: 57px; font-weight: 700; line-height: 1; letter-spacing: -.08em; }
.stats-card .stat-caption { max-width: 150px; color: var(--muted); font-size: 14px; }
.stats-line { display: flex; align-items: center; justify-content: space-between; padding-top: 17px; border-top: 1px solid var(--border); color: var(--muted); font-size: 13px; }
.stats-line strong { color: var(--green); }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 16px; }
.section-heading h2 { margin-bottom: 0; font-size: 20px; }
.document-list { overflow: hidden; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.document-row { display: grid; grid-template-columns: minmax(0, 1fr) 140px 130px 36px; align-items: center; gap: 20px; min-height: 82px; padding: 14px 20px; border-bottom: 1px solid var(--border); }
.document-row:last-child { border-bottom: 0; }
.document-row:hover { background: #fff; }
.doc-main { display: flex; align-items: center; gap: 13px; min-width: 0; }
.file-icon { display: grid; width: 40px; height: 44px; place-items: center; flex: 0 0 auto; color: var(--teal); background: var(--teal-soft); border-radius: 9px; font-size: 20px; overflow: hidden; }
.document-thumbnail img { display: block; width: 100%; height: 100%; object-fit: cover; }
.doc-main strong, .doc-main small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-main strong { margin-bottom: 3px; font-size: 14px; }
.doc-main small, .doc-meta, .doc-meta small { color: var(--muted); font-size: 12px; }
.doc-meta strong, .doc-meta small { display: block; }
.doc-meta strong { color: var(--ink); font-size: 12px; }
.doc-meta { white-space: nowrap; }
.status-badge { display: inline-flex; align-items: center; width: max-content; gap: 6px; padding: 5px 8px; border-radius: 6px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.status-badge::before { width: 6px; height: 6px; background: currentColor; border-radius: 50%; content: ''; }
.status-ready { color: var(--green); background: var(--green-soft); }
.status-processing { color: var(--amber); background: var(--amber-soft); }
.status-failed { color: var(--red); background: var(--red-soft); }
.row-menu { display: grid; width: 34px; height: 34px; place-items: center; color: var(--muted); background: transparent; border: 0; border-radius: 8px; font-size: 20px; }
.row-menu:hover { color: var(--ink); background: var(--surface-muted); }

.results-summary { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 2px 2px 16px; color: var(--muted); font-size: 13px; }
.results-summary .text-button { min-height: auto; padding: 0; }
.year-group { margin-bottom: 26px; }
.year-group:last-child { margin-bottom: 0; }
.year-group-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin: 0 2px 12px; }
.year-group-head h2 { margin: 0; font-size: 18px; }
.year-group-head span { color: var(--subtle); font-size: 12px; font-weight: 600; }
.reset-inline { margin-top: 18px; }

.filter-bar { display: flex; align-items: center; gap: 8px; margin: 0 0 18px; overflow-x: auto; scrollbar-width: none; }
.filter-bar::-webkit-scrollbar { display: none; }
.filter-chip { min-height: 34px; padding: 0 13px; color: var(--muted); background: transparent; border: 1px solid var(--border); border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.filter-chip.is-active, .filter-chip:hover { color: var(--teal-deep); background: var(--teal-soft); border-color: #b6d9dc; }
.year-bar { display: flex; align-items: center; gap: 8px; margin: 0 0 12px; overflow-x: auto; scrollbar-width: none; }
.year-label { margin-right: 4px; color: var(--muted); font-size: 12px; font-weight: 700; white-space: nowrap; }
.year-chip { min-height: 34px; padding: 0 13px; color: var(--muted); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.year-chip.is-active, .year-chip:hover { color: var(--teal-deep); background: var(--teal-soft); border-color: #b6d9dc; }

.capture-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 18px; }
.capture-panel { padding: clamp(24px, 4vw, 44px); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-xl); }
.capture-dropzone { display: grid; min-height: 300px; place-items: center; padding: 28px; text-align: center; background: #faf9f5; border: 1px dashed var(--border-strong); border-radius: var(--radius-lg); transition: .18s ease; }
.capture-dropzone.is-dragging { background: var(--teal-soft); border-color: var(--teal); }
.capture-symbol { display: grid; width: 64px; height: 64px; margin: 0 auto 18px; place-items: center; color: var(--teal); background: var(--teal-soft); border-radius: 18px; font-size: 31px; }
.capture-dropzone h2 { margin-bottom: 8px; font-size: 24px; }
.capture-dropzone p { max-width: 380px; margin-bottom: 20px; color: var(--muted); }
.capture-options { display: grid; gap: 11px; margin-top: 20px; }
.capture-option { display: flex; align-items: center; gap: 14px; padding: 15px; text-align: left; background: white; border: 1px solid var(--border); border-radius: var(--radius-md); }
.capture-option:hover { border-color: var(--teal); background: #fcffff; }
.capture-option-icon { display: grid; width: 36px; height: 36px; place-items: center; color: var(--teal); background: var(--teal-soft); border-radius: 10px; font-size: 19px; }
.capture-option strong, .capture-option small { display: block; }
.capture-option strong { margin-bottom: 1px; font-size: 14px; }
.capture-option small { color: var(--muted); font-size: 12px; }
.guide-card { padding: 24px; background: #eeece5; border-radius: var(--radius-lg); }
.guide-card h3 { font-size: 18px; }
.guide-list { display: grid; gap: 16px; margin: 20px 0 0; padding: 0; list-style: none; }
.guide-list li { display: grid; grid-template-columns: 24px 1fr; gap: 10px; color: var(--muted); font-size: 13px; }
.guide-list li::before { display: grid; width: 22px; height: 22px; place-items: center; color: var(--teal); background: var(--teal-soft); border-radius: 50%; content: '✓'; font-size: 11px; font-weight: 700; }
.upload-note { display: none; margin-top: 15px; padding: 12px; color: var(--green); background: var(--green-soft); border-radius: var(--radius-md); font-size: 13px; }
.upload-note.is-visible { display: block; }

.search-panel { max-width: 850px; margin-bottom: 25px; padding: 10px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.search-panel-inner { display: flex; align-items: center; gap: 12px; min-height: 58px; padding: 0 14px; background: #faf9f5; border-radius: var(--radius-md); }
.search-panel-inner span { color: var(--teal); font-size: 25px; }
.search-panel-inner input { width: 100%; color: var(--ink); background: transparent; border: 0; outline: 0; font-size: 17px; }
.search-panel-inner input::placeholder { color: var(--subtle); }
.search-helper { color: var(--muted); font-size: 12px; }
.search-results-label { margin: 26px 0 11px; color: var(--muted); font-size: 13px; }
.empty-search { padding: 45px 24px; text-align: center; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.empty-search strong, .empty-search span { display: block; }
.empty-search strong { margin-bottom: 5px; font-family: 'Space Grotesk', sans-serif; font-size: 19px; }
.empty-search span { color: var(--muted); }

.detail-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 18px; }
.back-link { display: inline-flex; align-items: center; gap: 7px; margin-bottom: 25px; color: var(--muted); font-size: 13px; font-weight: 700; }
.back-link:hover { color: var(--teal); }
.preview-card { min-height: 480px; padding: clamp(18px, 4vw, 34px); display: grid; grid-template-columns: 86px minmax(0, 1fr); gap: 14px; align-items: start; background: #eae7df; border: 1px solid var(--border); border-radius: var(--radius-xl); }
.page-edit-bar { grid-column: 1; grid-row: 1; display: grid; width: 86px; gap: 9px; align-content: start; }
.page-edit-bar > .compact-button { width: 100%; padding: 0 6px; font-size: 11px; }
.preview-workspace > [data-page-edit-summary] { display: grid; gap: 8px; margin-bottom: 2px; padding: 12px 14px; color: var(--muted); background: rgba(255,254,250,.82); border: 1px solid var(--border); border-radius: var(--radius-md); font-size: 13px; line-height: 1.4; }
.preview-workspace > [data-page-edit-summary] strong { color: var(--ink); font-size: 15px; }
.page-edit-actions { display: grid; gap: 5px; margin-top: 5px; }
.page-edit-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.page-edit-actions .compact-button { width: auto; }
.page-rail { grid-column: 1; grid-row: 2; display: grid; align-content: start; gap: 8px; max-height: 515px; overflow-y: auto; padding: 0; }
.preview-card > .preview-workspace { grid-column: 2; grid-row: 1 / span 2; }
.page-thumb { display: grid; gap: 5px; min-height: 82px; padding: 8px; color: var(--muted); background: rgba(255,254,250,.66); border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 11px; font-weight: 700; text-align: center; }
.page-thumb:hover, .page-thumb.is-active { color: var(--teal-deep); background: white; border-color: var(--teal); }
.page-thumb span { display: grid; min-height: 48px; place-items: center; color: var(--teal); background: #f5f3ee; border-radius: 6px; font-size: 18px; overflow: hidden; }
.page-thumb img { display: block; width: 100%; height: 48px; object-fit: cover; }
.page-edit-unit { display: grid; gap: 6px; }
.page-edit-thumb { position: relative; }
.page-edit-thumb .page-thumb { width: 100%; }
.page-edit-thumb.is-selected .page-thumb { color: var(--red); border-color: var(--red); background: var(--red-soft); }
.page-delete-tool { position: absolute; top: 4px; right: 4px; display: grid; width: 22px; height: 22px; padding: 0; place-items: center; color: var(--red); background: var(--surface); border: 1px solid var(--red); border-radius: 50%; font-size: 15px; line-height: 1; cursor: pointer; }
.page-delete-tool.is-active { color: var(--green); border-color: var(--green); }
.page-gap-tool { position: relative; display: grid; min-width: 28px; min-height: 82px; padding: 0; place-items: center; color: var(--muted); background: transparent; border: 0; cursor: pointer; }
.page-gap-tool::before { content: ''; position: absolute; inset: 0 50% 0 auto; border-right: 2px dashed var(--border-strong); }
.page-gap-tool span { position: relative; z-index: 1; display: grid; width: 24px; height: 24px; place-items: center; color: var(--teal); background: var(--canvas); border: 1px solid var(--teal); border-radius: 50%; font-size: 17px; font-weight: 700; }
.page-gap-tool:hover span, .page-gap-tool.is-active span { color: white; background: var(--teal); }
.preview-workspace { display: grid; grid-template-rows: auto minmax(0, 1fr); min-width: 0; gap: 14px; }
.preview-toolbar, .search-hit-nav { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; color: var(--muted); font-size: 12px; font-weight: 700; }
.compact-button { min-height: 36px; padding: 0 12px; font-size: 12px; }
.compact-button.is-disabled { opacity: .48; pointer-events: none; }
.search-hit-nav > div { display: flex; gap: 7px; min-width: 0; overflow-x: auto; }
.hit-chip { display: inline-flex; align-items: center; min-height: 32px; padding: 0 10px; color: var(--muted); background: rgba(255,254,250,.72); border: 1px solid var(--border); border-radius: 999px; white-space: nowrap; }
.hit-chip.is-active, .hit-chip:hover { color: var(--teal-deep); background: var(--teal-soft); border-color: #b6d9dc; }
.document-preview { display: grid; min-height: 410px; place-items: center; padding: 26px; background: rgba(255,254,250,.32); border: 1px solid rgba(201,193,180,.7); border-radius: var(--radius-lg); }
.original-frame, .original-image { width: min(100%, 520px); height: 410px; background: white; border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: 0 17px 35px rgba(70,60,45,.1); }
.original-frame { display: block; }
.original-image { object-fit: contain; }
.preview-sheet { width: min(100%, 420px); min-height: 360px; padding: 32px; background: #fffefa; box-shadow: 0 17px 35px rgba(70,60,45,.1); }
.preview-kicker { margin-bottom: 18px; color: var(--teal); font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
.preview-sheet h3 { margin-bottom: 22px; font-size: 20px; }
.preview-text-line { display: block; min-height: 13px; margin-bottom: 13px; padding-bottom: 7px; color: var(--muted); border-bottom: 1px solid #ebe7dd; font-size: 13px; }
.preview-text-line.is-emphasis { width: 82%; color: var(--ink); border-bottom-color: var(--teal); border-bottom-width: 3px; font-weight: 700; }
.preview-stamp { width: max-content; margin-top: 36px; padding: 7px 10px; color: var(--green); background: var(--green-soft); border-radius: 7px; font-size: 11px; font-weight: 700; }
.detail-sidebar { padding: 25px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-xl); }
.mutation-controls { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--border); }
.mutation-controls .detail-actions { display: grid; gap: 8px; }
.mutation-panel { margin-top: 18px; padding: 16px; background: #f7fbfa; border: 1px solid #bddcda; border-radius: var(--radius-md); }
.mutation-panel.is-destructive { background: #fff9f5; border-color: #ebc8b4; }
.mutation-panel h3 { margin-bottom: 5px; }
.mutation-panel p { color: var(--muted); font-size: 12px; }
.mutation-field { display: grid; gap: 6px; margin: 15px 0; color: var(--muted); font-size: 12px; font-weight: 700; }
.mutation-field select { min-height: 38px; padding: 0 10px; color: var(--ink); background: white; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.boundary-preview { display: grid; grid-template-columns: minmax(0, 1fr) 150px minmax(0, 1fr); gap: 12px; align-items: center; margin: 16px 0; }
.boundary-page { margin: 0; padding: 8px; background: white; border: 1px solid var(--border); border-radius: var(--radius-sm); text-align: center; }
.boundary-page img { display: block; width: 100%; max-height: 190px; object-fit: contain; cursor: zoom-in; }
.boundary-page img.is-expanded { position: fixed; z-index: 20; inset: 10vh 10vw; width: 80vw; height: 80vh; max-height: none; padding: 20px; background: var(--surface); border: 1px solid var(--border); box-shadow: 0 12px 36px rgba(0, 0, 0, .25); object-fit: contain; cursor: zoom-out; }
.boundary-page figcaption { margin-top: 6px; color: var(--muted); font-size: 12px; font-weight: 700; }
.boundary-gap { display: grid; gap: 8px; color: var(--muted); font-size: 12px; font-weight: 700; text-align: center; }
.boundary-gap select { min-height: 36px; padding: 0 8px; color: var(--ink); background: white; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.boundary-gap strong { color: var(--teal); }
.mutation-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.page-selection { display: grid; gap: 7px; max-height: 180px; margin: 15px 0; overflow: auto; }
.page-selection label { display: flex; align-items: center; gap: 9px; min-height: 72px; padding: 6px 9px; color: var(--ink); background: white; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 12px; font-weight: 700; }
.page-selection label:has(input:checked) { border-color: var(--red); background: #fff1eb; }
.page-selection input { accent-color: var(--red); }
.page-selection img { width: 48px; height: 58px; object-fit: cover; border: 1px solid var(--border); border-radius: 4px; }
.selection-summary { margin-bottom: 13px; }
.recovery-notice { display: grid; gap: 7px; margin: 18px 0 0; color: var(--green); background: var(--green-soft); }
.recovery-notice span { color: var(--muted); }
.recovery-notice .secondary-button { width: max-content; }
.detail-sidebar h2 { font-size: 21px; }
@media (max-width: 680px) { .boundary-preview { grid-template-columns: 1fr; } .boundary-gap { order: 2; } .boundary-page:last-child { order: 3; } }
.detail-meta { display: grid; gap: 0; margin: 24px 0; }
.detail-meta-row { display: flex; justify-content: space-between; gap: 15px; padding: 12px 0; border-bottom: 1px solid var(--border); color: var(--muted); font-size: 12px; }
.detail-meta-row strong { color: var(--ink); text-align: right; font-size: 12px; }
.processing-callout { margin: 0 0 20px; padding: 13px; color: var(--amber); background: var(--amber-soft); border-radius: var(--radius-md); font-size: 12px; }
.processing-callout.is-failed { color: var(--red); background: var(--red-soft); }
.processing-callout strong { display: block; margin-bottom: 3px; color: var(--ink); font-size: 13px; }
.action-callout { margin: 0 0 20px; padding: 14px; color: var(--muted); background: var(--teal-soft); border-radius: var(--radius-md); font-size: 12px; }
.action-callout strong:first-child { display: block; margin-bottom: 6px; color: var(--ink); font-size: 13px; }
.action-callout span { display: flex; justify-content: space-between; gap: 12px; margin-top: 6px; }
.action-callout span strong { color: var(--ink); }
.detail-notes { margin: 0 0 24px; }
.detail-notes ul { margin: 8px 0 0; padding-left: 18px; color: var(--muted); font-size: 12px; }
.detail-notes li { margin-bottom: 6px; }
.detail-meta-row.is-editable { align-items: baseline; }
.detail-meta-row.is-editable strong { flex: 1; }
.detail-meta-row.is-editable button { flex: none; font-size: 11px; }
.detail-meta-row strong em { color: var(--muted); font-weight: 400; }
.detail-flag { display: block; margin-top: 3px; font-size: 10px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.detail-flag.is-uncertain { color: var(--amber); }
.detail-flag.is-edited { color: var(--green); }
.metadata-edit { display: flex; flex: 1; gap: 6px; justify-content: flex-end; align-items: center; flex-wrap: wrap; }
.metadata-edit input, .metadata-edit select { min-width: 0; flex: 1 1 120px; padding: 6px 8px; border: 1px solid var(--border); border-radius: var(--radius-md); font: inherit; font-size: 12px; }
.detail-actions { display: grid; gap: 9px; }
.detail-actions button { width: 100%; }

.auth-root { display: grid; place-items: center; min-height: 100vh; padding: 32px 20px; background: radial-gradient(120% 120% at 50% 0%, var(--teal-soft) 0%, var(--canvas) 55%); }
.auth-card { width: min(100%, 400px); padding: 36px 32px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-xl); box-shadow: var(--shadow); }
.auth-brand { display: flex; align-items: center; gap: 11px; margin-bottom: 26px; }
.auth-brand strong { display: block; font-family: 'Space Grotesk', sans-serif; font-size: 16px; }
.auth-brand small { color: var(--muted); font-size: 12px; }
.auth-card h1 { margin: 0 0 6px; font-size: 27px; }
.auth-lede { margin: 0 0 24px; color: var(--muted); font-size: 14px; }
.auth-form { display: grid; gap: 15px; }
.auth-field { display: grid; gap: 6px; font-size: 12px; font-weight: 700; color: var(--muted); }
.auth-field input { min-height: 46px; padding: 0 14px; color: var(--ink); background: var(--canvas); border: 1px solid var(--border); border-radius: var(--radius-md); }
.auth-field input:focus { outline: none; border-color: var(--teal); background: white; }
.auth-error { margin: 0; padding: 11px 13px; color: var(--red); background: var(--red-soft); border-radius: var(--radius-md); font-size: 13px; }
.auth-submit { width: 100%; margin-top: 4px; }
.auth-submit:disabled { opacity: .7; cursor: default; }
.auth-switch { margin: 22px 0 0; color: var(--muted); font-size: 13px; text-align: center; }
.auth-switch .text-button { min-height: auto; padding: 0; font-size: 13px; }

.toast { position: fixed; right: 24px; bottom: 24px; z-index: 10; max-width: 340px; padding: 13px 16px; color: white; background: var(--ink); border-radius: var(--radius-md); box-shadow: var(--shadow); opacity: 0; transform: translateY(10px); pointer-events: none; transition: .22s ease; }
.toast.is-visible { opacity: 1; transform: translateY(0); }

@media (max-width: 850px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    position: fixed;
    top: 0; bottom: 0; left: 0;
    z-index: 40;
    width: min(82vw, 300px);
    min-height: 100vh;
    transform: translateX(-100%);
    transition: transform .24s ease;
    box-shadow: var(--shadow);
  }
  .sidebar.is-open { transform: translateX(0); }
  .nav-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 39;
    background: rgba(20, 18, 14, .42);
    opacity: 0;
    pointer-events: none;
    transition: opacity .24s ease;
  }
  .nav-backdrop.is-open { opacity: 1; pointer-events: auto; }
  .mobile-topbar { display: flex; align-items: center; justify-content: space-between; width: 100%; height: 68px; padding: 0 20px; background: var(--canvas); border-bottom: 1px solid var(--border); }
  .mobile-topbar .brand-mark { width: 30px; height: 30px; font-size: 19px; }
  .mobile-topbar .brand strong { font-size: 14px; }
  .mobile-topbar .brand span span { font-size: 11px; }
  .icon-button { width: 44px; height: 44px; }
  .topbar { height: 76px; padding: 0 20px; }
  .topbar-actions { gap: 4px; }
  .household-label { display: none; }
  .view { padding: 30px 20px 72px; }
  .hero-grid, .capture-layout, .detail-layout { grid-template-columns: 1fr; }
  .preview-card { grid-template-columns: 86px minmax(0, 1fr); }
  .page-edit-bar { grid-column: 1; grid-row: 1; }
  .page-rail { grid-column: 1; grid-row: 2; display: grid; max-height: 515px; overflow-y: auto; padding: 0; }
  .preview-card > .preview-workspace { grid-column: 2; grid-row: 1 / span 2; }
  .stats-card { min-height: 170px; }
  .guide-card { order: -1; }
}

@media (max-width: 620px) {
  .topbar { padding: 0 16px; }
  .global-search { width: 100%; }
  .topbar-actions { display: none; }
  .view { padding: 28px 16px 70px; }
  .page-heading { display: block; margin-bottom: 26px; }
  .page-heading .actions { margin-top: 20px; }
  .page-heading .actions .secondary-button { display: none; }
  h1 { font-size: 32px; }
  .hero-card { min-height: 275px; padding: 25px; }
  .hero-card h2 { font-size: 29px; }
  .document-row { grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: auto auto; column-gap: 10px; row-gap: 9px; align-items: center; padding: 13px 14px; }
  .doc-main { grid-column: 1; grid-row: 1; }
  .row-menu { grid-column: 2; grid-row: 1; align-self: start; }
  .doc-meta { grid-column: 1; grid-row: 2; display: flex; align-items: center; gap: 8px; white-space: normal; }
  .doc-meta strong, .doc-meta small { display: inline; }
  .doc-meta small::before { margin-right: 8px; color: var(--subtle); content: ''; }
  .status-badge { grid-column: 2; grid-row: 2; justify-self: end; }
  .capture-panel { padding: 16px; }
  .capture-dropzone { min-height: 260px; }
  .search-panel-inner { min-height: 52px; }
  .search-helper { display: none; }
  .preview-card { min-height: 390px; padding: 16px; }
  .preview-toolbar, .search-hit-nav { align-items: flex-start; flex-direction: column; }
  .document-preview { min-height: 330px; padding: 16px; }
  .preview-sheet { min-height: 300px; padding: 24px; }
  .toast { right: 16px; bottom: 16px; left: 16px; max-width: none; }
}

@media (max-width: 680px) {
  .preview-card { grid-template-columns: 1fr; }
  .page-edit-bar, .page-rail, .preview-card > .preview-workspace { grid-column: 1; }
  .page-edit-bar { grid-row: 1; }
  .page-rail { grid-row: 2; display: flex; max-height: none; overflow-x: auto; padding: 0 0 2px; }
  .preview-card > .preview-workspace { grid-row: 3; }
  .page-thumb { min-width: 74px; }
}
