/* ===== APP SHELL ===== */
.app-body {
  overflow: hidden;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ===== NAV ===== */
.app-nav {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  height: 52px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 100;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--fg-primary);
  text-decoration: none;
  margin-right: 8px;
}

.nav-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--accent);
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: 0.06em;
}

.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  animation: blink 1.8s ease-in-out infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.2; }
}

.nav-actions { margin-left: auto; }

.btn-icon {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--accent-dim);
  border: 1px solid rgba(0,229,153,0.25);
  color: var(--accent);
  font-family: var(--font-display);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-icon:hover { background: rgba(0,229,153,0.2); }

/* ===== MAIN LAYOUT ===== */
.app-layout {
  display: grid;
  grid-template-columns: 280px 1fr 300px;
  flex: 1;
  overflow: hidden;
}

/* ===== LEFT SIDEBAR ===== */
.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  overflow: hidden;
}

.sidebar-section {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

.alerts-section { border-top: 1px solid var(--border); max-height: 40%; }

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
  font-family: var(--font-display);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--fg-muted);
  flex-shrink: 0;
}

.count-badge {
  background: var(--bg-card);
  border: 1px solid var(--border);
  font-size: 0.7rem;
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--fg-secondary);
  padding: 1px 7px;
  border-radius: 99px;
}

.alert-badge.has-alerts {
  background: rgba(255, 80, 80, 0.15);
  border-color: rgba(255, 80, 80, 0.4);
  color: #ff6b6b;
}

/* ===== TRACKER LIST ===== */
.tracker-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 8px;
}

.tracker-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px;
  padding: 12px 12px;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  margin-bottom: 4px;
  transition: background 0.15s, border-color 0.15s;
}

.tracker-card:hover { background: var(--bg-card); }

.tracker-card.active {
  background: var(--accent-dim);
  border-color: rgba(0,229,153,0.3);
}

.tracker-name {
  font-family: var(--font-display);
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--fg-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tracker-meta {
  font-size: 0.75rem;
  color: var(--fg-muted);
  margin-top: 2px;
}

.tracker-battery {
  display: flex;
  align-items: center;
  gap: 4px;
  font-family: var(--font-display);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--fg-muted);
  justify-self: end;
  align-self: start;
  margin-top: 2px;
}

.battery-bar {
  width: 20px;
  height: 8px;
  border: 1px solid var(--fg-muted);
  border-radius: 2px;
  position: relative;
  overflow: hidden;
}

.battery-fill {
  height: 100%;
  background: var(--accent);
  transition: width 0.3s;
}

.battery-fill.low { background: #ff6b6b; }
.battery-fill.medium { background: #f59e0b; }

/* Skeleton loading */
.skeleton-item {
  height: 58px;
  background: var(--bg-card);
  border-radius: 8px;
  margin-bottom: 4px;
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  0% { opacity: 0.4; }
  50% { opacity: 0.7; }
  100% { opacity: 0.4; }
}

/* ===== ALERTS ===== */
.alert-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 8px;
}

.empty-state {
  font-size: 0.8rem;
  color: var(--fg-muted);
  text-align: center;
  padding: 20px 12px;
  line-height: 1.6;
}

.alert-item {
  display: flex;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 6px;
  margin-bottom: 4px;
  background: var(--bg-card);
  border-left: 3px solid transparent;
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(-8px); }
  to { opacity: 1; transform: translateX(0); }
}

.alert-item.exit { border-left-color: #ff6b6b; }
.alert-item.enter { border-left-color: var(--accent); }

.alert-icon { font-size: 1rem; flex-shrink: 0; }

.alert-body { min-width: 0; }

.alert-title {
  font-size: 0.78rem;
  font-family: var(--font-display);
  font-weight: 600;
  color: var(--fg-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.alert-time {
  font-size: 0.7rem;
  color: var(--fg-muted);
}

/* ===== MAP ===== */
.map-container {
  position: relative;
  overflow: hidden;
}

#map {
  width: 100%;
  height: 100%;
  background: var(--bg-primary);
}

/* Dark Leaflet tiles */
.leaflet-tile-pane {
  filter: brightness(0.7) saturate(0.8);
}

/* Map controls overlay */
.map-controls {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  z-index: 1000;
}

.map-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--fg-secondary);
  font-family: var(--font-display);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: all 0.2s;
}

.map-btn:hover {
  border-color: rgba(0,229,153,0.3);
  color: var(--fg-primary);
}

.map-btn.active {
  background: var(--accent-dim);
  border-color: rgba(0,229,153,0.4);
  color: var(--accent);
}

.map-btn.drawing {
  background: rgba(255,165,0,0.12);
  border-color: rgba(255,165,0,0.4);
  color: #ffb347;
  animation: pulse-btn 1.5s ease-in-out infinite;
}

@keyframes pulse-btn {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.65; }
}

/* Draw mode banner */
.draw-banner {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 18px;
  background: rgba(22, 22, 31, 0.95);
  border: 1px solid rgba(255,165,0,0.4);
  border-radius: 8px;
  font-size: 0.82rem;
  color: #ffb347;
  font-family: var(--font-display);
  font-weight: 500;
  z-index: 1000;
  backdrop-filter: blur(8px);
}

.draw-banner.hidden { display: none; }

.btn-cancel {
  background: none;
  border: 1px solid rgba(255,165,0,0.4);
  color: #ffb347;
  font-family: var(--font-display);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 4px;
  cursor: pointer;
}

/* Custom Leaflet marker */
.tracker-marker {
  background: var(--accent);
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 3px solid var(--bg-primary);
  box-shadow: 0 0 0 2px var(--accent), 0 0 12px var(--accent-glow);
}

.tracker-marker.offline {
  background: var(--fg-muted);
  box-shadow: none;
}

/* ===== RIGHT DETAIL PANEL ===== */
.detail-panel {
  background: var(--bg-secondary);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.detail-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--fg-muted);
  font-size: 0.85rem;
  text-align: center;
  line-height: 1.6;
  padding: 40px 20px;
}

.detail-content { padding: 20px; }
.detail-content.hidden { display: none; }

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

.detail-name {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--fg-primary);
}

.detail-label {
  font-size: 0.75rem;
  color: var(--accent);
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: 0.08em;
  margin-top: 2px;
}

.btn-danger-sm {
  background: rgba(255, 80, 80, 0.08);
  border: 1px solid rgba(255, 80, 80, 0.25);
  color: #ff6b6b;
  border-radius: 6px;
  padding: 6px 8px;
  cursor: pointer;
  transition: background 0.2s;
  display: flex;
  align-items: center;
}

.btn-danger-sm:hover { background: rgba(255, 80, 80, 0.2); }

.detail-coords {
  font-family: var(--font-display);
  font-size: 0.78rem;
  color: var(--fg-muted);
  margin-bottom: 16px;
  letter-spacing: 0.04em;
}

.detail-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 20px;
}

.stat-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  text-align: center;
}

.stat-val {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  color: var(--fg-primary);
}

.stat-key {
  font-size: 0.68rem;
  color: var(--fg-muted);
  margin-top: 2px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.detail-section-heading {
  font-family: var(--font-display);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--fg-muted);
  margin-bottom: 8px;
}

.detail-geofence-list { margin-bottom: 10px; }

.geofence-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  margin-bottom: 4px;
  font-size: 0.8rem;
}

.geofence-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.geofence-name {
  flex: 1;
  font-family: var(--font-display);
  font-weight: 500;
  color: var(--fg-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.geofence-radius {
  font-size: 0.72rem;
  color: var(--fg-muted);
}

.geofence-del {
  background: none;
  border: none;
  color: var(--fg-muted);
  cursor: pointer;
  padding: 2px;
  border-radius: 3px;
  transition: color 0.2s;
  line-height: 1;
  font-size: 0.8rem;
}

.geofence-del:hover { color: #ff6b6b; }

.detail-last-seen {
  font-size: 0.8rem;
  color: var(--fg-muted);
  margin-bottom: 20px;
}

/* ===== BUTTONS ===== */
.btn-primary {
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: 6px;
  padding: 9px 20px;
  font-family: var(--font-display);
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.2s;
}

.btn-primary:hover { opacity: 0.85; }

.btn-outline {
  background: none;
  border: 1px solid var(--border);
  color: var(--fg-secondary);
  border-radius: 6px;
  padding: 9px 20px;
  font-family: var(--font-display);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-outline:hover {
  border-color: rgba(0,229,153,0.3);
  color: var(--fg-primary);
}

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

/* ===== MODALS ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-overlay.hidden { display: none; }

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 420px;
  max-width: 95vw;
  overflow: hidden;
  animation: modal-in 0.2s ease;
}

@keyframes modal-in {
  from { opacity: 0; transform: scale(0.95) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  color: var(--fg-primary);
}

.modal-close {
  background: none;
  border: none;
  color: var(--fg-muted);
  font-size: 1rem;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: color 0.2s;
}

.modal-close:hover { color: var(--fg-primary); }

.modal-body { padding: 20px; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 20px 18px;
  border-top: 1px solid var(--border);
}

.form-label {
  display: block;
  font-family: var(--font-display);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--fg-secondary);
  margin-bottom: 6px;
  margin-top: 14px;
}

.form-label:first-child { margin-top: 0; }

.req { color: var(--accent); }

.form-input {
  width: 100%;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 9px 12px;
  color: var(--fg-primary);
  font-family: var(--font-body);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s;
}

.form-input:focus { border-color: rgba(0,229,153,0.4); }

select.form-input { cursor: pointer; }

.form-range {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}

.range-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--fg-muted);
  margin-top: 4px;
}

.form-hint {
  font-size: 0.75rem;
  color: var(--fg-muted);
  margin-top: 12px;
  line-height: 1.5;
}

/* ===== LEAFLET OVERRIDES ===== */
.leaflet-container { background: var(--bg-primary); }
.leaflet-control-zoom a {
  background: var(--bg-card) !important;
  color: var(--fg-primary) !important;
  border-color: var(--border) !important;
}
.leaflet-control-zoom a:hover { background: var(--bg-secondary) !important; }
.leaflet-popup-content-wrapper {
  background: var(--bg-card);
  color: var(--fg-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: var(--font-display);
  font-size: 0.82rem;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
}
.leaflet-popup-tip { background: var(--bg-card); }
.leaflet-popup-content { margin: 10px 14px; }

/* ===== RESPONSIVE ===== */
@media (max-width: 1024px) {
  .app-layout {
    grid-template-columns: 240px 1fr;
  }
  .detail-panel { display: none; }
}

@media (max-width: 640px) {
  .app-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  .sidebar {
    max-height: 200px;
    flex-direction: row;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .sidebar-section { border-top: none; border-right: 1px solid var(--border); }
  .alerts-section { max-height: unset; }
}
