:root {
  --bg: #f6f4ee; --panel: #ffffff; --ink: #1d2421; --muted: #5e6662; --line: #ddd8cb; --line-soft: #ece8dd;
  --brand: #1f4d3f; --brand-ink: #ffffff; --brand-soft: #e5eee9; --gold: #e7c66a;
  --price: #8a4a12; --price-bg: #fbeee0; --qty: #9a2f25; --qty-bg: #f8e3e1; --dup: #4a3c8c; --dup-bg: #e9e6f5;
  --check: #4f5753; --check-bg: #eceae3; --good: #1f6b45; --good-bg: #e2f1e8; --error: #a12d1b;
  --radius: 8px; --mono: "IBM Plex Mono", Consolas, monospace;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.55 "IBM Plex Sans", "Segoe UI", Arial, sans-serif; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }
h1, h2, h3 { letter-spacing: -0.01em; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* Top bar */
.bar { background: var(--panel); border-bottom: 1px solid var(--line); }
.bar-in { display: flex; align-items: center; justify-content: space-between; gap: 12px; height: 58px; }
.mark { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 18px; color: var(--ink); text-decoration: none; }
.tick { width: 14px; height: 14px; border: 2px solid var(--brand); border-radius: 2px; position: relative; }
.tick::after { content: ""; position: absolute; left: 3px; top: 0; width: 4px; height: 7px; border: solid var(--brand); border-width: 0 2px 2px 0; transform: rotate(45deg); }
.private { display: flex; align-items: center; gap: 7px; font-size: 13.5px; color: var(--brand); background: var(--brand-soft); padding: 5px 11px; border-radius: 99px; white-space: nowrap; }
.lock { width: 10px; height: 8px; background: var(--brand); border-radius: 2px; position: relative; margin-top: 4px; }
.lock::before { content: ""; position: absolute; left: 1.5px; top: -6px; width: 7px; height: 7px; border: 1.6px solid var(--brand); border-bottom: 0; border-radius: 4px 4px 0 0; box-sizing: border-box; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border-radius: 6px; border: 1.5px solid transparent;
  padding: 9px 16px; font-weight: 500; cursor: pointer; text-decoration: none; background: none; line-height: 1.3; }
.btn.primary { background: var(--brand); color: var(--brand-ink); }
.btn.primary:hover:not(:disabled) { background: #173b30; }
.btn.primary:disabled { background: #a9b8b1; cursor: not-allowed; }
.btn.ghost { border-color: var(--line); background: var(--panel); }
.btn.ghost:hover { border-color: var(--brand); color: var(--brand); }
.btn.link { color: var(--brand); padding: 6px 4px; }
.btn.link:hover { text-decoration: underline; }
.btn.big { padding: 13px 28px; font-size: 17px; }
.btn.small { padding: 5px 10px; font-size: 14px; }
.icon-btn { border: 0; background: none; font-size: 26px; line-height: 1; cursor: pointer; color: var(--muted); padding: 4px 8px; border-radius: 6px; }
.icon-btn:hover { background: var(--line-soft); color: var(--ink); }

/* Intro */
.intro { display: flex; justify-content: space-between; align-items: flex-end; gap: 24px; padding: 32px 0 20px; flex-wrap: wrap; }
.intro h1 { margin: 0 0 6px; font-size: clamp(26px, 3.5vw, 34px); font-weight: 600; }
.intro p { margin: 0; color: var(--muted); max-width: 40em; }
.intro-actions { display: flex; gap: 8px; align-items: center; }
.menu { position: relative; }
.menu summary { list-style: none; }
.menu summary::-webkit-details-marker { display: none; }
.menu-list { position: absolute; right: 0; top: calc(100% + 4px); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 10px 30px -12px rgba(20, 30, 25, .3); padding: 6px; min-width: 240px; z-index: 5; }
.menu-list button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.menu-list button:hover { background: var(--brand-soft); }

/* File cards */
.files { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.file { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; display: flex; flex-direction: column; min-width: 0; }
.file h2 { font-size: 17px; margin: 0; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.file .opt { font-size: 12.5px; font-weight: 500; color: var(--muted); border: 1px solid var(--line); border-radius: 99px; padding: 1px 8px; }
.file .what { color: var(--muted); font-size: 14.5px; margin: 4px 0 14px; }
.drop { border: 1.5px dashed #c9c2b1; border-radius: var(--radius); padding: 20px 14px; text-align: center; cursor: pointer; background: #fcfbf8;
  transition: border-color .15s, background .15s; margin-top: auto; }
.drop:hover, .drop.over { border-color: var(--brand); background: var(--brand-soft); }
.drop strong { color: var(--brand); }
.drop .formats { display: block; font-size: 13px; color: var(--muted); margin-top: 4px; }
.loaded { margin-top: auto; }
.file-name { display: flex; align-items: center; gap: 8px; font-weight: 500; min-width: 0; }
.file-name span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-meta { font-size: 14px; color: var(--muted); margin: 2px 0 10px; }
.status { display: flex; align-items: flex-start; gap: 8px; font-size: 14.5px; padding: 8px 10px; border-radius: 6px; margin-bottom: 10px; }
.status.ok { background: var(--good-bg); color: var(--good); }
.status.warn { background: var(--price-bg); color: var(--price); }
.status.bad { background: var(--qty-bg); color: var(--qty); }
.status ul { margin: 4px 0 0; padding-left: 18px; }
.file-actions { display: flex; gap: 4px; flex-wrap: wrap; }
.sheet-pick { margin-bottom: 10px; font-size: 14px; display: flex; gap: 6px; align-items: center; }
.sheet-pick select { padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; background: #fff; max-width: 100%; }
.mapping { border-top: 1px solid var(--line-soft); margin-top: 10px; padding-top: 10px; display: grid; gap: 8px; }
.map-row { display: grid; grid-template-columns: 1fr 1.25fr; gap: 8px; align-items: center; font-size: 14px; }
.map-row label { color: var(--muted); }
.map-row label b { color: var(--qty); font-weight: 600; }
.map-row select { width: 100%; padding: 5px 6px; border: 1px solid var(--line); border-radius: 6px; background: #fff; min-width: 0; }
.map-row .eg { grid-column: 2; font-family: var(--mono); font-size: 12px; color: var(--muted); margin-top: -6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Options */
.options { margin-top: 16px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.options > summary { cursor: pointer; padding: 12px 18px; font-weight: 500; }
.options-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; padding: 4px 18px 16px; }
.options label { display: grid; gap: 6px; font-size: 14.5px; color: var(--muted); }
.options input, .options select { padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink); width: 100%; }
.input-unit { display: flex; align-items: center; gap: 8px; }
.input-unit input { width: 90px; }
.input-unit span { color: var(--muted); font-size: 14px; white-space: nowrap; }
.conversions { border-top: 1px solid var(--line-soft); padding: 12px 18px 16px; }
.conversions h3 { margin: 0; font-size: 15.5px; }
.conversions p { margin: 2px 0 10px; font-size: 14px; }
.conv-table { border-collapse: collapse; width: 100%; max-width: 760px; font-size: 14px; }
.conv-table th { text-align: left; font-weight: 500; color: var(--muted); padding: 4px 6px; }
.conv-table td { padding: 3px 6px 3px 0; }
.conv-table input { padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; width: 100%; }

/* Run */
.run-row { display: flex; align-items: center; gap: 16px; margin: 22px 0 8px; flex-wrap: wrap; }
.run-row p { margin: 0; }
.error { color: var(--error); background: var(--qty-bg); padding: 10px 14px; border-radius: 6px; }

/* Results */
.results { margin-top: 26px; }
.summary { display: grid; grid-template-columns: minmax(240px, 1fr) 2fr; gap: 14px; margin-bottom: 18px; }
.headline { background: var(--brand); color: #eef3ef; border-radius: var(--radius); padding: 22px 24px; }
.headline .label { font-size: 14px; color: #c4d4cb; }
.headline .total { font-family: var(--mono); font-size: clamp(34px, 5vw, 46px); font-weight: 500; letter-spacing: -0.02em; color: #fff; line-height: 1.15; margin: 4px 0; }
.headline .muted { color: #c4d4cb; font-size: 14.5px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.stat .n { font-size: 26px; font-weight: 600; font-family: var(--mono); letter-spacing: -0.02em; }
.stat .t { font-size: 14px; color: var(--muted); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tabs button { border: 0; background: none; padding: 10px 14px; cursor: pointer; font-weight: 500; color: var(--muted); border-bottom: 2.5px solid transparent; margin-bottom: -1px; }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--brand); }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 6px; }
.toolbar input, .toolbar select { padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.toolbar input { flex: 1 1 240px; min-width: 0; }
.toolbar select { flex: 0 1 auto; max-width: 220px; }
.toolbar .btn { margin-left: auto; }

.issues { display: grid; gap: 8px; margin-top: 8px; }
.issue { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.issue.done { opacity: .62; }
.issue-head { display: grid; grid-template-columns: 190px 1fr 120px 130px; gap: 14px; align-items: center; padding: 12px 16px; cursor: pointer; }
.issue-head:hover { background: #fcfbf8; }
.issue-main { min-width: 0; }
.issue-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.issue-sub { font-size: 13.5px; color: var(--muted); font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.amount { font-family: var(--mono); font-weight: 500; text-align: right; }
.amount.zero { color: var(--muted); font-weight: 400; }
.status-select { padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: #fff; font-size: 14px; width: 100%; }
.chip { display: inline-block; font-size: 12.5px; font-weight: 600; padding: 3px 8px; border-radius: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.chip.price { background: var(--price-bg); color: var(--price); }
.chip.qty { background: var(--qty-bg); color: var(--qty); }
.chip.dup { background: var(--dup-bg); color: var(--dup); }
.chip.check { background: var(--check-bg); color: var(--check); }
.chip.good { background: var(--good-bg); color: var(--good); }
.issue-body { border-top: 1px solid var(--line-soft); padding: 14px 16px 16px; display: grid; gap: 14px; }
.explain { margin: 0; font-size: 15.5px; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 0; border: 1px solid var(--line-soft); border-radius: 6px; overflow: hidden; }
.fact { padding: 8px 12px; border-right: 1px solid var(--line-soft); }
.fact:last-child { border-right: 0; }
.fact .k { font-size: 12.5px; color: var(--muted); }
.fact .v { font-family: var(--mono); font-size: 15px; }
.fact.hot .v { color: var(--qty); font-weight: 600; }
.note { width: 100%; min-height: 60px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; resize: vertical; }
.sources summary { cursor: pointer; font-size: 14px; color: var(--brand); }
.source { margin-top: 8px; font-size: 13px; }
.source h4 { margin: 0 0 4px; font-size: 13px; font-weight: 600; }
.source-scroll { overflow-x: auto; }
.source table { border-collapse: collapse; font-family: var(--mono); font-size: 12.5px; }
.source th, .source td { border: 1px solid var(--line-soft); padding: 4px 8px; text-align: left; white-space: nowrap; }
.source th { background: #faf8f3; font-weight: 500; color: var(--muted); }
.empty { background: var(--panel); border: 1px dashed var(--line); border-radius: var(--radius); padding: 28px; text-align: center; color: var(--muted); }

.supplier-table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.suppliers { width: 100%; border-collapse: collapse; font-size: 15px; }
.suppliers th { text-align: left; font-weight: 500; font-size: 14px; color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--line); }
.suppliers td { padding: 12px 14px; border-bottom: 1px solid var(--line-soft); }
.suppliers tr:last-child td { border-bottom: 0; }
.suppliers .num { text-align: right; font-family: var(--mono); }
.suppliers td:last-child { text-align: right; }

/* Help */
.help { margin: 48px 0 24px; padding-top: 28px; border-top: 1px solid var(--line); }
.help h2 { font-size: 20px; margin: 0 0 12px; font-weight: 600; }
.help-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px; }
.help h3 { font-size: 16px; margin: 0 0 4px; }
.help p { margin: 0; color: var(--muted); font-size: 15px; }
.foot { border-top: 1px solid var(--line); padding: 18px 0 36px; font-size: 13.5px; color: var(--muted); }

/* Dispute dialog */
dialog { border: 0; border-radius: 10px; padding: 0; width: min(760px, calc(100vw - 32px)); max-height: calc(100vh - 48px); box-shadow: 0 30px 80px -20px rgba(0, 0, 0, .45); color: var(--ink); }
dialog::backdrop { background: rgba(20, 28, 24, .45); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: #fff; }
.dialog-head h2 { margin: 0; font-size: 18px; }
.letter { padding: 22px 26px; }
.letter h3 { margin: 0 0 2px; font-size: 20px; }
.letter .meta { color: var(--muted); font-size: 14px; margin-bottom: 16px; }
.letter table { width: 100%; border-collapse: collapse; font-size: 14px; margin: 10px 0; }
.letter th { text-align: left; color: var(--muted); font-weight: 500; border-bottom: 1px solid var(--line); padding: 6px 8px; }
.letter td { border-bottom: 1px solid var(--line-soft); padding: 8px; vertical-align: top; }
.letter td.num, .letter th.num { text-align: right; font-family: var(--mono); white-space: nowrap; }
.letter tfoot td { font-weight: 600; border-bottom: 0; }
.dialog-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding: 14px 18px; border-top: 1px solid var(--line); position: sticky; bottom: 0; background: #fff; }

@media (max-width: 900px) {
  .files, .help-grid { grid-template-columns: 1fr; }
  .options-grid { grid-template-columns: 1fr 1fr; }
  .summary { grid-template-columns: 1fr; }
  .issue-head { grid-template-columns: 1fr auto; grid-template-areas: "chip amount" "main main" "status status"; gap: 6px 12px; }
  .issue-head .chip-cell { grid-area: chip; }
  .issue-head .issue-main { grid-area: main; }
  .issue-head .amount { grid-area: amount; }
  .issue-head .status-cell { grid-area: status; }
  .toolbar .btn { margin-left: 0; }
}
@media (max-width: 560px) {
  .options-grid { grid-template-columns: 1fr; }
  .private { font-size: 0; padding: 7px; }
  .private .lock { margin: 4px 1px 0; }
  .intro-actions { width: 100%; }
  .letter { padding: 16px; }
}

/* Print only the dispute report */
@media print {
  body > *:not(dialog) { display: none !important; }
  dialog { position: static; box-shadow: none; width: auto; max-height: none; }
  dialog::backdrop { display: none; }
  .dialog-head, .dialog-actions { display: none; }
}
