@font-face { font-family: 'Plex Sans'; font-weight: 400; font-display: swap; src: url('fonts/ibm-plex-sans-latin-400-normal.woff2') format('woff2'); }
@font-face { font-family: 'Plex Sans'; font-weight: 500; font-display: swap; src: url('fonts/ibm-plex-sans-latin-500-normal.woff2') format('woff2'); }
@font-face { font-family: 'Plex Sans'; font-weight: 600; font-display: swap; src: url('fonts/ibm-plex-sans-latin-600-normal.woff2') format('woff2'); }
@font-face { font-family: 'Plex Mono'; font-weight: 400; font-display: swap; src: url('fonts/ibm-plex-mono-latin-400-normal.woff2') format('woff2'); }
@font-face { font-family: 'Plex Mono'; font-weight: 500; font-display: swap; src: url('fonts/ibm-plex-mono-latin-500-normal.woff2') format('woff2'); }

:root {
  --bg: #f6f5f1;
  --panel: #ffffff;
  --soft: #fbfaf7;
  --ink: #1c1f23;
  --ink-2: #3a3f45;
  --muted: #5c6168;
  --line: #dcd9d0;
  --line-2: #ebe8e0;
  --line-3: #f0eee8;
  --accent: #0f5e5a;
  --accent-dark: #0a4441;
  --accent-soft: #eef5f4;
  --red: #b3261e;
  --red-ink: #8c1d18;
  --red-soft: #fdf3f2;
  --red-chip: #fbe9e7;
  --amber: #8f5600;
  --amber-ink: #6e4300;
  --amber-soft: #fdf1dc;
  --green: #2e6b3a;
  --green-ink: #1f4d29;
  --green-soft: #e3efe5;
  --sans: 'Plex Sans', 'Helvetica Neue', Arial, sans-serif;
  --mono: 'Plex Mono', ui-monospace, Menlo, Consolas, monospace;
  --radius: 8px;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--sans); font-size: 14px; line-height: 1.45; -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
a:hover { color: var(--accent-dark); }
h1, h2, h3 { margin: 0; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.boot { padding: 40px; color: var(--muted); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 8px 14px; border-radius: 6px; border: 1px solid #c9c5b9; background: var(--panel); color: var(--ink); cursor: pointer; font-size: 13px; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: #a9a597; }
.btn:disabled { cursor: not-allowed; opacity: 1; background: #f1f0ec; color: #80858b; border-color: var(--line); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.primary:disabled { background: #dfe9e8; border-color: #b7c9c7; color: #5d7472; }
.btn.outline { border-color: var(--accent); color: var(--accent); }
.btn.danger { border-color: #e8b4ae; color: var(--red-ink); }
.btn.danger:hover { border-color: var(--red); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { min-height: 32px; padding: 5px 10px; font-size: 12px; }
.btn.big { min-height: 44px; padding: 10px 16px; font-size: 14px; }
.btn .spin { width: 14px; height: 14px; }

.tag { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 600; letter-spacing: 0.04em; padding: 2px 7px; border-radius: 4px; white-space: nowrap; }
.tag.sim { background: var(--amber-soft); color: var(--amber-ink); }
.tag.real { background: var(--green-soft); color: var(--green-ink); }
.chip { display: inline-flex; font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 4px; white-space: nowrap; }
.chip.review { background: var(--amber-soft); color: var(--amber-ink); }
.chip.blocked { background: var(--red-chip); color: var(--red-ink); }
.chip.approved { background: var(--green-soft); color: var(--green-ink); }
.chip.exported { background: #e4ecf5; color: #1d3d63; }
.chip.rejected { background: #ecebe7; color: #4a4f55; }

.spin { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--accent); animation: spin 0.8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation-duration: 2.4s; } }

/* Header */
.topbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; padding: 12px 24px; border-bottom: 1px solid var(--line); background: var(--soft); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 16px; letter-spacing: -0.01em; }
.badge { font-size: 12px; padding: 3px 8px; border: 1px solid #c9c5b9; border-radius: 4px; color: #4a4f55; }
.spacer { flex: 1 1 auto; }
.author { text-decoration: none; }
.author .by { color: var(--muted); font-weight: 400; }
.status-dot { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: #4a4f55; }
.status-dot::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: #8b8f95; }
.status-dot.on::before { background: var(--green); }

/* Guided tour */
.tour { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 12px 24px; border-bottom: 1px solid var(--line); background: var(--panel); }
.tour-head { display: flex; flex-direction: column; gap: 2px; margin-right: 6px; min-width: 150px; }
.tour-head strong { font-weight: 600; }
.tour-steps { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; flex: 1 1 640px; }
.tour-step { display: flex; align-items: center; gap: 10px; padding: 8px 12px; min-height: 48px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--panel); cursor: pointer; text-align: left; }
.tour-step:hover { border-color: #b9b5a8; }
.tour-step.current { border: 1.5px solid var(--accent); background: var(--accent-soft); }
.tour-step .num { flex: none; width: 24px; height: 24px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600; background: var(--line-2); color: var(--ink-2); }
.tour-step.current .num { background: var(--accent); color: #fff; }
.tour-step.done .num { background: var(--green); color: #fff; }
.tour-step .t { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.tour-step .t b { font-weight: 500; }
.tour-step .t span { font-size: 12px; color: var(--muted); }

/* Counts */
.counts { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); border-bottom: 1px solid var(--line); background: var(--soft); }
.count { display: flex; flex-direction: column; gap: 2px; padding: 10px 24px; border: 0; border-right: 1px solid var(--line); background: transparent; text-align: left; cursor: pointer; }
.count:last-child { border-right: 0; }
.count:hover { background: #f3f1ea; }
.count.active { background: var(--accent-soft); box-shadow: inset 0 -2px 0 var(--accent); }
.count .label { font-size: 12px; color: var(--muted); }
.count .n { font-family: var(--mono); font-size: 22px; font-weight: 500; }
.count.warn .n { color: var(--red-ink); }
.count.good .n { color: var(--green-ink); }

/* Layout */
.layout { display: grid; grid-template-columns: 300px minmax(0, 1fr) 280px; align-items: start; }
.rail { padding: 20px 18px; display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.rail.left { border-right: 1px solid var(--line); }
.rail.right { border-left: 1px solid var(--line); }
.main { padding: 20px 24px; display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.section-title { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.stack { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; align-items: center; gap: 8px; }
.between { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }

/* Upload */
.drop { border: 1.5px dashed #b9b5a8; border-radius: var(--radius); padding: 18px; display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; background: var(--soft); cursor: pointer; }
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop .link { color: var(--accent); text-decoration: underline; }

/* Inbox */
.mail { display: flex; gap: 10px; align-items: flex-start; padding: 10px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.mail.fetched { background: #f8f7f3; }
.mail .body { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.mail .subject { font-weight: 500; font-size: 13px; overflow-wrap: anywhere; }
.mail .from { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.mail .att { font-size: 12px; color: var(--ink-2); display: flex; align-items: center; gap: 4px; overflow-wrap: anywhere; }
.mail svg { flex: none; margin-top: 2px; }

/* Queue */
.qitem { display: flex; flex-direction: column; gap: 6px; padding: 10px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--panel); cursor: pointer; text-align: left; width: 100%; }
.qitem:hover { border-color: #b9b5a8; }
.qitem.selected { border: 1.5px solid var(--accent); background: var(--accent-soft); }
.qitem .l1, .qitem .l2 { display: flex; justify-content: space-between; gap: 8px; align-items: center; width: 100%; }
.qitem .sup { font-weight: 500; overflow-wrap: anywhere; }
.qitem .amt { font-family: var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
.empty { padding: 14px; border: 1px dashed var(--line); border-radius: var(--radius); color: var(--muted); font-size: 13px; text-align: center; }

/* Document header */
.doc-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px 12px; }
.doc-head h1 { font-size: 22px; font-weight: 600; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.doc-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--muted); }

/* Progress stepper */
.progress { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); overflow: hidden; }
.progress li { display: flex; gap: 8px; align-items: center; padding: 10px 12px; border-right: 1px solid var(--line-2); min-width: 0; }
.progress li:last-child { border-right: 0; }
.progress .ic { flex: none; width: 22px; height: 22px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600; background: var(--line-2); color: var(--muted); }
.progress .done .ic { background: var(--green); color: #fff; }
.progress .block { background: var(--red-soft); }
.progress .block .ic { background: var(--red); color: #fff; }
.progress .warn .ic { background: var(--amber); color: #fff; }
.progress .todo { color: var(--muted); }
.progress .t { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.progress .t b { font-weight: 500; font-size: 13px; }
.progress .t span { font-size: 12px; color: var(--muted); font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Work area */
.work { display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr); gap: 16px; align-items: start; }
.viewer { overflow: hidden; position: sticky; top: 12px; }
.viewer-bar { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 10px; border-bottom: 1px solid var(--line-2); font-size: 12px; color: var(--muted); }
.viewer-canvas { background: #efede7; padding: 16px; max-height: 78vh; overflow: auto; }
.viewer-canvas img { cursor: zoom-in; display: block; margin: 0 auto; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.14); max-width: none; }
.viewer-canvas.fit img { width: 100%; height: auto; }
.icon-btn { width: 32px; height: 32px; border: 1px solid var(--line); border-radius: 4px; background: #fff; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }

.alerts { display: flex; flex-direction: column; gap: 8px; }
.alert { border-radius: var(--radius); padding: 12px 14px; display: flex; gap: 10px; align-items: flex-start; border: 1px solid; }
.alert.blocking { border-color: #e8b4ae; background: var(--red-soft); }
.alert.warning { border-color: #ecd3a6; background: #fffaf0; }
.alert.ok { border-color: #b9d4bf; background: #f3f8f4; }
.alert .ab { display: flex; flex-direction: column; gap: 4px; min-width: 0; flex: 1 1 auto; }
.alert .at { font-weight: 600; }
.alert.blocking .at { color: var(--red-ink); }
.alert.warning .at { color: var(--amber-ink); }
.alert.ok .at { color: var(--green-ink); }
.alert .ad { font-size: 13px; color: #4a4f55; }
.alert .acts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.alert svg { flex: none; margin-top: 1px; }

.fields { display: flex; flex-direction: column; }
.fields-head, .field { display: grid; grid-template-columns: 96px minmax(0, 1fr) 76px; gap: 10px; align-items: center; padding: 7px 14px; }
.fields-head { border-bottom: 1px solid var(--line-2); font-size: 12px; color: var(--muted); }
.field { border-bottom: 1px solid var(--line-3); }
.field:last-child { border-bottom: 0; }
.field.flag { background: var(--red-soft); }
.field.lowc { background: #fffaf0; }
.field label { font-size: 13px; color: var(--ink-2); }
.field .inwrap { display: flex; gap: 6px; min-width: 0; }
.input { width: 100%; min-width: 0; min-height: 36px; padding: 6px 9px; border: 1px solid var(--line); border-radius: 6px; background: #fff; font-size: 14px; }
.input.num { font-family: var(--mono); text-align: right; font-variant-numeric: tabular-nums; }
.input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 2px rgba(15, 94, 90, 0.18); }
.input.flag { border: 1.5px solid var(--red); }
.input.lowc { border: 1.5px solid var(--amber); }
.input.dirty { background: #f4faf9; border-color: var(--accent); }
.input:disabled { background: #f6f5f1; color: var(--ink-2); }
.conf { display: flex; flex-direction: column; gap: 3px; }
.bar { height: 4px; border-radius: 2px; background: var(--line-2); overflow: hidden; }
.bar > span { display: block; height: 4px; }
.conf .src { font-size: 11px; color: var(--muted); white-space: nowrap; }
.confirm { flex: none; width: 36px; min-height: 36px; border: 1px solid var(--amber); color: var(--amber-ink); border-radius: 6px; background: #fff; cursor: pointer; }
.confirm:hover { background: var(--amber-soft); }

.table-wrap { overflow-x: auto; }
table.items { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 520px; }
table.items.vat { min-width: 0; }
table.items th { font-size: 12px; font-weight: 500; color: var(--muted); text-align: right; padding: 6px; }
table.items th:first-child, table.items td:first-child { text-align: left; padding-left: 14px; }
table.items th:last-child, table.items td:last-child { padding-right: 14px; }
table.items td { border-top: 1px solid var(--line-3); padding: 4px 6px; }
table.items td.bad { background: var(--red-soft); }
table.items .input { min-height: 32px; padding: 4px 6px; font-size: 13px; }
table.items tfoot td { font-size: 12px; color: var(--muted); padding: 8px 6px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--line-2); flex-wrap: wrap; }
.panel-head h2 { font-size: 14px; font-weight: 600; }
.ok-text { color: var(--green-ink); font-size: 12px; }
.bad-text { color: var(--red-ink); font-size: 12px; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.actions .hint { font-size: 12px; color: var(--muted); }

.audit ol { list-style: none; margin: 0; padding: 0; }
.audit li { display: grid; grid-template-columns: 96px 160px minmax(0, 1fr); gap: 12px; padding: 6px 0; border-top: 1px solid var(--line-3); font-size: 13px; }
.audit li .time { white-space: nowrap; font-family: var(--mono); color: var(--muted); font-size: 12px; }
.audit li .act { font-weight: 500; }
.audit li .det { color: var(--ink-2); overflow-wrap: anywhere; }

.metric { padding: 12px; display: flex; flex-direction: column; gap: 2px; }
.metric .v { font-family: var(--mono); font-size: 22px; font-weight: 500; font-variant-numeric: tabular-nums; }
.metric .v.na { font-family: var(--sans); font-size: 14px; color: var(--muted); font-weight: 400; padding: 5px 0; }

.export { padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.history { display: flex; flex-direction: column; gap: 6px; border-top: 1px solid var(--line-2); padding-top: 10px; }
.history .h { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }

.truth li { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; }
.truth ul { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 8px; }

/* Processing card */
.processing { padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.meter { height: 6px; border-radius: 3px; background: var(--line-2); overflow: hidden; }
.meter > span { display: block; height: 6px; background: var(--accent); transition: width 0.3s ease; }
.meter.indeterminate > span { width: 30%; animation: slide 1.2s ease-in-out infinite; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(340%); } }
.steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.steps li { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.steps .ic { flex: none; width: 20px; height: 20px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 600; }
.steps .done .ic { background: var(--green); color: #fff; }
.steps .todo .ic { border: 1px solid #c9c5b9; }
.steps .fail .ic { background: var(--red); color: #fff; }
.steps .ms { margin-left: auto; font-family: var(--mono); font-size: 12px; color: var(--muted); }

.welcome { padding: 28px; display: flex; flex-direction: column; gap: 14px; }
.welcome h1 { font-size: 24px; font-weight: 600; letter-spacing: -0.01em; }
.welcome p { margin: 0; color: var(--ink-2); max-width: 64ch; }
.welcome ol { margin: 0; padding-left: 20px; color: var(--ink-2); display: flex; flex-direction: column; gap: 4px; }

/* Dialog */
dialog { border: 1px solid var(--line); border-radius: 10px; padding: 0; max-width: 460px; width: calc(100vw - 32px); color: var(--ink); }
dialog::backdrop { background: rgba(28, 31, 35, 0.35); }
.dlg { padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.dlg h2 { font-size: 16px; font-weight: 600; }
.dlg textarea { width: 100%; min-height: 90px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; resize: vertical; }
.dlg .acts { display: flex; justify-content: flex-end; gap: 8px; }

/* Toast */
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 13px; max-width: calc(100vw - 32px); box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2); z-index: 10; }
.toast.error { background: var(--red-ink); }

.foot { padding: 16px 24px 28px; color: var(--muted); font-size: 12px; border-top: 1px solid var(--line); }

/* Responsive */
@media (max-width: 1360px) {
  .layout { grid-template-columns: 300px minmax(0, 1fr); }
  .rail.right { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: start; }
}
@media (max-width: 1100px) {
  .work { grid-template-columns: minmax(0, 1fr); }
  .viewer { position: static; }
  .viewer-canvas { max-height: 60vh; }
}
@media (max-width: 900px) {
  .topbar, .tour { padding-left: 16px; padding-right: 16px; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .rail.left { border-right: 0; border-bottom: 1px solid var(--line); }
  .rail.right { grid-template-columns: minmax(0, 1fr); }
  .main { padding: 16px; }
  .tour-steps { display: flex; overflow-x: auto; flex: 1 1 100%; padding-bottom: 4px; scroll-snap-type: x mandatory; }
  .tour-step { flex: 0 0 230px; scroll-snap-align: start; }
  .counts { display: flex; overflow-x: auto; }
  .count { flex: 0 0 auto; padding: 8px 16px; }
  .count .n { font-size: 18px; }
  .progress { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .progress li:nth-child(3) { border-right: 0; }
  .progress li:nth-child(-n+3) { border-bottom: 1px solid var(--line-2); }
  .audit li { grid-template-columns: 92px minmax(0, 1fr); }
  .audit li .det { grid-column: 2; }
}
@media (max-width: 520px) {
  .fields-head { display: none; }
  .field { grid-template-columns: minmax(0, 1fr); gap: 4px; }
  .conf { flex-direction: row; align-items: center; gap: 8px; }
  .conf .bar { flex: 1 1 auto; }
  .actions .btn { flex: 1 1 auto; }
  .topbar .badge { display: none; }
  .author .by { display: none; }
}

dialog.lightbox { max-width: min(1000px, 96vw); width: auto; max-height: 94vh; padding: 0; overflow: hidden; }
.lightbox-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 12px; border-bottom: 1px solid var(--line-2); font-size: 13px; color: var(--muted); }
.lightbox-body { overflow: auto; max-height: calc(94vh - 50px); background: #efede7; }
.lightbox-body img { display: block; max-width: 100%; height: auto; margin: 0 auto; }
