/* Archive Structure Workbench - Styles */

:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary: #6b7280;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --bg: #f9fafb;
    --bg-secondary: #f3f4f6;
    --text: #111827;
    --foreground: #111827;
    --accent: #2563eb;
    --border: #e5e7eb;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

.debug-ui [data-ui-id] { outline: 2px dashed rgba(156, 39, 176, .7); outline-offset: -2px; position: relative; }
.debug-ui .ui-debug-label { position: absolute; z-index: 20; top: 0; left: 0; padding: .1rem .3rem; background: #6a1b9a; color: #fff; font: 600 10px/1.2 monospace; pointer-events: none; }

/* Navbar */
.navbar {
    background: #fff;
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 1.5rem;
}

.nav-container {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.nav-brand {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--primary);
    text-decoration: none;
}

.nav-links a {
    margin-left: 1.5rem;
    color: var(--secondary);
    text-decoration: none;
    font-size: 0.9rem;
}

.nav-links a:hover, .nav-links a.active {
    color: var(--primary);
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 1.25rem;
}

.nav-links a { margin-left: 0; }

.user-menu { position: relative; }
.user-menu summary {
    color: var(--secondary);
    font-size: 0.9rem;
    cursor: pointer;
    list-style: none;
}
.user-menu summary::-webkit-details-marker { display: none; }
.user-menu summary::after { content: " ▾"; }
.user-menu-panel {
    position: absolute;
    right: 0;
    z-index: 20;
    min-width: 180px;
    margin-top: 0.5rem;
    padding: 0.5rem;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
}
.user-menu-panel a { display: block; padding: 0.5rem 0.75rem; }

/* Main content */
.main-content {
    max-width: 1200px;
    margin: 2rem auto;
    padding: 0 1.5rem;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    text-decoration: none;
    font-size: 0.9rem;
    cursor: pointer;
    border: 1px solid transparent;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover { background: var(--primary-hover); }

.btn-secondary {
    background: #fff;
    color: var(--secondary);
    border-color: var(--border);
}

.btn-secondary:hover { background: var(--bg); }

.btn-sm {
    padding: 0.25rem 0.5rem;
    font-size: 0.8rem;
}

/* Stats grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin: 1.5rem 0;
}

.stat-card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    text-align: center;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary);
}

.stat-label {
    font-size: 0.85rem;
    color: var(--secondary);
}

/* Data tables */
.data-table {
    width: 100%;
    border-collapse: collapse;
    margin: 1rem 0;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}

.data-table th {
    background: var(--bg);
    padding: 0.75rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.85rem;
    border-bottom: 1px solid var(--border);
}

.data-table td {
    padding: 0.75rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}

.data-table tr:last-child td { border-bottom: none; }

/* Forms */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.25rem;
    font-weight: 500;
    font-size: 0.9rem;
}

.form-group input[type="text"],
.form-group input[type="password"],
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.9rem;
}

/* Login */
.login-container {
    max-width: 400px;
    margin: 4rem auto;
    background: #fff;
    padding: 2rem;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.login-container h1 {
    text-align: center;
    margin-bottom: 1.5rem;
}

/* Maintainer diagnostics */
.diagnostics-card {
    background: #111827;
    border: 1px solid #374151;
    border-radius: 8px;
    padding: 1rem;
    overflow-x: auto;
}

.diagnostics-json {
    color: #d1fae5;
    font: 0.82rem/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
    margin: 0;
    white-space: pre-wrap;
}

.diagnostics-card h2, .diagnostics-card h3 { color: #f9fafb; margin-top: 0; }
.diagnostics-card p, .diagnostics-card dd, .diagnostics-card li { color: #d1d5db; }
.diagnostics-card a { color: #93c5fd; }
.diagnostics-timeline, .diagnostics-evidence-list { margin: 0; padding-left: 1.5rem; }
.diagnostics-timeline > li, .diagnostics-evidence-list > li { border-left: 2px solid #4b5563; margin: 0 0 1rem; padding: 0 0 0.5rem 1rem; }
.diagnostics-timeline-heading { display: flex; justify-content: space-between; gap: 1rem; color: #f9fafb; }
.diagnostics-timeline time, .diagnostics-evidence-list small { color: #9ca3af; font-size: 0.78rem; }
.diagnostics-evidence-list span { display: inline-block; margin: 0.35rem 0; white-space: pre-wrap; }
.diagnostics-evidence-list small { display: block; }
.diagnostics-facts { display: grid; grid-template-columns: minmax(10rem, 18rem) 1fr; gap: 0.5rem 1rem; }
.diagnostics-facts dt { color: #9ca3af; }
.diagnostics-facts dd { margin: 0; }
.diagnostics-reasoning { color: #fde68a; font: 0.85rem/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; max-height: 42rem; overflow: auto; }
.diagnostics-tool-events { padding-left: 1.25rem; }
.diagnostics-raw summary { cursor: pointer; color: #f9fafb; }
.diagnostics-raw summary h2 { display: inline; }

/* Actions */
.actions {
    margin: 1.5rem 0;
    display: flex;
    gap: 0.5rem;
}

/* Messages */
.message {
    padding: 0.75rem 1rem;
    border-radius: 6px;
    margin-bottom: 0.5rem;
}

.message-success { background: #dcfce7; color: #166534; }
.message-error { background: #fee2e2; color: #991b1b; }
.message-warning { background: #fef3c7; color: #92400e; }

/* Guidelines */
.guidelines section {
    margin: 1.5rem 0;
    padding: 1rem;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
}

.guidelines h2 {
    font-size: 1.2rem;
    margin-bottom: 0.5rem;
}

.guidelines ul {
    margin-left: 1.5rem;
}

.guidelines li {
    margin-bottom: 0.25rem;
}

/* Sections */
h1 { margin-bottom: 1rem; }
h2 { margin: 1.5rem 0 0.5rem; font-size: 1.2rem; }
h3 { margin: 1rem 0 0.5rem; font-size: 1.1rem; }
h4 { margin: 0.75rem 0 0.5rem; font-size: 1rem; }

/* Footer */
.footer {
    margin-top: 3rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border);
    text-align: center;
    font-size: 0.8rem;
    color: var(--secondary);
}

.footer-container {
    max-width: 1200px;
    margin: 0 auto;
}

/* Read-only document workspace */
.workspace { max-width: 1400px; margin: 0 auto; }
.workspace-header { display: flex; justify-content: space-between; align-items: start; gap: 1.5rem; margin-bottom: 1.5rem; }
.workspace-header h1 { overflow-wrap: anywhere; margin-bottom: .25rem; }
.workspace-meta { display: inline-block; margin-left: .5rem; color: var(--secondary); }
.workspace-grid { display: grid; grid-template-columns: 150px minmax(360px, 1fr) minmax(300px, .8fr); gap: 1rem; align-items: start; }
.workspace-pages, .workspace-scan, .workspace-content { background: #fff; border: 1px solid var(--border); border-radius: 10px; min-width: 0; }
.workspace-panel-heading { display: flex; justify-content: space-between; align-items: center; padding: .8rem 1rem; border-bottom: 1px solid var(--border); }
.workspace-panel-heading h2 { margin: 0; font-size: 1rem; }
.workspace-panel-heading span { color: var(--secondary); font-size: .8rem; }
.scan-navigation { display: flex; align-items: center; gap: .55rem; font-size: .8rem; }
.scan-navigation a { color: var(--primary); text-decoration: none; font-size: 1.1rem; line-height: 1; }
.scan-toolbar { display: flex; align-items: center; justify-content: center; gap: .45rem; padding: .55rem; border-bottom: 1px solid var(--border); }
.scan-toolbar span { min-width: 3.5rem; text-align: center; color: var(--secondary); font-size: .8rem; }
.page-list { max-height: 72vh; overflow-y: auto; padding: .5rem; }
.page-list-item { display: block; position: relative; color: var(--text); text-decoration: none; padding: .35rem; margin-bottom: .4rem; border: 2px solid transparent; border-radius: 7px; font-size: .78rem; }
.page-list-item:hover, .page-list-item.is-selected { border-color: var(--primary); background: #eff6ff; }
.page-list-item img { display: block; width: 100%; aspect-ratio: 3 / 4; object-fit: contain; background: #f3f4f6; margin-bottom: .25rem; }
.page-number { position: absolute; z-index: 1; top: .45rem; left: .45rem; padding: 0 .25rem; background: rgba(255,255,255,.9); border-radius: 3px; font-weight: 700; }
.scan-viewport { max-height: 72vh; overflow: auto; padding: 1rem; background: #e5e7eb; touch-action: none; cursor: grab; }
.scan-viewport:active { cursor: grabbing; }
.scan-stage { position: relative; width: max-content; max-width: 100%; margin: 0 auto; line-height: 0; will-change: transform; }
.scan-stage img { display: block; max-width: 100%; max-height: 68vh; width: auto; height: auto; }
.region-overlay { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; z-index: 3; }
.region-hit-layer { position: absolute; inset: 0; z-index: 2; }
.region-hit { position: absolute; display: block; overflow: hidden; color: transparent; text-indent: -9999px; border: 1px solid transparent; border-radius: 2px; }
.region-hit:hover, .region-hit:focus { border-color: #d97706; background: rgba(245,158,11,.12); outline: none; }
.region-link { cursor: pointer; }
.region-box { fill: rgba(37,99,235,.08); stroke: rgba(37,99,235,.7); stroke-width: .003; vector-effect: non-scaling-stroke; transition: fill .15s, stroke .15s; }
.region-box:hover, .region-box:focus, .region-box.is-selected { fill: rgba(245,158,11,.25); stroke: #d97706; stroke-width: .006; }
.region-box.is-suppressed { fill: rgba(107,114,128,.04); stroke: #9ca3af; stroke-dasharray: .01 .008; opacity: .5; }
.region-hit.is-suppressed { opacity: .45; }
.scan-legend { padding: .65rem 1rem; color: var(--secondary); font-size: .8rem; }
.region-filters { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; padding: .6rem 1rem 0; }
.filter-label { color: var(--secondary); font-size: .78rem; margin-right: .15rem; }
.filter-button { border: 1px solid var(--border); border-radius: 999px; padding: .2rem .55rem; background: #fff; color: var(--secondary); font-size: .72rem; cursor: pointer; }
.filter-button:hover, .filter-button.is-active { border-color: var(--primary); color: var(--primary); background: #eff6ff; }
.filter-button span { font-variant-numeric: tabular-nums; }
.legend-swatch { display: inline-block; width: .7rem; height: .7rem; margin-right: .3rem; vertical-align: -.05rem; border: 1px solid var(--primary); background: rgba(37,99,235,.12); }
.workspace-content { max-height: 76vh; overflow-y: auto; }
.region-detail, .page-text, .page-tables { padding: 1rem; border-bottom: 1px solid var(--border); }
.region-detail { background: #fffbeb; }
.region-detail-heading { display: flex; justify-content: space-between; gap: .5rem; align-items: center; color: var(--secondary); font-size: .78rem; }
.region-type-badge { color: #92400e; font-weight: 700; }
.region-text { margin: .75rem 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.technical-summary, .technical-details { display: grid; gap: .4rem; font-size: .8rem; }
.technical-summary div, .technical-details div { display: flex; justify-content: space-between; gap: .75rem; }
.technical-summary dt, .technical-details dt { color: var(--secondary); }
.technical-summary dd, .technical-details dd { text-align: right; overflow-wrap: anywhere; }
.region-detail details { margin-top: .8rem; font-size: .8rem; }
.page-text h3, .page-tables h3 { margin: 0 0 .6rem; font-size: .95rem; }
.page-text pre { white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; font-size: .9rem; }
.table-result { margin-top: .5rem; border: 1px solid var(--border); border-radius: 6px; padding: .45rem .6rem; font-size: .82rem; }
.table-result summary { cursor: pointer; color: var(--primary); }
.table-preview { overflow-x: auto; margin-top: .6rem; }
.table-preview table { border-collapse: collapse; width: 100%; font-size: .78rem; }
.table-preview td, .table-preview th { border: 1px solid var(--border); padding: .3rem .4rem; text-align: left; }
.empty-state { color: var(--secondary); padding: 1rem; }

/* Evidence-grounded research workspace */
.chat-workspace { max-width: 1500px; margin: 0 auto; }
.chat-page-header { align-items: end; }
.eyebrow { color: var(--primary); font-size: .75rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; margin-bottom: .25rem; }
.chat-shell { display: grid; grid-template-columns: 230px minmax(0, 1fr) minmax(320px, 380px); gap: 1rem; align-items: stretch; height: min(760px, calc(100vh - 190px)); min-height: 560px; }
.chat-sessions, .chat-panel, .chat-context { background: #fff; border: 1px solid var(--border); border-radius: 10px; min-width: 0; }
.chat-sessions, .chat-context { padding: .8rem; }
.chat-sidebar-heading, .chat-panel-header { display: flex; justify-content: space-between; align-items: center; gap: .75rem; }
.chat-sidebar-heading { padding: .25rem .2rem .65rem; border-bottom: 1px solid var(--border); }
.chat-sidebar-heading h2 { margin: 0; font-size: .95rem; }
.chat-sidebar-heading span { color: var(--secondary); font-size: .78rem; }
.chat-session-list { display: grid; gap: .35rem; padding-top: .65rem; }
.chat-session { display: block; padding: .65rem; border-radius: 7px; color: var(--text); text-decoration: none; }
.chat-session:hover, .chat-session.is-selected { background: #eff6ff; color: var(--primary); }
.chat-session strong, .chat-session small, .chat-document-list strong, .chat-document-list small, .chat-evidence-list small { display: block; overflow-wrap: anywhere; }
.chat-session small, .chat-document-list small, .chat-evidence-list small { color: var(--secondary); font-size: .72rem; margin-top: .15rem; }
.chat-panel { display: flex; flex-direction: column; overflow: hidden; }
.chat-panel-header { padding: 1rem 1.2rem; border-bottom: 1px solid var(--border); }
.chat-panel-header h2 { margin: 0; font-size: 1.05rem; }
.chat-panel-header span { color: var(--secondary); font-size: .78rem; }
.chat-status-label { color: #166534 !important; background: #dcfce7; border-radius: 999px; padding: .2rem .5rem; white-space: nowrap; }
.chat-messages { flex: 1; padding: 1rem; overflow-y: auto; min-height: 0; overscroll-behavior: contain; }
.chat-message { max-width: 86%; margin-bottom: .9rem; padding: .8rem 1rem; border-radius: 9px; border: 1px solid var(--border); }
.chat-message-user { margin-left: auto; background: #eff6ff; border-color: #bfdbfe; }
.chat-message-assistant { background: #f9fafb; }
.message-role { color: var(--secondary); font-size: .72rem; font-weight: 700; margin-bottom: .3rem; }
.message-body p { margin: 0 0 .45rem; }
.message-body p:last-child { margin-bottom: 0; }
.chat-citation { display: inline-block; margin: 0 .08rem; padding: 0 .22rem; border-radius: 4px; background: #dbeafe; color: #1d4ed8; font-weight: 700; text-decoration: none; }
.chat-citation:hover, .chat-citation:focus { background: #bfdbfe; text-decoration: underline; }
.chat-question-form { position: sticky; bottom: 0; display: flex; gap: .6rem; align-items: end; padding: .9rem 1rem; border-top: 1px solid var(--border); background: #fff; z-index: 2; }
.chat-question-form textarea, .chat-start-form textarea { flex: 1; width: 100%; resize: vertical; padding: .65rem; border: 1px solid var(--border); border-radius: 6px; font: inherit; }
.composer-main { flex: 1; min-width: 0; }
.scope-summary { display: block; color: var(--secondary); font-size: .72rem; margin-top: .3rem; }
.chat-empty-start { padding: 2rem 1.2rem .5rem; }
.chat-empty-start h2 { margin-top: 0; }
.chat-start-form { padding: 1rem 1.2rem; }
.chat-start-form fieldset { border: 0; margin-bottom: 1rem; }
.chat-start-form legend { font-weight: 700; margin-bottom: .5rem; }
.checkbox-row { display: flex; gap: .5rem; align-items: start; padding: .45rem 0; }
.checkbox-row span, .checkbox-row small { display: block; }
.checkbox-row small { color: var(--secondary); font-size: .75rem; }
.chat-start-form > label { display: block; font-weight: 700; margin-bottom: .35rem; }
.chat-start-form .btn { margin-top: .7rem; }
.chat-context { display: grid; align-content: start; gap: 1.2rem; overflow: hidden; }
.chat-context section { min-width: 0; }
.chat-context-intro { color: var(--secondary); font-size: .78rem; padding: .65rem .2rem; }
.chat-document-list, .chat-evidence-list { list-style: none; display: grid; gap: .55rem; padding: .7rem .2rem 0; }
.chat-document-list li, .chat-evidence-list li { padding-bottom: .55rem; border-bottom: 1px solid var(--border); font-size: .8rem; }
.chat-evidence-list a { color: var(--primary); font-weight: 600; }
.chat-citation.is-selected { outline: 2px solid #2563eb; outline-offset: 2px; }
.evidence-reader-panel, .run-inspector { min-width: 0; height: 100%; overflow-y: auto; overscroll-behavior: contain; }
.evidence-reader-header { display: flex; justify-content: space-between; gap: .75rem; align-items: start; border-bottom: 1px solid var(--border); padding-bottom: .75rem; }
.evidence-reader-header h2 { margin: 0; overflow-wrap: anywhere; }
.evidence-meta { color: var(--secondary); font-size: .78rem; margin: .25rem 0 0; overflow-wrap: anywhere; }
.icon-button { border: 1px solid var(--border); background: #fff; border-radius: 5px; font-size: 1.2rem; line-height: 1; padding: .25rem .5rem; cursor: pointer; }
.evidence-navigation { display: flex; justify-content: space-between; align-items: center; padding: .7rem 0; gap: .4rem; }
.evidence-navigation span { color: var(--secondary); font-size: .78rem; }
.evidence-tabs { display: flex; gap: .2rem; border-bottom: 1px solid var(--border); }
.evidence-tabs button { border: 0; background: transparent; padding: .55rem .65rem; cursor: pointer; color: var(--secondary); }
.evidence-tabs button[aria-selected="true"] { color: var(--primary); border-bottom: 2px solid var(--primary); font-weight: 700; }
.evidence-view { padding-top: .8rem; min-width: 0; }
.matching-label { color: var(--secondary); font-size: .75rem; font-weight: 700; text-transform: uppercase; }
.evidence-view blockquote { margin: .4rem 0 1rem; padding: .75rem; border-left: 3px solid #2563eb; background: #eff6ff; white-space: pre-wrap; overflow-wrap: anywhere; }
.evidence-view pre { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 260px; overflow: auto; background: #f8fafc; padding: .7rem; font: inherit; }
.evidence-page-tools { display: flex; gap: .35rem; margin-bottom: .5rem; }
.evidence-page-viewport { min-height: 220px; max-height: 420px; overflow: auto; background: #f8fafc; display: grid; place-items: center; padding: .5rem; }
.evidence-page-viewport img { max-width: none; width: 100%; height: auto; transform-origin: center top; }
.evidence-facts { display: grid; grid-template-columns: 1fr 1fr; gap: .45rem; font-size: .8rem; }
.evidence-facts dt { color: var(--secondary); }
.evidence-facts dd { margin: 0; overflow-wrap: anywhere; }
.evidence-reader-footer { padding: 1rem 0; }
.run-inspector { background: #fff; }
.inspector-body { padding-top: .8rem; font-size: .8rem; overflow-wrap: anywhere; }
.inspector-summary { display: grid; gap: .35rem; padding: .75rem; background: #f8fafc; border: 1px solid var(--border); border-radius: 6px; }
.inspector-phases, .inspector-evidence { padding-left: 1.2rem; display: grid; gap: .5rem; }
.inspector-phases li { display: grid; grid-template-columns: 1fr auto; gap: .2rem .5rem; border-left: 3px solid #86efac; padding-left: .5rem; }
.inspector-phases li.is-failed { border-color: #ef4444; }
.inspector-phases li span { grid-column: 1 / -1; color: var(--secondary); }
.inspector-phases li small { color: var(--secondary); }
.inspector-body pre { max-height: 250px; overflow: auto; white-space: pre-wrap; }
.run-failure-label { color: #b91c1c; font-size: .78rem; }
.chat-sessions, .chat-context { overflow-y: auto; overscroll-behavior: contain; }
.chat-run-status { display: flex; gap: .6rem; align-items: center; padding: .8rem; background: #fffbeb; border: 1px solid #fde68a; border-radius: 7px; color: #92400e; }
.chat-run-status span { font-size: .8rem; }
@media (max-width: 1050px) { .chat-shell { grid-template-columns: 190px minmax(0, 1fr) minmax(280px, 330px); gap: .65rem; } }
@media (max-width: 820px) { .chat-shell { grid-template-columns: 170px minmax(0, 1fr); } .chat-context { position: fixed; inset: 1rem; z-index: 10; box-shadow: 0 10px 40px #0003; } .chat-context[data-open="false"] { position: static; box-shadow: none; } }
@media (max-width: 600px) { .chat-shell { display: block; height: auto; min-height: 0; } .chat-sessions { max-height: 160px; margin-bottom: .65rem; } .chat-panel { min-height: calc(100vh - 270px); } .chat-context { position: fixed; inset: .5rem; } .chat-context[data-open="false"] { position: static; } .chat-question-form { display: block; } .chat-question-form .btn { margin-top: .6rem; width: 100%; } .chat-message { max-width: 100%; } .evidence-reader-panel, .run-inspector { height: calc(100vh - 1rem); } }

@media (max-width: 950px) {
    .workspace-grid { grid-template-columns: 120px minmax(0, 1fr); }
    .workspace-content { grid-column: 1 / -1; max-height: none; }
    .scan-viewport { max-height: 65vh; }
}
@media (max-width: 600px) {
    .workspace-header { display: block; }
    .workspace-header .btn { margin-top: .75rem; }
    .workspace-grid { grid-template-columns: 1fr; }
    .workspace-pages { order: 1; }
    .workspace-scan { order: 2; }
    .workspace-content { order: 3; }
    .page-list { display: flex; gap: .5rem; max-height: none; overflow-x: auto; }
    .page-list-item { flex: 0 0 76px; margin-bottom: 0; }
    .page-list-item img { aspect-ratio: 3 / 4; }
}

/* Primary actions (dashboard) */
.primary-actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin: 2rem 0;
}

.action-card {
    display: block;
    padding: 1.5rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    text-decoration: none;
    color: var(--foreground);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.action-card:hover {
    border-color: var(--accent);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.action-icon {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.action-card h2 {
    margin: 0 0 0.25rem;
    font-size: 1.1rem;
}

.action-card p {
    margin: 0;
    font-size: 0.85rem;
    color: var(--secondary);
}

/* Settings page */
.settings-grid {
    display: grid;
    gap: 2rem;
}

.settings-section {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.5rem;
}

.settings-section h2 {
    margin-top: 0;
}

.settings-form {
    max-width: 500px;
}

.settings-form .form-group {
    margin-bottom: 1rem;
}

.settings-form label {
    display: block;
    margin-bottom: 0.25rem;
    font-weight: 600;
}

.settings-form select,
.settings-form input[type="text"],
.settings-form input[type="password"] {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
}

.help-text {
    font-size: 0.8rem;
    color: var(--secondary);
    margin-top: 0.25rem;
}

.checkbox-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.checkbox-group label {
    margin-bottom: 0;
}

.scope-badge {
    display: inline-block;
    padding: 0.125rem 0.5rem;
    margin: 0.125rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 3px;
    font-size: 0.75rem;
    font-family: monospace;
}

/* Page header */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.page-header h1 { margin-bottom: 0.25rem; }
.page-intro { color: var(--secondary); max-width: 700px; }
.eyebrow {
    color: var(--primary);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.dashboard-section { margin: 2rem 0; }
.section-heading {
    display: flex;
    justify-content: space-between;
    align-items: end;
    gap: 1rem;
    margin-bottom: 0.75rem;
}
.section-heading h2 { margin: 0; }
.section-heading a { color: var(--primary); text-decoration: none; }
.item-list {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
}
.item-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    text-decoration: none;
}
.item-row:last-child { border-bottom: 0; }
a.item-row:hover { background: var(--bg); }
.item-row small { display: block; color: var(--secondary); margin-top: 0.125rem; }
.status-badge {
    flex: none;
    padding: 0.25rem 0.65rem;
    border-radius: 999px;
    background: var(--bg-secondary);
    color: var(--secondary);
    font-size: 0.78rem;
}
.status-active { background: #dbeafe; color: #1d4ed8; }
.status-ready { background: #dcfce7; color: #166534; }
.status-warning { background: #fef3c7; color: #92400e; }
.empty-state { padding: 2rem; text-align: center; }
.empty-state h2, .empty-state h3 { margin-top: 0; }
.empty-state p { color: var(--secondary); margin-bottom: 1rem; }
.evaluation-summary {
    padding: 1rem 1.25rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--bg-secondary);
}

.upload-container { max-width: 760px; margin: 0 auto; }
.upload-form {
    margin-top: 1.5rem;
    padding: 1.5rem;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
}
.form-step { display: flex; gap: 1rem; padding: 1.25rem 0; border-bottom: 1px solid var(--border); }
.step-number {
    display: grid;
    place-items: center;
    width: 2rem;
    height: 2rem;
    flex: none;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    font-weight: 700;
}
.step-content { flex: 1; min-width: 0; }
.step-content > label:first-child { display: block; font-weight: 700; margin-bottom: 0.5rem; }
.step-content > small { display: block; color: var(--secondary); margin-top: 0.35rem; }
.step-content select {
    width: 100%;
    padding: 0.7rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
}
.file-drop {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
    padding: 2rem;
    border: 2px dashed #cbd5e1;
    border-radius: 10px;
    text-align: center;
    cursor: pointer;
}
.file-drop:hover, .file-drop.dragover { border-color: var(--primary); background: #eff6ff; }
.file-drop.has-file { border-color: var(--success, #16a34a); background: #f0fdf4; }
.file-drop.has-error { border-color: #dc2626; background: #fef2f2; }
.region-detail-back { margin-left: auto; }
.correction-block { margin: 0.5rem 0 1rem; padding: 0.75rem 0.9rem; border: 1px solid var(--border); border-radius: 8px; }
.correction-block-title { margin: 0 0 0.4rem; font-size: 0.9rem; }
.file-drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.file-drop span { color: var(--secondary); font-size: 0.85rem; }
.file-selected {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.1rem;
    margin-top: 0.35rem;
}
.file-selected-name { font-weight: 600; color: var(--text, #111827); }
.file-selected-meta { color: var(--secondary); }
.file-selected-ok { color: var(--success, #16a34a); font-weight: 600; }
.file-drop.has-error .file-selected-ok { color: #dc2626; font-weight: 400; }
.analysis-option {
    display: flex;
    gap: 0.75rem;
    padding: 0.9rem;
    margin: 0.5rem 0;
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
}
.analysis-option.selected-option { border-color: var(--primary); background: #eff6ff; }
.analysis-option small { display: block; color: var(--secondary); }
.advanced-options { margin-top: 0.75rem; }
.advanced-options summary { color: var(--primary); cursor: pointer; }
.advanced-options > p { color: var(--secondary); font-size: 0.85rem; margin: 0.5rem 0; }
.next-explanation { margin-top: 1.25rem; padding: 1rem; background: var(--bg-secondary); border-radius: 8px; }
.next-explanation p { color: var(--secondary); margin-top: 0.25rem; }
.no-project-access { margin-top: 1.5rem; border: 1px solid var(--border); border-radius: 10px; background: #fff; }
.workflow-steps { margin: 2rem 0; list-style: none; counter-reset: steps; }
.workflow-steps li { display: flex; flex-direction: column; margin: 1rem 0; padding-left: 3rem; position: relative; }
.workflow-steps li::before {
    counter-increment: steps;
    content: counter(steps);
    position: absolute;
    left: 0;
    display: grid;
    place-items: center;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    background: var(--primary);
    color: white;
}
.workflow-steps span { color: var(--secondary); }

@media (max-width: 760px) {
    .nav-container { align-items: flex-start; gap: 1rem; }
    .nav-links { flex-wrap: wrap; justify-content: flex-end; gap: 0.75rem; }
    .page-header { align-items: flex-start; flex-direction: column; }
    .form-step { flex-direction: column; }
    .item-row { align-items: flex-start; }
}

/* ----- HTR (handwritten-text recognition) panel + line overlay ----- */
.htr-panel { margin-top: 1rem; border-top: 1px solid #e5e7eb; padding-top: .75rem; }
.htr-panel > details > summary { font-weight: 600; cursor: pointer; }
.htr-panel .help-text { color: var(--secondary); font-size: .875rem; margin: .5rem 0; }
.htr-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin: .5rem 0; align-items: center; }
.htr-pipeline-label { display: inline-flex; align-items: center; gap: .35rem; font-size: .875rem; color: var(--secondary); }
.htr-pipeline-label select { padding: .25rem .4rem; font-size: .875rem; border: 1px solid #d1d5db; border-radius: .25rem; background: #fff; }
.htr-status { font-size: .875rem; min-height: 1.25rem; }
.htr-status[data-kind="error"] { color: #b91c1c; }
.htr-status[data-kind="success"] { color: #047857; }
.htr-runs { margin-top: .5rem; }
.htr-history-item { padding: .5rem; border: 1px solid #e5e7eb; border-radius: .375rem; margin-bottom: .5rem; }
.htr-history-item.is-selected { border-color: #d97706; background: #fffbeb; }
.htr-run-actions { display: flex; gap: .5rem; margin-top: .5rem; align-items: center; }
.htr-line-meta { display: flex; gap: .75rem; font-size: .875rem; color: var(--secondary); margin-bottom: .25rem; }
.htr-line-text { margin: 0; padding: .5rem; background: #f9fafb; border-radius: .375rem; font-size: .875rem; }
.htr-line-detail { margin-top: .5rem; padding: .5rem; border: 1px solid #e5e7eb; border-radius: .375rem; }
.badge { display: inline-block; padding: .125rem .5rem; background: #dcfce7; color: #065f46; border-radius: 1rem; font-size: .75rem; }
.badge-htr-pipeline { background: #ffedd5; color: #9a3412; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; margin-left: .25rem; }

/* HTR line overlay — lives inside the same viewBox=0 0 1 1 region-overlay SVG. */
.htr-line { cursor: pointer; }
.htr-line-box { fill: rgba(217,119,6,.10); stroke: #d97706; stroke-width: .004; vector-effect: non-scaling-stroke; transition: fill .15s, stroke .15s; }
.htr-line:hover .htr-line-box, .htr-line:focus .htr-line-box { fill: rgba(217,119,6,.30); stroke-width: .006; }
.htr-line.is-selected .htr-line-box { fill: rgba(217,119,6,.40); stroke: #b45309; stroke-width: .007; }
.htr-line-order { fill: #b45309; font-size: .02px; font-weight: 700; pointer-events: none; }
