:root {
  color-scheme: light;
  --ink: #17231f;
  --muted: #66736d;
  --paper: #f4f3ee;
  --surface: #fffefa;
  --line: #d5dbd6;
  --line-strong: #b8c2bc;
  --accent: #176b52;
  --accent-dark: #0f4f3c;
  --warning: #a85408;
  --warning-bg: #fff7e8;
  --danger: #b42318;
  --danger-bg: #fff0ee;
  font-family: Arial, Helvetica, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--paper); color: var(--ink); }
.site-header { position: sticky; top: 0; z-index: 100; height: 64px; padding: 0 4vw; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); background: rgba(255,254,250,.97); }
.brand { color: var(--ink); font-weight: 760; text-decoration: none; letter-spacing: -.02em; }
.tag, .hint, .meta { color: var(--muted); }
.header-actions { display: flex; align-items: center; gap: 18px; }
.header-actions form { margin: 0; }
main { width: min(1760px, 96vw); margin: 0 auto; padding: 32px 0 64px; }
h1 { margin: 4px 0 12px; font-size: clamp(2rem, 3vw, 3rem); letter-spacing: -.045em; line-height: 1.05; }
h2 { margin: 0; font-size: .94rem; letter-spacing: .045em; text-transform: uppercase; }
.eyebrow { margin: 0 0 8px; color: var(--accent); font-size: .76rem; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; }
.lead { max-width: 650px; color: var(--muted); font-size: 1.08rem; line-height: 1.6; }

.upload-card, .login-card { max-width: 780px; margin: 5vh auto; padding: clamp(28px,5vw,64px); background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 18px 56px rgba(31,45,39,.07); }
.login-card { max-width: 520px; }
.upload-form { display: grid; gap: 20px; margin-top: 34px; }
label { display: grid; gap: 8px; font-size: .88rem; font-weight: 700; }
select, input[type=file], td input { width: 100%; border: 1px solid var(--line-strong); border-radius: 5px; background: white; color: var(--ink); font: inherit; }
select, input[type=file] { padding: 12px; }
button, .secondary-button, .text-button { min-height: 42px; border: 1px solid var(--accent); border-radius: 7px; padding: 10px 16px; background: var(--accent); color: white; font: inherit; font-weight: 750; text-decoration: none; cursor: pointer; }
button:hover { background: var(--accent-dark); }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid #60a98f; outline-offset: 2px; }
.secondary-button { display: inline-flex; align-items: center; justify-content: center; background: white; color: var(--accent-dark); }
.text-button { display: inline-flex; align-items: center; min-height: 38px; border-color: transparent; background: transparent; color: var(--accent-dark); text-decoration: underline; text-underline-offset: 3px; }
.logout-button { min-height: 36px; padding: 7px 11px; background: transparent; color: var(--accent-dark); font-size: .78rem; }
.alert { margin: 16px 0; padding: 13px 16px; border-left: 4px solid var(--warning); background: var(--warning-bg); color: #663204; }
.validation-banner { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; margin: 0 0 16px; padding: 11px 14px; border-left: 4px solid #b37a14; background: #fff8e9; font-size: .84rem; }
.validation-banner > span { color: var(--muted); }
.validation-banner ul { grid-column: 1 / -1; margin: 5px 0 0; padding-left: 20px; }
.validation-banner.has-errors { border-left-color: var(--danger); background: var(--danger-bg); }
.validation-banner.is-valid { border-left-color: var(--accent); background: #eaf6ef; }

.review-header { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.review-header h1 { overflow-wrap: anywhere; }
.document-meta { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .9rem; }
.status-pill { display: inline-flex; align-items: center; border-radius: 999px; padding: 4px 9px; font-size: .76rem; font-weight: 800; }
.status-review { background: var(--warning-bg); color: #784006; }
.status-approved { background: #e2f2e9; color: #145c44; }

.workspace { display: grid; grid-template-columns: minmax(360px,.78fr) minmax(760px,1.42fr); gap: 16px; align-items: start; }
.scan-panel, .data-panel, .summary-panel { min-width: 0; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); }
.scan-panel { position: sticky; top: 80px; padding: 14px; }
.data-panel { padding: 14px; }
.panel-heading { min-height: 32px; margin-bottom: 12px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.panel-heading > span, .panel-heading p { margin: 4px 0 0; color: var(--muted); font-size: .75rem; }
.scan-scroll { height: calc(100vh - 145px); min-height: 480px; overflow: auto; background: #deded9; border: 1px solid var(--line); }
.scan-scroll img { display: block; width: 100%; min-width: 460px; }
.table-heading { align-items: end; }
.issue-button { min-height: 36px; padding: 7px 10px; border-color: var(--line-strong); background: white; color: var(--ink); font-size: .75rem; white-space: nowrap; }
.issue-button:hover { background: #f0f3f1; }
kbd { border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 3px; padding: 1px 4px; background: #f5f5f2; font: inherit; font-size: .68rem; }

.table-scroll { overflow: auto; border: 1px solid var(--line); scrollbar-color: #9ca8a1 #edf0ed; }
.ocr-table { width: 100%; min-width: 840px; table-layout: fixed; border-collapse: collapse; background: white; }
.ocr-table .col-name { width: 24%; }
.ocr-table .col-pkwiu { width: 9%; }
.ocr-table .col-unit { width: 6%; }
.ocr-table .col-quantity { width: 9%; }
.ocr-table .col-price { width: 12%; }
.ocr-table .col-net { width: 11%; }
.ocr-table .col-vat-rate { width: 7%; }
.ocr-table .col-vat { width: 10%; }
.ocr-table .col-gross { width: 12%; }
th { position: sticky; top: 0; z-index: 2; padding: 10px 7px; background: #e8ede9; border-bottom: 1px solid var(--line-strong); color: #25322d; font-size: .67rem; line-height: 1.15; text-align: left; vertical-align: bottom; }
td { padding: 3px; border-top: 1px solid var(--line); }
.cell-editor { position: relative; }
td input { min-width: 0; height: 38px; padding: 7px 33px 7px 7px; border-color: transparent; border-radius: 3px; font-size: .83rem; }
td:not(:first-child) input { font-variant-numeric: tabular-nums; }
td small { position: absolute; top: 50%; right: 5px; transform: translateY(-50%); padding: 2px 3px; border-radius: 3px; color: var(--muted); background: rgba(255,255,255,.84); font-size: .58rem; font-variant-numeric: tabular-nums; pointer-events: none; }
td.warning { box-shadow: inset 3px 0 var(--warning); background: var(--warning-bg); }
td.warning small { color: #783d03; font-weight: 800; }
td.missing { box-shadow: inset 3px 0 var(--danger); background: var(--danger-bg); }
td.missing small { color: var(--danger); font-weight: 800; }
td.corrected { box-shadow: inset 3px 0 #29865f; background: #edf8f1; }
td.validation-error { box-shadow: inset 3px 0 var(--danger); background: var(--danger-bg); }
.row-message td { padding: 5px 10px 8px; border-top: 0; background: #fff6f3; color: #7a271a; font-size: .7rem; }
.row-message ul { display: flex; flex-wrap: wrap; gap: 3px 22px; margin: 0; padding-left: 17px; }
td input[aria-invalid="true"]:focus { outline-color: var(--warning); }
.actions { position: sticky; bottom: 10px; z-index: 10; display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; padding: 10px; border: 1px solid var(--line); border-radius: 7px; background: rgba(255,254,250,.97); box-shadow: 0 8px 24px rgba(24,39,33,.12); }
.actions > div { display: flex; gap: 8px; }
.issue-count { color: var(--muted); font-size: .78rem; font-weight: 700; }
.empty-state { padding: 28px; background: #f4f5f2; color: var(--muted); }

.summary-panel { margin-top: 16px; padding: 16px; }
.summary-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 12px; }
.summary-heading h2 { margin-bottom: 3px; }
.summary-heading span { color: var(--muted); font-size: .72rem; }
.summary-grand-total { flex: 0 0 auto; display: grid; justify-items: end; gap: 2px; }
.summary-grand-total small { color: var(--muted); font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; }
.summary-grand-total strong { font-size: 1.45rem; font-variant-numeric: tabular-nums; }
.summary-table { min-width: 1450px; border-collapse: collapse; background: white; }
.summary-table td { padding: 10px 8px; white-space: nowrap; font-size: .84rem; font-variant-numeric: tabular-nums; }
.summary-table th:first-child, .summary-table td:first-child { position: sticky; left: 0; z-index: 3; background: #f6f8f5; box-shadow: 1px 0 var(--line-strong); }
.summary-table .summary-total { background: #e5ef83; font-weight: 800; }
.summary-table td:nth-child(6) { background: #e998ba; }
.summary-table td:nth-child(9) { background: #ff912b; }

@media (max-width: 1180px) {
  .workspace { grid-template-columns: 1fr; }
  .scan-panel { position: static; }
  .scan-scroll { height: 52vh; min-height: 360px; }
}

@media (max-width: 650px) {
  .tag { display: none; }
  main { width: 94vw; padding-top: 22px; }
  .review-header, .summary-heading { align-items: start; flex-direction: column; }
  .table-heading { align-items: start; flex-direction: column; }
  .actions { align-items: stretch; flex-direction: column; }
  .actions > div { display: grid; grid-template-columns: 1fr 1fr; }
  .issue-button { width: 100%; }
  .summary-grand-total { justify-items: start; }
}
