/* Палитра: нейтральная земля, один акцент, статусные цвета только там, где
   они несут смысл (оценка, срок). Тёмная тема переопределяет токены. */
:root {
  --bg: #f6f5f2; --surface: #ffffff; --surface-2: #efeee9; --line: #dddbd3;
  --text: #1d1c19; --muted: #6b6960; --faint: #97948a;
  --accent: #1f5f4a; --accent-text: #ffffff; --accent-soft: #e3efe9;
  --good: #1f7a4d; --good-soft: #dff1e6; --warn: #9a6400; --warn-soft: #fbedcf;
  --bad: #a8322a; --bad-soft: #f9e0dd; --radius: 10px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141412; --surface: #1d1d1a; --surface-2: #272723; --line: #35342f;
    --text: #ebe9e2; --muted: #a09d92; --faint: #76736a;
    --accent: #6fc3a3; --accent-text: #10241c; --accent-soft: #1f3a30;
    --good: #6fcf97; --good-soft: #1c3527; --warn: #e5b454; --warn-soft: #3a2f16;
    --bad: #f08a80; --bad-soft: #3d1f1c;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
}
h1, h2, h3, p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* --- верхняя панель --- */
.top {
  display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; justify-content: space-between;
  padding: 14px 20px; border-bottom: 1px solid var(--line); background: var(--surface);
  position: sticky; top: 0; z-index: 5;
}
.top-title { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.top h1 { font-size: 19px; letter-spacing: -0.01em; }
.run-state { font-size: 13px; color: var(--muted); }
.run-state.stale { color: var(--warn); }
.run-state.bad { color: var(--bad); }
.top-actions { display: flex; gap: 8px; }

.btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 8px;
  padding: 7px 12px; cursor: pointer; font-size: 14px; white-space: nowrap;
}
a.btn { text-decoration: none; color: inherit; display: inline-block; }
.btn:hover { border-color: var(--faint); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
.btn.danger { color: var(--bad); }
.btn.icon { padding: 7px 10px; }
.btn.more { display: block; margin: 14px auto 28px; }

/* --- воронка --- */
.funnel { display: flex; gap: 8px; overflow-x: auto; padding: 14px 20px 4px; scrollbar-width: thin; }
.stage {
  flex: 0 0 auto; min-width: 104px; text-align: left; border: 1px solid var(--line);
  background: var(--surface); border-radius: var(--radius); padding: 9px 12px; cursor: pointer;
}
.stage .n { display: block; font-size: 21px; font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1.15; }
.stage .l { font-size: 12.5px; color: var(--muted); }
.stage.on { border-color: var(--accent); background: var(--accent-soft); }
.stage.on .l { color: var(--text); }
.stage.muted .n { color: var(--faint); font-weight: 500; }

/* --- фильтры --- */
.filters { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 20px; }
.filters input, .filters select {
  border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 8px 10px; min-width: 0;
}
.filters input { flex: 1 1 260px; }
.filters select { flex: 0 1 auto; }
input:focus-visible, select:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* --- раскладка --- */
.layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0 18px; padding: 0 20px; align-items: start; }
.layout.split { grid-template-columns: minmax(0, 1fr) minmax(360px, 460px); }
.list-head { font-size: 13px; color: var(--muted); padding: 2px 2px 8px; }
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }

.row {
  display: grid; grid-template-columns: 46px minmax(0, 1fr) auto; gap: 4px 12px; align-items: start;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 11px 14px; cursor: pointer;
}
.row:hover { border-color: var(--faint); }
.row.on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.row .name { font-weight: 550; overflow-wrap: anywhere; }
.row .who { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .meta { display: flex; flex-wrap: wrap; gap: 4px 8px; margin-top: 5px; font-size: 12.5px; color: var(--muted); }
.row .money { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.row .due { text-align: right; font-size: 12.5px; color: var(--muted); white-space: nowrap; margin-top: 2px; }
.due.soon { color: var(--warn); font-weight: 600; }
.due.now { color: var(--bad); font-weight: 600; }

.score {
  width: 40px; height: 40px; border-radius: 9px; display: grid; place-items: center;
  font-weight: 700; font-variant-numeric: tabular-nums; font-size: 15px;
  background: var(--surface-2); color: var(--faint);
}
.score.s-hi { background: var(--good-soft); color: var(--good); }
.score.s-mid { background: var(--warn-soft); color: var(--warn); }
.score.s-lo { background: var(--bad-soft); color: var(--bad); }

.tag { border-radius: 5px; padding: 1px 6px; background: var(--surface-2); color: var(--muted); font-size: 12px; white-space: nowrap; }
.tag.smp { background: var(--accent-soft); color: var(--accent); }
.tag.st-in_work, .tag.st-submitted { background: var(--accent-soft); color: var(--accent); }
.tag.st-won { background: var(--good-soft); color: var(--good); }
.tag.st-lost, .tag.st-filtered_out { background: var(--bad-soft); color: var(--bad); }

.empty { padding: 42px 16px; text-align: center; color: var(--muted); background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); }

/* --- карточка --- */
.card {
  position: sticky; top: 70px; max-height: calc(100vh - 86px); overflow: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px 20px;
}
.card-head { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; }
.card h2 { font-size: 16.5px; line-height: 1.35; overflow-wrap: anywhere; }
.card .close { flex: 0 0 auto; }
.card .sub { color: var(--muted); font-size: 13.5px; margin-top: 6px; overflow-wrap: anywhere; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 4px; }

.facts { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 5px 14px; margin: 14px 0 0; font-size: 14px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.facts .num { font-family: var(--mono); font-size: 13px; }

.block { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.block h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 8px; }
.verdict { display: flex; gap: 12px; align-items: center; }
.verdict .score { width: 48px; height: 48px; font-size: 18px; }
.verdict b { display: block; }
.verdict span { font-size: 13px; color: var(--muted); }
.rationale { margin-top: 10px; }
.signal { margin-top: 10px; padding: 9px 11px; border-left: 3px solid var(--warn); background: var(--warn-soft); border-radius: 0 7px 7px 0; font-size: 14px; }
.signal q { display: block; margin-top: 4px; color: var(--muted); font-style: italic; quotes: "«" "»"; }
.lic { margin: 8px 0 0; padding-left: 18px; font-size: 14px; }
.small { font-size: 13px; color: var(--muted); }
.gap { margin-top: 10px; }
.ok { color: var(--good); } .no { color: var(--bad); }

.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; font-size: 13.5px; }
.timeline li { display: grid; grid-template-columns: 92px minmax(0, 1fr); gap: 10px; }
.timeline time { color: var(--faint); font-variant-numeric: tabular-nums; font-size: 12.5px; padding-top: 1px; }
.timeline .why { color: var(--muted); overflow-wrap: anywhere; }

/* --- диалоги и тост --- */
.dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--text); padding: 20px; width: min(420px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(0,0,0,.45); }
.dialog h2 { font-size: 17px; margin-bottom: 8px; }
.dialog p { color: var(--muted); font-size: 14px; margin-bottom: 12px; }
.dialog input { width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 9px 11px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.error { color: var(--bad) !important; }
code { font-family: var(--mono); font-size: .92em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.toast {
  position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 9px 14px; border-radius: 9px; font-size: 14px;
  max-width: calc(100vw - 32px); z-index: 20;
}
.toast.err { background: var(--bad); color: #fff; }

/* --- телефон: карточка становится листом на весь экран --- */
@media (max-width: 860px) {
  .top { padding: 12px 16px; }
  .funnel, .filters { padding-left: 16px; padding-right: 16px; }
  .layout, .layout.split { grid-template-columns: minmax(0, 1fr); padding: 0 16px; }
  .card { position: fixed; inset: 0; max-height: none; border-radius: 0; border: 0; z-index: 10;
          padding: calc(14px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom)); }
  .row { grid-template-columns: 40px minmax(0, 1fr); }
  .row .right { grid-column: 2; display: flex; gap: 10px; align-items: baseline; }
  .row .money, .row .due { text-align: left; margin: 0; }
  .score { width: 36px; height: 36px; font-size: 14px; }
  .top-actions .btn:not(.icon) { padding: 7px 10px; font-size: 13px; }
}

/* --- позиции, характеристики, документы --- */
.pos { margin-top: 8px; }
.pos summary { cursor: pointer; font-size: 14px; }
.chars { width: 100%; border-collapse: collapse; margin-top: 6px; font-size: 13.5px; }
.chars td { padding: 4px 6px; border-top: 1px solid var(--line); vertical-align: top; overflow-wrap: anywhere; }
.chars td:first-child { color: var(--muted); width: 34%; }
.chars td:nth-child(2) { font-weight: 550; width: 26%; }
.chars .quote { color: var(--faint); font-style: italic; }
.docs { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 14px; }
.docs a { color: var(--accent); }
.signal.sev-high { border-left-color: var(--bad); background: var(--bad-soft); }
.signal.sev-low { border-left-color: var(--faint); background: var(--surface-2); }

.tag.ok { color: var(--good); background: var(--good-soft); }
.tag.warn { color: var(--warn); background: var(--warn-soft); }
.tag.no { color: var(--bad); background: var(--bad-soft); }
.warn { color: var(--warn); }
pre.rfq { white-space: pre-wrap; font: inherit; font-size: 13px; background: var(--surface-2); padding: 10px 12px; border-radius: 6px; margin: 6px 0 8px; }
.switch { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted, inherit); cursor: pointer; margin-right: 6px; white-space: nowrap; }
.dialog.wide { width: min(860px, calc(100vw - 32px)); max-height: calc(100vh - 40px); overflow: auto; }
.crit-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; }
.crit-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.crit-grid label.check { flex-direction: row; align-items: center; gap: 8px; }
.crit-grid label.check input { width: auto; }
.crit-grid textarea { width: 100%; border: 1px solid var(--line); background: var(--bg); color: var(--text); border-radius: 8px; padding: 8px 10px; font: inherit; resize: vertical; }
.crit-preview { margin-top: 14px; padding: 10px 12px; border-radius: 8px; background: var(--surface-2); font-size: 14px; }
.crit-preview ul { margin: 6px 0 0 18px; }
@media (max-width: 640px) { .crit-grid { grid-template-columns: 1fr; } }
.econ-lines { display: grid; gap: 8px; margin: 8px 0; }
.econ-line { display: grid; grid-template-columns: 1fr 90px; gap: 6px 10px; align-items: end; padding: 8px 10px; background: var(--surface-2); border-radius: 8px; }
.econ-line .manual { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; grid-column: 1 / -1; }
.econ-line label, .econ-row label { display: flex; flex-direction: column; gap: 3px; font-size: 13px; }
.econ-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 8px 0; }
.econ-line select, .econ-line input, .econ-row input { width: 100%; border: 1px solid var(--line); background: var(--bg); color: var(--text); border-radius: 7px; padding: 7px 9px; font: inherit; }
table.econ { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 8px; }
table.econ td { padding: 4px 6px; border-top: 1px solid var(--line); }
table.econ td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.econ tr.total td { font-weight: 600; }
.verdict { display: inline-block; padding: 2px 8px; border-radius: 6px; font-weight: 600; font-size: 13px; }
.verdict.go { color: var(--good); background: var(--good-soft); }
.verdict.no_go { color: var(--bad); background: var(--bad-soft); }
.verdict.incomplete { color: var(--warn); background: var(--warn-soft); }
.assume li.guess { color: var(--warn); }
.dialog .check { display: flex; align-items: flex-start; gap: 8px; font-size: 14px; margin: 6px 0; }
.dialog .check input { width: auto; margin-top: 3px; }
.set-h { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 16px 0 6px; }
#login-dialog input + input { margin-top: 8px; }
