/* Minimal admin styling: system fonts only, no external assets, no CDN. */
:root {
  color-scheme: light;
  --ink: #16181d;
  --muted: #5c6470;
  --line: #d9dde4;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --accent: #1b4dd8;
  --warn: #8a5a00;
  --warn-bg: #fff4d6;
  --error: #a4141f;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, "Helvetica Neue", Arial, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 10px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; letter-spacing: .04em; }
.topbar nav { display: flex; gap: 16px; }
.topbar nav a { color: var(--muted); padding: 4px 0; }
.topbar nav a.on { color: var(--ink); border-bottom: 2px solid var(--accent); }
.logout { margin-left: auto; }
.logout button, .filters button {
  font: inherit;
  padding: 5px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  cursor: pointer;
}
.logout button:hover, .filters button:hover { border-color: var(--accent); }

main { padding: 20px; max-width: 1500px; }
h1 { font-size: 20px; margin: 0 0 16px; }
h2 { font-size: 15px; margin: 24px 0 8px; }

footer {
  padding: 16px 20px 32px;
  color: var(--muted);
  font-size: 12px;
}

.cards { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 8px; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 16px;
  min-width: 200px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.card .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.card .value { font-size: 24px; font-weight: 600; }
.card .hint { color: var(--muted); font-size: 12px; }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 24px; }

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
th, td { padding: 6px 10px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: #eef1f5; font-weight: 600; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafbfc; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table-scroll { overflow-x: auto; }

/* /import grouped route table: one model cell spans the group's route rows, and
   every route keeps its own row, so a supplier's priority and purchase cost stay
   on the line they belong to while our price and the mode are printed once, on
   the group's first row. The spanning cell is tinted and separated so the group
   reads as one block; the name and its two-line summary live in it. Numbers use
   the shared ``.num`` grid (tabular figures). */
.import-routes .model-cell {
  background: #e6ebf2;
  border-top: 2px solid var(--line);
  vertical-align: baseline;
  padding-top: 8px;
  padding-bottom: 8px;
  text-align: left;
  white-space: normal;
}
.import-routes .model-cell .model-name { font-weight: 600; }
.import-routes .model-cell .model-meta {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
}
.import-routes .route-row td { vertical-align: top; }

/* A model family's picture in front of its name. The box is fixed whether or not
   the family has a stored file, so a name never shifts when an icon appears; the
   placeholder borrows the border colour of the page and carries no glyph (D-C53). */
.family-icon {
  width: 20px;
  height: 20px;
  object-fit: contain;
  vertical-align: middle;
  margin-right: 6px;
  border-radius: 4px;
}
.icon-placeholder { display: inline-block; background: var(--line, rgba(127,127,127,.25)); }

/* /sources is a dense index, read row by row rather than studied: one line per
   price source plus the FX contour. Only this table tightens — vertical padding
   drops 6px → 3px per cell and the line box 1.45 → 1.3, so a source row is
   ~25px instead of ~33px (18.2 + 6 + 1 border against 20.3 + 12 + 1, −8px,
   about −24%), and the merged cells (тип · метод, интервал · включён,
   прогон · время, офферы / отклонено) keep each value on one line. The shared
   table look of every other screen is untouched. */
.sources-table th,
.sources-table td { padding: 3px 8px; line-height: 1.3; }

/* The merged report: a two-level sticky header in a bounded scroller and a
   frozen model column. Both header rows carry an explicit line box and height,
   so the second level sticks flush under the first without JavaScript
   measuring anything and without the fragile guess that the first row is some
   exact pixel height. This screen also drops the reading-width cap of ``main``;
   the class sits on ``<body>`` so no other page changes. */
body.report-page main { max-width: none; }

.report-scroll {
  max-height: 72vh;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}
.report-table {
  /* The first header row's real height: 31px line box plus its 1px bottom
     border. The second row sticks at exactly this offset. */
  --report-head1: 32px;
  --report-head2: 34px;
  border: 0;
  border-radius: 0;
  /* The shared ``table`` rule clips with ``overflow: hidden`` to round the
     corners. This table has square corners, so the clip earns nothing here and
     costs the sticky header: an overflow ancestor that is not the scroller
     becomes the scrollport a sticky cell measures ``top`` against, the table
     itself never scrolls, and both header rows rode up with the rows. Visible
     leaves ``.report-scroll`` as the scrollport for both axes. */
  overflow: visible;
  border-collapse: separate;
  border-spacing: 0;
}
.report-table th,
.report-table td {
  border-bottom: 1px solid var(--line);
}
.report-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #eef1f5;
  white-space: nowrap;
}
.report-table thead tr:first-child th {
  height: var(--report-head1);
  line-height: calc(var(--report-head1) - 1px);
  padding-top: 0;
  padding-bottom: 0;
}
.report-table thead tr:nth-child(2) th {
  top: var(--report-head1);
  height: var(--report-head2);
  line-height: calc(var(--report-head2) - 1px);
  padding-top: 0;
  padding-bottom: 0;
}
.report-table thead th.col-model {
  left: 0;
  z-index: 5;
  box-shadow: inset -1px 0 0 var(--line);
}
.report-table tbody td.col-model {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--panel);
  box-shadow: inset -1px 0 0 var(--line);
}
.report-table thead th.g-model { background: #e3e8ef; }
.report-table thead th.g-cost { background: #e7ebf1; color: var(--ink); }
.report-table thead th.g-market { background: #ffffff; }
.report-table thead th.g-market-out { background: #f3f5f8; }
.report-table thead th.g-margin { background: #e7ebf1; }
.report-table thead th.g-advice {
  background: #eef1f5;
  border-left: 3px solid var(--accent);
}
/* The export decision is not a money column: it keeps the neutral header and a
   centred checkbox, so the eye can run the money columns without reading it and
   still find the one control that changes what leaves the service. */
.report-table thead th.g-export { background: #eef1f5; }
.report-table tbody td.col-export { text-align: center; background: var(--panel); }
.report-table .export-form { margin: 0; display: inline; }
.report-table .export-flag {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
  vertical-align: middle;
}
.report-table .export-save { font-size: 11px; padding: 1px 4px; }
.report-table thead th.sub { font-weight: 500; color: var(--ink); }
.report-table thead th.is-sorted { box-shadow: inset 0 -2px 0 var(--accent); }
.report-table tbody td.g-cost { background: #f7f8fa; }
.report-table tbody td.g-market-out { background: #fbfcfd; }
.report-table tbody td.g-margin { background: #f7f8fa; }
.report-table tbody tr:hover td { background: #fafbfc; }
.report-table tbody tr:hover td.col-model { background: #fafbfc; }

/* Margin severity of D-C43 tints the whole cell, not only the digits: the
   group's grey stays the base for a row whose margin is undefined. The class
   sits on the content span, so the cell is reached with ``:has``, and the same
   three rules on the span keep the tint where that selector is unavailable.
   These sit after the row hover rule on purpose: equal specificity means order
   decides, and a red cell must not turn grey under the pointer. The text keeps
   ``--ink`` and its ``.status-*`` colour, so contrast never depends on the tint. */
.report-table tbody tr td.num:has(.margin-critical) { background: #fde2e1; }
.report-table tbody tr td.num:has(.margin-warning) { background: #fff1d6; }
.report-table tbody tr td.num:has(.margin-ok) { background: #e3f4e6; }
.report-table td.num .margin-critical { background: #fde2e1; }
.report-table td.num .margin-warning { background: #fff1d6; }
.report-table td.num .margin-ok { background: #e3f4e6; }

.empty, .muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }

.badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 10px;
  font-size: 11px;
  border: 1px solid var(--warn);
  color: var(--warn);
  background: var(--warn-bg);
  white-space: nowrap;
}

.badge-neutral { border-color: var(--line); color: var(--muted); background: #f2f4f7; }

/* A planned price: the figure is calculated on the fly, not stored. The badge
   keeps that distinction visible without turning the money cell into a warning —
   a plan is a normal state of a model that has no price yet. */
.badge-plan {
  margin-left: 4px;
  padding: 0 4px;
  border-radius: 8px;
  font-size: 10.5px;
  line-height: 1.5;
  color: var(--muted);
  background: #f2f4f7;
  border: 1px solid var(--line);
  white-space: nowrap;
}

/* The two states of a matching row: the rule bound it (green) or the operator
   has to decide (amber). Colour is the second signal; the words carry the state
   on their own for a reader who cannot see it. */
.badge-matched { border-color: #9ccfae; color: #17652a; background: #e8f5ec; }
.badge-unmatched { border-color: var(--warn); color: var(--warn); background: var(--warn-bg); }


.status { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.status-success { color: #17652a; }
.status-partial { color: var(--warn); }
.status-failed { color: var(--error); }

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  padding: 12px;
  margin-bottom: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.filters label { color: var(--muted); font-size: 12px; }
.filters select, .filters input {
  font: inherit;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
}
.filters .reset { color: var(--muted); font-size: 12px; }

/* The blocked-publication panel of /import: a quiet bordered block that lists
   what the operator must fix, one reason and its plan count per line. The amber
   rule on the left is the warning signal; the words carry the instruction on
   their own, so the colour is never the only information. */
.notice {
  padding: 12px 16px;
  margin: 0 0 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 3px solid var(--warn);
  border-radius: 8px;
}
.notice p { margin: 0; }
.notice ul { margin: 8px 0 0; padding-left: 20px; }
.notice li { margin: 2px 0; }
.notice .notice-sub { margin: 8px 0 0; color: var(--muted); }

.inline-form { display: inline; }

.pager { display: flex; gap: 16px; margin: 12px 0; }

.facts {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 4px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 16px;
}
.facts dt { color: var(--muted); }
.facts dd { margin: 0; word-break: break-word; }

pre {
  margin: 0;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow-x: auto;
}
pre.raw { max-height: 420px; overflow-y: auto; }

.crumbs { margin: 0 0 8px; }

.login-page { display: grid; place-items: center; min-height: 100vh; background: var(--bg); }
.login-box {
  width: 340px;
  padding: 24px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login-box h1 { margin: 0; }
.login-box form { display: flex; flex-direction: column; gap: 8px; }
.login-box label { color: var(--muted); font-size: 12px; }
.login-box input {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
}
.login-box button {
  font: inherit;
  padding: 8px 10px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
.error { margin: 0; color: var(--error); }

.error-page { display: grid; place-items: center; min-height: 60vh; }
.error-page h1 { font-size: 40px; margin: 0 0 8px; }

/* /matching: the method summary, then one collapsible block per group of names.
   The summary is the only emphasised element; groups stay quiet so the eye can
   travel from a chip to the group it filtered. */
.match-summary { margin: 0 0 16px; }
.match-summary h2 { margin: 0 0 8px; }
.chips { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 6px; margin: 0; }
.chip {
  display: inline-block;
  padding: 3px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.chip:hover { border-color: var(--accent); text-decoration: none; }
.chip-on { border-color: var(--accent); background: #eef2ff; }
.chip-sep { color: var(--muted); }

.groups { display: flex; flex-direction: column; gap: 8px; }
.match-group {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.match-group > summary {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  align-items: baseline;
  justify-content: space-between;
  padding: 10px 14px;
  cursor: pointer;
}
.match-group > summary:hover { background: #fafbfc; }
.match-group[open] > summary { border-bottom: 1px solid var(--line); }
.match-group-head { font-weight: 600; }
.match-group-stats { color: var(--muted); font-variant-numeric: tabular-nums; }
.match-group-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  align-items: baseline;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
}

.match-names { margin: 0; padding: 0; list-style: none; }
.match-name {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.match-name:last-child { border-bottom: 0; }
.match-name-head { margin: 0; display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: baseline; }
.match-name-stats, .match-explain { margin: 0; }
.match-explain { color: var(--ink); font-variant-numeric: tabular-nums; }

.candidates { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 2px; }
.candidates .score { font-weight: 600; font-variant-numeric: tabular-nums; }
.manual .candidates { margin: 0 0 8px; }

/* The legend is four short rules, one per line: a level and what it means. */
.rule-list { margin: 0 0 8px; padding-left: 20px; color: var(--muted); }
.rule-list li + li { margin-top: 2px; }
.rule-list .mono { color: var(--ink); }

/* A row states its state once: a badge and, when a rule bound it, the model. */
.match-state { margin: 0; display: flex; flex-wrap: wrap; gap: 4px 6px; align-items: baseline; }
.match-state .badge { margin-left: 0; }
.match-model { margin: 0; }

/* Where a ``canonical`` binding came from: the registry spelling, then one
   sentence saying the dictionary — not name similarity — is the reason. */
.match-provenance { margin: 0; font-variant-numeric: tabular-nums; }
.match-provenance .muted { display: block; margin-top: 2px; max-width: 70ch; }

/* Re-binding a matched writing is a deliberate second step, so the form lives
   behind a closed disclosure with the consequence spelled out inside. */
.rebind > summary { color: var(--accent); cursor: pointer; width: fit-content; }
.rebind[open] > summary { margin-bottom: 8px; }
.rebind-warning { color: var(--warn); margin: 0 0 8px; }

.approve-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.approve-form input {
  font: inherit;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  min-width: 260px;
  max-width: 420px;
}

/* Matching v2: two tabs, a three-line explanation, and proposal blocks under a
   writing. A proposal is quiet until the eye reaches it: the kind is a label, the
   evidence is a sentence, and the two decisions sit at the end of the line. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.how { margin: 0 0 12px; }
.how h2 { margin: 0 0 4px; }

.match-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--line);
  margin: 0 0 12px;
}
.match-tab {
  padding: 7px 14px;
  color: var(--muted);
  border: 1px solid transparent;
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
}
.match-tab:hover { text-decoration: none; background: var(--panel); }
.match-tab.on {
  color: var(--ink);
  background: var(--panel);
  border-color: var(--line);
  font-weight: 600;
  margin-bottom: -1px;
}

.proposal {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 10px;
  padding: 6px 10px;
  border-left: 3px solid var(--line);
  background: #fbfcfd;
}
.proposal-kind {
  min-width: 92px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.proposal-text { flex: 1 1 320px; }
.proposal-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.proposal-actions button,
.manual button,
.reject-row button,
.rebind button,
.matched-actions button {
  font: inherit;
  padding: 3px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  cursor: pointer;
}
.proposal-actions button:hover,
.manual button:hover,
.rebind button:hover { border-color: var(--accent); }

/* The manual choice is a visible list of candidate buttons: the operator sees
   the models the page already found without opening a disclosure, and one click
   binds the spelling. The filter hides rows only; it never submits or decides. */
.manual { display: flex; flex-direction: column; gap: 6px; }
.manual-title { margin: 0; }
.manual-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
}
.manual-filter input {
  font: inherit;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  min-width: 240px;
}
.manual .candidates { list-style: none; padding-left: 0; gap: 4px; }
.manual .candidate { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: baseline; }
.candidate-form { display: inline; }
.candidate-pick { display: inline-flex; gap: 6px; align-items: baseline; }
.candidate-pick .score { color: var(--muted); font-weight: 600; }
.reject-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  align-items: baseline;
  margin-top: 2px;
}

.matched-table td { vertical-align: top; }
.matched-actions { min-width: 220px; }
.matched-actions .rebind { margin-bottom: 4px; }
.matched-actions input[type="text"] {
  font: inherit;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  min-width: 180px;
}

/* The price chain under a report row: the ladder of the price from the supplier
   cost to the final recommendation, per side. It is a second row spanning the
   table, so the money columns above stay aligned; the disclosure keeps it out of
   the way until the operator asks for it. The four share stages carry a percent
   instead of an amount because the contract folds them into the floor. */
.chain-row > td { background: #fcfdfe; border-top: 0; padding: 0 12px 8px; }
.price-chain { font-size: 13px; }
.price-chain > summary { color: var(--accent); cursor: pointer; width: fit-content; padding: 6px 0; }
.price-chain[open] > summary { margin-bottom: 6px; }
.chain-sides { display: flex; flex-wrap: wrap; gap: 8px 32px; }
.chain-side { flex: 1 1 320px; }
.chain-title { margin: 0 0 4px; font-size: 12px; color: var(--muted); font-weight: 600; }
.chain-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 8px;
  font-variant-numeric: tabular-nums;
}
.chain-list > li { display: inline-flex; align-items: baseline; gap: 4px; }
.chain-list > li + li::before { content: "→"; color: var(--muted); margin-right: 4px; }
.chain-label { color: var(--muted); }
.chain-value { font-weight: 600; }
.chain-note { color: var(--muted); font-size: 12px; }
.chain-flags { margin: 6px 0 0; display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; }
.chain-flags:empty { display: none; }
.badge-dump {
  border: 1px dashed var(--warn);
  color: var(--warn);
  background: transparent;
}
