:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #f1f3f6;
  --border: #e3e6eb;
  --text: #111827;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-contrast: #ffffff;
  --ok: #16a34a;
  --ok-bg: #dcfce7;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --bad: #dc2626;
  --bad-bg: #fee2e2;
  --info-bg: #e0e7ff;
  --sev-critical: #dc2626;
  --sev-high: #ea580c;
  --sev-medium: #ca8a04;
  --sev-low: #2563eb;
  --sev-info: #6b7280;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f17;
    --panel: #121826;
    --panel-2: #182032;
    --border: #243049;
    --text: #e5e7eb;
    --muted: #94a3b8;
    --accent: #3b82f6;
    --ok: #22c55e;
    --ok-bg: rgba(34, 197, 94, .15);
    --warn: #f59e0b;
    --warn-bg: rgba(245, 158, 11, .15);
    --bad: #f87171;
    --bad-bg: rgba(248, 113, 113, .15);
    --info-bg: rgba(99, 102, 241, .18);
    --sev-critical: #f87171;
    --sev-high: #fb923c;
    --sev-medium: #facc15;
    --sev-low: #60a5fa;
    --sev-info: #94a3b8;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
code, pre { font-family: var(--mono); font-size: 12.5px; }
pre { background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px; overflow: auto; white-space: pre-wrap; word-break: break-word; margin: 0; }
.boot { padding: 40px; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.stack > * + * { margin-top: 16px; }
.grow { flex: 1; }
.nowrap { white-space: nowrap; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* layout */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar { background: var(--panel); border-right: 1px solid var(--border); padding: 16px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; padding: 4px 8px 16px; }
.brand svg { width: 26px; height: 26px; }
.nav a { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px; border-radius: 8px; color: var(--text); }
.nav a:hover { background: var(--panel-2); text-decoration: none; }
.nav a.active { background: var(--info-bg); color: var(--accent); font-weight: 600; }
.sidebar .foot { margin-top: auto; font-size: 12px; color: var(--muted); padding: 8px; }
.main { padding: 24px 28px 60px; min-width: 0; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; background: var(--muted); flex: none; }
.dot.up, .dot.ok { background: var(--ok); }
.dot.down, .dot.fail, .dot.error { background: var(--bad); }
.dot.warn { background: var(--warn); }
.dot.pulse { animation: pulse 2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(34, 197, 94, .5); } 70% { box-shadow: 0 0 0 7px rgba(34, 197, 94, 0); } 100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); } }

/* panels */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 26px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat.bad .value { color: var(--bad); }
.stat.warn .value { color: var(--warn); }
.stat.ok .value { color: var(--ok); }
.banner { border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px; border: 1px solid; }
.banner.bad { background: var(--bad-bg); border-color: var(--bad); color: var(--text); }
.banner.warn { background: var(--warn-bg); border-color: var(--warn); }

/* fleet grid */
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin: 16px 0; align-items: center; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.tile { display: block; background: var(--panel); border: 1px solid var(--border); border-left: 4px solid var(--border); border-radius: var(--radius); padding: 12px 14px; color: var(--text); box-shadow: var(--shadow); transition: transform .08s; }
.tile:hover { text-decoration: none; transform: translateY(-1px); border-color: var(--accent); }
.tile.up { border-left-color: var(--ok); }
.tile.down { border-left-color: var(--bad); background: var(--bad-bg); }
.tile.unknown { border-left-color: var(--muted); }
.tile.paused { opacity: .55; }
.tile .name { font-weight: 600; }
.tile .host { color: var(--muted); font-size: 12px; }
.tile .meta { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; font-size: 12px; color: var(--muted); }
.grade { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: 7px; font-weight: 800; font-size: 14px; color: #fff; flex: none; }
.grade.big { width: 52px; height: 52px; font-size: 26px; border-radius: 12px; }
.grade.A { background: #16a34a; } .grade.B { background: #65a30d; } .grade.C { background: #ca8a04; }
.grade.D { background: #ea580c; } .grade.F { background: #dc2626; } .grade.\- { background: #9ca3af; }

/* badges */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: var(--panel-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.sev { color: #fff; border: none; text-transform: uppercase; letter-spacing: .03em; font-size: 10.5px; }
.sev.critical { background: var(--sev-critical); } .sev.high { background: var(--sev-high); }
.sev.medium { background: var(--sev-medium); color: #1f2937; } .sev.low { background: var(--sev-low); } .sev.info { background: var(--sev-info); }
.st-ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.st-warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.st-fail, .st-error, .st-down { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.st-up { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; }

/* tables */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: var(--panel-2); }
tr:last-child td { border-bottom: none; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--panel-2); }
.table-wrap { overflow-x: auto; }

/* forms */
input, select, textarea, button { font: inherit; color: inherit; }
input[type=text], input[type=email], input[type=password], input[type=url], input[type=number], input[type=search], select, textarea {
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; min-width: 0; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { font-family: var(--mono); font-size: 12.5px; min-height: 140px; }
label.field { display: block; }
label.field > span { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.filters input, .filters select { width: auto; }
.filters input[type=search] { min-width: 220px; flex: 1; max-width: 360px; }
button, .btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--border); background: var(--panel); border-radius: 8px; padding: 7px 12px; cursor: pointer; font-weight: 500; white-space: nowrap; color: var(--text); }
button:hover, .btn:hover { background: var(--panel-2); text-decoration: none; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--bad); }
button.sm { padding: 3px 8px; font-size: 12px; }
button:disabled { opacity: .55; cursor: default; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: 20px 0 16px; overflow-x: auto; }
.tabs button { border: none; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 8px 12px; color: var(--muted); }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.error-text { color: var(--bad); font-size: 13px; }

/* findings */
.finding { border-bottom: 1px solid var(--border); padding: 14px 16px; }
.finding:last-child { border-bottom: none; }
.finding .title { font-weight: 600; }
.finding .detail { white-space: pre-wrap; margin-top: 4px; font-size: 13px; }
.finding .fix { margin-top: 6px; font-size: 13px; background: var(--panel-2); border-radius: 8px; padding: 8px 10px; }
.finding.resolved, .finding.ignored { opacity: .6; }

/* activity */
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: flex; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); align-items: baseline; }
.feed li:last-child { border-bottom: none; }
.feed .when { color: var(--muted); font-size: 12px; white-space: nowrap; min-width: 70px; }

/* charts */
.bars { display: flex; gap: 1px; height: 34px; align-items: stretch; }
.bars span { flex: 1; border-radius: 1px; background: var(--ok); min-width: 1px; }
.bars span.bad { background: var(--bad); }
svg.chart { width: 100%; height: 140px; display: block; }
svg.chart .line { fill: none; stroke: var(--accent); stroke-width: 1.5; }
svg.chart .area { fill: var(--accent); opacity: .12; }
svg.chart .axis { stroke: var(--border); }
svg.chart text { fill: var(--muted); font-size: 10px; }
svg.chart rect.bar { fill: var(--accent); }

/* login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login { width: 100%; max-width: 380px; }

/* toasts */
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; max-width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--panel); border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: 8px; padding: 10px 14px; box-shadow: 0 8px 24px rgba(0, 0, 0, .18); font-size: 13px; }
.toast.critical, .toast.error { border-left-color: var(--bad); }
.toast.high { border-left-color: var(--sev-high); }
.toast.success { border-left-color: var(--ok); }

details summary { cursor: pointer; color: var(--accent); font-size: 12px; }
.empty { padding: 32px; text-align: center; color: var(--muted); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 8px 12px; border-right: none; border-bottom: 1px solid var(--border); }
  .brand { padding: 4px 8px; }
  .nav { display: flex; flex-wrap: wrap; gap: 2px; }
  .sidebar .foot { display: none; }
  .main { padding: 16px; }
  .two-col { grid-template-columns: 1fr; }
}

/* screenshots & QR */
img.shot { width: 100%; height: auto; border: 1px solid var(--border); border-radius: 8px; display: block; background: #fff; }
img.qr { background: #fff; border-radius: 8px; padding: 6px; flex: none; }
.two-col h3 { margin-bottom: 6px; }
