:root {
    --ink: #17211b;
    --muted: #657168;
    --paper: #f4f1e8;
    --panel: #fffdf8;
    --line: #dedbd0;
    --green: #155f43;
    --green-2: #0d7b52;
    --green-soft: #dff0e7;
    --amber: #a35f0c;
    --amber-soft: #fff0d3;
    --red: #a83b32;
    --red-soft: #f9e1dc;
    --blue: #315f78;
    --shadow: 0 18px 55px rgba(38, 49, 41, .09);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
    margin: 0;
    color: var(--ink);
    background:
        radial-gradient(circle at 10% 0%, rgba(21,95,67,.09), transparent 30rem),
        linear-gradient(180deg, #f8f6ef 0, var(--paper) 52%, #eeece3 100%);
    min-height: 100vh;
}
button, input { font: inherit; }
button { color: inherit; }
.hidden { display: none !important; }

.app-shell { width: min(1440px, 100%); margin: 0 auto; padding: 0 32px; }
.topbar {
    height: 88px; display: flex; align-items: center; justify-content: space-between;
    border-bottom: 1px solid rgba(23,33,27,.11);
}
.brand { display: flex; align-items: center; gap: 12px; color: inherit; text-decoration: none; }
.brand-mark {
    display: grid; place-items: center; width: 42px; height: 42px; border-radius: 12px;
    background: var(--green); color: white; font-weight: 800; letter-spacing: -.03em;
    box-shadow: 0 8px 20px rgba(21,95,67,.2);
}
.brand strong, .brand small { display: block; }
.brand strong { font-size: 16px; letter-spacing: -.02em; }
.brand small { color: var(--muted); font-size: 11px; margin-top: 2px; }
.source-badge {
    display: flex; align-items: center; gap: 8px; padding: 8px 12px; border: 1px solid #bad3c5;
    border-radius: 999px; color: var(--green); background: rgba(255,255,255,.55); font-size: 12px; font-weight: 700;
}
.source-badge span { width: 7px; height: 7px; background: #26a46e; border-radius: 50%; box-shadow: 0 0 0 4px rgba(38,164,110,.12); }

main { width: min(1180px, 100%); margin: 0 auto; }
.hero { text-align: center; padding: 86px 16px 48px; }
.eyebrow, .step-label { color: var(--green-2); font-size: 11px; font-weight: 800; letter-spacing: .16em; }
.hero h1 {
    max-width: 850px; margin: 16px auto 18px; font-family: Georgia, "Times New Roman", serif;
    font-size: clamp(42px, 6vw, 72px); line-height: .99; letter-spacing: -.045em; font-weight: 500;
}
.hero p { max-width: 700px; margin: 0 auto; color: var(--muted); font-size: 17px; line-height: 1.7; }
.panel {
    background: rgba(255,253,248,.92); border: 1px solid rgba(117,122,112,.25);
    border-radius: 24px; box-shadow: var(--shadow);
}
.upload-card { padding: 34px; }
.section-heading, .results-toolbar, .table-tools {
    display: flex; justify-content: space-between; align-items: flex-start; gap: 24px;
}
.section-heading { padding-bottom: 26px; border-bottom: 1px solid var(--line); }
.section-heading h2, .results-toolbar h2 { margin: 6px 0 0; font-size: 27px; letter-spacing: -.035em; }
.section-heading p, .table-tools p { color: var(--muted); margin: 4px 0 0; font-size: 13px; line-height: 1.5; }

.drop-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-top: 26px; }
.drop-zone {
    min-height: 225px; display: flex; flex-direction: column; align-items: center; justify-content: center;
    text-align: center; padding: 28px; border: 1.5px dashed #aab5ab; border-radius: 18px;
    background: #faf9f4; cursor: pointer; transition: .2s ease;
}
.drop-zone:hover, .drop-zone.dragging { border-color: var(--green); transform: translateY(-2px); background: #f5faf6; }
.drop-zone.selected { border-style: solid; border-color: #76aa8e; background: #f1f8f4; }
.drop-zone input { position: absolute; opacity: 0; pointer-events: none; }
.drop-icon {
    display: grid; place-items: center; width: 58px; height: 58px; margin-bottom: 16px; border-radius: 16px;
    background: var(--green-soft); color: var(--green); font-size: 12px; font-weight: 900; letter-spacing: .06em;
}
.contract .drop-icon { color: var(--blue); background: #e3edf1; }
.drop-zone strong { font-size: 17px; }
.drop-zone > span:not(.drop-icon) { margin-top: 7px; color: var(--muted); font-size: 13px; }
.drop-zone small { margin-top: 16px; color: #929a93; }
.selection-summary { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-top: 22px; }
.selection-label { display: block; color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .09em; margin-bottom: 8px; }
.file-chips { display: flex; flex-wrap: wrap; gap: 7px; }
.file-chip { padding: 7px 10px; border: 1px solid #ccd7ce; border-radius: 9px; background: white; font-size: 12px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.policy-note { display: flex; gap: 12px; align-items: flex-start; margin: 24px 0; padding: 15px 17px; background: #f1f5f1; border-radius: 13px; color: #536158; }
.policy-note p { margin: 0; font-size: 12px; line-height: 1.55; }
.policy-icon { flex: 0 0 auto; display: grid; place-items: center; width: 21px; height: 21px; border: 1px solid #8e9d92; border-radius: 50%; font: 700 12px Georgia; }
.primary-button, .secondary-button {
    border: 0; border-radius: 12px; cursor: pointer; font-weight: 750; transition: .2s ease;
}
.primary-button {
    width: 100%; padding: 16px 22px; display: flex; justify-content: center; gap: 15px; align-items: center;
    color: white; background: var(--green); box-shadow: 0 10px 25px rgba(21,95,67,.18);
}
.primary-button:hover { background: #104e37; transform: translateY(-1px); }
.primary-button:disabled { opacity: .55; cursor: wait; transform: none; }
.primary-button.compact { width: auto; padding: 11px 16px; font-size: 13px; }
.secondary-button { padding: 10px 15px; border: 1px solid var(--line); background: transparent; font-size: 13px; }
.secondary-button:hover { background: white; }
.history-panel { margin-top: 18px; padding: 24px; }
.history-panel .section-heading { align-items: center; padding-bottom: 18px; }
.history-panel .section-heading h2 { font-size: 20px; }
.history-list { display: grid; gap: 8px; margin-top: 16px; }
.history-row {
    display: grid; grid-template-columns: minmax(190px, 1.6fr) repeat(3, minmax(65px, .45fr)) auto;
    align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--line);
    border-radius: 12px; background: #faf9f4;
}
.history-file { min-width: 0; }
.history-file strong, .history-file small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-file strong { font-size: 12px; }
.history-file small { color: var(--muted); font-size: 10px; margin-top: 3px; }
.history-metric { text-align: right; }
.history-metric span, .history-metric b { display: block; }
.history-metric span { color: var(--muted); font-size: 9px; text-transform: uppercase; letter-spacing: .06em; }
.history-metric b { margin-top: 3px; font-size: 13px; }
.history-actions { display: flex; gap: 5px; }
.history-actions button { border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; background: white; cursor: pointer; font-size: 10px; font-weight: 750; }
.history-actions .delete-job { color: var(--red); }
.history-empty { color: var(--muted); text-align: center; padding: 18px; font-size: 12px; }

.processing { margin-top: 24px; padding: 30px 34px; display: grid; grid-template-columns: auto 1fr; gap: 20px; align-items: center; position: relative; overflow: hidden; }
.processing h2 { margin: 5px 0; font-size: 22px; }
.processing p { margin: 0; color: var(--muted); font-size: 13px; }
.processing-orbit { width: 52px; height: 52px; border: 2px solid #c9d9cf; border-radius: 50%; padding: 6px; animation: spin 1.5s linear infinite; }
.processing-orbit span { display: block; width: 12px; height: 12px; border-radius: 50%; background: var(--green); }
.progress-track { position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: #e6e6de; }
.progress-track span { display: block; height: 100%; width: 8%; background: var(--green-2); transition: width .6s ease; }
@keyframes spin { to { transform: rotate(360deg); } }

.results { margin-top: 54px; }
.results-toolbar { align-items: center; margin-bottom: 20px; }
.toolbar-actions { display: flex; gap: 9px; }
.verification-banner {
    display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 14px;
    padding: 17px 20px; border: 1px solid #b8d5c4; background: var(--green-soft); border-radius: 16px;
}
.verification-banner.review { background: var(--amber-soft); border-color: #e3c388; }
.verification-banner.error { background: var(--red-soft); border-color: #dfaaa1; }
.verification-symbol { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; color: white; background: var(--green); font-weight: 900; }
.review .verification-symbol { background: var(--amber); }
.error .verification-symbol { background: var(--red); }
.verification-banner strong, .verification-banner span { display: block; }
.verification-banner > div:nth-child(2) span { color: var(--muted); font-size: 12px; margin-top: 3px; }
.confidence { text-align: right; padding-left: 24px; border-left: 1px solid rgba(32,60,44,.16); }
.confidence span { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
.confidence strong { margin-top: 2px; font-size: 20px; }
.metric-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 13px; margin: 16px 0; }
.metric-card { padding: 20px; border: 1px solid var(--line); border-radius: 16px; background: rgba(255,253,248,.72); }
.metric-card span, .metric-card small { display: block; color: var(--muted); }
.metric-card span { font-size: 12px; font-weight: 700; }
.metric-card strong { display: block; margin: 7px 0 2px; font: 500 34px Georgia, serif; }
.metric-card small { font-size: 10px; }
.warning-stack { margin: 16px 0; display: grid; gap: 8px; }
.warning-item { padding: 13px 16px; border: 1px solid #e3c388; border-radius: 12px; background: var(--amber-soft); color: #75470c; font-size: 12px; line-height: 1.55; }

.result-panel { margin-top: 16px; overflow: hidden; }
.tabs { display: flex; gap: 4px; padding: 10px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab { white-space: nowrap; border: 0; background: transparent; padding: 10px 14px; border-radius: 9px; color: var(--muted); cursor: pointer; font-size: 12px; font-weight: 750; }
.tab:hover { background: #f2f1eb; }
.tab.active { color: white; background: var(--ink); }
.tab-pane { display: none; padding: 28px; }
.tab-pane.active { display: block; }
.table-tools { align-items: center; margin-bottom: 18px; }
.table-tools h3 { margin: 0; font-size: 18px; }
.search-box { min-width: 275px; display: flex; align-items: center; gap: 7px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px; background: white; }
.search-box input { width: 100%; border: 0; outline: 0; background: transparent; font-size: 12px; color: var(--ink); }
.table-scroll { overflow: auto; max-height: 620px; border: 1px solid var(--line); border-radius: 13px; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th { position: sticky; top: 0; z-index: 2; padding: 11px 13px; background: #f1f0e9; color: #6d756f; font-size: 10px; text-transform: uppercase; letter-spacing: .07em; text-align: left; }
td { padding: 12px 13px; border-top: 1px solid #e8e5db; vertical-align: top; }
tbody tr:hover { background: #faf9f4; }
.numeric { text-align: right; font-variant-numeric: tabular-nums; }
.code-pill { display: inline-block; padding: 4px 7px; border-radius: 6px; background: #eceee9; font-weight: 800; }
.status-pill { display: inline-block; padding: 5px 8px; border-radius: 999px; font-size: 10px; font-weight: 800; }
.status-pill.match { color: var(--green); background: var(--green-soft); }
.status-pill.diff { color: var(--red); background: var(--red-soft); }
.status-pill.review { color: var(--amber); background: var(--amber-soft); }
.subtext { display: block; color: var(--muted); font-size: 10px; margin-top: 3px; }
.area-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.area-card { border: 1px solid var(--line); border-radius: 14px; padding: 17px; background: #faf9f4; }
.area-card span { display: block; color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .08em; }
.area-card strong { display: block; margin-top: 8px; font-size: 16px; }
.area-card b { display: block; margin-top: 14px; font: 500 30px Georgia, serif; }
.evidence-table td { max-width: 260px; word-break: break-word; }
.table-footnote { color: var(--muted); text-align: right; font-size: 11px; margin: 10px 0 0; }
.diagnostic-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.diagnostic-card { padding: 18px; border: 1px solid var(--line); border-radius: 14px; background: #faf9f4; }
.diagnostic-card header { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.diagnostic-card h4 { margin: 0; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.diagnostic-score { color: var(--green); font-weight: 800; font-size: 12px; }
.diagnostic-list { display: grid; grid-template-columns: auto 1fr; gap: 7px 12px; margin: 0; font-size: 11px; }
.diagnostic-list dt { color: var(--muted); }
.diagnostic-list dd { margin: 0; text-align: right; font-weight: 700; }

footer { display: flex; justify-content: space-between; padding: 42px 4px; color: var(--muted); font-size: 11px; }
footer span { color: var(--ink); font-weight: 800; }
footer p { margin: 0; }
.toast { position: fixed; right: 24px; bottom: 24px; max-width: 380px; padding: 14px 17px; color: white; background: var(--ink); border-radius: 12px; box-shadow: var(--shadow); font-size: 12px; z-index: 20; }

@media (max-width: 900px) {
    .drop-grid, .selection-summary { grid-template-columns: 1fr; }
    .metric-grid { grid-template-columns: 1fr 1fr; }
    .area-grid { grid-template-columns: 1fr 1fr; }
    .diagnostic-grid { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
    .app-shell { padding: 0 16px; }
    .topbar { height: 72px; }
    .source-badge { font-size: 0; padding: 10px; }
    .hero { padding: 58px 0 34px; }
    .hero h1 { font-size: 42px; }
    .upload-card, .tab-pane { padding: 20px; }
    .section-heading, .results-toolbar, .table-tools { flex-direction: column; align-items: stretch; }
    .toolbar-actions, .search-box { width: 100%; }
    .toolbar-actions > * { flex: 1; }
    .metric-grid, .area-grid { grid-template-columns: 1fr; }
    .history-row { grid-template-columns: 1fr 1fr 1fr; }
    .history-file, .history-actions { grid-column: 1 / -1; }
    .history-metric { text-align: left; }
    .verification-banner { grid-template-columns: auto 1fr; }
    .confidence { grid-column: 1 / -1; border: 0; border-top: 1px solid rgba(32,60,44,.16); padding: 10px 0 0; text-align: left; }
    footer { flex-direction: column; gap: 5px; }
}
.category-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 0 0 18px;
}

.category-chip {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--panel);
    font-size: 0.82rem;
}

.category-chip strong {
    font-size: 0.95rem;
}

.category-chip.match { border-color: #8fd0ad; }
.category-chip.review { border-color: #e2c675; }
.category-chip.diff { border-color: #e4a4a4; }
