:root {
  --bg:#f3f5f8; --card:#fff; --text:#141a26; --muted:#667085; --line:#e6e9ef; --line2:#d0d5dd;
  --accent:#2a78d6; --accent-soft:#eaf2fc; --bad:#c4302b; --bad-soft:#fdeceb; --ok:#067647; --ok-soft:#e7f6ee;
  --warn-c:#b54708; --warn-soft:#fff4e5; --side:#121826; --radius:12px;
  --shadow:0 1px 2px rgba(16,24,40,.04), 0 1px 3px rgba(16,24,40,.06);
}
* { box-sizing:border-box; }
html, body { margin:0; }
body { font:14.5px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; background:var(--bg); color:var(--text); }
a { color:var(--accent); text-decoration:none; }
a:hover { text-decoration:underline; }

/* ---------- каркас ---------- */
.layout { display:flex; min-height:100vh; }
.side { width:224px; flex:none; background:var(--side); color:#c5cbd8; display:flex; flex-direction:column; position:sticky; top:0; height:100vh; }
.brand { display:flex; align-items:center; gap:10px; padding:20px 20px 18px; color:#fff; font-weight:600; font-size:15.5px; }
.brand .logo { width:32px; height:32px; border-radius:9px; background:linear-gradient(135deg,#3b8cf0,#1f5fb4); display:grid; place-items:center; }
.nav { display:flex; flex-direction:column; gap:2px; padding:6px 10px; }
.nav a { display:flex; align-items:center; gap:11px; padding:9px 12px; border-radius:8px; color:#c5cbd8; font-weight:500; }
.nav a:hover { background:rgba(255,255,255,.06); color:#fff; text-decoration:none; }
.nav a.on { background:rgba(59,140,240,.18); color:#fff; }
.nav a.on svg { color:#6aa8f5; }
.nav svg { width:18px; height:18px; flex:none; }
.nav .sub { padding-left:41px; font-size:13.5px; }
.side-foot { margin-top:auto; padding:16px 20px; border-top:1px solid rgba(255,255,255,.08); display:flex; align-items:center; justify-content:space-between; gap:8px; }
.side-foot .who { display:flex; align-items:center; gap:8px; font-size:13.5px; }
.side-foot .ava { width:28px; height:28px; border-radius:50%; background:#2b3446; color:#fff; display:grid; place-items:center; font-weight:600; font-size:12px; text-transform:uppercase; }
.side-foot button { background:none; border:1px solid rgba(255,255,255,.18); color:#c5cbd8; border-radius:7px; padding:4px 10px; font:inherit; font-size:12.5px; cursor:pointer; }
.side-foot button:hover { color:#fff; border-color:rgba(255,255,255,.4); }
.content { flex:1; min-width:0; }
main { max-width:1320px; margin:0 auto; padding:26px 30px 40px; }
.page-head { display:flex; align-items:flex-end; justify-content:space-between; gap:16px; flex-wrap:wrap; margin-bottom:18px; }
.page-head h1 { font-size:23px; margin:0; letter-spacing:-.01em; }
.page-head .sub { color:var(--muted); margin-top:2px; }
.page-head .acts { display:flex; gap:8px; flex-wrap:wrap; }
@media (max-width:900px) {
  .layout { flex-direction:column; }
  .side { width:auto; height:auto; position:static; }
  .nav { flex-direction:row; flex-wrap:wrap; }
  .nav .sub { padding-left:12px; }
  .side-foot { margin:0; }
  main { padding:18px 14px 30px; }
}

/* ---------- карточки ---------- */
.card { background:var(--card); border:1px solid var(--line); border-radius:var(--radius); padding:18px 20px; margin-bottom:18px; box-shadow:var(--shadow); }
.card > h1:first-child, .card > h2:first-child { margin-top:0; }
h1 { font-size:20px; margin:0 0 14px; }
h2, .card h1[style*="17px"] { font-size:16px; margin:0 0 12px; font-weight:600; }
h3 { font-size:15px; }
.card-head { display:flex; justify-content:space-between; align-items:baseline; gap:12px; flex-wrap:wrap; margin-bottom:10px; }
.card-head h2 { margin:0; }
.card-head .muted { font-size:13px; }
.row2 { display:grid; grid-template-columns:repeat(auto-fit,minmax(420px,1fr)); gap:18px; margin-bottom:18px; }
.row2 > .card, .row3 > .card { margin:0; }
.row3 { display:grid; grid-template-columns:repeat(auto-fit,minmax(300px,1fr)); gap:18px; margin-bottom:18px; }
.span2 { grid-column:span 2; }
@media (max-width:980px) { .row2 { grid-template-columns:1fr; } .span2 { grid-column:auto; } }

/* показатели */
.kpis { display:grid; grid-template-columns:repeat(auto-fit,minmax(170px,1fr)); gap:14px; margin-bottom:18px; }
.kpi { background:var(--card); border:1px solid var(--line); border-radius:var(--radius); padding:15px 18px; box-shadow:var(--shadow); position:relative; overflow:hidden; }
.kpi .k-l { color:var(--muted); font-size:13px; font-weight:500; display:flex; align-items:center; gap:7px; }
.kpi .k-l i { width:8px; height:8px; border-radius:50%; background:var(--accent); display:inline-block; }
.kpi .k-v { font-size:25px; font-weight:650; letter-spacing:-.015em; margin-top:4px; font-variant-numeric:tabular-nums; white-space:nowrap; }
.kpi .k-v small { font-size:14px; color:var(--muted); font-weight:500; margin-left:3px; }
.kpi .k-s { font-size:12.5px; color:var(--muted); margin-top:3px; }
.delta { font-weight:600; padding:1px 6px; border-radius:6px; font-size:12px; }
.delta.up { color:var(--ok); background:var(--ok-soft); }
.delta.down { color:var(--bad); background:var(--bad-soft); }
.kpi.bad .k-v { color:var(--bad); }
.kpi.warnk .k-v { color:var(--warn-c); }
.kpi.okk .k-v { color:var(--ok); }
.kpis .kpi .k-v { font-size:clamp(19px, 1.7vw, 25px); }

/* ---------- таблицы ---------- */
table { border-collapse:separate; border-spacing:0; width:100%; }
th, td { padding:8px 11px; border-bottom:1px solid var(--line); text-align:left; white-space:nowrap; }
th { font-weight:600; color:var(--muted); font-size:12.5px; background:#f9fafb; position:sticky; top:0; z-index:1; }
thead th:first-child { border-top-left-radius:8px; } thead th:last-child { border-top-right-radius:8px; }
td.n, th.n { text-align:right; font-variant-numeric:tabular-nums; }
tbody tr:hover td { background:#f5f8fd; }
tfoot td { font-weight:650; background:#f9fafb; border-top:1px solid var(--line2); position:sticky; bottom:0; }
th.sortable { cursor:pointer; user-select:none; }
th.sortable:hover { color:var(--text); }
th.sortable::after { content:"↕"; opacity:.3; margin-left:5px; font-size:11px; }
th.asc::after { content:"↑"; opacity:.9; color:var(--accent); }
th.desc::after { content:"↓"; opacity:.9; color:var(--accent); }
.dt-bar { display:flex; align-items:center; gap:12px; margin-bottom:10px; }
.dt-bar input { width:280px; max-width:100%; padding-left:32px; background:#fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%23667085' stroke-width='2'%3E%3Ccircle cx='7' cy='7' r='5'/%3E%3Cpath d='m11 11 3.5 3.5'/%3E%3C/svg%3E") no-repeat 10px center; }
.scroll { max-height:70vh; overflow:auto; border:1px solid var(--line); border-radius:9px; }
.scroll table td:first-child, .scroll table th:first-child { padding-left:14px; }
.tbl-wrap { overflow:auto; }

/* ---------- формы ---------- */
form.inline { display:flex; flex-wrap:wrap; gap:12px; align-items:end; }
label { display:flex; flex-direction:column; gap:5px; font-size:12.5px; color:var(--muted); font-weight:500; }
input, select, textarea { font:inherit; font-size:14px; padding:7px 10px; border:1px solid var(--line2); border-radius:8px; background:#fff; color:var(--text); outline:none; transition:border-color .15s, box-shadow .15s; }
input:focus, select:focus, textarea:focus { border-color:var(--accent); box-shadow:0 0 0 3px rgba(42,120,214,.15); }
input[type=checkbox] { accent-color:var(--accent); width:16px; height:16px; }
.grid { display:grid; grid-template-columns:repeat(auto-fill, minmax(210px,1fr)); gap:14px; }
.btn { display:inline-flex; align-items:center; gap:6px; font:inherit; font-size:14px; font-weight:550; padding:8px 15px; border-radius:8px; border:1px solid var(--accent); background:var(--accent); color:#fff; cursor:pointer; text-decoration:none; transition:filter .15s, background .15s; line-height:1.3; }
.btn:hover { filter:brightness(1.07); text-decoration:none; }
.btn.ghost { background:#fff; color:var(--text); border-color:var(--line2); }
.btn.ghost:hover { background:#f5f7fa; filter:none; }
.btn.danger { background:#fff; color:var(--bad); border-color:#f1b5b2; }
.btn.danger:hover { background:var(--bad-soft); filter:none; }
.chips { display:flex; flex-wrap:wrap; gap:6px; }
.chips a { padding:5px 11px; border-radius:20px; border:1px solid var(--line2); background:#fff; color:var(--text); font-size:13px; font-weight:500; }
.chips a:hover { border-color:var(--accent); text-decoration:none; }
.chips a.on { background:var(--accent); border-color:var(--accent); color:#fff; }
.filters { display:flex; flex-wrap:wrap; gap:14px 20px; align-items:end; justify-content:space-between; }

.flash { padding:11px 15px; border-radius:10px; margin-bottom:14px; border:1px solid transparent; font-weight:500; }
.flash.ok { background:var(--ok-soft); color:var(--ok); border-color:#b5e3c8; }
.flash.error { background:var(--bad-soft); color:var(--bad); border-color:#f4c5c2; }
.tag { font-size:12px; padding:2px 8px; border-radius:20px; background:#eef1f5; color:#475467; font-weight:500; }
.tag.manual { background:var(--warn-soft); color:var(--warn-c); }
.tag.blue { background:var(--accent-soft); color:#1c5cab; }
.muted { color:var(--muted); } .warn { color:var(--warn-c); }
details summary { cursor:pointer; }
pre { background:#0f1522; color:#d3dae6; padding:12px 14px; border-radius:9px; overflow:auto; }
.empty { text-align:center; color:var(--muted); padding:30px 10px; }

/* ---------- графики ---------- */
.ch { position:relative; }
.ch-plot { width:100%; }
.ch svg { display:block; overflow:visible; }
.ch-grid { stroke:#eceff3; stroke-width:1; }
.ch-base { stroke:#c5cad3; stroke-width:1; }
.ch-ax { fill:#7a8394; font-size:11.5px; font-variant-numeric:tabular-nums; }
.ch-hl { fill:#2a78d6; opacity:.07; }
.ch-cross { stroke:#98a2b3; stroke-width:1; stroke-dasharray:3 3; }
.ch-dash { stroke-dasharray:5 4; }
.ch-legend { display:flex; flex-wrap:wrap; gap:6px 16px; margin:0 0 8px; font-size:12.5px; color:#475467; }
.ch-legend span, .ch-tip div { display:inline-flex; align-items:center; gap:6px; }
.ch-legend i, .ch-tip i { width:10px; height:10px; border-radius:3px; display:inline-block; flex:none; }
.ch-tip { position:absolute; display:none; pointer-events:none; background:#fff; border:1px solid var(--line); box-shadow:0 8px 24px rgba(16,24,40,.14); border-radius:9px; padding:8px 11px; font-size:12.5px; z-index:5; min-width:130px; white-space:nowrap; }
.ch-tip div { display:flex; }
.ch-tip .ch-tt { font-weight:600; margin-bottom:4px; color:var(--text); }
.ch-tip .ch-tot { border-top:1px solid var(--line); margin-top:4px; padding-top:4px; }
.ch-tip b { font-variant-numeric:tabular-nums; margin-left:auto; padding-left:8px; }
.hb { display:flex; flex-direction:column; gap:9px; }
.hb-row { display:grid; grid-template-columns:minmax(80px,32%) 1fr auto; gap:10px; align-items:center; font-size:13.5px; }
.hb-l { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.hb-t { background:#f1f3f6; border-radius:5px; height:12px; overflow:hidden; }
.hb-b { height:100%; border-radius:0 5px 5px 0; }
.hb-v { font-variant-numeric:tabular-nums; font-weight:600; text-align:right; min-width:60px; }
.seg { display:flex; height:12px; border-radius:6px; overflow:hidden; gap:2px; background:#fff; }
.seg div { height:100%; }

/* ---------- вход ---------- */
.login-page { min-height:100vh; display:grid; place-items:center; background:radial-gradient(1200px 600px at 20% 0%, #1f3a66 0%, #121826 60%); padding:20px; }
.login-card { width:380px; max-width:100%; background:#fff; border-radius:16px; padding:30px 30px 26px; box-shadow:0 20px 60px rgba(0,0,0,.35); }
.login-card .brand { color:var(--text); padding:0 0 18px; font-size:17px; }
.login-card h1 { font-size:20px; margin:0 0 4px; }
.login-card input:not([type=checkbox]) { padding:10px 12px; }
.login-card .btn { justify-content:center; padding:10px; }

/* ---------- узкие экраны (телефон, окно мини-приложения Telegram на ПК) ---------- */
.row2 { grid-template-columns:repeat(auto-fit,minmax(min(420px,100%),1fr)); }
.row3 { grid-template-columns:repeat(auto-fit,minmax(min(300px,100%),1fr)); }
.tbl-x { overflow-x:auto; -webkit-overflow-scrolling:touch; }
.ch-plot, .ch svg { touch-action:pan-y; }
@media (max-width:640px) {
  body { font-size:14px; }
  main { padding:12px 10px 24px; }
  .page-head { margin-bottom:12px; align-items:flex-start; }
  .page-head h1 { font-size:20px; }
  .page-head .sub { font-size:13px; }
  .card { padding:13px 12px; margin-bottom:12px; border-radius:10px; }
  .row2, .row3 { gap:12px; margin-bottom:12px; }
  .card-head { margin-bottom:6px; }
  .card-head h2 { font-size:15px; }
  .card-head .muted { font-size:12px; }
  .kpis { grid-template-columns:1fr 1fr; gap:8px; margin-bottom:12px; }
  .kpi { padding:10px 11px; border-radius:10px; }
  .kpi .k-l { font-size:12px; }
  .kpis .kpi .k-v { font-size:17px; white-space:normal; line-height:1.25; }
  .kpi .k-v small { font-size:12px; }
  .kpi .k-s { font-size:11.5px; }
  .filters { flex-direction:column; align-items:stretch; gap:10px; }
  .filters > * { min-width:0; max-width:100%; }
  .chips { flex-wrap:nowrap; overflow-x:auto; margin:0 -12px; padding:0 12px 2px; scrollbar-width:none; }
  .chips::-webkit-scrollbar { display:none; }
  .chips a { white-space:nowrap; flex:none; }
  .filters form.inline { display:grid; grid-template-columns:minmax(0,1fr) minmax(0,1fr); gap:8px; }
  .filters form.inline label { min-width:0; }
  .filters input, .filters select { padding:7px 8px; }
  .filters form.inline label:nth-child(3) { grid-column:1 / -1; }
  .filters form.inline .btn { grid-column:1 / -1; justify-content:center; }
  .filters input, .filters select { width:100%; min-width:0; max-width:100%; font-size:16px; } /* 16px — iPhone не увеличивает страницу */
  th, td { padding:7px 8px; font-size:13px; }
  .tbl-x th:nth-child(3), .tbl-x td:nth-child(3), .tbl-x th:nth-child(5), .tbl-x td:nth-child(5) { display:none; } /* доля видна полоской ниже */
  .ch-ax { font-size:10.5px; }
  .ch-legend { font-size:12px; gap:4px 12px; }
}

/* ---------- «Сводка» для просмотра: верхняя полоска вместо бокового меню ---------- */
.vlayout { min-height:100vh; min-height:100dvh; }
.topbar { display:flex; align-items:center; justify-content:space-between; gap:10px; padding:10px 18px; background:var(--side); color:#c5cbd8; }
.topbar .brand { padding:0; font-size:15px; }
.topbar .brand .logo { width:28px; height:28px; border-radius:8px; }
.topbar form { display:flex; align-items:center; gap:10px; font-size:13px; }
.topbar button { background:none; border:1px solid rgba(255,255,255,.2); color:#c5cbd8; border-radius:7px; padding:3px 10px; font:inherit; font-size:12.5px; cursor:pointer; }
@media (max-width:640px) { .topbar { padding:8px 12px; } .topbar .who { display:none; } }

/* ---------- внутри Telegram: цвета темы Telegram (светлая/тёмная) ---------- */
.tg body { background:var(--bg); }
.tg .topbar { display:none; }            /* в Telegram своя шапка; выход не нужен — вход по Telegram */
.tg .card, .tg .kpi, .tg .login-card { box-shadow:none; }
.tg input, .tg select, .tg textarea, .tg .btn.ghost, .tg .chips a, .tg .ch-tip, .tg .seg { background:var(--card); color:var(--text); }
.tg .chips a.on { background:var(--accent); color:var(--accent-text, #fff); border-color:var(--accent); }
.tg .btn { background:var(--accent); border-color:var(--accent); color:var(--accent-text, #fff); }
.tg .btn.ghost { border-color:var(--line2); }
.tg th, .tg tfoot td { background:var(--bg); }
.tg tbody tr:hover td { background:transparent; }
.tg .ch-grid { stroke:var(--line); }
.tg .ch-base { stroke:var(--line2); }
.tg .ch-ax { fill:var(--muted); }
.tg .ch-legend { color:var(--muted); }
.tg .ch-tip .ch-tt { color:var(--text); }
.tg .login-page { background:var(--bg); min-height:100dvh; }
.tg .login-card { background:var(--card); color:var(--text); }
.tg .delta.up { background:transparent; } .tg .delta.down { background:transparent; }
