/* Force light mode — prevent dark mode from inverting map tiles */
:root { color-scheme: light only !important; }
html { color-scheme: light only !important; }

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

:root {
  --bg: #ffffff;
  --bg-card: #ffffff;
  --bg-muted: #f5f5f7;
  --border: #e5e5e7;
  --text: #1d1d1f;
  --text-secondary: #6e6e73;
  --text-tertiary: #aeaeb2;
  --green: #34c759;
  --orange: #ff9500;
  --red: #ff3b30;
  --blue: #007aff;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

/* ===== Map ===== */
#map {
  position: fixed;
  inset: 0;
  z-index: 1;
}

/* Prevent dark mode from inverting map tiles */
.leaflet-tile-pane,
.leaflet-tile-pane img,
.leaflet-container,
.leaflet-layer,
.leaflet-tile {
  filter: none !important;
  -webkit-filter: none !important;
  mix-blend-mode: normal !important;
  color-scheme: light !important;
}

@media (prefers-color-scheme: dark) {
  .leaflet-tile-pane,
  .leaflet-tile-pane img,
  .leaflet-container,
  .leaflet-layer,
  .leaflet-tile {
    filter: none !important;
    -webkit-filter: none !important;
  }
  #map {
    background: #e8e0d8 !important;
  }
}

.leaflet-control-zoom { display: none; }
.leaflet-control-attribution {
  font-size: 9px !important;
  background: rgba(255,255,255,0.7) !important;
  padding: 2px 6px !important;
}

/* Map markers */
.station-pin {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border-radius: 20px;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(0,0,0,0.18);
  border: 2px solid;
  white-space: nowrap;
  min-width: 44px;
  text-align: center;
}
.station-pin.cheap { border-color: var(--green); color: #1a8f35; }
.station-pin.mid { border-color: var(--orange); color: #b36b00; }
.station-pin.expensive { border-color: var(--red); color: var(--red); }

.station-pin-active {
  transform: scale(1.15);
  box-shadow: 0 4px 16px rgba(0,122,255,0.35);
  border-color: var(--blue) !important;
  color: var(--blue) !important;
  z-index: 999 !important;
}

/* User location dot */
.user-dot {
  width: 18px;
  height: 18px;
  background: #ED017F;
  border: 3px solid #fff;
  border-radius: 50%;
  box-shadow: 0 2px 10px rgba(237,1,127,0.5);
}

/* ===== Top Bar ===== */
#topBar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  padding: calc(var(--safe-top) + 8px) 16px 8px;
  pointer-events: none;
}

.search-container {
  display: flex;
  align-items: center;
  background: var(--bg-card);
  border-radius: 12px;
  box-shadow: 0 2px 16px rgba(0,0,0,0.1);
  padding: 0 4px 0 14px;
  pointer-events: all;
  gap: 6px;
}

.search-icon { flex-shrink: 0; }

#searchInput {
  flex: 1;
  min-width: 0;
  padding: 14px 0;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: 16px;
  outline: none;
  -webkit-appearance: none;
}
#searchInput::placeholder { color: var(--text-tertiary); }

#fuelSelect {
  flex-shrink: 0;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-muted);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
  outline: none;
  text-align: center;
  text-align-last: center;
}

#locateBtn {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: none;
  background: var(--bg-muted);
  color: var(--blue);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s;
}
#locateBtn:active { background: #ddd; }

/* ===== Station List (Bottom Sheet) ===== */
.station-list {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1100;
  background: var(--bg-card);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -4px 30px rgba(0,0,0,0.12);
  max-height: 55vh;
  min-height: 200px;
  display: flex;
  flex-direction: column;
  transition: max-height 0.35s cubic-bezier(0.25, 1, 0.5, 1);
}

.station-list.expanded {
  max-height: 55vh;
}

.station-list.collapsed {
  max-height: 80px;
}

.station-list.hidden-list {
  max-height: 0 !important;
  min-height: 0 !important;
  overflow: hidden !important;
  padding-bottom: 0 !important;
  box-shadow: none;
}

.list-handle {
  width: 36px;
  height: 5px;
  background: var(--border);
  border-radius: 3px;
  margin: 10px auto 6px;
  flex-shrink: 0;
  cursor: pointer;
  padding: 10px 40px; /* bigger tap target */
  background-clip: content-box;
}

.list-header {
  cursor: pointer;
}

.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 20px 12px;
  flex-shrink: 0;
}

.list-header h2 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.view-toggle-btn {
  flex-shrink: 0;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-muted);
  color: var(--blue);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.list-content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0 16px calc(var(--safe-bottom) + 300px);
  min-height: 0; /* critical for flex scroll */
}

.list-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 40px 0;
  gap: 12px;
  color: var(--text-secondary);
  font-size: 14px;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Station card in list */
.station-card {
  display: flex;
  align-items: stretch;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: all 0.15s;
  gap: 14px;
}
.station-card:active { background: var(--bg-muted); transform: scale(0.98); }
.station-card.station-cheapest {
  background: #edf9f0;
  border-color: #b8e6c8;
}
.station-card.station-cheapest .station-rank {
  color: #1a8f35;
}
.station-card.station-cheapest .station-brand-dist {
  color: #2d7a3f;
}

.station-rank {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  flex-shrink: 0;
  font-size: 18px;
  font-weight: 800;
  color: var(--text-tertiary);
}

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

.station-name {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.station-brand-dist {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.station-prices-row {
  display: flex;
  gap: 8px;
}

.price-chip {
  display: flex;
  align-items: baseline;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 8px;
  background: var(--bg-muted);
  font-size: 12px;
}

.price-chip .fuel-label {
  color: var(--text-secondary);
  font-weight: 500;
}

.price-chip .fuel-val {
  font-weight: 700;
  font-size: 15px;
}

.price-chip.cheapest {
  background: #c8edcf;
}
.price-chip.cheapest .fuel-label { color: #2d7a3f; }
.price-chip.cheapest .fuel-val { color: #1a8f35; }

.station-arrow {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  color: var(--text-tertiary);
}

/* ===== Detail Overlay ===== */
.detail-overlay {
  position: fixed;
  inset: 0;
  z-index: 1200;
  background: var(--bg);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  transition: transform 0.3s cubic-bezier(0.25, 1, 0.5, 1);
}
.detail-overlay.hidden {
  transform: translateY(100%);
  pointer-events: none;
}

.detail-card {
  padding: calc(var(--safe-top) + 12px) 20px calc(var(--safe-bottom) + 20px);
  max-width: 500px;
  margin: 0 auto;
}

.back-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  border: none;
  background: none;
  color: var(--blue);
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  padding: 8px 0;
  margin-bottom: 12px;
}

.detail-name {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.4px;
  margin-bottom: 4px;
}

.detail-brand {
  font-size: 14px;
  color: var(--blue);
  font-weight: 500;
  margin-bottom: 2px;
}

.detail-address {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.detail-distance {
  font-size: 13px;
  color: var(--text-tertiary);
  margin-bottom: 20px;
}

.detail-section-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-tertiary);
  margin-bottom: 10px;
}

.detail-price-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 24px;
}

.detail-price-card {
  background: var(--bg-muted);
  border-radius: 14px;
  padding: 16px;
  text-align: center;
}

.detail-price-card .d-fuel-type {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-bottom: 6px;
}

.detail-price-card .d-fuel-price {
  font-size: 32px;
  font-weight: 800;
  letter-spacing: -1px;
}

.detail-price-card .d-fuel-unit {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
}

.detail-price-card .d-fuel-updated {
  font-size: 11px;
  color: var(--text-tertiary);
  margin-top: 4px;
}

.detail-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 24px;
}

.detail-tag {
  padding: 6px 12px;
  border-radius: 8px;
  background: var(--bg-muted);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
}
.detail-tag.highlight {
  background: #e8f8ed;
  color: #1a8f35;
}

.directions-btn {
  display: block;
  width: 100%;
  padding: 16px;
  border-radius: 14px;
  border: none;
  background: var(--blue);
  color: #fff;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  transition: opacity 0.15s;
}
.directions-btn:active { opacity: 0.8; }

/* ===== Auth Screen ===== */
.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.auth-screen.hidden { display: none; }

.auth-card {
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.auth-logo {
  width: 100px;
  height: 100px;
  border-radius: 22px;
  margin-bottom: 16px;
}

.auth-title {
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -1px;
  margin-bottom: 4px;
}

.auth-subtitle {
  font-size: 15px;
  color: var(--text-secondary);
  margin-bottom: 32px;
}

.auth-error {
  background: #fef2f2;
  color: var(--red);
  font-size: 13px;
  font-weight: 500;
  padding: 10px 14px;
  border-radius: 10px;
  margin-bottom: 16px;
  text-align: left;
}

#authForm {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#authForm input {
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-muted);
  font-size: 16px;
  color: var(--text);
  outline: none;
  -webkit-appearance: none;
}
#authForm input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(0,122,255,0.1);
}
#authForm input::placeholder { color: var(--text-tertiary); }

.auth-btn {
  padding: 16px;
  border-radius: 14px;
  border: none;
  background: #ED017F;
  color: #fff;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
  margin-top: 4px;
}
.auth-btn:active { opacity: 0.8; }
.auth-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.auth-toggle {
  display: block;
  width: 100%;
  margin-top: 20px;
  padding: 8px;
  border: none;
  background: none;
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
}
.auth-toggle strong { color: #ED017F; }

.password-wrapper {
  position: relative;
}
.password-wrapper input {
  width: 100%;
  padding-right: 48px !important;
}
.eye-btn {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: none;
  cursor: pointer;
  padding: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.eye-btn svg.eye-off line {
  stroke: #aeaeb2;
}

/* Biometric login screen */
.bio-icon-wrap {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: #fff0f7;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
}
.bio-label {
  font-size: 16px;
  color: var(--text-secondary);
  margin-bottom: 24px;
}
.bio-trigger-btn {
  width: 100%;
  padding: 18px;
  border-radius: 14px;
  border: none;
  background: #ED017F;
  color: #fff;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.bio-trigger-btn:active { opacity: 0.8; }
.bio-trigger-btn:disabled { opacity: 0.5; }

.auth-policies-link {
  display: block;
  margin-top: 32px;
  font-size: 11px;
  color: var(--text-tertiary);
  text-decoration: none;
}
.auth-policies-link:active { color: var(--text-secondary); }

.auth-copyright {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-tertiary);
}

/* ===== Desktop ===== */
@media (min-width: 768px) {
  .station-list {
    left: auto;
    right: 20px;
    bottom: 20px;
    width: 400px;
    border-radius: 20px;
    max-height: 70vh;
  }
  .station-list.expanded { max-height: 80vh; }
  .station-list.collapsed { max-height: 80px; }

  .detail-overlay {
    left: auto;
    right: 0;
    width: 440px;
    box-shadow: -4px 0 30px rgba(0,0,0,0.1);
    border-radius: 20px 0 0 20px;
  }
}
