/* Porthole — light/dark, compact, no external assets */
:root {
  color-scheme: light;
  --bg: #f5f5f3;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e3e2de;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #7a7974;
  --accent: #2a78d6;
  --accent-soft: rgba(42, 120, 214, .12);
  --track: #dce8f7;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 1px 1px rgba(0,0,0,.03);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --border: #2e2e2c;
    --text: #f0efec; --text-2: #c3c2b7; --text-3: #8f8e86;
    --accent: #3987e5; --accent-soft: rgba(57, 135, 229, .16); --track: #1f3450;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #232321; --border: #2e2e2c;
  --text: #f0efec; --text-2: #c3c2b7; --text-3: #8f8e86;
  --accent: #3987e5; --accent-soft: rgba(57, 135, 229, .16); --track: #1f3450;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1 { font-size: 18px; font-weight: 600; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 12px; font-weight: 600; margin: 0 0 12px; color: var(--text-2); text-transform: uppercase; letter-spacing: .06em; }
.mt { margin-top: 20px; }
.muted { color: var(--text-2); }
.small { font-size: 12px; }
.right { text-align: right; }
.error { color: var(--critical); margin: 0; }
code { font-family: var(--mono); font-size: 12px; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
a { color: var(--accent); }

/* Brand */
.brand { display: flex; align-items: center; gap: 9px; font-weight: 600; letter-spacing: -.01em; white-space: nowrap; }
.brand-lg { font-size: 20px; }
.mark { width: 16px; height: 16px; border-radius: 50%; border: 3px solid var(--accent); position: relative; flex: none; }
.mark::after { content: ""; position: absolute; inset: 2px; border-radius: 50%; background: var(--accent); }

/* Buttons & inputs */
.btn {
  font: inherit; font-size: 13px; cursor: pointer; border-radius: 8px;
  padding: 6px 12px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 500; }
.btn-primary:hover { background: var(--accent); filter: brightness(1.07); }
.btn-sm { padding: 3px 9px; font-size: 12px; }
.btn-danger:hover { border-color: var(--critical); color: var(--critical); }
.icon-btn {
  display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px;
  border: 0; background: transparent; color: var(--text-2); cursor: pointer; font: inherit;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; width: 100%;
}
input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 340px; display: grid; gap: 14px; padding: 28px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow);
}
.login-card p { margin: -6px 0 4px; }
.field { display: grid; gap: 6px; font-size: 12px; color: var(--text-2); font-weight: 500; }
.login-card .btn { padding: 9px; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 20px; padding: 0 20px; height: 54px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; flex: 1; }
.tabs a {
  color: var(--text-2); text-decoration: none; padding: 6px 11px; border-radius: 7px; font-size: 13px; white-space: nowrap;
}
.tabs a:hover { color: var(--text); background: var(--surface-2); }
.tabs a[aria-current="page"] { color: var(--text); background: var(--surface-2); font-weight: 500; }
.top-actions { display: flex; align-items: center; gap: 4px; }
.live { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-2); margin-right: 6px; }
.live i { width: 7px; height: 7px; border-radius: 50%; background: var(--good); box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 22%, transparent); }
.live.off i { background: var(--text-3); box-shadow: none; }

/* Layout */
.content { max-width: 1080px; margin: 0 auto; padding: 24px 20px 8px; }
.tab { display: grid; gap: 16px; animation: fade .18s ease-out; }
@keyframes fade { from { opacity: 0; transform: translateY(3px); } }
.host-line { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.toolbar h1 { margin-right: auto; }
.search { width: 200px; padding: 6px 10px; }
.foot { text-align: center; padding: 20px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card.flush { padding: 0; overflow: hidden; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* Tiles */
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px 12px; box-shadow: var(--shadow); display: grid; gap: 8px; min-width: 0;
}
.tile header { display: flex; justify-content: space-between; align-items: baseline; color: var(--text-2); font-size: 12px; font-weight: 500; }
.tile b { font-size: 22px; font-weight: 600; color: var(--text); letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.tile footer { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spark { height: 44px; position: relative; cursor: crosshair; }
.spark svg { display: block; width: 100%; height: 100%; overflow: visible; }
.spark .area { fill: var(--accent-soft); }
.spark .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.spark .x { stroke: var(--text-3); stroke-width: 1; vector-effect: non-scaling-stroke; }
.spark .dot { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }

/* Key/value */
.kv { display: grid; grid-template-columns: auto 1fr; gap: 9px 18px; margin: 0; }
.kv dt { color: var(--text-2); }
.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

/* Meters */
.meters { display: grid; gap: 14px; }
.meter-head { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 6px; font-size: 13px; }
.meter-head span:last-child { color: var(--text-2); font-variant-numeric: tabular-nums; }
.meter { height: 8px; border-radius: 99px; background: var(--track); overflow: hidden; }
.meter i { display: block; height: 100%; border-radius: 99px; background: var(--accent); transition: width .4s; }
.meter.warn i { background: var(--warning); }
.meter.crit i { background: var(--critical); }

.glance { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.glance li { display: flex; align-items: center; gap: 8px; }
.glance a { margin-left: auto; font-size: 12px; text-decoration: none; }

/* Status pill: icon + label, never color alone */
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500; white-space: nowrap; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); flex: none; }
.status.good::before { background: var(--good); }
.status.warning::before { background: var(--warning); }
.status.serious::before { background: var(--serious); }
.status.critical::before { background: var(--critical); border-radius: 2px; transform: rotate(45deg); width: 7px; height: 7px; }

/* Tables */
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left; font-weight: 500; font-size: 12px; color: var(--text-2);
  padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--surface-2);
}
.table td { padding: 9px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th.right, .table td.right { text-align: right; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
.table td.num { font-variant-numeric: tabular-nums; }
.table .mono { font-family: var(--mono); font-size: 12px; }
.table .desc { color: var(--text-2); max-width: 320px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.actions { display: inline-flex; gap: 6px; justify-content: flex-end; }
.pin { color: var(--accent); font-size: 10px; margin-left: 6px; vertical-align: 1px; }
.empty { text-align: center; color: var(--text-2); padding: 28px !important; }

/* Sites */
.site-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.site { display: grid; gap: 12px; }
.site-url { font-weight: 600; overflow-wrap: anywhere; text-decoration: none; color: var(--text); }
.site-url:hover { color: var(--accent); }
.site-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.site-stats div { display: grid; gap: 2px; }
.site-stats span { font-size: 11px; color: var(--text-2); text-transform: uppercase; letter-spacing: .05em; }
.site-stats b { font-weight: 600; font-variant-numeric: tabular-nums; }

/* Dialog */
.dialog {
  width: min(900px, calc(100vw - 32px)); max-height: 80vh; padding: 0;
  border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text);
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.dialog::backdrop { background: rgba(0,0,0,.35); backdrop-filter: blur(2px); }
.dialog header { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 12px 18px; border-bottom: 1px solid var(--border); }
.dialog h2 { margin: 0; text-transform: none; letter-spacing: 0; font-size: 14px; color: var(--text); font-family: var(--mono); }
.log { margin: 0; padding: 14px 18px; overflow: auto; max-height: calc(80vh - 56px); font: 12px/1.55 var(--mono); white-space: pre-wrap; word-break: break-word; color: var(--text-2); }

/* Toast & tooltip */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 50;
  background: var(--text); color: var(--bg); padding: 9px 14px; border-radius: 9px; font-size: 13px;
  box-shadow: 0 8px 24px rgba(0,0,0,.2); max-width: calc(100vw - 32px);
}
.toast.bad { background: var(--critical); color: #fff; }
.tip {
  position: fixed; z-index: 40; pointer-events: none; transform: translate(-50%, calc(-100% - 10px));
  background: var(--text); color: var(--bg); padding: 5px 8px; border-radius: 6px; font-size: 12px; white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.tip span { opacity: .7; margin-left: 6px; }

/* Responsive */
@media (max-width: 900px) {
  .tiles { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 10px 14px 0; gap: 8px; }
  .topbar .brand { flex: 1; }
  .tabs { order: 3; flex-basis: 100%; padding-bottom: 8px; }
  .content { padding: 18px 14px 8px; }
  .tiles { gap: 10px; }
  .hide-sm { display: none; }
  .table th, .table td { padding: 9px 10px; }
  .search { width: 100%; order: 3; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
