:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --ink: #14181f;
  --muted: #5d6675;
  --line: #dfe3ea;
  --accent: #0f5c4a;
  --accent-ink: #ffffff;
  --warn-bg: #fff6e5;
  --warn-ink: #7a5200;
  --good: #0f7a52;
  --mid: #b07500;
  --low: #a3341f;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151a;
    --card: #1a1f26;
    --ink: #e9edf3;
    --muted: #9aa5b5;
    --line: #2b323c;
    --accent: #3fae8f;
    --accent-ink: #08150f;
    --warn-bg: #3a2f14;
    --warn-ink: #f0cf86;
    --good: #4ec49c;
    --mid: #e0b45c;
    --low: #ef8a72;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.wrap { max-width: 880px; margin: 0 auto; padding: 0 20px; }

header {
  background: var(--accent);
  color: var(--accent-ink);
  padding: 22px 0;
  margin-bottom: 24px;
}
header h1 { margin: 0; font-size: 22px; letter-spacing: -0.01em; }
header .sub { margin: 4px 0 0; opacity: 0.85; font-size: 14px; }
.header-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.whoami { text-align: right; font-size: 14px; line-height: 1.3; white-space: nowrap; }
.whoami .who-name { display: block; opacity: 0.9; }
.whoami .signout { color: inherit; opacity: 0.75; text-decoration: underline; }
.whoami .signout:hover { opacity: 1; }

.login { max-width: 440px; margin: 48px auto; text-align: center; }
.login h2 { margin: 0 0 6px; }
.ms-signin {
  display: inline-flex; align-items: center; gap: 10px;
  margin-top: 14px; padding: 10px 18px; border-radius: 6px;
  background: var(--card); color: var(--ink); border: 1px solid var(--line);
  font-weight: 600; text-decoration: none;
}
.ms-signin:hover { border-color: var(--accent); }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 18px;
}

.tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.tab {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--muted);
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  font: inherit;
}
.tab.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.panel { display: none; }
.panel.active { display: block; }

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

label { display: block; font-size: 13px; color: var(--muted); }
input, select {
  width: 100%;
  margin-top: 4px;
  padding: 9px 10px;
  font: inherit;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 7px;
}
input[type="checkbox"] { width: auto; margin: 0 6px 0 0; }
input[type="file"] { padding: 7px; }

.checks { margin: 14px 0 4px; display: grid; gap: 6px; }
.checks label { display: flex; align-items: center; color: var(--ink); font-size: 14px; }

.hint { color: var(--muted); font-size: 13px; margin: 10px 0 0; }

button.primary {
  margin-top: 16px;
  padding: 11px 20px;
  background: var(--accent);
  color: var(--accent-ink);
  border: 0;
  border-radius: 8px;
  font: 600 15px/1 inherit;
  cursor: pointer;
}
button.primary:disabled { opacity: 0.55; cursor: progress; }

.status {
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--card);
  border: 1px solid var(--line);
  margin-bottom: 18px;
}
.status.error { background: var(--warn-bg); color: var(--warn-ink); border-color: transparent; }

.headline { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.headline .value { font-size: 34px; font-weight: 650; letter-spacing: -0.02em; }
.headline .range { color: var(--muted); }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid currentColor;
}
.badge.high { color: var(--good); }
.badge.medium { color: var(--mid); }
.badge.low, .badge.none { color: var(--low); }

.prices { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-top: 18px; }
.price-cell { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.price-cell .k { color: var(--muted); font-size: 12px; }
.price-cell .v { font-size: 18px; font-weight: 600; margin-top: 2px; }

h2 { font-size: 15px; margin: 22px 0 8px; }
ul.plain { margin: 0; padding-left: 18px; color: var(--muted); }
ul.plain li { margin-bottom: 4px; }

.warnings { background: var(--warn-bg); color: var(--warn-ink); border-radius: 8px; padding: 12px 14px 12px 30px; margin-top: 16px; }
.warnings li { margin-bottom: 5px; }

.table-scroll { overflow-x: auto; margin-top: 8px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; min-width: 640px; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; }

dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0; font-size: 14px; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; }

footer { color: var(--muted); font-size: 13px; padding: 8px 20px 40px; }
footer a { color: var(--accent); }
details.auth summary { cursor: pointer; color: var(--muted); }
details.auth label { margin-top: 10px; }

/* --- per-process decisions ------------------------------------------------ */
.decisions { display: grid; gap: 10px; }
.decision {
  border: 1px solid var(--line);
  border-left: 4px solid var(--muted);
  border-radius: 8px;
  padding: 10px 12px;
}
.decision.use { border-left-color: var(--good); }
.decision.review { border-left-color: var(--mid); }
.decision.appraise, .decision.reject { border-left-color: var(--low); }

.d-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.d-label { font-weight: 600; }
.d-price { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 600; }
.d-step { color: var(--muted); font-size: 13px; margin-top: 4px; }
.d-checks { margin: 6px 0 0; padding-left: 18px; color: var(--muted); font-size: 12.5px; }

/* The advance a valuation supports. Shown with its reason attached: a credit limit
   with no visible basis gets overridden by whoever is under pressure that day. */
.d-ltv {
  margin-top: 8px;
  padding: 8px 10px;
  border-left: 3px solid var(--accent, #3b82f6);
  background: rgba(59, 130, 246, 0.06);
  border-radius: 4px;
}
.ltv-figure { display: block; font-weight: 600; font-size: 13.5px; }
.ltv-why { display: block; margin-top: 3px; color: var(--muted); font-size: 12.5px; line-height: 1.45; }
.d-checks li { margin-bottom: 2px; }

.action {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  border: 1px solid currentColor;
}
.action.use { color: var(--good); }
.action.review { color: var(--mid); }
.action.appraise, .action.reject { color: var(--low); }
code { font-size: 12px; background: var(--bg); padding: 1px 4px; border-radius: 4px; }

/* --- measured accuracy ---------------------------------------------------- */
.accuracy { border-left: 4px solid var(--accent); }
.a-lead { margin: 0 0 4px; font-size: 14.5px; }
.a-baseline { margin: 12px 0 0; color: var(--muted); font-size: 13.5px; font-style: italic; }
.a-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-top: 14px; }
.a-tile { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.a-tile .k { color: var(--muted); font-size: 12px; }
.a-tile .v { font-size: 20px; font-weight: 650; margin: 2px 0; font-variant-numeric: tabular-nums; }
.adj { color: var(--muted); font-size: 11.5px; }

/* ---------------------------------------------------------------- report card
   The valuation reads like the dealer-desk cards the business already works from:
   one market level with the distances below it, the comparables as dots, and every
   correction named.

   No `color-mix()` anywhere below. It is unsupported in some of the browsers this form
   gets opened in, and an unsupported colour function does not degrade politely — the
   range band rendered as a solid black block and the ladder bars vanished entirely.
   Opacity on top of a token colour does the same job everywhere. */

.ladder { display: grid; gap: 6px; }
.rung {
  display: grid;
  grid-template-columns: 150px 1fr 130px 58px;
  align-items: center;
  gap: 10px;
  padding: 5px 0;
  cursor: help;
}
.rung + .rung { border-top: 1px solid var(--line); }
.rung-label { font-size: 13px; color: var(--muted); }
.rung-bar {
  height: 12px;
  background: var(--line);
  border-radius: 6px;
  overflow: hidden;
}
.rung-bar i {
  display: block;
  height: 100%;
  border-radius: 6px;
  background: var(--accent);
  opacity: 0.45;
}
/* The two levels money decisions are actually made on carry the full accent. */
.rung.market_value .rung-bar i,
.rung.quick_sale .rung-bar i { opacity: 1; }
.rung-value { font-variant-numeric: tabular-nums; font-weight: 600; text-align: right; }
.rung-drop {
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--muted);
  text-align: right;
}

.scatter-wrap { overflow-x: auto; }
.scatter-wrap svg { width: 100%; min-width: 480px; height: auto; display: block; }
.scatter-wrap .dot {
  fill: var(--accent);
  fill-opacity: 0.6;
  stroke: var(--card);
  stroke-width: 1;
}
.scatter-wrap .band { fill: var(--accent); fill-opacity: 0.1; }
.scatter-wrap .expected {
  stroke: var(--accent);
  stroke-width: 1.5;
  stroke-dasharray: 5 4;
}
.scatter-wrap .subject { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 2 3; }
.scatter-wrap .lbl { fill: var(--accent); font-size: 11px; font-weight: 600; }
.scatter-wrap .ax { fill: var(--muted); font-size: 10.5px; }
.scatter-wrap .axis-title { fill: var(--muted); font-size: 10.5px; font-style: italic; }

.adj-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.adj-table th, .adj-table td { padding: 6px 8px; border-bottom: 1px solid var(--line); }
.adj-table th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; }
.adj-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.adj-table .up { color: var(--good); }
.adj-table .down { color: var(--low); }
.adj-table .muted-cell { color: var(--muted); }

.chips-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  font-size: 12px;
  padding: 3px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
}

@media (max-width: 640px) {
  .rung { grid-template-columns: 104px 1fr 104px; }
  .rung-drop { display: none; }
}

/* Provenance of a number, shown next to it. Added after a CFO review of the five-price
   list asked "это откуда?" and three of the five had no answer — two named concepts the
   business does not use, one was asking price less an assumed haggle percentage. */
.basis { font-size: 11px; letter-spacing: 0.01em; }
.price-cell .basis { margin-top: 2px; }
.basis.observed { color: var(--good); }
.basis.validated { color: var(--accent); }
.basis.assumed { color: var(--mid); }
.rung-label .basis { display: block; font-style: normal; }

.book-table { min-width: 780px; font-size: 12.5px; }
.book-table td, .book-table th { padding: 5px 7px; white-space: nowrap; }
