/* VED II design system — rules in docs/ui.md.
   Layout concept: a working ledger — summary and filters on top, then aligned comparison rows. */
:root {
  --bg: #f2f4f7; --surface: #ffffff; --surface-2: #f6f8fa; --line: #dde3ea;
  --ink: #16202b; --ink-2: #5a6878;
  --accent: #0c6a8a; --accent-ink: #ffffff; --accent-soft: #e2f0f5;
  --ok: #1c7a49; --ok-soft: #e2f3e9; --warn: #955800; --warn-soft: #fbeedb;
  --bad: #b42318; --bad-soft: #fdeceb; --info: #3b58a8; --info-soft: #e7ecf8;
  --font-ui: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-num: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --r-card: 10px; --r-ctl: 8px;
  --shadow: 0 1px 2px rgb(16 32 48 / 0.06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1318; --surface: #151c23; --surface-2: #1a222b; --line: #26303b;
    --ink: #e5eaef; --ink-2: #93a1b0;
    --accent: #4fb2d3; --accent-ink: #03202b; --accent-soft: #11303b;
    --ok: #5cc48b; --ok-soft: #12301f; --warn: #e2a54a; --warn-soft: #32250e;
    --bad: #ff8b7b; --bad-soft: #3a1713; --info: #8ea7eb; --info-soft: #1a2440;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1318; --surface: #151c23; --surface-2: #1a222b; --line: #26303b;
  --ink: #e5eaef; --ink-2: #93a1b0;
  --accent: #4fb2d3; --accent-ink: #03202b; --accent-soft: #11303b;
  --ok: #5cc48b; --ok-soft: #12301f; --warn: #e2a54a; --warn-soft: #32250e;
  --bad: #ff8b7b; --bad-soft: #3a1713; --info: #8ea7eb; --info-soft: #1a2440;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.45 var(--font-ui); }
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.muted { color: var(--ink-2); }
.wrap { max-width: 1120px; margin: 0 auto; padding-inline: max(16px, env(safe-area-inset-left, 0px)) max(16px, env(safe-area-inset-right, 0px)); }

/* App header */
.app-head { background: var(--surface); border-bottom: 1px solid var(--line); }
.app-head .wrap { display: flex; align-items: center; gap: 24px; min-height: 52px; flex-wrap: wrap; }
.brand { font-weight: 600; letter-spacing: 0.02em; }
.brand span { color: var(--ink-2); font-weight: 400; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { color: var(--ink-2); text-decoration: none; padding: 6px 10px; border-radius: var(--r-ctl); font-size: 14px; }
.nav a:hover { color: var(--ink); background: var(--surface-2); }
.nav a[aria-current="page"] { color: var(--ink); background: var(--accent-soft); font-weight: 500; }
.mode { font-size: 12px; color: var(--ink-2); display: flex; align-items: center; gap: 6px; }
.mode::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ink-2); }
.mode.on::before { background: var(--ok); }

/* Page head and toolbar (sticky) */
.page-head { padding-block: 22px 6px; }
.page-head h1 { font-size: 22px; line-height: 1.25; margin: 0; font-weight: 600; text-wrap: balance; }
.page-head p { margin: 4px 0 0; color: var(--ink-2); font-size: 13px; }
.toolbar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; background: var(--bg); padding-block: 10px; border-bottom: 1px solid var(--line); }
.toolbar .wrap { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; }
.toolbar .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar .grow { flex: 1; }
.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.chip-filter { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 4px 10px; font-size: 13px; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; }
.chip-filter b { font-family: var(--font-num); font-weight: 500; color: var(--ink-2); }
.chip-filter[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip-filter[aria-pressed="true"] b { color: inherit; }
.search { border: 1px solid var(--line); background: var(--surface); border-radius: var(--r-ctl); padding: 6px 10px; min-width: 0; width: 220px; max-width: 100%; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; border-radius: var(--r-ctl); padding: 6px 12px; border: 1px solid transparent; cursor: pointer; white-space: nowrap; font-size: 14px; line-height: 1.3; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-ink); font-weight: 500; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.secondary { background: var(--accent-soft); color: var(--ink); }
.btn.secondary:hover { border-color: var(--accent); }
.btn.quiet { background: transparent; color: var(--ink-2); }
.btn.quiet:hover { color: var(--ink); background: var(--surface-2); }
.btn.danger { background: var(--bad); color: var(--surface); }
.btn .num { font-size: 13px; }
.confirm { display: inline-flex; gap: 6px; align-items: center; flex-wrap: wrap; font-size: 14px; }

/* Pills and tags */
.pill { display: inline-block; border-radius: 999px; padding: 1px 8px; font: 500 12px/1.6 var(--font-num); white-space: nowrap; }
.pill.later { background: var(--warn-soft); color: var(--warn); }
.pill.earlier { background: var(--info-soft); color: var(--info); }
.pill.new { background: var(--accent-soft); color: var(--accent); }
.tag { display: inline-block; font-size: 11px; letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-2); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; line-height: 1.6; }
.tag.bad { color: var(--bad); border-color: currentColor; }
.tag.ok { color: var(--ok); border-color: currentColor; }
.chip { font-size: 12px; color: var(--ink-2); background: var(--surface-2); border-radius: 999px; padding: 1px 8px; white-space: nowrap; }

/* Groups and comparison rows */
.section-title { display: flex; align-items: baseline; gap: 8px; font-size: 13px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-2); margin: 26px 0 8px; }
.group { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card); box-shadow: var(--shadow); margin-block: 10px; transition: opacity 0.15s; }
.group.busy { opacity: 0.55; pointer-events: none; }
.group-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.group-head h3 { margin: 0; font-size: 17px; font-weight: 600; }
.group-head .grow { flex: 1; }
.group-head .expires { font-size: 12px; color: var(--ink-2); }
.cols, .line { display: grid; grid-template-columns: minmax(150px, 1.1fr) 112px 78px minmax(220px, 2.2fr) auto; gap: 8px 14px; align-items: center; }
.cols { padding: 6px 14px 0; font-size: 11px; letter-spacing: 0.05em; text-transform: uppercase; color: var(--ink-2); }
.line { padding: 10px 14px; border-top: 1px solid var(--line); position: relative; }
.cols + .line { border-top: 0; }
.line.flagged { box-shadow: inset 3px 0 0 var(--bad); }
.line .field { font-weight: 500; min-width: 0; }
.line .field .tags { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 3px; }
.line .current { color: var(--ink-2); }
.line .proposed { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; min-width: 0; }
.line .keep { justify-self: end; }
.line .below { grid-column: 2 / -1; font-size: 13px; color: var(--ink-2); display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
.line .below .num { color: var(--ink); }
.date-other { display: inline-flex; gap: 6px; align-items: center; }
.date-other input { border: 1px solid var(--line); border-radius: var(--r-ctl); background: var(--surface); padding: 4px 6px; }
@media (max-width: 760px) {
  .cols { display: none; }
  .line { grid-template-columns: 1fr auto; }
  .line .field { grid-column: 1 / -1; }
  .line .current::before { content: "в админке "; font-size: 12px; }
  .line .proposed { grid-column: 1 / -1; }
  .line .keep { grid-column: 1 / -1; justify-self: start; }
  .line .below { grid-column: 1 / -1; }
  .search { width: 100%; }
}

/* Notices, empty state, table */
.notice { padding: 12px 14px; display: grid; gap: 10px; }
.notice p { margin: 0; }
.notice.warn p { color: var(--warn); }
.notice.bad p { color: var(--bad); }
.notice .choices { display: flex; gap: 8px; flex-wrap: wrap; }
.mail { padding: 10px 14px; display: grid; gap: 8px; }
.mail p { margin: 0; }
.mail .facts { display: flex; flex-wrap: wrap; gap: 6px; }
.page-head a { color: var(--accent); }
.empty { background: var(--surface); border: 1px dashed var(--line); border-radius: var(--r-card); padding: 18px; color: var(--ink-2); }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card); }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th { text-align: left; font-size: 11px; letter-spacing: 0.05em; text-transform: uppercase; color: var(--ink-2); font-weight: 500; padding: 8px 12px; border-bottom: 1px solid var(--line); }
table.data td { padding: 8px 12px; border-top: 1px solid var(--line); vertical-align: top; }
table.data tr:first-child td { border-top: 0; }

/* A link out (sheet row, proforma file, admin card) */
a.ext { color: var(--accent); text-decoration: none; font-size: 13px; white-space: nowrap; }
a.ext:hover { text-decoration: underline; }
a.chip.ext { font-size: 12px; }

/* «?» next to a field: where the bot took the value */
.source { display: inline-block; position: relative; vertical-align: 1px; }
.source summary { list-style: none; cursor: pointer; width: 16px; height: 16px; border-radius: 50%; border: 1px solid var(--line); color: var(--ink-2); font: 600 11px/14px var(--font-ui); text-align: center; }
.source summary::-webkit-details-marker { display: none; }
.source summary:hover, .source[open] summary { color: var(--accent); border-color: var(--accent); }
.source > div { position: absolute; z-index: 6; top: 22px; left: -8px; width: max-content; max-width: min(340px, calc(100vw - 48px)); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-ctl); box-shadow: 0 6px 20px rgb(16 32 48 / 0.14); padding: 8px 10px; font-size: 13px; font-weight: 400; color: var(--ink); line-height: 1.45; }

/* DDP: the admin against the supplier tab (/ui/ddp) */
.tag.warn { color: var(--warn); border-color: currentColor; }
.tag.info { color: var(--info); border-color: currentColor; }
.figures { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 8px; padding: 12px 14px; }
.figure { background: var(--surface-2); border-radius: var(--r-ctl); padding: 8px 12px; display: grid; gap: 2px; min-width: 0; }
.figure span { font-size: 12px; color: var(--ink-2); }
.figure b { font-size: 17px; font-weight: 500; }
.figure small { font-size: 12px; color: var(--ink-2); }
.figure.bad b { color: var(--bad); }
.figure.ok b { color: var(--ok); }
.ddp-cols, .ddp-line { display: grid; grid-template-columns: minmax(150px, 1.3fr) minmax(130px, 1fr) minmax(130px, 1fr) minmax(150px, 1.1fr) 112px; gap: 4px 14px; align-items: start; }
.ddp-cols { padding: 6px 14px 4px; font-size: 11px; letter-spacing: 0.05em; text-transform: uppercase; color: var(--ink-2); border-top: 1px solid var(--line); }
.ddp-line { padding: 8px 14px; border-top: 1px solid var(--line); }
.ddp-line.calm { color: var(--ink-2); }
.ddp-line.flagged { box-shadow: inset 3px 0 0 var(--bad); }
.ddp-line .amount { display: grid; gap: 1px; min-width: 0; }
.ddp-line .amount small, .ddp-line .label small { font-size: 12px; color: var(--ink-2); }
.ddp-line .label { display: grid; gap: 2px; font-weight: 500; }
.ddp-line .verdict { justify-self: end; }
.ddp-rest { padding: 8px 14px 12px; border-top: 1px solid var(--line); font-size: 13px; color: var(--ink-2); display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.diff-bar { position: relative; display: block; height: 4px; margin-top: 4px; background: var(--surface-2); border-radius: 2px; overflow: hidden; }
.diff-bar::after { content: ""; position: absolute; left: 50%; top: 0; bottom: 0; width: 1px; background: var(--line); }
.diff-bar i { position: absolute; top: 0; bottom: 0; background: var(--ink-2); border-radius: 2px; }
.diff-bar.bad i { background: var(--bad); }
.diff-bar.info i { background: var(--info); }
@media (max-width: 760px) {
  .ddp-cols { display: none; }
  .ddp-line { grid-template-columns: 1fr 1fr; }
  .ddp-line .label { grid-column: 1 / -1; }
  .ddp-line .amount::before { content: attr(data-side); font-size: 11px; color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.05em; }
  .ddp-line .verdict { justify-self: start; }
}

/* The excursion (/ui/guide): the data path, then numbered steps */
.flow { display: flex; flex-wrap: wrap; align-items: stretch; gap: 6px; margin-block: 12px 4px; }
.flow-box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card); padding: 8px 12px; display: grid; gap: 2px; flex: 1 1 140px; min-width: 0; }
.flow-box b { font-size: 14px; font-weight: 600; }
.flow-box span { font-size: 12px; color: var(--ink-2); }
.flow-arrow { align-self: center; color: var(--ink-2); }
.step-no { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font: 600 13px/1 var(--font-num); }
.step-body { padding: 4px 14px 14px; display: grid; gap: 10px; }
.step-body .lead { margin: 6px 0 0; color: var(--ink-2); font-size: 14px; max-width: 75ch; }
.step-body .table-wrap { box-shadow: none; }
.step-body .notice { padding: 0; }
.step-body ul.below { margin: 4px 0 0; padding-left: 18px; font-size: 14px; }
select.search { width: auto; min-width: 200px; }
@media (max-width: 760px) { .flow-arrow { display: none; } .flow-box { flex-basis: 100%; } }

/* Toast */
#toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translate(-50%, 8px); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: var(--r-ctl); opacity: 0; transition: opacity 0.18s, transform 0.18s; pointer-events: none; max-width: calc(100vw - 32px); font-size: 14px; z-index: 20; }
#toast.show { opacity: 0.96; transform: translate(-50%, 0); }
#toast.bad { background: var(--bad); color: var(--surface); }
main { padding-bottom: 80px; }
main h2 { font-size: 15px; font-weight: 600; margin: 22px 0 8px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* Owner's login (T-44) */
.login { display: grid; gap: 12px; max-width: 320px; margin-block: 48px; }
.login input { font: inherit; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--surface); color: inherit; }

/* Feedback on a draft: a quiet disclosure under the card, the developer's channel. */
button, input, select, textarea { font: inherit; color: inherit; }
a.chip.warn { color: var(--warn); background: var(--warn-soft); text-decoration: none; }
details.feedback { border-top: 1px dashed var(--line); margin-top: 8px; padding-top: 6px; }
details.feedback > summary { cursor: pointer; font-size: 13px; color: var(--ink-2); width: max-content; }
details.feedback[open] > summary { color: var(--ink); }
.feedback-form { display: grid; gap: 8px; margin-top: 8px; max-width: 640px; }
.feedback-form select, .feedback-form textarea { border: 1px solid var(--line); border-radius: var(--r-ctl); background: var(--surface); padding: 6px 8px; width: 100%; }
.feedback-form textarea { resize: vertical; min-height: 64px; }
.feedback-form .btn { justify-self: start; }
.feedback-form .muted { font-size: 12px; }
table.data tr.flagged td { background: var(--warn-soft); }

/* «Плановые даты»: a number in force, its source, the hand value under it */
.plan-days td { vertical-align: top; }
.plan-days input.days { margin-top: 6px; width: 7em; border: 1px solid var(--line); border-radius: var(--r-ctl); background: var(--surface); color: inherit; padding: 4px 8px; font: inherit; }
.group > .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 12px; }
