/* ── Reset & Variables ────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0b0d17;
  --surface: #141824;
  --surface2: #1c2133;
  --border: #2a2f45;
  --text: #e4e6f0;
  --text2: #8b90a8;
  --green: #22c55e;
  --red: #ef4444;
  --amber: #f59e0b;
  --accent: #6366f1;
  --radius: 12px;
}

html { font-size: 16px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

/* ══════════════════════════════════════════════════════════════════════════
   MOBILE DETECTOR PAGE
   ══════════════════════════════════════════════════════════════════════════ */

/* ── Header ──────────────────────────────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.header .logo {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #818cf8);
  display: grid; place-items: center;
  font-size: 16px; color: #fff;
}
.header h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.3px;
}

/* ── Device name bar ─────────────────────────────────────────────────────── */
.device-name-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.device-name-bar label {
  font-size: 0.78rem;
  color: var(--text2);
  white-space: nowrap;
}
.device-name-input {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 600;
  padding: 6px 10px;
  outline: none;
  transition: border-color 0.2s;
}
.device-name-input:focus {
  border-color: var(--accent);
}

/* ── App description ─────────────────────────────────────────────────────── */
.app-desc {
  font-size: 0.82rem;
  color: var(--text2);
  line-height: 1.5;
}

/* ── Status bar (inline inside content) ──────────────────────────────────── */
.status-bar-inline {
  display: flex;
  gap: 20px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.8rem;
  color: var(--text2);
}
.status-item {
  display: flex; align-items: center; gap: 5px;
}
.indicator {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #555;
  transition: background 0.3s;
}
.indicator.on { background: var(--green); box-shadow: 0 0 6px var(--green); }

/* ── Tab container ───────────────────────────────────────────────────────── */
.tab-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.tab-bar {
  display: flex;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
}
.tab-btn {
  flex: 1;
  padding: 12px 8px;
  border: none;
  background: transparent;
  color: var(--text2);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.2s, background 0.2s;
  position: relative;
}
.tab-btn:not(:last-child) {
  border-right: 1px solid var(--border);
}
.tab-btn.active {
  color: var(--text);
  background: var(--surface);
}
.tab-btn.active::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 2px;
  background: var(--accent);
}
.tab-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.tab-panel {
  display: none;
  padding: 14px 16px;
  flex-direction: column;
  gap: 14px;
}
.tab-panel.active {
  display: flex;
}

/* ── ML info card ────────────────────────────────────────────────────────── */
.ml-info-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.ml-info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
}
.ml-info-row .label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text2);
}
.ml-badge {
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 0.72rem;
  font-weight: 600;
}
.ml-badge.loading {
  background: rgba(245, 158, 11, 0.15);
  color: var(--amber);
}
.ml-badge.ready {
  background: rgba(34, 197, 94, 0.15);
  color: var(--green);
}
.ml-badge.error {
  background: rgba(239, 68, 68, 0.15);
  color: var(--red);
}

/* ── Map on phone page ───────────────────────────────────────────────────── */
.map-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  overflow: hidden;
}
.map-box .label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text2);
  margin-bottom: 8px;
}
.phone-map {
  width: 100%;
  height: 200px;
  border-radius: 8px;
  background: #0a0c14;
}

/* ── Hidden helper ───────────────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Main content ────────────────────────────────────────────────────────── */
.detector-content {
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── Spectrum ────────────────────────────────────────────────────────────── */
.spectrum-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  overflow: hidden;
}
.spectrum-box .label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text2);
  margin-bottom: 8px;
}
.spectrum-wrap {
  width: 100%;
  height: 120px;
  position: relative;
}
.spectrum-wrap canvas {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 6px;
  background: #0a0c14;
}

/* ── Detection badge ─────────────────────────────────────────────────────── */
.detection-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  transition: border-color 0.4s, background 0.4s;
}
.detection-card.detected {
  border-color: var(--red);
  background: rgba(239, 68, 68, 0.08);
}

.detection-dot {
  width: 14px; height: 14px;
  border-radius: 50%;
  display: inline-block;
  vertical-align: middle;
  margin-right: 8px;
  background: var(--green);
  transition: background 0.3s;
}
.detection-card.detected .detection-dot {
  background: var(--red);
  animation: pulse-dot 1s infinite;
}

@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,.5); }
  50%      { box-shadow: 0 0 0 10px rgba(239,68,68,0); }
}

.detection-label {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.5px;
}
.detection-card.detected .detection-label { color: var(--red); }

/* ── Confidence ──────────────────────────────────────────────────────────── */
.confidence {
  margin-top: 14px;
}
.confidence .track {
  height: 8px;
  background: var(--surface2);
  border-radius: 4px;
  overflow: hidden;
}
.confidence .bar {
  height: 100%;
  width: 0%;
  background: var(--green);
  border-radius: 4px;
  transition: width 0.2s;
}
.confidence .bar.mid { background: var(--amber); }
.confidence .bar.high { background: var(--red); }
.confidence .meta {
  display: flex; justify-content: space-between;
  font-size: 0.75rem; color: var(--text2);
  margin-top: 4px;
}

/* ── Profile selector ────────────────────────────────────────────────────── */
.profile-section {
  padding: 0 0 4px;
}
.profile-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.profile-header .label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text2);
}
.btn-sm {
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface2);
  color: var(--text2);
  font-size: 0.7rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}
.btn-sm:active { opacity: 0.8; }
.btn-sm:hover  { border-color: var(--accent); color: var(--text); }

.profile-chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.profile-chips::-webkit-scrollbar { display: none; }

.profile-chip {
  flex-shrink: 0;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface2);
  color: var(--text2);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
}
.profile-chip:active { opacity: 0.8; }
.profile-chip.active {
  border-color: var(--accent);
  background: rgba(99, 102, 241, 0.15);
  color: var(--text);
}
.profile-chip .chip-del {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: rgba(255,255,255,0.1);
  display: grid;
  place-items: center;
  font-size: 0.6rem;
  line-height: 1;
  color: var(--text2);
  transition: background 0.2s, color 0.2s;
}
.profile-chip .chip-del:hover {
  background: var(--red);
  color: #fff;
}

/* ── Settings ────────────────────────────────────────────────────────────── */
.settings {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.tab-panel .settings {
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0;
}
.setting-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.setting-row label {
  font-size: 0.8rem;
  color: var(--text2);
  min-width: 80px;
}
.setting-row input[type=range] {
  flex: 1;
  accent-color: var(--accent);
}
.setting-row .val {
  font-size: 0.8rem;
  font-weight: 600;
  min-width: 55px;
  text-align: right;
}

/* ── Advanced parameters panel ───────────────────────────────────────────── */
.advanced-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.tab-panel .advanced-panel {
  background: var(--surface2);
  border-color: var(--border);
}
.advanced-panel summary {
  padding: 14px 16px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text2);
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: color 0.2s;
}
.advanced-panel summary::-webkit-details-marker { display: none; }
.advanced-panel summary::before {
  content: '';
  display: inline-block;
  width: 6px; height: 6px;
  border-right: 2px solid var(--text2);
  border-bottom: 2px solid var(--text2);
  transform: rotate(-45deg);
  transition: transform 0.2s;
}
.advanced-panel[open] summary::before { transform: rotate(45deg); }
.advanced-panel[open] summary { color: var(--text); border-bottom: 1px solid var(--border); }

.param-grid {
  padding: 12px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.param-group-title {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--accent);
  margin-top: 4px;
  padding-bottom: 2px;
  border-bottom: 1px solid var(--border);
}
.param-grid .setting-row label { min-width: 72px; font-size: 0.75rem; }
.param-grid .setting-row .val  { font-size: 0.75rem; min-width: 60px; }

/* ── Button ──────────────────────────────────────────────────────────────── */
.btn-primary {
  display: block;
  width: 100%;
  padding: 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  cursor: pointer;
  background: linear-gradient(135deg, var(--accent), #818cf8);
  color: #fff;
  transition: opacity 0.2s;
}
.btn-primary:active { opacity: 0.85; }
.btn-primary.active {
  background: linear-gradient(135deg, var(--red), #f87171);
}

/* ── Log ─────────────────────────────────────────────────────────────────── */
.log-box {
  padding: 12px 16px 16px;
  max-height: 180px;
  overflow-y: auto;
  font-size: 0.72rem;
  font-family: 'SF Mono', 'Fira Code', monospace;
  color: var(--text2);
  line-height: 1.6;
}

/* ══════════════════════════════════════════════════════════════════════════
   ADMIN DASHBOARD
   ══════════════════════════════════════════════════════════════════════════ */
.admin-layout {
  display: flex;
  height: 100dvh;
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  width: 320px;
  min-width: 280px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sidebar-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-header h1 { font-size: 1.05rem; font-weight: 700; }
.sidebar-header .conn {
  margin-left: auto;
  font-size: 0.72rem;
  color: var(--text2);
  display: flex; align-items: center; gap: 5px;
}
.sidebar-header .conn .indicator { width: 7px; height: 7px; }

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}
.stat-card {
  background: var(--surface2);
  border-radius: 10px;
  padding: 12px 10px;
  text-align: center;
}
.stat-card .num {
  font-size: 1.6rem;
  font-weight: 800;
  line-height: 1;
}
.stat-card .lbl {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text2);
  margin-top: 4px;
}
.stat-card.phones .num { color: var(--accent); }
.stat-card.detecting .num { color: var(--amber); }
.stat-card.alerts .num { color: var(--red); }

/* Phone list */
.phone-list-header {
  padding: 12px 20px 8px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text2);
}
.phone-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 12px 12px;
}
.phone-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color 0.3s, background 0.3s;
}
.phone-card:hover { border-color: var(--accent); }
.phone-card.detected { border-color: var(--red); background: rgba(239,68,68,0.06); }

.phone-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  font-weight: 600;
}
.phone-card-header .dot {
  width: 8px; height: 8px;
  border-radius: 50%;
}
.dot.green { background: var(--green); }
.dot.red { background: var(--red); animation: pulse-dot 1s infinite; }
.dot.grey { background: #555; }
.phone-card.disconnected { opacity: 0.55; }
.phone-card-header .phone-ago {
  margin-left: auto;
  font-size: 0.68rem;
  color: var(--text2);
  font-weight: 400;
}

.phone-card-body {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--text2);
  margin-top: 4px;
}
.phone-card-conf {
  font-size: 0.72rem;
  color: var(--red);
  margin-top: 4px;
  font-weight: 600;
}
.phone-list .empty {
  text-align: center;
  color: var(--text2);
  padding: 30px 0;
  font-size: 0.85rem;
}

/* ── Map area ────────────────────────────────────────────────────────────── */
.map-area {
  flex: 1;
  position: relative;
}
#map { width: 100%; height: 100%; }

/* Alert banner */
.alert-banner {
  position: absolute;
  top: 16px; left: 50%;
  transform: translateX(-50%) translateY(-60px);
  background: rgba(239, 68, 68, 0.92);
  color: #fff;
  padding: 10px 24px;
  border-radius: 30px;
  font-size: 0.85rem;
  font-weight: 600;
  z-index: 1000;
  backdrop-filter: blur(8px);
  transition: transform 0.4s cubic-bezier(.175,.885,.32,1.275);
  pointer-events: none;
  white-space: nowrap;
}
.alert-banner.visible {
  transform: translateX(-50%) translateY(0);
}

/* Leaflet icon overrides */
.phone-icon {
  background: transparent !important;
  border: none !important;
}
.phone-icon svg { width: 100%; height: 100%; }
.phone-icon.detected svg { filter: drop-shadow(0 0 5px rgba(239,68,68,.6)); }

.drone-icon {
  background: transparent !important;
  border: none !important;
}
.drone-icon svg { width: 100%; height: 100%; filter: drop-shadow(0 0 8px rgba(239,68,68,.7)); }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .admin-layout { flex-direction: column-reverse; }
  .sidebar { width: 100%; min-width: 0; max-height: 40vh; border-right: none; border-top: 1px solid var(--border); }
  .map-area { min-height: 60vh; }
}
