:root {
  /* Светлая тема — по умолчанию. Тёмная включается переключателем (data-theme="dark"). */
  color-scheme: light;
  --page: #e9eef3;
  --frame: #f4f6f8;
  --card: #ffffff;
  --sidebar: #fbfcfd;
  --text-primary: #111317;
  --text-secondary: #5a606b;
  --text-muted: #8a909a;
  --line: #e8ebef;
  --line-dashed: #dce0e6;
  --head-bar: #f2f4f7;
  --hover: #eef1f5;
  /* Цвета логотипа: градиент от синего к бирюзовому. Для кнопок — тот же синий, темнее (контраст 5,4:1). */
  --brand-blue: #558dca;
  --brand-teal: #55b6c5;
  --brand-grad: linear-gradient(135deg, var(--brand-blue), var(--brand-teal));
  --accent: #2f6cb3;
  --accent-soft: #e4eef9;
  --good-bg: #d9f4e6; --good-fg: #137a43;
  --bad-bg: #fde3e3;  --bad-fg: #c2352f;
  --flat-bg: #eef1f5; --flat-fg: #5a606b;
  --meter-track: #e4eef9;
  --avatar-bg: #e8edf3;
  --shadow: 0 1px 2px rgba(17,19,23,.04), 0 6px 24px rgba(17,19,23,.05);
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0b0c0e; --frame: #121417; --card: #1b1d21; --sidebar: #16181b;
  --text-primary: #f3f4f6; --text-secondary: #b3b8c1; --text-muted: #858b95;
  --line: #2a2d33; --line-dashed: #343840; --head-bar: #23262b; --hover: #262a30;
  --accent: #6fa8e3; --accent-soft: #1c2f45;
  --good-bg: #133826; --good-fg: #5fd394;
  --bad-bg: #431d1c;  --bad-fg: #ff8a80;
  --flat-bg: #2a2d33; --flat-fg: #b3b8c1;
  --meter-track: #1c2f45; --avatar-bg: #2a2d33;
  --shadow: none;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0; background: var(--page); color: var(--text-primary);
  font: 14px/1.45 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* --- рамка приложения --- */
.app {
  display: grid; grid-template-columns: 248px minmax(0, 1fr); gap: 24px;
  max-width: 1440px; margin: 16px auto; padding: 16px;
  background: var(--frame); border-radius: 28px; min-height: calc(100vh - 32px);
}

/* --- сайдбар --- */
.sidebar {
  background: var(--sidebar); border-radius: 22px; padding: 20px 14px;
  display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 32px; align-self: start; min-height: calc(100vh - 64px);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; }
.brand-mark { width: 34px; height: 36px; flex: none; display: block; object-fit: contain; }
.brand-name { font-weight: 600; font-size: 16px; line-height: 1.2; }
.brand-org { color: var(--text-muted); font-size: 12px; }
.nav-title { color: var(--text-muted); font-size: 13px; padding: 14px 10px 6px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 12px;
  color: var(--text-primary); text-decoration: none; font-weight: 500;
}
.nav a:hover { background: var(--hover); }
.nav a[aria-current="page"] { background: var(--hover); }
.nav svg { flex: none; }
.sidebar-foot { margin-top: auto; padding: 10px; color: var(--text-muted); font-size: 12px; display: grid; gap: 10px; }
.demo-note {
  background: var(--accent-soft); color: var(--accent); border-radius: 12px;
  padding: 10px 12px; font-weight: 500; font-size: 13px;
}

/* --- шапка --- */
main { min-width: 0; padding: 12px 4px 24px 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
h1 { font-size: 36px; font-weight: 600; letter-spacing: -0.02em; margin: 0; }
.topbar-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.updated { color: var(--text-muted); font-size: 13px; }
.select-pill {
  position: relative; display: inline-flex; align-items: center; gap: 8px;
  background: var(--card); border-radius: 14px; padding: 0 12px; height: 44px; box-shadow: var(--shadow);
}
.select-pill select {
  appearance: none; -webkit-appearance: none; border: 0; background: none; color: var(--text-primary);
  font: 500 14px Inter, system-ui, sans-serif; padding: 0 22px 0 0; height: 100%; cursor: pointer;
}
.select-pill select:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 6px; }
.select-pill .chev { position: absolute; right: 12px; pointer-events: none; }

#content { transition: opacity .15s; }
#content.loading { opacity: .5; }

/* --- карточки --- */
.card { background: var(--card); border-radius: 24px; padding: 24px; box-shadow: var(--shadow); min-width: 0; }
.card h2 { font-size: 18px; font-weight: 600; margin: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.card-sub { color: var(--text-muted); font-size: 13px; }

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 20px; margin-bottom: 20px; }
.kpi { display: flex; flex-direction: column; gap: 22px; }
.kpi-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.kpi-label { font-size: 15px; font-weight: 500; }
.kpi-value { display: flex; align-items: center; gap: 10px; font-size: 30px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.1; }
.kpi-sub { color: var(--text-muted); font-size: 13px; margin-top: -14px; }

.badge {
  display: inline-flex; align-items: center; gap: 4px; white-space: nowrap;
  font-size: 13px; font-weight: 500; padding: 4px 10px; border-radius: 9px;
  font-variant-numeric: tabular-nums;
}
.badge.good { background: var(--good-bg); color: var(--good-fg); }
.badge.bad  { background: var(--bad-bg);  color: var(--bad-fg); }
.badge.flat { background: var(--flat-bg); color: var(--flat-fg); }
.badge.warn { background: #fdecd7; color: #9a5300; }
:root[data-theme="dark"] .badge.warn { background: #45301a; color: #ffb766; }
.arrow {
  width: 20px; height: 20px; border-radius: 50%; display: inline-grid; place-items: center; flex: none;
}
.arrow.good { background: var(--good-bg); color: var(--good-fg); }
.arrow.bad  { background: var(--bad-bg);  color: var(--bad-fg); }
.arrow.flat { background: var(--flat-bg); color: var(--flat-fg); }

.row2 { display: grid; grid-template-columns: minmax(260px, 1fr) minmax(0, 2.2fr); gap: 20px; margin-bottom: 20px; }

/* очередь сейчас */
.queue { display: grid; gap: 4px; }
.queue-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 0; border-bottom: 1px dashed var(--line-dashed);
}
.queue-row:last-child { border-bottom: 0; }
.queue-label { color: var(--text-secondary); }
.queue-label small { display: block; color: var(--text-muted); font-size: 12px; }
.queue-value { font-size: 28px; font-weight: 600; letter-spacing: -0.02em; display: flex; align-items: center; gap: 8px; }

/* таблицы */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 14px; }
thead th {
  background: var(--head-bar); color: var(--text-secondary); font-weight: 500; text-align: left;
  padding: 11px 16px; white-space: nowrap;
}
thead th:first-child { border-radius: 12px 0 0 12px; }
thead th:last-child { border-radius: 0 12px 12px 0; }
tbody td { padding: 14px 16px; border-bottom: 1px dashed var(--line-dashed); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.strong { font-weight: 600; }
.nowrap { white-space: nowrap; }
td.muted { color: var(--text-secondary); }
.who { display: flex; align-items: center; gap: 10px; font-weight: 500; white-space: nowrap; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--avatar-bg); color: var(--text-secondary);
  display: grid; place-items: center; font-size: 12px; font-weight: 600; flex: none;
}
.meter { display: inline-block; vertical-align: middle; width: 64px; height: 6px; border-radius: 3px; background: var(--meter-track); margin-left: 10px; overflow: hidden; }
.meter b { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.desc { color: var(--text-secondary); max-width: 300px; }
.empty { color: var(--text-muted); padding: 12px 0; }
.error { background: var(--bad-bg); color: var(--bad-fg); border-radius: 16px; padding: 14px 18px; margin-bottom: 20px; }

/* --- адаптив --- */
@media (max-width: 1180px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .row2 { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; margin: 0; border-radius: 0; padding: 12px; gap: 12px; }
  .sidebar { position: static; min-height: 0; flex-direction: row; align-items: center; flex-wrap: wrap; padding: 10px; }
  .brand { padding: 0 6px; }
  .nav-title, .sidebar-foot .version { display: none; }
  .nav { display: flex; gap: 4px; flex-wrap: wrap; }
  .sidebar-foot { margin: 0 0 0 auto; padding: 0; }
  .nav a[aria-current="page"]::before { display: none; }
  h1 { font-size: 28px; }
}
@media (max-width: 520px) {
  .kpis { grid-template-columns: 1fr; gap: 12px; }
  .card { padding: 18px; border-radius: 20px; }
  .kpi-value { font-size: 26px; }
  .nav a span { display: none; }
}

/* ===== Интерфейс с ролями: кнопки, вкладки, формы, окна ===== */
:root { --danger: #d03b3b; --focus: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 40px; padding: 0 16px; border-radius: 12px; border: 0; cursor: pointer;
  font: 500 14px Inter, system-ui, sans-serif; white-space: nowrap;
  background: var(--hover); color: var(--text-primary);
}
.btn:hover { filter: brightness(0.97); }
.btn:focus-visible { outline: none; box-shadow: var(--focus); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.soft { background: var(--accent-soft); color: var(--accent); }
.btn.danger { background: var(--bad-bg); color: var(--bad-fg); }
.btn.ghost { background: transparent; }
.btn.sm { height: 32px; padding: 0 12px; border-radius: 10px; font-size: 13px; }

.user-chip { display: flex; align-items: center; gap: 10px; background: var(--card); border-radius: 14px; padding: 6px 6px 6px 8px; box-shadow: var(--shadow); }
.user-chip .avatar { width: 32px; height: 32px; }
.user-chip .who-name { font-weight: 600; font-size: 14px; line-height: 1.2; }
.user-chip .who-role { color: var(--text-muted); font-size: 12px; }

.tabs { display: inline-flex; background: var(--card); border-radius: 14px; padding: 4px; gap: 2px; box-shadow: var(--shadow); }
.tabs button {
  border: 0; background: none; color: var(--text-secondary); font: 500 14px Inter, system-ui, sans-serif;
  height: 36px; padding: 0 14px; border-radius: 10px; cursor: pointer;
}
.tabs button[aria-selected="true"] { background: var(--hover); color: var(--text-primary); }
.tabs .count { color: var(--text-muted); margin-left: 4px; font-variant-numeric: tabular-nums; }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }

tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--hover); }
tr.clickable:focus-visible td { background: var(--hover); outline: none; }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.dot.on { background: var(--good-fg); }
.dot.off { background: var(--text-muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

/* формы */
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field > span { color: var(--text-secondary); font-size: 13px; font-weight: 500; }
.input, select.input, textarea.input {
  width: 100%; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--card);
  color: var(--text-primary); font: 15px Inter, system-ui, sans-serif; padding: 0 14px;
}
textarea.input { height: auto; min-height: 96px; padding: 12px 14px; resize: vertical; line-height: 1.45; }
.input:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus); }
.checks { display: flex; flex-wrap: wrap; gap: 8px; }
.check {
  display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 10px;
  background: var(--head-bar); cursor: pointer; font-size: 14px; user-select: none;
}
.check input { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }
.hint { color: var(--text-muted); font-size: 12px; }
.form-error { color: var(--bad-fg); background: var(--bad-bg); border-radius: 10px; padding: 10px 12px; font-size: 13px; margin-bottom: 14px; }

/* окно */
dialog.panel {
  border: 0; padding: 0; border-radius: 24px; background: var(--card); color: var(--text-primary);
  width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 32px); box-shadow: 0 24px 64px rgba(0,0,0,.24);
}
dialog.panel::backdrop { background: rgba(17,17,19,.32); }
/* Шапка и кнопки окна всегда видны, прокручивается только содержимое */
dialog.panel[open], dialog.panel[open] > form { display: flex; flex-direction: column; min-height: 0; }
dialog.panel > form { flex: 1; max-height: inherit; }
.panel-body { flex: 1; min-height: 0; }
.panel-foot { border-top: 1px solid var(--line); padding-top: 16px; }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 22px 24px 0; }
.panel-head h2 { font-size: 20px; margin: 0; }
.panel-body { padding: 18px 24px; overflow: auto; }
.panel-foot { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; padding: 0 24px 22px; }
.panel-foot .spacer { flex: 1; }
.close-x { border: 0; background: var(--hover); width: 32px; height: 32px; border-radius: 10px; cursor: pointer; color: var(--text-secondary); flex: none; }
dl.facts { display: grid; grid-template-columns: 120px 1fr; gap: 10px 14px; margin: 0 0 6px; }
dl.facts dt { color: var(--text-muted); font-size: 13px; }
dl.facts dd { margin: 0; }
.section-title { font-size: 13px; color: var(--text-muted); font-weight: 500; margin: 18px 0 10px; }

/* уведомление внизу экрана */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50;
  background: var(--text-primary); color: var(--card); border-radius: 12px; padding: 12px 16px;
  font-size: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.2); max-width: calc(100vw - 32px);
}

/* страница входа */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(420px, 100%); background: var(--card); border-radius: 28px; padding: 32px; box-shadow: var(--shadow); }
.login-card h1 { font-size: 28px; margin: 18px 0 6px; }
.login-card .lead { color: var(--text-secondary); margin: 0 0 22px; }
.login-card .btn { width: 100%; height: 46px; }
.code-input { letter-spacing: .4em; font-size: 22px; text-align: center; font-variant-numeric: tabular-nums; }
.link-btn { border: 0; background: none; color: var(--accent); font: inherit; cursor: pointer; padding: 0; }

[hidden] { display: none !important; }

/* ===== Фирменные цвета ===== */
.btn.primary { background: var(--accent); color: #fff; }
.nav a { position: relative; }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.nav a[aria-current="page"]::before {
  content: ""; position: absolute; left: -14px; top: 8px; bottom: 8px; width: 4px;
  border-radius: 0 4px 4px 0; background: var(--brand-grad);
}
.meter b { background: var(--brand-grad); }
.login-card { border-top: 4px solid transparent; background:
  linear-gradient(var(--card), var(--card)) padding-box, var(--brand-grad) border-box; }

.theme-toggle {
  width: 44px; height: 44px; border-radius: 14px; border: 0; cursor: pointer;
  background: var(--card); color: var(--text-secondary); box-shadow: var(--shadow);
  display: grid; place-items: center; flex: none;
}
.theme-toggle:hover { color: var(--text-primary); }
.theme-toggle:focus-visible { outline: none; box-shadow: var(--focus); }
.theme-toggle .moon { display: none; }
:root[data-theme="dark"] .theme-toggle .moon { display: block; }
:root[data-theme="dark"] .theme-toggle .sun { display: none; }

.profile-link { color: var(--accent); text-decoration: none; font-weight: 500; }
.profile-link:hover { text-decoration: underline; }

ul.history { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; font-size: 13px; }
ul.history li { line-height: 1.4; }
.invite { margin-left: 8px; }
.login-first { margin-top: 18px; padding: 14px; border-radius: 14px; background: var(--accent-soft); font-size: 13px; }
.login-first a.btn { margin-top: 10px; height: 40px; width: 100%; text-decoration: none; }
