:root {
  --bg: #f3f4f7;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --text: #182033;
  --muted: #667085;
  --border: #e3e6ec;
  --brand: #1f2a44;
  --brand-text: #ffffff;
  --accent: #e8930c;
  --ok: #12805c;
  --ok-soft: #dcf3ea;
  --warn: #b25e09;
  --warn-soft: #fdeccf;
  --bad: #c0362c;
  --bad-soft: #fbe2df;
  --info: #2457c5;
  --info-soft: #e1eafc;
  /* диаграммы (проверенная палитра) */
  --s1: #2a78d6;
  --s2: #eb6834;
  --neg: #e34948;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --axis-text: #898781;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 12px;
  --tabbar-h: 62px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1420; --surface: #182030; --surface-2: #1e2738; --text: #e8ecf3; --muted: #98a2b3; --border: #2a3448;
    --brand: #141b2b; --accent: #f2a43a; --ok: #4cc79a; --ok-soft: #173329; --warn: #f0b155; --warn-soft: #3a2c14;
    --bad: #f07a70; --bad-soft: #3c1f1d; --info: #7ea6f5; --info-soft: #1c2a47;
    --s1: #3987e5; --s2: #d95926; --neg: #e66767; --grid: #2c2c2a; --axis: #383835; --axis-text: #898781;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1420; --surface: #182030; --surface-2: #1e2738; --text: #e8ecf3; --muted: #98a2b3; --border: #2a3448;
  --brand: #141b2b; --accent: #f2a43a; --ok: #4cc79a; --ok-soft: #173329; --warn: #f0b155; --warn-soft: #3a2c14;
  --bad: #f07a70; --bad-soft: #3c1f1d; --info: #7ea6f5; --info-soft: #1c2a47;
  --s1: #3987e5; --s2: #d95926; --neg: #e66767; --grid: #2c2c2a; --axis: #383835; --axis-text: #898781;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent;
}
a { color: var(--info); text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
.splash { display: grid; place-items: center; min-height: 100vh; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos { color: var(--ok); }
.neg { color: var(--bad); }
.icon { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 8px;
  min-height: 56px; padding: 8px 16px; padding-top: calc(8px + env(safe-area-inset-top));
  background: var(--brand); color: var(--brand-text);
}
.topbar h1 { font-size: 18px; font-weight: 650; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .iconbtn { color: var(--brand-text); }
.topbar .btn.primary { background: var(--accent); color: #1b1203; }
main.view { max-width: 1100px; margin: 0 auto; padding: 16px 16px calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom)); }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; justify-content: center;
  background: var(--surface); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1; max-width: 140px; height: var(--tabbar-h); display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; color: var(--muted); font-size: 11.5px;
}
.tabbar a.on { color: var(--info); font-weight: 600; }

/* ---------- cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; }
.card.pad0 { padding: 0; }
.card h2 { margin-bottom: 10px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 12px; }
.grid.two { grid-template-columns: 1fr; }
@media (min-width: 820px) { .grid.two { grid-template-columns: 1fr 1fr; } }
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 720px) { .tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); min-width: 0; }
.tile .k { font-size: 12.5px; color: var(--muted); }
.tile .v { font-size: clamp(15px, 4.4vw, 20px); font-weight: 650; margin-top: 2px; overflow-wrap: anywhere; }
.tile .s { font-size: 12px; color: var(--muted); margin-top: 2px; }
a.tile { color: inherit; display: block; }

.list { list-style: none; margin: 0; padding: 0; }
.list > li, .list > a { display: flex; align-items: center; gap: 10px; padding: 11px 16px; border-top: 1px solid var(--border); color: inherit; }
.list > :first-child { border-top: 0; }
.list .t { font-weight: 560; }
.list .sub { font-size: 13px; color: var(--muted); }
.list .amt { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 600; }

.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.badge.info { background: var(--info-soft); color: var(--info); border-color: transparent; }

.notice { padding: 10px 14px; border-radius: 10px; background: var(--info-soft); color: var(--text); font-size: 14px; }
.notice.warn { background: var(--warn-soft); }
.notice.bad { background: var(--bad-soft); }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; }

/* ---------- buttons & forms ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 8px 14px;
  border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 560; cursor: pointer; white-space: nowrap;
}
.btn.primary { background: var(--info); border-color: var(--info); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.small { min-height: 32px; padding: 4px 10px; font-size: 13.5px; }
.btn:disabled { opacity: .55; cursor: default; }
.iconbtn { background: none; border: 0; padding: 8px; border-radius: 8px; color: inherit; cursor: pointer; display: inline-flex; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 99px; padding: 6px 12px; font: inherit; font-size: 13.5px; cursor: pointer; }
.chip.on { background: var(--brand); color: #fff; border-color: var(--brand); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .chip.on { background: var(--info); border-color: var(--info); } }

form .f { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; min-width: 0; }
form .f > span { font-size: 13px; color: var(--muted); }
.fgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.fgrid > .wide { grid-column: 1 / -1; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 9px 11px; min-height: 42px; width: 100%; min-width: 0;
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--info); outline-offset: -1px; }
input[type=checkbox] { width: 20px; min-height: 20px; height: 20px; }
label.check { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; cursor: pointer; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.filters > * { flex: 1 1 150px; width: auto; }
.filters > .chips { flex: 1 1 100%; }
.kindgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 12px; }
.kindgrid button { text-align: left; border: 1px solid var(--border); background: var(--surface); border-radius: 10px; padding: 8px 10px; font: inherit; font-size: 13.5px; cursor: pointer; color: var(--text); }
.kindgrid button.on { border-color: var(--info); background: var(--info-soft); font-weight: 600; }
.preview { font-size: 13px; color: var(--muted); margin: -6px 0 12px; }

/* ---------- sheet (окно поверх) ---------- */
.sheet { position: fixed; inset: 0; z-index: 50; background: rgba(10, 14, 22, .45); display: flex; align-items: flex-end; justify-content: center; }
.sheet-box {
  background: var(--surface); width: 100%; max-width: 640px; max-height: 92vh; overflow: auto;
  border-radius: 16px 16px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
}
@media (min-width: 700px) { .sheet { align-items: center; } .sheet-box { border-radius: 16px; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.sheet-foot { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 6px; }

/* ---------- tables ---------- */
.tablewrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th, table.t td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
table.t th { font-size: 12.5px; color: var(--muted); font-weight: 600; background: var(--surface-2); }
table.t td.r, table.t th.r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.t tr.total td { font-weight: 650; background: var(--surface-2); }
@media (max-width: 600px) {
  table.t { font-size: 12.5px; }
  table.t th, table.t td { padding: 6px 6px; }
}

/* ---------- charts ---------- */
.chart { width: 100%; overflow: hidden; }
.chart svg { display: block; width: 100%; height: auto; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--axis); stroke-width: 1; }
.chart text { fill: var(--axis-text); font-size: 11px; font-family: inherit; }
.chart .lbl { fill: var(--text); font-size: 11.5px; }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover + .hl, .chart .hl.on { opacity: 1; }
.chart .hl { fill: var(--text); opacity: 0; pointer-events: none; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.hbar { display: grid; grid-template-columns: minmax(90px, 38%) 1fr auto; gap: 6px 10px; align-items: center; font-size: 13.5px; }
.hbar .bar { height: 12px; border-radius: 0 4px 4px 0; background: var(--s1); min-width: 2px; }
.hbar .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar .val { font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; }
.tip {
  position: fixed; z-index: 60; pointer-events: none; background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; font-size: 13px; box-shadow: 0 4px 16px rgba(0, 0, 0, .15); max-width: 260px;
}
.tip b { display: block; margin-bottom: 2px; }
.tip .r { display: flex; justify-content: space-between; gap: 14px; font-variant-numeric: tabular-nums; }
.tip i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; }

.meter { height: 10px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; }
.meter > div { height: 100%; background: var(--s1); }
.meter.warn > div { background: var(--bad); }
.qr svg { width: 200px; height: 200px; background: #fff; padding: 8px; border-radius: 8px; }
.files { display: flex; flex-direction: column; gap: 6px; }
.files a { display: flex; align-items: center; gap: 8px; }
code.secret { font-size: 15px; letter-spacing: 1px; word-break: break-all; background: var(--surface-2); padding: 4px 8px; border-radius: 6px; }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: #1d2433; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; transition: .2s; z-index: 70;
  pointer-events: none; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--bad); }

.login { max-width: 380px; margin: 10vh auto 0; padding: 0 16px; }
.login .logo { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.login .logo img { width: 44px; height: 44px; }
