:root {
  --bg: #f7f7f4;
  --surface: #ffffff;
  --text: #1a1c1a;
  --muted: #5f655f;
  --line: #e3e5df;
  --accent: #15803d;
  --accent-ink: #ffffff;
  --accent-soft: #e7f4ec;
  --warn-soft: #fff7e6;
  --warn-line: #f2d99a;
  /* Графики: категориальные цвета (проверены валидатором на этих фонах) и служебные линии */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --grid: #ecede8;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111311;
    --surface: #181b18;
    --text: #ecefea;
    --muted: #a0a79f;
    --line: #2a2f2a;
    --accent: #34c46e;
    --accent-ink: #08130c;
    --accent-soft: #15301f;
    --warn-soft: #2a2414;
    --warn-line: #5a4a1f;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --grid: #262a26;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.wrap { max-width: 860px; margin-left: auto; margin-right: auto; padding: 0 16px; }
a { color: var(--accent); }
code { font-family: var(--mono); font-size: 0.9em; }
h1 { font-size: clamp(2.1rem, 6vw, 3.4rem); line-height: 1.08; margin: 0 0 18px; letter-spacing: -0.02em; }
h2 { font-size: 1.35rem; margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 0.88rem; }

.top { border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; z-index: 5; }
.top-inner { display: flex; align-items: center; justify-content: space-between; height: 56px; gap: 12px; }
.brand { font-weight: 700; color: var(--text); text-decoration: none; font-size: 1.1rem; }
.brand span { color: var(--accent); }
nav { display: flex; gap: 16px; flex-wrap: wrap; }
nav a { color: var(--muted); text-decoration: none; font-size: 0.95rem; }
nav a:hover { color: var(--text); }

section { margin-top: 44px; }
.hero { margin-top: 56px; }
.lead { font-size: 1.12rem; max-width: 640px; color: var(--muted); }
.lead b { color: var(--text); }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-top: 28px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.num { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.lbl { color: var(--muted); font-size: 0.85rem; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px 22px; }
.card.wrap { max-width: 828px; width: calc(100% - 32px); }
.warn { background: var(--warn-soft); border-color: var(--warn-line); }

form { display: flex; gap: 10px; margin: 14px 0 6px; }
input[type=text] {
  flex: 1; min-width: 0; padding: 12px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
  font: 15px var(--mono);
}
input[type=text]:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
button {
  padding: 12px 20px; border-radius: 10px; border: 0; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); font: 600 15px system-ui, sans-serif;
}
button.ghost { background: transparent; color: var(--accent); border: 1px solid var(--accent); }

#result { margin-top: 14px; }
.res-head { font-weight: 600; margin: 8px 0; }
.item {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: baseline;
  border-top: 1px solid var(--line); padding: 12px 0;
}
.item .amt { font-weight: 600; font-variant-numeric: tabular-nums; }
.item .meta { color: var(--muted); font-size: 0.88rem; grid-column: 1 / -1; overflow-wrap: anywhere; }
.badge { display: inline-block; font-size: 0.78rem; font-weight: 600; padding: 2px 8px; border-radius: 99px; border: 1px solid var(--line); }
.ok { color: var(--accent); }
.scroll-x { overflow-x: auto; }
.scroll-x td { white-space: nowrap; }
#alerts:empty { display: none; }
.badge.stuck { background: var(--warn-soft); border: 1px solid var(--warn-line); }
.badge.returned { background: var(--accent-soft); color: var(--accent); }

.steps { padding-left: 20px; }
.steps li { margin: 10px 0; }
.checks { padding-left: 20px; }
.checks li { margin: 8px 0; }
.addr { overflow-wrap: anywhere; }

.alert { border: 1px solid var(--warn-line); background: var(--warn-soft); border-radius: var(--radius); padding: 12px 16px; margin-top: 10px; }

table { width: 100%; border-collapse: collapse; font-size: 0.93rem; }
th, td { text-align: left; padding: 9px 8px; border-top: 1px solid var(--line); }
th { color: var(--muted); font-weight: 500; }
td.r, th.r { text-align: right; font-variant-numeric: tabular-nums; }

.tipbox { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-top: 12px; flex-wrap: wrap; }
.tipname { font-size: 1.25rem; font-weight: 700; }

.foot { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 56px; padding-top: 18px; padding-bottom: 40px; border-top: 1px solid var(--line); font-size: 0.9rem; }

/* Страница статистики */
.chart-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 0.88rem; color: var(--muted); margin: 4px 0 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { fill: var(--muted); font: 14px system-ui, sans-serif; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .base { stroke: var(--line); stroke-width: 1; }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover, .chart .hit.on { fill: var(--text); fill-opacity: 0.05; }
.tip {
  position: absolute; pointer-events: none; z-index: 3; min-width: 170px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 10px; font-size: 0.85rem; box-shadow: 0 4px 16px rgba(0,0,0,.12);
}
.tip .row { display: flex; justify-content: space-between; gap: 14px; font-variant-numeric: tabular-nums; }
.tip .row i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }
.hbars .hrow { display: grid; grid-template-columns: 120px 1fr; gap: 10px; align-items: center; margin: 8px 0; font-size: 0.9rem; }
.hbars .track { display: flex; align-items: center; gap: 8px; min-width: 0; }
.hbars .bar { height: 14px; background: var(--series-1); border-radius: 0 4px 4px 0; min-width: 2px; }
.hbars .val { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
details.table-view { margin-top: 10px; }
details.table-view summary { cursor: pointer; color: var(--muted); font-size: 0.88rem; }
.netbar { display: inline-block; height: 8px; background: var(--series-1); border-radius: 0 3px 3px 0; vertical-align: middle; margin-right: 8px; }

@media (max-width: 640px) {
  .hbars .hrow { grid-template-columns: 96px 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  form { flex-direction: column; }
  nav { gap: 12px; }
  nav a:nth-child(n+3) { display: none; }
  nav a.keep { display: inline; }
  .card { padding: 18px 16px; }
}
