:root {
    --bg: #f4f0e8;
    --ink: #1f2228;
    --muted: #5d646f;
    --card: #fff9f0;
    --line: #d9ccb6;
    --accent: #b85c38;
    --accent-dark: #8d4123;
    --soft: #efe2ce;
    --success: #2d7a52;
    --warn: #9d5c0d;
    --blue-band: rgba(214, 229, 246, 0.72);
    --sand-band: rgba(245, 235, 217, 0.92);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Georgia, "Times New Roman", serif;
    background:
        radial-gradient(circle at top left, rgba(184, 92, 56, 0.18), transparent 30%),
        linear-gradient(180deg, #faf5ed 0%, var(--bg) 100%);
    color: var(--ink);
}

.shell {
    max-width: 1800px;
    margin: 0 auto;
    padding: 40px 20px 80px;
}

body.reviewing .shell {
    max-width: none;
    padding-inline: 12px;
}

.hero {
    padding: 28px 0 10px;
}

.hero-top {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: center;
}

.eyebrow {
    margin: 0 0 10px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    font-size: 12px;
    color: var(--accent-dark);
}

h1, h2, h3, h4 {
    margin: 0;
    font-weight: 700;
}

h1 {
    font-size: clamp(34px, 6vw, 58px);
    line-height: 1;
    max-width: 980px;
}

.subhead {
    max-width: 860px;
    color: var(--muted);
    font-size: 18px;
    line-height: 1.5;
    margin-top: 18px;
}

.card,
.map-card,
.inspector-card {
    background: rgba(255, 249, 240, 0.9);
    border: 1px solid var(--line);
    border-radius: 20px;
    box-shadow: 0 14px 40px rgba(63, 45, 30, 0.08);
}

.card {
    padding: 24px;
    margin-top: 18px;
}

.auth-shell {
    max-width: 860px;
}

.login-card {
    max-width: 520px;
}

.login-form {
    display: grid;
    gap: 16px;
}

.field-label {
    font-size: 15px;
    color: var(--muted);
}

.password-field {
    width: 100%;
    padding: 14px 16px;
    border-radius: 14px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.9);
}

.form-error {
    border-radius: 12px;
    padding: 12px 14px;
    background: #fff1ec;
    border: 1px solid rgba(184, 74, 74, 0.25);
    color: #8b3737;
}

.logout-form {
    margin: 0;
}

.upload-form {
    display: grid;
    gap: 18px;
}

.dropzone {
    display: grid;
    gap: 10px;
    padding: 32px;
    border: 2px dashed rgba(184, 92, 56, 0.4);
    border-radius: 18px;
    background: linear-gradient(180deg, rgba(255,255,255,0.6), rgba(239,226,206,0.65));
    cursor: pointer;
}

.dropzone.drag-active {
    border-color: var(--accent-dark);
    background: linear-gradient(180deg, rgba(255,255,255,0.85), rgba(239,226,206,0.9));
    box-shadow: inset 0 0 0 2px rgba(141, 65, 35, 0.12);
}

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

.dropzone-title {
    font-size: 24px;
}

.dropzone-note {
    color: var(--muted);
    line-height: 1.5;
}

.dropzone-file {
    color: var(--accent-dark);
    font-size: 15px;
}

code {
    font-family: "SFMono-Regular", Consolas, monospace;
    font-size: 0.92em;
}

button,
input,
select {
    font: inherit;
}

button {
    border: 0;
    border-radius: 999px;
    padding: 12px 18px;
    cursor: pointer;
}

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

button.primary:hover {
    background: var(--accent-dark);
}

button.secondary {
    background: var(--soft);
    color: var(--ink);
}

button.secondary.danger,
.segment-delete-button,
.page-delete-button {
    background: rgba(184, 74, 74, 0.12);
    color: #8b3737;
    border: 1px solid rgba(184, 74, 74, 0.2);
}

button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.status-panel {
    margin-top: 18px;
    padding: 14px 16px;
    border-radius: 14px;
    background: #fff;
    border: 1px solid var(--line);
    line-height: 1.5;
}

.hidden {
    display: none !important;
}

.review-shell {
    margin-top: 20px;
    display: grid;
    gap: 10px;
}

.review-shell.busy {
    pointer-events: none;
    opacity: 0.72;
}

.review-command-bar {
    position: sticky;
    top: 12px;
    z-index: 30;
    padding: 10px 12px;
    border-radius: 16px;
    border: 1px solid rgba(217, 204, 182, 0.9);
    background: rgba(255, 249, 240, 0.95);
    box-shadow: 0 10px 26px rgba(63, 45, 30, 0.08);
    backdrop-filter: blur(12px);
}

.review-header {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    align-items: flex-start;
    margin-bottom: 14px;
}

.review-header.compact {
    align-items: center;
    margin-bottom: 8px;
}

.review-title-row {
    display: grid;
    gap: 2px;
}

.review-title-row h2 {
    font-size: 20px;
}

.review-mini-copy {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.35;
}

.review-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.review-actions-primary button {
    min-height: 40px;
}

.mode-toggle {
    display: inline-flex;
    gap: 8px;
    padding: 6px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.78);
    border: 1px solid var(--line);
}

.mode-toggle button.active {
    background: var(--accent-dark);
    color: #fff;
}

button.secondary.active {
    background: var(--accent-dark);
    color: #fff;
    border-color: var(--accent-dark);
}

.toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: 14px;
}

.zoom-controls {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.8);
    border: 1px solid var(--line);
}

.zoom-controls input[type="range"] {
    width: 180px;
}

.zoom-label {
    color: var(--muted);
    font-size: 14px;
}

.banner-list {
    display: grid;
    gap: 10px;
    margin-bottom: 14px;
}

.banner-list.compact {
    margin: 8px 0 0;
}

.banner {
    border-radius: 12px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    background: rgba(255,255,255,0.75);
}

.banner.warn {
    border-color: #e1b76a;
    background: #fff5df;
}

.banner.info {
    border-color: #b3c8df;
    background: #eef5ff;
}

.map-card,
.list-card {
    padding: 0;
}

.map-card-full {
    padding: 0;
    border: 0;
    box-shadow: none;
    background: transparent;
}

.map-toolbar {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    align-items: flex-start;
    margin-bottom: 8px;
}

.map-toolbar.compact h3 {
    font-size: 16px;
}

.map-summary,
.map-help,
.inspector-meta,
.inspector-copy {
    margin: 6px 0 0;
    color: var(--muted);
    line-height: 1.45;
}

.map-help {
    max-width: 380px;
    font-size: 12px;
}

.page-map-shell {
    overflow: visible;
    border-radius: 0;
    border: 0;
    background: transparent;
    padding: 0;
}

.list-card {
    padding: 20px;
}

.page-map {
    --thumb-width: 180px;
    display: grid;
    gap: 18px;
    grid-template-columns: minmax(0, 1fr);
    align-items: start;
}

.segment-cluster {
    display: grid;
    gap: 14px;
    border-radius: 20px;
    border: 2px solid transparent;
    padding: 14px;
    box-shadow: 0 10px 22px rgba(63, 45, 30, 0.08);
}

.segment-cluster.segment-selected {
    border-color: rgba(141, 65, 35, 0.45);
    box-shadow: 0 0 0 3px rgba(184, 92, 56, 0.12), 0 12px 24px rgba(63, 45, 30, 0.12);
}

.segment-cluster.segment-target,
.segment-summary-card.segment-target,
.list-segment-row.target {
    box-shadow: 0 0 0 3px rgba(45, 122, 82, 0.14), 0 12px 24px rgba(63, 45, 30, 0.12);
    border-color: rgba(45, 122, 82, 0.35);
}

.segment-cluster-header {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    align-items: flex-start;
}

.segment-cluster-meta {
    display: grid;
    gap: 4px;
    color: var(--muted);
    font-size: 13px;
}

.segment-cluster-controls {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.segment-page-grid {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fill, minmax(var(--thumb-width), 1fr));
    align-items: start;
}

.segment-cluster-placeholder {
    display: grid;
    place-items: center;
    border-radius: 16px;
    border: 1px dashed rgba(141, 65, 35, 0.25);
    background: rgba(255, 255, 255, 0.55);
    padding: 18px;
}

.segment-cluster-placeholder-copy {
    display: grid;
    gap: 8px;
    text-align: center;
    max-width: 460px;
    color: var(--muted);
}

.page-card {
    position: relative;
    display: grid;
    gap: 8px;
    align-content: start;
    width: 100%;
    text-align: left;
    border-radius: 18px;
    border: 2px solid transparent;
    padding: 12px;
    box-shadow: 0 8px 18px rgba(63, 45, 30, 0.06);
    transition: transform 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}

.page-delete-button {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 2;
    padding: 6px 10px;
    border-radius: 999px;
    font-size: 11px;
    line-height: 1;
}

.page-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 24px rgba(63, 45, 30, 0.1);
}

.segment-band-a {
    background: linear-gradient(180deg, rgba(255,255,255,0.95), var(--blue-band));
}

.segment-band-b {
    background: linear-gradient(180deg, rgba(255,255,255,0.95), var(--sand-band));
}

.page-card.segment-selected {
    border-color: rgba(141, 65, 35, 0.45);
}

.page-card.page-selected {
    border-color: var(--accent-dark);
    box-shadow: 0 0 0 3px rgba(184, 92, 56, 0.18), 0 12px 24px rgba(63, 45, 30, 0.14);
}

.page-card img {
    width: 100%;
    height: auto;
    aspect-ratio: 8.5 / 11;
    object-fit: contain;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 12px;
    border: 1px solid rgba(217, 204, 182, 0.7);
    display: block;
}

.segment-summary-card {
    width: 100%;
    text-align: left;
    display: grid;
    gap: 12px;
    padding: 14px;
    cursor: pointer;
    border-radius: 20px;
    border: 2px solid transparent;
    box-shadow: 0 10px 22px rgba(63, 45, 30, 0.08);
}

.selection-strip {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: center;
    padding: 8px 0 6px;
    border-top: 1px solid rgba(217, 204, 182, 0.75);
}

.selection-empty {
    color: var(--muted);
}

.selection-summary {
    margin: 0;
    font-size: 14px;
    line-height: 1.35;
}

.selection-helper {
    color: var(--muted);
    font-size: 12px;
}

.review-link-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: flex-start;
    padding-top: 6px;
}

.mini-panel {
    border-radius: 12px;
    border: 1px solid rgba(217, 204, 182, 0.75);
    background: rgba(255, 255, 255, 0.52);
    padding: 0 10px;
}

.mini-panel summary {
    cursor: pointer;
    list-style: none;
    padding: 10px 0;
    color: var(--accent-dark);
    font-size: 13px;
    font-weight: 700;
}

.mini-panel summary::-webkit-details-marker {
    display: none;
}

.mini-panel[open] {
    padding-bottom: 10px;
}

.mini-panel-grid {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

.segment-target-button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 999px;
    border: 1px solid rgba(141, 65, 35, 0.18);
    background: rgba(255, 255, 255, 0.88);
    color: var(--ink);
    cursor: pointer;
    white-space: nowrap;
}

.segment-delete-button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 999px;
    cursor: pointer;
    white-space: nowrap;
}

.segment-delete-button.compact {
    font-size: 13px;
}

.segment-target-button.compact {
    font-size: 13px;
}

.segment-target-button.active {
    border-color: rgba(45, 122, 82, 0.35);
    background: rgba(45, 122, 82, 0.11);
    color: #225b3d;
}

.target-swatch {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    display: inline-block;
    border: 1px solid rgba(31, 34, 40, 0.12);
}

.segment-summary-top {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
}

.segment-summary-pages {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.collapsed-thumb {
    display: grid;
    gap: 8px;
    font-size: 13px;
    color: var(--muted);
}

.collapsed-thumb img {
    width: 100%;
    height: auto;
    aspect-ratio: 8.5 / 11;
    object-fit: contain;
    background: rgba(255, 255, 255, 0.94);
    border-radius: 12px;
    border: 1px solid rgba(217, 204, 182, 0.7);
    display: block;
}

.segment-summary-meta {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    color: var(--muted);
    font-size: 14px;
}

.segment-summary-actions {
    display: flex;
    justify-content: flex-end;
}

.inline-expand {
    padding: 8px 12px;
}

.page-footer {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    color: var(--muted);
    font-size: 13px;
}

.segment-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    font-size: 13px;
    color: var(--ink);
}

.confidence-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

.confidence-dot.good {
    background: #2d7a52;
}

.confidence-dot.mid {
    background: #c58f11;
}

.confidence-dot.low {
    background: #b84a4a;
}

.mini-warning {
    border-radius: 999px;
    padding: 2px 8px;
    background: rgba(255, 245, 223, 0.95);
    border: 1px solid #e1b76a;
    color: var(--warn);
}

.inspector-empty {
    display: grid;
    gap: 8px;
}

.inspector-empty p {
    margin: 0;
    color: var(--muted);
}

.inspector-panel {
    display: block;
}

.command-top {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    align-items: flex-start;
    flex-wrap: wrap;
}

.command-top.compact {
    align-items: center;
    gap: 10px;
}

.command-main {
    display: grid;
    gap: 2px;
}

.command-status {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
}

.segment-tag {
    margin: 0;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--accent-dark);
    font-size: 12px;
}

.inspector-title {
    margin: 0;
    color: var(--muted);
    font-size: 12px;
}

.target-chip {
    display: inline-flex;
    align-items: center;
    padding: 8px 12px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.76);
    border: 1px solid var(--line);
    color: var(--muted);
    font-size: 13px;
}

.target-chip.active {
    background: rgba(45, 122, 82, 0.1);
    border-color: rgba(45, 122, 82, 0.28);
    color: #225b3d;
}

.confidence-chip {
    padding: 8px 12px;
    border-radius: 999px;
    font-size: 13px;
    white-space: nowrap;
}

.confidence-chip.good {
    background: rgba(45, 122, 82, 0.12);
    color: #225b3d;
}

.confidence-chip.mid {
    background: rgba(197, 143, 17, 0.12);
    color: #805b0e;
}

.confidence-chip.low {
    background: rgba(184, 74, 74, 0.12);
    color: #8b3737;
}

.detail-pill-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    padding-top: 2px;
}

.detail-pill {
    display: inline-grid;
    gap: 4px;
    padding: 8px 10px;
    min-width: 150px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.75);
    border: 1px solid rgba(217, 204, 182, 0.75);
}

.detail-label {
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.action-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 10px;
}

.command-actions {
    margin-top: 4px;
}

.list-segment-row {
    width: 100%;
    text-align: left;
    display: grid;
    gap: 12px;
    padding: 16px;
    cursor: pointer;
    margin-bottom: 12px;
    border-radius: 18px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.72);
    box-shadow: 0 10px 26px rgba(63, 45, 30, 0.06);
}

.list-segment-row.selected {
    border-color: var(--accent-dark);
    box-shadow: 0 0 0 3px rgba(184, 92, 56, 0.15), 0 12px 28px rgba(63, 45, 30, 0.1);
}

.list-segment-row-top {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: flex-start;
}

.list-segment-row-title {
    display: grid;
    gap: 6px;
}

.list-segment-row-title strong {
    font-size: 18px;
}

.list-segment-row-title span,
.list-segment-row-grid span {
    color: var(--muted);
}

.list-row-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.list-segment-row-grid {
    display: grid;
    gap: 10px 14px;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.list-segment-row-grid strong {
    color: var(--ink);
    margin-right: 6px;
}

@media (max-width: 1180px) {
    .review-command-bar {
        top: 0;
    }
}

@media (max-width: 860px) {
    .hero-top,
    .review-header,
    .map-toolbar,
    .command-top,
    .list-segment-row-top,
    .selection-strip {
        flex-direction: column;
        align-items: flex-start;
    }

    .review-actions {
        justify-content: flex-start;
    }

    .action-grid {
        grid-template-columns: 1fr;
    }

    .segment-cluster-header,
    .segment-summary-top,
    .segment-summary-meta,
    .segment-cluster-controls {
        flex-direction: column;
        align-items: flex-start;
        text-align: left;
        justify-items: start;
    }
}
