@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500;700&display=swap');

:root {
  --bg: #000000;
  --surface: #0a0a0a;
  --surface-2: #121212;
  --surface-3: #1a1a1a;
  --border: #1c1c1c;
  --border-strong: #2e2e2e;

  --text: #f2f2f2;
  --text-2: #a8a8a8;
  --text-3: #6b6b6b;
  --text-4: #3d3d3d;

  --ok: #22c55e;
  --ok-dim: #14532d;
  --warn: #f5a623;
  --warn-dim: #7a5416;
  --danger: #ef4444;
  --danger-dim: #7f1d1d;
  --info: #5b9dff;

  --sans: "Inter", -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --ease: cubic-bezier(0.2, 0, 0, 1);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* iPhone safe-area insets (notch / Dynamic Island / home indicator) —
   padded into :root so every fixed/sticky edge element can add it to its
   own padding rather than guessing a fixed pixel offset. */
:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

/* Author-stylesheet `display` rules (.dash's grid, .command-view's flex,
   etc.) have the same specificity as the browser default [hidden]{display:
   none} and, being author-origin, win the tie — so a tab-panel set to
   `display:grid`/`flex` never actually hid when JS toggled its `hidden`
   attribute; it just stacked behind whichever panel was meant to show.
   This forces hidden to always win, regardless of what else targets the
   element. */
[hidden] { display: none !important; }
::selection { background: var(--text); color: var(--bg); }

html { color-scheme: dark; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  min-height: 100vh;
  min-height: 100dvh;
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

a { color: var(--text); }
button { font-family: var(--sans); }
img { -webkit-user-drag: none; user-select: none; }

*:focus-visible {
  outline: 1px solid var(--text);
  outline-offset: 2px;
}

.icon { display: inline-flex; width: 1em; height: 1em; }
.icon svg { width: 100%; height: 100%; display: block; }

.label {
  font-size: 10px;
  letter-spacing: 1.4px;
  color: var(--text-3);
  text-transform: uppercase;
  font-weight: 600;
}

.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ── Top bar ─────────────────────────────────────────────────────────── */
header.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--safe-top) calc(20px + var(--safe-right)) 0 calc(20px + var(--safe-left));
  height: calc(54px + var(--safe-top));
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky; top: 0; z-index: 20;
  gap: 10px;
}
.topbar-left { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  width: 30px; height: 30px;
  border: 1px solid var(--border-strong);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 800; letter-spacing: 0.5px;
  color: var(--text);
  background: var(--surface-2);
}
.brand-org { font-size: 9px; letter-spacing: 1.6px; color: var(--text-3); font-weight: 600; }
.brand-name { font-size: 15px; font-weight: 700; letter-spacing: 2.5px; }
.brand-sub { font-size: 9px; letter-spacing: 1.8px; color: var(--text-3); margin-left: 8px; font-weight: 600; }

.topbar-mid {
  display: flex;
  align-items: center;
  gap: 30px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.topbar-mid::-webkit-scrollbar { display: none; }
.stat-block { text-align: left; }
.stat-block .label { margin-bottom: 4px; }
.stat-block .value { font-size: 12px; font-weight: 600; letter-spacing: 0.3px; font-family: var(--mono); }
.value.status-dot { display: flex; align-items: center; gap: 6px; }
.pulse-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-4);
  flex-shrink: 0;
}
.pulse-dot.ok { background: var(--ok); box-shadow: 0 0 6px rgba(34,197,94,0.7); }
.pulse-dot.danger { background: var(--danger); box-shadow: 0 0 6px rgba(239,68,68,0.7); }
.pulse-dot.warn { background: var(--warn); box-shadow: 0 0 6px rgba(245,166,35,0.6); }
.pulse-dot.pulsing { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

.topbar-right { display: flex; align-items: center; gap: 6px; }
.topbar-link {
  display: flex; align-items: center; gap: 6px;
  font-size: 10px;
  letter-spacing: 1.3px;
  font-weight: 600;
  color: var(--text-2);
  text-decoration: none;
  cursor: pointer;
  background: none;
  border: none;
  font-family: var(--sans);
  padding: 8px 10px;
  transition: color 140ms var(--ease), background 140ms var(--ease);
}
.topbar-link:hover { color: var(--text); background: var(--surface-2); }
.topbar-link .icon { font-size: 13px; }
.topbar-link.outline { border: 1px solid var(--border-strong); }

/* ── App shell ───────────────────────────────────────────────────────── */
.shell {
  display: flex;
  height: calc(100vh - (54px + var(--safe-top)) - 38px - (36px + var(--safe-bottom)));
  height: calc(100dvh - (54px + var(--safe-top)) - 38px - (36px + var(--safe-bottom)));
}

nav.sidebar {
  width: 80px;
  border-right: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  padding-top: 4px;
  padding-left: var(--safe-left);
  flex-shrink: 0;
}
.sidebar-footer {
  margin-top: auto;
  padding: 12px 6px 16px;
  text-align: center;
  font-size: 7.5px;
  font-weight: 700;
  letter-spacing: 1px;
  line-height: 1.6;
  color: var(--text-4);
  border-top: 1px solid var(--border);
}
.sidebar .nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  padding: 15px 4px;
  color: var(--text-3);
  text-decoration: none;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 1px;
  border-left: 2px solid transparent;
  cursor: pointer;
  background: none;
  border-top: none; border-right: none; border-bottom: none;
  width: 100%;
  font-family: var(--sans);
  transition: color 140ms var(--ease), background 140ms var(--ease), border-color 140ms var(--ease);
}
.sidebar .nav-item .icon { font-size: 18px; }
.sidebar .nav-item:hover { color: var(--text-2); background: var(--surface-2); }
.sidebar .nav-item.active {
  color: var(--text);
  border-left-color: var(--text);
  background: var(--surface-2);
}

main.content {
  flex: 1;
  min-width: 0;
  height: 100%;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
}

/* ── Bottom status bar ───────────────────────────────────────────────── */
footer.statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: calc(36px + var(--safe-bottom));
  padding: 0 calc(18px + var(--safe-right)) var(--safe-bottom) calc(18px + var(--safe-left));
  border-top: 1px solid var(--border);
  background: var(--surface);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1px;
  color: var(--text-2);
  position: sticky; bottom: 0;
  gap: 10px;
}
.statusbar-left {
  display: flex;
  align-items: center;
  gap: 24px;
  overflow-x: auto;
  white-space: nowrap;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  min-width: 0;
}
.statusbar-left::-webkit-scrollbar { display: none; }
.statusbar-right { flex-shrink: 0; }
.statusbar-left .stat-item { display: flex; align-items: center; gap: 6px; }
.statusbar-left .stat-item.ok { color: var(--ok); }
.statusbar-left .stat-item.warn { color: var(--warn); }
.statusbar-left .stat-item.danger { color: var(--danger); }
.statusbar-right { display: flex; align-items: center; gap: 10px; }

.btn-footer {
  display: flex; align-items: center; gap: 7px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  padding: 7px 14px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text-2);
  cursor: pointer;
  font-family: var(--sans);
  transition: all 140ms var(--ease);
}
.btn-footer:hover:not(:disabled) { color: var(--text); border-color: var(--text-3); }
.btn-footer:disabled { opacity: 0.35; cursor: not-allowed; }
.btn-footer.danger {
  background: var(--danger-dim);
  border-color: var(--danger);
  color: #ffd7d7;
}
.btn-footer.danger:hover { background: var(--danger); color: #fff; }
.btn-footer.danger:active { transform: scale(0.97); }

/* ── Toasts ──────────────────────────────────────────────────────────── */
.toast-stack {
  position: fixed; top: 64px; right: 18px; z-index: 999;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--text);
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.5px;
  min-width: 220px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  animation: toast-in 180ms var(--ease);
}
.toast.ok { border-left-color: var(--ok); }
.toast.danger { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warn); }
.toast .toast-title { color: var(--text); }
.toast .toast-sub { color: var(--text-3); font-weight: 500; margin-top: 2px; font-size: 10px; }
@keyframes toast-in { from { opacity: 0; transform: translateX(12px); } to { opacity: 1; transform: none; } }
.toast.leaving { animation: toast-out 180ms var(--ease) forwards; }
@keyframes toast-out { to { opacity: 0; transform: translateX(12px); } }

/* ── Login ───────────────────────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 50% 30%, rgba(255,255,255,0.03), transparent 55%),
    var(--bg);
}
.login-box {
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 40px 36px;
  width: 320px;
}
.login-box .icon-lock {
  width: 34px; height: 34px;
  border: 1px solid var(--border-strong);
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 18px;
  color: var(--text-2);
  font-size: 16px;
}
.login-box .brand-name { display: block; text-align: center; margin-bottom: 4px; font-size: 17px; }
.login-box .brand-org { display: block; text-align: center; margin-bottom: 24px; }
.login-box label {
  display: block;
  font-size: 10px;
  color: var(--text-3);
  letter-spacing: 1.4px;
  font-weight: 600;
  margin: 16px 0 6px;
  text-transform: uppercase;
}
.login-box input {
  width: 100%;
  background: #000;
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 10px 11px;
  font-family: var(--mono);
  font-size: 16px;
  transition: border-color 140ms var(--ease);
}
.login-box input:focus { outline: none; border-color: var(--text-2); }
.login-box button {
  width: 100%;
  margin-top: 24px;
  background: var(--text);
  border: none;
  color: #000;
  padding: 11px;
  letter-spacing: 2px;
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
  transition: opacity 140ms var(--ease);
}
.login-box button:hover { opacity: 0.85; }
.login-box button:active { opacity: 0.7; }
.login-error {
  color: var(--danger);
  font-size: 11px;
  font-weight: 600;
  margin-top: 12px;
  text-align: center;
  min-height: 14px;
}

.page-footer {
  position: fixed;
  left: 0; right: 0; bottom: 14px;
  text-align: center;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1.4px;
  color: var(--text-4);
  pointer-events: none;
}

/* ── Fleet page ──────────────────────────────────────────────────────── */
.page-wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding: 36px 20px 60px;
}
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding-bottom: 18px;
  margin-bottom: 22px;
  border-bottom: 1px solid var(--border);
}
.page-title { font-size: 20px; font-weight: 700; letter-spacing: 0.3px; margin-top: 4px; }
.fleet-count {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.4px;
  color: var(--text-2);
  border: 1px solid var(--border-strong);
  padding: 6px 12px;
  font-family: var(--mono);
}

.page-head-actions { display: flex; align-items: center; gap: 10px; }
.pair-btn {
  background: var(--text);
  border: none;
  color: #000;
  padding: 8px 16px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1.3px;
  cursor: pointer;
  font-family: var(--sans);
  transition: opacity 140ms var(--ease);
}
.pair-btn:hover { opacity: 0.85; }

/* ── Pair New Unit modal ─────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-box {
  width: 420px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 60px);
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
}
.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-head .title { font-size: 14px; font-weight: 700; margin-top: 3px; }
.modal-close {
  background: none;
  border: none;
  color: var(--text-3);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: 18px; }
.modal-body label {
  display: block;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1.3px;
  color: var(--text-3);
  text-transform: uppercase;
  margin: 14px 0 6px;
}
.modal-body label:first-child { margin-top: 0; }
.modal-body input, .modal-body select {
  width: 100%;
  background: #000;
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 9px 10px;
  font-family: var(--sans);
  font-size: 16px;
}
.modal-body input:focus, .modal-body select:focus { outline: none; border-color: var(--text-2); }
.modal-body #pairSubmitBtn {
  width: 100%;
  margin-top: 18px;
  background: var(--text);
  border: none;
  color: #000;
  padding: 10px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1.5px;
  cursor: pointer;
}
.modal-body #pairSubmitBtn:hover { opacity: 0.85; }

.pair-error {
  color: var(--danger);
  font-size: 11px;
  font-weight: 600;
  min-height: 14px;
  margin-top: 10px;
}

.user-remove-btn {
  background: transparent;
  border: 1px solid var(--danger-dim);
  color: var(--danger);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.8px;
  padding: 3px 8px;
  cursor: pointer;
  font-family: var(--sans);
  transition: all 140ms var(--ease);
}
.user-remove-btn:hover:not(:disabled) { background: var(--danger-dim); color: #fff; }
.user-remove-btn:disabled { opacity: 0.3; cursor: not-allowed; }

.pair-config {
  background: #000;
  border: 1px solid var(--border-strong);
  padding: 12px 14px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ok);
  white-space: pre-wrap;
  word-break: break-all;
  margin: 0 0 14px;
}

.pair-modal-actions { display: flex; gap: 1px; background: var(--border); }
.pair-modal-actions button {
  flex: 1;
  padding: 10px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.2px;
  cursor: pointer;
  border: none;
  font-family: var(--sans);
}
#pairCopyBtn { background: var(--text); color: #000; }
#pairCopyBtn:hover { opacity: 0.85; }

.grid {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  justify-content: center;
}
.bot-card {
  width: 300px;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 20px;
  text-decoration: none;
  color: var(--text);
  display: block;
  transition: background 140ms var(--ease);
}
.bot-card:hover { background: var(--surface-2); border-color: var(--border-strong); }
.bot-card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.bot-card .name { font-size: 15px; letter-spacing: 1.2px; font-weight: 700; }
.bot-card .code { font-size: 10px; color: var(--text-3); margin-top: 4px; letter-spacing: 1px; font-family: var(--mono); }
.bot-card-meta {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  background: var(--border);
  margin-top: 18px;
  border: 1px solid var(--border);
}
.meta-item { background: var(--surface-2); padding: 9px 10px; }
.meta-item .label { margin-bottom: 5px; }
.meta-value { font-size: 11px; font-weight: 600; font-family: var(--mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1.4px;
  border: 1px solid var(--border-strong);
  flex-shrink: 0;
}
.status-pill::before { content: ""; width: 5px; height: 5px; border-radius: 50%; }
.status-pill.online { color: var(--ok); border-color: var(--ok-dim); }
.status-pill.online::before { background: var(--ok); box-shadow: 0 0 5px rgba(34,197,94,0.7); }
.status-pill.offline { color: var(--danger); border-color: var(--danger-dim); }
.status-pill.offline::before { background: var(--danger); }
.empty-state {
  grid-column: 1 / -1;
  padding: 60px 20px;
  text-align: center;
  color: var(--text-3);
  font-size: 12px;
  letter-spacing: 0.5px;
}

/* ── Command layout ──────────────────────────────────────────────────── */
.dash {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 1px;
  background: var(--border);
}
@media (max-width: 980px) { .dash { grid-template-columns: 1fr; } }

.panel { background: var(--surface); padding: 0; }
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.panel-head .label { margin-bottom: 3px; }
.panel-head .title { font-size: 13px; font-weight: 700; letter-spacing: 0.3px; }
.panel-body { padding: 16px; }

.live-tag {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1.2px;
  color: var(--ok);
  border: 1px solid var(--ok-dim);
  padding: 3px 9px;
  display: flex; align-items: center; gap: 6px;
}
.live-tag::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 5px rgba(34,197,94,0.7); }
.live-tag.stale { color: var(--warn); border-color: var(--warn-dim); }
.live-tag.stale::before { background: var(--warn); animation: pulse 1.2s ease-in-out infinite; }
.live-tag.down { color: var(--text-3); border-color: var(--border-strong); }
.live-tag.down::before { background: var(--text-4); box-shadow: none; }

.feed-wrap {
  position: relative;
  background: #000;
  aspect-ratio: 16 / 10;
  overflow: hidden;
}

/* ── Command tab: single full-height view, no page scroll ────────────── */
.command-view { height: 100%; display: flex; flex-direction: column; }

.command-grid {
  flex: 1;
  min-height: 0;
  display: flex;
  gap: 1px;
  background: var(--border);
}
.command-main { flex: 1.7; min-width: 0; display: flex; flex-direction: column; }
.command-side {
  flex: 1;
  min-width: 260px;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--border);
}
.side-panel { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.side-panel .panel-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 10px 12px;
}

.feed-wrap-full { flex: 1; min-height: 0; aspect-ratio: unset; }

.split-feed-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  gap: 1px;
  background: var(--border);
}
.feed-wrap-split { flex: 1; min-width: 0; min-height: 0; aspect-ratio: unset; }

@media (max-width: 900px) {
  .split-feed-wrap { flex-direction: column; }
}

.hud-pip {
  position: absolute;
  bottom: 14px; right: 14px;
  width: clamp(120px, 14vw, 200px);
  aspect-ratio: 16 / 10;
  background: #000;
  border: 1px solid var(--border-strong);
  box-shadow: 0 8px 24px rgba(0,0,0,0.65);
  overflow: hidden;
  z-index: 2;
}
.hud-pip img { width: 100%; height: 100%; object-fit: cover; display: block; background: #000; }

/* Compact metric cells for the side panels — same idea as .metric-grid
   but tighter, since three panels have to share one column's height. */
.metric-grid-compact {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--border);
  margin-bottom: 8px;
  flex-shrink: 0;
}
.metric-cell-compact { background: var(--surface); padding: 6px 9px; }
.metric-cell-compact .label { margin-bottom: 3px; }
.metric-cell-compact .value { font-size: 13px; font-weight: 700; font-family: var(--mono); }

.thermal-img-compact { flex: 1; min-height: 0; background: #000; overflow: hidden; }
.thermal-img-compact img { width: 100%; height: 100%; object-fit: cover; display: block; }

.scope-wrap { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; }
.scope-wrap canvas {
  height: 100%;
  width: auto;
  max-width: 100%;
  aspect-ratio: 1 / 1;
  display: block;
  background: #030303;
}

@media (max-width: 980px) {
  .command-grid { flex-direction: column; }
  .command-side { max-width: none; flex-direction: row; }
}
.feed-wrap img { display: block; width: 100%; height: 100%; object-fit: cover; background: #000; transition: opacity 200ms var(--ease); }
.feed-placeholder {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 8px;
  color: var(--text-4);
  font-size: 10px; letter-spacing: 1.5px; font-weight: 700;
  background:
    repeating-linear-gradient(45deg, #060606, #060606 10px, #0a0a0a 10px, #0a0a0a 20px);
}
.feed-placeholder .icon { font-size: 22px; opacity: 0.4; }

.crosshair {
  position: absolute; top: 50%; left: 50%;
  width: 48px; height: 48px;
  transform: translate(-50%, -50%);
  border: 1px solid rgba(255,255,255,0.35);
  border-radius: 50%;
  pointer-events: none;
}
.crosshair::before, .crosshair::after {
  content: "";
  position: absolute;
  background: rgba(255,255,255,0.35);
}
.crosshair::before { top: 50%; left: -11px; right: -11px; height: 1px; transform: translateY(-50%); }
.crosshair::after { left: 50%; top: -11px; bottom: -11px; width: 1px; transform: translateX(-50%); }

.feed-overlay {
  position: absolute; inset: 0;
  pointer-events: none;
  display: flex; flex-direction: column; justify-content: space-between;
  padding: 9px 11px;
  font-family: var(--mono);
  font-size: 10px;
  color: rgba(255,255,255,0.65);
  text-shadow: 0 1px 3px rgba(0,0,0,0.9);
}
.feed-overlay .row { display: flex; justify-content: space-between; }

.view-toggle { display: flex; border-top: 1px solid var(--border); }
.view-toggle button {
  flex: 1;
  background: transparent;
  border: none;
  border-right: 1px solid var(--border);
  color: var(--text-3);
  padding: 10px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.4px;
  cursor: pointer;
  transition: color 140ms var(--ease), background 140ms var(--ease);
}
.view-toggle button:last-child { border-right: none; }
.view-toggle button:hover { color: var(--text-2); }
.view-toggle button.active { color: var(--text); background: var(--surface-2); }

.pip-row { display: flex; gap: 1px; background: var(--border); }
.pip { flex: 1; position: relative; background: #000; aspect-ratio: 16/10; overflow: hidden; }
.pip img { width: 100%; height: 100%; object-fit: cover; display: block; background: #000; }
.pip-label {
  position: absolute; bottom: 5px; left: 7px;
  font-size: 9px; font-weight: 700; letter-spacing: 1px; color: rgba(255,255,255,0.7);
  font-family: var(--mono);
}

table.kv { width: 100%; border-collapse: collapse; font-size: 11px; }
table.kv td { padding: 7px 2px; border-bottom: 1px solid var(--border); }
table.kv td.k { color: var(--text-3); letter-spacing: 0.3px; font-weight: 500; }
table.kv td.v { text-align: right; color: var(--text); font-weight: 600; font-family: var(--mono); }
.v.ok { color: var(--ok); }
.v.bad { color: var(--danger); }
.v.warn { color: var(--warn); }

.metric-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; background: var(--border); }
.metric-cell { background: var(--surface); padding: 11px 13px; }
.metric-cell .label { margin-bottom: 6px; }
.metric-cell .value { font-size: 18px; font-weight: 700; letter-spacing: 0.2px; font-family: var(--mono); }

canvas.radarscope { width: 100%; aspect-ratio: 1 / 1; background: #030303; display: block; }

.thermal-img-wrap { background: #000; aspect-ratio: 16/10; overflow: hidden; margin-top: 10px; position: relative; }
.thermal-img-wrap img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* ── Sensors tab: compact, uniform card grid ─────────────────────────── */
.sensor-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  background: var(--border);
}
@media (max-width: 1000px) { .sensor-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 620px) { .sensor-grid { grid-template-columns: 1fr; } }

.sensor-grid .panel-body { padding: 16px 18px; }
.sensor-grid .metric-grid-compact .value { font-size: 15px; }
.sensor-grid table.kv { font-size: 12px; }

.sensor-thermal-img {
  background: #000;
  height: 160px;
  overflow: hidden;
  margin-top: 10px;
}
.sensor-thermal-img img { width: 100%; height: 100%; object-fit: cover; display: block; }

.sensor-scope-wrap { display: flex; justify-content: center; margin-top: 6px; }
.sensor-scope-wrap canvas { width: 180px; height: 180px; background: #030303; }

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 38px;
  padding: 0 calc(18px + var(--safe-right)) 0 calc(18px + var(--safe-left));
  box-sizing: border-box;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.4px;
  color: var(--text-3);
  text-decoration: none;
  transition: color 140ms var(--ease);
}
.back-link:hover { color: var(--text); }
.back-link .icon { font-size: 13px; }

/* ── Drive tab ───────────────────────────────────────────────────────── */
.drive-pad {
  display: grid;
  grid-template-columns: repeat(3, 66px);
  grid-template-rows: repeat(3, 66px);
  gap: 6px;
  justify-content: center;
  margin: 22px 0;
}
.drive-btn {
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
  user-select: none;
  display: flex; align-items: center; justify-content: center;
  transition: all 100ms var(--ease);
}
.drive-btn .icon { font-size: 20px; }
.drive-btn:hover:not(:disabled) { border-color: var(--text-3); }
.drive-btn:active { background: var(--surface-3); transform: scale(0.96); }
.drive-btn:disabled { opacity: 0.25; cursor: not-allowed; }

.estop-btn {
  width: 100%;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 24px;
  background: var(--danger-dim);
  border: 1px solid var(--danger);
  color: #ffd7d7;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 3px;
  cursor: pointer;
  transition: all 120ms var(--ease);
}
.estop-btn .icon { font-size: 18px; }
.estop-btn:hover { background: var(--danger); color: #fff; }
.estop-btn:active { transform: scale(0.985); }

.disabled-note {
  font-size: 10.5px;
  color: var(--text-3);
  letter-spacing: 0.2px;
  margin-top: 10px;
  line-height: 1.6;
}

.mission-form label { display: block; font-size: 10px; font-weight: 600; letter-spacing: 1.4px; color: var(--text-3); margin: 15px 0 6px; text-transform: uppercase; }
.mission-form input, .mission-form select {
  width: 100%;
  background: #000;
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 10px 11px;
  font-family: var(--sans);
  font-size: 16px;
}
.mission-form input:focus, .mission-form select:focus { outline: none; border-color: var(--text-2); }
.mission-form button {
  margin-top: 20px;
  background: var(--text);
  border: none;
  color: #000;
  padding: 10px 20px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1.5px;
  cursor: pointer;
  transition: opacity 140ms var(--ease);
}
.mission-form button:hover { opacity: 0.85; }

.mode-presets {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  background: var(--border);
  margin-top: 14px;
}
.mission-form .mode-preset-btn {
  margin-top: 0;
  background: var(--surface-2);
  color: var(--text-2);
  padding: 8px 4px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.8px;
}
.mission-form .mode-preset-btn:hover { opacity: 1; color: var(--text); background: var(--surface-3); }

.mission-status-block {
  padding: 16px 0 18px;
  border-top: 1px solid var(--border);
  margin-top: 20px;
}
.mission-status-block table.kv td { padding-left: 16px; padding-right: 16px; }

table.log { width: 100%; border-collapse: collapse; font-size: 11px; }
table.log th {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--border-strong);
  color: var(--text-3);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 1.4px;
  text-transform: uppercase;
}
table.log td { padding: 9px 10px; border-bottom: 1px solid var(--border); color: var(--text-2); font-family: var(--mono); }
table.log tbody tr { transition: background 120ms var(--ease); }
table.log tbody tr:hover { background: var(--surface-2); }

/* ── Power tab: battery visual ──────────────────────────────────────── */
/* ── Diagnostics tab ─────────────────────────────────────────────────── */
.stability-banner {
  display: flex;
  align-items: center;
  gap: 26px;
  padding: 26px 30px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border-strong);
  margin-bottom: 20px;
}
.stability-score {
  font-family: var(--mono);
  font-size: 46px;
  font-weight: 800;
  line-height: 1;
  flex-shrink: 0;
  min-width: 110px;
}
.stability-info { min-width: 0; }
.stability-verdict { font-size: 16px; font-weight: 700; letter-spacing: 1.5px; margin-bottom: 5px; }
.stability-detail { font-size: 12px; color: var(--text-2); line-height: 1.6; }

.stability-banner.ok { border-left-color: var(--ok); }
.stability-banner.warn { border-left-color: var(--warn); }
.stability-banner.danger { border-left-color: var(--danger); }
.stability-score.ok { color: var(--ok); }
.stability-score.warn { color: var(--warn); }
.stability-score.danger { color: var(--danger); }

.diag-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--border);
}
@media (max-width: 820px) { .diag-grid { grid-template-columns: 1fr; } }

/* ── Mission tab: waypoint editor ────────────────────────────────────── */
.mission-grid {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 1px;
  background: var(--border);
  align-items: start;
}
@media (max-width: 900px) { .mission-grid { grid-template-columns: 1fr; } }

.waypoint-layout { display: flex; }
.waypoint-map { flex: 1; min-width: 0; height: 440px; background: #0a0a0a; }
.waypoint-list-wrap {
  width: 250px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border);
}
.waypoint-list-head {
  display: flex;
  justify-content: space-between;
  padding: 10px 14px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.4px;
  color: var(--text-3);
  border-bottom: 1px solid var(--border);
}
.waypoint-list {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
  min-height: 0;
  max-height: 340px;
  overflow-y: auto;
}
.waypoint-empty {
  padding: 20px 14px;
  font-size: 11px;
  color: var(--text-3);
  text-align: center;
  line-height: 1.6;
}
.waypoint-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
}
.waypoint-num {
  flex-shrink: 0;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  display: flex; align-items: center; justify-content: center;
  font-size: 9px;
  font-weight: 700;
  font-family: var(--mono);
}
.waypoint-coords {
  flex: 1;
  min-width: 0;
  font-family: var(--mono);
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.waypoint-item-actions { display: flex; gap: 2px; flex-shrink: 0; }
.waypoint-item-actions button {
  width: 20px; height: 20px;
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-3);
  font-size: 9px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: color 140ms var(--ease), border-color 140ms var(--ease);
}
.waypoint-item-actions button:hover:not(:disabled) { color: var(--text); border-color: var(--text-3); }
.waypoint-item-actions button:disabled { opacity: 0.25; cursor: not-allowed; }

.waypoint-actions {
  display: flex;
  gap: 1px;
  background: var(--border);
  border-top: 1px solid var(--border);
}
.waypoint-actions button {
  flex: 1;
  padding: 10px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.2px;
  cursor: pointer;
  border: none;
  font-family: var(--sans);
}
#waypointSaveBtn { background: var(--text); color: #000; }
#waypointSaveBtn:hover { opacity: 0.85; }
.waypoint-btn-secondary { background: var(--surface-2); color: var(--text-2); }
.waypoint-btn-secondary:hover { color: var(--text); }

/* Leaflet map controls need light-on-dark tuning to fit the theme */
.leaflet-container { background: #0a0a0a; font-family: var(--sans); }
.leaflet-control-attribution {
  background: rgba(5,5,5,0.75) !important;
  color: var(--text-3) !important;
  font-size: 9px !important;
}
.leaflet-control-attribution a { color: var(--text-2) !important; }
.leaflet-control-zoom a {
  background: var(--surface-2) !important;
  color: var(--text) !important;
  border-color: var(--border-strong) !important;
}
.leaflet-control-zoom a:hover { background: var(--surface-3) !important; }

.waypoint-marker-inner {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--ok);
  color: var(--text);
  display: flex; align-items: center; justify-content: center;
  font-size: 10px;
  font-weight: 700;
  font-family: var(--mono);
  box-shadow: 0 2px 8px rgba(0,0,0,0.6);
}

.power-page-wrap {
  max-width: 920px;
  margin: 0 auto;
  padding: 40px 20px 60px;
  display: flex;
  justify-content: center;
}
.power-wrap {
  display: flex;
  gap: 1px;
  background: var(--border);
  width: 100%;
  max-width: 820px;
}
.power-visual-panel { flex: 0 0 320px; }
.power-detail-panel { flex: 1; min-width: 0; }
.power-visual-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 44px 24px 36px;
}

.battery-visual { display: flex; flex-direction: column; align-items: center; }
.battery-visual-cap {
  width: 46px; height: 12px;
  background: var(--border-strong);
  border-radius: 4px 4px 0 0;
}
.battery-visual-shell {
  position: relative;
  width: 124px; height: 240px;
  border: 3px solid var(--border-strong);
  border-radius: 8px;
  overflow: hidden;
  background: #050505;
  display: flex;
  align-items: flex-end;
}

.battery-fill {
  width: 100%;
  height: 0%;
  position: relative;
  overflow: hidden;
  background: linear-gradient(180deg, var(--ok), var(--ok-dim));
  transition: height 900ms var(--ease), background 400ms var(--ease);
}
.battery-fill::before {
  content: "";
  position: absolute; inset: -20px 0 0 0;
  background: repeating-linear-gradient(
    180deg,
    rgba(255,255,255,0.10) 0px,
    rgba(255,255,255,0.10) 2px,
    transparent 2px,
    transparent 9px
  );
  animation: battery-flow 1.1s linear infinite;
}
@keyframes battery-flow {
  from { transform: translateY(-20px); }
  to { transform: translateY(0); }
}
.battery-fill.charging::before { animation-direction: reverse; }

.battery-fill.warn { background: linear-gradient(180deg, var(--warn), var(--warn-dim)); }
.battery-fill.danger {
  background: linear-gradient(180deg, var(--danger), var(--danger-dim));
  animation: battery-critical-pulse 1.1s ease-in-out infinite;
}
@keyframes battery-critical-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.55; } }

.battery-bolt {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 36px; height: 36px;
  color: #fff;
  filter: drop-shadow(0 0 8px rgba(255,255,255,0.65));
  opacity: 0;
  transition: opacity 300ms var(--ease);
  pointer-events: none;
}

.battery-percent-big {
  font-family: var(--mono);
  font-size: 44px;
  font-weight: 800;
  letter-spacing: 0.5px;
  margin-top: 24px;
}
.battery-endurance-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.6px;
  color: var(--text-3);
  text-transform: uppercase;
  margin-top: 20px;
}
.battery-endurance-value {
  font-family: var(--mono);
  font-size: 24px;
  font-weight: 700;
  margin-top: 6px;
}

@media (max-width: 700px) {
  .power-wrap { flex-direction: column; }
  .power-visual-panel { flex: none; }
}

/* ══════════════════════════════════════════════════════════════════════
   Phone-width pass (iPhone portrait/landscape and similarly narrow
   Android). The breakpoints above this point handle tablet-ish widths;
   these handle the cases where THREE side panels or a map+list split
   that looked fine at 900px are actually unusable squeezed into ~390px.
   ══════════════════════════════════════════════════════════════════════ */
@media (max-width: 640px) {
  /* Command/Drive tabs: at ≤980px .command-side already went row-wise
     (fine on a tablet) — on an actual phone three panels side-by-side
     leaves each one too narrow to read. Stack them instead. */
  .command-side { flex-direction: column !important; max-width: none; }
  .command-side .panel, .command-side .side-panel { width: 100%; }

  /* Mission tab: map+list side-by-side only works with real width to
     split; below that the map shrinks to the point it's not usable. */
  .waypoint-layout { flex-direction: column; }
  .waypoint-list-wrap { width: 100%; border-left: none; border-top: 1px solid var(--border); }
  .waypoint-map { height: 260px; }
  .waypoint-list { max-height: 220px; }

  /* Topbar: Mission/Mode/Uplink/Local doesn't fit next to the brand and
     Reports/Users/Logout on a 390px screen — that detail is one tab away
     (Mission, Diagnostics), so it's a reasonable thing to hide here
     rather than force a cramped horizontal scroller front and center. */
  .topbar-mid { display: none; }
  .brand-sub { display: none; }
  header.topbar { padding-left: calc(14px + var(--safe-left)); padding-right: calc(14px + var(--safe-right)); gap: 6px; }
  .topbar-right { gap: 2px; }
  .topbar-link { padding: 8px 7px; font-size: 9px; }
  .topbar-link .icon { font-size: 12px; }

  /* Sidebar: narrower, tighter labels — still vertical (not converted to
     a bottom tab bar) because the footer status bar already owns the
     bottom edge and Emergency Stop needs to stay the only thing fixed
     there, not compete with nav for space. */
  nav.sidebar { width: 56px; }
  .sidebar .nav-item { font-size: 7.5px; padding: 11px 2px; gap: 5px; }
  .sidebar .nav-item .icon { font-size: 16px; }
  .sidebar-footer { font-size: 6.5px; padding: 8px 4px 12px; }

  /* Footer status bar: keep Emergency Stop fully visible and tappable;
     let the system-health readouts scroll under a thumb instead of
     shrinking to illegibility. */
  .btn-footer { padding: 7px 9px; font-size: 9px; }
  .btn-footer .icon { font-size: 11px; }

  /* Login: edge-to-edge safe margins instead of a fixed 320px box that
     can clip against the safe-area on the narrowest phones. */
  .login-wrap { padding: 20px calc(16px + var(--safe-left)) 20px calc(16px + var(--safe-right)); }
  .login-box { width: 100%; max-width: 320px; padding: 32px 24px; }

  /* Fleet page header: count badge + pair button wrap instead of
     overflowing when the page title is also fighting for width. */
  .page-head { flex-wrap: wrap; gap: 12px; }
  .page-head-actions { width: 100%; justify-content: space-between; }

  /* Power tab's two-panel layout and the Diagnostics stability banner
     both read better full-width and stacked below ~400px even though
     their existing breakpoints already collapse the grid. */
  .stability-banner { flex-direction: column; align-items: flex-start; gap: 12px; padding: 18px 20px; }
  .stability-score { font-size: 36px; }

  /* Any table wider than its container scrolls horizontally in its own
     lane instead of forcing the whole page to scroll sideways. */
  .panel-body:has(table.log) { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table.log { min-width: 560px; }
}

/* Larger tap targets + no iOS double-tap-to-zoom on anything clickable. */
button, a, .nav-item, .drive-btn, .topbar-link, .btn-footer,
.view-toggle button, .waypoint-item-actions button {
  touch-action: manipulation;
}
