/* Grumpy HomeLab: tokens first, dark by default with a light scheme. */
:root {
  color-scheme: dark;
  --bg: #121312;
  --surface: #1a1a19;
  --surface-2: #222321;
  --surface-3: #2c2c2a;
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #f0efec;
  --text-2: #c3c2b7;
  --text-3: #8f8e86;
  --accent: #3987e5;          /* series 1: load meters & sparklines */
  --accent-ink: #ffffff;
  --brand: #3ddc84;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --unknown: #6f6e67;
  --track: #2c2c2a;
  --edge: #3a3b38;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --radius: 12px;
  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, monospace;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #f3f2ee;
    --surface: #fcfcfb;
    --surface-2: #f5f4f0;
    --surface-3: #e9e8e2;
    --border: rgba(11, 11, 11, 0.10);
    --border-strong: rgba(11, 11, 11, 0.18);
    --text: #0b0b0b;
    --text-2: #52514e;
    --text-3: #75746e;
    --accent: #2a78d6;
    --brand: #0d8a4a;
    --unknown: #a3a29b;
    --track: #e1e0d9;
    --edge: #c3c2b7;
    --shadow: 0 10px 30px rgba(20, 20, 10, 0.12);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }
code { font-family: var(--mono); font-size: 0.9em; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 0 16px;
  border-radius: 10px; border: 1px solid var(--border-strong);
  background: var(--surface-2); cursor: pointer; font-weight: 600;
  text-decoration: none; color: var(--text);
}
.btn:hover { background: var(--surface-3); }
.btn:focus-visible, .icon-btn:focus-visible, .node:focus-visible, .card:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.btn-primary { background: var(--accent); border-color: transparent; color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.1); }
.btn-small { min-height: 32px; padding: 0 12px; font-size: 13px; }
.btn-block { width: 100%; min-height: 48px; font-size: 16px; }
.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px;
  border-radius: 10px; border: 0; background: transparent; cursor: pointer; color: var(--text-2);
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }

/* ---------- gate (login) ---------- */
.gate { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.gate-card {
  width: min(380px, 100%); text-align: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
  padding: 36px 28px; box-shadow: var(--shadow);
  display: grid; gap: 14px; justify-items: center;
}
.gate-card h1 { margin: 0; font-size: 22px; letter-spacing: -0.01em; }
.gate-message { margin: 0 0 6px; color: var(--text-2); }
.gate-logo { border-radius: 14px; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -0.01em; }
.brand img { border-radius: 7px; }
.topbar-status { display: flex; gap: 8px; flex: 1; flex-wrap: wrap; }
.topbar-user { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.avatar { border-radius: 50%; border: 1px solid var(--border-strong); }
.pill {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 4px 10px; border-radius: 999px; font-size: 13px;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2);
}
.pill strong { color: var(--text); font-variant-numeric: tabular-nums; }
.live .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--unknown); }
.live.ok .dot { background: var(--good); box-shadow: 0 0 0 0 var(--good); animation: pulse 2.4s infinite; }
.live.stale .dot { background: var(--warning); }
.live.down .dot { background: var(--critical); }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--good) 60%, transparent); }
  70% { box-shadow: 0 0 0 7px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}
@media (prefers-reduced-motion: reduce) { .live.ok .dot { animation: none; } }

.banner {
  margin: 12px 16px 0; padding: 10px 14px; border-radius: 10px;
  background: color-mix(in srgb, var(--warning) 14%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--warning) 45%, transparent);
  font-size: 14px;
}

/* ---------- layout ---------- */
.layout {
  display: grid; gap: 16px; padding: 16px;
  max-width: 1400px; margin: 0 auto;
}
.app.has-detail .layout { margin-right: 400px; max-width: none; }
.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  min-width: 0;
}
.panel-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  padding: 14px 16px 0;
}
.panel-head h2 { margin: 0; font-size: 15px; font-weight: 650; }

/* ---------- network map ---------- */
.map-scroll { overflow: auto; padding: 8px 16px 18px; -webkit-overflow-scrolling: touch; }
.map { position: relative; margin: 0 auto; transform-origin: top left; }
.map svg.edges { position: absolute; inset: 0; overflow: visible; pointer-events: none; }
.edge { fill: none; stroke: var(--edge); stroke-width: 2; }
.edge.online { stroke: color-mix(in srgb, var(--good) 55%, var(--edge)); }
.edge.offline { stroke-dasharray: 4 5; }

.node {
  position: absolute; width: 168px; height: 84px;
  display: flex; gap: 10px; align-items: flex-start; text-align: left;
  padding: 10px 12px; border-radius: 12px; cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--border-strong);
  transition: border-color .15s, transform .15s, background .15s;
}
.node:hover { border-color: var(--accent); transform: translateY(-1px); }
.node.selected { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--surface-2)); }
.node.offline { opacity: 0.62; }
.node .icon { flex: none; width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; background: var(--surface-3); color: var(--text-2); }
.node .body { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.3; }
.node .name { font-weight: 650; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 14px; }
.node .sub { font-size: 12px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.node .status-dot { position: absolute; top: 10px; right: 10px; }
.node .mini { display: grid; grid-template-columns: auto 1fr; gap: 3px 6px; align-items: center; margin-top: 6px; font-size: 10px; line-height: 1; color: var(--text-3); }
.node .mini .meter { height: 4px; }

.status-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--unknown); flex: none; }
.status-dot.online { background: var(--good); }
.status-dot.offline { background: var(--critical); }

/* ---------- meters ---------- */
.meter { position: relative; height: 8px; border-radius: 999px; background: var(--track); overflow: hidden; }
.meter > span { position: absolute; inset: 0 auto 0 0; border-radius: 999px; background: var(--accent); transition: width .5s ease; }
.meter.warn > span { background: var(--warning); }
.meter.crit > span { background: var(--critical); }

/* ---------- computer cards ---------- */
.cards { display: grid; gap: 12px; padding: 12px 16px 16px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.card {
  text-align: left; cursor: pointer; display: grid; gap: 10px;
  padding: 14px; border-radius: 12px;
  background: var(--surface-2); border: 1px solid var(--border);
}
.card:hover { border-color: var(--accent); }
.card.offline { opacity: 0.65; }
.card-head { display: flex; align-items: center; gap: 10px; }
.card-head .icon { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; background: var(--surface-3); color: var(--text-2); flex: none; }
.card-title { min-width: 0; flex: 1; }
.card-title .name { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-title .sub { font-size: 12px; color: var(--text-3); }
.stat-row { display: grid; grid-template-columns: 42px 1fr 52px; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); }
.stat-row .val { text-align: right; color: var(--text); font-family: var(--mono); font-variant-numeric: tabular-nums; font-size: 12.5px; }
.card .connect { margin-top: 2px; }
.empty { padding: 20px 16px; color: var(--text-2); }

.status-label { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--text-2); }

/* ---------- detail panel ---------- */
.detail {
  position: fixed; z-index: 30; top: 0; right: 0; bottom: 0; width: 400px;
  background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow);
  overflow-y: auto; padding-top: env(safe-area-inset-top);
}
.detail-inner { padding: 18px 18px 32px; display: grid; gap: 18px; }
.detail-head { display: flex; gap: 12px; align-items: flex-start; }
.detail-head .icon { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--surface-3); color: var(--text-2); flex: none; }
.detail-head h2 { margin: 0; font-size: 19px; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.detail-head .close { margin-left: auto; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; font-size: 13.5px; }
.facts dt { color: var(--text-3); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-3); margin: 0 0 8px; font-weight: 650; }
.gauges { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.gauge { padding: 12px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); display: grid; gap: 6px; }
.gauge .label { font-size: 12px; color: var(--text-2); }
.gauge .big { font-size: 22px; font-weight: 650; font-family: var(--mono); font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.gauge .big small { font-size: 13px; color: var(--text-2); font-weight: 500; }
.gauge .meta { font-size: 11.5px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spark-wrap { padding: 12px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); }
.spark-wrap + .spark-wrap { margin-top: 10px; }
.spark-head { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-2); margin-bottom: 6px; }
.spark { position: relative; height: 56px; }
.spark svg { width: 100%; height: 100%; display: block; overflow: visible; }
.spark .grid { stroke: var(--track); stroke-width: 1; }
.spark .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.spark .area { fill: color-mix(in srgb, var(--accent) 14%, transparent); stroke: none; }
.spark .cursor { stroke: var(--text-3); stroke-width: 1; }
.spark .marker { fill: var(--accent); stroke: var(--surface-2); stroke-width: 2; }
.spark .tip {
  position: absolute; top: -6px; transform: translate(-50%, -100%);
  background: var(--surface-3); border: 1px solid var(--border-strong); color: var(--text);
  padding: 3px 7px; border-radius: 6px; font-size: 11.5px; white-space: nowrap; pointer-events: none;
  font-family: var(--mono);
}
.disk { display: grid; gap: 5px; font-size: 13px; }
.disk + .disk { margin-top: 10px; }
.disk-head { display: flex; justify-content: space-between; gap: 8px; }
.disk-head .val { color: var(--text-2); font-family: var(--mono); font-size: 12px; }
.rdp-box { display: grid; gap: 8px; }
.rdp-alt { display: flex; gap: 14px; flex-wrap: wrap; font-size: 13px; }
.rdp-alt a, .linkish { color: var(--accent); background: none; border: 0; padding: 0; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; font-size: 13px; }
.hint { font-size: 12.5px; color: var(--text-2); background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.hint code { background: var(--surface-3); padding: 1px 5px; border-radius: 5px; overflow-wrap: anywhere; }
.scrim { position: fixed; inset: 0; z-index: 25; background: rgba(0, 0, 0, 0.45); }

/* ---------- dialog ---------- */
.dialog {
  border: 1px solid var(--border-strong); border-radius: 16px; padding: 0;
  background: var(--surface); color: var(--text); width: min(460px, calc(100% - 32px));
  box-shadow: var(--shadow);
}
.dialog::backdrop { background: rgba(0, 0, 0, 0.5); }
.dialog form { padding: 20px; display: grid; gap: 14px; }
.dialog h2 { margin: 0; font-size: 18px; }
.dialog fieldset { border: 0; padding: 0; margin: 0; display: grid; gap: 10px; }
.dialog legend { font-weight: 650; margin-bottom: 8px; font-size: 14px; }
.radio { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: start; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; cursor: pointer; }
.radio:has(input:checked) { border-color: var(--accent); }
.radio input { margin-top: 4px; accent-color: var(--accent); }
.dialog-actions { display: flex; justify-content: flex-end; }

/* ---------- small screens ---------- */
@media (max-width: 900px) {
  .app.has-detail .layout { margin-right: 0; }
  .detail {
    top: auto; left: 0; width: 100%; max-height: 86dvh;
    border-left: 0; border-top: 1px solid var(--border-strong);
    border-radius: 18px 18px 0 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .detail-inner::before {
    content: ""; justify-self: center; width: 40px; height: 4px; border-radius: 2px; background: var(--surface-3); margin-top: -6px;
  }
}
@media (max-width: 560px) {
  .topbar { gap: 8px; }
  .brand span { display: none; }
  .topbar-status { order: 3; flex-basis: 100%; }
  .layout { padding: 12px; gap: 12px; }
  .cards { grid-template-columns: 1fr; padding: 12px; }
  .map-scroll { padding: 6px 12px 14px; }
  #map-hint { display: none; }
}

@media (forced-colors: active) {
  .meter > span, .status-dot { forced-color-adjust: none; }
}
