/* ============================================
   SearchGuard — Premium Dark Mode Styles
   ============================================ */

:root {
  --bg-primary: #0f1117;
  --bg-secondary: #1a1d27;
  --bg-tertiary: #242837;
  --bg-glass: rgba(26, 29, 39, 0.85);
  --bg-glass-hover: rgba(36, 40, 55, 0.9);

  --text-primary: #f0f2f5;
  --text-secondary: #a0a6b4;
  --text-muted: #6b7280;

  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-glow: rgba(99, 102, 241, 0.25);

  --danger: #ef4444;
  --danger-hover: #f87171;
  --warning: #f59e0b;
  --success: #22c55e;

  --zone-unsearched: #ef4444;
  --zone-progress: #f59e0b;
  --zone-searched: #22c55e;

  --border: rgba(255, 255, 255, 0.08);
  --border-hover: rgba(255, 255, 255, 0.15);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.5);

  --sidebar-width: 360px;
  --topbar-height: 56px;

  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
  --transition-smooth: 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  overflow: hidden;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}

/* ============ Topbar ============ */

#topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topbar-height);
  background: var(--bg-glass);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 1000;
}

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

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-icon {
  color: var(--accent);
  filter: drop-shadow(0 0 8px var(--accent-glow));
}

.brand-name {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.topbar-center {
  display: flex;
  align-items: center;
}

#stats-bar {
  display: flex;
  gap: 24px;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}

.stat-value {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
}

.stat-label {
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

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

/* ============ Icon Buttons ============ */

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.icon-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-color: var(--border-hover);
}

/* ============ Sidebar ============ */

#sidebar {
  position: fixed;
  top: var(--topbar-height);
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--bg-glass);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border-right: 1px solid var(--border);
  z-index: 900;
  display: flex;
  flex-direction: column;
  transform: translateX(0);
  transition: transform var(--transition-smooth);
  overflow: hidden;
}

#sidebar.closed {
  transform: translateX(-100%);
}

.sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  padding: 0 8px;
  flex-shrink: 0;
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 4px 10px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.68rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition-fast);
  border-bottom: 2px solid transparent;
  position: relative;
}

.tab:hover {
  color: var(--text-secondary);
}

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-panel {
  display: none;
  flex: 1;
  flex-direction: column;
  overflow-y: auto;
  padding: 16px;
}

.tab-panel.active {
  display: flex;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  flex-shrink: 0;
}

.panel-header h2 {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.panel-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 8px;
}

.panel-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 20px;
  gap: 8px;
  color: var(--text-muted);
}

.empty-state p {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.empty-state span {
  font-size: 0.78rem;
}

/* ============ Zone Cards ============ */

.zone-card {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  cursor: pointer;
  transition: all var(--transition-fast);
  position: relative;
  overflow: hidden;
}

.zone-card::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
}

.zone-card[data-status="unsearched"]::before {
  background: var(--zone-unsearched);
}

.zone-card[data-status="in-progress"]::before {
  background: var(--zone-progress);
}

.zone-card[data-status="searched"]::before {
  background: var(--zone-searched);
}

.zone-card:hover {
  border-color: var(--border-hover);
  background: var(--bg-glass-hover);
  transform: translateY(-1px);
}

.zone-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.zone-card-name {
  font-weight: 600;
  font-size: 0.88rem;
}

.zone-card-status {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.zone-card-status.unsearched {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
}

.zone-card-status.in-progress {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
}

.zone-card-status.searched {
  background: rgba(34, 197, 94, 0.15);
  color: #4ade80;
}

.zone-card-meta {
  display: flex;
  gap: 12px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* ============ Team Cards ============ */

.team-card {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: all var(--transition-fast);
}

.team-card:hover {
  border-color: var(--border-hover);
  background: var(--bg-glass-hover);
}

.team-color-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 8px currentColor;
}

.team-info {
  flex: 1;
}

.team-name {
  font-weight: 600;
  font-size: 0.88rem;
}

.team-zones-count {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.team-remove {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.team-remove:hover {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
}

/* ============ Forms ============ */

.panel-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

input[type="text"],
input[type="number"],
input[type="datetime-local"],
textarea,
select {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.88rem;
  font-family: inherit;
  color: var(--text-primary);
  transition: border-color var(--transition-fast);
  outline: none;
  width: 100%;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.form-row {
  display: flex;
  gap: 8px;
}

/* ============ Buttons ============ */

.btn {
  padding: 10px 18px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition-fast);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.78rem;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: 0 0 20px var(--accent-glow);
}

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--bg-glass-hover);
  border-color: var(--border-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.25);
  color: var(--danger-hover);
}

/* ============ Modal ============ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  animation: fadeIn 0.2s ease;
}

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

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  width: 90%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.25s ease;
}

.modal h3 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 20px;
}

.modal-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 20px;
}

.modal-actions .spacer {
  flex: 1;
}

/* ============ Color Swatches ============ */

.color-options {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.color-swatch {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 3px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.color-swatch:hover {
  transform: scale(1.1);
}

.color-swatch.active {
  border-color: var(--text-primary);
  box-shadow: 0 0 12px rgba(255, 255, 255, 0.2);
}

/* ============ Layer Switcher ============ */

.dropdown {
  position: fixed;
  top: calc(var(--topbar-height) + 8px);
  right: 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-md);
  z-index: 1100;
  animation: slideDown 0.15s ease;
}

.dropdown.hidden {
  display: none;
}

.dropdown-item {
  display: block;
  width: 100%;
  padding: 10px 16px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition: background var(--transition-fast);
}

.dropdown-item:hover {
  background: var(--bg-tertiary);
}

.dropdown-item.active {
  color: var(--accent);
  font-weight: 600;
}

/* ============ Divider ============ */

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 8px 0;
}

/* Map positioning handled by #map-wrapper section below */

/* Override Leaflet styles for dark mode */
.leaflet-control-zoom a {
  background: var(--bg-secondary) !important;
  color: var(--text-primary) !important;
  border-color: var(--border) !important;
  transition: background var(--transition-fast) !important;
}

.leaflet-control-zoom a:hover {
  background: var(--bg-tertiary) !important;
}

.leaflet-bar {
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-sm) !important;
  box-shadow: var(--shadow-sm) !important;
  overflow: hidden;
}

.leaflet-draw-toolbar a {
  background-color: var(--bg-secondary) !important;
  color: var(--text-primary) !important;
  border-color: var(--border) !important;
}

.leaflet-draw-toolbar a:hover {
  background-color: var(--bg-tertiary) !important;
}

.leaflet-popup-content-wrapper {
  background: var(--bg-secondary) !important;
  color: var(--text-primary) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-md) !important;
  box-shadow: var(--shadow-md) !important;
}

.leaflet-popup-tip {
  background: var(--bg-secondary) !important;
  border: 1px solid var(--border) !important;
  box-shadow: none !important;
}

.leaflet-popup-close-button {
  color: var(--text-muted) !important;
}

.leaflet-popup-close-button:hover {
  color: var(--text-primary) !important;
}

.leaflet-control-attribution {
  background: rgba(15, 17, 23, 0.7) !important;
  color: var(--text-muted) !important;
  font-size: 10px !important;
}

.leaflet-control-attribution a {
  color: var(--text-secondary) !important;
}

/* Draw toolbar icons fix */
.leaflet-draw-toolbar .leaflet-draw-draw-polygon,
.leaflet-draw-toolbar .leaflet-draw-draw-rectangle,
.leaflet-draw-toolbar .leaflet-draw-draw-circle,
.leaflet-draw-toolbar .leaflet-draw-draw-marker,
.leaflet-draw-toolbar .leaflet-draw-edit-edit,
.leaflet-draw-toolbar .leaflet-draw-edit-remove {
  background-size: 300px 30px !important;
}

/* Popup styling */
.zone-popup {
  min-width: 200px;
}

.zone-popup h4 {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.zone-popup .popup-status {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.zone-popup .popup-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 10px;
  line-height: 1.5;
}

.zone-popup .popup-actions {
  display: flex;
  gap: 6px;
}

.popup-btn {
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.popup-btn:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ============ Compass ============ */

.leaflet-compass-control {
  pointer-events: none;
}

.compass-rose {
  pointer-events: auto;
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: rgba(15, 17, 23, 0.7);
  backdrop-filter: blur(12px) saturate(150%);
  -webkit-backdrop-filter: blur(12px) saturate(150%);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow:
    0 4px 20px rgba(0, 0, 0, 0.4),
    inset 0 0 30px rgba(0, 0, 0, 0.2),
    0 0 15px rgba(239, 68, 68, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  cursor: default;
}

.compass-rose:hover {
  transform: scale(1.05);
  box-shadow:
    0 4px 24px rgba(0, 0, 0, 0.5),
    inset 0 0 30px rgba(0, 0, 0, 0.2),
    0 0 20px rgba(239, 68, 68, 0.15);
}

.compass-ring {
  display: flex;
  align-items: center;
  justify-content: center;
}

.compass-ring svg {
  display: block;
}

/* ============ Map Wrapper (Rotation) ============ */

#map-wrapper {
  position: fixed;
  top: var(--topbar-height);
  left: var(--sidebar-width);
  right: 0;
  bottom: 0;
  z-index: 1;
  transition: left var(--transition-smooth);
  overflow: hidden;
}

#sidebar.closed~#map-wrapper {
  left: 0;
}

#map {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  transition: transform 0.15s ease;
  transform-origin: center center;
}

/* ============ Coordinate Readout Bar ============ */

#coord-bar {
  position: fixed;
  bottom: 0;
  right: 0;
  left: var(--sidebar-width);
  height: 28px;
  background: rgba(15, 17, 23, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  z-index: 100;
  font-size: 0.72rem;
  font-family: 'Inter', monospace;
  color: var(--text-muted);
  transition: left var(--transition-smooth);
}

#sidebar.closed~#coord-bar {
  left: 0;
}

.coord-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.coord-item svg {
  opacity: 0.5;
}

.coord-item span {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.coord-divider {
  width: 1px;
  height: 14px;
  background: var(--border);
}

.coord-hint {
  margin-left: auto;
  font-size: 0.65rem;
  color: var(--text-muted);
  opacity: 0.6;
  font-style: italic;
}

/* ============ Measurement Display ============ */

#measure-display {
  position: fixed;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-secondary);
  border: 1px solid var(--accent);
  border-radius: var(--radius-md);
  padding: 10px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 1200;
  box-shadow: 0 4px 24px rgba(99, 102, 241, 0.2);
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-primary);
  animation: slideUp 0.2s ease;
}

#measure-display.hidden {
  display: none;
}

.measure-close {
  width: 24px;
  height: 24px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.measure-close:hover {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
}

/* Measure button active state */
.icon-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
}

/* ============ Search History Timeline ============ */

.zone-card-history {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
}

.history-entry {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.68rem;
  color: var(--text-muted);
}

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

.history-dot.unsearched {
  background: var(--zone-unsearched);
}

.history-dot.in-progress {
  background: var(--zone-progress);
}

.history-dot.searched {
  background: var(--zone-searched);
}

.history-dot.created {
  background: var(--accent);
}

.history-time {
  font-variant-numeric: tabular-nums;
  opacity: 0.7;
}

/* ============ Animations ============ */

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.6;
  }
}

/* ============ Scrollbar ============ */

::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-hover);
}

/* ============ Responsive ============ */

@media (max-width: 768px) {
  :root {
    --sidebar-width: 100%;
  }

  #sidebar {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 50vh;
    border-right: none;
    border-top: 1px solid var(--border);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    transform: translateY(0);
  }

  #sidebar.closed {
    transform: translateY(100%);
  }

  #map-wrapper {
    left: 0;
    bottom: 50vh;
  }

  #sidebar.closed~#map-wrapper {
    bottom: 0;
  }

  #stats-bar {
    display: none;
  }

  #coord-bar {
    left: 0;
  }
}

/* Incident marker pulse */
.incident-marker-icon {
  position: relative;
}

.incident-marker-icon::after {
  content: '';
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: var(--danger);
  animation: pulse 2s ease-in-out infinite;
  opacity: 0.4;
  top: 0;
  left: 0;
}