:root {
  --bg: #f4f5f7; --surface: #fff; --text: #1d2330; --muted: #6a7385; --line: #dfe3ea;
  --accent: #1f5fd6; --accent-text: #fff; --ok: #1d7a46; --ok-bg: #e5f5ec;
  --warn: #8a5a00; --warn-bg: #fff4d6; --err: #b3261e; --err-bg: #fde7e5; --info-bg: #e8effc;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171d; --surface: #1d222b; --text: #e6e9ef; --muted: #98a1b3; --line: #313846;
    --accent: #6ea0ff; --accent-text: #0b1220; --ok: #6bd39a; --ok-bg: #163224;
    --warn: #f0c46a; --warn-bg: #3a2e14; --err: #ff9a92; --err-bg: #3d1d1b; --info-bg: #1c2740;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 16px/1.45 system-ui, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
.hidden { display: none !important; }
.center { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
h1 { font-size: 22px; margin: 0 0 4px; } h2 { font-size: 18px; margin: 0 0 12px; } h3 { font-size: 16px; margin: 16px 0 8px; }
.muted { color: var(--muted); } .error { color: var(--err); min-height: 1.2em; }

header { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 20px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; }
nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
nav button { background: none; border: 0; padding: 10px 14px; border-radius: 8px; color: var(--muted); font-size: 16px; cursor: pointer; }
nav button.active { background: var(--info-bg); color: var(--accent); font-weight: 600; }
.who { color: var(--muted); font-size: 14px; }
main { max-width: 1360px; margin: 0 auto; padding: 16px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 16px; }
.login { width: 100%; max-width: 360px; display: grid; gap: 12px; }
label { display: grid; gap: 4px; font-size: 14px; color: var(--muted); }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; min-height: 44px; width: 100%; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type=checkbox] { width: 22px; height: 22px; min-height: 0; }
button { font: inherit; min-height: 44px; padding: 0 16px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--text); cursor: pointer; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--err); }
button.link { border: 0; background: none; min-height: 0; padding: 0; color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }

.row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); align-items: end; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 12px; }
.drop { border: 2px dashed var(--line); border-radius: 12px; padding: 28px 16px; text-align: center; color: var(--muted); cursor: pointer; margin: 12px 0; }
.drop.over { border-color: var(--accent); background: var(--info-bg); }

.pill { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: 13px; background: var(--info-bg); color: var(--accent); white-space: nowrap; }
.pill.created { background: var(--ok-bg); color: var(--ok); } .pill.error { background: var(--err-bg); color: var(--err); }
.pill.recognizing, .pill.new { background: var(--warn-bg); color: var(--warn); }
.notice { padding: 10px 12px; border-radius: 8px; margin: 8px 0; }
.notice.warn { background: var(--warn-bg); color: var(--warn); } .notice.ok { background: var(--ok-bg); color: var(--ok); } .notice.err { background: var(--err-bg); color: var(--err); }

.doc-head { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; cursor: pointer; }
.doc-head .name { font-weight: 600; flex: 1; min-width: 160px; word-break: break-all; }
.review { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); margin-top: 12px; }
@media (min-width: 980px) { .review { grid-template-columns: 300px minmax(0, 1fr); } }
.scan img { width: 100%; border-radius: 8px; border: 1px solid var(--line); }
.scan { position: sticky; top: 70px; align-self: start; }
.grid2 { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th, td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: 13px; }
td input, td select { min-height: 38px; padding: 6px 8px; min-width: 80px; }
td.num input { text-align: right; min-width: 90px; }
.newnom { display: grid; gap: 6px; margin-top: 6px; grid-template-columns: 1fr 110px 80px; }
.totals { text-align: right; margin: 8px 0; font-weight: 600; }
.toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 10px; z-index: 20; max-width: 90vw; }
.modal-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, .5); overflow-y: auto; z-index: 30; padding: 16px; }
.modal { max-width: 1180px; margin: 0 auto; background: var(--bg); border-radius: 12px; padding: 12px; }
.modal-bar { position: sticky; top: 0; z-index: 2; background: var(--bg); padding-bottom: 8px; }
.modal .scan { top: 56px; }
/* История: компактная таблица, одна строка на документ, длинное обрезается (полный текст во всплывающей подсказке) */
.card.hist { padding: 4px 8px 8px; }
.hist table { border-collapse: separate; border-spacing: 0; }
.hist thead th { position: sticky; top: 0; background: var(--surface); font-size: 12px; text-transform: uppercase; letter-spacing: .04em;
  padding: 10px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.hist tbody td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; }
.hist tbody tr { cursor: pointer; }
.hist tbody tr:hover td { background: var(--info-bg); }
.hist tbody tr:last-child td { border-bottom: 0; }
.hist td.file { max-width: 130px; color: var(--muted); font-size: 13px; }
.hist td.supplier { max-width: 250px; }
.hist td.doc { max-width: 230px; }
.hist td.doc-err { color: var(--err); font-size: 13px; }
.hist td.muted-cell { color: var(--muted); font-size: 13px; }
.hist td.num, .hist th.num { text-align: right; }
.hist td.strong { font-weight: 600; }
.hist td.act, .hist th:last-child { width: 36px; text-align: center; }
.hist-foot { padding: 8px 10px 0; font-size: 13px; }
.warn-count { margin-left: 6px; font-size: 12px; color: var(--warn); background: var(--warn-bg); padding: 1px 7px; border-radius: 99px; }
button.icon-del { min-height: 28px; width: 28px; padding: 0; border: 0; background: none; color: var(--muted); border-radius: 6px; }
button.icon-del:hover { background: var(--err-bg); color: var(--err); }
.pill.unposted { background: var(--warn-bg); color: var(--warn); }
.pill.deleted { background: var(--err-bg); color: var(--err); text-decoration: line-through; }
td.num { text-align: right; white-space: nowrap; }
.pill.duplicate { background: var(--warn-bg); color: var(--warn); }
.notice.clickable { cursor: pointer; }
.notice.clickable:hover { filter: brightness(.95); }
a.btn-link { display: inline-block; padding: 8px 14px; border-radius: 8px; background: var(--accent); color: var(--accent-text); text-decoration: none; font-weight: 600; }
.auto-nom { font-size: 14px; color: var(--ok); margin: 4px 0; }
.card.batch { border-color: var(--accent); }
.doc-head input[type=checkbox] { flex: none; }
.inline { display: flex; gap: 8px; align-items: center; } .inline label { display: flex; gap: 8px; align-items: center; color: var(--text); font-size: 16px; }

/* история: выбор строк и панель массовых действий */
.bulkbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; position: sticky; top: 8px; z-index: 5; padding: 10px 16px; border-color: var(--accent); }
.bulkbar select { max-width: 280px; }
th.chk, td.chk { width: 32px; padding-left: 10px; padding-right: 0; }
td.chk input, th.chk input { cursor: pointer; }
