/* ============================================================
   EV Charge Vegas — Design System
   Art direction: Dark, utilitarian, electric-green EV aesthetic
   ============================================================ */

:root {
  --text-xs:   clamp(0.7rem,  0.65rem + 0.25vw, 0.8rem);
  --text-sm:   clamp(0.8rem, 0.75rem + 0.25vw, 0.875rem);
  --text-base: clamp(0.875rem, 0.84rem + 0.2vw, 0.95rem);
  --text-lg:   clamp(1rem, 0.95rem + 0.3vw, 1.2rem);
  --text-xl:   clamp(1.25rem, 1.1rem + 0.5vw, 1.5rem);

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-6: 1.5rem;
  --space-8: 2rem;

  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-full: 9999px;

  --transition-fast: 150ms cubic-bezier(0.16, 1, 0.3, 1);

  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* Light mode */
:root, [data-theme="light"] {
  --color-bg: #f4f5f7;
  --color-surface: #ffffff;
  --color-surface-2: #f8f9fa;
  --color-surface-raised: #ffffff;
  --color-border: #e2e4e8;
  --color-border-subtle: #eef0f2;
  --color-text: #1a1d23;
  --color-text-secondary: #5f6670;
  --color-text-tertiary: #9ca3af;
  --color-primary: #059669;
  --color-primary-hover: #047857;
  --color-primary-bg: rgba(5, 150, 105, 0.08);
  --color-chip-bg: #eef0f2;
  --color-chip-active-bg: #1a1d23;
  --color-chip-active-text: #ffffff;
  --color-popup-bg: #ffffff;
  --color-popup-border: #e2e4e8;
  --color-hotel-badge: #f59e0b;
  --color-free-badge: #10b981;
  --color-dcfast-badge: #8b5cf6;
  --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 12px 32px rgba(0,0,0,0.1);
  --map-tiles: 1;
}

/* Dark mode */
[data-theme="dark"] {
  --color-bg: #0f1117;
  --color-surface: #181a20;
  --color-surface-2: #1e2028;
  --color-surface-raised: #22242c;
  --color-border: #2a2d36;
  --color-border-subtle: #22252d;
  --color-text: #e4e5e9;
  --color-text-secondary: #9ca3af;
  --color-text-tertiary: #5f6670;
  --color-primary: #34d399;
  --color-primary-hover: #6ee7b7;
  --color-primary-bg: rgba(52, 211, 153, 0.1);
  --color-chip-bg: #22242c;
  --color-chip-active-bg: #34d399;
  --color-chip-active-text: #0f1117;
  --color-popup-bg: #1e2028;
  --color-popup-border: #2a2d36;
  --color-hotel-badge: #fbbf24;
  --color-free-badge: #34d399;
  --color-dcfast-badge: #a78bfa;
  --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 12px 32px rgba(0,0,0,0.5);
  --map-tiles: 1;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --color-bg: #0f1117;
    --color-surface: #181a20;
    --color-surface-2: #1e2028;
    --color-surface-raised: #22242c;
    --color-border: #2a2d36;
    --color-border-subtle: #22252d;
    --color-text: #e4e5e9;
    --color-text-secondary: #9ca3af;
    --color-text-tertiary: #5f6670;
    --color-primary: #34d399;
    --color-primary-hover: #6ee7b7;
    --color-primary-bg: rgba(52, 211, 153, 0.1);
    --color-chip-bg: #22242c;
    --color-chip-active-bg: #34d399;
    --color-chip-active-text: #0f1117;
    --color-popup-bg: #1e2028;
    --color-popup-border: #2a2d36;
    --color-hotel-badge: #fbbf24;
    --color-free-badge: #34d399;
    --color-dcfast-badge: #a78bfa;
    --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 12px 32px rgba(0,0,0,0.5);
  }
}

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

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow: hidden;
  height: 100%;
}

body {
  font-family: var(--font-body);
  font-size: var(--text-base);
  color: var(--color-text);
  background: var(--color-bg);
  height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

button { cursor: pointer; background: none; border: none; font: inherit; color: inherit; }

/* ============================================================
   Header
   ============================================================ */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) var(--space-4);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  z-index: 1000;
  flex-shrink: 0;
  height: 52px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.logo-icon {
  color: var(--color-primary);
  flex-shrink: 0;
}

.header-title h1 {
  font-size: var(--text-lg);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

.header-subtitle {
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
  line-height: 1.2;
}

.header-actions {
  display: flex;
  gap: var(--space-1);
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  color: var(--color-text-secondary);
  transition: all var(--transition-fast);
}

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

.icon-btn.active {
  background: var(--color-primary-bg);
  color: var(--color-primary);
}

/* ============================================================
   Filter Bar
   ============================================================ */
.filter-bar {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  z-index: 999;
  flex-shrink: 0;
  overflow: hidden;
}

.filter-scroll {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  white-space: nowrap;
}

.filter-scroll::-webkit-scrollbar { display: none; }

.filter-search {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--color-chip-bg);
  border-radius: var(--radius-full);
  padding: 6px 12px;
  min-width: 180px;
  flex-shrink: 0;
}

.filter-search svg {
  color: var(--color-text-tertiary);
  flex-shrink: 0;
}

.filter-search input {
  background: none;
  border: none;
  outline: none;
  font-size: var(--text-sm);
  color: var(--color-text);
  width: 100%;
  min-width: 120px;
}

.filter-search input::placeholder {
  color: var(--color-text-tertiary);
}

.filter-group {
  display: flex;
  gap: var(--space-1);
  flex-shrink: 0;
}

.filter-divider {
  width: 1px;
  height: 24px;
  background: var(--color-border);
  flex-shrink: 0;
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 500;
  background: var(--color-chip-bg);
  color: var(--color-text-secondary);
  border: 1px solid transparent;
  transition: all var(--transition-fast);
  white-space: nowrap;
  flex-shrink: 0;
}

.filter-chip:hover {
  border-color: var(--color-border);
  color: var(--color-text);
}

.filter-chip.active {
  background: var(--color-chip-active-bg);
  color: var(--color-chip-active-text);
  border-color: transparent;
}

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

/* ============================================================
   Main Content
   ============================================================ */
.app-main {
  flex: 1;
  position: relative;
  overflow: hidden;
}

.map-container {
  width: 100%;
  height: 100%;
  z-index: 1;
}

/* Leaflet overrides for dark mode */
[data-theme="dark"] .leaflet-tile-pane {
  filter: brightness(0.8) invert(1) contrast(1.1) hue-rotate(200deg) saturate(0.35);
}

[data-theme="dark"] .leaflet-control-zoom a {
  background: var(--color-surface-raised);
  color: var(--color-text);
  border-color: var(--color-border);
}

[data-theme="dark"] .leaflet-control-attribution {
  background: var(--color-surface) !important;
  color: var(--color-text-tertiary) !important;
}

[data-theme="dark"] .leaflet-control-attribution a {
  color: var(--color-text-secondary) !important;
}

/* Marker cluster overrides */
.marker-cluster {
  background: transparent !important;
}

.marker-cluster div {
  background: var(--color-primary) !important;
  color: var(--color-chip-active-text) !important;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 12px;
  width: 36px !important;
  height: 36px !important;
  margin-left: -2px !important;
  margin-top: -2px !important;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}

.marker-cluster-small div { width: 32px !important; height: 32px !important; }
.marker-cluster-medium div { width: 40px !important; height: 40px !important; }
.marker-cluster-large div { width: 48px !important; height: 48px !important; font-size: 14px; }

/* Custom markers */
.ev-marker {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2.5px solid white;
  box-shadow: 0 2px 8px rgba(0,0,0,0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease;
}

.ev-marker:hover {
  transform: scale(1.2);
  z-index: 9999 !important;
}

.ev-marker svg {
  width: 14px;
  height: 14px;
  fill: white;
}

.ev-marker.dcfast {
  width: 32px;
  height: 32px;
  border-width: 3px;
}

.ev-marker.dcfast svg {
  width: 16px;
  height: 16px;
}

/* ============================================================
   Popup Styles
   ============================================================ */
.leaflet-popup-content-wrapper {
  background: var(--color-popup-bg) !important;
  border: 1px solid var(--color-popup-border) !important;
  border-radius: var(--radius-lg) !important;
  box-shadow: var(--shadow-lg) !important;
  padding: 0 !important;
  max-width: 340px;
  min-width: 280px;
}

.leaflet-popup-content {
  margin: 0 !important;
  font-family: var(--font-body) !important;
  color: var(--color-text) !important;
  font-size: var(--text-sm) !important;
  line-height: 1.5 !important;
  width: 300px !important;
  max-width: 300px;
}

.leaflet-popup-tip {
  background: var(--color-popup-bg) !important;
  border: 1px solid var(--color-popup-border) !important;
  border-top: 0 !important;
  border-left: 0 !important;
}

.leaflet-popup-close-button {
  color: var(--color-text-secondary) !important;
  font-size: 20px !important;
  width: 28px !important;
  height: 28px !important;
  top: 8px !important;
  right: 8px !important;
}

/* Popup content */
.popup-card {
  padding: var(--space-4);
}

.popup-network {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: var(--space-2);
}

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

.popup-name {
  font-size: var(--text-lg);
  font-weight: 700;
  line-height: 1.25;
  margin-bottom: var(--space-1);
  padding-right: 20px;
}

.popup-address {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  margin-bottom: var(--space-3);
}

.popup-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: var(--space-3);
}

.popup-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.popup-badge.level {
  background: rgba(139, 92, 246, 0.12);
  color: var(--color-dcfast-badge);
}

.popup-badge.free {
  background: rgba(16, 185, 129, 0.12);
  color: var(--color-free-badge);
}

.popup-badge.hotel {
  background: rgba(245, 158, 11, 0.12);
  color: var(--color-hotel-badge);
}

.popup-badge.ports {
  background: var(--color-chip-bg);
  color: var(--color-text-secondary);
}

.popup-section {
  padding: var(--space-3) 0;
  border-top: 1px solid var(--color-border-subtle);
}

.popup-section-title {
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-tertiary);
  margin-bottom: var(--space-2);
}

.popup-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  font-size: var(--text-sm);
  margin-bottom: 4px;
}

.popup-row-label {
  color: var(--color-text-secondary);
  flex-shrink: 0;
}

.popup-row-value {
  text-align: right;
  font-weight: 500;
  max-width: 180px;
}

.popup-amenities {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.popup-amenity-tag {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 8px;
  background: var(--color-chip-bg);
  border-radius: var(--radius-full);
  font-size: 11px;
  color: var(--color-text-secondary);
}

.popup-amenity-names {
  font-size: 11px;
  color: var(--color-text-tertiary);
  margin-top: 4px;
  line-height: 1.4;
}

.popup-nav-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 10px;
  background: var(--color-primary);
  color: var(--color-chip-active-text);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 600;
  margin-top: var(--space-3);
  text-decoration: none;
  transition: background var(--transition-fast);
}

.popup-nav-btn:hover {
  background: var(--color-primary-hover);
}

/* ============================================================
   List View
   ============================================================ */
.list-view {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--color-bg);
  z-index: 500;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.list-view.hidden { display: none; }

.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text-secondary);
  flex-shrink: 0;
}

.list-sort {
  background: var(--color-chip-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 4px 8px;
  font-size: var(--text-xs);
  color: var(--color-text);
  cursor: pointer;
}

.list-container {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-2);
}

.list-card {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-3);
  background: var(--color-surface);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-2);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.list-card:hover {
  border-color: var(--color-primary);
  box-shadow: var(--shadow-sm);
}

.list-card-marker {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.list-card-marker svg {
  width: 18px;
  height: 18px;
  fill: white;
}

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

.list-card-name {
  font-size: var(--text-sm);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.list-card-address {
  font-size: var(--text-xs);
  color: var(--color-text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.list-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}

.list-card-tag {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: var(--radius-full);
  font-weight: 500;
}

.list-card-tag.network {
  background: var(--color-chip-bg);
  color: var(--color-text-secondary);
}

.list-card-tag.dcfast {
  background: rgba(139, 92, 246, 0.12);
  color: var(--color-dcfast-badge);
}

.list-card-tag.free-tag {
  background: rgba(16, 185, 129, 0.12);
  color: var(--color-free-badge);
}

.list-card-tag.hotel-tag {
  background: rgba(245, 158, 11, 0.12);
  color: var(--color-hotel-badge);
}

/* ============================================================
   Mobile Filter Toggle
   ============================================================ */
.mobile-filter-toggle {
  display: none;
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 20px;
  background: var(--color-surface-raised);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  z-index: 1001;
  align-items: center;
  gap: var(--space-2);
}

.mobile-filter-toggle svg {
  color: var(--color-primary);
}

/* Locate button */
.locate-btn {
  position: fixed;
  bottom: 24px;
  right: 16px;
  width: 44px;
  height: 44px;
  background: var(--color-surface-raised);
  border: 1px solid var(--color-border);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-md);
  z-index: 1001;
  color: var(--color-text-secondary);
  transition: all var(--transition-fast);
}

.locate-btn:hover {
  color: var(--color-primary);
  border-color: var(--color-primary);
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 768px) {
  .app-header { padding: var(--space-2) var(--space-3); height: 48px; }
  .header-title h1 { font-size: var(--text-base); }

  .filter-bar {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
    border-bottom: none;
  }

  .filter-bar.open {
    max-height: 300px;
    border-bottom: 1px solid var(--color-border);
    overflow: visible;
  }

  .filter-bar.open .filter-scroll {
    flex-wrap: wrap;
    white-space: normal;
    padding: var(--space-3);
    gap: var(--space-2);
  }

  .filter-bar.open .filter-divider { display: none; }
  .filter-bar.open .filter-group { flex-wrap: wrap; }

  .filter-bar.open .filter-search {
    width: 100%;
    min-width: unset;
  }

  .mobile-filter-toggle {
    display: flex;
  }

  .locate-btn {
    bottom: 80px;
  }

  .leaflet-popup-content-wrapper {
    max-width: 280px !important;
  }

  .leaflet-popup-content {
    max-width: 260px !important;
  }

  .popup-name {
    font-size: var(--text-base);
  }
}

@media (max-width: 380px) {
  .header-actions .icon-btn:nth-child(3) { display: none; }
}

/* ============================================================
   Loading state
   ============================================================ */
.loading-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  z-index: 600;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading-text {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  font-weight: 500;
}

/* Empty state in list */
.list-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-8);
  color: var(--color-text-tertiary);
  text-align: center;
}

.list-empty svg {
  width: 48px;
  height: 48px;
  margin-bottom: var(--space-3);
  opacity: 0.4;
}
