/* ============================================
   GASOLINA APP - iOS PWA Optimized UI
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

:root {
  --bg-primary: #0a0e17;
  --bg-secondary: #0f1923;
  --bg-card: rgba(22, 34, 50, 0.85);

  --accent-green: #00d4aa;
  --accent-yellow: #f59e0b;
  --accent-red: #ef4444;
  --accent-blue: #3b82f6;

  --text-primary: #e8edf5;
  --text-secondary: #8899aa;
  --text-muted: #4a5e73;

  --border-subtle: rgba(255, 255, 255, 0.08);
  --glass-bg: rgba(15, 25, 35, 0.85);
  --glass-blur: 16px;

  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-card: 0 8px 32px rgba(0, 0, 0, 0.4);

  /* iOS Safe Area Insets */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  /* Disable iOS tap highlight */
  -webkit-tap-highlight-color: transparent;
}

html {
  /* Prevent iOS rubber-band scrolling on map view */
  overscroll-behavior: none;
}

html, body {
  font-family: 'Inter', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  width: 100%;
  /* Use dvh for dynamic viewport that handles iOS Safari toolbar */
  height: 100dvh;
  height: 100vh; /* Fallback for older browsers */
  overflow: hidden;
  /* Disable text selection on UI elements */
  -webkit-user-select: none;
  user-select: none;
  /* Smooth font rendering on iOS */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Allow text selection on input fields */
input, textarea {
  -webkit-user-select: auto;
  user-select: auto;
}

/* For pages that need scrolling like station details */
body.scrollable {
  height: auto;
  min-height: 100dvh;
  min-height: 100vh; /* Fallback */
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}

/* Animated background gradient for details page */
body.scrollable::before {
  content: '';
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(0, 212, 170, 0.05) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 100%, rgba(59, 130, 246, 0.05) 0%, transparent 50%);
  pointer-events: none;
  z-index: -1;
}

/* ---- iOS Standalone (PWA) specific adjustments ---- */
@media all and (display-mode: standalone) {
  /* When running as installed PWA, account for the status bar */
  .search-box {
    top: calc(20px + var(--safe-top)) !important;
  }
  
  .top-stations-panel {
    bottom: calc(24px + var(--safe-bottom)) !important;
  }
  
  .detail-container {
    padding-top: calc(20px + var(--safe-top)) !important;
    padding-bottom: calc(60px + var(--safe-bottom)) !important;
  }
  
  /* Locate button adjustment in standalone */
  .locate-btn {
    top: calc(140px + var(--safe-top)) !important;
  }
}

/* Glass panel utility */
.glass-panel {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
}

/* ---- MAP CONTAINER ---- */
#map-container {
  position: relative;
  width: 100%;
  height: 100dvh;
  height: 100vh; /* Fallback */
  z-index: 1;
  /* Prevent overscroll bouncing on iOS */
  overflow: hidden;
  touch-action: manipulation;
}

#map {
  width: 100%;
  height: 100%;
  z-index: 1;
  /* Ensure touch events work properly for Leaflet */
  touch-action: none;
}

/* ---- SEARCH BAR (Google Maps style) ---- */
.search-box {
  position: absolute;
  top: calc(20px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  width: calc(100% - 24px);
  max-width: 400px;
  display: flex;
  flex-direction: column;
  padding: 8px;
  gap: 8px;
}

.search-input-wrapper {
  display: flex;
  align-items: center;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  padding: 4px 12px;
}

.search-icon {
  font-size: 16px;
  margin-right: 8px;
  opacity: 0.7;
  flex-shrink: 0;
}

#search-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 16px; /* 16px minimum prevents iOS auto-zoom on focus */
  padding: 10px 0;
  outline: none;
  min-width: 0; /* Prevent input from overflowing flex container */
}

#search-input::placeholder {
  color: var(--text-muted);
  font-size: 0.85rem;
}

#search-clear {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 8px;
  font-size: 16px;
  flex-shrink: 0;
  /* Larger touch target */
  min-width: 36px;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.fuel-selector-wrapper {
  display: flex;
  gap: 8px;
  align-items: center;
}

.custom-select.small-select {
  flex: 1;
  appearance: none;
  -webkit-appearance: none;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  outline: none;
  /* Prevent iOS default styling */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238899aa' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}

.btn-icon {
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  width: 40px;
  height: 40px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  /* Better touch target */
  min-width: 40px;
  min-height: 40px;
  transition: all 0.2s ease;
}

.btn-icon:active {
  background: rgba(0, 212, 170, 0.15);
  border-color: var(--accent-green);
  color: var(--accent-green);
  transform: scale(0.95);
}

/* Search Results Autocomplete */
.search-results {
  position: absolute;
  top: 110px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  width: calc(100% - 24px);
  max-width: 400px;
  max-height: min(300px, 40vh);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 0;
}

.result-item {
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid rgba(255,255,255,0.03);
  display: flex;
  flex-direction: column;
  transition: background 0.15s ease;
  /* Minimum touch target size for iOS */
  min-height: 44px;
  justify-content: center;
}

.result-item:active {
  background: rgba(255,255,255,0.08);
}

.result-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
}

.result-sub {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* ---- MAP POPUP OVERRIDES ---- */
.leaflet-popup-content-wrapper {
  background: var(--bg-secondary) !important;
  color: var(--text-primary) !important;
  border-radius: var(--radius-md) !important;
  border: 1px solid var(--border-subtle) !important;
  padding: 0 !important;
  overflow: hidden;
}

.leaflet-popup-content {
  margin: 0 !important;
  font-size: 14px !important;
  line-height: 1.5 !important;
}

.leaflet-popup-tip {
  background: var(--bg-secondary) !important;
}

/* Make popup close button more touch-friendly */
.leaflet-popup-close-button {
  width: 32px !important;
  height: 32px !important;
  font-size: 20px !important;
  line-height: 32px !important;
  color: var(--text-secondary) !important;
  padding: 0 !important;
  right: 4px !important;
  top: 4px !important;
}

.map-popup-inner {
  padding: 14px;
  width: 100%;
}

.popup-station-name {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--accent-green);
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 24px; /* Space for close button */
}

.popup-address {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.popup-price-primary {
  font-size: 1.1rem;
  font-weight: 800;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.popup-price-value {
  color: var(--text-primary);
}
.popup-price-value.cheap { color: var(--accent-green); }
.popup-price-value.expensive { color: var(--accent-red); }

.popup-btn {
  display: block;
  width: 100%;
  background: #162436;
  color: white;
  text-align: center;
  padding: 12px;
  border-radius: 8px;
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
  transition: all 0.2s ease;
  /* iOS minimum touch target */
  min-height: 44px;
  line-height: 20px;
}

.popup-btn:active {
  background: var(--accent-blue);
  transform: scale(0.98);
}

/* Markers */
.custom-marker {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.9);
  box-shadow: 0 0 8px rgba(0, 0, 0, 0.6);
}
.custom-marker.cheap { background: var(--accent-green); }
.custom-marker.mid { background: var(--accent-yellow); }
.custom-marker.expensive { background: var(--accent-red); }
.custom-marker.electric { 
  background: #3b82f6; /* Blue for Electric */
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 8px;
}
.custom-marker.electric::after {
  content: '⚡';
  color: white;
}
.popup-price-value.electric {
  color: #3b82f6;
  font-weight: 800;
}
.popup-btn.btn-ev {
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
}

/* Leaflet Cluster Overrides for dark theme */
.marker-cluster-small {
  background-color: rgba(0, 212, 170, 0.3) !important;
}
.marker-cluster-small div {
  background-color: rgba(0, 212, 170, 0.6) !important;
  color: #fff !important;
  font-weight: 700 !important;
  font-family: 'Inter', sans-serif !important;
}
.marker-cluster-medium {
  background-color: rgba(245, 158, 11, 0.3) !important;
}
.marker-cluster-medium div {
  background-color: rgba(245, 158, 11, 0.6) !important;
  color: #fff !important;
  font-weight: 700 !important;
  font-family: 'Inter', sans-serif !important;
}
.marker-cluster-large {
  background-color: rgba(239, 68, 68, 0.3) !important;
}
.marker-cluster-large div {
  background-color: rgba(239, 68, 68, 0.6) !important;
  color: #fff !important;
  font-weight: 700 !important;
  font-family: 'Inter', sans-serif !important;
}

/* Locate button on map */
.locate-btn {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--border-subtle);
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 18px;
  box-shadow: var(--shadow-card);
  transition: all 0.2s ease;
}

.locate-btn:active {
  background: rgba(59, 130, 246, 0.2);
  border-color: var(--accent-blue);
  transform: scale(0.95);
}

/* Leaflet zoom controls - styled for dark theme */
.leaflet-control-zoom {
  border: none !important;
  box-shadow: var(--shadow-card) !important;
}

.leaflet-control-zoom a {
  background: var(--glass-bg) !important;
  color: var(--text-primary) !important;
  border: 1px solid var(--border-subtle) !important;
  backdrop-filter: blur(var(--glass-blur)) !important;
  -webkit-backdrop-filter: blur(var(--glass-blur)) !important;
  width: 36px !important;
  height: 36px !important;
  line-height: 36px !important;
  font-size: 18px !important;
}

.leaflet-control-zoom a:first-child {
  border-radius: 10px 10px 0 0 !important;
}

.leaflet-control-zoom a:last-child {
  border-radius: 0 0 10px 10px !important;
}

.leaflet-control-zoom a:active {
  background: rgba(255,255,255,0.1) !important;
}

/* Hide Leaflet attribution on small screens */
@media (max-width: 480px) {
  .leaflet-control-attribution {
    font-size: 8px !important;
    max-width: 200px;
    background: rgba(0,0,0,0.5) !important;
    color: var(--text-muted) !important;
    padding: 2px 6px !important;
    border-radius: 4px 0 0 0 !important;
  }
  .leaflet-control-attribution a {
    color: var(--text-secondary) !important;
  }
}

/* ---- STATION DETAILS PAGE ---- */
.detail-container {
  max-width: 600px;
  margin: 0 auto;
  padding: 20px;
  padding-top: calc(20px + var(--safe-top));
  padding-bottom: calc(60px + var(--safe-bottom));
  padding-left: calc(20px + var(--safe-left));
  padding-right: calc(20px + var(--safe-right));
}

.nav-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
  padding-top: 10px;
}

.btn-back {
  background: var(--glass-bg);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  /* iOS minimum touch target */
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  font-size: 1.2rem;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.btn-back:active {
  background: rgba(255,255,255,0.1);
  transform: scale(0.95);
}

.station-header {
  overflow: hidden;
}

.station-header h1 {
  font-size: 1.3rem;
  font-weight: 800;
  line-height: 1.2;
  margin-bottom: 6px;
  background: linear-gradient(135deg, #fff, var(--text-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.station-header p {
  font-size: 0.85rem;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
  word-wrap: break-word;
}

.update-badge {
  display: inline-block;
  background: rgba(0, 212, 170, 0.15);
  color: var(--accent-green);
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  margin-top: 16px;
}

.prices-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-top: 24px;
  margin-bottom: 24px;
}

.price-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 16px;
  text-align: center;
  transition: transform 0.2s ease;
}

.price-card:active {
  transform: scale(0.98);
}

.price-card.active {
  border-color: var(--accent-blue);
  background: rgba(59, 130, 246, 0.05);
}

.price-fuel-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
  font-weight: 500;
}

.price-fuel-value {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text-primary);
}

.price-fuel-none {
  font-size: 0.9rem;
  color: var(--text-muted);
  font-weight: 400;
}

.chart-section {
  background: var(--glass-bg);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 24px;
}

.chart-section h3 {
  font-size: 1rem;
  margin-bottom: 16px;
  font-weight: 600;
}

.station-chart-wrapper {
  position: relative;
  height: 220px;
  width: 100%;
  /* Allow touch interaction with chart */
  touch-action: pan-x pan-y;
}

.utility-buttons {
  display: flex;
  gap: 12px;
}

.utility-btn {
  flex: 1;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  padding: 14px 12px;
  border-radius: var(--radius-md);
  color: var(--text-primary);
  text-align: center;
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  /* iOS minimum touch target */
  min-height: 48px;
  transition: all 0.2s ease;
}

.utility-btn:active {
  transform: scale(0.98);
  background: rgba(255,255,255,0.05);
}

.utility-btn.primary {
  background: var(--accent-blue);
  color: white;
  border: none;
}

.utility-btn.primary:active {
  background: #2563eb;
}

/* Loading Overlay */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-primary);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: opacity 0.3s ease;
}

.loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.loader {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 3px solid var(--border-subtle);
  border-top-color: var(--accent-green);
  animation: spin 0.8s linear infinite;
  margin-bottom: 16px;
}

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

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

/* Helpers */
.hidden { display: none !important; }

/* ---- INSTALL PWA BANNER ---- */
.install-banner {
  position: fixed;
  bottom: calc(20px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 10px 16px;
  box-shadow: var(--shadow-card);
  animation: slideUp 0.3s ease;
}

.install-btn {
  background: var(--accent-green);
  color: var(--bg-primary);
  border: none;
  padding: 6px 14px;
  border-radius: 6px;
  font-weight: 700;
  font-size: 0.8rem;
  cursor: pointer;
  min-height: 32px;
}

.install-banner .dismiss {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px;
  font-size: 16px;
}

/* ---- TOP STATIONS PANEL ---- */
.top-stations-panel {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1000;
  width: calc(100% - 24px);
  max-width: 400px;
  max-height: 60vh;
  display: flex;
  flex-direction: column;
  animation: popCenter 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes popCenter {
  from { opacity: 0; transform: translate(-50%, -40%) scale(0.95); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

.top-stations-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-subtle);
  background: rgba(0,0,0,0.3);
  border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.top-stations-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--accent-green);
}

.btn-icon-small {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 1.1rem;
  cursor: pointer;
  /* Larger touch target */
  padding: 8px;
  min-width: 36px;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-icon-small:active {
  color: white;
}

.top-stations-list {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 0;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
}

.top-station-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.03);
  text-decoration: none;
  color: inherit;
  transition: background 0.15s ease;
  /* iOS minimum touch target */
  min-height: 48px;
}

.top-station-item:last-child {
  border-bottom: none;
}

.top-station-item:active {
  background: rgba(255,255,255,0.08);
}

.top-st-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: hidden;
  flex: 1;
}

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

.top-st-addr {
  font-size: 0.7rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-st-price {
  font-weight: 800;
  color: var(--accent-green);
  font-size: 0.95rem;
  margin-left: 10px;
  flex-shrink: 0;
}

/* ---- iOS SPLASH SCREEN STYLES ---- */
/* Smooth fade-in for content after splash */
.fade-in {
  animation: fadeIn 0.4s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---- RESPONSIVE: Small phones (iPhone SE, etc.) ---- */
@media (max-width: 375px) {
  .search-box {
    width: calc(100% - 16px);
    padding: 6px;
    gap: 6px;
  }
  
  #search-input {
    font-size: 16px; /* Keep 16px to prevent zoom */
    padding: 8px 0;
  }
  
  #search-input::placeholder {
    font-size: 0.75rem;
  }
  
  .custom-select.small-select {
    padding: 8px 10px;
    font-size: 0.75rem;
  }
  
  .top-stations-panel {
    width: calc(100% - 16px);
    max-height: 65vh;
  }
  
  .prices-grid {
    gap: 8px;
  }
  
  .price-card {
    padding: 12px;
  }
  
  .price-fuel-value {
    font-size: 1.3rem;
  }
  
  .station-header h1 {
    font-size: 1.1rem;
  }
}

/* ---- RESPONSIVE: Medium phones (iPhone 12/13/14) ---- */
@media (min-width: 376px) and (max-width: 430px) {
  .search-box {
    width: calc(100% - 20px);
  }
  
  .top-stations-panel {
    width: calc(100% - 20px);
  }
}

/* ---- RESPONSIVE: Large phones / Small tablets ---- */
@media (min-width: 431px) and (max-width: 768px) {
  .search-box {
    max-width: 420px;
  }
}

/* ---- RESPONSIVE: Tablets & Desktop ---- */
@media (min-width: 769px) {
  .search-box {
    max-width: 440px;
  }
  
  .top-stations-panel {
    max-width: 440px;
  }
  
  /* Show hover effects only on non-touch */
  .btn-icon:hover {
    border-color: var(--accent-green);
    color: var(--accent-green);
  }
  
  .result-item:hover {
    background: rgba(255,255,255,0.05);
  }
  
  .top-station-item:hover {
    background: rgba(255,255,255,0.05);
  }
  
  .popup-btn:hover {
    background: var(--accent-blue);
  }
  
  .btn-back:hover {
    background: rgba(255,255,255,0.1);
  }
}

/* ---- Landscape mode on phones ---- */
@media (max-height: 500px) and (orientation: landscape) {
  .search-box {
    top: calc(8px + var(--safe-top));
    padding: 6px;
  }
  
  .top-stations-panel {
    bottom: calc(8px + var(--safe-bottom));
    max-height: 50vh;
  }
  
  .station-chart-wrapper {
    height: 180px;
  }
}

/* ---- SAVINGS CALCULATOR - Floating Button ---- */
.btn-calculate {
  position: fixed;
  bottom: calc(45px + var(--safe-bottom));
  right: 16px;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(135deg, #00d4aa, #00b894);
  color: #0a0e17;
  border: none;
  border-radius: 28px;
  padding: 12px 20px;
  font-family: 'Inter', sans-serif;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(0, 212, 170, 0.4), 0 2px 8px rgba(0, 0, 0, 0.3);
  transition: all 0.25s ease;
  min-height: 48px;
}

.btn-calculate:active {
  transform: scale(0.95);
  box-shadow: 0 2px 12px rgba(0, 212, 170, 0.3);
}

.btn-calculate-icon {
  font-size: 1.2rem;
}

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

/* ---- SAVINGS BADGE ---- */
.savings-badge {
  position: fixed;
  bottom: calc(100px + var(--safe-bottom));
  right: 16px;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid rgba(0, 212, 170, 0.3);
  border-radius: 20px;
  padding: 8px 14px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent-green);
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  transition: all 0.2s ease;
}

.savings-badge:active {
  transform: scale(0.95);
}

.savings-badge-icon {
  font-size: 1rem;
}

.badge-pulse {
  animation: badgePulse 0.6s ease;
}

@keyframes badgePulse {
  0% { transform: scale(1); }
  30% { transform: scale(1.1); box-shadow: 0 0 20px rgba(0, 212, 170, 0.5); }
  100% { transform: scale(1); }
}

/* ---- BOTTOM SHEET OVERLAY ---- */
.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 2000;
  animation: fadeIn 0.2s ease;
}

/* ---- BOTTOM SHEET PANEL ---- */
.savings-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 2001;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-subtle);
  border-radius: 20px 20px 0 0;
  max-height: 85vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px 20px calc(20px + var(--safe-bottom));
  box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.5);
  animation: sheetSlideUp 0.35s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

.savings-sheet.sheet-closing {
  animation: sheetSlideDown 0.3s ease forwards;
}

@keyframes sheetSlideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

@keyframes sheetSlideDown {
  from { transform: translateY(0); }
  to { transform: translateY(100%); }
}

.sheet-handle {
  width: 40px;
  height: 4px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
  margin: 8px auto 16px;
}

.sheet-section {
  padding-bottom: 12px;
}

.sheet-title {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.sheet-subtitle {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 20px;
  line-height: 1.4;
}

/* ---- SHEET INPUT FIELDS ---- */
.sheet-field {
  margin-bottom: 20px;
}

.sheet-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

.sheet-input-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

/* Custom Range Slider */
.sheet-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  outline: none;
}

.sheet-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent-green);
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 212, 170, 0.4);
  border: 3px solid #0f1923;
}

.sheet-slider::-moz-range-thumb {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent-green);
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 212, 170, 0.4);
  border: 3px solid #0f1923;
}

.sheet-input-box {
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 6px 10px;
  min-width: 100px;
}

.sheet-number-input {
  width: 48px;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  font-size: 0.95rem;
  font-weight: 700;
  text-align: right;
  outline: none;
  -moz-appearance: textfield;
}

.sheet-number-input::-webkit-inner-spin-button,
.sheet-number-input::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.sheet-input-unit {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
}

/* Fuel info row */
.sheet-fuel-info {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  margin-bottom: 20px;
  font-size: 0.85rem;
  font-weight: 600;
}

.sheet-fuel-hint {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 400;
}

/* Find Best Button */
.btn-find-best {
  width: 100%;
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: white;
  border: none;
  border-radius: 12px;
  padding: 16px;
  font-family: 'Inter', sans-serif;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  min-height: 52px;
  transition: all 0.2s ease;
  box-shadow: 0 4px 16px rgba(59, 130, 246, 0.3);
}

.btn-find-best:active {
  transform: scale(0.98);
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.2);
}

/* ---- RESULTS VIEW ---- */
.sheet-results-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.btn-back-sheet {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.1rem;
  flex-shrink: 0;
  transition: all 0.15s ease;
}

.btn-back-sheet:active {
  background: rgba(255, 255, 255, 0.15);
  transform: scale(0.95);
}

.results-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Result Card */
.result-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 16px;
  transition: all 0.2s ease;
  animation: fadeIn 0.3s ease;
}

.result-card.result-rank-best {
  border-color: rgba(0, 212, 170, 0.4);
  background: rgba(0, 212, 170, 0.05);
  box-shadow: 0 0 20px rgba(0, 212, 170, 0.08);
}

.result-rank {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent-green);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.result-station-name {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.result-station-addr {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-bottom: 14px;
}

.result-details {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}

.result-detail-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.result-detail-label {
  font-size: 0.68rem;
  color: var(--text-muted);
  font-weight: 500;
}

.result-detail-value {
  font-size: 0.85rem;
  color: var(--text-primary);
  font-weight: 600;
}

.result-detail-trip .result-detail-value {
  color: var(--accent-yellow);
  font-size: 0.8rem;
}

/* Total cost row */
.result-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 8px;
  margin-bottom: 10px;
}

.result-total-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.result-total-value {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--text-primary);
}

.result-rank-best .result-total-value {
  color: var(--accent-green);
}

.result-total-sublabel {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  margin-top: 2px;
}

/* Savings message */
.result-savings {
  font-size: 0.78rem;
  color: var(--accent-green);
  padding: 8px 12px;
  background: rgba(0, 212, 170, 0.08);
  border-radius: 8px;
  margin-bottom: 12px;
  text-align: center;
  line-height: 1.4;
}

/* Go refuel button */
.btn-go-refuel {
  width: 100%;
  background: linear-gradient(135deg, #00d4aa, #00b894);
  color: #0a0e17;
  border: none;
  border-radius: 10px;
  padding: 13px;
  font-family: 'Inter', sans-serif;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  min-height: 46px;
  transition: all 0.15s ease;
}

.btn-go-refuel:active {
  transform: scale(0.97);
  filter: brightness(0.9);
}

/* ---- TOAST NOTIFICATION ---- */
.app-toast {
  position: fixed;
  bottom: calc(90px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  padding: 14px 24px;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-weight: 500;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  animation: toastIn 0.3s ease;
  max-width: calc(100% - 32px);
  text-align: center;
  line-height: 1.4;
}

.app-toast.toast-out {
  animation: toastOut 0.4s ease forwards;
}

@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

@keyframes toastOut {
  from { opacity: 1; transform: translate(-50%, 0); }
  to { opacity: 0; transform: translate(-50%, 10px); }
}

/* ---- LOAD ERROR BANNER ---- */
.load-error-banner {
  position: fixed;
  top: calc(80px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 3000;
  background: var(--bg-card);
  border: 1px solid var(--accent-red);
  border-radius: var(--radius-md);
  padding: 16px;
  width: calc(100% - 32px);
  max-width: 400px;
  box-shadow: var(--shadow-card);
  animation: toastIn 0.3s ease;
}

.load-error-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
}

.load-error-icon {
  font-size: 2rem;
}

.load-error-text {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.load-error-text strong {
  color: var(--accent-red);
  font-size: 1rem;
}

.load-error-text span {
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.load-error-retry {
  background: var(--accent-red);
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  transition: all 0.2s ease;
}

.load-error-retry:active {
  transform: scale(0.95);
  background: #dc2626;
}

/* ---- iOS Standalone adjustments for savings UI ---- */
@media all and (display-mode: standalone) {
  .btn-calculate {
    bottom: calc(45px + var(--safe-bottom)) !important;
  }
  
  .savings-badge {
    bottom: calc(100px + var(--safe-bottom)) !important;
  }
  
  .savings-sheet {
    padding-bottom: calc(20px + var(--safe-bottom)) !important;
  }
}

/* ---- Responsive: Small phones ---- */
@media (max-width: 375px) {
  .btn-calculate {
    padding: 10px 14px;
    font-size: 0.78rem;
    gap: 6px;
  }
  
  .btn-calculate-label {
    display: none; /* Only show icon on small screens */
  }
  
  .savings-badge {
    padding: 6px 10px;
    font-size: 0.72rem;
  }
  
  .sheet-title {
    font-size: 1rem;
  }
  
  .result-details {
    gap: 6px;
  }
}

/* ---- Landscape mode ---- */
@media (max-height: 500px) and (orientation: landscape) {
  .savings-sheet {
    max-height: 90vh;
  }
  
  .btn-calculate {
    bottom: calc(8px + var(--safe-bottom));
  }
  
  .savings-badge {
    bottom: calc(60px + var(--safe-bottom));
  }
}

/* ---- Desktop hover states ---- */
@media (min-width: 769px) {
  .btn-calculate:hover {
    box-shadow: 0 6px 28px rgba(0, 212, 170, 0.5);
    transform: translateY(-2px);
  }
  
  .btn-find-best:hover {
    box-shadow: 0 6px 24px rgba(59, 130, 246, 0.4);
    transform: translateY(-1px);
  }
  
  .btn-go-refuel:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
  }
  
  .result-card:hover {
    border-color: rgba(255, 255, 255, 0.15);
  }
  
  .savings-badge:hover {
    border-color: rgba(0, 212, 170, 0.5);
  }
}

/* ---- Dark status bar for iOS ---- */
@supports (padding-top: env(safe-area-inset-top)) {
  body::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: env(safe-area-inset-top);
    background: rgba(10, 14, 23, 0.8);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    z-index: 999;
    pointer-events: none;
  }
  
  /* Don't show status bar overlay on detail page */
  body.scrollable::after {
    display: none;
  }
}
