:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --panel-2: #f8f9fb;
  --text: #1c1f24;
  --muted: #6b7280;
  --line: #e3e6ea;
  --accent: #2f6fde;
  --accent-text: #ffffff;
  --accent-soft: #e8f0fd;
  --ok: #1f8a4c;
  --ok-soft: #e6f5ec;
  --bad: #c9372c;
  --bad-soft: #fdecea;
  --warn: #a96a00;
  --warn-soft: #fff4dc;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 2px 8px rgba(0, 0, 0, .04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171b; --panel: #1e2126; --panel-2: #24282e; --text: #e8eaed; --muted: #9aa1ab; --line: #31363d;
    --accent: #5b93f0; --accent-text: #0d1117; --accent-soft: #1f2d45; --ok: #49c27c; --ok-soft: #173326;
    --bad: #f0796f; --bad-soft: #3a1f1d; --warn: #e7b14d; --warn-soft: #3a2e15; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15171b; --panel: #1e2126; --panel-2: #24282e; --text: #e8eaed; --muted: #9aa1ab; --line: #31363d;
  --accent: #5b93f0; --accent-text: #0d1117; --accent-soft: #1f2d45; --ok: #49c27c; --ok-soft: #173326;
  --bad: #f0796f; --bad-soft: #3a1f1d; --warn: #e7b14d; --warn-soft: #3a2e15; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
h1 { font-size: 20px; margin: 0 0 14px; }
h2 { font-size: 16px; margin: 0 0 10px; }
h3 { font-size: 14px; margin: 14px 0 8px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
code { font-size: 13px; background: var(--panel-2); padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: 8px; }
.right { margin-left: auto; }
.mt { margin-top: 12px; }
.pre { white-space: pre-wrap; word-break: break-word; }

/* каркас: вкладки сверху, меню вкладки слева, окно метрик справа */
.shell { min-height: 100vh; display: flex; flex-direction: column; }
.top {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: stretch; gap: 8px; padding: 0 16px;
  background: var(--panel); border-bottom: 1px solid var(--line); min-height: 52px;
}
.brand { display: flex; gap: 6px; align-items: center; font-weight: 700; font-size: 16px; white-space: nowrap; padding-right: 8px; }
.brand small { font-weight: 400; color: var(--muted); font-size: 12px; }
.tabs-top { display: flex; gap: 2px; overflow-x: auto; flex: 1; min-width: 0; scrollbar-width: none; }
.tabs-top::-webkit-scrollbar { display: none; }
.tabs-top a {
  display: flex; gap: 6px; align-items: center; padding: 0 14px; color: var(--muted); text-decoration: none; white-space: nowrap;
  border-bottom: 2px solid transparent; font-weight: 500;
}
.tabs-top a:hover { color: var(--text); background: var(--panel-2); }
.tabs-top a.on { color: var(--accent); border-bottom-color: var(--accent); }
.who { display: flex; gap: 10px; align-items: center; white-space: nowrap; font-size: 13px; color: var(--muted); }
.body { flex: 1; display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 0; }
.body.no-side { grid-template-columns: minmax(0, 1fr); }
.side { background: var(--panel); border-right: 1px solid var(--line); position: sticky; top: 52px; height: calc(100vh - 52px); overflow-y: auto; }
.side-title { padding: 14px 16px 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; }
.nav a {
  display: flex; gap: 10px; align-items: center; padding: 8px 16px; color: var(--text); text-decoration: none;
  border-left: 3px solid transparent;
}
.nav a:hover { background: var(--panel-2); }
.nav a.on { background: var(--accent-soft); border-left-color: var(--accent); font-weight: 600; }
.main { min-width: 0; padding: 20px 24px 80px; }
.body:not(.no-side) .main { max-width: 1180px; }
@media (min-width: 1100px) { body.mh-metrics-open .main { padding-right: 270px; } }
.metrics { position: fixed; right: 0; top: 50%; transform: translateY(-50%); z-index: 40; }
body.mh-notes-open .metrics { top: 30%; }
.metrics-tab {
  border-radius: 10px 0 0 10px; border-right: 0; padding: 10px 8px; font-size: 18px; box-shadow: var(--shadow); position: relative;
}
.metrics-tab .dot { position: absolute; top: -6px; left: -6px; background: var(--bad); color: #fff; font-size: 11px; border-radius: 99px; padding: 0 6px; }
.metrics-box {
  width: 230px; max-height: 50vh; overflow-y: auto; margin-right: 12px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: 0 6px 24px rgba(0,0,0,.12); padding: 6px 0;
}
.metrics-head { padding: 4px 12px 6px; border-bottom: 1px solid var(--line); }
.metric { display: flex; gap: 8px; padding: 6px 12px; color: var(--text); text-decoration: none; font-size: 13px; }
.metric[href]:hover { background: var(--panel-2); }
.metric b { font-size: 15px; }
.metric.alert b { color: var(--bad); }

@media (max-width: 820px) {
  .top { padding: 0 8px; flex-wrap: wrap; }
  .brand-name, .who-name { display: none; }
  .tabs-top { order: 3; flex-basis: 100%; border-top: 1px solid var(--line); }
  .tabs-top a { padding: 10px 10px; }
  .body { display: block; }
  .side { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .side-title { display: none; }
  .nav { display: flex; overflow-x: auto; gap: 4px; padding: 8px; }
  .nav a { border: 1px solid var(--line); border-radius: 99px; padding: 6px 12px; white-space: nowrap; }
  .nav a.on { border-color: var(--accent); }
  .main { padding: 14px 12px 80px; }
  .metrics-box { width: min(260px, calc(100vw - 40px)); }
}

/* карточки и таблицы */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card + .card { margin-top: 12px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; align-items: start; }
.cards > .card { margin-top: 0; }
.stat { font-size: 26px; font-weight: 700; }
.list { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); overflow: hidden; }
.list > .item { padding: 10px 14px; border-top: 1px solid var(--line); display: flex; gap: 10px; align-items: center; }
.list > .item:first-child { border-top: 0; }
.list > .item.click { cursor: pointer; }
.list > .item.click:hover { background: var(--panel-2); }
.tbl-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
table.tbl { border-collapse: collapse; width: 100%; font-size: 14px; }
.tbl th, .tbl td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.tbl th { background: var(--panel-2); font-weight: 600; font-size: 13px; color: var(--muted); }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: var(--panel-2); }

/* формы */
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
label.field > span { font-weight: 600; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea { width: 100%; min-height: 110px; resize: vertical; }
input[type=number] { width: 110px; }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); }
.check { display: flex; gap: 10px; align-items: center; cursor: pointer; padding: 6px 0; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }

button, .btn {
  font: inherit; font-size: 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel);
  color: var(--text); padding: 7px 14px; cursor: pointer; text-decoration: none; display: inline-flex; gap: 6px;
  align-items: center; white-space: nowrap;
}
button:hover, .btn:hover { background: var(--panel-2); }
button:disabled { opacity: .5; cursor: default; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.primary:hover { filter: brightness(1.07); }
button.danger { color: var(--bad); border-color: var(--bad); }
button.danger:hover { background: var(--bad-soft); }
button.ok { color: var(--ok); border-color: var(--ok); }
button.ok:hover { background: var(--ok-soft); }
button.link { border: 0; background: none; color: var(--accent); padding: 0; }
button.sm { padding: 4px 10px; font-size: 13px; }

.badge { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 99px; background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.note { padding: 10px 12px; border-radius: 8px; background: var(--panel-2); border: 1px solid var(--line); font-size: 14px; }
.note.warn { background: var(--warn-soft); border-color: transparent; }
.note.bad { background: var(--bad-soft); border-color: transparent; }
.note.ok { background: var(--ok-soft); border-color: transparent; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 8px 12px; }
.tabs button.on { border-bottom-color: var(--accent); color: var(--accent); font-weight: 600; }

/* всплывающие */
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; max-width: calc(100vw - 32px); }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); font-size: 14px; max-width: 420px; }
.toast.bad { background: var(--bad); color: #fff; }
.modal-veil { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 90; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: var(--panel); border-radius: 12px; padding: 18px; width: 100%; max-width: 520px; box-shadow: var(--shadow); max-height: 90vh; overflow-y: auto; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }

.center { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login { max-width: 440px; text-align: center; }
.login .logo { font-size: 48px; }
.spinner { display: inline-block; width: 18px; height: 18px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty { padding: 30px; text-align: center; color: var(--muted); }

/* подсказка ⓘ */
.info { display: inline-flex; align-items: center; justify-content: center; width: 17px; height: 17px; margin-left: 6px;
  border-radius: 50%; border: 1.5px solid var(--accent); color: var(--accent); cursor: help; font: italic 700 11px/1 Georgia, serif;
  vertical-align: middle; position: relative; flex: 0 0 auto; }
.info:hover, .info:focus { background: var(--accent-soft); outline: none; }
.info-pop { position: fixed; z-index: 120; background: var(--panel); color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: 0 8px 28px rgba(0,0,0,.18); padding: 12px 14px; font: normal 400 13px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5; text-align: left; cursor: default; max-height: 60vh; overflow-y: auto; }
.info-title { display: block; margin-bottom: 6px; font-size: 14px; }
