/* ============================================
   Bản đồ số cấp xã - Modern Light Theme
   ============================================ */

:root {
  --primary: #0284c7;
  --primary-light: #38bdf8;
  --primary-dark: #0369a1;
  --accent: #0ea5e9;
  --accent-light: #7dd3fc;

  --bg-dark: #f0f4f8;
  /* Background of the app */
  --bg-card: #ffffff;
  --bg-card-hover: #f8fafc;
  --bg-glass: rgba(255, 255, 255, 0.9);
  --bg-input: #f1f5f9;

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;

  --border: rgba(2, 132, 199, 0.2);
  --border-hover: rgba(2, 132, 199, 0.4);

  --success: #16a34a;
  --error: #ef4444;
  --warning: #f59e0b;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
  --shadow-glow: 0 0 20px rgba(2, 132, 199, 0.1);

  --sidebar-width: 340px;
  --radius: 12px;
  --radius-sm: 8px;

  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

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

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
}

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

::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

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

.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-right: 1px solid var(--border);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  transition: transform var(--transition);
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar.collapsed {
  transform: translateX(calc(-1 * var(--sidebar-width)));
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  z-index: 10;
}

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

.logo h1 {
  font-size: 1.25rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.sidebar-toggle {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}

.sidebar-toggle:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  border-color: var(--border-hover);
}

/* Desktop expand button — shown when sidebar is collapsed */
.sidebar-expand-btn {
  display: none;
  position: fixed;
  top: 90px;
  left: 16px;
  z-index: 1001;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  color: var(--text-primary);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-md);
  transition: all var(--transition);
}

.sidebar-expand-btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-hover);
  transform: scale(1.05);
}

.sidebar.collapsed~.sidebar-expand-btn {
  display: flex;
}

/* Sections */
.sidebar-section {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-section:last-child {
  border-bottom: none;
}

.section-title {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* User Section */
.user-section {
  padding: 8px 16px;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: rgba(99, 102, 241, 0.08);
  border: 1px solid rgba(99, 102, 241, 0.15);
  border-radius: var(--radius-sm);
}

.user-avatar {
  width: 36px;
  height: 36px;
  min-width: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 0.9rem;
  font-weight: 700;
}

.user-details {
  flex: 1;
  min-width: 0;
}

.user-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-email {
  font-size: 0.7rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.btn-logout:hover {
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.3);
  color: var(--error);
}

/* Upload Area */
.upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 16px 12px;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  background: var(--bg-input);
}

.upload-area:hover,
.upload-area.dragover {
  border-color: var(--primary);
  background: rgba(99, 102, 241, 0.08);
  box-shadow: var(--shadow-glow);
}

.upload-area.dragover {
  transform: scale(1.02);
}

.upload-icon {
  color: var(--text-muted);
  margin-bottom: 12px;
  transition: all var(--transition);
}

.upload-area:hover .upload-icon {
  color: var(--primary-light);
  transform: translateY(-2px);
}

.upload-text {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.upload-subtext {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.upload-hint {
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* Progress */
.upload-progress {
  margin-top: 12px;
}

.progress-bar {
  height: 4px;
  background: var(--bg-input);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 8px;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  border-radius: 2px;
  width: 0%;
  transition: width 0.3s ease;
  animation: progressPulse 2s infinite;
}

@keyframes progressPulse {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.7;
  }
}

.progress-text {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-align: center;
}

/* CRS Selector */
.crs-selector {
  margin-top: 12px;
}

.crs-label {
  display: block;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.crs-select {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all var(--transition);
  appearance: auto;
}

.crs-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.crs-select option,
.crs-select optgroup {
  background: var(--bg-card);
  color: var(--text-primary);
}

/* File List */
.file-list {
  max-height: 200px;
  overflow-y: auto;
  overflow-x: hidden;
  /* Fix unwanted horizontal scrollbar on item hover */
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.empty-state {
  text-align: center;
  padding: 24px 0;
  color: var(--text-muted);
}

.empty-state svg {
  margin-bottom: 8px;
  opacity: 0.4;
}

.empty-state p {
  font-size: 0.8rem;
}

.file-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: grab;
  transition: all var(--transition);
  animation: slideIn 0.3s ease;
}

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

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

.file-item:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-hover);
  transform: translateX(2px);
}

.file-item:active {
  cursor: grabbing;
}

.file-item.active {
  border-color: var(--primary);
  background: rgba(99, 102, 241, 0.1);
}

.file-item.dragging {
  opacity: 0.4;
  border: 1px dashed var(--primary);
  background: rgba(99, 102, 241, 0.05);
}

.file-item.drag-over {
  border-top: 2px solid var(--primary);
  background: rgba(99, 102, 241, 0.1);
  transform: translateY(2px);
}

.file-item-icon {
  width: 32px;
  height: 32px;
  min-width: 32px;
  border-radius: 6px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 0.65rem;
  font-weight: 700;
}

.file-item-info {
  flex: 1;
  min-width: 0;
}

.file-item-name {
  font-size: 0.8rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-item-meta {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.file-item-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity var(--transition);
}

.file-item:hover .file-item-actions {
  opacity: 1;
}

.file-action-btn {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}

.file-action-btn:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

.file-action-btn.delete:hover {
  background: rgba(239, 68, 68, 0.15);
  color: var(--error);
}

.file-action-btn.public-active,
.cl-action-btn.public-active {
  background: rgba(34, 197, 94, 0.15);
  color: #22c55e;
  border-radius: 6px;
}

.file-action-btn.public-active:hover,
.cl-action-btn.public-active:hover {
  background: rgba(239, 68, 68, 0.12);
  color: var(--error);
}

.file-item-toggle {
  width: 36px;
  height: 20px;
  background: var(--text-muted);
  border-radius: 10px;
  position: relative;
  cursor: pointer;
  transition: background var(--transition);
  border: none;
  padding: 0;
  flex-shrink: 0;
}

.file-item-toggle.active {
  background: var(--primary);
}

.file-item-toggle::after {
  content: '';
  width: 16px;
  height: 16px;
  background: white;
  border-radius: 50%;
  position: absolute;
  top: 2px;
  left: 2px;
  transition: transform var(--transition);
}

.file-item-toggle.active::after {
  transform: translateX(16px);
}

/* Buttons */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}

.btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn-location {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.15), rgba(139, 92, 246, 0.15));
  border-color: rgba(99, 102, 241, 0.3);
}

.btn-location:hover {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.25), rgba(139, 92, 246, 0.25));
  border-color: var(--primary);
}

.btn-clear {
  color: var(--text-secondary);
}

.btn-clear:hover {
  color: var(--error);
  border-color: rgba(239, 68, 68, 0.3);
  background: rgba(239, 68, 68, 0.08);
}

.sidebar-footer {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: sticky;
  bottom: 0;
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  z-index: 10;
  padding-top: 12px;
}

/* Measurement group */
.measure-group {
  display: flex;
  gap: 6px;
  margin-top: 4px;
}

.measure-group .btn {
  flex: 1;
  padding: 10px 8px;
  font-size: 0.75rem;
}

.btn-measure {
  background: linear-gradient(135deg, rgba(34, 197, 94, 0.1), rgba(16, 185, 129, 0.1));
  border-color: rgba(34, 197, 94, 0.25);
}

.btn-measure:hover {
  background: linear-gradient(135deg, rgba(34, 197, 94, 0.2), rgba(16, 185, 129, 0.2));
  border-color: rgba(34, 197, 94, 0.5);
}

.btn-measure.active {
  background: linear-gradient(135deg, rgba(34, 197, 94, 0.3), rgba(16, 185, 129, 0.3));
  border-color: #22c55e;
  color: #22c55e;
}

/* Measurement Panel */
.measure-panel {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1100;
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 14px 18px;
  min-width: 280px;
  max-width: 400px;
  animation: fadeInUp 0.3s ease;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

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

.measure-panel-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
}

.measure-panel-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.3rem;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.measure-panel-result {
  font-size: 1.1rem;
  font-weight: 700;
  color: #22c55e;
  padding: 8px 0;
  text-align: center;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.measure-panel-actions {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}

.btn-measure-action {
  flex: 1;
  padding: 8px 10px;
  font-size: 0.75rem;
  border-radius: var(--radius-sm);
}

.btn-finish {
  background: linear-gradient(135deg, rgba(34, 197, 94, 0.2), rgba(16, 185, 129, 0.2));
  border-color: rgba(34, 197, 94, 0.4);
  color: #22c55e;
}

.btn-finish:hover {
  background: linear-gradient(135deg, rgba(34, 197, 94, 0.3), rgba(16, 185, 129, 0.3));
}

/* Measure cursor */
.measure-cursor {
  cursor: crosshair !important;
}

.measure-cursor .leaflet-interactive {
  cursor: crosshair !important;
}

.measure-cursor .leaflet-overlay-pane,
.measure-cursor .leaflet-overlay-pane *,
.measure-cursor .leaflet-overlay-pane svg,
.measure-cursor .leaflet-overlay-pane path {
  pointer-events: none !important;
}

/* Allow measurement markers to be draggable */
.measure-cursor .leaflet-marker-pane,
.measure-cursor .leaflet-marker-pane * {
  pointer-events: auto !important;
}

.measure-drag-point {
  cursor: grab !important;
  z-index: 1000 !important;
}

.measure-drag-point:active {
  cursor: grabbing !important;
}

@media (max-width: 768px) {
  .measure-panel {
    bottom: 72px;
    left: 12px;
    right: 12px;
    transform: none;
    min-width: auto;
    max-width: none;
    padding: 12px 14px;
  }

  @keyframes fadeInUp {
    from {
      opacity: 0;
      transform: translateY(10px);
    }

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

  .measure-panel-result {
    font-size: 1rem;
  }

  .measure-group {
    flex-direction: row;
  }

  .measure-group .btn {
    font-size: 0.7rem;
    padding: 8px 6px;
  }
}

/* ============================================
   Map
   ============================================ */

.map-container {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: var(--sidebar-width);
  transition: left var(--transition);
}

.sidebar.collapsed~.map-container {
  left: 0;
}

#map {
  width: 100%;
  height: 100%;
}

/* Map Info */
.map-info {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  animation: fadeInDown 0.3s ease;
}

@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(-10px);
  }

  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

.map-info-content {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  padding: 10px 16px;
  border-radius: 50px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  font-size: 0.85rem;
}

.map-info-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0 2px;
}

/* Loading */
.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.75);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.loader {
  text-align: center;
}

.loader-spinner {
  width: 48px;
  height: 48px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 16px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.loader p {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

/* ============================================
   Mobile Menu Button
   ============================================ */

.mobile-menu-btn {
  display: none;
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 1001;
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  color: var(--text-primary);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-md);
}

/* ============================================
   Toasts
   ============================================ */

.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  font-size: 0.85rem;
  animation: toastIn 0.3s ease;
  max-width: 400px;
}

.toast.success {
  border-left: 3px solid var(--success);
}

.toast.error {
  border-left: 3px solid var(--error);
}

.toast.warning {
  border-left: 3px solid var(--warning);
}

.toast.info {
  border-left: 3px solid var(--primary);
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateX(20px);
  }

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

.toast-exit {
  animation: toastOut 0.3s ease forwards;
}

@keyframes toastOut {
  to {
    opacity: 0;
    transform: translateX(20px);
  }
}

/* ============================================
   Leaflet Overrides
   ============================================ */

.custom-popup .leaflet-popup-content-wrapper {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  font-family: 'Inter', sans-serif;
  font-size: 0.8rem;
  overflow: hidden;
}

.custom-popup .leaflet-popup-content {
  word-wrap: break-word;
  overflow-wrap: break-word;
  overflow-y: auto;
  max-height: 350px;
  margin: 12px 14px;
}

.custom-popup .leaflet-popup-tip {
  background: var(--bg-card);
  border: 1px solid var(--border);
}

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

/* Popup measurement info */
.popup-measure-divider {
  height: 1px;
  background: var(--border);
  margin: 8px 0;
}

.popup-measure-section {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.popup-measure-row {
  font-size: 0.8rem;
  color: var(--text-secondary);
  padding: 2px 0;
}

.popup-measure-row strong {
  color: #22c55e;
  font-weight: 600;
}

.popup-feature-header {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--primary-light);
  margin-bottom: 4px;
  padding-bottom: 2px;
  border-bottom: 1px solid var(--border);
}

.popup-feature-separator {
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(34, 197, 94, 0.4), transparent);
  margin: 10px 0;
}

.leaflet-control-layers {
  background: var(--bg-card) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-sm) !important;
  color: var(--text-primary) !important;
  box-shadow: var(--shadow-md) !important;
}

.leaflet-control-layers label {
  color: var(--text-primary);
}

.leaflet-control-zoom a {
  background: var(--bg-card) !important;
  color: var(--text-primary) !important;
  border-color: var(--border) !important;
}

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

.leaflet-control-attribution {
  background: rgba(255, 255, 255, 0.85) !important;
  color: var(--text-muted) !important;
  font-size: 0.65rem !important;
}

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

/* ============================================
   Responsive - Tablet (≤768px)
   ============================================ */

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

  .sidebar {
    width: 100%;
    height: 70vh;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    transform: translateY(100%);
    border-right: none;
    border-top: 1px solid var(--border);
    border-radius: 20px 20px 0 0;
    z-index: 1002;
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  }

  .sidebar.open {
    transform: translateY(0);
  }

  .sidebar-header {
    padding: 12px 20px;
    position: relative;
  }

  /* Drag handle for mobile slide-up panel */
  .sidebar-header::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 4px;
    background: var(--text-muted);
    border-radius: 2px;
    opacity: 0.5;
  }

  .sidebar-toggle {
    display: none;
  }

  .sidebar-section {
    padding: 12px 16px;
  }

  .upload-area {
    padding: 20px 12px;
  }

  .upload-icon svg {
    width: 36px;
    height: 36px;
  }

  .file-list {
    max-height: 200px;
  }

  .sidebar-footer {
    flex-direction: row;
    gap: 8px;
    padding-bottom: env(safe-area-inset-bottom, 16px);
  }

  .sidebar-footer .btn {
    flex: 1;
    padding: 10px 12px;
    font-size: 0.8rem;
  }

  .map-container {
    left: 0;
    bottom: 0;
  }

  /* Mobile Menu Button */
  .mobile-menu-btn {
    display: flex;
  }

  /* Hide desktop expand btn on mobile */
  .sidebar-expand-btn {
    display: none !important;
  }

  /* Mobile Bottom Toolbar */
  .mobile-toolbar {
    display: flex !important;
  }

  /* Toast on mobile */
  .toast-container {
    bottom: 80px;
    right: 12px;
    left: 12px;
  }

  .toast {
    max-width: 100%;
    font-size: 0.8rem;
    padding: 10px 14px;
  }

  /* Map info on mobile */
  .map-info {
    top: auto;
    bottom: 72px;
    left: 12px;
    right: 12px;
    transform: none;
  }

  .map-info-content {
    font-size: 0.75rem;
    padding: 8px 12px;
    width: 100%;
  }

  /* Leaflet control positions for mobile */
  .leaflet-top.leaflet-left {
    top: 60px;
  }

  .leaflet-top.leaflet-right {
    top: 60px;
  }

  .leaflet-control-zoom a {
    width: 36px !important;
    height: 36px !important;
    line-height: 36px !important;
    font-size: 18px !important;
  }

  /* Overlay backdrop */
  .sidebar-backdrop {
    display: block !important;
  }
}

/* ============================================
   Mobile Bottom Toolbar
   ============================================ */

.mobile-toolbar {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1001;
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  padding: 8px 12px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  gap: 6px;
  justify-content: space-around;
  align-items: center;
}

.mobile-toolbar-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.65rem;
  font-weight: 500;
  cursor: pointer;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  min-width: 60px;
}

.mobile-toolbar-btn:active {
  background: rgba(99, 102, 241, 0.15);
  color: var(--primary-light);
  transform: scale(0.95);
}

.mobile-toolbar-btn.active {
  color: var(--primary-light);
}

.mobile-toolbar-btn svg {
  width: 22px;
  height: 22px;
}

/* Sidebar Backdrop for mobile */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.2);
  z-index: 1001;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}

.sidebar-backdrop.visible {
  opacity: 1;
  pointer-events: auto;
}

/* ============================================
   Responsive - Small Phone (≤480px)
   ============================================ */

@media (max-width: 480px) {
  .sidebar {
    height: 75vh;
  }

  .sidebar-header {
    padding: 10px 14px;
  }

  .logo h1 {
    font-size: 1.1rem;
  }

  .section-title {
    font-size: 0.7rem;
    margin-bottom: 8px;
  }

  .sidebar-section {
    padding: 10px 14px;
  }

  .upload-area {
    padding: 16px 10px;
  }

  .upload-text {
    font-size: 0.85rem;
  }

  .upload-subtext {
    font-size: 0.75rem;
  }

  .upload-hint {
    font-size: 0.65rem;
  }

  .file-item {
    padding: 8px 10px;
    gap: 8px;
  }

  .file-item-icon {
    width: 28px;
    height: 28px;
    min-width: 28px;
    font-size: 0.6rem;
  }

  .file-item-name {
    font-size: 0.75rem;
  }

  .file-item-meta {
    font-size: 0.65rem;
  }

  .file-item-toggle {
    width: 32px;
    height: 18px;
  }

  .file-item-toggle::after {
    width: 14px;
    height: 14px;
  }

  .file-item-toggle.active::after {
    transform: translateX(14px);
  }

  .file-list {
    max-height: 180px;
  }

  .btn {
    padding: 10px 12px;
    font-size: 0.8rem;
  }

  .mobile-toolbar-btn {
    font-size: 0.6rem;
    padding: 5px 8px;
    min-width: 50px;
  }

  .mobile-toolbar-btn svg {
    width: 20px;
    height: 20px;
  }

  /* Mobile menu button */
  .mobile-menu-btn {
    top: 10px;
    left: 10px;
    width: 40px;
    height: 40px;
  }
}

/* ============================================
   Responsive - Extra Small (≤360px)
   ============================================ */

@media (max-width: 360px) {
  .sidebar {
    height: 80vh;
  }

  .logo svg {
    width: 24px;
    height: 24px;
  }

  .logo h1 {
    font-size: 1rem;
  }

  .sidebar-footer {
    flex-direction: column;
  }
}

/* ============================================
   Landscape Mobile
   ============================================ */

@media (max-height: 500px) and (orientation: landscape) {
  .sidebar {
    height: 90vh;
  }

  .upload-area {
    padding: 12px 10px;
  }

  .upload-icon {
    display: none;
  }

  .file-list {
    max-height: 120px;
  }

  .sidebar-footer {
    flex-direction: row;
  }

  .mobile-toolbar {
    flex-direction: column;
    width: 56px;
    height: auto;
    left: auto;
    right: 0;
    top: 50%;
    bottom: auto;
    transform: translateY(-50%);
    border-top: none;
    border-left: 1px solid var(--border);
    border-radius: var(--radius-sm) 0 0 var(--radius-sm);
    padding: 8px 4px;
  }

  .mobile-toolbar-btn {
    font-size: 0;
    padding: 8px;
    min-width: auto;
  }
}

/* Touch enhancements */
@media (hover: none) and (pointer: coarse) {
  .file-item-actions {
    opacity: 1;
  }

  .btn:hover {
    transform: none;
    box-shadow: none;
  }

  .file-item:hover {
    transform: none;
  }

  .upload-area:hover .upload-icon {
    transform: none;
  }
}

/* ============================================
   Custom Layers
   ============================================ */

.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.section-title-row .section-title {
  margin-bottom: 0;
}

.btn-add-layer {
  width: 30px;
  height: 30px;
  border: 1px solid rgba(99, 102, 241, 0.3);
  border-radius: 8px;
  background: rgba(99, 102, 241, 0.12);
  color: var(--primary-light);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}

.btn-add-layer:hover {
  background: rgba(99, 102, 241, 0.25);
  border-color: var(--primary);
  transform: scale(1.05);
}

.custom-layer-list {
  max-height: 180px;
  overflow-y: auto;
  overflow-x: hidden;
  /* Fix unwanted horizontal scrollbar on item hover */
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.custom-layer-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  animation: slideIn 0.3s ease;
}

.custom-layer-item:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-hover);
}

.custom-layer-item.selected {
  border-color: var(--primary);
  background: rgba(99, 102, 241, 0.12);
  box-shadow: 0 0 0 1px rgba(99, 102, 241, 0.2);
}

.cl-color-dot {
  width: 14px;
  height: 14px;
  min-width: 14px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.2);
}

.cl-info {
  flex: 1;
  min-width: 0;
}

.cl-name {
  font-size: 0.8rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cl-meta {
  font-size: 0.68rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.cl-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity var(--transition);
}

.custom-layer-item:hover .cl-actions {
  opacity: 1;
}

.cl-action-btn {
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  font-size: 0.72rem;
}

.cl-action-btn:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

.cl-action-btn.delete:hover {
  background: rgba(239, 68, 68, 0.15);
  color: var(--error);
}

/* Draw Toolbar */
.draw-toolbar {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(99, 102, 241, 0.05);
}

.draw-toolbar-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--primary-light);
  margin-bottom: 8px;
}

.draw-toolbar-title span {
  color: var(--text-primary);
}

.draw-toolbar-btns {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.btn-draw {
  flex: 1;
  min-width: 70px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px 10px;
  font-size: 0.72rem;
  font-weight: 500;
  font-family: inherit;
  border: 1px solid rgba(99, 102, 241, 0.25);
  border-radius: var(--radius-sm);
  background: rgba(99, 102, 241, 0.1);
  color: var(--primary-light);
  cursor: pointer;
  transition: all var(--transition);
}

.btn-draw:hover {
  background: rgba(99, 102, 241, 0.2);
  border-color: var(--primary);
}

.btn-draw.active {
  background: rgba(99, 102, 241, 0.3);
  border-color: var(--primary);
  color: white;
  box-shadow: 0 0 12px rgba(99, 102, 241, 0.2);
}

.btn-draw-cancel {
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.25);
  color: var(--error);
}

.btn-draw-cancel:hover {
  background: rgba(239, 68, 68, 0.2);
  border-color: var(--error);
}

/* ============================================
   Modals
   ============================================ */

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

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

.modal-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg), 0 0 40px rgba(99, 102, 241, 0.08);
  animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: translateY(-20px) scale(0.97);
  }

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

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

.modal-header h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.4rem;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  transition: color var(--transition);
}

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

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  display: flex;
  gap: 10px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

.modal-btn-cancel {
  flex: 1;
  background: var(--bg-input);
  border-color: var(--border);
  color: var(--text-secondary);
}

.modal-btn-cancel:hover {
  color: var(--text-primary);
}

.modal-btn-save {
  flex: 1;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border: none;
  color: white;
  font-weight: 600;
}

.modal-btn-save:hover {
  background: linear-gradient(135deg, var(--primary-dark), var(--primary)) !important;
  color: white !important;
  box-shadow: 0 4px 16px rgba(2, 132, 199, 0.3);
}

/* Form Fields */
.form-group {
  margin-bottom: 16px;
}

.form-group:last-child {
  margin-bottom: 0;
}

.form-group label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.form-group .required {
  color: var(--error);
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group input[type="date"],
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.85rem;
  transition: all var(--transition);
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.form-group textarea {
  resize: vertical;
  min-height: 60px;
}

.color-picker-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.color-picker-row input[type="color"] {
  width: 40px;
  height: 34px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-input);
  cursor: pointer;
}

.color-preview {
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-family: monospace;
}

/* Fields Builder */
.fields-builder {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 8px;
}

.field-row {
  display: flex;
  gap: 6px;
  align-items: center;
  animation: slideIn 0.2s ease;
}

.field-row input {
  flex: 1;
  padding: 8px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.8rem;
}

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

.field-row select {
  width: 100px;
  padding: 8px 6px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.78rem;
}

.field-row select option {
  background: var(--bg-card);
}

.field-row .btn-remove-field {
  width: 28px;
  height: 28px;
  min-width: 28px;
  border: none;
  border-radius: 6px;
  background: rgba(239, 68, 68, 0.1);
  color: var(--error);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  transition: all var(--transition);
}

.field-row .btn-remove-field:hover {
  background: rgba(239, 68, 68, 0.25);
}

.btn-add-field {
  display: block;
  width: 100%;
  padding: 8px;
  background: rgba(99, 102, 241, 0.08);
  border: 1px dashed rgba(99, 102, 241, 0.3);
  border-radius: 6px;
  color: var(--primary-light);
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-add-field:hover {
  background: rgba(99, 102, 241, 0.15);
  border-color: var(--primary);
}

/* Draw Panel (floating) */
.draw-panel {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1100;
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(99, 102, 241, 0.3);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg), 0 0 20px rgba(99, 102, 241, 0.1);
  padding: 14px 18px;
  min-width: 280px;
  max-width: 400px;
  animation: fadeInUp 0.3s ease;
}

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

.draw-panel-header span {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--primary-light);
}

.draw-panel-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.3rem;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.draw-panel-info {
  font-size: 0.85rem;
  color: var(--text-secondary);
  padding: 6px 0;
  text-align: center;
}

.draw-panel-actions {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}

.btn-draw-action {
  flex: 1;
  padding: 8px 10px;
  font-size: 0.75rem;
  border-radius: var(--radius-sm);
}

/* Draw cursor */
.draw-cursor,
.draw-cursor #map {
  cursor: crosshair !important;
}

.draw-cursor .leaflet-interactive {
  cursor: crosshair !important;
}

/* Draw vertex markers */
.draw-vertex {
  cursor: grab !important;
  z-index: 1000 !important;
}

.draw-vertex:active {
  cursor: grabbing !important;
}

/* Feature popup actions */
.feature-popup-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.feature-popup-actions button {
  flex: 1;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-input);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}

.feature-popup-actions button:hover {
  background: var(--bg-card-hover);
}

.feature-popup-actions button.btn-edit-feature {
  border-color: rgba(99, 102, 241, 0.3);
  color: var(--primary-light);
}

.feature-popup-actions button.btn-delete-feature {
  border-color: rgba(239, 68, 68, 0.3);
  color: var(--error);
}

.feature-popup-actions button.btn-delete-feature:hover {
  background: rgba(239, 68, 68, 0.15);
}

@media (max-width: 768px) {
  .draw-panel {
    bottom: 72px;
    left: 12px;
    right: 12px;
    transform: none;
    min-width: auto;
    max-width: none;
  }

  .modal-box {
    max-height: 90vh;
  }

  .cl-actions {
    opacity: 1;
  }
}

/* Attribute Popup Styles */
.popup-attr-section {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.popup-attr-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.popup-attr-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--primary-light);
  display: flex;
  align-items: center;
  gap: 6px;
}

.popup-attr-select {
  width: 100%;
  padding: 6px 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 0.75rem;
  cursor: pointer;
  margin-bottom: 10px;
}

.popup-attr-select option {
  background: var(--bg-card);
}

.popup-attr-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 200px;
  overflow-y: auto;
  padding-right: 4px;
}

.popup-attr-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.popup-attr-label {
  font-size: 0.7rem;
  color: var(--text-secondary);
}

.popup-attr-input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 8px;
  color: var(--text-primary);
  font-size: 0.8rem;
  width: 100%;
}

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

.popup-attr-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.btn-attr-save {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 4px;
  padding: 6px 12px;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  flex: 1;
  transition: opacity 0.2s;
}

.btn-attr-save:hover {
  opacity: 0.9;
}

.popup-attr-status {
  font-size: 0.7rem;
  color: var(--success);
  margin-top: 4px;
  display: none;
}

/* ============================================
   Statistics / Query — Floating Side Panel
   ============================================ */

.stats-panel {
  position: fixed;
  top: 12px;
  right: 12px;
  bottom: 12px;
  width: 400px;
  max-width: calc(100vw - 24px);
  z-index: 1500;
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg), 0 0 30px rgba(2, 132, 199, 0.08);
  display: flex;
  flex-direction: column;
  animation: statsPanelIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1),
    opacity 0.25s ease;
}

@keyframes statsPanelIn {
  from {
    opacity: 0;
    transform: translateX(30px);
  }

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

.stats-panel.minimized {
  transform: translateX(calc(100% + 20px));
  opacity: 0;
  pointer-events: none;
}

/* Panel header */
.stats-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.stats-panel-header h3 {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stats-panel-header-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.stats-panel-btn {
  width: 30px;
  height: 30px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  font-size: 1.2rem;
}

.stats-panel-btn:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  border-color: var(--border-hover);
}

/* Panel body */
.stats-panel-body {
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

/* Mini restore button */
.stats-mini-restore {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 1500;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  background: var(--bg-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--primary);
  border-radius: 50px;
  box-shadow: var(--shadow-lg), 0 0 20px rgba(2, 132, 199, 0.15);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--primary);
  cursor: pointer;
  transition: all var(--transition);
  animation: statsMiniIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes statsMiniIn {
  from {
    opacity: 0;
    transform: scale(0.8);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

.stats-mini-restore:hover {
  background: rgba(2, 132, 199, 0.1);
  box-shadow: var(--shadow-lg), 0 0 30px rgba(2, 132, 199, 0.2);
  transform: scale(1.05);
}

.stats-mini-restore span {
  padding: 2px 8px;
  background: var(--primary);
  color: white;
  border-radius: 12px;
  font-size: 0.72rem;
  min-width: 20px;
  text-align: center;
}

/* Section label */
.stats-section-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

/* Logic Toggle (AND / OR) */
.stats-logic-toggle {
  display: flex;
  gap: 0;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  overflow: hidden;
  margin-bottom: 10px;
}

.stats-logic-btn {
  flex: 1;
  padding: 7px 10px;
  background: transparent;
  border: none;
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
}

.stats-logic-btn.active {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: white;
  font-weight: 600;
}

.stats-logic-btn:hover:not(.active) {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

/* Conditions Container */
.stats-conditions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 8px;
  max-height: 160px;
  overflow-y: auto;
  padding-right: 4px;
}

/* Condition Row */
.stats-condition-row {
  display: flex;
  align-items: center;
  gap: 4px;
  animation: slideIn 0.2s ease;
}

.stats-condition-row .stats-field-select {
  flex: 2;
  min-width: 0;
}

.stats-condition-row .stats-op-select {
  width: 72px;
  min-width: 72px;
}

.stats-condition-row .stats-value-input {
  flex: 2;
  min-width: 0;
}

.stats-condition-row select,
.stats-condition-row input {
  padding: 7px 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.78rem;
  transition: all var(--transition);
  width: 100%;
}

.stats-condition-row select:focus,
.stats-condition-row input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(2, 132, 199, 0.15);
}

.stats-condition-row select option {
  background: var(--bg-card);
}

.stats-condition-row .btn-remove-condition {
  width: 26px;
  height: 26px;
  min-width: 26px;
  border: none;
  border-radius: 6px;
  background: rgba(239, 68, 68, 0.1);
  color: var(--error);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  transition: all var(--transition);
}

.stats-condition-row .btn-remove-condition:hover {
  background: rgba(239, 68, 68, 0.25);
}

/* Logic label between rows */
.stats-logic-label {
  text-align: center;
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 1px 0;
}

/* Add condition button */
.btn-add-condition {
  display: block;
  width: 100%;
  padding: 7px;
  background: rgba(2, 132, 199, 0.06);
  border: 1px dashed rgba(2, 132, 199, 0.3);
  border-radius: 6px;
  color: var(--primary);
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  margin-bottom: 10px;
}

.btn-add-condition:hover {
  background: rgba(2, 132, 199, 0.12);
  border-color: var(--primary);
}

/* Actions row */
.stats-actions {
  display: flex;
  gap: 6px;
}

.stats-btn-search {
  flex: 2;
  background: linear-gradient(135deg, var(--primary), var(--accent)) !important;
  border: none !important;
  color: white !important;
  font-weight: 600 !important;
  padding: 9px 14px !important;
}

.stats-btn-search:hover {
  box-shadow: 0 4px 16px rgba(2, 132, 199, 0.3) !important;
  transform: translateY(-1px) !important;
}

.stats-btn-reset {
  flex: 1;
  color: var(--text-secondary) !important;
}

/* Results Section */
.stats-results-section {
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.stats-results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.stats-results-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  background: linear-gradient(135deg, rgba(2, 132, 199, 0.1), rgba(14, 165, 233, 0.1));
  border: 1px solid rgba(2, 132, 199, 0.2);
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--primary);
}

.stats-btn-export {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px !important;
  width: auto !important;
  background: rgba(22, 163, 74, 0.1) !important;
  border-color: rgba(22, 163, 74, 0.3) !important;
  color: var(--success) !important;
  font-size: 0.72rem !important;
  font-weight: 500 !important;
}

.stats-btn-export:hover {
  background: rgba(22, 163, 74, 0.2) !important;
  border-color: var(--success) !important;
}

/* Results table */
.stats-results-table-wrapper {
  max-height: 280px;
  overflow-y: auto;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.stats-results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.75rem;
}

.stats-results-table thead {
  position: sticky;
  top: 0;
  z-index: 1;
}

.stats-results-table th {
  background: var(--bg-input);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.stats-results-table td {
  padding: 7px 10px;
  border-bottom: 1px solid rgba(2, 132, 199, 0.06);
  color: var(--text-primary);
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stats-results-table tbody tr {
  cursor: pointer;
  transition: all 0.15s ease;
}

.stats-results-table tbody tr:nth-child(even) {
  background: rgba(2, 132, 199, 0.02);
}

.stats-results-table tbody tr:hover {
  background: rgba(2, 132, 199, 0.08);
}

.stats-results-table tbody tr.stats-row-active {
  background: rgba(2, 132, 199, 0.15);
  box-shadow: inset 3px 0 0 var(--primary);
}

.stats-results-table td:first-child {
  font-weight: 500;
  color: var(--primary);
}

/* View on map button in table */
.stats-view-btn {
  padding: 3px 8px;
  background: rgba(2, 132, 199, 0.1);
  border: 1px solid rgba(2, 132, 199, 0.2);
  border-radius: 4px;
  color: var(--primary);
  font-size: 0.68rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.stats-view-btn:hover {
  background: rgba(2, 132, 199, 0.2);
  border-color: var(--primary);
}

/* Loading & Empty states */
.stats-loading,
.stats-empty {
  text-align: center;
  padding: 24px 0;
  color: var(--text-muted);
}

.stats-loading p,
.stats-empty p {
  font-size: 0.82rem;
  margin-top: 8px;
}

.stats-empty svg {
  opacity: 0.4;
}

/* Responsive — Mobile */
@media (max-width: 768px) {
  .stats-panel {
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    max-width: 100%;
    border-radius: var(--radius) var(--radius) 0 0;
    max-height: 70vh;
  }

  @keyframes statsPanelIn {
    from {
      opacity: 0;
      transform: translateY(100%);
    }

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

  .stats-panel.minimized {
    transform: translateY(100%);
  }

  .stats-mini-restore {
    top: auto;
    bottom: 72px;
    right: 12px;
  }

  .stats-results-table-wrapper {
    max-height: 200px;
  }

  .stats-condition-row {
    flex-wrap: wrap;
  }

  .stats-condition-row .stats-value-input {
    flex: 1 1 100%;
  }
}

/* ============================================
   DGN Text Labels
   ============================================ */

.dgn-text-label {
  font-family: 'Inter', sans-serif;
  font-weight: 600;
  font-size: 11px;
  color: var(--text-primary);
  text-shadow:
    -1px -1px 0 #fff,
    1px -1px 0 #fff,
    -1px 1px 0 #fff,
    1px 1px 0 #fff,
    0px 0px 2px rgba(0, 0, 0, 0.5);
  white-space: nowrap;
  pointer-events: auto;
  cursor: pointer;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
}

.dgn-text-label:hover {
  color: var(--primary);
  text-decoration: underline;
}

/* Hide text labels based on map state */
/* .hide-dgn-texts .dgn-text-label {
  display: none !important;
} */