:root {
  --bg: #f6f4f1;
  --card: #ffffff;
  --text: #1d1e22;
  --muted: #7a7e87;
  --line: #ece8e3;
  --side: #1b1c1f;
  --side-text: #c9ccd3;
  --accent: #ff5a2f;
  --grad: linear-gradient(135deg, #ff9a3d 0%, #ff3a30 100%);
  --ok: #178a4a;
  --ok-soft: #e6f6ec;
  --bad: #d92d20;
  --bad-soft: #fdecea;
  --wait: #a56200;
  --wait-soft: #fff3dc;
  --code: #f2efeb;
  --shadow: 0 1px 2px rgba(31, 32, 35, 0.04), 0 8px 24px rgba(31, 32, 35, 0.05);
  --c-out: #a8abb3;
  --c-err: #ff7a7a;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141517;
    --card: #1e1f23;
    --text: #ececee;
    --muted: #9a9ea8;
    --line: #2c2d32;
    --side: #0f1012;
    --ok: #5fd08a;
    --ok-soft: #173525;
    --bad: #ff8a80;
    --bad-soft: #3d1f1d;
    --wait: #f2c46d;
    --wait-soft: #3a2f17;
    --code: #26272c;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
h1 { font-size: 28px; margin: 0 0 6px; letter-spacing: -0.01em; }
h2 { font-size: 18px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 16px 0 8px; }
.muted, .hint { color: var(--muted); }
.hint { display: block; font-size: 13px; margin-top: 4px; }
code, pre { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 13px; }
code { background: var(--code); padding: 1px 6px; border-radius: 4px; }
pre.code, pre.token { background: var(--code); padding: 12px; border-radius: 10px; overflow-x: auto; white-space: pre-wrap; word-break: break-all; }

/* Оболочка кабинета: темное меню слева, светлая рабочая область */
.shell { display: flex; min-height: 100vh; padding: 14px; gap: 18px; }
.side {
  width: 244px; flex: none; background: var(--side); color: var(--side-text); border-radius: 22px;
  padding: 20px 14px; display: flex; flex-direction: column; position: sticky; top: 14px; height: calc(100vh - 28px);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 10px 18px; color: #fff; text-decoration: none; font-weight: 700; font-size: 22px; }
.brand img { width: 36px; height: 36px; }
.menu { display: grid; gap: 4px; }
.menu a {
  display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: 999px;
  color: var(--side-text); text-decoration: none; font-weight: 500;
}
.menu a:hover { background: rgba(255, 255, 255, 0.07); color: #fff; }
.menu a.active { background: var(--grad); color: #fff; box-shadow: 0 6px 18px rgba(255, 90, 47, 0.35); }
.menu svg { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.menu hr { border: 0; border-top: 1px solid rgba(255, 255, 255, 0.1); margin: 10px 8px; width: 100%; }
.side-foot { margin-top: auto; padding: 12px 10px 0; font-size: 13px; display: flex; align-items: center; gap: 8px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #3ddc84; display: inline-block; }
.dot.bad { background: #ff5a4f; }
.content { flex: 1; min-width: 0; padding: 6px 6px 32px; }
.topbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.topbar p { margin: 0; color: var(--muted); }
.who { display: flex; align-items: center; gap: 10px; }
.search { background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 4px 6px 4px 16px; display: flex; gap: 8px; align-items: center; min-width: 280px; box-shadow: var(--shadow); }
.search input { border: 0; background: transparent; padding: 6px 0; min-width: 0; flex: 1; }
.search input:focus { outline: none; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--grad); color: #fff; display: grid; place-items: center; font-weight: 600; flex: none; }
.logout { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; padding: 4px 8px; }

/* Карточки и сетка */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 20px; margin: 16px 0; box-shadow: var(--shadow); }
.card.accent { border-color: #ffb48a; background: #fff6ef; }
@media (prefers-color-scheme: dark) { .card.accent { background: #2b2018; border-color: #6b3b1f; } }
.card h2 { margin-bottom: 10px; }
.grid { display: grid; gap: 16px; }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cols-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); align-items: start; }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid > .card { margin: 0; }
.stack { display: grid; gap: 16px; align-content: start; }
.stack > .card { margin: 0; }
@media (max-width: 1100px) { .cols-main, .cols-3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 860px) {
  .shell { flex-direction: column; padding: 8px; }
  .side { width: auto; position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px; }
  .menu { display: flex; flex-wrap: wrap; flex: 1; }
  .menu hr, .side-foot { display: none; }
  .brand { padding: 0 8px 0 4px; }
  .cols-main, .cols-3, .cols-2 { grid-template-columns: 1fr; }
}
.inst-card { display: grid; gap: 8px; }
.inst-head { display: flex; align-items: center; gap: 12px; }
.chan { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 700; flex: none; }
.chan.telegram { background: #2aabee; }
.chan.max { background: #6a5cff; }
.inst-head b { display: block; font-size: 16px; }
.inst-foot { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; margin-top: 6px; }
.empty { text-align: center; padding: 28px 12px; color: var(--muted); }

/* График */
.chart-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--muted); margin: 6px 0 14px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }
.chart { display: grid; grid-template-columns: 36px 1fr; gap: 8px; height: 230px; }
.axis { display: flex; flex-direction: column-reverse; justify-content: space-between; text-align: right; font-size: 12px; color: var(--muted); padding-bottom: 22px; }
.bars { display: grid; grid-template-columns: repeat(7, 1fr); border-bottom: 1px solid var(--line); }
.bars .day { display: flex; flex-direction: column; justify-content: flex-end; align-items: center; position: relative; padding-bottom: 22px; }
.bars .pair { display: flex; align-items: flex-end; gap: 4px; height: 100%; width: 100%; justify-content: center; }
.bars .bar { width: 14px; border-radius: 5px 5px 0 0; min-height: 3px; }
.bar.in { background: linear-gradient(#ffd24d, #ff9a3d); }
.bar.out { background: var(--c-out); }
.bar.err { background: var(--c-err); width: 8px; }
.bars .day span { position: absolute; bottom: 2px; font-size: 12px; color: var(--muted); }
.bars .day.today .bar.in { background: linear-gradient(#ff9a3d, #ff3a30); }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 18px; }
.kpi { border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; }
.kpi small { color: var(--muted); display: block; }
.kpi b { font-size: 26px; margin-right: 8px; }
.pill { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--ok-soft); color: var(--ok); font-weight: 600; }
.pill.bad { background: var(--bad-soft); color: var(--bad); }

/* Лента */
.feed { list-style: none; margin: 0; padding: 0; display: grid; }
.feed li { display: grid; grid-template-columns: 38px 1fr auto; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.feed li:last-child { border-bottom: 0; }
.feed b { display: block; font-weight: 500; }
.feed small { color: var(--muted); }
.ico { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; background: #fff1e0; color: #e07a10; font-weight: 700; }
.ico.ok { background: var(--ok-soft); color: var(--ok); }
.ico.bad { background: var(--bad-soft); color: var(--bad); }
.ico.wait { background: var(--wait-soft); color: var(--wait); }
.time { color: var(--muted); font-size: 13px; }
.status { font-size: 12px; padding: 3px 12px; border-radius: 999px; border: 1px solid currentColor; font-weight: 600; }
.status.ok { color: var(--ok); }
.status.bad { color: var(--bad); }
.status.wait { color: var(--wait); }
.progress { height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; margin-top: 6px; }
.progress i { display: block; height: 100%; background: var(--grad); }
.file-row { display: flex; align-items: center; gap: 12px; border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; flex-wrap: wrap; }
.file-row b { flex: 1; min-width: 120px; }

/* Формы и кнопки */
.form { display: grid; gap: 12px; max-width: 560px; }
.form label { display: grid; gap: 4px; font-weight: 500; }
.form label.check, label.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #ffb48a; outline-offset: 0; }
input[type=checkbox] { width: auto; margin-top: 4px; }
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; display: grid; gap: 4px; }
legend { color: var(--muted); padding: 0 4px; }
.btn {
  display: inline-block; background: var(--grad); color: #fff; border: 0; border-radius: 12px;
  padding: 10px 18px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:hover { filter: brightness(1.05); }
.btn.small { padding: 6px 12px; font-size: 14px; }
.btn.ghost { background: transparent; color: var(--accent); border: 1px solid #ffb48a; }
.btn.danger { background: var(--bad); }
button.link { background: none; border: 0; color: var(--accent); font: inherit; cursor: pointer; padding: 0; }
form.inline { display: inline; }
form.danger { margin-top: 16px; }
.flash { padding: 10px 14px; border-radius: 12px; margin: 8px 0; background: var(--ok-soft); color: var(--ok); }
.flash.bad { background: var(--bad-soft); color: var(--bad); }
.badge { display: inline-block; padding: 2px 12px; border-radius: 999px; font-size: 12px; font-weight: 600; border: 1px solid currentColor; }
.badge.ok { color: var(--ok); }
.badge.bad { color: var(--bad); }
.badge.wait { color: var(--wait); }
.table { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; display: block; overflow-x: auto; }
.table th, .table td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { color: var(--muted); font-weight: 500; font-size: 13px; }
.table.small td { font-size: 14px; }
details.help { margin-top: 12px; }
details.help summary { cursor: pointer; color: var(--accent); }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 14px; }
.filters label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.filters select, .filters input { min-width: 150px; width: auto; }

/* Публичные страницы */
.wrap { max-width: 1040px; margin: 0 auto; padding: 0 16px; }
.top { background: var(--card); border-bottom: 1px solid var(--line); }
.top-row { display: flex; align-items: center; justify-content: space-between; min-height: 60px; gap: 12px; flex-wrap: wrap; }
.logo { font-weight: 700; font-size: 20px; color: var(--text); text-decoration: none; display: flex; align-items: center; gap: 8px; }
.logo img { width: 30px; height: 30px; }
nav { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
nav a { text-decoration: none; }
main.wrap { padding-top: 24px; padding-bottom: 32px; }
.narrow { max-width: 420px; margin: 32px auto; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin: 16px 0; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid2 .card, .grid3 .card { margin: 0; }
@media (max-width: 760px) { .grid2, .grid3 { grid-template-columns: 1fr; } }
.hero { padding: 24px 0 8px; }
.hero h1 { font-size: 34px; max-width: 760px; }
.lead { font-size: 18px; color: var(--muted); max-width: 760px; }
.foot { color: var(--muted); font-size: 13px; padding-bottom: 24px; }

:root[data-theme="dark"] {
    --bg: #141517;
    --card: #1e1f23;
    --text: #ececee;
    --muted: #9a9ea8;
    --line: #2c2d32;
    --side: #0f1012;
    --ok: #5fd08a;
    --ok-soft: #173525;
    --bad: #ff8a80;
    --bad-soft: #3d1f1d;
    --wait: #f2c46d;
    --wait-soft: #3a2f17;
    --code: #26272c;
    --shadow: none;
}
