:root {
  --bg: #0b1220;
  --surface: #111a2e;
  --surface-2: #17233d;
  --border: #253456;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --ok: #10b981;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 12px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

h1, h2, h3, h4 {
  margin: 0;
  font-weight: 600;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.85rem;
}

.stack-sm { display: flex; flex-direction: column; gap: 8px; }
.stack-md { display: flex; flex-direction: column; gap: 14px; }
.stack-lg { display: flex; flex-direction: column; gap: 20px; }

.row-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}
.row-actions.wrap {
  flex-wrap: wrap;
}

.row-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

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

/* Inputs & Buttons */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

label {
  font-size: 0.85rem;
  color: var(--muted);
}

input[type="text"],
input[type="password"],
input[type="number"],
.select-input {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.95rem;
}

input:focus, .select-input:focus {
  outline: none;
  border-color: var(--primary);
}

.select-input {
  width: auto;
  min-width: 180px;
}

.select-input.compact {
  min-width: 130px;
  padding: 6px 10px;
  font-size: 0.85rem;
}

.btn {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  color: #fff;
  background: var(--surface-2);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.btn:hover { opacity: 0.92; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-sm { padding: 6px 10px; font-size: 0.82rem; }
.btn-full { width: 100%; }

.btn-primary { background: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface-2); border-color: var(--border); color: var(--text); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--muted); }
.btn-warn { background: #d97706; }
.btn-danger { background: #dc2626; }
.danger-text { color: #f87171 !important; border-color: rgba(239, 68, 68, 0.35); }
.disabled-link { pointer-events: none; opacity: 0.45; }

.btn-alert-toggle {
  background: #1e293b;
  border: 1px solid var(--warn);
  color: #fbbf24;
  min-width: 180px;
}
.btn-alert-toggle.active {
  background: var(--danger);
  border-color: #f87171;
  color: #fff;
  animation: pulseBorder 1.8s infinite;
}

@keyframes pulseBorder {
  0% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.45); }
  70% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
  100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

/* Login */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 26px;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.brand-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 0 12px rgba(59, 130, 246, 0.7);
  flex-shrink: 0;
}

.alert-banner {
  background: rgba(239, 68, 68, 0.14);
  border: 1px solid rgba(239, 68, 68, 0.45);
  color: #fca5a5;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.88rem;
}

/* Topbar */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-title { font-weight: 700; font-size: 1.05rem; }
.brand-sub { font-size: 0.8rem; color: var(--muted); }

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* Layout */
.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 18px 20px 40px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

/* Status Hero */
.status-hero {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.hero-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.hero-meta {
  color: var(--muted);
  font-size: 0.88rem;
  margin-top: 4px;
}

.alert-mode-box {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  flex-wrap: wrap;
}

.alert-mode-title {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.alert-mode-desc {
  font-size: 0.86rem;
}

/* Pills & Badges */
.pill {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  text-transform: uppercase;
}
.pill-ok { background: rgba(16, 185, 129, 0.16); color: #34d399; border: 1px solid rgba(16, 185, 129, 0.4); }
.pill-warn { background: rgba(245, 158, 11, 0.16); color: #fbbf24; border: 1px solid rgba(245, 158, 11, 0.4); }
.pill-danger { background: rgba(239, 68, 68, 0.18); color: #f87171; border: 1px solid rgba(239, 68, 68, 0.45); }
.pill-muted { background: rgba(148, 163, 184, 0.14); color: #cbd5e1; border: 1px solid rgba(148, 163, 184, 0.3); }

/* Telemetry Grid */
.telemetry-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}

.stat-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.stat-value {
  font-size: 1.28rem;
  font-weight: 700;
  margin-top: 4px;
}

.stat-sub {
  font-size: 0.82rem;
  color: var(--muted);
  margin-top: 2px;
}

/* Main Map + Commands Grid */
.main-grid {
  display: grid;
  grid-template-columns: 1.45fr 1fr;
  gap: 16px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.map-canvas {
  width: 100%;
  height: 360px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #0a101d;
}

.commands-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.cmd-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* Tabs & Feeds */
.tabs-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.tabs {
  display: flex;
  gap: 8px;
}

.tab-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 12px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.tab-btn.active {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text);
}

.badge {
  background: var(--danger);
  color: #fff;
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 0.75rem;
}

.badge-muted {
  background: var(--primary);
}

.feed-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 360px;
  overflow-y: auto;
}

.feed-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.feed-item.unread {
  border-left: 3px solid var(--warn);
}

.feed-title {
  font-weight: 600;
  font-size: 0.93rem;
}

.feed-meta {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 2px;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 2000;
}

.modal-card {
  width: 100%;
  max-width: 580px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.btn-close {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 1.6rem;
  cursor: pointer;
  line-height: 1;
}

.subcard {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}

.pair-box {
  background: var(--bg);
  border: 1px dashed var(--primary);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.copy-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.big-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1.55rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  color: #60a5fa;
}

.checklist {
  margin: 4px 0 0 18px;
  padding: 0;
  font-size: 0.88rem;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.toast-area {
  position: fixed;
  bottom: 18px;
  right: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 3000;
}

.toast {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.88rem;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.45);
}

.toast.error { border-left-color: var(--danger); }
.toast.ok { border-left-color: var(--ok); }

@media (max-width: 960px) {
  .telemetry-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .main-grid { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .telemetry-grid { grid-template-columns: 1fr; }
  .cmd-grid { grid-template-columns: 1fr; }
  .form-grid-3 { grid-template-columns: 1fr; }
  .map-canvas { height: 280px; }
}
