/* ============================================================
   AEGIS TWIN — Mission-Critical Ops Command Center
   Dark-mode native workstation design system
   ============================================================ */

:root {
  /* ---- Atmospheric base ---- */
  --bg-abyss: #06090f;
  --bg-deep: #0a0f18;
  --bg-panel: rgba(15, 22, 34, 0.72);
  --bg-panel-solid: #0e1622;
  --bg-raised: rgba(24, 34, 50, 0.66);
  --bg-inset: rgba(5, 9, 15, 0.6);
  --bg-canvas: #080d15;

  /* ---- Hairlines & strokes ---- */
  --line-hair: rgba(120, 160, 210, 0.14);
  --line-soft: rgba(120, 160, 210, 0.22);
  --line-strong: rgba(140, 190, 255, 0.38);

  /* ---- Domain accents (ops-teal / amber / critical) ---- */
  --acc-primary: #2dd4bf;
  --acc-primary-dim: rgba(45, 212, 191, 0.16);
  --acc-cyan: #38bdf8;
  --acc-amber: #f5a524;
  --acc-red: #f43f5e;
  --acc-green: #34d399;
  --acc-violet: #a78bfa;

  /* ---- Text ---- */
  --tx-hi: #e8f1fb;
  --tx-mid: #9db2c9;
  --tx-low: #5d7189;
  --tx-faint: #3d4d63;

  /* ---- Status ---- */
  --ok: #34d399;
  --warn: #f5a524;
  --crit: #f43f5e;

  /* ---- Glows / shadows ---- */
  --glow-teal: 0 0 18px rgba(45, 212, 191, 0.28);
  --glow-red: 0 0 16px rgba(244, 63, 94, 0.34);
  --shadow-panel: 0 8px 32px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(160, 200, 255, 0.05);
  --shadow-modal: 0 24px 72px rgba(0, 0, 0, 0.65);

  /* ---- Fluid type ---- */
  --fs-xxs: clamp(0.58rem, 0.55rem + 0.15vw, 0.66rem);
  --fs-xs: clamp(0.66rem, 0.62rem + 0.2vw, 0.75rem);
  --fs-sm: clamp(0.74rem, 0.7rem + 0.25vw, 0.85rem);
  --fs-md: clamp(0.85rem, 0.8rem + 0.3vw, 0.98rem);
  --fs-lg: clamp(1rem, 0.92rem + 0.4vw, 1.2rem);
  --fs-xl: clamp(1.15rem, 1rem + 0.7vw, 1.5rem);

  /* ---- Spacing ---- */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;

  --font-ui: "Inter", "Ubuntu", "Segoe UI", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", "Ubuntu Mono", "Cascadia Code", ui-monospace, monospace;

  --hostbar-h: 52px;
  --sessionbar-h: 42px;
}

/* ============================================================
   RESET / BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: var(--fs-sm);
  color: var(--tx-hi);
  background:
    radial-gradient(1200px 700px at 75% -10%, rgba(45, 212, 191, 0.07), transparent 60%),
    radial-gradient(900px 600px at -10% 110%, rgba(56, 189, 248, 0.06), transparent 55%),
    linear-gradient(180deg, var(--bg-deep), var(--bg-abyss));
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

body::after { /* faint scanline atmosphere */
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(0deg, rgba(255,255,255,0.012) 0 1px, transparent 1px 3px);
  z-index: 5;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: 0.02em; }
p { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select { font: inherit; color: var(--tx-hi); }
canvas { display: block; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  clip: rect(0 0 0 0); clip-path: inset(50%);
  overflow: hidden; white-space: nowrap;
}

:focus-visible {
  outline: 2px solid var(--acc-cyan);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(120, 160, 210, 0.22); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(120, 160, 210, 0.4); }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 7px 14px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line-soft);
  background: var(--bg-raised);
  color: var(--tx-hi);
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.03em;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s, transform 0.1s;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}
.btn:hover:not(:disabled) { border-color: var(--line-strong); background: rgba(34, 48, 70, 0.8); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.42; cursor: not-allowed; }

.btn--primary {
  background: linear-gradient(135deg, rgba(45, 212, 191, 0.22), rgba(56, 189, 248, 0.14));
  border-color: rgba(45, 212, 191, 0.5);
  color: #b7fff3;
}
.btn--primary:hover:not(:disabled) { box-shadow: var(--glow-teal); border-color: var(--acc-primary); }

.btn--accent {
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.22), rgba(167, 139, 250, 0.14));
  border-color: rgba(56, 189, 248, 0.5);
  color: #cdeaff;
}
.btn--accent:hover:not(:disabled) { box-shadow: 0 0 16px rgba(56, 189, 248, 0.3); }

.btn--ghost { background: transparent; border-color: var(--line-hair); color: var(--tx-mid); }
.btn--ghost:hover:not(:disabled) { color: var(--tx-hi); }

.btn--danger {
  background: linear-gradient(135deg, rgba(244, 63, 94, 0.24), rgba(244, 63, 94, 0.1));
  border-color: rgba(244, 63, 94, 0.55);
  color: #ffd6de;
}
.btn--danger:hover:not(:disabled) { box-shadow: var(--glow-red); border-color: var(--acc-red); }

.btn--block { width: 100%; justify-content: center; }

.btn--cmd {
  justify-content: center;
  padding: 8px 6px;
  font-size: var(--fs-xxs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ============================================================
   HOST BAR (native desktop chrome)
   ============================================================ */
.host-bar {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  height: var(--hostbar-h);
  padding: 0 var(--sp-4);
  background: rgba(10, 15, 24, 0.82);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line-hair);
  position: sticky;
  top: 0;
  z-index: 60;
  -webkit-app-region: drag;
}
.host-bar button, .host-bar a { -webkit-app-region: no-drag; }

.host-bar__brand { display: flex; align-items: center; gap: var(--sp-2); min-width: 0; }
.brand-mark { color: var(--acc-primary); filter: drop-shadow(0 0 6px rgba(45, 212, 191, 0.6)); flex: none; }
.brand-name {
  font-size: var(--fs-md);
  font-weight: 800;
  letter-spacing: 0.18em;
  background: linear-gradient(90deg, #d9fff8, #7dd3fc);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  white-space: nowrap;
}
.brand-sub {
  font-size: var(--fs-xxs);
  color: var(--tx-low);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  padding-left: var(--sp-2);
  border-left: 1px solid var(--line-hair);
  white-space: nowrap;
}

.host-bar__targets { display: flex; gap: var(--sp-2); margin-inline: auto; }
.platform-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line-hair);
  background: var(--bg-inset);
  color: var(--tx-low);
  font-size: var(--fs-xxs);
  letter-spacing: 0.05em;
  transition: color 0.15s, border-color 0.15s;
}
.platform-chip[data-platform="ubuntu"] { color: var(--acc-primary); border-color: rgba(45, 212, 191, 0.4); box-shadow: inset 0 0 10px rgba(45, 212, 191, 0.08); }
.platform-chip:hover { color: var(--tx-hi); border-color: var(--line-strong); }

.host-bar__actions { display: flex; gap: var(--sp-2); align-items: center; }

/* ============================================================
   SESSION / RBAC BAR
   ============================================================ */
.session-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  height: var(--sessionbar-h);
  padding: 0 var(--sp-4);
  background: rgba(8, 12, 20, 0.7);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line-hair);
  font-size: var(--fs-xs);
  color: var(--tx-mid);
}

.session-bar__identity, .session-bar__meta { display: flex; align-items: center; gap: var(--sp-3); min-width: 0; }

.status-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--tx-faint);
  flex: none;
}
.status-dot--locked { background: var(--acc-red); box-shadow: 0 0 8px rgba(244, 63, 94, 0.7); animation: pulse-dot 2.2s infinite; }
.status-dot--ok { background: var(--ok); box-shadow: 0 0 8px rgba(52, 211, 153, 0.7); }
@keyframes pulse-dot { 50% { opacity: 0.45; } }

.role-badge {
  padding: 2px 9px;
  border-radius: 999px;
  font-size: var(--fs-xxs);
  font-weight: 700;
  letter-spacing: 0.14em;
  border: 1px solid var(--line-soft);
}
.role-badge--none { color: var(--acc-red); border-color: rgba(244, 63, 94, 0.5); background: rgba(244, 63, 94, 0.1); }
.role-badge--operator { color: var(--acc-cyan); border-color: rgba(56, 189, 248, 0.5); background: rgba(56, 189, 248, 0.1); }
.role-badge--supervisor { color: var(--acc-amber); border-color: rgba(245, 165, 36, 0.5); background: rgba(245, 165, 36, 0.1); }
.role-badge--admin { color: var(--acc-violet); border-color: rgba(167, 139, 250, 0.5); background: rgba(167, 139, 250, 0.1); }

.meta-pill {
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--bg-inset);
  border: 1px solid var(--line-hair);
  font-family: var(--font-mono);
  font-size: var(--fs-xxs);
  color: var(--tx-low);
  white-space: nowrap;
}

/* ============================================================
   WORKSPACE GRID
   ============================================================ */
.workspace {
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr) 340px;
  gap: var(--sp-3);
  padding: var(--sp-3);
  height: calc(100vh - var(--hostbar-h) - var(--sessionbar-h));
  min-height: 0;
}

/* ============================================================
   RAILS (left fleet / right ops)
   ============================================================ */
.rail {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  min-height: 0;
  overflow: hidden;
}
.rail--ops { overflow-y: auto; padding-right: 2px; }

.rail__title, .panel__title {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--fs-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--tx-mid);
  padding-bottom: var(--sp-2);
  border-bottom: 1px solid var(--line-hair);
}
.rail__title svg, .panel__title svg { color: var(--acc-primary); }

.rail--fleet {
  background: var(--bg-panel);
  border: 1px solid var(--line-hair);
  border-radius: var(--r-lg);
  padding: var(--sp-3);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: var(--shadow-panel);
}

.rail__search input {
  width: 100%;
  padding: 8px 12px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line-soft);
  background: var(--bg-inset);
  font-size: var(--fs-xs);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.rail__search input::placeholder { color: var(--tx-faint); }
.rail__search input:focus { outline: none; border-color: var(--acc-primary); box-shadow: var(--glow-teal); }

.fleet-summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--sp-1);
  font-size: var(--fs-xxs);
  text-align: center;
}
.fleet-summary__cell {
  padding: 5px 2px;
  border-radius: var(--r-sm);
  background: var(--bg-inset);
  border: 1px solid var(--line-hair);
  color: var(--tx-low);
}
.fleet-summary__cell strong { display: block; font-family: var(--font-mono); font-size: var(--fs-sm); color: var(--tx-hi); }
.fleet-summary__cell--ok strong { color: var(--ok); }
.fleet-summary__cell--warn strong { color: var(--warn); }
.fleet-summary__cell--crit strong { color: var(--crit); }

.fleet-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 0;
}
.fleet-list__empty, .panel__empty {
  color: var(--tx-faint);
  font-size: var(--fs-xs);
  padding: var(--sp-3);
  text-align: center;
  border: 1px dashed var(--line-hair);
  border-radius: var(--r-sm);
}
.fleet-item {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 7px 9px;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  background: rgba(20, 30, 46, 0.4);
  cursor: pointer;
  transition: border-color 0.12s, background 0.12s;
}
.fleet-item:hover { border-color: var(--line-soft); background: var(--bg-raised); }
.fleet-item[aria-selected="true"], .fleet-item.is-selected {
  border-color: rgba(45, 212, 191, 0.55);
  background: var(--acc-primary-dim);
  box-shadow: inset 0 0 12px rgba(45, 212, 191, 0.07);
}
.fleet-item__dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.fleet-item__dot--nominal { background: var(--ok); box-shadow: 0 0 6px rgba(52, 211, 153, 0.6); }
.fleet-item__dot--warning { background: var(--warn); box-shadow: 0 0 6px rgba(245, 165, 36, 0.6); }
.fleet-item__dot--critical { background: var(--crit); box-shadow: 0 0 6px rgba(244, 63, 94, 0.7); animation: pulse-dot 1.4s infinite; }
.fleet-item__callsign { font-family: var(--font-mono); font-size: var(--fs-xs); color: var(--tx-hi); }
.fleet-item__type { margin-left: auto; font-size: var(--fs-xxs); color: var(--tx-low); text-transform: uppercase; letter-spacing: 0.06em; }

/* ============================================================
   CENTER VIEWPORT STACK
   ============================================================ */
.viewport-stack {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto auto;
  gap: var(--sp-3);
  min-height: 0;
  min-width: 0;
}

.viewport-frame {
  position: relative;
  border-radius: var(--r-lg);
  border: 1px solid var(--line-soft);
  overflow: hidden;
  background: var(--bg-canvas);
  box-shadow: var(--shadow-panel), inset 0 0 80px rgba(20, 60, 90, 0.18);
  min-height: 0;
}
.viewport-frame::before { /* corner reticle atmosphere */
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(rgba(45, 212, 191, 0.05), transparent 1px) 0 0 / 100% 48px,
    linear-gradient(90deg, rgba(45, 212, 191, 0.05), transparent 1px) 0 0 / 48px 100%;
  z-index: 1;
}

#twin-viewport {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

.viewport-hud {
  position: absolute;
  display: flex;
  gap: var(--sp-2);
  z-index: 3;
  pointer-events: none;
}
.viewport-hud > * { pointer-events: auto; }
.viewport-hud--tl { top: var(--sp-3); left: var(--sp-3); flex-wrap: wrap; }
.viewport-hud--tr { top: var(--sp-3); right: var(--sp-3); }
.viewport-hud--bl { bottom: var(--sp-3); left: var(--sp-3); align-items: center; }

.hud-toggle {
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--line-hair);
  background: rgba(10, 16, 26, 0.72);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  color: var(--tx-low);
  font-size: var(--fs-xxs);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition: all 0.15s;
}
.hud-toggle:hover { color: var(--tx-hi); border-color: var(--line-strong); }
.hud-toggle.is-active {
  color: var(--acc-primary);
  border-color: rgba(45, 212, 191, 0.5);
  background: rgba(45, 212, 191, 0.1);
  box-shadow: inset 0 0 10px rgba(45, 212, 191, 0.1);
}

.hud-mode {
  padding: 4px 12px;
  border-radius: 999px;
  font-size: var(--fs-xxs);
  font-weight: 800;
  letter-spacing: 0.14em;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}
.hud-mode--live { color: #7dffc9; background: rgba(52, 211, 153, 0.12); border: 1px solid rgba(52, 211, 153, 0.5); animation: pulse-dot 2s infinite; }
.hud-mode--replay { color: var(--acc-amber); background: rgba(245, 165, 36, 0.12); border: 1px solid rgba(245, 165, 36, 0.5); }
.hud-mode--paused { color: var(--acc-red); background: rgba(244, 63, 94, 0.12); border: 1px solid rgba(244, 63, 94, 0.5); }

.hud-clock {
  font-family: var(--font-mono);
  font-size: var(--fs-xxs);
  color: var(--tx-mid);
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(10, 16, 26, 0.72);
  border: 1px solid var(--line-hair);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.viewport-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 4;
  background: rgba(6, 9, 15, 0.7);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  color: var(--tx-mid);
  font-size: var(--fs-md);
}

/* ============================================================
   DVR TIMELINE BAR
   ============================================================ */
.dvr {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--sp-4);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-lg);
  border: 1px solid var(--line-soft);
  background: var(--bg-panel);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: var(--shadow-panel);
}

.dvr__transport { display: flex; align-items: center; gap: var(--sp-2); }

.dvr-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line-soft);
  background: var(--bg-raised);
  color: var(--tx-mid);
  font-size: var(--fs-xxs);
  font-weight: 700;
  letter-spacing: 0.06em;
  transition: all 0.15s;
}
.dvr-btn:hover { color: var(--tx-hi); border-color: var(--line-strong); }

.dvr-btn--live {
  color: #7dffc9;
  border-color: rgba(52, 211, 153, 0.5);
  background: rgba(52, 211, 153, 0.1);
}
.live-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 8px rgba(52, 211, 153, 0.8);
  animation: pulse-dot 1.8s infinite;
}
.dvr-btn--live.is-off { color: var(--tx-low); border-color: var(--line-hair); background: transparent; }
.dvr-btn--live.is-off .live-dot { background: var(--tx-faint); box-shadow: none; animation: none; }

.dvr-btn--play {
  width: 40px;
  justify-content: center;
  color: var(--acc-primary);
  border-color: rgba(45, 212, 191, 0.5);
  background: var(--acc-primary-dim);
}
.dvr-btn--play[aria-pressed="true"] { color: var(--acc-amber); border-color: rgba(245, 165, 36, 0.55); background: rgba(245, 165, 36, 0.12); }

.dvr__speed { display: flex; border: 1px solid var(--line-hair); border-radius: var(--r-sm); overflow: hidden; margin-left: var(--sp-2); }
.dvr-speed {
  padding: 7px 10px;
  background: transparent;
  border: none;
  border-right: 1px solid var(--line-hair);
  color: var(--tx-low);
  font-family: var(--font-mono);
  font-size: var(--fs-xxs);
  transition: all 0.12s;
}
.dvr-speed:last-child { border-right: none; }
.dvr-speed:hover { color: var(--tx-hi); }
.dvr-speed.is-active { color: var(--acc-cyan); background: rgba(56, 189, 248, 0.14); }

.dvr__scrub { position: relative; display: flex; align-items: center; min-width: 0; }
#dvr-event-track {
  position: absolute;
  inset: 0 0 auto 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  opacity: 0.85;
}

#dvr-scrubber {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 26px;
  background: transparent;
  position: relative;
  z-index: 2;
  cursor: ew-resize;
}
#dvr-scrubber::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(90deg, rgba(245, 165, 36, 0.35), rgba(45, 212, 191, 0.55));
  border: 1px solid var(--line-hair);
}
#dvr-scrubber::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 20px;
  margin-top: -8px;
  border-radius: 4px;
  background: linear-gradient(180deg, #b7fff3, var(--acc-primary));
  border: 1px solid rgba(45, 212, 191, 0.8);
  box-shadow: var(--glow-teal);
}
#dvr-scrubber::-moz-range-track {
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(90deg, rgba(245, 165, 36, 0.35), rgba(45, 212, 191, 0.55));
  border: 1px solid var(--line-hair);
}
#dvr-scrubber::-moz-range-thumb {
  width: 14px; height: 20px;
  border-radius: 4px;
  background: linear-gradient(180deg, #b7fff3, var(--acc-primary));
  border: 1px solid rgba(45, 212, 191, 0.8);
  box-shadow: var(--glow-teal);
}

.dvr__readout { display: flex; align-items: center; gap: var(--sp-3); }
.dvr-time {
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  font-weight: 700;
  color: var(--acc-primary);
  min-width: 96px;
  text-align: right;
}
.dvr-time.is-replay { color: var(--acc-amber); }
.dvr-window { font-size: var(--fs-xxs); color: var(--tx-faint); white-space: nowrap; }

/* ============================================================
   LIVE SENSOR CHART GRID
   ============================================================ */
.charts {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: var(--sp-3);
}

.chart-card {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  padding: var(--sp-3);
  border-radius: var(--r-md);
  border: 1px solid var(--line-hair);
  background: var(--bg-panel);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: var(--shadow-panel);
  min-width: 0;
  transition: border-color 0.2s;
}
.chart-card.is-alarm { border-color: rgba(244, 63, 94, 0.6); box-shadow: var(--shadow-panel), var(--glow-red); }

.chart-card__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-2);
}
.chart-card__head h3 {
  font-size: var(--fs-xxs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--tx-mid);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chart-unit { color: var(--tx-faint); font-weight: 400; margin-left: 3px; }
.chart-value {
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  font-weight: 700;
  color: var(--acc-primary);
  white-space: nowrap;
}
.chart-card.is-alarm .chart-value { color: var(--crit); }

.chart-canvas {
  width: 100%;
  height: 64px;
  border-radius: var(--r-sm);
  background: var(--bg-inset);
  border: 1px solid var(--line-hair);
}

/* ============================================================
   RIGHT PANELS — INSPECTOR / RULES / AUDIT
   ============================================================ */
.panel {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  padding: var(--sp-3);
  border-radius: var(--r-lg);
  border: 1px solid var(--line-hair);
  background: var(--bg-panel);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: var(--shadow-panel);
}

.panel__subtitle {
  font-size: var(--fs-xxs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--tx-low);
  padding-top: var(--sp-2);
  border-top: 1px solid var(--line-hair);
}

/* ---- Inspector ---- */
.inspector { display: flex; flex-direction: column; gap: var(--sp-3); }
.inspector__head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); }
.inspector__head h3 { font-family: var(--font-mono); font-size: var(--fs-lg); color: var(--tx-hi); }

.health-badge {
  padding: 3px 10px;
  border-radius: 999px;
  font-size: var(--fs-xxs);
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  border: 1px solid var(--line-soft);
  color: var(--tx-mid);
}
.health-badge--nominal { color: var(--ok); border-color: rgba(52, 211, 153, 0.5); background: rgba(52, 211, 153, 0.1); }
.health-badge--warning { color: var(--warn); border-color: rgba(245, 165, 36, 0.5); background: rgba(245, 165, 36, 0.1); }
.health-badge--critical { color: var(--crit); border-color: rgba(244, 63, 94, 0.55); background: rgba(244, 63, 94, 0.12); animation: pulse-dot 1.6s infinite; }

.inspector__grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-2);
  margin: 0;
}
.inspector__grid > div {
  padding: 6px 9px;
  border-radius: var(--r-sm);
  background: var(--bg-inset);
  border: 1px solid var(--line-hair);
}
.inspector__grid dt { font-size: var(--fs-xxs); text-transform: uppercase; letter-spacing: 0.1em; color: var(--tx-faint); }
.inspector__grid dd { margin: 2px 0 0; font-family: var(--font-mono); font-size: var(--fs-xs); color: var(--tx-hi); }

.inspector__health label { display: block; font-size: var(--fs-xxs); text-transform: uppercase; letter-spacing: 0.1em; color: var(--tx-low); margin-bottom: 5px; }
.inspector__health progress {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 10px;
  border-radius: 5px;
  overflow: hidden;
  border: 1px solid var(--line-hair);
  background: var(--bg-inset);
}
.inspector__health progress::-webkit-progress-bar { background: var(--bg-inset); }
.inspector__health progress::-webkit-progress-value {
  border-radius: 5px;
  background: linear-gradient(90deg, var(--acc-red), var(--acc-amber) 45%, var(--ok));
  transition: width 0.4s ease;
}
.inspector__health progress::-moz-progress-bar {
  border-radius: 5px;
  background: linear-gradient(90deg, var(--acc-red), var(--acc-amber) 45%, var(--ok));
}

.inspector__actions { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-2); }

/* ---- Alert rules form ---- */
.rule-form { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-2); }
.rule-form__row { display: flex; flex-direction: column; gap: 4px; }
.rule-form__row label { font-size: var(--fs-xxs); text-transform: uppercase; letter-spacing: 0.1em; color: var(--tx-low); }
.rule-form select, .rule-form input {
  padding: 7px 9px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line-soft);
  background: var(--bg-inset);
  font-size: var(--fs-xs);
  width: 100%;
}
.rule-form select:focus, .rule-form input:focus { outline: none; border-color: var(--acc-primary); box-shadow: var(--glow-teal); }
.rule-form .btn { grid-column: 1 / -1; }

.rules-list, .alerts-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-height: 160px;
  overflow-y: auto;
}
.rule-item, .alert-item {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 7px 9px;
  border-radius: var(--r-sm);
  background: var(--bg-inset);
  border: 1px solid var(--line-hair);
  font-family: var(--font-mono);
  font-size: var(--fs-xxs);
  color: var(--tx-mid);
}
.rule-item__sev, .alert-item__sev {
  padding: 1px 7px;
  border-radius: 999px;
  font-size: var(--fs-xxs);
  font-weight: 800;
  letter-spacing: 0.08em;
  flex: none;
}
.rule-item__sev--warning, .alert-item__sev--warning { color: var(--warn); background: rgba(245, 165, 36, 0.12); border: 1px solid rgba(245, 165, 36, 0.45); }
.rule-item__sev--critical, .alert-item__sev--critical { color: var(--crit); background: rgba(244, 63, 94, 0.12); border: 1px solid rgba(244, 63, 94, 0.5); }
.rule-item__delete {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--tx-faint);
  font-size: var(--fs-sm);
  padding: 0 4px;
}
.rule-item__delete:hover { color: var(--crit); }
.alert-item { border-color: rgba(244, 63, 94, 0.35); animation: alert-in 0.3s ease; }
@keyframes alert-in { from { opacity: 0; transform: translateY(-4px); } }

/* ---- Audit ledger ---- */
.panel--audit { flex: 1; min-height: 180px; }
.hash-chain-badge {
  margin-left: auto;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: var(--fs-xxs);
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--acc-violet);
  border: 1px solid rgba(167, 139, 250, 0.45);
  background: rgba(167, 139, 250, 0.1);
  text-transform: none;
}
.audit-log {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 0;
  font-family: var(--font-mono);
  font-size: var(--fs-xxs);
}
.audit-entry {
  padding: 6px 9px;
  border-radius: var(--r-sm);
  background: var(--bg-inset);
  border: 1px solid var(--line-hair);
  border-left: 2px solid var(--acc-violet);
  color: var(--tx-mid);
  line-height: 1.5;
  word-break: break-word;
}
.audit-entry__time { color: var(--tx-faint); margin-right: 6px; }
.audit-entry__actor { color: var(--acc-cyan); }
.audit-entry__cmd { color: var(--acc-amber); font-weight: 700; }
.audit-entry__hash { display: block; color: var(--tx-faint); font-size: 0.85em; margin-top: 2px; }
.audit-entry--denied { border-left-color: var(--crit); }
.audit-entry--denied .audit-entry__cmd { color: var(--crit); }

/* ============================================================
   MODALS
   ============================================================ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: var(--sp-4);
  background: rgba(4, 7, 12, 0.72);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  animation: fade-in 0.18s ease;
}
.modal-backdrop[hidden] { display: none; }
@keyframes fade-in { from { opacity: 0; } }

.modal {
  position: relative;
  width: min(440px, 100%);
  padding: var(--sp-5);
  border-radius: var(--r-lg);
  border: 1px solid var(--line-soft);
  background: linear-gradient(180deg, rgba(20, 30, 46, 0.92), rgba(12, 18, 28, 0.94));
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: var(--shadow-modal), inset 0 1px 0 rgba(160, 200, 255, 0.08);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  animation: modal-in 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
@keyframes modal-in { from { opacity: 0; transform: translateY(12px) scale(0.97); } }
.modal--narrow { width: min(360px, 100%); }

.modal h2 { font-size: var(--fs-lg); letter-spacing: 0.04em; }
.modal__lede { font-size: var(--fs-xs); color: var(--tx-mid); line-height: 1.55; }

.modal__divider {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  color: var(--tx-faint);
  font-size: var(--fs-xxs);
  text-transform: uppercase;
  letter-spacing: 0.12em;
}
.modal__divider::before, .modal__divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line-hair);
}

.modal__actions { display: flex; gap: var(--sp-2); justify-content: flex-end; }
.modal__close {
  position: absolute;
  top: var(--sp-3);
  right: var(--sp-3);
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 1px solid var(--line-hair);
  background: transparent;
  color: var(--tx-low);
  font-size: var(--fs-xs);
  transition: all 0.15s;
}
.modal__close:hover { color: var(--crit); border-color: rgba(244, 63, 94, 0.5); }

.auth-form { display: flex; flex-direction: column; gap: var(--sp-2); }
.auth-form label { font-size: var(--fs-xxs); text-transform: uppercase; letter-spacing: 0.1em; color: var(--tx-low); margin-top: var(--sp-1); }
.auth-form input, .auth-form select {
  padding: 9px 12px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line-soft);
  background: var(--bg-inset);
  font-size: var(--fs-sm);
}
.auth-form input:focus, .auth-form select:focus { outline: none; border-color: var(--acc-primary); box-shadow: var(--glow-teal); }
.auth-form .btn { margin-top: var(--sp-2); }

.auth-error {
  padding: 8px 12px;
  border-radius: var(--r-sm);
  border: 1px solid rgba(244, 63, 94, 0.5);
  background: rgba(244, 63, 94, 0.1);
  color: #ffd6de;
  font-size: var(--fs-xs);
}

.share-output { display: flex; flex-direction: column; gap: var(--sp-2); align-items: center; }
.share-output label { align-self: flex-start; font-size: var(--fs-xxs); text-transform: uppercase; letter-spacing: 0.1em; color: var(--tx-low); }
.share-output input {
  width: 100%;
  padding: 8px 11px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line-soft);
  background: var(--bg-inset);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--acc-cyan);
}
#share-qr {
  border-radius: var(--r-md);
  border: 1px solid var(--line-soft);
  background: #fff;
  padding: 6px;
}

/* ============================================================
   TOASTS
   ============================================================ */
.toast-region {
  position: fixed;
  bottom: var(--sp-5);
  right: var(--sp-5);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  max-width: 340px;
  pointer-events: none;
}
.toast {
  padding: 10px 14px;
  border-radius: var(--r-md);
  border: 1px solid var(--line-soft);
  background: rgba(16, 24, 38, 0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: var(--shadow-panel);
  font-size: var(--fs-xs);
  color: var(--tx-hi);
  border-left: 3px solid var(--acc-cyan);
  animation: toast-in 0.25s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
.toast--ok { border-left-color: var(--ok); }
.toast--warn { border-left-color: var(--warn); }
.toast--crit { border-left-color: var(--crit); box-shadow: var(--shadow-panel), var(--glow-red); }
@keyframes toast-in { from { opacity: 0; transform: translateX(24px); } }
.toast.is-leaving { opacity: 0; transform: translateX(24px); transition: all 0.25s; }

/* ============================================================
   RESPONSIVE — TABLET (≤ 1024px)
   ============================================================ */
@media (max-width: 1024px) {
  .workspace { grid-template-columns: 220px minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; height: auto; min-height: calc(100vh - var(--hostbar-h) - var(--sessionbar-h)); }
  .rail--ops { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: start; overflow: visible; }
  .charts { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .host-bar__targets { display: none; }
}

/* ============================================================
   RESPONSIVE — SMALL TABLET / FIELD (≤ 768px)
   ============================================================ */
@media (max-width: 768px) {
  .host-bar { flex-wrap: wrap; height: auto; padding: var(--sp-2) var(--sp-3); gap: var(--sp-2); }
  .host-bar__actions { margin-left: auto; }
  .host-bar__actions .btn { padding: 6px 10px; font-size: var(--fs-xxs); }
  #btn-share-view { display: none; }

  .session-bar { flex-wrap: wrap; height: auto; padding: var(--sp-2) var(--sp-3); gap: var(--sp-2); }
  .session-bar__meta { flex-wrap: wrap; }

  .workspace { grid-template-columns: 1fr; grid-template-rows: none; padding: var(--sp-2); }
  .rail--fleet { max-height: 240px; }
  .rail--ops { grid-template-columns: 1fr; }
  .viewport-frame { min-height: 320px; }
  .charts { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  .dvr { grid-template-columns: 1fr; gap: var(--sp-2); }
  .dvr__transport { flex-wrap: wrap; justify-content: center; }
  .dvr__readout { justify-content: space-between; }
  .dvr-window { display: none; }
}

/* ============================================================
   RESPONSIVE — MOBILE HANDSET (≤ 480px)
   ============================================================ */
@media (max-width: 480px) {
  .brand-sub { display: none; }
  .host-bar__actions .btn span, #btn-launch-desktop { font-size: 0; gap: 0; }
  #btn-launch-desktop svg, #btn-export-seed svg { margin: 0; }
  .meta-pill { font-size: 0.58rem; padding: 2px 7px; }

  .charts { grid-template-columns: 1fr; }
  .inspector__grid { grid-template-columns: 1fr; }
  .inspector__actions { grid-template-columns: 1fr; }
  .rule-form { grid-template-columns: 1fr; }

  .viewport-hud--tl { max-width: 60%; }
  .hud-toggle { padding: 4px 8px; font-size: 0.56rem; }
  .viewport-frame { min-height: 260px; }

  .dvr__speed { margin-left: 0; }
  .dvr-btn { padding: 6px 9px; }
  .dvr-time { min-width: 0; font-size: var(--fs-xs); }

  .modal { padding: var(--sp-4); }
  .toast-region { left: var(--sp-3); right: var(--sp-3); bottom: var(--sp-3); max-width: none; }
  .fleet-summary { grid-template-columns: repeat(2, 1fr); }
}

/* ============================================================
   REDUCED MOTION
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
main > section:nth-of-type(n+2), .silvae-section:nth-of-type(n+2) { content-visibility: auto; contain-intrinsic-size: auto 480px; }
:where(a:any-link, button, input, select, textarea, [role="button"]):focus-visible { outline: 2px solid var(--primary, #38bdf8); outline-offset: 2px; }
.visually-hidden:where(:not(:focus-within, :active)) { position: absolute !important; clip-path: inset(50%) !important; overflow: hidden !important; width: 1px !important; height: 1px !important; margin: -1px !important; padding: 0 !important; border: 0 !important; white-space: nowrap !important; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; } }