/* ==========================================================================
   NanoPi Control — tech / HUD theme
   ========================================================================== */
:root {
  color-scheme: dark;
  --bg:          #070b11;
  --bg-grid:     rgba(56, 189, 248, 0.045);
  --panel:       #0f1923;
  --panel-2:     #13202c;
  --line:        #1d2e3d;
  --line-strong: #2a4256;
  --text:        #e6eef5;
  --text-2:      #8da2b5;
  --text-3:      #5d7184;
  --accent:      #22d3ee;   /* UI chrome only — never a data series */
  --accent-dim:  rgba(34, 211, 238, 0.12);

  /* Data series (validated dark categorical order) */
  --series-1: #338ced;
  --series-2: #e76624;
  --series-3: #00a888;
  --series-4: #d28e05;
  --series-5: #e24d8b;
  --series-6: #0aac23;

  /* Status — reserved, always paired with icon + label */
  --good:     #0aac23;
  --warning:  #fbb315;
  --serious:  #f18a59;
  --critical: #dc3c3d;

  --radius: 10px;
  --mono: "JetBrains Mono", "Fira Code", "Cascadia Code", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --sidebar-w: 232px;
}

* { box-sizing: border-box; }
/* The hidden attribute must win over component display rules (.reconnect, .cam-nosignal, …) */
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background:
    linear-gradient(var(--bg-grid) 1px, transparent 1px) 0 0 / 32px 32px,
    linear-gradient(90deg, var(--bg-grid) 1px, transparent 1px) 0 0 / 32px 32px,
    radial-gradient(1200px 600px at 80% -10%, rgba(34, 211, 238, 0.07), transparent 60%),
    var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
.mono, .num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--text-2); }
.dim { color: var(--text-3); }
.icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: linear-gradient(180deg, rgba(15, 25, 35, 0.92), rgba(7, 11, 17, 0.92));
  border-right: 1px solid var(--line);
  padding: 20px 14px; display: flex; flex-direction: column; gap: 22px;
  backdrop-filter: blur(6px);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 8px; display: grid; place-items: center;
  border: 1px solid var(--accent); color: var(--accent); background: var(--accent-dim);
  box-shadow: 0 0 18px rgba(34, 211, 238, 0.25), inset 0 0 10px rgba(34, 211, 238, 0.15);
}
.brand-name { font-family: var(--mono); font-weight: 700; letter-spacing: 0.08em; font-size: 13px; }
.brand-sub { font-family: var(--mono); font-size: 11px; color: var(--text-3); }
.nav-group-title { font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--text-3); padding: 0 10px 6px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; margin: 2px 0;
  border-radius: 8px; color: var(--text-2); border: 1px solid transparent; position: relative;
}
.nav a:hover { color: var(--text); background: rgba(255, 255, 255, 0.03); }
.nav a.active { color: var(--accent); background: var(--accent-dim); border-color: rgba(34, 211, 238, 0.25); }
.nav a.active::before {
  content: ""; position: absolute; left: -14px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0;
  background: var(--accent); box-shadow: 0 0 10px var(--accent);
}
.sidebar-foot { margin-top: auto; font-family: var(--mono); font-size: 11px; color: var(--text-3); padding: 0 8px; line-height: 1.7; }

.main { min-width: 0; padding: 0 28px 40px; }
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 16px 0 14px; margin-bottom: 18px;
  background: linear-gradient(180deg, var(--bg) 70%, rgba(7, 11, 17, 0));
}
.page-title { font-family: var(--mono); font-size: 18px; font-weight: 600; letter-spacing: 0.04em; margin: 0; }
.page-title .slash { color: var(--accent); margin-right: 6px; }
.topbar .spacer { flex: 1; }
.top-meta { display: flex; gap: 18px; font-family: var(--mono); font-size: 12px; color: var(--text-2); flex-wrap: wrap; }
.top-meta b { color: var(--text); font-weight: 500; }
.menu-btn { display: none; }

/* ---------- panels ---------- */
.grid { display: grid; gap: 16px; }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.span-all { grid-column: 1 / -1; }
.section { margin-top: 16px; }

.panel {
  position: relative; background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; min-width: 0;
}
/* HUD corner brackets */
.panel::before, .panel::after {
  content: ""; position: absolute; width: 12px; height: 12px; pointer-events: none;
  border-color: var(--line-strong); border-style: solid;
}
.panel::before { top: -1px; left: -1px; border-width: 1px 0 0 1px; border-top-left-radius: var(--radius); }
.panel::after { bottom: -1px; right: -1px; border-width: 0 1px 1px 0; border-bottom-right-radius: var(--radius); }
.panel-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.panel-title { font-family: var(--mono); font-size: 11.5px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--text-2); margin: 0; }
.panel-head .right { margin-left: auto; font-family: var(--mono); font-size: 12px; color: var(--text-2); }

/* ---------- stat tiles with ring gauge ---------- */
.tile { display: flex; align-items: center; gap: 16px; }
.gauge { position: relative; width: 88px; height: 88px; flex: none; }
.gauge svg { width: 100%; height: 100%; transform: rotate(135deg); }
.gauge .track { stroke: #1a2a38; }
.gauge .bar { transition: stroke-dashoffset 0.6s ease, stroke 0.3s; filter: drop-shadow(0 0 4px currentColor); }
.gauge .val { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--mono); font-size: 19px; font-weight: 600; }
.gauge .val small { font-size: 11px; color: var(--text-2); font-weight: 400; }
.tile-body { min-width: 0; }
.tile-label { font-family: var(--mono); font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--text-2); }
.tile-detail { font-family: var(--mono); font-size: 12px; color: var(--text-2); margin-top: 4px; }

/* Column count is set by NP.balanceTiles (common.js) so rows come out even;
   this auto-fit rule is only the no-JS fallback. */
.kv-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; }
.kv { padding: 12px 14px; min-width: 0; container-type: inline-size; }
.kv .tile-label { margin-bottom: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kv .big {
  font-family: var(--mono); font-weight: 600; font-variant-numeric: tabular-nums;
  font-size: 22px; font-size: clamp(15px, 16cqi, 22px);   /* scales with the tile's width */
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.kv .big small { font-size: 0.55em; color: var(--text-2); font-weight: 400; margin-left: 3px; }

/* ---------- status ---------- */
.status { display: inline-flex; align-items: center; gap: 6px; font-family: var(--mono); font-size: 11.5px; padding: 3px 9px; border-radius: 999px; border: 1px solid; white-space: nowrap; color: var(--text); }
.status .icon { width: 13px; height: 13px; stroke-width: 2.4; }
.status.good     { border-color: rgba(10, 172, 35, 0.5);  background: rgba(10, 172, 35, 0.1); }
.status.good .icon { color: var(--good); }
.status.warning  { border-color: rgba(251, 179, 21, 0.5); background: rgba(251, 179, 21, 0.1); }
.status.warning .icon { color: var(--warning); }
.status.serious  { border-color: rgba(241, 138, 89, 0.5); background: rgba(241, 138, 89, 0.1); }
.status.serious .icon { color: var(--serious); }
.status.critical { border-color: rgba(220, 60, 61, 0.6);  background: rgba(220, 60, 61, 0.12); }
.status.critical .icon { color: var(--critical); }
.status.unknown  { border-color: var(--line-strong); color: var(--text-2); }

.health-banner { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.health-main { display: flex; align-items: center; gap: 12px; }
.health-orb { width: 14px; height: 14px; border-radius: 50%; background: var(--text-3); box-shadow: 0 0 0 4px rgba(255,255,255,0.04); }
.health-orb.good { background: var(--good); box-shadow: 0 0 14px var(--good); animation: pulse 2.4s infinite; }
.health-orb.warning { background: var(--warning); box-shadow: 0 0 14px var(--warning); animation: pulse 1.6s infinite; }
.health-orb.critical { background: var(--critical); box-shadow: 0 0 14px var(--critical); animation: pulse 0.9s infinite; }
@keyframes pulse { 50% { opacity: 0.45; } }
.health-word { font-family: var(--mono); font-size: 16px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; }
.health-checks { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- filters / controls ---------- */
.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 18px 0 12px; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; }
.seg button {
  background: transparent; color: var(--text-2); border: 0; padding: 6px 12px; cursor: pointer;
  font-family: var(--mono); font-size: 12px; border-right: 1px solid var(--line);
}
.seg button:last-child { border-right: 0; }
.seg button:hover { color: var(--text); background: rgba(255, 255, 255, 0.03); }
.seg button.on { color: var(--accent); background: var(--accent-dim); }
select, .btn {
  background: var(--panel); color: var(--text); border: 1px solid var(--line-strong); border-radius: 8px;
  padding: 6px 10px; font-family: var(--mono); font-size: 12px; cursor: pointer;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.round { width: 34px; height: 34px; padding: 0; display: inline-grid; place-items: center; font-size: 16px; }
.live { display: inline-flex; align-items: center; gap: 6px; font-family: var(--mono); font-size: 11px; color: var(--text-2); }
.live::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 8px var(--accent); animation: pulse 1.4s infinite; }
.live.stale::before { background: var(--critical); box-shadow: 0 0 8px var(--critical); }

/* toggle switch */
.switch { position: relative; width: 46px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: #1a2a38; border: 1px solid var(--line-strong); cursor: pointer; transition: 0.2s; }
.switch span::after { content: ""; position: absolute; width: 18px; height: 18px; top: 2px; left: 2px; border-radius: 50%; background: var(--text-2); transition: 0.2s; }
.switch input:checked + span { background: var(--accent-dim); border-color: var(--accent); }
.switch input:checked + span::after { transform: translateX(22px); background: var(--accent); box-shadow: 0 0 8px var(--accent); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- charts ---------- */
.chart-box { position: relative; height: 210px; }
.chart-box.tall { height: 260px; }
.chart-box.short { height: 150px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-family: var(--mono); font-size: 11.5px; color: var(--text-2); }
.legend i { display: inline-block; width: 10px; height: 3px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.legend b { color: var(--text); font-weight: 500; margin-left: 4px; }

/* bars (per-core, disks, memory) */
.hbar { margin: 10px 0; }
.hbar-top { display: flex; justify-content: space-between; font-family: var(--mono); font-size: 12px; margin-bottom: 5px; gap: 8px; }
.hbar-track { height: 8px; border-radius: 4px; background: #15232f; overflow: hidden; display: flex; gap: 2px; }
.hbar-fill { height: 100%; border-radius: 4px; background: var(--series-1); transition: width 0.5s ease; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th { text-align: left; font-family: var(--mono); font-weight: 500; font-size: 10.5px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--text-3); padding: 8px 10px; border-bottom: 1px solid var(--line-strong); white-space: nowrap; }
td { padding: 7px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td.num, th.num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
tbody tr:hover { background: rgba(34, 211, 238, 0.04); }
th.sortable { cursor: pointer; }
th.sortable.on { color: var(--accent); }
.kv-table td:first-child { color: var(--text-2); font-family: var(--mono); font-size: 12px; width: 40%; }
.kv-table td { white-space: normal; word-break: break-word; }

/* ---------- device cards ---------- */
.device-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.device-icon { width: 38px; height: 38px; border-radius: 9px; display: grid; place-items: center; border: 1px solid var(--line-strong); color: var(--text-2); }
.device-icon.hot { color: var(--series-2); border-color: rgba(231, 102, 36, 0.5); box-shadow: 0 0 14px rgba(231, 102, 36, 0.25); }
.device-name { font-weight: 600; }
.device-room { font-family: var(--mono); font-size: 11px; color: var(--text-3); }
.device-head .switch { margin-left: auto; }
.heater-readout { display: flex; align-items: flex-end; gap: 22px; flex-wrap: wrap; margin-bottom: 12px; }
.heater-temp { font-family: var(--mono); font-size: 40px; font-weight: 600; line-height: 1; font-variant-numeric: tabular-nums; }
.heater-temp small { font-size: 16px; color: var(--text-2); }
.setpoint { display: flex; align-items: center; gap: 8px; }
.setpoint .num { min-width: 64px; text-align: center; font-size: 18px; }
.error-text { color: var(--serious); font-family: var(--mono); font-size: 12px; }

.cam-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 380px), 1fr)); gap: 16px; }
.cam-view { position: relative; aspect-ratio: 16 / 9; background: #05080c; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); cursor: zoom-in; }
.cam-view img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cam-view .cam-overlay { position: absolute; left: 10px; top: 8px; font-family: var(--mono); font-size: 11px; color: #fff; text-shadow: 0 1px 2px #000; display: flex; gap: 8px; align-items: center; }
.cam-view .rec { width: 8px; height: 8px; border-radius: 50%; background: var(--critical); animation: pulse 1.2s infinite; }
.cam-nosignal { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; font-family: var(--mono); color: var(--text-3);
  background: repeating-linear-gradient(0deg, rgba(255,255,255,0.025) 0 2px, transparent 2px 4px); }
.cam-view:fullscreen { cursor: zoom-out; }
.cam-view:fullscreen img { object-fit: contain; }

.empty { text-align: center; padding: 48px 20px; color: var(--text-2); }
.empty pre { text-align: left; display: inline-block; background: #05080c; border: 1px solid var(--line); border-radius: 8px; padding: 14px 18px; color: var(--text); font-size: 12px; max-width: 100%; overflow-x: auto; }

/* ---------- power controls ---------- */
.power-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.power-actions .btn { display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; }
.power-actions .icon { width: 15px; height: 15px; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; border-color: var(--line-strong); color: var(--text-2); }
.btn.danger { border-color: rgba(220, 60, 61, 0.55); }
.btn.danger:hover:not(:disabled) { border-color: var(--critical); color: #ff8a8b; background: rgba(220, 60, 61, 0.1); }
.power-status { margin-top: 10px; font-family: var(--mono); font-size: 11.5px; color: var(--text-2); display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }

.modal { background: linear-gradient(180deg, var(--panel-2), var(--panel)); color: var(--text); border: 1px solid var(--line-strong);
  border-radius: var(--radius); padding: 22px; width: min(400px, calc(100vw - 32px)); box-shadow: 0 0 40px rgba(0, 0, 0, 0.6); }
.modal::backdrop { background: rgba(3, 6, 10, 0.75); backdrop-filter: blur(3px); }
.modal p { color: var(--text-2); margin: 10px 0 16px; }
.modal input { width: 100%; margin: 6px 0 8px; padding: 10px 12px; background: #05080c; color: var(--text); border: 1px solid var(--line-strong);
  border-radius: 8px; font: 18px var(--mono); letter-spacing: 0.3em; }
.modal input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 14px; }
.modal-actions .btn { padding: 8px 14px; }

.reconnect { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: rgba(3, 6, 10, 0.88); backdrop-filter: blur(4px); padding: 16px; }
.reconnect-box { text-align: center; padding: 30px 40px; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.spinner { width: 44px; height: 44px; border-radius: 50%; border: 3px solid var(--line-strong); border-top-color: var(--accent);
  animation: spin 0.9s linear infinite; margin-bottom: 10px; box-shadow: 0 0 18px rgba(34, 211, 238, 0.2); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- responsive ---------- */
@media (max-width: 1280px) { .cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 1000px) {
  .cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cols-2 { grid-template-columns: minmax(0, 1fr); }
  .span-2 { grid-column: auto; }
}
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 20; left: 0; width: var(--sidebar-w); transform: translateX(-100%); transition: transform 0.25s; }
  .sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, 0.6); }
  .menu-btn { display: inline-grid; }
  .main { padding: 0 16px 32px; }
}
@media (max-width: 620px) {
  .cols-3, .cols-4 { grid-template-columns: minmax(0, 1fr); }
  .top-meta { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
