:root {
  color-scheme: light;
  --bg: #f4f3ef;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --line: #e4e3de;
  --grid: #ebeae6;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #7a7974;
  --accent: #1c5cab;
  --accent-ink: #ffffff;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --good: #0ca30c;
  --good-ink: #006300;
  --warning: #fab219;
  --warning-ink: #8a5a00;
  --serious: #ec835a;
  --critical: #d03b3b;
  --critical-ink: #b42323;
  --good-bg: #e6f4e6;
  --warning-bg: #fdf3dc;
  --critical-bg: #fbe7e7;
  --info-bg: #e7eef9;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.04), 0 1px 1px rgb(0 0 0 / 0.03);
  --radius: 14px;
  --mono: ui-monospace, 'SF Mono', 'Cascadia Mono', 'Roboto Mono', Menlo, monospace;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --surface-2: #232321;
    --line: #2e2e2b;
    --grid: #2a2a27;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --text-3: #8f8e86;
    --accent: #3987e5;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --good-ink: #5fd35f;
    --warning-ink: #fab219;
    --critical-ink: #f08080;
    --good-bg: #142a14;
    --warning-bg: #2d2412;
    --critical-bg: #331a1a;
    --info-bg: #172438;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 150px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--sans);
  font-variant-numeric: tabular-nums;
}
[hidden] { display: none !important; }
a { color: var(--accent); }
code, .mono { font-family: var(--mono); font-size: 0.88em; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; overflow-wrap: anywhere; }
h1 { font-size: 22px; margin: 4px 0 2px; letter-spacing: -0.01em; }
h2 { font-size: 18px; margin: 0; letter-spacing: -0.01em; }
h3 { font-size: 14px; margin: 0 0 8px; color: var(--text-2); font-weight: 600; }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.small { font-size: 13px; }
.error { color: var(--critical-ink); min-height: 1.2em; margin: 8px 0 0; }

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
input[type=password], input[type=search], input[type=text] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}
input:focus-visible, button:focus-visible, a:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary {
  width: 100%;
  margin-top: 14px;
  padding: 11px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
button.primary:disabled { opacity: 0.6; }
.icon-btn {
  display: inline-grid;
  place-items: center;
  min-width: 36px;
  height: 36px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  font-size: 17px;
  line-height: 1;
  list-style: none;
}
.icon-btn::-webkit-details-marker { display: none; }
.linkish { border: 0; background: none; padding: 0; color: var(--accent); font: inherit; text-align: left; }

.boot { padding: 40px 16px; text-align: center; color: var(--text-2); }
.center { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  min-width: 0;
}
.login-card { width: min(380px, 100%); }
.login-card label { display: block; margin: 14px 0 6px; font-weight: 600; font-size: 14px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: -0.01em; min-width: 0; }
.brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* header */
.top {
  position: sticky;
  top: 0;
  z-index: 5;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  padding: 10px 16px 0;
}
.top-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; max-width: 1180px; margin: 0 auto; }
.top-row.controls { margin-top: 8px; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.updated { white-space: nowrap; }
.updated.stale { color: var(--critical-ink); font-weight: 600; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--surface); flex: none; }
.seg button { border: 0; background: none; padding: 7px 12px; font-size: 14px; color: var(--text-2); }
.seg button[aria-pressed=true] { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.ip-search { flex: 1; max-width: 260px; }
.ip-search input { padding: 7px 10px; }
.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; max-width: 1180px; margin: 8px auto 0; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { flex: none; padding: 8px 10px; color: var(--text-2); text-decoration: none; font-size: 14px; border-bottom: 2px solid transparent; }
.tabs a.on { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.menu { position: relative; }
.menu-pop {
  position: absolute; right: 0; top: 42px; z-index: 6; min-width: 200px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 6px; box-shadow: 0 8px 24px rgb(0 0 0 / 0.15);
}
.menu-pop button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 9px 10px; border-radius: 8px; }
.menu-pop button:hover { background: var(--surface-2); }

/* layout */
.content { max-width: 1180px; margin: 0 auto; padding: 16px 16px 40px; }
.section { margin-bottom: 30px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 0 0 10px; flex-wrap: wrap; }
.section-head p { margin: 0; }
.grid { display: grid; gap: 12px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); }
.tiles { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 160px), 1fr)); }
.stack > * + * { margin-top: 12px; }
.foot { max-width: 1180px; margin: 0 auto; padding: 0 16px 30px; }

/* hero + alerts */
.hero { display: flex; gap: 14px; align-items: center; }
.hero-badge { flex: none; width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; font-size: 22px; font-weight: 700; color: #fff; }
.hero-badge.good { background: var(--good); }
.hero-badge.warn { background: var(--warning); color: #3a2a00; }
.hero-badge.crit { background: var(--critical); }
.hero h1 { margin: 0; }
.alerts { list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 8px; }
.alert { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); }
.alert.crit { background: var(--critical-bg); }
.alert.warn { background: var(--warning-bg); }
.alert.info { background: var(--info-bg); }
.alert .lvl { font-size: 12px; font-weight: 700; padding: 2px 7px; border-radius: 6px; align-self: start; color: #fff; white-space: nowrap; }
.alert.crit .lvl { background: var(--critical); }
.alert.warn .lvl { background: var(--warning); color: #3a2a00; }
.alert.info .lvl { background: var(--accent); }
.alert .t { font-weight: 600; overflow-wrap: anywhere; }
.alert .d { grid-column: 2; font-size: 13px; color: var(--text-2); overflow-wrap: anywhere; }

/* stat tiles */
.tile { padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; text-decoration: none; color: inherit; }
a.tile:hover { border-color: var(--accent); }
.tile .label { font-size: 13px; color: var(--text-2); }
.tile .value { font-size: 26px; font-weight: 650; letter-spacing: -0.02em; line-height: 1.15; }
.tile .sub { font-size: 12.5px; color: var(--text-3); }
.tile .sub .up { color: var(--critical-ink); }
.tile .sub .down { color: var(--good-ink); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.dot.good { background: var(--good); }
.dot.warn { background: var(--warning); }
.dot.crit { background: var(--critical); }

/* tables */
.table-wrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { text-align: left; font-weight: 600; color: var(--text-2); font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 7px 8px; border-bottom: 1px solid var(--grid); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; white-space: nowrap; }
td.wrap { overflow-wrap: anywhere; min-width: 140px; }
td.nowrap { white-space: nowrap; }
.empty { color: var(--text-3); font-size: 13.5px; padding: 6px 0; }
.ip { font-family: var(--mono); font-size: 13px; border: 0; background: none; padding: 0; color: var(--accent); text-align: left; cursor: pointer; overflow-wrap: anywhere; }
.ip:hover { text-decoration: underline; }
.bar-cell { position: relative; min-width: 70px; }
.bar-cell .bar { position: absolute; left: 8px; top: 50%; height: 6px; margin-top: -3px; border-radius: 3px; background: var(--series-1); opacity: 0.25; }
.bar-cell span { position: relative; }

/* badges */
.badge { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); white-space: nowrap; margin: 1px 2px 1px 0; }
.badge.good { background: var(--good-bg); color: var(--good-ink); }
.badge.warn { background: var(--warning-bg); color: var(--warning-ink); }
.badge.crit { background: var(--critical-bg); color: var(--critical-ink); }
.badge.info { background: var(--info-bg); color: var(--accent); }

/* meters */
.meter { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; margin: 6px 0 2px; }
.meter > div { height: 100%; border-radius: 4px; background: var(--series-1); }
.meter > div.warn { background: var(--warning); }
.meter > div.crit { background: var(--critical); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; font-size: 14px; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

/* checks */
.checks { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.checks li { display: grid; grid-template-columns: 22px 1fr; gap: 8px; align-items: start; font-size: 14px; }
.checks .mark { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; color: #fff; font-weight: 700; }
.checks .ok { background: var(--good); }
.checks .bad { background: var(--critical); }

/* charts */
.chart { position: relative; }
.chart svg { display: block; width: 100%; overflow: visible; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12.5px; color: var(--text-2); margin-bottom: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.legend .total { margin-left: auto; color: var(--text-3); }
.swatch-1 { background: var(--series-1); }
.swatch-2 { background: var(--series-2); }
.swatch-3 { background: var(--series-3); }
.chart .axis { fill: var(--text-3); font-size: 11px; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--line); stroke-width: 1; }
.chart .s1 { fill: var(--series-1); }
.chart .s2 { fill: var(--series-2); }
.chart .s3 { fill: var(--series-3); }
.chart .hit { fill: transparent; }
.chart .hit:hover, .chart .hit.on { fill: var(--text); fill-opacity: 0.05; }
.spark { display: block; width: 90px; height: 22px; }
.spark path { fill: none; stroke: var(--series-1); stroke-width: 1.5; stroke-linejoin: round; stroke-linecap: round; }
.tooltip {
  position: fixed; z-index: 20; pointer-events: none; max-width: 260px;
  background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 10px; font-size: 12.5px; box-shadow: 0 8px 24px rgb(0 0 0 / 0.18);
}
.tooltip b { display: block; margin-bottom: 4px; }
.tooltip .row { display: flex; justify-content: space-between; gap: 14px; }
.tooltip .row i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }

details.more { margin-top: 10px; }
details.more > summary { cursor: pointer; color: var(--accent); font-size: 14px; }
.note { font-size: 13.5px; color: var(--text-2); background: var(--surface-2); border-radius: 10px; padding: 10px 12px; margin: 0; }
.note pre { white-space: pre-wrap; overflow-wrap: anywhere; margin: 8px 0 0; font-family: var(--mono); font-size: 12px; }

/* IP dialog */
dialog {
  width: min(560px, calc(100% - 24px));
  max-height: calc(100dvh - 40px);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0;
  background: var(--surface);
  color: var(--text);
}
dialog::backdrop { background: rgb(0 0 0 / 0.45); }
.dialog-head { position: sticky; top: 0; display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
.dialog-head h2 { font-family: var(--mono); font-size: 16px; overflow-wrap: anywhere; }
#ip-body { padding: 14px 16px 18px; }
#ip-body section + section { margin-top: 16px; }
.links { display: flex; gap: 12px; flex-wrap: wrap; font-size: 14px; margin-top: 4px; }

@media (max-width: 560px) {
  body { font-size: 14.5px; }
  .tile .value { font-size: 22px; }
  .updated { display: none; }
  .top-row.controls { gap: 8px; }
}

.icon-btn.spin { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
