:root {
    --ink: #0f1620;
    --ink-soft: #3a4150;
    --muted: #6b7280;
    --line: #e5e7eb;
    --line-strong: #d4d4ce;
    --bg: #f7f7f5;
    --card: #ffffff;
    --brand: #1f3a5f;
    --brand-ink: #0e1f33;
    --accent: #b8762b;
    --accent-soft: #e8d4b3;
    --hi: #f2c14e;          /* bbox highlight fill */
    --hi-stroke: #b8762b;   /* bbox highlight border */
    --ok: #2f6e4d;
    --err: #9b2c2c;
    --shadow: 0 1px 2px rgba(15, 22, 32, 0.04), 0 8px 24px rgba(15, 22, 32, 0.06);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    background: var(--bg);
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
}

body { display: flex; flex-direction: column; min-height: 100vh; }

/* ============ Header / footer ============ */
.site-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 24px;
    border-bottom: 1px solid var(--line);
    background: var(--card);
    flex-shrink: 0;
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand-mark {
    font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
    font-weight: 600;
    font-size: 20px;
    letter-spacing: 0.5px;
    color: var(--brand-ink);
}
.brand-tag {
    font-size: 11px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 1.2px;
}
.nav-pill {
    display: inline-block;
    padding: 3px 9px;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--muted);
    font-size: 11px;
    letter-spacing: 0.8px;
    text-transform: uppercase;
}

.site-footer {
    text-align: center;
    color: var(--muted);
    font-size: 11px;
    padding: 10px 24px;
    border-top: 1px solid var(--line);
    background: var(--card);
    flex-shrink: 0;
}
.site-footer .dot { margin: 0 8px; }

/* ============ Upload view ============ */
.container {
    max-width: 980px;
    margin: 0 auto;
    padding: 40px 32px 60px;
}
.hero { margin-bottom: 24px; }
.hero h1 {
    font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
    font-weight: 600;
    font-size: 36px;
    line-height: 1.1;
    margin: 0 0 10px;
    color: var(--brand-ink);
}
.hero .lede {
    margin: 0;
    max-width: 720px;
    color: var(--ink-soft);
    font-size: 15px;
}

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}
.uploader { padding: 24px; }
.drop {
    display: block;
    border: 2px dashed #c9c9c2;
    border-radius: 6px;
    padding: 32px 24px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    background: #fafaf7;
}
.drop:hover, .drop.dragover { border-color: var(--brand); background: #fff; }
.drop-icon { font-size: 26px; color: var(--brand); }
.drop-title { margin-top: 10px; font-weight: 600; color: var(--ink); }
.drop-sub { margin-top: 4px; font-size: 12px; color: var(--muted); }

.actions {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-top: 16px;
}
.file-name { color: var(--muted); font-size: 13px; }

.btn-primary, .btn-secondary, .icon-btn {
    appearance: none;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s;
}
.btn-primary {
    border: 0;
    background: var(--brand);
    color: #fff;
    font-weight: 600;
    font-size: 13px;
    padding: 9px 16px;
    border-radius: 6px;
    text-decoration: none;
    display: inline-block;
}
.btn-primary:hover { background: var(--brand-ink); }
.btn-primary:disabled { background: #a3a8b2; cursor: not-allowed; }

.btn-secondary {
    border: 1px solid var(--line);
    background: #fff;
    color: var(--ink);
    font-weight: 500;
    font-size: 13px;
    padding: 8px 14px;
    border-radius: 6px;
}
.btn-secondary:hover { background: #f3f3ee; }

.icon-btn {
    border: 1px solid var(--line);
    background: #fff;
    color: var(--ink);
    font-size: 16px;
    line-height: 1;
    width: 28px;
    height: 28px;
    border-radius: 4px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.icon-btn:hover { background: #f3f3ee; }

.progress {
    display: flex;
    align-items: center;
    gap: 18px;
    padding: 20px;
    margin-top: 18px;
}
.spinner {
    width: 22px; height: 22px;
    border-radius: 50%;
    border: 3px solid var(--accent-soft);
    border-top-color: var(--accent);
    animation: spin 0.9s linear infinite;
    flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }
.progress-text strong { color: var(--ink); }
.progress-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.progress-timer { margin-top: 4px; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12px; }

.error { margin-top: 22px; padding: 22px; border-color: #f1d4d4; background: #fdf6f6; }
.error-title { color: var(--err); font-weight: 600; margin-bottom: 6px; }
.error-detail { color: var(--ink-soft); font-size: 14px; margin-bottom: 14px; white-space: pre-wrap; }

/* ============ Results view ============ */
.view-results { display: flex; flex-direction: column; flex: 1; min-height: 0; }

.results-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 10px 20px;
    border-bottom: 1px solid var(--line);
    background: var(--card);
    flex-shrink: 0;
}
.results-bar-left { display: flex; align-items: center; gap: 14px; }
.results-bar-right { display: flex; align-items: center; gap: 14px; }
.results-title { display: flex; flex-direction: column; }
.results-name {
    font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
    font-weight: 600;
    font-size: 17px;
    color: var(--brand-ink);
}
.results-meta { color: var(--muted); font-size: 12px; margin-top: 1px; }

.bid-total { text-align: right; }
.bid-total-label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; }
.bid-total-value {
    font-weight: 600;
    font-size: 18px;
    font-variant-numeric: tabular-nums;
    color: var(--accent);
}

/* Split: left = table, right = pdf */
.split {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    flex: 1;
    min-height: 0;
}
.pane {
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: var(--card);
}
.pane-left { border-right: 1px solid var(--line); }

.pane-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px;
    border-bottom: 1px solid var(--line);
    background: #fafaf7;
    font-size: 12px;
    color: var(--muted);
    flex-shrink: 0;
}
.legend { display: inline-flex; align-items: center; gap: 10px; }
.legend-dot {
    display: inline-block;
    width: 8px; height: 8px;
    border-radius: 50%;
    margin-right: 4px;
    vertical-align: middle;
}
.legend-dot.extracted { background: var(--brand); }
.legend-dot.computed { background: var(--accent-soft); border: 1px solid var(--accent); }

/* ============ Table ============ */
.table-scroll {
    overflow: auto;
    flex: 1;
    min-height: 0;
}
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12.5px;
}
thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    text-align: left;
    background: #fafaf7;
    color: var(--ink-soft);
    font-weight: 600;
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 8px 10px;
    border-bottom: 1px solid var(--line-strong);
    white-space: nowrap;
}
thead th.num { text-align: right; }
thead th.sticky-l { left: 0; z-index: 3; }
tbody td {
    padding: 7px 10px;
    border-bottom: 1px solid var(--line);
    vertical-align: top;
    white-space: nowrap;
}
tbody td.wide { white-space: normal; min-width: 200px; }
tbody td.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody td.sticky-l { position: sticky; left: 0; background: var(--card); z-index: 1; }
tbody tr { cursor: pointer; }
tbody tr:hover, tbody tr.active {
    background: #fff8eb;
}
tbody tr:hover td.sticky-l, tbody tr.active td.sticky-l { background: #fff8eb; }
tbody tr:last-child td { border-bottom: 0; }

.code-pill {
    display: inline-block;
    background: var(--accent-soft);
    color: #5d3d10;
    padding: 1px 6px;
    border-radius: 3px;
    font-weight: 600;
    font-size: 11px;
    letter-spacing: 0.4px;
}
/* "Computed" cells get a softer treatment so the user sees what came from
   the drawing vs the rate library. */
.computed { color: #8a6a3a; background: #fcf6e8; }

/* Editable quantity cells — visually signal that this is the one input
   the estimator should verify against the drawings. */
.qty-cell {
    padding: 0 !important;
    background: #eef4ff;
    position: relative;
}
.qty-input {
    appearance: none;
    width: 100%;
    border: 0;
    background: transparent;
    padding: 7px 10px;
    font: inherit;
    font-variant-numeric: tabular-nums;
    text-align: right;
    color: var(--ink);
}
.qty-input:focus {
    outline: 2px solid var(--brand);
    outline-offset: -2px;
    background: #fff;
}
/* Hide the spinner arrows in the qty input (cleaner look). */
.qty-input::-webkit-outer-spin-button,
.qty-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.qty-input[type=number] { -moz-appearance: textfield; }

.qty-cell.edited {
    background: #e9f4e9;
}
.qty-cell.edited::after {
    content: "edited";
    position: absolute;
    bottom: 1px;
    right: 4px;
    font-size: 9px;
    color: #2f6e4d;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    pointer-events: none;
    opacity: 0.7;
}

/* Low-confidence rows: subtle warning stripe on the left edge. */
tbody tr.low-conf td.sticky-l {
    box-shadow: inset 3px 0 0 var(--accent);
}

/* ============ PDF viewer ============ */
.viewer-header { gap: 12px; }
.viewer-nav, .viewer-zoom { display: inline-flex; align-items: center; gap: 6px; }
.page-indicator { font-size: 12px; color: var(--ink-soft); }
.page-indicator input {
    width: 48px;
    padding: 3px 6px;
    border: 1px solid var(--line);
    border-radius: 4px;
    font: inherit;
    font-size: 12px;
    text-align: center;
}
.page-of { color: var(--muted); margin-left: 4px; }

.viewer-wrap {
    flex: 1;
    overflow: auto;
    background: #2c2f33;
    min-height: 0;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 18px;
}
.viewer-stage {
    position: relative;
    background: #fff;
    box-shadow: 0 8px 30px rgba(0,0,0,0.4);
    line-height: 0; /* eliminate canvas baseline gap */
}
.viewer-stage canvas {
    display: block;
    max-width: none;
}
.bbox-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
}
.bbox {
    position: absolute;
    border: 2px solid var(--hi-stroke);
    background: rgba(242, 193, 78, 0.25);
    border-radius: 2px;
    box-shadow: 0 0 0 9999px rgba(15, 22, 32, 0.18);
    transition: opacity 0.12s;
}

/* ============ Responsiveness ============ */
@media (max-width: 1100px) {
    .split { grid-template-columns: 1fr; grid-template-rows: minmax(280px, 45vh) 1fr; }
    .pane-left { border-right: 0; border-bottom: 1px solid var(--line); }
}
@media (max-width: 640px) {
    .hero h1 { font-size: 26px; }
    .container { padding: 24px 18px 50px; }
    .results-bar { flex-wrap: wrap; gap: 10px; }
}
