:root {
  --bg: #f0f2f5;
  --bg-panel: #ffffff;
  --bg-card: #f7f8fa;
  --bg-input: #f0f2f5;
  --border: #e0e3e8;
  --text: #1a1a2e;
  --text-dim: #5a6478;
  --text-muted: #8892a4;
  --accent: #4c8bf5;
  --accent-hover: #3a7ae0;
  --green: #16a34a;
  --yellow: #d97706;
  --red: #dc2626;
  --radius: 10px;
  --radius-sm: 6px;
  --map-filter: none;
  --popup-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  --panel-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  --heading-color: #1a1a2e;
  --marker-border: rgba(0, 0, 0, 0.15);
}

[data-theme="dark"] {
  --bg: #1a1a2e;
  --bg-panel: #16213e;
  --bg-card: #1e2a47;
  --bg-input: #0f1a30;
  --border: #2a3a5c;
  --text: #e0e0e0;
  --text-dim: #8892a4;
  --text-muted: #5a6478;
  --accent: #4c8bf5;
  --accent-hover: #6ba1ff;
  --green: #16a34a;
  --yellow: #d97706;
  --red: #dc2626;
  --map-filter: brightness(0.75) contrast(1.1) saturate(0.3) hue-rotate(180deg) invert(1);
  --popup-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  --panel-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  --heading-color: #ffffff;
  --marker-border: rgba(255, 255, 255, 0.2);
}

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

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
}

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

/* Map tiles filter (dark mode inverts) */
.leaflet-tile-pane {
  filter: var(--map-filter);
}

.leaflet-control-attribution {
  background: var(--bg-panel) !important;
  color: var(--text-muted) !important;
  font-size: 10px;
}

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

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

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

/* Panel */
#panel {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 1000;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  width: 290px;
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  backdrop-filter: blur(12px);
  box-shadow: var(--panel-shadow);
}

#panel::-webkit-scrollbar {
  width: 4px;
}

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

#panel::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

/* Header */
#panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

#panel h1 {
  font-size: 17px;
  font-weight: 600;
  margin-bottom: 2px;
  color: var(--heading-color);
  letter-spacing: -0.3px;
}

#theme-toggle,
#panel-toggle {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12px;
  padding: 4px 8px;
  color: var(--text-dim);
  flex-shrink: 0;
  margin-top: 2px;
  transition: all 0.2s;
}

#theme-toggle:hover,
#panel-toggle:hover {
  background: var(--border);
  color: var(--text);
}

#panel-body {
  overflow: hidden;
  transition: max-height 0.3s ease, opacity 0.2s ease;
  max-height: 800px;
  opacity: 1;
}

#panel-body.collapsed {
  max-height: 0;
  opacity: 0;
}

/* Date section */
#date-section {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

#date-display {
  font-size: 13px;
  color: var(--text-dim);
  font-weight: 500;
}

#history-select {
  font-size: 11px;
  padding: 3px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text);
  cursor: pointer;
}

/* Fuel tabs */
#fuel-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 14px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  padding: 3px;
}

.fuel-tab {
  flex: 1;
  padding: 7px 4px;
  font-size: 11px;
  font-weight: 500;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.2s;
}

.fuel-tab:hover {
  color: var(--text);
  background: var(--bg-card);
}

.fuel-tab.active {
  background: var(--accent);
  color: var(--heading-color);
  box-shadow: 0 2px 8px rgba(76, 139, 245, 0.3);
}

/* Averages */
#averages {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 14px;
}

.avg-row {
  display: flex;
  justify-content: space-between;
  padding: 3px 0;
}

.avg-label {
  color: var(--text-dim);
  font-size: 12px;
}

.avg-value {
  font-weight: 600;
  font-size: 13px;
  color: var(--heading-color);
  font-variant-numeric: tabular-nums;
}

/* Filters */
#filters {
  margin-bottom: 14px;
}

.filter-section {
  margin-bottom: 8px;
}

.filter-section label {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-dim);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.filter-section select,
.filter-section input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  background: var(--bg-input);
  color: var(--text);
  transition: border-color 0.2s;
  outline: none;
}

.filter-section select:focus,
.filter-section input:focus {
  border-color: var(--accent);
}

.filter-section input::placeholder {
  color: var(--text-muted);
}

/* Cluster mode */
#cluster-mode {
  margin-bottom: 14px;
}

#cluster-mode label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-dim);
  display: block;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

#mode-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  padding: 3px;
}

.mode-tab {
  flex: 1;
  padding: 6px 8px;
  font-size: 12px;
  font-weight: 500;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.2s;
}

.mode-tab:hover {
  color: var(--text);
  background: var(--bg-card);
}

.mode-tab.active {
  background: var(--accent);
  color: var(--heading-color);
  box-shadow: 0 2px 8px rgba(76, 139, 245, 0.3);
}

/* Legend */
#legend {
  margin-bottom: 14px;
  font-size: 12px;
}

.legend-title {
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
  font-size: 12px;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 0;
  color: var(--text-dim);
  font-size: 12px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

/* Stats */
#stats {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

/* Attribution */
#attribution {
  font-size: 10px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

#attribution a {
  color: var(--accent);
  text-decoration: none;
}

#attribution a:hover {
  color: var(--accent-hover);
}

/* Cluster & marker price labels */
.price-cluster {
  background: transparent !important;
}

.cluster-icon {
  border-radius: 20px;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  text-align: center;
  white-space: nowrap;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  border: 2px solid rgba(255, 255, 255, 0.5);
  font-variant-numeric: tabular-nums;
}

/* Popup styles */
.leaflet-popup-content-wrapper {
  background: var(--bg-panel) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius) !important;
  box-shadow: var(--popup-shadow) !important;
  color: var(--text) !important;
}

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

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

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

.station-popup h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--heading-color);
}

.station-popup .company {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.station-popup .address {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.station-popup .prices {
  font-size: 13px;
}

.station-popup .price-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
}

.station-popup .price-row:last-child {
  border-bottom: none;
}

.station-popup .fuel-name {
  color: var(--text-dim);
  font-size: 12px;
}

.station-popup .price-value {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.station-popup .change-up {
  color: var(--red);
  font-size: 11px;
  font-weight: 500;
}

.station-popup .change-down {
  color: var(--green);
  font-size: 11px;
  font-weight: 500;
}

.station-popup .change-none {
  color: var(--text-muted);
  font-size: 11px;
}

/* Marker cluster overrides for dark theme */
.marker-cluster-small,
.marker-cluster-medium,
.marker-cluster-large {
  background: rgba(76, 139, 245, 0.2) !important;
}

.marker-cluster-small div,
.marker-cluster-medium div,
.marker-cluster-large div {
  background: var(--accent) !important;
  color: #fff !important;
  font-weight: 600;
}

/* Mobile responsive */
@media (max-width: 600px) {
  #panel {
    width: calc(100% - 24px);
    max-height: 45vh;
  }

  #fuel-tabs {
    flex-wrap: wrap;
  }
}
