:root {
  --bg: #0f1216;
  --bg-elev: #161b22;
  --bg-soft: #1c222b;
  --border: #262d38;
  --text: #e6edf3;
  --muted: #8b98a9;
  --accent: #11a97e;
  --accent-dim: #0d7d5d;
  --info: #4a9eff;
  --warning: #e3b341;
  --average: #f0883e;
  --high: #f85149;
  --disaster: #da3633;
  --ok: #2ea043;
  --shadow: 0 6px 24px rgba(0,0,0,.35);
  --radius: 10px;
}

html[data-theme="light"] {
  --bg: #f4f6f9;
  --bg-elev: #ffffff;
  --bg-soft: #eef1f5;
  --border: #d8dee6;
  --text: #1a1f26;
  --muted: #616d7d;
  --shadow: 0 4px 16px rgba(20,30,50,.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* ---------- вход ---------- */
.login { min-height: 100vh; display: grid; place-items: center; }
.login-box {
  width: 330px; padding: 32px; background: var(--bg-elev);
  border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 12px;
}
.login-logo { font-size: 26px; font-weight: 700; letter-spacing: -.5px; }
.login-sub { color: var(--muted); margin-bottom: 8px; }

/* ---------- каркас ---------- */
.topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 0 20px; height: 56px;
  background: var(--bg-elev); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 17px; color: var(--text); }
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.nav a {
  color: var(--muted); padding: 7px 12px; border-radius: 7px; font-weight: 500;
}
.nav a:hover { background: var(--bg-soft); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--bg-soft); color: var(--text); }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.user { color: var(--muted); }
main { padding: 22px; max-width: 1500px; margin: 0 auto; }
.foot { padding: 8px 22px 24px; color: var(--muted); font-size: 12px; text-align: center; }

/* ---------- элементы ---------- */
.btn {
  border: 1px solid var(--border); background: var(--bg-soft); color: var(--text);
  padding: 7px 13px; border-radius: 8px; cursor: pointer; font-size: 13px; font-weight: 500;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dim); }
.btn.danger { color: var(--high); }
.btn.ghost { background: transparent; }
.btn.wide { width: 100%; padding: 9px; }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.icon-btn { background: none; border: none; color: var(--muted); font-size: 18px; cursor: pointer; }

input, select, textarea {
  background: var(--bg); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; font-size: 13px; font-family: inherit; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-dim); outline-offset: -1px; }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 140px; }
.err { color: var(--high); font-size: 13px; min-height: 18px; }

.card {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
}
.card h2, .card h3 { margin: 0 0 12px; font-size: 15px; font-weight: 600; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 20px; margin: 0; font-weight: 650; }
.spacer { flex: 1; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; color: var(--muted); font-weight: 500; padding: 8px 10px;
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--bg-soft); }
.empty { padding: 28px; text-align: center; color: var(--muted); }

/* ---------- плитки ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 18px; }
.tile { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.tile .n { font-size: 26px; font-weight: 650; letter-spacing: -.5px; }
.tile .l { color: var(--muted); font-size: 12px; margin-top: 2px; }
.tile.alert .n { color: var(--high); }
.tile.ok .n { color: var(--ok); }

/* ---------- карточки хостов ---------- */
.hosts-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 12px; }
.host-card {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; display: block; color: var(--text);
}
.host-card:hover { border-color: var(--accent-dim); text-decoration: none; }
.host-card .hc-top { display: flex; align-items: center; gap: 8px; margin-bottom: 3px; }
.host-card .hc-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.host-card .hc-meta { color: var(--muted); font-size: 12px; margin-bottom: 12px; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--muted); }
.dot.online { background: var(--ok); }
.dot.offline { background: var(--high); }
.dot.disabled { background: var(--muted); }

.gauge { margin-bottom: 8px; }
.gauge-top { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.bar { height: 6px; background: var(--bg-soft); border-radius: 4px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.bar > i.warn { background: var(--warning); }
.bar > i.crit { background: var(--high); }

/* ---------- важность ---------- */
.sev { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.sev.info { background: rgba(74,158,255,.15); color: var(--info); }
.sev.warning { background: rgba(227,179,65,.15); color: var(--warning); }
.sev.average { background: rgba(240,136,62,.15); color: var(--average); }
.sev.high { background: rgba(248,81,73,.15); color: var(--high); }
.sev.disaster { background: rgba(218,54,51,.2); color: var(--disaster); }
.sev.resolved { background: rgba(46,160,67,.15); color: var(--ok); }

.tag { display: inline-block; background: var(--bg-soft); border: 1px solid var(--border);
  padding: 1px 7px; border-radius: 20px; font-size: 11px; color: var(--muted); margin-right: 4px; }

/* ---------- графики ---------- */
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 12px; }
.chart-card { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 14px 6px; }
.chart-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 6px; }
.chart-head h3 { margin: 0; font-size: 14px; font-weight: 600; }
.chart-head .now { margin-left: auto; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.chart { width: 100%; height: 190px; display: block; touch-action: none; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart .axis-text { fill: var(--muted); font-size: 10px; }
.chart .cursor-line { stroke: var(--muted); stroke-dasharray: 3 3; }
.legend { display: flex; flex-wrap: wrap; gap: 10px; font-size: 11px; color: var(--muted); padding: 4px 0 8px; }
.legend i { display: inline-block; width: 9px; height: 3px; border-radius: 2px; margin-right: 4px; vertical-align: middle; }
.chart-tip {
  position: fixed; pointer-events: none; z-index: 50; background: var(--bg-elev);
  border: 1px solid var(--border); border-radius: 7px; padding: 7px 9px; font-size: 12px;
  box-shadow: var(--shadow); white-space: nowrap;
}

.periods { display: flex; gap: 4px; }
.periods button { padding: 5px 10px; font-size: 12px; }
.periods button.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- модальные окна ---------- */
.modal-bg {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 100;
  display: grid; place-items: center; padding: 20px;
}
.modal {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 14px;
  padding: 20px; width: 520px; max-width: 100%; max-height: 88vh; overflow: auto; box-shadow: var(--shadow);
}
.modal h2 { margin: 0 0 16px; font-size: 17px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }

/* ---------- уведомления ---------- */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--bg-elev); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: 8px; padding: 10px 14px; box-shadow: var(--shadow); max-width: 380px;
}
.toast.error { border-left-color: var(--high); }

.badge { background: var(--high); color: #fff; border-radius: 20px; padding: 0 6px; font-size: 11px; font-weight: 700; }

.code {
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px; overflow-x: auto; white-space: pre; margin: 6px 0 14px;
}

/* длинные таблицы прокручиваются внутри карточки, а не растягивают страницу */
.scroll-box { max-height: 440px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; }
.scroll-box thead th { position: sticky; top: 0; background: var(--bg-elev); z-index: 1; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 13px; }
.kv .k { color: var(--muted); }

@media (max-width: 720px) {
  .topbar { height: auto; flex-wrap: wrap; padding: 10px 14px; gap: 10px; }
  main { padding: 14px; }
  .charts { grid-template-columns: 1fr; }
}
