:root {
  --bg: #f6f7f9; --surface: #ffffff; --surface-2: #f0f2f5; --border: #dfe3e8;
  --text: #1c2430; --muted: #5d6877; --accent: #2563eb; --accent-text: #ffffff;
  --ok: #15803d; --ok-bg: #e3f4e8; --warn: #a15c07; --warn-bg: #fdf0d5;
  --crit: #b42318; --crit-bg: #fde4e1; --off: #5d6877; --off-bg: #e8ebef;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f141b; --surface: #171e27; --surface-2: #1f2833; --border: #2b3643;
    --text: #e6eaf0; --muted: #96a2b3; --accent: #5b8def; --accent-text: #0b1220;
    --ok: #5fcf85; --ok-bg: #12301d; --warn: #f0b955; --warn-bg: #36290e;
    --crit: #ff8a7d; --crit-bg: #3b1714; --off: #96a2b3; --off-bg: #232d39;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #0f141b; --surface: #171e27; --surface-2: #1f2833; --border: #2b3643;
  --text: #e6eaf0; --muted: #96a2b3; --accent: #5b8def; --accent-text: #0b1220;
  --ok: #5fcf85; --ok-bg: #12301d; --warn: #f0b955; --warn-bg: #36290e;
  --crit: #ff8a7d; --crit-bg: #3b1714; --off: #96a2b3; --off-bg: #232d39;
  --shadow: none;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
.wrap { max-width: 1280px; margin: 0 auto; padding: 0 16px; }

header.top { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
header.top .wrap { display: flex; align-items: center; gap: 20px; height: 54px; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 650; font-size: 16px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand svg { width: 24px; height: 24px; }
nav { display: flex; gap: 4px; }
nav a { white-space: nowrap; color: var(--muted); padding: 7px 11px; border-radius: 7px; font-weight: 500; }
nav a:hover { background: var(--surface-2); text-decoration: none; }
nav a.active { color: var(--text); background: var(--surface-2); }
nav .count { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 5px; border-radius: 9px; background: var(--crit-bg); color: var(--crit); font-size: 12px; text-align: center; }
.spacer { flex: 1; }
.top .tools { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12.5px; }

main { padding: 20px 0 48px; }
h1 { font-size: 20px; margin: 0 0 14px; font-weight: 650; }
h2 { font-size: 15px; margin: 0 0 10px; font-weight: 650; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: 12.5px; }

.btn { border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 7px 13px; cursor: pointer; font-weight: 500; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--crit); }
.btn.sm { padding: 4px 9px; font-size: 12.5px; }
.btn:disabled { opacity: .55; cursor: default; }
input[type=text], input[type=search], input[type=password], input[type=date], select, textarea {
  border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 7px 10px; min-width: 0;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { width: 100%; resize: vertical; min-height: 64px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { text-align: left; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; cursor: pointer; box-shadow: var(--shadow); }
.tile:hover { border-color: var(--accent); }
.tile.on { border-color: var(--accent); outline: 1px solid var(--accent); }
.tile .num { display: block; font-size: 26px; font-weight: 650; line-height: 1.2; }
.tile .lbl { color: var(--muted); font-size: 12.5px; }
.tile.crit .num { color: var(--crit); } .tile.warn .num { color: var(--warn); } .tile.okc .num { color: var(--ok); }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 12px; }
.toolbar input[type=search] { width: 260px; max-width: 100%; }

.tablewrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; white-space: nowrap; background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
tbody tr.link:hover { background: var(--surface-2); cursor: pointer; }
td.num, th.num { text-align: right; white-space: nowrap; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px 2px 8px; border-radius: 999px; font-size: 12.5px; font-weight: 550; white-space: nowrap; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.ok { color: var(--ok); background: var(--ok-bg); }
.badge.warning { color: var(--warn); background: var(--warn-bg); }
.badge.critical { color: var(--crit); background: var(--crit-bg); }
.badge.offline, .badge.info { color: var(--off); background: var(--off-bg); }
.badge.plain::before { display: none; }

.bar { position: relative; width: 90px; height: 7px; border-radius: 4px; background: var(--surface-2); display: inline-block; vertical-align: middle; margin-right: 7px; overflow: hidden; }
.bar > i { position: absolute; inset: 0 auto 0 0; background: var(--accent); border-radius: 4px; }
.bar.warn > i { background: var(--warn); } .bar.crit > i { background: var(--crit); }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px 24px; }
.kv .k { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.kv .v { margin-top: 1px; word-break: break-word; }
.head { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 16px; }
.head h1 { margin: 0; }
.crumb { font-size: 13px; margin-bottom: 8px; display: block; }
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; }
.chart .t { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
.chart svg { display: block; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linejoin: round; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart .thr { stroke: var(--crit); stroke-width: 1; stroke-dasharray: 4 3; }
.chart text { fill: var(--muted); font-size: 10.5px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 5px 11px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--accent); color: var(--accent-text); }

.msg { min-width: 220px; max-width: 760px; word-break: break-word; white-space: pre-wrap; }
.alert-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-start; padding: 8px 0; border-bottom: 1px solid var(--border); }
.alert-row:last-child { border-bottom: 0; }
.alert-row .body { flex: 1 1 200px; min-width: 0; word-break: break-word; }

.overlay { position: fixed; inset: 0; background: rgba(8, 12, 18, .55); display: flex; align-items: flex-start; justify-content: center; padding: 8vh 16px 16px; z-index: 20; overflow-y: auto; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; width: 100%; max-width: 520px; padding: 20px; }
.modal h2 { font-size: 17px; margin-bottom: 14px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
.field input[type=text], .field input[type=date], .field select, .field textarea { width: 100%; }
.checks { display: flex; gap: 16px; flex-wrap: wrap; }
.checks label { display: inline-flex; gap: 6px; align-items: center; color: var(--text); font-size: 14px; margin: 0; }
.actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }
pre.code { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; overflow-x: auto; margin: 6px 0; font: 12.5px/1.5 ui-monospace, Consolas, monospace; white-space: pre-wrap; word-break: break-all; }
.notice { background: var(--warn-bg); color: var(--warn); border-radius: 8px; padding: 9px 12px; margin: 10px 0; }
.err { color: var(--crit); margin-top: 8px; }

.login { max-width: 360px; margin: 14vh auto 0; }
.login .card { padding: 24px; }
.toast { position: fixed; right: 16px; bottom: 16px; background: var(--text); color: var(--bg); padding: 9px 14px; border-radius: 9px; z-index: 30; }
@media (max-width: 720px) {
  header.top .wrap { gap: 10px; }
  .brand span { display: none; }
  nav a { padding: 7px 8px; }
  th, td { padding: 8px 9px; }
  .hide-sm { display: none; }
}
