/* =============================================================================
   OE5XRX Station Manager — Operator's Console
   A radio-ops aesthetic: dark, marine, cyan-accented, typography-led.
   ============================================================================= */

/* ---------- Reset-ish ---------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { height: 100%; scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }

body {
  min-height: 100%;
  background: var(--bg-0);
  color: var(--ink-0);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  font-feature-settings: "cv11", "ss01", "ss03";
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Page atmosphere: subtle radial glow + faint grid */
body::before {
  content: "";
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(1200px 600px at 85% -10%, var(--accent-tint), transparent 60%),
    radial-gradient(900px 500px at -5% 110%, color-mix(in srgb, var(--cyan) 5%, transparent), transparent 60%);
}
body::after {
  content: "";
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    linear-gradient(to right, color-mix(in srgb, var(--sheen-color) 1.5%, transparent) 1px, transparent 1px),
    linear-gradient(to bottom, color-mix(in srgb, var(--sheen-color) 1.5%, transparent) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse at center, var(--shadow-color) 30%, transparent 85%);
}
:root[data-theme="light"] body::before,
:root[data-theme="light"] body::after { display: none; }

/* Focus */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

/* Selection */
::selection { background: var(--accent); color: var(--on-accent-ink); }

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--line-bright) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--line-bright);
  border: 2px solid transparent;
  background-clip: padding-box;
  border-radius: 10px;
}
*::-webkit-scrollbar-thumb:hover { background: var(--line-hot); background-clip: padding-box; }

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-soft); }

hr { border: none; border-top: 1px solid var(--line); margin: 20px 0; }

img { max-width: 100%; display: block; }

/* ---------- Typography utilities ----------------------------------------- */
.t-display {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.05;
}
.t-display-xl { font-family: var(--font-display); font-weight: 600; font-size: 44px; letter-spacing: -0.03em; line-height: 1.02; }
.t-display-lg { font-family: var(--font-display); font-weight: 600; font-size: 32px; letter-spacing: -0.025em; line-height: 1.06; }
.t-display-md { font-family: var(--font-display); font-weight: 600; font-size: 22px; letter-spacing: -0.02em; }
.t-mono { font-family: var(--font-mono); }
.t-mono-sm { font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.02em; }
.t-label {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-2);
  font-weight: 600;
}
.t-num { font-variant-numeric: tabular-nums; }
.t-muted { color: var(--ink-2); }
.t-dim { color: var(--ink-1); }
.t-accent { color: var(--accent); }
.t-signal { color: var(--signal); }
.t-danger { color: var(--danger); }
.t-warn { color: var(--warn); }
.t-cyan { color: var(--cyan); }

h1 { font-family: var(--font-display); font-weight: 600; font-size: 26px; letter-spacing: -0.02em; margin: 0; }
h2 { font-family: var(--font-display); font-weight: 600; font-size: 20px; letter-spacing: -0.015em; margin: 0; }
h3 { font-family: var(--font-display); font-weight: 600; font-size: 16px; letter-spacing: -0.01em; margin: 0; }
h4 { font-family: var(--font-body); font-weight: 600; font-size: 14px; margin: 0; }

/* ---------- App shell ---------------------------------------------------- */
.app-shell {
  display: grid;
  grid-template-columns: var(--rail-w) var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas:
    "rail sidebar topbar"
    "rail sidebar main";
  min-height: 100vh;
  position: relative;
  z-index: 1;
}

/* Vertical rack label */
.rail {
  grid-area: rail;
  background: var(--bg-1);
  border-right: 1px solid var(--line);
  position: relative;
  overflow: hidden;
}
.rail-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-90deg);
  white-space: nowrap;
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.4em;
  text-transform: uppercase;
  color: var(--ink-3);
  user-select: none;
}
.rail::before, .rail::after {
  content: "";
  position: absolute; left: 50%; transform: translateX(-50%);
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--line-bright);
  box-shadow: 0 0 0 2px var(--bg-1), 0 0 0 3px var(--line);
}
.rail::before { top: 14px; }
.rail::after { bottom: 14px; background: var(--accent); box-shadow: 0 0 0 2px var(--bg-1), 0 0 0 3px var(--line), 0 0 10px 2px var(--accent-glow); }

/* Sidebar */
.sidebar {
  grid-area: sidebar;
  background: var(--bg-1);
  border-right: 1px solid var(--line);
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.sidebar-brand {
  padding: 16px 18px 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-mark {
  width: 30px; height: 30px;
  display: grid; place-items: center;
  color: var(--accent);
  flex-shrink: 0;
}
.brand-mark svg { width: 100%; height: 100%; display: block; }
.brand-text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.brand-callsign {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
  color: var(--ink-0);
  line-height: 1;
}
.brand-sub {
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-2);
  line-height: 1;
}

.nav-section { padding: 14px 10px 2px; }
.nav-section-label {
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-3);
  padding: 6px 10px 6px;
  display: flex; align-items: center; gap: 8px;
}
.nav-section-label::after {
  content: ""; flex: 1; height: 1px; background: var(--line);
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--ink-1);
  font-size: 13.5px;
  font-weight: 600;
  margin: 1px 0;
  position: relative;
  transition: color 0.15s var(--ease), background 0.15s var(--ease);
}
.nav-item:hover { color: var(--ink-0); background: var(--bg-3); }
.nav-item .icon { width: 16px; height: 16px; flex-shrink: 0; opacity: 0.85; }
.nav-item .label { flex: 1; }
.nav-item .nav-tag {
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 3px;
  background: var(--bg-3);
  color: var(--ink-2);
  letter-spacing: 0.04em;
}
.nav-item[aria-current="page"],
.nav-item.active {
  color: var(--ink-0);
  background: var(--bg-3);
}
.nav-item[aria-current="page"]::before,
.nav-item.active::before {
  content: "";
  position: absolute;
  left: -10px; top: 14%; bottom: 14%;
  width: 2px;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
  box-shadow: 0 0 8px var(--accent-glow);
}
.nav-item[aria-current="page"] .icon,
.nav-item.active .icon { color: var(--accent); opacity: 1; }

.sidebar-footer {
  margin-top: auto;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
  display: flex; align-items: center; gap: 10px;
}
.sb-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: linear-gradient(135deg, var(--cyan), var(--violet));
  display: grid; place-items: center;
  font-family: var(--font-mono); font-weight: 700; font-size: 11px;
  color: var(--on-accent-ink);
}
.sb-user { flex: 1; min-width: 0; }
.sb-user-name {
  font-size: 12.5px; font-weight: 600; color: var(--ink-0);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sb-user-role {
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-2);
}

/* Topbar */
.topbar {
  grid-area: topbar;
  background: var(--bg-0);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 22px;
  position: sticky; top: 0; z-index: 30;
  backdrop-filter: blur(8px);
  background: color-mix(in oklab, var(--bg-0) 85%, transparent);
}
.topbar-crumbs {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  letter-spacing: 0.06em;
  color: var(--ink-2);
  flex: 1;
  min-width: 0;
}
.topbar-crumbs a { color: var(--ink-2); }
.topbar-crumbs a:hover { color: var(--ink-0); }
.topbar-crumbs .sep { color: var(--ink-3); }
.topbar-crumbs .cur { color: var(--ink-0); }

.waveform {
  width: 80px; height: 22px;
  display: inline-block;
  opacity: 0.9;
}
.wavebar {
  animation: wave 1.6s ease-in-out infinite;
  transform-origin: center;
}
.wavebar:nth-child(1) { animation-delay: 0s; }
.wavebar:nth-child(2) { animation-delay: 0.1s; }
.wavebar:nth-child(3) { animation-delay: 0.2s; }
.wavebar:nth-child(4) { animation-delay: 0.3s; }
.wavebar:nth-child(5) { animation-delay: 0.4s; }
.wavebar:nth-child(6) { animation-delay: 0.5s; }
.wavebar:nth-child(7) { animation-delay: 0.6s; }
.wavebar:nth-child(8) { animation-delay: 0.7s; }
@keyframes wave {
  0%, 100% { transform: scaleY(0.3); }
  50% { transform: scaleY(1); }
}

.topbar-clock {
  font-family: var(--font-mono);
  font-size: 11.5px;
  letter-spacing: 0.08em;
  color: var(--ink-1);
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-1);
}
.topbar-clock .utc { color: var(--ink-3); margin-right: 6px; }

/* Main */
.main {
  grid-area: main;
  padding: 26px 32px 80px;
  min-width: 0;
  position: relative;
}
.main-inner { max-width: 1600px; margin: 0 auto; }

/* Page header */
.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin-bottom: 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
}
.page-head-main { min-width: 0; }
.page-eyebrow {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-2);
  margin-bottom: 6px;
  display: flex; align-items: center; gap: 8px;
}
.page-eyebrow::after {
  content: ""; flex: 0 0 24px; height: 1px; background: var(--line-bright);
}
.page-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 30px;
  letter-spacing: -0.025em;
  line-height: 1.05;
  margin: 0 0 6px;
  color: var(--ink-0);
}
.page-sub {
  color: var(--ink-2);
  font-size: 13.5px;
  max-width: 720px;
}
.page-head-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

/* ---------- Cards / Panels ----------------------------------------------- */
.panel {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  position: relative;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 18px;
  border-bottom: 1px solid var(--line);
  gap: 12px;
}
.panel-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 14.5px;
  letter-spacing: -0.005em;
  color: var(--ink-0);
  display: flex; align-items: center; gap: 10px;
}
.panel-title .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
}
.panel-body { padding: 18px; }
.panel-body.flush { padding: 0; }
.panel-foot {
  padding: 12px 18px;
  border-top: 1px solid var(--line);
  color: var(--ink-2);
  font-size: 12.5px;
}

/* Hero panel variant (for landing/dashboard) */
.panel-hero {
  background:
    radial-gradient(600px 200px at 90% 20%, var(--accent-tint), transparent 70%),
    linear-gradient(180deg, var(--bg-2) 0%, var(--bg-1) 100%);
  border: 1px solid var(--line-bright);
  overflow: hidden;
}
.panel-hero::before {
  /* subtle scanlines */
  content: "";
  position: absolute; inset: 0;
  pointer-events: none;
  background-image: repeating-linear-gradient(
    0deg, transparent 0, transparent 3px,
    color-mix(in srgb, var(--sheen-color) 1.2%, transparent) 3px, color-mix(in srgb, var(--sheen-color) 1.2%, transparent) 4px
  );
  opacity: 0.5;
}

/* ---------- KPI / stat card --------------------------------------------- */
.stat {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  display: flex; flex-direction: column; gap: 6px;
  position: relative;
  overflow: hidden;
  transition: border-color 0.18s var(--ease), transform 0.18s var(--ease);
}
.stat:hover { border-color: var(--line-bright); transform: translateY(-1px); }
.stat::after {
  content: "";
  position: absolute; inset: 0;
  background: linear-gradient(135deg, var(--accent-tint), transparent 40%);
  opacity: 0; transition: opacity 0.2s var(--ease);
  pointer-events: none;
}
.stat:hover::after { opacity: 1; }
.stat-label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-2);
  display: flex; align-items: center; gap: 8px;
}
.stat-value {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 30px;
  letter-spacing: -0.03em;
  color: var(--ink-0);
  font-variant-numeric: tabular-nums;
  line-height: 1;
  margin-top: 6px;
}
.stat-value.with-unit { display: flex; align-items: baseline; gap: 6px; }
.stat-unit {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-2);
  font-weight: 400;
  letter-spacing: 0.04em;
}
.stat-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-2);
  letter-spacing: 0.04em;
  margin-top: 4px;
  display: flex; align-items: center; gap: 6px;
}
.stat-accent { color: var(--accent); }
.stat-ok { color: var(--signal); }
.stat-warn { color: var(--warn); }
.stat-danger { color: var(--danger); }

/* Grid helpers */
.grid { display: grid; gap: 14px; }
.grid-kpi { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-main { grid-template-columns: 2fr 1fr; }
@media (max-width: 980px) {
  .grid-cols-2, .grid-cols-3, .grid-main { grid-template-columns: 1fr; }
}

/* ---------- Badges / pills ---------------------------------------------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 600;
  background: var(--bg-3);
  color: var(--ink-1);
  border: 1px solid var(--line);
  white-space: nowrap;
  line-height: 1.4;
}
.pill .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: currentColor;
}
.pill-online   { background: var(--signal-soft);  color: var(--signal);  border-color: color-mix(in srgb, var(--signal) 30%, transparent); }
.pill-offline  { background: var(--danger-soft);  color: var(--danger);  border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
.pill-updating { background: var(--cyan-soft);    color: var(--cyan);    border-color: color-mix(in srgb, var(--cyan) 30%, transparent); }
.pill-error    { background: var(--danger-soft);  color: var(--danger);  border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
.pill-warn     { background: var(--warn-soft);    color: var(--warn);    border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.pill-accent   { background: var(--accent-tint);  color: var(--accent);  border-color: color-mix(in srgb, var(--accent) 35%, transparent); }
.pill-violet   { background: var(--violet-soft);  color: var(--violet);  border-color: color-mix(in srgb, var(--violet) 30%, transparent); }
.pill-muted    { background: var(--bg-3);         color: var(--ink-2); }

/* Deployment / job statuses */
.pill-pending     { background: var(--bg-3);       color: var(--ink-1);  border-color: var(--line); }
.pill-in-progress { background: var(--cyan-soft);  color: var(--cyan);   border-color: color-mix(in srgb, var(--cyan) 30%, transparent); }
.pill-completed   { background: var(--signal-soft); color: var(--signal); border-color: color-mix(in srgb, var(--signal) 30%, transparent); }
.pill-success     { background: var(--signal-soft); color: var(--signal); border-color: color-mix(in srgb, var(--signal) 30%, transparent); }
.pill-failed      { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
.pill-cancelled   { background: var(--bg-3);       color: var(--ink-2);  border-color: var(--line); }
.pill-superseded  { background: var(--bg-3);       color: var(--ink-2);  border-color: var(--line); }
.pill-building    { background: var(--cyan-soft);  color: var(--cyan);   border-color: color-mix(in srgb, var(--cyan) 30%, transparent); }
.pill-downloading { background: var(--cyan-soft);  color: var(--cyan); }
.pill-installing  { background: var(--accent-tint);color: var(--accent); }
.pill-rebooting   { background: var(--warn-soft);  color: var(--warn); }
.pill-verifying   { background: var(--cyan-soft);  color: var(--cyan); }
.pill-rolled-back { background: var(--warn-soft);  color: var(--warn); }
.pill-rolled_back { background: var(--warn-soft);  color: var(--warn); }
.pill-in_progress { background: var(--cyan-soft);  color: var(--cyan);   border-color: color-mix(in srgb, var(--cyan) 30%, transparent); }

/* Station drain banner (module firmware update pending). Same cyan "in transit"
   channel as .pill-updating; shared by station detail and the control panel. */
.fw-drain-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  margin-bottom: 20px;
  border-radius: var(--radius-md);
  border: 1px solid color-mix(in srgb, var(--cyan) 35%, transparent);
  background: var(--cyan-soft);
  color: var(--cyan);
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.04em;
}
.fw-drain-banner .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

/* Dashboard firmware-update rows: same rhythm as the deployment rows; a module
   stuck in DFU mode gets a warn edge because it needs a hands-on power-cycle. */
.fw-dash-row {
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
}
.fw-dash-row:last-child { border-bottom: 0; }
.fw-dash-row[data-fw-dfu-stuck] { box-shadow: inset 3px 0 0 var(--warn); }

/* Live dot for online pill */
.pill-online .dot {
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--signal) 60%, transparent);
  animation: pulse-dot 1.8s ease-in-out infinite;
}
@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--signal) 60%, transparent); }
  50% { box-shadow: 0 0 0 5px color-mix(in srgb, var(--signal) 0%, transparent); }
}

.tag {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.04em;
  background: var(--bg-3);
  color: var(--ink-1);
  border: 1px solid var(--line);
}
.tag::before {
  content: ""; width: 6px; height: 6px; border-radius: 2px; background: var(--tag-color, var(--accent));
}

/* ---------- Buttons ------------------------------------------------------ */
.btn {
  --btn-bg: var(--bg-2);
  --btn-fg: var(--ink-0);
  --btn-border: var(--line-bright);
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: -0.005em;
  cursor: pointer;
  background: var(--btn-bg);
  color: var(--btn-fg);
  border: 1px solid var(--btn-border);
  line-height: 1.3;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease), transform 0.08s var(--ease);
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: var(--bg-3); border-color: var(--line-hot); color: var(--ink-0); }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn.is-disabled { opacity: 0.5; cursor: not-allowed; }
.btn .icon { width: 14px; height: 14px; }

.btn-primary {
  --btn-bg: var(--accent);
  --btn-fg: var(--on-accent-ink);
  --btn-border: var(--accent);
  font-weight: 600;
  box-shadow: 0 0 0 0 var(--accent-glow);
  transition: box-shadow 0.2s var(--ease), background 0.15s var(--ease), transform 0.08s var(--ease);
}
.btn-primary:hover {
  background: var(--accent-soft);
  border-color: var(--accent-soft);
  --btn-fg: var(--on-accent-ink);
  box-shadow: 0 0 28px -4px var(--accent-glow);
  color: var(--on-accent-ink);
}

.btn-ghost {
  --btn-bg: transparent;
  --btn-border: var(--line);
}
.btn-danger {
  --btn-bg: transparent;
  --btn-fg: var(--danger);
  --btn-border: color-mix(in srgb, var(--danger) 35%, transparent);
}
.btn-danger:hover { background: var(--danger-soft); color: var(--danger); }

.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-lg { padding: 10px 18px; font-size: 14.5px; }
.btn-icon { padding: 7px; aspect-ratio: 1; justify-content: center; }
.btn-block { display: flex; width: 100%; justify-content: center; }

/* Button group (segmented) */
.btn-group {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg-2);
}
.btn-group .btn {
  border: none;
  border-right: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
}
.btn-group .btn:last-child { border-right: none; }
.btn-group .btn.active { background: var(--bg-3); color: var(--accent); }

/* ---------- Forms -------------------------------------------------------- */
.form-group { margin-bottom: 16px; }
.form-group label, label.form-label {
  display: block;
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-2);
  margin-bottom: 6px;
  font-weight: 600;
}
.form-control, .form-select,
input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="search"], input[type="url"],
input[type="date"], input[type="time"], input[type="datetime-local"],
input[type="tel"], textarea, select {
  width: 100%;
  padding: 9px 12px;
  font-family: var(--font-body);
  font-size: 13.5px;
  color: var(--ink-0);
  background: var(--bg-0);
  border: 1px solid var(--line-bright);
  border-radius: var(--radius-sm);
  line-height: 1.4;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.form-control::placeholder, input::placeholder, textarea::placeholder { color: var(--ink-3); }
.form-control:focus, .form-select:focus,
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-tint);
}
textarea { resize: vertical; min-height: 90px; font-family: var(--font-body); }

.form-control[readonly] { background: var(--bg-2); color: var(--ink-1); }
input[type="color"].form-control-color { padding: 3px; min-height: 36px; cursor: pointer; }

.form-select, select {
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-2) 50%),
                    linear-gradient(-45deg, transparent 50%, var(--ink-2) 50%);
  background-position: calc(100% - 14px) 16px, calc(100% - 9px) 16px;
  background-size: 5px 5px;
  background-repeat: no-repeat;
  appearance: none;
  padding-right: 30px;
}
.form-select:focus { background-image: linear-gradient(45deg, transparent 50%, var(--accent) 50%), linear-gradient(-45deg, transparent 50%, var(--accent) 50%); }

.form-check-input, input[type="checkbox"], input[type="radio"] {
  width: 16px; height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
  vertical-align: middle;
}

.form-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
@media (max-width: 720px) { .form-row { grid-template-columns: 1fr; } }

.form-help, .helptext { display: block; font-size: 11.5px; color: var(--ink-2); margin-top: 5px; }
.form-error, .errorlist {
  color: var(--danger); font-size: 12px; margin-top: 5px;
  list-style: none; padding: 0; margin: 5px 0 0;
}
.errorlist li { margin: 0; }

/* Checkbox multi-select (tags, modules) */
ul[multiple], ul.checkbox-list { list-style: none; padding: 0; margin: 0;
  display: flex; flex-wrap: wrap; gap: 6px;
}
input[type="checkbox"] + label, label + input[type="checkbox"] { display: inline; }

/* Django renders CheckboxSelectMultiple as <ul><li><label><input></label></li></ul> */
.form-group ul { list-style: none; padding: 0; margin: 0;
  display: flex; flex-wrap: wrap; gap: 6px;
}
.form-group ul li { margin: 0; }
.form-group ul li label {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-2);
  color: var(--ink-1);
  font-family: var(--font-mono); font-size: 11.5px;
  cursor: pointer;
  text-transform: none; letter-spacing: 0;
  font-weight: 400;
  transition: border-color 0.15s var(--ease), color 0.15s var(--ease);
  margin: 0;
}
.form-group ul li label:hover { border-color: var(--line-hot); color: var(--ink-0); }
.form-group ul li input[type="checkbox"]:checked + span,
.form-group ul li label:has(input:checked) { color: var(--accent); border-color: var(--accent); background: var(--accent-tint); }

/* ---------- Table -------------------------------------------------------- */
.table-wrap { border-radius: var(--radius-md); overflow: hidden; border: 1px solid var(--line); background: var(--bg-1); }
.t-table { width: 100%; border-collapse: collapse; }
.t-table thead th {
  text-align: left;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-2);
  font-weight: 600;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-2);
  white-space: nowrap;
}
.t-table tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  color: var(--ink-1);
  vertical-align: middle;
}
.t-table tbody tr:last-child td { border-bottom: none; }
.t-table tbody tr { transition: background 0.12s var(--ease); }
.t-table tbody tr:hover { background: var(--bg-2); }
.t-table tbody tr:hover td { color: var(--ink-0); }
.t-table tbody tr.is-clickable { cursor: pointer; }
.t-table td.t-mono, .t-table td .t-mono { font-family: var(--font-mono); font-size: 12px; }
.t-table td.num { font-variant-numeric: tabular-nums; text-align: right; }
.t-table td.actions { text-align: right; white-space: nowrap; }

/* ---------- Empty / loading ---------------------------------------------- */
.empty {
  padding: 48px 24px;
  text-align: center;
  color: var(--ink-2);
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.empty-icon {
  width: 44px; height: 44px; border-radius: 50%;
  border: 1px dashed var(--line-bright);
  display: grid; place-items: center;
  color: var(--ink-3);
}
.empty-title { font-family: var(--font-display); font-weight: 600; font-size: 15px; color: var(--ink-1); }
.skeleton { background: linear-gradient(90deg, var(--bg-2) 0%, var(--bg-3) 50%, var(--bg-2) 100%); background-size: 200% 100%; animation: skeleton 1.6s infinite; border-radius: var(--radius-sm); }
@keyframes skeleton { 0%{background-position:200% 0} 100%{background-position:-200% 0} }

/* ---------- Progress bar ------------------------------------------------- */
.progress {
  height: 6px;
  background: var(--bg-3);
  border-radius: 100px;
  overflow: hidden;
  position: relative;
}
.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-deep), var(--accent));
  transition: width 0.4s var(--ease);
  border-radius: 100px;
  box-shadow: 0 0 12px var(--accent-glow);
}
.progress-bar.ok { background: linear-gradient(90deg, color-mix(in srgb, var(--signal) 70%, var(--shadow-color)), var(--signal)); box-shadow: 0 0 12px color-mix(in srgb, var(--signal) 35%, transparent); }
.progress-bar.warn { background: linear-gradient(90deg, color-mix(in srgb, var(--warn) 70%, var(--shadow-color)), var(--warn)); }
.progress-bar.danger { background: linear-gradient(90deg, color-mix(in srgb, var(--danger) 70%, var(--shadow-color)), var(--danger)); }

/* Stepped progress (used on deployment detail) */
.prog-steps { display: flex; gap: 3px; align-items: center; }
.prog-step {
  flex: 1; height: 6px; border-radius: 2px; background: var(--bg-3);
}
.prog-step.ok { background: var(--signal); }
.prog-step.fail { background: var(--danger); }
.prog-step.cur { background: var(--accent); box-shadow: 0 0 6px var(--accent-glow); }

/* ---------- Tabs --------------------------------------------------------- */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--line);
  margin-bottom: 22px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
  background: none;
  border-top: none; border-left: none; border-right: none;
  font-family: var(--font-body);
  white-space: nowrap;
  display: inline-flex; align-items: center; gap: 8px;
  transition: color 0.15s var(--ease), border-color 0.15s var(--ease);
}
.tab:hover { color: var(--ink-0); }
.tab.active, .tab[aria-selected="true"] {
  color: var(--ink-0);
  border-bottom-color: var(--accent);
}
.tab .count {
  font-family: var(--font-mono); font-size: 10.5px;
  padding: 1px 6px; border-radius: 3px;
  background: var(--bg-3); color: var(--ink-2);
}
.tab.active .count, .tab[aria-selected="true"] .count { color: var(--accent); background: var(--accent-tint); }

/* ---------- Messages ----------------------------------------------------- */
.flash-stack {
  position: fixed;
  top: calc(var(--topbar-h) + 14px);
  right: 22px;
  z-index: 100;
  display: flex; flex-direction: column; gap: 8px;
  max-width: 420px;
}
.flash {
  background: var(--bg-2);
  border: 1px solid var(--line-bright);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  color: var(--ink-0);
  box-shadow: var(--shadow-md);
  display: flex; align-items: flex-start; gap: 10px;
  animation: flash-in 0.4s var(--ease-out);
}
.flash.success { border-left-color: var(--signal); }
.flash.error, .flash.danger { border-left-color: var(--danger); }
.flash.warning { border-left-color: var(--warn); }
.flash.info { border-left-color: var(--cyan); }
.flash-close { margin-left: auto; background: none; border: none; color: var(--ink-2); cursor: pointer; padding: 0; font-size: 16px; line-height: 1; }
@keyframes flash-in { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Misc layout helpers ------------------------------------------ */
.row-split { display: flex; justify-content: space-between; align-items: center; gap: 14px; }
.row-gap-8 { display: flex; gap: 8px; align-items: center; }
.row-gap-12 { display: flex; gap: 12px; align-items: center; }
.stack { display: flex; flex-direction: column; }
.stack-gap-2 { display: flex; flex-direction: column; gap: 2px; }
.stack-gap-6 { display: flex; flex-direction: column; gap: 6px; }
.stack-gap-10 { display: flex; flex-direction: column; gap: 10px; }
.stack-gap-14 { display: flex; flex-direction: column; gap: 14px; }
.stack-gap-20 { display: flex; flex-direction: column; gap: 20px; }
.mt-10 { margin-top: 10px; }
.mt-14 { margin-top: 14px; }
.mt-20 { margin-top: 20px; }
.mt-24 { margin-top: 24px; }
.mb-10 { margin-bottom: 10px; }
.mb-14 { margin-bottom: 14px; }
.mb-20 { margin-bottom: 20px; }
.mb-24 { margin-bottom: 24px; }
.center { display: flex; align-items: center; justify-content: center; }

.divider { height: 1px; background: var(--line); margin: 14px 0; }

/* Callsign / ID display */
.callsign {
  font-family: var(--font-mono);
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--accent);
}
.frame-id {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-2);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.frame-id::before { content: "FR/"; color: var(--ink-3); }

/* Coordinate readout */
.coord {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-1);
  letter-spacing: 0.03em;
}
.coord .axis { color: var(--ink-3); margin-right: 4px; }

/* Code block (tokens) */
.codebox {
  background: var(--bg-0);
  border: 1px solid var(--line-bright);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-0);
  word-break: break-all;
  position: relative;
  line-height: 1.6;
}
.codebox.sensitive {
  border-color: var(--accent);
  background: linear-gradient(180deg, var(--accent-tint), transparent 50%), var(--bg-0);
}
.copy-btn {
  position: absolute; top: 8px; right: 8px;
  background: var(--bg-2); border: 1px solid var(--line-bright);
  color: var(--ink-1); padding: 3px 8px; border-radius: var(--radius-xs);
  font-family: var(--font-mono); font-size: 10px; letter-spacing: 0.1em;
  cursor: pointer;
}
.copy-btn:hover { color: var(--accent); border-color: var(--accent); }
.copy-btn.copied { color: var(--signal); border-color: var(--signal); }

/* ---------- Filter bar --------------------------------------------------- */
.filter-bar {
  display: flex; flex-wrap: wrap; align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  margin-bottom: 16px;
}
.filter-bar .search {
  flex: 1; min-width: 220px;
  position: relative;
}
.filter-bar .search input { padding-left: 36px; }
.filter-bar .search::before {
  content: "";
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  width: 14px; height: 14px;
  background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20' stroke='%237E8899' stroke-width='2'><circle cx='9' cy='9' r='6'/><path d='M14 14l4 4'/></svg>") center/contain no-repeat;
  pointer-events: none;
}

/* ---------- Login page --------------------------------------------------- */
.auth-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1.1fr;
  background: var(--bg-0);
  position: relative;
  overflow: hidden;
}
@media (max-width: 900px) { .auth-shell { grid-template-columns: 1fr; } }
.auth-shell::before {
  content: "";
  position: fixed; inset: 0; pointer-events: none;
  background:
    radial-gradient(800px 500px at 80% 20%, var(--accent-tint), transparent 60%),
    radial-gradient(600px 400px at 20% 80%, color-mix(in srgb, var(--cyan) 6%, transparent), transparent 65%);
}
.auth-panel {
  padding: 60px 72px;
  display: flex; flex-direction: column; justify-content: center;
  gap: 26px;
  background: var(--bg-1);
  border-right: 1px solid var(--line);
  position: relative;
  z-index: 1;
}
@media (max-width: 640px) { .auth-panel { padding: 40px 28px; } }
.auth-side {
  padding: 60px 60px;
  display: flex; flex-direction: column; justify-content: space-between;
  position: relative; z-index: 1;
  overflow: hidden;
}
.auth-side::before {
  content: "";
  position: absolute; inset: 0;
  background-image:
    linear-gradient(to right, color-mix(in srgb, var(--sheen-color) 2%, transparent) 1px, transparent 1px),
    linear-gradient(to bottom, color-mix(in srgb, var(--sheen-color) 2%, transparent) 1px, transparent 1px);
  background-size: 32px 32px;
  mask-image: radial-gradient(ellipse at 70% 40%, var(--shadow-color) 30%, transparent 80%);
}
@media (max-width: 900px) { .auth-side { display: none; } }
.auth-brand {
  display: flex; align-items: center; gap: 12px;
}
.auth-brand .brand-mark { width: 40px; height: 40px; }
.auth-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 42px;
  letter-spacing: -0.03em;
  color: var(--ink-0);
  line-height: 1.05;
  margin: 0;
}
.auth-title em { font-style: normal; color: var(--accent); }
.auth-sub { color: var(--ink-1); font-size: 14.5px; max-width: 440px; }

.auth-side-big {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 88px;
  letter-spacing: -0.04em;
  line-height: 0.92;
  color: var(--ink-0);
  position: relative; z-index: 1;
}
.auth-side-big em { font-style: normal; color: var(--accent); }
.auth-side-big small {
  display: block;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 400;
  color: var(--ink-2);
  letter-spacing: 0.24em;
  text-transform: uppercase;
  margin-top: 16px;
}
.auth-side-bottom {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  color: var(--ink-2);
  text-transform: uppercase;
  position: relative; z-index: 1;
  display: flex; flex-direction: column; gap: 6px;
}
.auth-side-bottom .row { display: flex; justify-content: space-between; gap: 12px; }
.auth-side-bottom .key { color: var(--ink-3); }
.auth-side-bottom .val { color: var(--ink-1); }

/* Auth station map preview (decorative SVG placeholder) */
.auth-map {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  opacity: 0.45;
  pointer-events: none;
  width: 600px; height: 600px;
  max-width: 80%; max-height: 80%;
}

/* ---------- Terminal tab specific --------------------------------------- */
.terminal-host {
  background: var(--term-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 14px;
  min-height: 440px;
  position: relative;
}
.terminal-host::before {
  content: "● ● ●";
  color: var(--line-bright);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.3em;
  position: absolute; top: 8px; left: 14px;
}
#xterm-container { min-height: 420px; padding-top: 20px; }

/* ---------- Detail pages: summary bar ----------------------------------- */
.summary-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.summary-item {
  padding: 14px 18px;
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 4px;
}
.summary-item:last-child { border-right: none; }
.summary-key {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-2);
}
.summary-val {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 18px;
  letter-spacing: -0.02em;
  color: var(--ink-0);
}
.summary-val.mono { font-family: var(--font-mono); font-size: 15px; letter-spacing: 0; font-weight: 600; }

/* Definition list */
.dlist { display: grid; grid-template-columns: 180px 1fr; gap: 8px 16px; font-size: 13px; }
.dlist dt {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-2);
  align-self: center;
}
.dlist dd { margin: 0; color: var(--ink-0); }
@media (max-width: 640px) { .dlist { grid-template-columns: 1fr; } .dlist dt { margin-top: 8px; } }

/* ---------- Logbook timeline --------------------------------------------- */
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li {
  position: relative;
  padding: 14px 0 14px 28px;
  border-bottom: 1px solid var(--line);
}
.timeline li:last-child { border-bottom: none; }
.timeline li::before {
  content: "";
  position: absolute;
  left: 8px; top: 20px;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--bg-1);
  border: 2px solid var(--accent);
  z-index: 1;
}
.timeline li::after {
  content: "";
  position: absolute;
  left: 11px; top: 32px; bottom: -1px;
  width: 2px; background: var(--line);
}
.timeline li:last-child::after { display: none; }
.timeline .tl-head {
  display: flex; align-items: baseline; gap: 10px; margin-bottom: 3px;
}
.timeline .tl-title { font-weight: 600; color: var(--ink-0); font-size: 13.5px; }
.timeline .tl-meta {
  font-family: var(--font-mono); font-size: 11px; color: var(--ink-2); letter-spacing: 0.04em;
}
.timeline .tl-message { color: var(--ink-1); font-size: 13px; white-space: pre-wrap; }

/* Event type color coding */
.timeline li[data-type="note"]::before { border-color: var(--cyan); }
.timeline li[data-type="maintenance"]::before { border-color: var(--warn); }
.timeline li[data-type="incident"]::before { border-color: var(--danger); }
.timeline li[data-type="update"]::before { border-color: var(--accent); }
.timeline li[data-type="deployment"]::before { border-color: var(--violet); }

/* ---------- Alert card --------------------------------------------------- */
.alert-card {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-left: 3px solid var(--warn);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: start;
}
.alert-card.severity-critical { border-left-color: var(--danger); }
.alert-card.severity-warning { border-left-color: var(--warn); }
.alert-card.is-resolved { opacity: 0.55; }
.alert-card.is-resolved .alert-title { text-decoration: line-through; }
.alert-title { font-weight: 600; color: var(--ink-0); font-size: 14px; margin: 0 0 4px; }
.alert-meta { font-family: var(--font-mono); font-size: 11px; color: var(--ink-2); letter-spacing: 0.04em; }
.alert-message { color: var(--ink-1); font-size: 13px; margin: 6px 0 0; }

/* ---------- Pagination --------------------------------------------------- */
.pager {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 0;
  color: var(--ink-2);
  font-family: var(--font-mono); font-size: 12px; letter-spacing: 0.04em;
}
.pager-links { display: flex; gap: 4px; }
.pager-links a, .pager-links span {
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--ink-1);
  font-family: var(--font-mono);
  font-size: 12px;
}
.pager-links a:hover { border-color: var(--accent); color: var(--accent); }
.pager-links .current { background: var(--accent); color: var(--on-accent-ink); border-color: var(--accent); font-weight: 600; }

/* ---------- Photo gallery ------------------------------------------------ */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
}
.photo-cell {
  aspect-ratio: 4 / 3;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg-2);
  border: 1px solid var(--line);
  position: relative;
}
.photo-cell img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-cell figcaption {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 6px 9px;
  background: linear-gradient(transparent, color-mix(in srgb, var(--shadow-color) 85%, transparent));
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--ink-0);
  letter-spacing: 0.02em;
}

/* ---------- Responsive sidebar ------------------------------------------- */
.menu-toggle { display: none; }
@media (max-width: 1024px) {
  .app-shell {
    grid-template-columns: 0 1fr;
    grid-template-areas:
      "rail topbar"
      "main main";
  }
  .sidebar {
    position: fixed;
    top: 0; bottom: 0; left: 0;
    width: 280px;
    max-width: 84vw;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.3s var(--ease);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.is-open { transform: none; }
  .sidebar-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: color-mix(in srgb, var(--shadow-color) 60%, transparent);
    z-index: 150;
    backdrop-filter: blur(2px);
  }
  .sidebar.is-open + .sidebar-backdrop { display: block; }
  .menu-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-2);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 0;
    width: 40px;
    height: 40px;
    cursor: pointer;
    color: var(--ink-0);
    flex-shrink: 0;
  }
  .menu-toggle:hover { background: var(--bg-3); border-color: var(--line-hot); }
  .main { padding: 18px; }
  .rail { display: none; }
  /* Bump nav items to 44px tap target on touch */
  .nav-item { padding: 11px 12px; font-size: 14px; }
  .sidebar-brand { padding: 18px 18px 14px; }
}

/* ---------- Mobile: tablets and phones (≤ 1024px) ------------------------- */
@media (max-width: 1024px) {
  /* Tighter KPI grid, still readable */
  .grid-kpi { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
  .grid { gap: 12px; }
  .stat { padding: 13px 14px; }
  .stat-value { font-size: 24px; }

  /* Page header stacks */
  .page-head {
    flex-direction: column;
    align-items: stretch;
    gap: 14px;
    margin-bottom: 20px;
    padding-bottom: 16px;
  }
  .page-title { font-size: 24px; }
  .page-head-actions { flex-wrap: wrap; gap: 8px; }
  .page-head-actions .btn { flex: 1 1 auto; justify-content: center; min-height: 40px; }

  /* Tables: horizontal scroll by default on narrow screens */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table-wrap::after {
    content: "";
    display: block;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--line-bright) 50%, transparent);
    opacity: 0.4;
  }
  .t-table { min-width: 560px; }

  /* Filter bar stacks */
  .filter-bar { flex-direction: column; align-items: stretch; padding: 10px; }
  .filter-bar .search { width: 100%; min-width: 0; }
  .filter-bar select,
  .filter-bar .form-select {
    width: 100% !important;
    min-width: 0 !important;
  }

  /* Summary bar: two columns on tablet */
  .summary-bar { grid-template-columns: repeat(2, 1fr); }
  .summary-item { border-right: 1px solid var(--line); }
  .summary-item:nth-child(2n) { border-right: none; }

  /* Topbar density */
  .topbar { padding: 0 14px; gap: 10px; }
  .topbar-crumbs { font-size: 11px; }

  /* Hide decorative topbar bits */
  .waveform { display: none; }
}

/* ---------- Phones (≤ 640px) --------------------------------------------- */
@media (max-width: 640px) {
  body { font-size: 14px; }

  .main { padding: 14px 12px 64px; }
  .main-inner { max-width: 100%; }

  /* Page head: condensed */
  .page-head { margin-bottom: 16px; padding-bottom: 12px; gap: 10px; }
  .page-eyebrow { font-size: 9.5px; letter-spacing: 0.16em; }
  .page-title { font-size: 22px; letter-spacing: -0.02em; }
  .page-sub { font-size: 13px; }
  .page-head-actions { width: 100%; }
  .page-head-actions .btn { width: 100%; flex: 1 1 100%; }

  /* KPI grid - 2 columns on phones */
  .grid-kpi { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .stat { padding: 12px; gap: 4px; }
  .stat-label { font-size: 9px; letter-spacing: 0.14em; }
  .stat-value { font-size: 22px; }
  .stat-unit { font-size: 11px; }
  .stat-meta { font-size: 10px; }

  /* Grid variants collapse to 1 col */
  .grid-cols-2, .grid-cols-3, .grid-main,
  .v-split, .v-split-3 { grid-template-columns: 1fr !important; }

  /* Summary bar: single column, borders go to bottom */
  .summary-bar { grid-template-columns: 1fr; }
  .summary-item {
    border-right: none !important;
    border-bottom: 1px solid var(--line);
  }
  .summary-item:last-child { border-bottom: none; }
  .summary-val { font-size: 16px; }
  .summary-val.mono { font-size: 13px; }

  /* Panels */
  .panel-head {
    padding: 11px 14px;
    flex-wrap: wrap;
    gap: 8px;
  }
  .panel-title { font-size: 13.5px; }
  .panel-body { padding: 14px; }

  /* Topbar: icon-only mode */
  .topbar { height: 54px; padding: 0 10px; gap: 6px; }
  .topbar-crumbs { font-size: 10.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
  .topbar-crumbs a, .topbar-crumbs span { flex-shrink: 0; }
  .topbar-clock { padding: 4px 7px; font-size: 10.5px; }
  .topbar-clock .utc { display: none; }
  .theme-toggle span { display: none; }
  .theme-toggle { padding: 8px; width: 36px; height: 36px; justify-content: center; }
  [data-lang-form] select { padding: 6px 20px 6px 6px !important; font-size: 10px !important; }
  [data-ws-indicator] { font-size: 9px; padding: 2px 6px; }
  :root { --topbar-h: 54px; }

  /* Buttons: touchable */
  .btn { min-height: 40px; padding: 9px 14px; font-size: 13.5px; }
  .btn-sm { min-height: 32px; padding: 6px 11px; }
  .btn-lg { min-height: 48px; padding: 12px 18px; }
  .btn-icon { min-width: 40px; width: 40px; height: 40px; padding: 0; justify-content: center; }

  /* Form inputs: 44px+ height for touch */
  .form-control, .form-select,
  input[type="text"], input[type="email"], input[type="password"],
  input[type="number"], input[type="search"], input[type="url"],
  input[type="date"], input[type="time"], input[type="datetime-local"],
  input[type="tel"], textarea, select {
    font-size: 16px; /* prevents iOS zoom on focus */
    padding: 11px 12px;
    min-height: 44px;
  }
  textarea { min-height: 110px; }
  .form-select, select {
    background-position: calc(100% - 14px) 20px, calc(100% - 9px) 20px;
  }
  input[type="checkbox"], input[type="radio"] { width: 20px; height: 20px; }
  .form-group ul li label { padding: 8px 12px; min-height: 36px; font-size: 12.5px; }

  /* Tabs: more compact, fade hint on the right for scroll */
  .tabs {
    margin-bottom: 16px;
    margin-left: -12px;
    margin-right: -12px;
    padding: 0 12px;
    position: relative;
  }
  .tab {
    padding: 12px 12px;
    font-size: 13px;
    min-height: 44px;
  }

  /* Forms - full width, cancel spacing */
  form[class*="stack-gap"] { max-width: 100% !important; }
  .form-row { gap: 12px; }

  /* Tables → card layout on phones
     Using display:block and pseudo-labels via thead hidden.
     Tables that have [data-mobile-cards] attribute reflow into cards. */
  .t-table[data-mobile-cards],
  [data-mobile-cards] .t-table {
    min-width: 0;
    display: block;
  }
  [data-mobile-cards] .t-table thead { display: none; }
  [data-mobile-cards] .t-table tbody { display: block; }
  [data-mobile-cards] .t-table tr {
    display: block;
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
    background: var(--bg-1);
  }
  [data-mobile-cards] .t-table tr:hover { background: var(--bg-2); }
  [data-mobile-cards] .t-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 5px 0;
    border: none;
    font-size: 13px;
  }
  [data-mobile-cards] .t-table td::before {
    content: attr(data-label);
    font-family: var(--font-mono);
    font-size: 9.5px;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--ink-3);
    flex-shrink: 0;
  }
  [data-mobile-cards] .t-table td:not([data-label])::before { display: none; }
  [data-mobile-cards] .t-table td[data-primary] {
    justify-content: flex-start;
    padding-bottom: 8px;
    margin-bottom: 4px;
    border-bottom: 1px solid var(--line);
  }
  [data-mobile-cards] .t-table td[data-primary]::before { display: none; }
  [data-mobile-cards] .t-table td.actions {
    justify-content: flex-end;
    padding-top: 8px;
    margin-top: 4px;
    border-top: 1px dashed var(--line);
  }

  /* Flash stack repositions */
  .flash-stack {
    right: 10px;
    left: 10px;
    max-width: none;
    top: calc(var(--topbar-h) + 10px);
  }

  /* Filter bar — ensure HTMX spinner placement */
  .filter-bar .htmx-indicator { align-self: center; }

  /* Hero/callsign action buttons wrap */
  .row-split { flex-wrap: wrap; }
  .row-gap-8, .row-gap-12 { flex-wrap: wrap; }

  /* Dlist compact labels */
  .dlist { font-size: 13px; gap: 4px 12px; }
  .dlist dt { font-size: 10px; letter-spacing: 0.12em; margin-top: 10px; }
  .dlist dt:first-of-type { margin-top: 0; }

  /* Pager */
  .pager { flex-direction: column; gap: 10px; align-items: flex-start; }
  .pager-links { flex-wrap: wrap; }
  .pager-links a, .pager-links span { min-height: 36px; display: inline-flex; align-items: center; }

  /* Timeline */
  .timeline li { padding: 12px 0 12px 22px; }
  .timeline li::before { left: 4px; top: 16px; }
  .timeline li::after { left: 7px; top: 28px; }
  .timeline .tl-head { flex-wrap: wrap; gap: 6px; }

  /* Alert card */
  .alert-card { grid-template-columns: 1fr; gap: 8px; }

  /* Photo grid */
  .photo-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }

  /* Code boxes */
  .codebox { font-size: 11px; padding: 10px 12px; }

  /* Terminal */
  .terminal-host { padding: 10px; min-height: 360px; }
  #xterm-container { min-height: 340px; }

  /* Progress bar a touch taller for visibility */
  .progress { height: 8px; }

  /* Inventory nested panels */
  .panel .panel { margin-bottom: 8px; }

  /* Station callsign hero row */
  .page-title .callsign { display: block; font-size: 22px; }
  .page-title .t-muted { display: block; font-size: 14px; font-weight: 400; margin-top: 2px; }

  /* Deployment progress bar inline row wraps */
  .t-table td[style*="min-width"] { min-width: 0 !important; }
}

/* ---------- Small phones (≤ 380px) --------------------------------------- */
@media (max-width: 380px) {
  .grid-kpi { grid-template-columns: 1fr; }
  .topbar-crumbs { font-size: 10px; }
  .page-title { font-size: 20px; }
  .stat-value { font-size: 20px; }
  .brand-callsign { font-size: 14px; }
}

/* ---------- Login page on phones ----------------------------------------- */
@media (max-width: 640px) {
  .auth-shell { min-height: 100vh; min-height: 100dvh; }
  .auth-panel {
    padding: 32px 20px 40px;
    gap: 20px;
    border-right: none;
    min-height: 100vh;
    min-height: 100dvh;
  }
  .auth-title { font-size: 30px; letter-spacing: -0.025em; }
  .auth-sub { font-size: 13.5px; }
  .auth-brand .brand-mark { width: 36px; height: 36px; }
}

/* ---------- Touch-device niceties ---------------------------------------- */
@media (hover: none) and (pointer: coarse) {
  /* Disable hover-translate that feels sticky on touch */
  .stat:hover { transform: none; }
  .btn:active { transform: translateY(1px); }
  /* Larger tap targets for action links in tables */
  .t-table .btn-sm.btn-ghost { min-height: 36px; min-width: 36px; }
}

/* ---------- Print -------------------------------------------------------- */
@media print {
  .sidebar, .topbar, .rail, .page-head-actions { display: none; }
  .main { padding: 0; }
  body::before, body::after { display: none; }
  .panel { border: 1px solid var(--line); }
}

/* ---------- Theme switcher ----------------------------------------------- */
.theme-toggle {
  background: transparent;
  border: 1px solid var(--line-bright);
  color: var(--ink-1);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  display: inline-flex; align-items: center; gap: 6px;
}
.theme-toggle:hover { color: var(--accent); border-color: var(--accent); }

/* ---------- Helpers for data density ------------------------------------- */
.v-split { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.v-split-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
@media (max-width: 720px) { .v-split, .v-split-3 { grid-template-columns: 1fr; } }

/* Dashboard station mini-card (in recent activity strip) */
.mini-station {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--bg-1);
  transition: border-color 0.15s var(--ease), background 0.15s var(--ease);
}
.mini-station:hover { border-color: var(--line-hot); background: var(--bg-2); }
.mini-station .ms-name { font-weight: 600; color: var(--ink-0); font-size: 13px; }
.mini-station .ms-meta { font-family: var(--font-mono); font-size: 10.5px; color: var(--ink-2); }

/* Signal icon (tiny bars) */
.sig-bars {
  display: inline-flex; align-items: flex-end; gap: 2px; height: 12px;
}
.sig-bars span {
  width: 2px; background: var(--line-bright); border-radius: 1px;
}
.sig-bars span:nth-child(1) { height: 4px; }
.sig-bars span:nth-child(2) { height: 7px; }
.sig-bars span:nth-child(3) { height: 10px; }
.sig-bars span:nth-child(4) { height: 12px; }
.sig-bars.online span { background: var(--signal); }
.sig-bars.offline span { background: var(--line-bright); }
.sig-bars.error span { background: var(--danger); }

/* ---------- Action menu (dropdown replacement for row actions) ----------- */
.menu { position: relative; display: inline-block; }
.menu-list {
  position: absolute;
  right: 0; top: calc(100% + 4px);
  min-width: 180px;
  background: var(--bg-2);
  border: 1px solid var(--line-bright);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  padding: 4px;
  display: none;
  z-index: 60;
}
.menu.is-open .menu-list { display: block; }
.menu-list a, .menu-list button {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px;
  font-size: 13px;
  color: var(--ink-1);
  border-radius: var(--radius-xs);
  background: transparent; border: none; width: 100%; text-align: left;
  cursor: pointer; font-family: inherit;
}
.menu-list a:hover, .menu-list button:hover { background: var(--bg-3); color: var(--ink-0); }
.menu-list .danger { color: var(--danger); }

/* ---------- Tiny helpers ------------------------------------------------- */
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.nowrap { white-space: nowrap; }
.visually-hidden {
  position: absolute !important; width: 1px !important; height: 1px !important;
  padding: 0 !important; margin: -1px !important; overflow: hidden !important;
  clip: rect(0,0,0,0) !important; white-space: nowrap !important; border: 0 !important;
}

/* No results / htmx loading indicator */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline-flex; }
.htmx-request.htmx-indicator { display: inline-flex; }
.spinner {
  width: 14px; height: 14px;
  border: 2px solid var(--line-bright);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Rollout sequence edit list */
.sequence-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sequence-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 6px;
}
.sequence-row .grip {
  cursor: grab;
  font-size: 20px;
  line-height: 1;
  color: var(--ink-2);
  user-select: none;
  padding: 0 4px;
}
.sequence-row .grip:active { cursor: grabbing; }
.sequence-row .sequence-pos {
  min-width: 28px;
  text-align: right;
  font-size: 12.5px;
}
.sequence-row .sequence-tag {
  flex: 1 1 auto;
  font-weight: 600;
  color: var(--ink-0);
  word-break: break-word;
}
.sequence-row .sequence-remove-form { margin: 0; }
.sequence-row-ghost {
  opacity: 0.4;
  background: var(--bg-3, var(--bg-2));
  border-style: dashed;
}
.sequence-add-form select { min-width: 220px; }

/* Archived ImageRelease rows in the Image Releases table.
   Mute the data cells only — the .actions cell carries the Restore
   button and must stay at full contrast so it doesn't look disabled. */
.t-table tr.is-archived td:not(.actions) { opacity: 0.55; }
.t-table tr.is-archived td:not(.actions) .frame-id { color: var(--ink-3); }

/* ---------------------------------------------------------------------------
   Onboarding hints (Profile page, 1c) — dezenter Border-Left, mobile-tauglich
   --------------------------------------------------------------------------- */
.onboarding-hint {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 12px 0;
  padding: 10px 12px;
  border-left: 3px solid var(--accent-soft, var(--accent));
  background: var(--bg-2);
  border-radius: 0 4px 4px 0;
  font-size: 13px;
  color: var(--ink-1);
}
.onboarding-hint-icon { flex: 0 0 auto; line-height: 1.4; }
.onboarding-hint-text { flex: 1; line-height: 1.4; }

/* ---------------------------------------------------------------------------
   Module firmware — import setup hints + GitHub variant preview
   --------------------------------------------------------------------------- */
.fw-setup-list { list-style: none; padding: 0; margin: 10px 0 0; }
.fw-setup-list li { padding: 8px 0; border-top: 1px solid var(--line); }
.fw-variants { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.fw-gh-hint { display: block; margin-top: 4px; font-size: 11.5px; }

/* ---------------------------------------------------------------------------
   Module firmware — convergence overview + module-detail firmware panel
   --------------------------------------------------------------------------- */
.fw-kpi { color: inherit; text-decoration: none; }
.fw-kpi.is-active { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.fw-kpi:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.fw-filter-select { width: auto; min-width: 150px; }
.fw-uid-link { color: inherit; text-decoration: none; }
.fw-uid-link:hover { text-decoration: underline; }
.fw-version {
  font-family: var(--font-mono);
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--ink-0);
}
.fw-version-match { color: var(--signal); }
.fw-target { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.fw-hint { display: block; margin-top: 4px; font-size: 11.5px; color: var(--ink-2); }
.fw-hint-warn { color: var(--warn); }
.fw-quarantine {
  margin-top: 8px;
  padding: 8px 10px;
  border-left: 3px solid var(--danger);
  background: var(--danger-soft);
  border-radius: 0 4px 4px 0;
  font-size: 12.5px;
  color: var(--ink-1);
  max-width: 60ch;
}
.fw-quarantine-meta { font-family: var(--font-mono); font-size: 11.5px; color: var(--danger); }
.fw-quarantine-msg { margin-top: 4px; overflow-wrap: anywhere; }
.fw-quarantine-form { margin: 8px 0 0; }
.fw-detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
}
