/* ============================================
   SI-ANDI — Sistem Informasi Analisis Demand Internal
   Premium Dark Theme CSS — Desktop + Mobile
   ============================================ */

/* ── CSS Variables ── */
:root {
  --bg-primary: #060a13;
  --bg-secondary: #0c1220;
  --bg-card: #111827;
  --bg-input: #1a2332;
  --bg-hover: #1e293b;
  
  --color-primary: #3b82f6;
  --color-primary-hover: #2563eb;
  --color-primary-glow: rgba(59, 130, 246, 0.3);
  --color-accent: #f59e0b;
  --color-accent-glow: rgba(245, 158, 11, 0.25);
  --color-success: #10b981;
  --color-warning: #f59e0b;
  --color-danger: #ef4444;
  --color-pln: #22c55e;
  
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  --border-color: rgba(148, 163, 184, 0.1);
  --border-active: rgba(59, 130, 246, 0.4);
  
  --sidebar-width: 380px;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 20px var(--color-primary-glow);
  
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);

  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 10px; }

/* ── Loading Overlay ── */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.5s ease, visibility 0.5s ease;
}
.loading-overlay.hidden {
  opacity: 0; visibility: hidden; pointer-events: none;
}
.loading-content { text-align: center; }
.loading-spinner {
  width: 48px; height: 48px;
  border: 3px solid var(--border-color);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 20px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-size: 1.2rem; font-weight: 600; margin-bottom: 6px; }
.loading-subtext { font-size: 0.85rem; color: var(--text-muted); }

/* ── Toast Notifications ── */
.toast-container {
  position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
  z-index: 9999; display: flex; flex-direction: column; gap: 8px;
  max-width: 360px; width: calc(100% - 40px);
}
.toast {
  padding: 12px 18px; border-radius: var(--radius-sm);
  background: var(--bg-card); border: 1px solid var(--border-color);
  color: var(--text-primary); font-size: 0.875rem;
  box-shadow: var(--shadow-lg); animation: slideDown 0.3s ease;
  display: flex; align-items: center; gap: 10px;
  backdrop-filter: blur(10px);
}
.toast.success { border-left: 3px solid var(--color-success); }
.toast.warning { border-left: 3px solid var(--color-warning); }
.toast.error { border-left: 3px solid var(--color-danger); }
.toast.info { border-left: 3px solid var(--color-primary); }
.toast.fade-out { animation: slideUp 0.3s ease forwards; }

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

/* ── App Layout ── */
.app-layout {
  display: flex; height: 100vh; width: 100vw;
}

/* ═══════════════════════════════════════════
   DESKTOP SIDEBAR
   ═══════════════════════════════════════════ */
.sidebar {
  width: var(--sidebar-width); height: 100vh;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex; flex-direction: column;
  z-index: 1000; flex-shrink: 0; position: relative;
}
.sidebar::after {
  content: ''; position: absolute; top: 0; right: -1px;
  width: 1px; height: 100%;
  background: linear-gradient(to bottom, transparent, var(--color-primary-glow), transparent);
  pointer-events: none;
}
.sidebar-inner {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  display: flex; flex-direction: column;
}

/* Sidebar Header */
.sidebar-header {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border-color);
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.08), rgba(245, 158, 11, 0.05));
}
.logo { display: flex; align-items: center; gap: 14px; }
.logo-icon {
  width: 48px; height: 48px; border-radius: var(--radius);
  background: linear-gradient(135deg, var(--color-primary), #6366f1);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem; box-shadow: var(--shadow-glow); flex-shrink: 0;
}
.logo-text h1 {
  font-size: 1.35rem; font-weight: 800; letter-spacing: -0.5px;
  background: linear-gradient(135deg, var(--text-primary), var(--color-primary));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text; line-height: 1.2;
}
.logo-text p { font-size: 0.72rem; color: var(--text-muted); margin-top: 2px; }

/* Sidebar Sections */
.sidebar-section {
  padding: 16px 20px; border-bottom: 1px solid var(--border-color);
}
.section-header { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.section-header.clickable {
  cursor: pointer; user-select: none; transition: var(--transition);
  padding: 4px 0; margin-bottom: 6px;
}
.section-header.clickable:hover { opacity: 0.8; }
.section-icon { font-size: 1rem; flex-shrink: 0; }
.section-header h2 {
  font-size: 0.8rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 1px; color: var(--text-secondary); flex: 1;
}
.toggle-icon { font-size: 0.65rem; color: var(--text-muted); transition: var(--transition); }
.toggle-icon.collapsed { transform: rotate(-90deg); }

/* Form Inputs */
.input-group { margin-bottom: 10px; }
.input-group label {
  display: block; font-size: 0.75rem; font-weight: 500;
  color: var(--text-secondary); margin-bottom: 5px;
}
input[type="number"],
input[type="text"] {
  width: 100%; padding: 10px 14px; font-size: 0.88rem;
  font-family: 'Inter', sans-serif;
  background: var(--bg-input); border: 1px solid var(--border-color);
  border-radius: var(--radius-xs); color: var(--text-primary);
  outline: none; transition: var(--transition);
}
input:focus { border-color: var(--color-primary); box-shadow: 0 0 0 3px var(--color-primary-glow); }
input::placeholder { color: var(--text-muted); }

/* Quick Coordinate Group */
.quick-coord-group {
  display: flex; gap: 6px; margin-bottom: 6px;
}
.quick-coord-group input { flex: 1; }

.btn-action-icon {
  width: 42px; height: 42px; min-width: 42px;
  background: var(--bg-input); border: 1px solid var(--border-color);
  border-radius: var(--radius-xs); color: var(--text-primary);
  font-size: 1rem; cursor: pointer; transition: var(--transition);
  display: flex; align-items: center; justify-content: center;
}
.btn-action-icon:hover { background: var(--bg-hover); border-color: var(--color-primary); }
.btn-action-icon:active { transform: scale(0.95); }
.btn-gps { position: relative; }
.btn-gps.locating {
  animation: gpsFlash 1s ease-in-out infinite;
}
@keyframes gpsFlash {
  0%, 100% { border-color: var(--color-primary); }
  50% { border-color: var(--color-success); background: rgba(16, 185, 129, 0.15); }
}

.coord-format-hint {
  font-size: 0.68rem; color: var(--text-muted); margin-bottom: 10px;
  padding-left: 2px;
}

.input-row { display: flex; gap: 10px; }
.input-row .input-group { flex: 1; }

.coord-details {
  margin-top: 8px; font-size: 0.78rem;
}
.coord-details summary {
  color: var(--text-muted); cursor: pointer; padding: 4px 0;
  user-select: none; font-size: 0.75rem;
}
.coord-details summary:hover { color: var(--text-secondary); }
.coord-details .input-row { margin-top: 8px; }

/* Buttons */
.btn {
  width: 100%; padding: 11px 18px; font-size: 0.88rem;
  font-weight: 600; font-family: 'Inter', sans-serif;
  border: none; border-radius: var(--radius-xs); cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: var(--transition); position: relative; overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
.btn-primary {
  background: linear-gradient(135deg, var(--color-primary), #6366f1);
  color: white; box-shadow: var(--shadow-glow);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 0 30px var(--color-primary-glow); }
.btn-primary:active { transform: translateY(0) scale(0.98); }
.btn-icon { font-size: 1rem; }

.text-btn {
  background: none; border: none; color: var(--color-primary);
  font-family: inherit; font-size: inherit; cursor: pointer;
  text-decoration: underline; padding: 0;
}

/* Search Group */
.search-group { display: flex; gap: 6px; }
.search-group input { flex: 1; }
.btn-search-icon {
  width: 42px; height: 42px; min-width: 42px;
  background: var(--bg-input); border: 1px solid var(--border-color);
  border-radius: var(--radius-xs); color: var(--text-primary);
  font-size: 1.1rem; cursor: pointer; transition: var(--transition);
  display: flex; align-items: center; justify-content: center;
}
.btn-search-icon:hover { background: var(--color-primary); border-color: var(--color-primary); }

/* Search Results */
.search-results {
  margin-top: 8px; display: flex; flex-direction: column; gap: 4px;
  max-height: 200px; overflow-y: auto;
}
.search-result-item {
  padding: 9px 12px; background: var(--bg-input);
  border: 1px solid var(--border-color); border-radius: var(--radius-xs);
  cursor: pointer; transition: var(--transition);
  font-size: 0.8rem; color: var(--text-secondary); line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
}
.search-result-item:hover, .search-result-item:active {
  background: var(--bg-hover); border-color: var(--color-primary); color: var(--text-primary);
}
.search-result-item .result-name { font-weight: 500; color: var(--text-primary); font-size: 0.82rem; }
.search-result-item .result-detail { font-size: 0.72rem; color: var(--text-muted); margin-top: 2px; }

/* Result Card */
.result-card {
  background: var(--bg-card); border: 1px solid var(--border-color);
  border-radius: var(--radius); overflow: hidden; animation: fadeInUp 0.3s ease;
}
@keyframes fadeInUp {
  from { transform: translateY(10px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.result-card-header { padding: 14px 16px; display: flex; align-items: center; gap: 10px; }
.result-card-header.pln {
  background: linear-gradient(135deg, rgba(34, 197, 94, 0.12), rgba(34, 197, 94, 0.04));
  border-bottom: 1px solid rgba(34, 197, 94, 0.2);
}
.result-card-header.non-pln {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.12), rgba(245, 158, 11, 0.04));
  border-bottom: 1px solid rgba(245, 158, 11, 0.2);
}
.result-card-header.outside {
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.12), rgba(239, 68, 68, 0.04));
  border-bottom: 1px solid rgba(239, 68, 68, 0.2);
}
.result-badge {
  padding: 4px 10px; border-radius: 20px; font-size: 0.68rem;
  font-weight: 700; text-transform: uppercase; letter-spacing: 0.8px;
}
.result-badge.pln { background: rgba(34, 197, 94, 0.15); color: var(--color-pln); border: 1px solid rgba(34, 197, 94, 0.3); }
.result-badge.non-pln { background: rgba(245, 158, 11, 0.15); color: var(--color-accent); border: 1px solid rgba(245, 158, 11, 0.3); }
.result-badge.outside { background: rgba(239, 68, 68, 0.15); color: var(--color-danger); border: 1px solid rgba(239, 68, 68, 0.3); }
.result-card-body { padding: 14px 16px; }
.result-info-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 0; border-bottom: 1px solid var(--border-color); font-size: 0.8rem;
}
.result-info-row:last-child { border-bottom: none; }
.result-info-label { color: var(--text-muted); font-weight: 500; }
.result-info-value { color: var(--text-primary); font-weight: 600; font-variant-numeric: tabular-nums; }

/* Legend */
.legend-body {
  max-height: 400px; overflow-y: auto; transition: var(--transition-slow);
  padding-right: 4px;
}
.legend-body.collapsed { max-height: 0; overflow: hidden; }
.legend-list { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }

.legend-uid-group {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm); 
  overflow: hidden;
  transition: var(--transition);
}
.legend-uid-group:hover {
  border-color: rgba(255,255,255,0.1);
  background: rgba(255, 255, 255, 0.03);
}

.legend-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px;
  cursor: pointer; transition: var(--transition);
  font-size: 0.85rem; color: var(--text-primary);
  font-weight: 500; user-select: none;
}
.legend-item:hover { background: rgba(255,255,255,0.04); }

.legend-color { 
  width: 12px; height: 12px; border-radius: 50%; 
  flex-shrink: 0; 
  box-shadow: 0 0 6px var(--border-color); 
}
.legend-name { flex: 1; letter-spacing: 0.3px; }
.legend-count { 
  font-size: 0.7rem; font-weight: 700; color: var(--text-secondary); 
  background: rgba(0,0,0,0.3); padding: 2px 8px; border-radius: 12px; 
}

.legend-chevron {
  font-size: 0.65rem; color: var(--text-muted); transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  flex-shrink: 0; margin-left: 2px;
}
.legend-chevron.expanded { transform: rotate(90deg); color: var(--color-primary); }

.legend-wilus-list {
  max-height: 0; overflow: hidden; transition: max-height 0.4s ease;
  background: rgba(0,0,0,0.2);
}
.legend-wilus-list.expanded { max-height: 1000px; }

.legend-wilus-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px 10px 40px; cursor: pointer; transition: var(--transition);
  font-size: 0.78rem; color: var(--text-secondary);
  border-top: 1px solid rgba(255,255,255,0.02);
}
.legend-wilus-item:hover {
  background: rgba(59, 130, 246, 0.08); color: var(--text-primary);
}
.legend-wilus-item:active { background: rgba(59, 130, 246, 0.15); }

.legend-wilus-dot {
  width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0;
  box-shadow: 0 0 4px currentColor; opacity: 0.8;
}

.legend-wilus-name {
  flex: 1; line-height: 1.4; word-break: break-word; font-weight: 500;
}

.legend-wilus-sub {
  color: var(--text-muted); font-size: 0.7rem; font-weight: 400; margin-left: 4px;
}

.legend-wilus-returned {
  color: var(--color-danger); font-weight: 800; font-size: 0.85rem; margin-left: 6px;
}

.legend-item-pln { 
  display: flex; align-items: center; gap: 12px; padding: 10px 14px;
  border-radius: var(--radius-sm); margin-top: 8px;
  background: rgba(34, 197, 94, 0.05); border: 1px solid rgba(34, 197, 94, 0.15);
  font-size: 0.85rem; font-weight: 600; color: var(--color-pln);
}
.legend-item-pln .legend-color { background: var(--color-pln); box-shadow: 0 0 8px rgba(34, 197, 94, 0.4); }
.legend-item-pln .legend-count { background: rgba(34, 197, 94, 0.15); color: var(--color-pln); }

/* Sidebar Footer */
.sidebar-footer { padding: 14px 20px; border-top: 1px solid var(--border-color); margin-top: auto; }
.sidebar-footer p { font-size: 0.7rem; color: var(--text-muted); text-align: center; }
.footer-hint { margin-top: 3px; color: var(--color-primary) !important; font-weight: 500; }

/* ═══════════════════════════════════════════
   MAP
   ═══════════════════════════════════════════ */
.map-container { flex: 1; position: relative; overflow: hidden; }
#map { width: 100%; height: 100%; background: var(--bg-primary); }

/* Leaflet overrides */
.leaflet-container { font-family: 'Inter', sans-serif; }
.leaflet-control-zoom { border: none !important; box-shadow: var(--shadow-md) !important; }
.leaflet-control-zoom a {
  background: var(--bg-card) !important; color: var(--text-primary) !important;
  border: 1px solid var(--border-color) !important;
  width: 36px !important; height: 36px !important; line-height: 36px !important; font-size: 16px !important;
}
.leaflet-control-zoom a:hover { background: var(--bg-hover) !important; }
.leaflet-control-attribution {
  background: rgba(12, 18, 32, 0.75) !important; color: var(--text-muted) !important;
  font-size: 0.65rem !important; backdrop-filter: blur(6px);
}
.leaflet-control-attribution a { color: var(--text-secondary) !important; }

/* Popups */
.leaflet-popup-content-wrapper {
  background: var(--bg-card) !important; border: 1px solid var(--border-color) !important;
  color: var(--text-primary) !important; border-radius: var(--radius) !important;
  box-shadow: var(--shadow-lg) !important; padding: 0 !important;
}
.leaflet-popup-content { margin: 0 !important; font-family: 'Inter', sans-serif !important; font-size: 0.85rem !important; min-width: 220px; }
.leaflet-popup-tip { background: var(--bg-card) !important; border: 1px solid var(--border-color) !important; }
.leaflet-popup-close-button { color: var(--text-muted) !important; font-size: 18px !important; width: 28px !important; height: 28px !important; padding: 4px !important; }
.leaflet-popup-close-button:hover { color: var(--text-primary) !important; }
.popup-content { padding: 14px 16px; }
.popup-title { font-size: 0.95rem; font-weight: 700; margin-bottom: 8px; line-height: 1.3; }
.popup-title.pln { color: var(--color-pln); }
.popup-title.non-pln { color: var(--color-accent); }
.popup-title.outside { color: var(--color-danger); }
.popup-title.gardu { color: #d97706; }
.popup-row { display: flex; justify-content: space-between; padding: 3px 0; font-size: 0.78rem; }
.popup-label { color: var(--text-muted); }
.popup-value { color: var(--text-primary); font-weight: 500; font-variant-numeric: tabular-nums; }

/* Coordinate Display */
.coord-display {
  position: absolute; bottom: 28px; left: 50%; transform: translateX(-50%);
  z-index: 800; background: rgba(12, 18, 32, 0.8);
  border: 1px solid var(--border-color); backdrop-filter: blur(10px);
  padding: 6px 16px; border-radius: 20px; font-size: 0.75rem;
  color: var(--text-secondary); font-variant-numeric: tabular-nums;
  pointer-events: none; transition: var(--transition);
  display: flex; gap: 12px; align-items: center;
}
.zoom-display {
  color: var(--color-primary); font-weight: 600;
  font-size: 0.72rem;
}

/* Map Controls */
.map-controls {
  position: absolute; top: 12px; right: 12px; z-index: 800;
  display: flex; flex-direction: column; gap: 4px;
  background: var(--bg-card); border: 1px solid var(--border-color);
  border-radius: var(--radius-sm); padding: 4px; box-shadow: var(--shadow-md);
}
.map-control-btn {
  width: 36px; height: 36px; background: transparent; border: none;
  border-radius: var(--radius-xs); color: var(--text-secondary);
  font-size: 1rem; cursor: pointer; transition: var(--transition);
  display: flex; align-items: center; justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.map-control-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.map-control-btn.active { background: var(--color-primary); color: white; }
.map-control-divider { height: 1px; background: var(--border-color); margin: 2px 4px; }

/* Measure Panel */
.measure-panel {
  position: absolute; top: calc(12px + 36px*7 + 4px*6 + 4px*2 + 16px); right: 12px; z-index: 800;
  width: 220px; background: var(--bg-card); border: 1px solid var(--border-color);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-md);
  overflow: hidden; animation: slideInRight 0.2s ease;
}
@keyframes slideInRight {
  from { opacity: 0; transform: translateX(-10px); }
  to { opacity: 1; transform: translateX(0); }
}
.measure-panel-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color); font-size: 0.75rem;
  font-weight: 600; color: var(--text-primary);
}
.measure-close-btn {
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; padding: 2px 6px; border-radius: 4px;
  font-size: 0.75rem; transition: var(--transition);
}
.measure-close-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.measure-panel-body {
  padding: 10px 12px; min-height: 60px;
}
.measure-empty {
  color: var(--text-muted); font-size: 0.72rem; text-align: center;
  padding: 10px 0;
}
.measure-row {
  display: flex; flex-direction: column; gap: 4px; margin-bottom: 6px;
}
.measure-row:last-child { margin-bottom: 0; }
.measure-label {
  font-size: 0.62rem; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.5px;
}
.measure-value {
  font-size: 0.82rem; font-weight: 700; color: var(--text-primary);
  font-family: 'JetBrains Mono', 'Consolas', monospace;
}
.measure-value .dist-num {
  color: #ef4444; font-size: 1rem;
}
.measure-divider {
  height: 1px; background: var(--border-color); margin: 6px 0;
}

/* Gardu Induk Marker */
/* Leaflet CircleMarker untuk gardu — stroke effect */
.gardu-gitet-path {
  animation: gardu-pulse 2.5s ease-in-out infinite;
}
@keyframes gardu-pulse {
  0%, 100% { stroke-width: 2; stroke-opacity: 0.6; }
  50% { stroke-width: 3; stroke-opacity: 1; }
}

/* GI / GITET label permanent di zoom 18+ */
.gi-label-on {
  background: rgba(11, 11, 26, 0.75) !important;
  backdrop-filter: blur(6px) !important;
  border: 1px solid rgba(255,255,255,0.08) !important;
  border-radius: 6px !important;
  padding: 2px 8px !important;
  font-size: 10px !important;
  font-weight: 600 !important;
  color: #e2e8f0 !important;
  white-space: nowrap !important;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3) !important;
}
.gi-label-on .leaflet-popup-content-wrapper {
  background: transparent !important;
  box-shadow: none !important;
}
.gi-label-on .leaflet-popup-tip-container {
  display: none !important;
}


/* Pulse animation for marker */
@keyframes pulse-ring {
  0% { transform: scale(0.5); opacity: 1; }
  100% { transform: scale(2.5); opacity: 0; }
}

/* Mobile FAB - hidden on desktop */
.mobile-fab-group { display: none; }

/* Bottom Sheet - hidden on desktop */
.bottom-sheet { display: none; }

/* Search Loading */
.search-loading {
  display: flex; align-items: center; justify-content: center;
  padding: 12px; color: var(--text-muted); font-size: 0.8rem; gap: 8px;
}
.search-loading .mini-spinner {
  width: 14px; height: 14px; border: 2px solid var(--border-color);
  border-top-color: var(--color-primary); border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
.empty-state { text-align: center; padding: 16px; color: var(--text-muted); font-size: 0.8rem; }


/* ═══════════════════════════════════════════
   MOBILE LAYOUT (< 768px)
   ═══════════════════════════════════════════ */
@media (max-width: 768px) {
  /* Hide desktop sidebar */
  .sidebar { display: none !important; }
  
  /* Map fills entire screen */
  .app-layout { flex-direction: column; }
  .map-container { height: 100vh; width: 100vw; }
  
  /* Adjust map controls position for mobile */
  .map-controls {
    top: 10px; right: 10px;
    flex-direction: row;
    padding: 3px;
  }
  .map-control-btn { width: 34px; height: 34px; font-size: 0.9rem; }
  .map-control-divider { width: 1px; height: auto; margin: 4px 2px; }
  
  /* Coord display above bottom sheet */
  .coord-display {
    bottom: auto; top: 10px; left: 10px; right: auto;
    transform: none; font-size: 0.7rem; padding: 5px 12px;
  }
  
  /* Leaflet zoom - move to left */
  .leaflet-control-zoom {
    margin-left: 10px !important;
  }
  .leaflet-control-zoom a {
    width: 34px !important; height: 34px !important; line-height: 34px !important;
  }
  
  /* ── Mobile FABs ── */
  .mobile-fab-group {
    display: flex; flex-direction: column; gap: 10px;
    position: absolute; bottom: calc(220px + 14px); right: 14px; z-index: 850;
  }
  
  .fab {
    width: 52px; height: 52px; border-radius: 50%;
    border: none; cursor: pointer;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    box-shadow: var(--shadow-lg);
    -webkit-tap-highlight-color: transparent;
    transition: var(--transition);
    position: relative;
  }
  .fab:active { transform: scale(0.9); }
  
  .fab-gps {
    background: linear-gradient(135deg, var(--color-primary), #6366f1);
    color: white;
  }
  .fab-gps.locating {
    animation: fabPulse 1.2s ease-in-out infinite;
  }
  @keyframes fabPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.4); }
    50% { box-shadow: 0 0 0 14px rgba(59, 130, 246, 0); }
  }
  .fab-icon { font-size: 1.3rem; line-height: 1; }
  .fab-label { font-size: 0.55rem; font-weight: 700; letter-spacing: 0.5px; margin-top: 1px; }

  /* ── Bottom Sheet ── */
  .bottom-sheet {
    display: flex; flex-direction: column;
    position: fixed; bottom: 0; left: 0; right: 0;
    z-index: 900;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -4px 30px rgba(0, 0, 0, 0.5);
    max-height: 85vh;
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    touch-action: none;
  }
  
  .bottom-sheet.minimized {
    transform: translateY(calc(100% - 200px));
  }
  .bottom-sheet.expanded {
    transform: translateY(0);
  }
  
  .bottom-sheet-handle {
    padding: 10px 0 6px;
    display: flex; justify-content: center;
    cursor: grab;
    touch-action: none;
  }
  .handle-bar {
    width: 40px; height: 4px; border-radius: 2px;
    background: var(--text-muted);
  }
  
  .bottom-sheet-content {
    flex: 1; overflow-y: auto; overflow-x: hidden;
    padding: 0 16px; padding-bottom: calc(12px + var(--safe-bottom));
    -webkit-overflow-scrolling: touch;
  }
  
  /* Mobile Header */
  .mobile-header {
    padding: 4px 0 10px; display: flex; align-items: center;
  }
  .logo-mini { display: flex; align-items: center; gap: 8px; }
  .logo-icon-mini {
    width: 28px; height: 28px; border-radius: 8px;
    background: linear-gradient(135deg, var(--color-primary), #6366f1);
    display: flex; align-items: center; justify-content: center;
    font-size: 0.9rem;
  }
  .logo-text-mini {
    font-size: 1rem; font-weight: 800;
    background: linear-gradient(135deg, var(--text-primary), var(--color-primary));
    -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
  }
  
  /* Mobile Sections */
  .mobile-section {
    padding: 10px 0;
    border-bottom: 1px solid var(--border-color);
  }
  .mobile-section:last-child { border-bottom: none; }
  
  .mobile-input-group {
    display: flex; gap: 6px;
  }
  .mobile-input-group input {
    flex: 1; padding: 12px 14px; font-size: 0.95rem;
    background: var(--bg-input); border: 1px solid var(--border-color);
    border-radius: var(--radius-sm); color: var(--text-primary);
    font-family: 'Inter', sans-serif; outline: none;
    transition: var(--transition);
    /* Remove number input arrows on mobile */
    -moz-appearance: textfield;
  }
  .mobile-input-group input:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-glow);
  }
  .mobile-input-group input::placeholder { color: var(--text-muted); }
  
  .mobile-btn-action {
    width: 48px; height: 48px; min-width: 48px;
    background: var(--bg-input); border: 1px solid var(--border-color);
    border-radius: var(--radius-sm); color: var(--text-primary);
    font-size: 1.2rem; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: var(--transition);
    -webkit-tap-highlight-color: transparent;
  }
  .mobile-btn-action:active { transform: scale(0.92); }
  .mobile-btn-primary {
    background: linear-gradient(135deg, var(--color-primary), #6366f1);
    color: white; border-color: transparent;
  }
  
  .mobile-hint {
    font-size: 0.72rem; color: var(--text-muted);
    margin-top: 6px; padding-left: 2px;
  }
  
  /* Mobile Legend */
  .mobile-legend-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 0; cursor: pointer; user-select: none;
    font-size: 0.82rem; color: var(--text-secondary); font-weight: 600;
  }
  
  /* Adjust mobile search results */
  .mobile-section .search-results {
    max-height: 180px;
  }
  
  /* Hide desktop coord display on mobile, show map crosshair */
  .leaflet-popup-content { min-width: 200px; }
  .popup-content { padding: 12px 14px; }
  .popup-title { font-size: 0.88rem; }
  .popup-row { font-size: 0.75rem; }

  /* Toast adjustments for mobile */
  .toast-container { top: auto; bottom: calc(210px + 14px); }
  .toast { font-size: 0.8rem; padding: 10px 14px; }
}

/* Very small phones */
@media (max-width: 380px) {
  .bottom-sheet-content { padding: 0 12px; }
  .mobile-input-group input { font-size: 0.88rem; padding: 10px 12px; }
  .mobile-btn-action { width: 44px; height: 44px; min-width: 44px; }
  .fab { width: 48px; height: 48px; }
}

/* Custom CSS for Measure Popup */
.measure-popup .leaflet-popup-content-wrapper {
  border: 1px solid var(--color-primary-glow) !important;
}
.measure-popup .leaflet-popup-content {
  min-width: 150px !important;
  margin: 8px !important;
}
