/* ============================================================
   ATMOS//NET — core design system
   A neon console: near-black ground, cyan primary, magenta
   counterpoint, angular clipped panels, everything glowing.
   ============================================================ */

:root {
  /* --- ground ------------------------------------------------ */
  --void:   #03050b;
  --deep:   #060a14;
  --panel:  linear-gradient(158deg, rgba(9,18,34,.70) 0%, rgba(4,9,19,.84) 100%);
  --panel-solid: #070d1a;

  /* --- neon --------------------------------------------------- */
  --cy:  #00eaff;   /* primary: structure, labels, most data      */
  --mg:  #ff2d8f;   /* counterpoint: highlights, deltas, alerts   */
  --am:  #ffb02e;   /* caution, sun, warmth                       */
  --lm:  #6dff4a;   /* good, safe, go                             */
  --vi:  #a75cff;   /* space weather, night, exotic               */
  --rd:  #ff3b57;   /* danger                                     */
  --ice: #8ab6ff;   /* cold                                       */

  /* --- text --------------------------------------------------- */
  --ink:   #d6ecfa;
  --dim:   #7b97ad;
  --faint: #3a5064;
  --ghost: #1e2c3a;

  /* --- geometry ----------------------------------------------- */
  --cut: 10px;                 /* corner chamfer                  */
  --gap: 12px;
  --bar: 46px;                 /* top bar height                  */
  --scrub: 108px;              /* time scrubber height            */
  --edge: rgba(0,234,255,.26);

  /* --- type --------------------------------------------------- */
  --ui: 'Chakra Petch', 'Rajdhani', ui-sans-serif, system-ui, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  --ease: cubic-bezier(.22,.61,.36,1);
  color-scheme: dark;
}

/* Quality tiers, set by perf.js. Tier 0 is battery-saver: no blur,
   no grain, no bloom-heavy shadows. Tier 3 is plugged-in maximum. */
html[data-q="0"] { --blur: none; }
html[data-q="1"] { --blur: blur(4px); }
html[data-q="2"] { --blur: blur(9px); }
html[data-q="3"] { --blur: blur(14px) saturate(1.25); }

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--void);
  color: var(--ink);
  font-family: var(--ui);
  font-size: 15px;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body { overscroll-behavior: none; }

::selection { background: rgba(0,234,255,.28); color: #fff; }

/* Scrollbars, restyled to match the console instead of the OS. */
* { scrollbar-width: thin; scrollbar-color: rgba(0,234,255,.28) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: rgba(0,0,0,.3); }
*::-webkit-scrollbar-thumb { background: rgba(0,234,255,.22); }
*::-webkit-scrollbar-thumb:hover { background: rgba(0,234,255,.45); }

/* ============================================================
   Layers
   ------------------------------------------------------------
   0  #sky      persistent WebGL sky, always live
   1  #grid     perspective floor grid
   2  #app      the console itself
   9  #fx       scanlines / vignette / grain, pointer-events none
   ============================================================ */

#sky, #grid {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  display: block;
}
#sky  { z-index: 0; }
#grid { z-index: 1; opacity: .55; mix-blend-mode: screen; }

#app {
  position: relative; z-index: 2;
  height: 100dvh;
  display: grid;
  grid-template-rows: var(--bar) 1fr auto;
}

/* Dim the sky behind the data-dense views so text stays readable. */
#app::before {
  content: ''; position: fixed; inset: 0; z-index: -1;
  background: radial-gradient(120% 90% at 50% 0%, transparent 20%, rgba(3,5,11,.55) 70%, rgba(3,5,11,.8) 100%);
  opacity: var(--stage-dim, 0);
  transition: opacity .5s var(--ease);
  pointer-events: none;
}

/* ------------------------------------------------------------ FX overlay */

#fx { position: fixed; inset: 0; z-index: 9; pointer-events: none; }

#fx .scan {
  position: absolute; inset: -50%;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0,0,0,0) 0px, rgba(0,0,0,0) 2px,
    rgba(0,20,30,.55) 3px, rgba(0,20,30,.55) 4px);
  opacity: .34;
  animation: scandrift 9s linear infinite;
}
@keyframes scandrift { to { transform: translateY(4px); } }

/* A single bright line sweeping down the screen, like a CRT refresh. */
#fx .sweep {
  position: absolute; left: 0; right: 0; height: 180px;
  background: linear-gradient(to bottom, transparent, rgba(0,234,255,.045) 45%, rgba(0,234,255,.09) 50%, rgba(0,234,255,.045) 55%, transparent);
  animation: sweep 7.5s cubic-bezier(.4,0,.6,1) infinite;
}
@keyframes sweep { 0% { top: -20%; } 100% { top: 120%; } }

#fx .vig {
  position: absolute; inset: 0;
  background:
    radial-gradient(130% 100% at 50% 50%, transparent 42%, rgba(0,0,0,.55) 100%),
    linear-gradient(to bottom, rgba(0,234,255,.03), transparent 12%, transparent 88%, rgba(255,45,143,.035));
}

#fx .grain {
  position: absolute; inset: 0;
  opacity: .05;
  background-image: var(--grain);
  background-size: 180px 180px;
  animation: grain .6s steps(3) infinite;
}
@keyframes grain {
  0%   { transform: translate(0,0); }
  33%  { transform: translate(-4px,3px); }
  66%  { transform: translate(3px,-2px); }
  100% { transform: translate(0,0); }
}

html[data-q="0"] #fx .grain,
html[data-q="0"] #fx .sweep,
html[data-q="1"] #fx .grain { display: none; }

@media (prefers-reduced-motion: reduce) {
  #fx .scan, #fx .sweep, #fx .grain { animation: none; }
}

/* ============================================================
   Panels — the angular clipped card that everything lives in
   ============================================================ */

.panel {
  --ac: var(--cy);
  position: relative;
  background: var(--panel);
  backdrop-filter: var(--blur, blur(9px));
  -webkit-backdrop-filter: var(--blur, blur(9px));
  clip-path: polygon(
    0 var(--cut), var(--cut) 0,
    100% 0, 100% calc(100% - var(--cut)),
    calc(100% - var(--cut)) 100%, 0 100%);
  padding: 11px 13px 12px;
  min-width: 0; min-height: 0;
  display: flex; flex-direction: column;
  transition: background .35s var(--ease);
}

/* 1px border that follows the chamfer, via a masked ring. */
.panel::before {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  padding: 1px;
  background: linear-gradient(150deg,
    color-mix(in srgb, var(--ac) 55%, transparent) 0%,
    color-mix(in srgb, var(--ac) 12%, transparent) 38%,
    color-mix(in srgb, var(--ac) 8%, transparent) 62%,
    color-mix(in srgb, var(--ac) 40%, transparent) 100%);
  clip-path: polygon(
    0 var(--cut), var(--cut) 0,
    100% 0, 100% calc(100% - var(--cut)),
    calc(100% - var(--cut)) 100%, 0 100%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
          mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
          mask-composite: exclude;
}

/* Inner top-edge glow, so panels read as lit rather than drawn. */
.panel::after {
  content: ''; position: absolute; left: var(--cut); right: 0; top: 0; height: 1px;
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--ac) 75%, transparent), transparent);
  box-shadow: 0 0 12px color-mix(in srgb, var(--ac) 45%, transparent);
  pointer-events: none;
}

.panel.flat { background: rgba(4,9,19,.55); }
.panel.bare { padding: 0; overflow: hidden; }

/* Panel heading: tiny caps label + rule + optional right-hand value. */
.hd {
  display: flex; align-items: center; gap: 8px;
  font-size: .62rem; font-weight: 700; letter-spacing: .2em;
  text-transform: uppercase;
  color: color-mix(in srgb, var(--ac) 78%, var(--dim));
  margin-bottom: 8px;
  flex: 0 0 auto;
  white-space: nowrap;
}
.hd::before {
  content: ''; width: 5px; height: 5px; flex: 0 0 auto;
  background: var(--ac);
  box-shadow: 0 0 8px var(--ac);
  transform: rotate(45deg);
}
.hd .rule { flex: 1; height: 1px; background: linear-gradient(90deg, color-mix(in srgb, var(--ac) 30%, transparent), transparent); }
.hd .val { color: var(--ink); font-family: var(--mono); letter-spacing: .04em; font-size: .68rem; }

.body { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }

/* ============================================================
   Type
   ============================================================ */

.lbl {
  font-size: .58rem; font-weight: 600; letter-spacing: .19em;
  text-transform: uppercase; color: var(--faint);
  white-space: nowrap;
}
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.neon { text-shadow: 0 0 7px currentColor, 0 0 24px color-mix(in srgb, currentColor 45%, transparent); }
.dimtext { color: var(--dim); }

/* Chromatic split: the signature treatment for very large numerals. */
.chroma {
  text-shadow:
    -1.5px 0 0 rgba(255,45,143,.50),
     1.5px 0 0 rgba(0,234,255,.50),
     0 0 34px rgba(0,234,255,.30),
     0 0 90px rgba(0,234,255,.14);
}
html[data-q="0"] .chroma { text-shadow: 0 0 12px rgba(0,234,255,.3); }

/* ============================================================
   Top bar
   ============================================================ */

#topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 0 14px;
  background: linear-gradient(180deg, rgba(4,9,19,.92), rgba(4,9,19,.66));
  border-bottom: 1px solid rgba(0,234,255,.18);
  backdrop-filter: blur(10px);
  position: relative; z-index: 5;
}
#topbar::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: -1px; height: 1px;
  background: linear-gradient(90deg, transparent, rgba(0,234,255,.55) 20%, rgba(255,45,143,.4) 70%, transparent);
}

.brand {
  display: flex; align-items: center; gap: 9px;
  font-weight: 700; letter-spacing: .13em; font-size: .82rem;
  flex: 0 0 auto;
}
.brand b { color: var(--cy); text-shadow: 0 0 10px rgba(0,234,255,.6); }
.brand i { color: var(--mg); font-style: normal; opacity: .85; }

/* Connection LED. Colour is driven by [data-state]. */
.led {
  width: 8px; height: 8px; flex: 0 0 auto;
  background: var(--lm); box-shadow: 0 0 10px var(--lm);
  transform: rotate(45deg);
  animation: pulse 2.4s var(--ease) infinite;
}
.led[data-state="load"] { background: var(--am); box-shadow: 0 0 10px var(--am); animation-duration: .7s; }
.led[data-state="err"]  { background: var(--rd); box-shadow: 0 0 10px var(--rd); animation-duration: .35s; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

/* --- nav tabs --- */
nav { display: flex; gap: 2px; flex: 0 0 auto; }
nav button {
  position: relative;
  font-family: var(--ui); font-size: .68rem; font-weight: 600;
  letter-spacing: .16em; text-transform: uppercase;
  color: var(--dim); background: transparent; border: 0;
  padding: 7px 14px 7px 12px; cursor: pointer;
  display: flex; align-items: center; gap: 7px;
  clip-path: polygon(6px 0, 100% 0, calc(100% - 6px) 100%, 0 100%);
  transition: color .2s, background .2s;
}
nav button kbd {
  font-family: var(--mono); font-size: .58rem; opacity: .5;
  border: 1px solid currentColor; padding: 0 3px; line-height: 1.3;
}
nav button:hover { color: var(--ink); background: rgba(0,234,255,.07); }
nav button[aria-selected="true"] {
  color: var(--void); background: var(--cy);
  text-shadow: none;
  box-shadow: 0 0 18px rgba(0,234,255,.5);
}
nav button[aria-selected="true"] kbd { opacity: .65; }

.spacer { flex: 1 1 auto; }

/* --- location control --- */
.loc {
  position: relative; flex: 0 1 auto; min-width: 0;
  display: flex; align-items: center; gap: 8px;
  padding: 5px 11px;
  background: rgba(0,234,255,.05);
  border: 1px solid rgba(0,234,255,.16);
  clip-path: polygon(7px 0,100% 0,100% calc(100% - 7px),calc(100% - 7px) 100%,0 100%,0 7px);
  cursor: pointer; transition: border-color .2s, background .2s;
}
.loc:hover { background: rgba(0,234,255,.1); border-color: rgba(0,234,255,.4); }
.loc .pin { color: var(--mg); font-size: .8rem; }
.loc .name { font-weight: 600; font-size: .78rem; letter-spacing: .04em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.loc .sub { font-size: .58rem; color: var(--faint); letter-spacing: .12em; text-transform: uppercase; }

.clock {
  font-family: var(--mono); font-size: .82rem; font-weight: 500;
  letter-spacing: .05em; color: var(--cy);
  text-shadow: 0 0 12px rgba(0,234,255,.45);
  flex: 0 0 auto; font-variant-numeric: tabular-nums;
}
.clock small { display: block; font-size: .52rem; color: var(--faint); letter-spacing: .18em; text-align: right; text-shadow: none; }

.iconbtn {
  background: transparent; border: 1px solid rgba(0,234,255,.16);
  color: var(--dim); cursor: pointer;
  width: 30px; height: 30px; flex: 0 0 auto;
  display: grid; place-items: center; font-size: .9rem;
  clip-path: polygon(5px 0,100% 0,100% calc(100% - 5px),calc(100% - 5px) 100%,0 100%,0 5px);
  transition: all .18s;
}
.iconbtn:hover { color: var(--cy); border-color: var(--cy); background: rgba(0,234,255,.1); }
.iconbtn.on { color: var(--void); background: var(--cy); border-color: var(--cy); }

/* Alert badge in the bar; pulses when something is active. */
.alertbtn { position: relative; }
.alertbtn[data-n]:not([data-n="0"]) {
  color: var(--rd); border-color: var(--rd);
  animation: alertpulse 1.6s ease-in-out infinite;
}
.alertbtn[data-n]:not([data-n="0"])::after {
  content: attr(data-n);
  position: absolute; top: -5px; right: -5px;
  background: var(--rd); color: #fff;
  font-family: var(--mono); font-size: .5rem; font-weight: 700;
  min-width: 13px; height: 13px; display: grid; place-items: center;
  border-radius: 50%;
}
@keyframes alertpulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(255,59,87,.5); }
  50%     { box-shadow: 0 0 0 7px rgba(255,59,87,0); }
}

/* ============================================================
   Stage / views
   ============================================================ */

#stage { position: relative; overflow: hidden; }

.view {
  position: absolute; inset: 0;
  padding: var(--gap);
  overflow: hidden;
  opacity: 0; visibility: hidden;
  transform: translateY(8px) scale(.995);
  transition: opacity .32s var(--ease), transform .32s var(--ease), visibility 0s .32s;
}
.view.active {
  opacity: 1; visibility: visible;
  transform: none;
  transition: opacity .32s var(--ease), transform .32s var(--ease), visibility 0s;
}

/* ============================================================
   Small shared components
   ============================================================ */

/* Stat tile: label over big value over unit/context. */
.stat { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stat .v {
  font-family: var(--mono); font-weight: 700; font-size: 1.5rem;
  line-height: 1; color: var(--ink); font-variant-numeric: tabular-nums;
}
.stat .v small { font-size: .58em; font-weight: 500; color: var(--dim); margin-left: 2px; }
.stat .c { font-size: .58rem; letter-spacing: .1em; color: var(--faint); text-transform: uppercase; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Horizontal meter with a neon fill. */
.meter { height: 4px; background: rgba(255,255,255,.06); position: relative; overflow: hidden; }
.meter i {
  position: absolute; inset: 0 auto 0 0; display: block;
  background: var(--ac, var(--cy));
  box-shadow: 0 0 10px var(--ac, var(--cy));
  transition: width .5s var(--ease);
}
.meter.seg { background: repeating-linear-gradient(90deg, rgba(255,255,255,.09) 0 3px, transparent 3px 5px); }

/* Key/value row used throughout the detail panels. */
.kv { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; padding: 3px 0; }
.kv + .kv { border-top: 1px solid rgba(255,255,255,.045); }
.kv dt { font-size: .62rem; letter-spacing: .11em; text-transform: uppercase; color: var(--faint); white-space: nowrap; }
.kv dd { font-family: var(--mono); font-size: .78rem; color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Status chip. */
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: .56rem; font-weight: 700; letter-spacing: .14em; text-transform: uppercase;
  padding: 2px 7px; color: var(--ac, var(--cy));
  border: 1px solid color-mix(in srgb, var(--ac, var(--cy)) 45%, transparent);
  background: color-mix(in srgb, var(--ac, var(--cy)) 10%, transparent);
  clip-path: polygon(4px 0,100% 0,100% calc(100% - 4px),calc(100% - 4px) 100%,0 100%,0 4px);
  white-space: nowrap;
}

canvas.chart { display: block; width: 100%; height: 100%; }

/* Empty / error state inside a panel. */
.nodata {
  flex: 1; display: grid; place-items: center; text-align: center;
  color: var(--faint); font-size: .64rem; letter-spacing: .14em; text-transform: uppercase;
  padding: 14px;
}

/* Loading shimmer for values that haven't arrived yet. */
.pending { color: var(--faint) !important; animation: blink 1.1s steps(2) infinite; }
@keyframes blink { 50% { opacity: .25; } }

/* Data-refresh glitch, triggered by adding .glitch for one frame. */
@keyframes glitchclip {
  0%   { clip-path: inset(0 0 0 0);      transform: translateX(0); }
  20%  { clip-path: inset(18% 0 62% 0);  transform: translateX(-3px); }
  40%  { clip-path: inset(70% 0 12% 0);  transform: translateX(3px); }
  60%  { clip-path: inset(40% 0 44% 0);  transform: translateX(-2px); }
  100% { clip-path: inset(0 0 0 0);      transform: translateX(0); }
}
.glitch { animation: glitchclip .26s steps(2) 1; }
