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

:root {
  /* --- ground ------------------------------------------------ */
  /* Deep blue-slate, never black. The console was near-black under blue-white
     text, 16.7:1: past the 11-13:1 that reads comfortably on a dark ground,
     where light glyphs on near-black bloom and tire the eye. Panels are
     nearly opaque now, so text always sits on a ground that is known. */
  --void:   #0f1826;
  --deep:   #121c2a;
  --panel:  linear-gradient(158deg, rgba(26,38,54,.93) 0%, rgba(22,33,47,.95) 100%);
  --panel-solid: #16212f;
  --raised: #1c2939;         /* hover, open rows, tooltips               */

  /* --- accents: jewel tones ------------------------------------ */
  /* The neon's hues, less saturated. Every one clears 5:1 on --raised,
     the lightest surface text sits on; the old magenta managed 4.2:1. */
  --cy:  #3fd0d8;   /* primary: structure, labels, most data      */
  --mg:  #f07aa6;   /* counterpoint: highlights, deltas, alerts   */
  --am:  #f2b45a;   /* caution, sun, warmth                       */
  --lm:  #8fdc6a;   /* good, safe, go                             */
  --vi:  #b39dfa;   /* space weather, night, exotic               */
  --rd:  #f47171;   /* danger                                     */
  --ice: #7fb2f0;   /* cold                                       */

  /* --- text --------------------------------------------------- */
  /* Three steps, on ground / panel / raised: --ink 14.4/13.1/11.9:1,
     --dim 9.5/8.7/7.9, --faint 6.2/5.7/5.2. read-audit holds both ends:
     nothing under 4.5:1, and no small text over 14:1 on screen.
     --ghost is for rules and fills, never for text. */
  --ink:   #dde2e8;
  --dim:   #b3bfcc;
  --faint: #8d9aab;
  --ghost: #26344a;

  /* --- geometry ----------------------------------------------- */
  --cut: 10px;                 /* corner chamfer                  */
  --gap: 12px;
  --bar: 46px;                 /* top bar height                  */
  --scrub: 108px;              /* time scrubber height            */
  --edge: color-mix(in srgb, var(--cy) 26%, transparent);

  /* --- type --------------------------------------------------- */
  /* Every small font-size is max(<size>, var(--fs-floor)): nothing a reader
     needs is drawn under 12px. It was set only on phones; desktop labels
     were 7-10px. */
  --fs-floor: 12px;
  --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;
  /* Safari otherwise inflates text in some layouts, and 48 of the 66 font
     sizes here are under 12px, so it has plenty to get wrong. */
  -webkit-text-size-adjust: 100%;
  text-rendering: optimizeLegibility;
}

body { overscroll-behavior: none; }

::selection { background: color-mix(in srgb, var(--cy) 28%, transparent); color: var(--ink); }

/* Scrollbars, restyled to match the console instead of the OS. */
* { scrollbar-width: thin; scrollbar-color: color-mix(in srgb, var(--cy) 28%, transparent) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: color-mix(in srgb, var(--void) 60%, transparent); }
*::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--cy) 22%, transparent); }
*::-webkit-scrollbar-thumb:hover { background: color-mix(in srgb, var(--cy) 45%, transparent); }

/* ============================================================
   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;
  /*
   * index.html sets viewport-fit=cover, which extends the layout under the
   * notch and the home indicator. Without this padding the 46px top bar sits
   * beneath the status bar and the bottom of the scrubber sits beneath the
   * home indicator - which is exactly where its drag gesture lives. Paying the
   * cost of `cover` with none of the benefit.
   */
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* 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%, color-mix(in srgb, var(--void) 55%, transparent) 70%, color-mix(in srgb, var(--void) 80%, transparent) 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(15,24,38,.55) 3px, rgba(15,24,38,.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, color-mix(in srgb, var(--cy) 4.5%, transparent) 45%, color-mix(in srgb, var(--cy) 9%, transparent) 50%, color-mix(in srgb, var(--cy) 4.5%, transparent) 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%, color-mix(in srgb, var(--void) 35%, transparent) 100%),
    linear-gradient(to bottom, color-mix(in srgb, var(--cy) 3%, transparent), transparent 12%, transparent 88%, rgba(240,122,166,.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 8px color-mix(in srgb, var(--ac) 22%, transparent);
  pointer-events: none;
}

.panel.flat { background: color-mix(in srgb, var(--panel-solid) 55%, transparent); }
.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: max(.62rem, var(--fs-floor, 0px)); font-weight: 700; letter-spacing: .12em;
  text-transform: uppercase;
  /* The accent lifted toward --ink (it was mixed toward --dim, which put
     the magenta headers at ~4:1). 65%, not 80%: at dusk the violet and magenta
     headers still measured 4.0-4.4:1 on production's brighter sky. */
  color: color-mix(in srgb, var(--ac) 65%, var(--ink));
  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 5px color-mix(in srgb, var(--ac) 50%, transparent);
  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: max(.68rem, var(--fs-floor, 0px)); }

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

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

.lbl {
  font-size: max(.58rem, var(--fs-floor, 0px)); font-weight: 600; letter-spacing: .12em;
  text-transform: uppercase; color: var(--faint);
  white-space: nowrap;
}
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
/* A distant halo, not a bloom: a full-strength glow 7px from the glyph
   blurred its edges, which is the glare this palette exists to remove. */
.neon { text-shadow: 0 0 18px color-mix(in srgb, currentColor 22%, transparent); }
.dimtext { color: var(--dim); }

/* Very large numerals get a wide, faint halo. They had a chromatic split,
   magenta and cyan fringes 1.5px either side of every stroke: striking once,
   and a double image the eye keeps trying to focus. */
.chroma { text-shadow: 0 0 34px color-mix(in srgb, var(--cy) 16%, transparent); }
html[data-q="0"] .chroma { text-shadow: none; }

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

#topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 0 14px;
  padding-top: env(safe-area-inset-top);
  background: linear-gradient(180deg, color-mix(in srgb, var(--panel-solid) 97%, transparent), color-mix(in srgb, var(--panel-solid) 92%, transparent));
  border-bottom: 1px solid color-mix(in srgb, var(--cy) 18%, transparent);
  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, color-mix(in srgb, var(--cy) 55%, transparent) 20%, rgba(240,122,166,.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 color-mix(in srgb, var(--cy) 22%, transparent); }
.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 6px var(--lm);
  transform: rotate(45deg);
  animation: pulse 2.4s var(--ease) infinite;
}
.led[data-state="load"] { background: var(--am); box-shadow: 0 0 6px var(--am); animation-duration: .7s; }
.led[data-state="err"]  { background: var(--rd); box-shadow: 0 0 6px 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: max(.68rem, var(--fs-floor, 0px)); font-weight: 600;
  letter-spacing: .12em; 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: max(.58rem, var(--fs-floor, 0px));
  border: 1px solid currentColor; padding: 0 3px; line-height: 1.3;
  /* Was .5, which halved the digits' contrast to 2.8:1; still quieter than
     the tab's word at .8. */
  opacity: .8;
}
nav button:hover { color: var(--ink); background: color-mix(in srgb, var(--cy) 7%, transparent); }
nav button[aria-selected="true"] {
  color: var(--void); background: var(--cy);
  text-shadow: none;
  box-shadow: 0 0 10px color-mix(in srgb, var(--cy) 22%, transparent);
}
nav button[aria-selected="true"] kbd { opacity: .8; }

.spacer { flex: 1 1 auto; }

/* --- location control --- */
.loc {
  color: var(--ink);   /* a <button>: left alone, dark mode paints it pure white */
  position: relative; flex: 0 1 auto; min-width: 0;
  display: flex; align-items: center; gap: 8px;
  padding: 5px 11px;
  background: color-mix(in srgb, var(--cy) 5%, transparent);
  border: 1px solid color-mix(in srgb, var(--cy) 16%, transparent);
  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: color-mix(in srgb, var(--cy) 10%, transparent); border-color: color-mix(in srgb, var(--cy) 40%, transparent); }
.loc .pin { color: var(--mg); font-size: .8rem; }
.loc .name { font-weight: 600; font-size: max(.78rem, var(--fs-floor, 0px)); letter-spacing: .04em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.loc .sub { font-size: max(.58rem, var(--fs-floor, 0px)); color: var(--dim); letter-spacing: .12em; text-transform: uppercase; }

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

/* The four bar icons travel together, so a narrow viewport can fold them as a
   group instead of orphaning one onto a second row. */
.bar-tools { display: flex; align-items: center; gap: 14px; flex: 0 0 auto; }

.iconbtn {
  background: transparent; border: 1px solid color-mix(in srgb, var(--cy) 16%, transparent);
  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: color-mix(in srgb, var(--cy) 10%, transparent); }
.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: max(.5rem, var(--fs-floor, 0px)); 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(244,113,113,.5); }
  50%     { box-shadow: 0 0 0 7px rgba(244,113,113,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: max(.58rem, var(--fs-floor, 0px)); 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 6px color-mix(in srgb, var(--ac, var(--cy)) 50%, transparent);
  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: max(.62rem, var(--fs-floor, 0px)); letter-spacing: .11em; text-transform: uppercase; color: var(--faint); white-space: nowrap; }
.kv dd { font-family: var(--mono); font-size: max(.78rem, var(--fs-floor, 0px)); color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Status chip. */
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: max(.56rem, var(--fs-floor, 0px)); font-weight: 700; letter-spacing: .12em; 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: max(.64rem, var(--fs-floor, 0px)); letter-spacing: .12em; 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; }
