/* Palette aligned with iishechka unifiedColorPaletteV1 (https://iishechka.itfood.space/) */
:root {
  --ink: #172033;
  --ink-soft: #344054;
  --muted: #667085;
  --line: #d9e2ef;
  --line-strong: #cfdbea;
  --surface: #ffffff;
  --surface-soft: #edf2f8;
  --bg: #f4f7fb;
  --side: #edf2f8;
  --hover: #e8eef7;
  --accent: #123b73;
  --accent-2: #0b2e5b;
  --accent-soft: #e8f0fa;
  --brand: #123b73;
  --brand-strong: #0b2e5b;
  --brand-soft: #e8f0fa;
  --warn: #a15c00;
  --bad: #b42318;
  --ok: #16794e;
  --amb: #245c9f;
  --boundary: #245c9f;
  --supplier: #eaf7f0;
  --ours: #e8f0fa;
  --shadow: 0 10px 28px rgba(22, 48, 82, 0.09);
  --radius: 20px;
  --radius-sm: 14px;
  --font: "Segoe UI", "Inter", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
}

.bg-grid {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.4;
  background-image:
    linear-gradient(rgba(18, 59, 115, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(18, 59, 115, 0.04) 1px, transparent 1px);
  background-size: 28px 28px;
  mask-image: radial-gradient(ellipse at center, black 35%, transparent 80%);
}

.page {
  position: relative;
  width: min(1680px, calc(100vw - 32px));
  max-width: none;
  margin: 0 auto;
  padding: 32px 0 80px;
}

.hero {
  margin-bottom: 28px;
}
.hero-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 12px;
}
.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(145deg, #1a4f96, var(--brand));
  box-shadow: 0 8px 20px rgba(18, 59, 115, 0.22);
  position: relative;
}
.brand-mark::after {
  content: "";
  position: absolute;
  inset: 11px;
  border: 2px solid rgba(255,255,255,0.85);
  border-radius: 6px;
  border-right-color: transparent;
  border-bottom-color: transparent;
  transform: rotate(45deg);
}
.eyebrow {
  margin: 0 0 2px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--brand);
}
.eyebrow a {
  color: inherit;
  text-decoration: none;
}
.eyebrow a:hover {
  color: var(--brand-strong);
  text-decoration: underline;
}
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 10px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--composer, var(--surface));
  color: var(--brand);
  font-size: 0.88rem;
  font-weight: 600;
  text-decoration: none;
  box-shadow: var(--brand-mark-shadow, 0 1px 2px rgba(18, 59, 115, 0.07));
}
.back-link:hover {
  background: var(--hover);
  border-color: var(--line-strong);
}
.hero h1 {
  margin: 0;
  font-size: clamp(2rem, 3.4vw, 2.6rem);
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1.05;
}
.hero-lead {
  margin: 0;
  max-width: 36rem;
  color: var(--ink-soft);
  font-size: 1.02rem;
  line-height: 1.55;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
}
.panel-head {
  margin-bottom: 22px;
}
.panel-head h2 {
  margin: 0 0 6px;
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.panel-head p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.docs-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.doc-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
  border-radius: 18px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
}
.doc-card-head {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.doc-step {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  font-size: 0.85rem;
}
.doc-card-head h3 {
  margin: 0 0 2px;
  font-size: 1.02rem;
  font-weight: 800;
}
.doc-card-head p {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.dropzone {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 6px;
  padding: 28px 18px 22px;
  border-radius: 16px;
  border: 1.5px dashed #a8b9d0;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.96), rgba(244, 247, 251, 0.9));
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease;
}
.dropzone:hover,
.dropzone.is-dragover {
  border-color: var(--brand);
  background: var(--brand-soft);
  transform: translateY(-1px);
}
.dropzone.has-file {
  border-style: solid;
  border-color: #9bb4d4;
  background: #f0f5fb;
}
.dropzone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}
.drop-icon {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  color: var(--accent);
  background: var(--accent-soft);
  margin-bottom: 4px;
}
.drop-title {
  font-weight: 700;
  color: var(--ink);
  font-size: 0.98rem;
}
.drop-sub {
  color: var(--muted);
  font-size: 0.84rem;
}
.drop-file {
  margin-top: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(18, 59, 115, 0.08);
  color: var(--brand);
  font-size: 0.8rem;
  font-weight: 700;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.key-fields {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #fff;
}
.key-fields.is-loading {
  border-color: var(--line-strong);
  background: #f7faf8;
}
.key-fields.is-ready {
  border-color: #9ec9b0;
  background: var(--brand-soft);
}
.key-fields.is-error {
  border-color: #e2b4b4;
  background: #fff7f7;
}
.key-fields-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.key-fields-head strong {
  font-size: 0.92rem;
  color: var(--ink);
}
.key-fields-status {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  font-family: "JetBrains Mono", ui-monospace, monospace;
}
.key-fields.is-ready .key-fields-status { color: var(--accent); }
.key-fields.is-error .key-fields-status { color: #b42318; }
.key-fields-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
  margin: 0;
}
.key-fields-grid > div {
  display: grid;
  gap: 2px;
  min-width: 0;
}
.key-fields-grid dt {
  margin: 0;
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 600;
}
.key-fields-grid dd {
  margin: 0;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.key-fields-note {
  margin: 10px 0 0;
  font-size: 0.78rem;
  color: var(--muted);
  line-height: 1.35;
}
@media (max-width: 640px) {
  .key-fields-grid { grid-template-columns: 1fr; }
}

.ours-1c-status {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.4;
}
.ours-1c-status.is-loading {
  border-color: #c5d8ec;
  background: #f3f8fc;
  color: var(--boundary);
}
.ours-1c-status.is-ready {
  border-color: #b9dcc8;
  background: var(--accent-soft);
  color: var(--accent);
}
.ours-1c-status.is-error {
  border-color: #f0c2bd;
  background: #fff5f4;
  color: var(--bad);
}
.ours-1c-status.is-manual {
  border-color: #d6c9e8;
  background: #f7f3fb;
  color: var(--amb);
}

.api-preview {
  border-radius: 12px;
  background: #fff;
  border: 1px solid var(--line);
  padding: 0 12px;
}
.api-preview summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 4px;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--ink-soft);
}
.api-preview summary::-webkit-details-marker { display: none; }
.api-preview summary::before {
  content: "";
  width: 7px;
  height: 7px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg);
  transition: transform 0.15s ease;
}
.api-preview[open] summary::before {
  transform: rotate(45deg);
}
.api-note {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.45;
}
.api-preview .fields-grid {
  padding-bottom: 12px;
}

.fields-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}
.field {
  display: grid;
  gap: 6px;
}
.field-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--ink-soft);
}
.field select,
.field input[type="date"] {
  font: inherit;
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  background: #fff;
  color: var(--ink);
}
.field select:focus,
.field input[type="date"]:focus {
  outline: 2px solid rgba(18, 59, 115, 0.28);
  border-color: var(--accent);
}
.period-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 8px;
  align-items: center;
}
.period-sep { color: var(--muted); font-weight: 700; }

.form-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  flex-wrap: wrap;
}

.toggle {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--accent-soft);
  border: 1px solid #c7e2d3;
  cursor: pointer;
  user-select: none;
  max-width: 420px;
}
.toggle.compact {
  padding: 8px 12px;
  background: #f1f6f2;
}
.toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.toggle-ui {
  width: 44px;
  height: 26px;
  border-radius: 999px;
  background: #b7c9be;
  position: relative;
  flex: 0 0 auto;
  transition: background 0.2s ease;
  margin-top: 1px;
}
.toggle-ui::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.16);
  transition: transform 0.2s ease;
}
.toggle input:checked + .toggle-ui { background: var(--accent); }
.toggle input:checked + .toggle-ui::after { transform: translateX(18px); }
.toggle-text {
  display: grid;
  gap: 2px;
  line-height: 1.3;
}
.toggle-text strong { font-weight: 800; }
.toggle-text small {
  color: var(--muted);
  font-size: 0.84rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  background: #e8eef8;
  color: #2a4f7a;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

button {
  appearance: none;
  border: 0;
  border-radius: 12px;
  background: var(--brand);
  color: white;
  font: inherit;
  font-weight: 700;
  padding: 13px 20px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 8px 18px rgba(18, 59, 115, 0.18);
  transition: filter 0.15s ease, transform 0.1s ease, background 0.15s ease;
}
button:hover { background: var(--brand-strong); filter: none; }
button:active { transform: translateY(1px); }
button.secondary {
  background: #fff;
  color: var(--brand);
  border: 1px solid var(--line-strong);
  box-shadow: none;
}
button.secondary:hover { background: var(--hover); }
button:disabled { opacity: 0.6; cursor: wait; box-shadow: none; }

.hint {
  color: var(--muted);
  font-size: 0.84rem;
  white-space: pre-wrap;
  margin: 0 0 12px;
  line-height: 1.45;
}
.status {
  margin-top: 16px;
  padding: 12px 14px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  white-space: pre-wrap;
  font-size: 0.88rem;
}
.hidden { display: none !important; }

.result-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 8px;
}
.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}
a.secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  border-radius: 12px;
  background: #fff;
  color: var(--brand);
  border: 1px solid var(--line-strong);
  text-decoration: none;
  font-weight: 700;
  font-size: 0.92rem;
}
.result-header h2 {
  margin: 0;
  font-size: 1.45rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}
.result-sub {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.meta { margin: 16px 0 18px; }
.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}
.meta-grid > div {
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
}
.meta-grid .k {
  display: block;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 4px;
  font-weight: 700;
}
.meta-grid .v {
  font-weight: 700;
  line-height: 1.35;
}
.meta-grid em {
  font-style: normal;
  font-weight: 600;
  color: var(--muted);
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.stat {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  background: #fff;
}
.stat .label { color: var(--muted); font-size: 0.8rem; font-weight: 600; }
.stat .value {
  font-size: 1.35rem;
  font-weight: 800;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}
.stat.ok .value { color: var(--ok); }
.stat.bad .value { color: var(--bad); }
.stat.amb .value { color: var(--amb); }
.stat.boundary .value { color: var(--boundary); }
.stat.warn .value { color: var(--warn); }

.table-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.rows-hint {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 600;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
}
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.9rem;
  min-width: 0;
  table-layout: auto;
}
#ops-table th.num,
#ops-table td.num {
  min-width: 7.2rem;
  white-space: nowrap;
}
#ops-table th.date,
#ops-table td.date {
  min-width: 6.2rem;
  white-space: nowrap;
}
#ops-table th.doc,
#ops-table td.doc {
  min-width: 8.5rem;
}
.group-date { background: #f3f1ea; color: #6a5a3a; }
.group-comment { background: #f2f4f7; color: #445060; min-width: 160px; }

.balance-row td {
  background: #f7faf8;
  font-weight: 650;
}
.balance-row.row-warn td {
  background: #fff7eb;
}
.balance-row td.balance-label {
  color: var(--boundary);
  font-weight: 750;
  letter-spacing: 0.01em;
}

.status-cell {
  min-width: 170px;
  vertical-align: middle;
}
.status-select {
  width: 100%;
  max-width: 210px;
  box-sizing: border-box;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 8px;
  font: inherit;
  font-size: 0.86rem;
  font-weight: 650;
  color: var(--ink);
  background: #fff;
  cursor: pointer;
}
.status-select:focus {
  outline: 2px solid rgba(18, 59, 115, 0.28);
  border-color: var(--accent);
}
.row-ok .status-select { color: var(--ok); }
.row-warn .status-select { color: var(--warn); }
.row-bad .status-select { color: var(--bad); }
.row-boundary .status-select { color: var(--boundary); }

.comment-cell {
  min-width: 180px;
  padding: 4px 8px !important;
  vertical-align: middle;
}
.pair-comment {
  width: 100%;
  min-width: 140px;
  box-sizing: border-box;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  font: inherit;
  font-size: 0.88rem;
  color: var(--ink);
  background: #fff;
}
.pair-comment:focus {
  outline: 2px solid rgba(18, 59, 115, 0.28);
  border-color: var(--accent);
}
.group-doc { background: #f1eef6; color: #5a4a72; }
th, td {
  padding: 11px 12px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--line);
}
thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f5f8f6;
  color: var(--muted);
  font-weight: 800;
  font-size: 0.78rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.group-row th {
  text-align: center;
  border-bottom: 1px solid var(--line);
}
.group-supplier { background: var(--supplier); color: var(--ok); }
.group-ours { background: var(--ours); color: var(--boundary); }
.party-head {
  text-transform: none;
  letter-spacing: 0;
  font-weight: 700;
  white-space: normal;
  line-height: 1.25;
  max-width: 14rem;
}
.subhead-row th { background: #eef2ef; font-weight: 700; text-transform: none; letter-spacing: 0; }
.subhead-row th:nth-child(1),
.subhead-row th:nth-child(2) { background: #f3f1ea; }
.subhead-row th:nth-child(3),
.subhead-row th:nth-child(4) { background: #f1eef6; }
.subhead-row th:nth-child(5),
.subhead-row th:nth-child(6) { background: var(--supplier); }
.subhead-row th:nth-child(7),
.subhead-row th:nth-child(8) { background: var(--ours); }

.totals-row th {
  background: #e7f2eb;
  color: var(--ink);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  border-bottom: 2px solid var(--line-strong);
  position: sticky;
  top: 70px;
  z-index: 1;
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.86rem;
  white-space: nowrap;
}
.totals-row th.num {
  font-family: var(--mono);
  white-space: nowrap !important;
}
.totals-row .sum-mismatch {
  color: var(--bad);
  background: #fdecec;
}
.totals-row .sum-ok { color: var(--ok); }

tbody tr:hover { background: #f4f8f5; }
tbody tr.empty-row {
  text-align: center;
  color: var(--muted);
}
.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-family: var(--mono);
  font-size: 0.84rem;
  white-space: nowrap;
}
.date {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  font-family: var(--mono);
  font-size: 0.84rem;
}
.doc {
  max-width: none;
  font-family: var(--mono);
  font-size: 0.84rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.money {
  white-space: nowrap !important;
  word-break: keep-all;
  overflow-wrap: normal;
}
.cell-mismatch {
  background: #fdecec !important;
  color: var(--bad);
  font-weight: 700;
}
.mismatch-stack {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  line-height: 1.25;
  white-space: nowrap;
}
.mismatch-neq {
  font-size: 0.72rem;
  opacity: 0.75;
  font-weight: 800;
}
.mismatch-a,
.mismatch-b {
  white-space: nowrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 800;
  font-size: 0.82rem;
  white-space: nowrap;
}
.badge.ok { color: var(--ok); }
.badge.bad { color: var(--bad); }
.badge.warn { color: var(--warn); }
.badge.amb { color: var(--amb); }
.badge.boundary { color: var(--boundary); }

@media (max-width: 860px) {
  .docs-grid { grid-template-columns: 1fr; }
  .form-footer { align-items: stretch; }
  .form-footer button { width: 100%; justify-content: center; }
  .toggle { max-width: none; }
  .panel { padding: 20px; }
  .result-header { flex-direction: column; align-items: stretch; }
}
