:root {
  color-scheme: light;
  --bg: #f6f6f4;
  --surface: #ffffff;
  --surface-2: #f0f0ed;
  --border: #e2e1dc;
  --text: #16161a;
  --text-2: #52514e;
  --muted: #7b7a75;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --series-1: #2a78d6;
  --grid: #e6e5e0;
  --good: #137a3a;
  --good-bg: #e3f4e8;
  --warn: #8a5a00;
  --warn-bg: #fdf1d6;
  --crit: #b42318;
  --crit-bg: #fde7e5;
  --shadow: 0 1px 2px rgba(0,0,0,.05);
  --radius: 10px;
  font-family: "Golos Text", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111113;
    --surface: #1a1a1c;
    --surface-2: #232326;
    --border: #2e2e32;
    --text: #f2f2f0;
    --text-2: #c3c2b7;
    --muted: #8f8e88;
    --accent: #3987e5;
    --series-1: #3987e5;
    --grid: #2a2a2d;
    --good: #5cc98a;
    --good-bg: #16301f;
    --warn: #f0b84a;
    --warn-bg: #33270e;
    --crit: #ff7b72;
    --crit-bg: #3a1614;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111113; --surface: #1a1a1c; --surface-2: #232326; --border: #2e2e32;
  --text: #f2f2f0; --text-2: #c3c2b7; --muted: #8f8e88; --accent: #3987e5; --series-1: #3987e5;
  --grid: #2a2a2d; --good: #5cc98a; --good-bg: #16301f; --warn: #f0b84a; --warn-bg: #33270e;
  --crit: #ff7b72; --crit-bg: #3a1614; --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.45; -webkit-text-size-adjust: 100%; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
.boot { padding: 40px; color: var(--muted); }

/* шапка */
.top { position: sticky; top: 0; z-index: 10; background: var(--surface); border-bottom: 1px solid var(--border); }
.top-row { display: flex; align-items: center; gap: 12px; padding: 10px 16px; max-width: 1280px; margin: 0 auto; }
.brand { font-weight: 700; font-size: 15px; white-space: nowrap; }
.brand span { color: var(--muted); font-weight: 500; }
.who { margin-left: auto; color: var(--text-2); font-size: 13px; display: flex; gap: 10px; align-items: center; white-space: nowrap; }
.nav { display: flex; gap: 2px; overflow-x: auto; padding: 0 12px; max-width: 1280px; margin: 0 auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a { padding: 9px 12px; color: var(--text-2); border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 500; }
.nav a:hover { text-decoration: none; color: var(--text); }
.nav a.on { color: var(--text); border-bottom-color: var(--accent); }
.nav .badge { margin-left: 4px; }

main { max-width: 1280px; margin: 0 auto; padding: 16px; }
h1 { font-size: 20px; margin: 4px 0 14px; font-weight: 700; }
h2 { font-size: 15px; margin: 22px 0 10px; font-weight: 600; }
h3 { font-size: 14px; margin: 0 0 8px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); min-width: 0; }
.grid { display: grid; gap: 12px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); }
.g3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.gc { grid-template-columns: repeat(auto-fit, minmax(min(100%, 460px), 1fr)); }

/* показатели */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; min-width: 0; }
.stat .lbl { color: var(--text-2); font-size: 13px; font-weight: 500; }
.stat .val { font-size: 22px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .val .sub { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 6px; }
.stat .def { color: var(--muted); font-size: 11.5px; margin-top: 4px; line-height: 1.35; }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: none; padding: 6px 12px; cursor: pointer; color: var(--text-2); }
.seg button.on { background: var(--accent); color: var(--accent-ink); }

/* таблицы — скролл внутри своего контейнера */
.tw { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 7px 10px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; vertical-align: top; }
th { color: var(--text-2); font-weight: 600; background: var(--surface-2); position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.wrap { white-space: normal; min-width: 220px; max-width: 520px; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--surface-2); }

.badge { display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.badge.good { background: var(--good-bg); color: var(--good); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.crit { background: var(--crit-bg); color: var(--crit); }

.btn { border: 1px solid var(--border); background: var(--surface); padding: 7px 12px; border-radius: 8px; cursor: pointer; font-weight: 500; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { border-color: var(--crit); color: var(--crit); }
.btn.danger.solid { background: var(--crit); color: #fff; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.link { border: 0; background: none; color: var(--accent); padding: 0; }
input[type=text], input[type=number], input[type=password], input[type=date], input[type=search], select, textarea {
  border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 7px 10px; min-width: 0; max-width: 100%;
}
textarea { width: 100%; min-height: 110px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.alert { padding: 10px 12px; border-radius: 8px; margin: 8px 0; font-size: 13px; }
.alert.crit { background: var(--crit-bg); color: var(--crit); }
.alert.warn { background: var(--warn-bg); color: var(--warn); }
.alert.good { background: var(--good-bg); color: var(--good); }
.alert.info { background: var(--surface-2); color: var(--text-2); }

dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

.actions { display: grid; gap: 10px; }
.action { border-top: 1px solid var(--border); padding-top: 10px; }
.action:first-child { border-top: 0; padding-top: 0; }

pre.out { background: var(--surface-2); padding: 10px; border-radius: 8px; overflow: auto; max-height: 360px; font-size: 12px; white-space: pre-wrap; }

/* чат поддержки и переписка */
.msgs { display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 760px; padding: 8px 11px; border-radius: 10px; background: var(--surface-2); white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user { align-self: flex-start; }
.msg.bot { align-self: flex-end; background: var(--surface); border: 1px solid var(--border); }
.msg.human, .msg.assistant { align-self: flex-end; background: var(--good-bg); }
.msg .meta { display: block; font-size: 11px; color: var(--muted); margin-bottom: 2px; white-space: normal; }

/* графики */
.chart { width: 100%; height: auto; display: block; }
.chart .bar { fill: var(--series-1); }
.chart .bar:hover, .chart .bar.hl { opacity: .75; }
.chart .gridl { stroke: var(--grid); stroke-width: 1; }
.chart text { fill: var(--muted); font-size: 10px; font-family: inherit; }
.chart-wrap { position: relative; }
.tip { position: absolute; pointer-events: none; background: var(--text); color: var(--bg); padding: 4px 8px; border-radius: 6px; font-size: 12px; white-space: nowrap; transform: translate(-50%, -110%); display: none; z-index: 5; }
.chart-title { font-weight: 600; font-size: 13px; }
.chart-def { color: var(--muted); font-size: 11.5px; margin-bottom: 4px; }

/* вход */
.login { max-width: 360px; margin: 12vh auto 0; padding: 0 16px; }
.login .card { padding: 22px; }
.login label { display: block; margin: 10px 0 4px; color: var(--text-2); }
.login input { width: 100%; }
.login .btn { width: 100%; margin-top: 16px; padding: 10px; }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 50; max-width: calc(100vw - 32px); }
.toast.err { background: var(--crit); color: #fff; }

.reveal { border: 1px dashed var(--border); border-radius: 8px; padding: 14px; text-align: center; }

@media (max-width: 640px) {
  main { padding: 12px 16px; }
  .top-row { padding: 8px 16px; }
  .who .name { display: none; }
  .stat .val { font-size: 19px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .stat { padding: 10px; }
  .stat .def { font-size: 11px; }
  .who .badge { display: none; }
  .brand span { display: none; }
  dl.kv { grid-template-columns: 1fr; }
  dl.kv dt { margin-top: 6px; }
}
