:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #14181f;
  --muted: #5b6675;
  --line: #e2e7ee;
  --accent: #2f6fed;
  --accent-weak: #e8efff;
  --ok: #1f9d55;
  --warn: #c47a00;
  --danger: #d64545;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 2px 10px rgba(16, 24, 40, 0.04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10151c;
    --card: #171d26;
    --text: #e8edf4;
    --muted: #93a1b3;
    --line: #25303d;
    --accent: #6b9bff;
    --accent-weak: #1c2940;
    --ok: #4ade80;
    --warn: #f5b301;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

#app { max-width: 560px; margin: 0 auto; padding: 12px 12px 82px; }

.hd h1 { font-size: 19px; margin: 2px 0 1px; letter-spacing: -0.2px; }
.hd .sub { margin: 0 0 8px; color: var(--muted); font-size: 12px; }

/* Вкладки — текстовые, с подчёркиванием, как в DDX */
.tabs {
  display: flex; gap: 16px; margin-bottom: 9px;
  border-bottom: 1px solid var(--line);
}
.tab {
  border: 0; border-bottom: 2px solid transparent; border-radius: 0;
  background: transparent; color: var(--muted);
  padding: 7px 0 6px; font-size: 13.5px; font-weight: 600;
  cursor: pointer; font-family: inherit;
}
.tab.on { color: var(--text); border-bottom-color: var(--accent); }
.dot {
  display: inline-block; width: 6px; height: 6px; margin-left: 5px;
  border-radius: 50%; background: var(--danger); vertical-align: middle;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 11px 12px;
  margin-bottom: 8px;
}

.card h2 { font-size: 14px; margin: 0 0 7px; display: flex; align-items: center; gap: 7px; }
.card h2 .n {
  display: inline-grid; place-items: center;
  width: 19px; height: 19px; border-radius: 6px;
  background: var(--accent-weak); color: var(--accent);
  font-size: 11px; font-weight: 700;
}

input[type="search"], input[type="text"], #time-custom {
  width: 100%; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 9px;
  background: transparent; color: var(--text); font-size: 14px;
  outline: none;
}
input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }

.list { list-style: none; margin: 7px 0 0; padding: 0; }
.list li {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 6px; border-radius: 9px; cursor: pointer;
  border: 1px solid transparent;
}
.list li:hover { background: var(--accent-weak); }
.list li.sel { background: var(--accent-weak); border-color: var(--accent); }
.list li .t { flex: 1; min-width: 0; }
.list li .t b { display: block; font-weight: 600; font-size: 13px; }
.list li .t span { display: block; color: var(--muted); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; }

.ava {
  width: 26px; height: 26px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 12px;
}

.group {
  margin: 9px 0 2px; color: var(--muted);
  font-size: 10px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
}
.group:first-child { margin-top: 3px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  padding: 6px 10px; border-radius: 999px; font-size: 12.5px; cursor: pointer;
  font-family: inherit;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* Специальности — компактные кнопки в столбик, с полным названием */
#spec-list { display: flex; flex-direction: column; gap: 5px; }
#spec-list .chip {
  width: 100%; text-align: left; border-radius: 8px;
  padding: 7px 9px; font-size: 12.5px; line-height: 1.3;
  white-space: normal; word-break: break-word;
}

.chip.star { color: #8a5a00; background: #fff4cc; border-color: #f0c14b; min-width: 34px; padding: 5px 9px; }
.chip.star.on { background: #f5b301; border-color: #f5b301; color: #1a1a1a; }

@media (prefers-color-scheme: dark) {
  .chip.star { background: #3a2f12; color: #f5c542; border-color: #6b5518; }
  .chip.star.on { background: #f5b301; border-color: #f5b301; color: #1a1a1a; }
}

.selected { margin-top: 8px; padding: 8px; border-radius: 9px; background: var(--accent-weak); font-size: 12px; }
.selected b { display: block; line-height: 1.3; }
.selected span { color: var(--muted); display: block; margin-top: 1px; }

.check { display: flex; align-items: center; gap: 7px; margin-top: 7px; font-size: 12.5px; color: var(--muted); }
.check input { flex: none; }

.row { display: flex; gap: 6px; margin-top: 7px; }
.row input { flex: 1; }

.ghost, .primary, .secondary {
  border-radius: 9px; padding: 8px 12px; font-size: 13px; font-weight: 600;
  cursor: pointer; border: 1px solid var(--line); background: var(--card); color: var(--text);
  font-family: inherit;
}
.ghost { margin-top: 7px; }
.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.secondary { background: var(--accent-weak); border-color: var(--accent-weak); color: var(--accent); }
.primary:active, .secondary:active, .ghost:active { transform: translateY(1px); }

.actions {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex; gap: 8px; padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
  max-width: 560px; margin: 0 auto;
  z-index: 6;
}
.actions button { flex: 1; padding: 9px 10px; }

.hidden { display: none !important; }

/* Тумблер включения мониторинга */
.switch-row {
  display: flex; align-items: center; gap: 10px; cursor: pointer;
  margin: 0; font-size: 14px;
}
.switch-text { flex: 1; min-width: 0; }
.switch-text b { display: block; font-weight: 600; font-size: 14px; }
.switch-text small { display: block; color: var(--muted); font-size: 11.5px; margin-top: 1px; }
.switch-row input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; }
.switch {
  width: 40px; height: 24px; border-radius: 999px; flex: none;
  background: var(--line); position: relative;
  transition: background 0.15s ease;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 18px; height: 18px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.25);
  transition: transform 0.15s ease;
}
.switch-row input:checked + .switch { background: var(--ok); }
.switch-row input:checked + .switch::after { transform: translateX(16px); }
.switch-row input:focus-visible + .switch { box-shadow: 0 0 0 3px var(--accent-weak); }

/* Диагностика — плотные строки и цветовые сигналы */
.diag-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.diag-head h2 { margin: 0; }
.diag-refresh { margin: 0; padding: 5px 9px; font-size: 11.5px; }
.diag-summary { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; }
.diag-status { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.dot-status { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.dot-status.ok { background: var(--ok); }
.dot-status.bad { background: var(--danger); }
.diag-kpis { display: flex; gap: 16px; }
.kpi { display: flex; align-items: baseline; gap: 5px; }
.kpi span { color: var(--muted); font-size: 11px; }
.kpi b { font-size: 16px; line-height: 1; }
.diag-last { font-size: 11.5px; line-height: 1.35; }
.diag-last.bad { color: var(--danger); }
.diag-list { list-style: none; margin: 7px 0 0; padding: 2px 0 0; border-top: 1px solid var(--line); }
.ev {
  display: grid; grid-template-columns: 40px 1fr 38px 58px; gap: 6px;
  align-items: baseline; padding: 6px 0;
  border-bottom: 1px solid var(--line); font-size: 12px;
}
.ev:last-child { border-bottom: 0; }
.ev-time { color: var(--muted); font-size: 10.5px; }
.ev-kind { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ev-code { text-align: right; font-weight: 600; }
.ev-code.ok { color: var(--ok); }
.ev-code.bad { color: var(--danger); }
.ev-ms { text-align: right; color: var(--muted); font-size: 10.5px; }
.ev-ms.slow { color: var(--warn); font-weight: 600; }
.ev-detail { grid-column: 1 / -1; color: var(--danger); font-size: 11px; line-height: 1.3; word-break: break-word; }
.ok { color: var(--ok); }
.bad { color: var(--danger); }

.toast {
  position: fixed; left: 50%; bottom: 72px; transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 8px 14px; border-radius: 9px; font-size: 13px; max-width: 90vw; z-index: 10;
}
.toast.err { background: var(--danger); color: #fff; }

.muted { color: var(--muted); font-size: 12px; }
