:root {
  --bg: #f4f5f7; --canvas: #f7f8fa; --dots: #e3e6eb; --panel: #ffffff; --card: #ffffff;
  --border: #e3e5e9; --border-strong: #cfd3da; --text: #212327; --muted: #7e8590; --faint: #a7adb6;
  --accent: #006fff; --accent-soft: #e6f0ff;
  --up: #17b26a; --down: #f04438; --warn: #f79009; --unknown: #b4b9c1;
  --c25: #f08c00; --c10: #2b7fff; --c2_5: #8b5cf6; --c1: #1fb26b; --cguest: #c5cad2; --cwifi: #9aa1ab;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --shadow-hover: 0 4px 12px rgba(16,24,40,.12);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121418; --canvas: #16191e; --dots: #23272e; --panel: #1b1e24; --card: #1f232a;
    --border: #2c3139; --border-strong: #3a414b; --text: #e7e9ec; --muted: #8d95a1; --faint: #5f6772;
    --accent: #4c9bff; --accent-soft: #1b2b44; --cguest: #3a414b;
    --shadow: 0 1px 2px rgba(0,0,0,.4); --shadow-hover: 0 4px 14px rgba(0,0,0,.5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121418; --canvas: #16191e; --dots: #23272e; --panel: #1b1e24; --card: #1f232a;
  --border: #2c3139; --border-strong: #3a414b; --text: #e7e9ec; --muted: #8d95a1; --faint: #5f6772;
  --accent: #4c9bff; --accent-soft: #1b2b44; --cguest: #3a414b;
  --shadow: 0 1px 2px rgba(0,0,0,.4); --shadow-hover: 0 4px 14px rgba(0,0,0,.5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 13px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; overflow: hidden;
}
button, input { font: inherit; color: inherit; }
.muted { color: var(--muted); }

#app { display: flex; height: 100vh; height: 100dvh; }

/* ------------------------------------------------ sidebar */
#side {
  width: 290px; flex: none; background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0; z-index: 5;
}
#app.side-hidden #side { display: none; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 8px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: 15px; }
.logo { color: var(--accent); font-size: 18px; }
.side-tabs { padding: 4px 14px 10px; }
#search {
  width: 100%; height: 32px; border: 1px solid var(--border); border-radius: 8px; padding: 0 10px;
  background: var(--canvas); outline: none;
}
#search:focus { border-color: var(--accent); }
#side-body { flex: 1; overflow: auto; padding: 0 8px 12px; }
.grp { margin-top: 10px; }
.grp-title {
  font-size: 11px; font-weight: 650; letter-spacing: .04em; text-transform: uppercase;
  color: var(--muted); padding: 6px 8px;
  display: flex; justify-content: space-between;
}
.row {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 7px;
  cursor: pointer; text-decoration: none; color: inherit; min-width: 0;
}
.row:hover { background: var(--accent-soft); }
.row .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .meta { color: var(--muted); font-size: 11.5px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row img, .row .glyph { width: 18px; height: 18px; flex: none; object-fit: contain; }
.legend { border-top: 1px solid var(--border); padding: 10px 14px 14px; }
.legend-title { font-size: 11px; color: var(--muted); margin-bottom: 6px; }
.legend-row { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: 11.5px; color: var(--muted); }
.legend-row i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }
.legend-row i.dash { background: repeating-linear-gradient(90deg, var(--faint) 0 3px, transparent 3px 6px); }

/* ------------------------------------------------ stage */
#stage { flex: 1; position: relative; min-width: 0; display: flex; flex-direction: column; }
#topbar {
  height: 48px; flex: none; display: flex; align-items: center; gap: 10px; padding: 0 14px;
  background: var(--panel); border-bottom: 1px solid var(--border); overflow-x: auto; white-space: nowrap;
}
#topbar .spacer { flex: 1; }
#side-open { display: none; }
#app.side-hidden #side-open { display: inline-flex; }
#stats { display: flex; gap: 16px; font-size: 12.5px; }
.stat b { font-variant-numeric: tabular-nums; font-weight: 650; }
.stat .muted { margin-left: 4px; }
.toggle { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); cursor: pointer; font-size: 12.5px; }
.toggle input { accent-color: var(--accent); margin: 0; }
.btn {
  height: 28px; padding: 0 10px; border-radius: 7px; border: 1px solid var(--border);
  background: var(--card); cursor: pointer; font-size: 12.5px;
}
.btn:hover, .icon-btn:hover { border-color: var(--border-strong); }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 7px; border: 1px solid var(--border);
  background: var(--card); cursor: pointer; font-size: 15px; line-height: 1; padding: 0; flex: none;
}
#updated { font-size: 11.5px; font-variant-numeric: tabular-nums; }

#viewport {
  flex: 1; position: relative; overflow: hidden; cursor: grab; touch-action: none;
  background-color: var(--canvas);
  background-image: radial-gradient(var(--dots) 1px, transparent 1px);
  background-size: 22px 22px;
}
#viewport.panning { cursor: grabbing; }
#world { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
#wires { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none; }
#cards { position: absolute; left: 0; top: 0; }

#zoomctl {
  position: absolute; left: 14px; bottom: 14px; display: flex; flex-direction: column; gap: 6px; z-index: 3;
}
#zoomctl .icon-btn { box-shadow: var(--shadow); }
#error {
  position: absolute; right: 14px; bottom: 14px; z-index: 4; max-width: 420px;
  background: var(--card); border: 1px solid var(--down); color: var(--text);
  padding: 8px 12px; border-radius: 8px; box-shadow: var(--shadow); font-size: 12.5px;
}

/* ------------------------------------------------ cards */
.card {
  position: absolute; background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow); display: flex; gap: 10px; padding: 10px 12px; cursor: pointer;
  transition: box-shadow .15s, border-color .15s; outline: none;
}
.card.nolink { cursor: default; }
.card:hover, .card:focus-visible { box-shadow: var(--shadow-hover); border-color: var(--border-strong); }
.card:focus-visible { border-color: var(--accent); }
.card.flash { animation: flash 1.6s ease-out 1; }
@keyframes flash { 0%,40% { box-shadow: 0 0 0 4px var(--accent); } 100% { box-shadow: var(--shadow); } }
.card .ic { width: 30px; height: 30px; flex: none; display: flex; align-items: center; justify-content: center; position: relative; }
.card .ic img { width: 28px; height: 28px; object-fit: contain; }
.card .ic svg { width: 26px; height: 26px; color: var(--muted); }
.card .st {
  position: absolute; right: -3px; bottom: -3px; width: 10px; height: 10px; border-radius: 50%;
  border: 2px solid var(--card); background: var(--unknown);
}
.st.up, .tdot.up { background: var(--up); }
.st.down, .tdot.down { background: var(--down); }
.card .body { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; }
.card .nm { font-weight: 650; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .sub { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.card .right {
  display: flex; flex-direction: column; align-items: flex-end; justify-content: center; gap: 2px;
  font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap;
}
.card .right .ok { color: var(--up); font-weight: 600; }
.card .right .bad { color: var(--down); font-weight: 600; }
.card.down { border-color: color-mix(in srgb, var(--down) 45%, var(--border)); }

.card.pve, .card.hasapps { flex-direction: column; gap: 6px; }
.card.hasapps .top { display: flex; gap: 10px; }
.card.pve .top { display: flex; gap: 10px; }
.card.pve .foot {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  border-top: 1px solid var(--border); padding-top: 6px; font-size: 12px; color: var(--muted);
}
.bars { display: flex; gap: 8px; }
.bar { display: flex; align-items: center; gap: 5px; white-space: nowrap; }
.bar .track { width: 36px; height: 5px; border-radius: 3px; background: var(--border); overflow: hidden; }
.bar .fill { height: 100%; border-radius: 3px; background: var(--accent); }
.bar .fill.hot { background: var(--warn); }
.bar .fill.crit { background: var(--down); }
.chev {
  border: 1px solid var(--border); background: var(--canvas); border-radius: 6px; height: 22px;
  padding: 0 8px; font-size: 11.5px; cursor: pointer; color: var(--muted); white-space: nowrap; flex: none;
}
.chev:hover { color: var(--text); border-color: var(--border-strong); }

.card.guest { padding: 7px 10px; gap: 8px; border-radius: 8px; flex-direction: column; }
.card.guest .top { display: flex; align-items: center; gap: 8px; min-width: 0; }
.card.guest .nm { font-size: 12.5px; flex: 1; min-width: 0; }
.card.guest.stopped { opacity: .55; }
.card.guest.stopped:hover { opacity: .9; }
.tdot { width: 8px; height: 8px; border-radius: 50%; background: var(--unknown); flex: none; }
.tag {
  font-size: 10.5px; font-weight: 650; padding: 1px 5px; border-radius: 4px; flex: none;
  background: var(--canvas); border: 1px solid var(--border); color: var(--muted); font-variant-numeric: tabular-nums;
}
.tag.vm { color: var(--c2_5); }
.tag.ct { color: var(--c10); }
.card.guest .sub { font-size: 11.5px; display: flex; justify-content: space-between; gap: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; height: 20px; padding: 0 7px 0 4px; border-radius: 10px;
  background: var(--accent-soft); color: var(--text); text-decoration: none; font-size: 11.5px; max-width: 100%;
  border: 1px solid transparent; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chip:hover { border-color: var(--accent); }
.chip img { width: 14px; height: 14px; object-fit: contain; }
.chip .glyph { width: 14px; height: 14px; border-radius: 4px; background: var(--accent); color: #fff; font-size: 9px; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; }

/* port badges */
.port {
  position: absolute; height: 20px; min-width: 26px; padding: 0 6px; border-radius: 5px; color: #fff;
  font-size: 11px; font-weight: 650; display: flex; align-items: center; justify-content: center; gap: 3px;
  transform: translate(-50%, 0); font-variant-numeric: tabular-nums; pointer-events: auto; cursor: default;
}
.port.unverified { background: var(--card) !important; color: var(--muted); border: 1px dashed var(--faint); }
.linklabel {
  position: absolute; transform: translate(-50%, -50%); font-size: 10.5px; color: var(--muted);
  background: var(--canvas); padding: 1px 5px; border-radius: 4px; border: 1px solid var(--border); white-space: nowrap;
}

/* ------------------------------------------------ mobile */
@media (max-width: 760px) {
  #side { position: absolute; inset: 0 auto 0 0; width: min(300px, 86vw); box-shadow: var(--shadow-hover); }
  #topbar { gap: 8px; padding: 0 10px; }
  #stats { display: none; }
  .btn { display: none; }
}

/* guest running light */
.tdot.led { width: 9px; height: 9px; margin: 0 4px 0 2px; }
.tdot.led.up { box-shadow: 0 0 0 1.5px color-mix(in srgb, var(--up) 25%, transparent), 0 0 3px var(--up); }
.tdot.led.down { box-shadow: 0 0 0 1.5px color-mix(in srgb, var(--down) 25%, transparent), 0 0 3px var(--down); }
.card.guest.stopped { opacity: .7; }

/* TrueNAS pool usage */
.pools { display: flex; flex-direction: column; gap: 4px; padding-top: 2px; }
.pool { display: grid; grid-template-columns: 64px 1fr auto; align-items: center; gap: 8px; font-size: 11px; color: var(--muted); }
.pool .pn { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.pool .pn.bad { color: var(--down); }
.pool .track { height: 5px; border-radius: 3px; background: var(--border); overflow: hidden; }
.pool .fill { display: block; height: 100%; border-radius: 3px; background: var(--accent); }
.pool .fill.hot { background: var(--warn); }
.pool .fill.crit { background: var(--down); }
.pool .pv { font-variant-numeric: tabular-nums; white-space: nowrap; }
.pool.muted { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* TrueNAS pool / dataset cards */
.tag.tpool { color: var(--c25); }
.tag.ds { color: var(--muted); }
.card.store .pct { margin-left: auto; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.card.store .usage { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 8px; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.card.store .track { height: 5px; border-radius: 3px; background: var(--border); overflow: hidden; }
.card.store .fill { display: block; height: 100%; border-radius: 3px; background: var(--accent); }
.card.store .fill.hot { background: var(--warn); }
.card.store .fill.crit { background: var(--down); }
.card.store.pool-card { border-color: var(--border-strong); }

/* ------------------------------------------------ 2D / 3D switch */
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; flex: none; }
.seg button { border: 0; background: transparent; padding: 4px 11px; cursor: pointer; color: var(--muted); font-weight: 600; font-size: 12px; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--accent); color: #fff; }
#z-spin { display: none; }
#z-spin.on { color: var(--accent); }

/* ------------------------------------------------ 3D view */
#g3d-wrap { position: absolute; inset: 48px 0 0 0; display: none; background: var(--canvas); overflow: hidden; }
#g3d { display: block; cursor: grab; }
#g3d:active { cursor: grabbing; }
#app.mode-3d #viewport { visibility: hidden; }
#app.mode-3d #g3d-wrap { display: block; }
#app.mode-3d #z-spin { display: flex; }
#app.mode-3d #expand-all, #app.mode-3d #collapse-all { display: none; }
#g3d-legend {
  position: absolute; left: 14px; top: 12px; right: 14px; display: flex; flex-wrap: wrap; gap: 4px 12px;
  font-size: 11.5px; color: var(--muted); pointer-events: none;
}
#g3d-legend span { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
#g3d-legend i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
#g3d-legend .hint { flex-basis: 100%; opacity: .75; white-space: normal; }
#g3d-info {
  position: absolute; right: 14px; bottom: 14px; width: 290px; z-index: 3; max-height: calc(100% - 90px); overflow: auto;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-hover);
  padding: 12px 14px; display: flex; flex-direction: column; gap: 8px;
}
#g3d-info[hidden] { display: none; }
.g3-head { display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: 14px; }
.g3-head .icon-btn { margin-left: auto; width: 26px; height: 26px; }
.g3-body { display: flex; flex-direction: column; gap: 3px; }
.kv { display: flex; justify-content: space-between; gap: 12px; font-size: 12px; }
.kv span:first-child { color: var(--muted); }
.kv span:last-child { text-align: right; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
#g3d-info .note { font-size: 11.5px; color: var(--muted); }
#g3d-info .apps { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 4px; }
#g3d-info .apps a { font-size: 11.5px; padding: 2px 7px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); text-decoration: none; }
#g3d-info .meter { height: 6px; border-radius: 3px; background: var(--border); overflow: hidden; margin-top: 4px; }
#g3d-info .meter span { display: block; height: 100%; background: var(--accent); }
#g3d-info .meter span.hot { background: var(--warn); }
#g3d-info .meter span.crit { background: var(--down); }
.g3-actions { display: flex; gap: 8px; align-items: center; }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
@media (max-width: 760px) {
  #g3d-legend { right: 10px; left: 10px; }
  #g3d-info .btn { display: inline-block; }
  #g3d-legend .hint { display: none; }
  #g3d-info { left: 56px; right: 10px; bottom: 10px; width: auto; max-height: 45%; }
  .seg { display: inline-flex; }
}

/* public snapshot: links go to the vendor/project site; items without one are not clickable */
.card[data-url=""], .chip:not([href]) { cursor: default; }
.g3-body .apps span { display: inline-block; margin: 2px 6px 0 0; }
