/* Топливный антифрод — общая дизайн-система.
   Один акцент (оранжевый), светлая/тёмная тема по prefers-color-scheme,
   без внешних шрифтов/либ. Плотная типографика инженерного справочника. */

:root {
  color-scheme: light;

  /* поверхности */
  --bg: #f7f7f5;
  --bg-elevated: #ffffff;
  --bg-inset: #eef0f2;

  /* текст */
  --text: #14202c;
  --text-dim: #4b5563;
  --text-muted: #6b7280;

  /* линии */
  --border: #dde1e6;
  --border-strong: #c3c9d1;

  /* бренд-акцент (один) */
  --accent: #b35900;       /* текст/ссылки — 4.8:1 на --bg */
  --accent-bg: #e8820c;    /* заливки/бейджи */
  --accent-contrast: #14202c;
  --accent-soft: #fbe6c8;  /* лёгкая подложка под акцент на светлом фоне */

  /* статусы — только со смысловой меткой, не цветом-в-одиночку */
  --ok: #157a37;
  --warn: #8a5300;
  --danger: #b3261e;
  --info: #0969da;
  --ok-soft: #e3f3e6;
  --warn-soft: #f6e9d6;
  --danger-soft: #fbe4e2;
  --info-soft: #ddedfd;

  --code-bg: #eef1f4;
  --code-border: #d7dce2;

  --radius: 6px;
  --mono: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;

    --bg: #0c2436;
    --bg-elevated: #102a3e;
    --bg-inset: #0a1e2d;

    --text: #eaf2f4;
    --text-dim: #a8c4c6;
    --text-muted: #82999b;

    --border: #1f3f57;
    --border-strong: #2a4d67;

    --accent: #e8820c;      /* 5.8:1 на --bg тёмного режима */
    --accent-bg: #e8820c;
    --accent-contrast: #14202c;
    --accent-soft: #2c2210;

    --ok: #3fb950;
    --warn: #d29922;
    --danger: #f85149;
    --info: #58a6ff;
    --ok-soft: #113019;
    --warn-soft: #332608;
    --danger-soft: #3a1615;
    --info-soft: #0e2740;

    --code-bg: #0a1e2d;
    --code-border: #1f3f57;
  }
}

* { box-sizing: border-box; }
html {
  -webkit-text-size-adjust: 100%;
  /* sticky .site-nav (~61px на десктопе) не должна перекрывать цель якорной ссылки/#hash-навигации */
  scroll-padding-top: 72px;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
a:focus-visible, button:focus-visible, input:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent-bg);
  outline-offset: 2px;
}

/* ---------- шапка/навигация ---------- */

.site-nav {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 18px;
  padding: 12px 24px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.site-nav__home {
  font-size: 13px;
  color: var(--text-muted);
  text-decoration: none;
  white-space: nowrap;
}
.site-nav__home:hover { color: var(--accent); }

.site-nav__brand {
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
  margin-right: auto;
}

.site-nav__links {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 4px;
  list-style: none;
  margin: 0;
  padding: 0;
}
.site-nav__links a {
  display: inline-block;
  padding: 6px 10px;
  border-radius: var(--radius);
  color: var(--text-dim);
  text-decoration: none;
  font-size: 13px;
  white-space: nowrap;
}
.site-nav__links a:hover { background: var(--bg-inset); color: var(--text); }
.site-nav__links a[aria-current="page"] {
  color: var(--accent-contrast);
  background: var(--accent-bg);
  font-weight: 600;
}

/* ---------- контейнеры ---------- */

.page {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 24px 64px;
}

.prose { max-width: 74ch; }

header.page-head { margin-bottom: 28px; }
header.page-head h1 { margin: 0 0 8px; font-size: 28px; letter-spacing: -0.01em; }
header.page-head .lede { margin: 0; color: var(--text-dim); max-width: 74ch; font-size: 15px; }

section { margin: 40px 0; }
section > h2 {
  font-size: 20px;
  margin: 0 0 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
section > h3 { font-size: 16px; font-weight: 600; margin: 20px 0 8px; }

p { margin: 0 0 12px; }
ul, ol { margin: 0 0 12px; padding-left: 22px; }
li { margin-bottom: 4px; }

.tabular { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); }

/* ---------- таблицы ---------- */

.table-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); padding: 8px; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  background: var(--bg-elevated);
}
caption {
  text-align: left;
  font-size: 12px;
  color: var(--text-muted);
  padding: 8px 12px 0;
}
th, td {
  text-align: left;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
thead th {
  background: var(--bg-inset);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--text-muted);
  white-space: nowrap;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--bg-inset); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- бейджи статусов ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid transparent;
}
.badge--ok      { color: var(--ok);      background: var(--ok-soft); }
.badge--warn    { color: var(--warn);    background: var(--warn-soft); }
.badge--danger  { color: var(--danger);  background: var(--danger-soft); }
.badge--info    { color: var(--info);    background: var(--info-soft); }

/* ---------- статистика (плитки-факты, без иконок) ---------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.stat-tile {
  background: var(--bg-elevated);
  padding: 16px 16px;
}
.stat-tile__value {
  font-family: var(--mono);
  font-size: 28px;
  font-weight: 700;
  line-height: 1.1;
}
.stat-tile__value.is-danger { color: var(--danger); }
.stat-tile__value.is-warn { color: var(--warn); }
.stat-tile__value.is-ok { color: var(--ok); }
.stat-tile__label {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

/* ---------- карточки детекторов ---------- */

.detector {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  margin-bottom: 12px;
}
.detector__head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px 14px;
  padding: 14px 16px;
}
.detector__id {
  font-family: var(--mono);
  font-weight: 700;
  color: var(--accent);
}
.detector__title { font-weight: 600; }
.detector__weight {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-muted);
}
.detector__confirmed {
  font-size: 12px;
  font-weight: 600;
  color: var(--ok);
  white-space: nowrap;
}
.detector__body { padding: 0 16px 16px; }
.detector__desc { color: var(--text-dim); margin: 0 0 10px; }
.detector__threshold {
  display: flex;
  gap: 8px;
  align-items: baseline;
  font-size: 13px;
  margin: 0 0 12px;
  padding: 8px 12px;
  background: var(--bg-inset);
  border-radius: var(--radius);
}
.detector__threshold b { color: var(--text); font-weight: 600; }
.detector__threshold span { font-family: var(--mono); }

.detector__algo {
  margin: 0 0 12px;
  padding-left: 20px;
  color: var(--text-dim);
  font-size: 13.5px;
  line-height: 1.55;
  display: grid;
  gap: 4px;
}
.detector__case {
  margin: 0 0 12px;
  padding: 10px 12px;
  background: var(--bg-inset);
  border-radius: var(--radius);
  font-size: 13.5px;
}
.detector__case b { color: var(--accent); }

details.sql-details > summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--text-dim);
  padding: 4px 0;
  user-select: none;
}
details.sql-details > summary:hover { color: var(--text); }
details.sql-details[open] > summary { margin-bottom: 8px; }

/* ---------- код/SQL ---------- */

pre {
  margin: 0;
  padding: 14px 16px;
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: var(--radius);
  overflow-x: auto;
  font-size: 12px;
  line-height: 1.6;
}
pre, code { font-family: var(--mono); }
code.inline {
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 0.9em;
}

/* токены SQL-подсветки (проставляются JS-хайлайтером, assets/sql-highlight.js) */
.tok-kw   { color: var(--accent); font-weight: 600; }
.tok-fn   { color: var(--info); }
.tok-str  { color: var(--ok); }
.tok-num  { color: var(--warn); }
.tok-com  { color: var(--text-muted); font-style: italic; }
.tok-ident{ color: var(--text); }

/* ---------- списки-ссылки на секции сайта ---------- */

.link-index { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.link-index li {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
}
.link-index a {
  display: block;
  padding: 14px 16px;
  text-decoration: none;
  color: var(--text);
}
.link-index a:hover { background: var(--bg-inset); }
.link-index .t { font-weight: 600; color: var(--accent); }
.link-index .d { display: block; margin-top: 3px; font-size: 13px; color: var(--text-dim); }

/* ---------- меры/гейджи ---------- */

.meter {
  position: relative;
  height: 22px;
  margin-bottom: 20px; /* место под подписи меток, которые сидят ниже трека */
}
.meter__track {
  position: relative;
  height: 100%;
  border-radius: 999px;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  overflow: hidden; /* клипует только заливку, не подписи меток снаружи */
}
.meter__fill {
  position: absolute;
  inset: 0;
  width: 100%;
  transform: scaleX(0);
  transform-origin: left;
  background: var(--info);
  transition: transform .2s linear, background-color .2s linear;
}
.meter__fill.is-ok { background: var(--ok); }
.meter__fill.is-warn { background: var(--warn); }
.meter__fill.is-danger { background: var(--danger); }
.meter__zones {
  /* статичные немые зоны (index.html) — не анимируются, поэтому не подпадают под layout-transition */
  position: absolute;
  inset: 0;
  width: 100%;
}
.meter__marks { position: absolute; inset: 0; }
.meter__mark {
  position: absolute;
  top: 0; bottom: 0;
  width: 1px;
  background: var(--border-strong);
}
.meter__mark::after {
  content: attr(data-label);
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  margin-top: 2px;
}

/* ---------- заметки/дисклеймеры ---------- */

.callout {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  padding: 12px 16px;
  font-size: 13px;
  color: var(--text-dim);
}
.callout b { color: var(--text); }
.callout--danger { border-color: var(--danger); }

.footnote {
  margin-top: 40px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
}

/* ---------- утилиты ---------- */

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

.vis-hidden {
  position: absolute; width: 1px; height: 1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap;
}

/* ---------- inline SVG-диаграмма связей (schema.html) ---------- */

.diagram { width: 100%; height: auto; display: block; }
.diagram .edge { stroke: var(--border-strong); stroke-width: 1.5; fill: none; }
.diagram .edge-label {
  font-family: var(--sans);
  font-size: 11px;
  fill: var(--text-muted);
}
.diagram .edge-label rect { fill: var(--bg); }
.diagram .node rect {
  fill: var(--bg-elevated);
  stroke: var(--border-strong);
  stroke-width: 1.5;
}
.diagram .node.hub rect { stroke: var(--accent-bg); stroke-width: 2.5; }
.diagram .node text {
  fill: var(--text);
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 600;
  text-anchor: middle;
}
.diagram .node .sub {
  fill: var(--text-muted);
  font-size: 11px;
  font-weight: 400;
}
.diagram marker path { fill: var(--border-strong); }

/* ---------- tz.html: варианты архитектуры ---------- */

.arch-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
  align-items: start;
}
.arch-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  padding: 16px;
}
.arch-card.is-recommended { border: 2px solid var(--accent-bg); padding: 15px; }
.arch-card__badge {
  display: inline-block;
  background: var(--accent-bg);
  color: var(--accent-contrast);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 2px 8px;
  border-radius: 4px;
  margin-bottom: 10px;
}
.arch-card__title { font-weight: 700; font-size: 15px; margin: 0 0 8px; }
.arch-card ul { margin: 0 0 10px; padding-left: 20px; font-size: 13px; }
.arch-card p { font-size: 13px; }
.arch-card .list-plus li::marker { color: var(--ok); }
.arch-card .list-minus li::marker { color: var(--danger); }
.arch-card__verdict {
  margin: 10px 0 0;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-dim);
}

/* ---------- fraud.html: анимация 4 актов ---------- */

.act-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
}
.act-tabs button {
  font: inherit;
  font-size: 13px;
  padding: 8px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-dim);
  cursor: pointer;
}
.act-tabs button:hover { border-color: var(--border-strong); color: var(--text); }
.act-tabs button[aria-selected="true"] {
  background: var(--accent-bg);
  border-color: var(--accent-bg);
  color: var(--accent-contrast);
  font-weight: 600;
}

.controls-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  padding: 12px 14px;
  margin-bottom: 20px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.controls-bar__scrub { display: flex; align-items: center; gap: 8px; flex: 1 1 240px; min-width: 200px; }
.controls-bar__scrub input[type="range"] { flex: 1; accent-color: var(--accent-bg); }
.controls-bar__readout { font-family: var(--mono); font-size: 12px; color: var(--text-dim); white-space: nowrap; min-width: 11ch; }
.controls-bar button.play {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 7px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--accent-bg);
  background: var(--accent-bg);
  color: var(--accent-contrast);
  cursor: pointer;
}
.controls-bar__speed { display: flex; gap: 4px; }
.controls-bar__speed button {
  font: inherit;
  font-size: 12px;
  padding: 5px 9px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-dim);
  cursor: pointer;
}
.controls-bar__speed button[aria-pressed="true"] { border-color: var(--accent-bg); color: var(--accent); font-weight: 600; }

.act-panel[hidden] { display: none; }

.legend-row { display: flex; flex-wrap: wrap; gap: 16px; margin-bottom: 10px; font-size: 12px; color: var(--text-dim); }
.legend-row .swatch { display: inline-flex; align-items: center; gap: 6px; }
.legend-row .dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

.big-counter {
  font-family: var(--mono);
  font-size: 34px;
  font-weight: 700;
  font-variant-numeric: proportional-nums;
  color: var(--danger);
}
.big-counter__label { font-size: 12px; color: var(--text-muted); margin-bottom: 2px; }

.act1-layout, .act2-layout { display: grid; grid-template-columns: 1fr; gap: 18px; }
@media (min-width: 780px) {
  .act1-layout { grid-template-columns: 1fr 220px; align-items: start; }
}

.tx-dot--burst { fill: var(--danger); }
.tx-dot--quiet { fill: var(--warn); }
.tx-dot--bg { fill: var(--text-muted); opacity: .55; }
.cum-line { stroke: var(--danger); stroke-width: 2; fill: none; }

.loss-estimate {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 14px;
  padding: 8px 12px;
  background: var(--bg-inset);
  border-radius: var(--radius);
}
.loss-estimate__label { font-size: 12px; color: var(--text-muted); }
.loss-estimate__value { font-family: var(--mono); font-weight: 700; color: var(--warn); font-size: 16px; }

.detector-panel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}
.detector-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  padding: 10px 12px;
  transition: background-color .25s, border-color .25s;
}
.detector-card__id { font-family: var(--mono); font-weight: 700; color: var(--text-muted); font-size: 12px; }
.detector-card__name { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.detector-card__delta { font-family: var(--mono); font-size: 12px; margin-top: 6px; color: var(--text-muted); }
.detector-card.is-active {
  background: var(--accent-soft);
  border-color: var(--accent-bg);
}
.detector-card.is-active .detector-card__id { color: var(--accent); }
.detector-card.is-active .detector-card__delta { color: var(--accent); font-weight: 600; }
.detector-card.is-inactive {
  border-style: dashed;
  opacity: .6;
}
.detector-card.is-inactive .detector-card__delta { color: var(--text-muted); font-style: italic; }

.score-readout { display: flex; align-items: baseline; gap: 10px; margin: 14px 0 6px; }
.score-readout__value { font-family: var(--mono); font-size: 26px; font-weight: 700; }
.score-readout__value.is-warn { color: var(--warn); }
.score-readout__value.is-danger { color: var(--danger); }

.alert-stage {
  opacity: 0;
  transform: translateY(6px);
  transition: opacity .35s ease, transform .35s ease;
}
.alert-stage.is-visible { opacity: 1; transform: none; }

.alert-card {
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  background: var(--danger-soft);
  padding: 16px;
  margin: 16px 0;
}
.alert-card__row { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; margin-bottom: 6px; }
.alert-card__row:last-child { margin-bottom: 0; }
.alert-card__row b { font-family: var(--mono); }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid var(--danger);
}

.notify-arrow { font-size: 13px; color: var(--text-dim); margin: 10px 0; }
.notify-arrow b { color: var(--text); }

.bars-compare {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 20px;
}
.bar-chart-title { font-size: 13px; color: var(--text-dim); margin-bottom: 10px; }
.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.bar-row__label { width: 9.5em; font-size: 12px; color: var(--text-dim); flex-shrink: 0; }
.bar-row__track { flex: 1; background: var(--bg-inset); border-radius: 4px; height: 22px; position: relative; overflow: hidden; }
.bar-row__fill {
  position: absolute; inset: 0;
  width: 100%;
  transform: scaleX(0);
  transform-origin: left;
  border-radius: 4px;
  transition: transform .6s ease;
}
.bar-row__fill.is-danger { background: var(--danger); }
.bar-row__fill.is-ok { background: var(--ok); }
.bar-row__value { width: 9em; text-align: right; font-family: var(--mono); font-size: 12px; flex-shrink: 0; }

.rm-note {
  font-size: 12px;
  color: var(--text-muted);
  padding: 8px 12px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  margin-bottom: 16px;
}

.reduced-motion * { transition: none !important; animation: none !important; }

@media (max-width: 640px) {
  html { scroll-padding-top: 140px; } /* nav переносится на 2 строки на узких экранах — выше */
  .page { padding: 20px 14px 48px; }
  .site-nav { padding: 10px 14px; }
  table { font-size: 12px; }
  th, td { padding: 6px 8px; }
  .big-counter { font-size: 26px; }
  .bar-row__label { width: 7em; }
}
