:root {
  --bg: #f4f4f2; --surface: #fcfcfb; --text: #0b0b0b; --muted: #52514e; --line: #e2e1dc;
  --accent: #2a78d6; --accent-soft: #e3eefb;
  --series-1: #2a78d6; --series-2: #eb6834;
  --good: #16a34a; --good-soft: #e3f6ea; --bad: #c62828; --bad-soft: #fdeaea; --warn: #a15c00; --warn-soft: #fdf1dc;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121211; --surface: #1a1a19; --text: #f0efec; --muted: #c3c2b7; --line: #2e2e2c;
    --accent: #3987e5; --accent-soft: #1b2a3d; --series-1: #3987e5; --series-2: #d95926;
    --good: #4ade80; --good-soft: #173525; --bad: #f87171; --bad-soft: #3d1d1d; --warn: #fbbf24; --warn-soft: #3a2c10;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121211; --surface: #1a1a19; --text: #f0efec; --muted: #c3c2b7; --line: #2e2e2c;
  --accent: #3987e5; --accent-soft: #1b2a3d; --series-1: #3987e5; --series-2: #d95926;
  --good: #4ade80; --good-soft: #173525; --bad: #f87171; --bad-soft: #3d1d1d; --warn: #fbbf24; --warn-soft: #3a2c10;
  color-scheme: dark;
}
* { box-sizing: border-box; }
/* Атрибут hidden должен скрывать даже элементы со своим display (форма входа — display: grid) */
[hidden] { display: none !important; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1 { font-size: 22px; margin: 0 0 12px; }
h2 { font-size: 17px; margin: 24px 0 10px; }
.muted { color: var(--muted); font-size: 13px; }
.err { color: var(--bad); min-height: 1.2em; }

.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 16px; padding: 10px 20px;
  background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { white-space: nowrap; }
nav { display: flex; gap: 4px; overflow-x: auto; flex: 1; }
nav a { padding: 7px 12px; border-radius: 8px; text-decoration: none; color: var(--muted); white-space: nowrap; }
nav a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
main { max-width: 1200px; margin: 0 auto; padding: 20px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 14px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.grid2 { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.tile .num { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile .label { color: var(--muted); font-size: 13px; }

label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
input, select, textarea { width: 100%; padding: 9px 11px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); }
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 16px; border: 0;
  border-radius: 8px; background: var(--accent); color: #fff; font-weight: 600; cursor: pointer; margin-top: 12px; }
.btn.secondary { background: var(--accent-soft); color: var(--accent); }
.btn.danger { background: var(--bad-soft); color: var(--bad); }
.btn.small { padding: 5px 10px; margin: 0; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
button.link { background: none; border: 0; color: var(--muted); cursor: pointer; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > * { margin-top: 0; }
.row input, .row select { width: auto; flex: 1; min-width: 140px; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 5px 12px; cursor: pointer; font-size: 13px; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--accent-soft); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.plain { background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.pill { background: var(--bad); color: #fff; border-radius: 999px; font-size: 11px; padding: 0 6px; margin-left: 2px; }

pre { background: var(--bg); border-radius: 8px; padding: 10px; overflow-x: auto; font: 12px/1.4 ui-monospace, Menlo, Consolas, monospace; white-space: pre-wrap; word-break: break-word; }
details summary { cursor: pointer; }
.msg { border-bottom: 1px solid var(--line); padding: 10px 0; }
.msg:last-child { border-bottom: 0; }
.msg .q { font-weight: 600; white-space: pre-wrap; word-break: break-word; }
.msg .a { color: var(--muted); white-space: pre-wrap; word-break: break-word; font-size: 13px; max-height: 6.5em; overflow: hidden; }
.msg.open .a { max-height: none; }

/* График */
.chart-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.chart { position: relative; margin-top: 10px; }
.chart svg { display: block; width: 100%; height: 240px; overflow: visible; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover { fill: var(--accent-soft); fill-opacity: .5; }
.tip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; font-size: 13px; box-shadow: 0 4px 16px rgba(0,0,0,.12); white-space: nowrap; z-index: 3; }
.tip b { display: block; margin-bottom: 2px; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; }
.login-card .btn { width: 100%; }
.toast { position: fixed; right: 16px; bottom: 16px; left: 16px; max-width: 420px; margin-left: auto; background: var(--text); color: var(--bg);
  padding: 10px 14px; border-radius: 10px; z-index: 20; }
.spinner { padding: 40px 0; text-align: center; color: var(--muted); }
@media (max-width: 640px) {
  .top { flex-wrap: wrap; gap: 8px; padding: 10px 16px; }
  nav { order: 3; flex-basis: 100%; }
  main { padding: 16px; }
  .grid2 { grid-template-columns: 1fr; }
}
