/* ============================================================
   UK Fuel Price Finder — Main Stylesheet
   ============================================================ */

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  background: #0d1b2a;
  color: #222;
}

/* ---- Header ---- */
#header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  background: linear-gradient(160deg, #0d1b2a 0%, #162840 100%);
  color: #fff;
  padding: 10px 16px 9px;
  box-shadow: 0 2px 16px rgba(0,0,0,0.55);
}

/* Top row: title + locate button */
#header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 9px;
}

#app-title {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  line-height: 1;
}

/* ---- Mode toggle (Petrol / Electric) ---- */
#mode-toggle {
  display: flex;
  background: rgba(255,255,255,0.1);
  border-radius: 22px;
  padding: 3px;
  margin-bottom: 9px;
  gap: 2px;
}
.mode-btn {
  flex: 1;
  padding: 7px 10px;
  border-radius: 19px;
  border: none;
  background: transparent;
  color: rgba(255,255,255,0.6);
  font-size: 0.87rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.mode-btn.active {
  background: #fff;
  color: #0d1b2a;
}
.mode-btn:hover:not(.active) {
  color: #fff;
  background: rgba(255,255,255,0.15);
}

/* Search row: postcode input + search btn + radius */
#search-row {
  display: flex;
  gap: 7px;
  align-items: center;
}

#postcode-input {
  flex: 1;
  min-width: 0;
  padding: 9px 15px;
  border: none;
  border-radius: 24px;
  font-size: 0.95rem;
  background: rgba(255,255,255,0.95);
  color: #111;
  outline: none;
  transition: box-shadow 0.15s;
}
#postcode-input::placeholder { color: #999; }
#postcode-input:focus { box-shadow: 0 0 0 3px rgba(33,150,243,0.45); }

/* Buttons */
button {
  border: none;
  border-radius: 24px;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.15s, transform 0.1s;
  white-space: nowrap;
}
button:active { transform: scale(0.95); }

#search-btn {
  padding: 9px 18px;
  background: #2196f3;
  color: #fff;
  font-size: 0.9rem;
}
#search-btn:hover { background: #1e88e5; }

#locate-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 7px 13px;
  background: rgba(255,255,255,0.1);
  color: #fff;
  font-size: 0.85rem;
  border: 1px solid rgba(255,255,255,0.22);
  border-radius: 24px;
}
#locate-btn:hover { background: rgba(255,255,255,0.2); }

/* Radius select */
#radius-select {
  padding: 8px 10px;
  border-radius: 20px;
  border: 1px solid rgba(255,255,255,0.22);
  background: rgba(255,255,255,0.1);
  color: #fff;
  font-size: 0.87rem;
  font-weight: 600;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  min-width: 58px;
  text-align: center;
}
#radius-select option {
  background: #1a2f4a;
  color: #fff;
}

/* ---- EV filters row ---- */
#ev-filters {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
#ev-filters.hidden { display: none; }

#ev-min-power {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border-radius: 20px;
  border: 1px solid rgba(255,255,255,0.22);
  background: rgba(255,255,255,0.1);
  color: #fff;
  font-size: 0.87rem;
  font-weight: 600;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}
#ev-min-power option { background: #1a2f4a; color: #fff; }

.ev-check-label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: rgba(255,255,255,0.75);
  font-size: 0.85rem;
  cursor: pointer;
  white-space: nowrap;
}
.ev-check-label input[type="checkbox"] { cursor: pointer; accent-color: #2196f3; }

/* Status bar */
#status-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
  font-size: 0.73rem;
  color: rgba(255,255,255,0.48);
  letter-spacing: 0.02em;
}
#station-count-msg:not(:empty) + #data-freshness:not(:empty)::before {
  content: "·";
  margin-right: 8px;
}

#terms-link {
  color: #ffd54f;
  text-decoration: none;
  margin-left: auto;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  padding: 2px 7px;
  border-radius: 4px;
  border: 1px solid rgba(255,213,79,0.45);
}
#terms-link:hover {
  color: #fff;
  background: rgba(255,213,79,0.18);
  border-color: rgba(255,213,79,0.8);
}

/* Attribution bar */
#attribution-bar {
  font-size: 0.68rem;
  color: rgba(255,255,255,0.42);
  margin-top: 5px;
  line-height: 1.4;
}
#attribution-bar a {
  color: rgba(255,255,255,0.62);
  text-decoration: underline;
  text-underline-offset: 2px;
}
#attribution-bar a:hover { color: #fff; }

/* Error message */
#error-msg {
  margin-top: 7px;
  padding: 7px 13px;
  background: rgba(211,47,47,0.9);
  color: #fff;
  border-radius: 8px;
  font-size: 0.83rem;
}
#error-msg.hidden { display: none; }

/* ---- Map ---- */
#map {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  /* top offset set by JS to match header height */
}

/* ---- Loading overlay ---- */
#no-data-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(13,27,42,0.8);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
}

#no-data-box {
  background: #fff;
  border-radius: 16px;
  padding: 36px 40px;
  max-width: 380px;
  width: 88%;
  text-align: center;
  box-shadow: 0 24px 64px rgba(0,0,0,0.45);
}

.spinner {
  width: 42px;
  height: 42px;
  border: 4px solid #e0e0e0;
  border-top-color: #2196f3;
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
  margin: 0 auto 20px;
}
@keyframes spin { to { transform: rotate(360deg); } }

#no-data-box h2 {
  margin-bottom: 10px;
  font-size: 1.1rem;
  color: #0d1b2a;
}
#no-data-box p {
  color: #666;
  margin-bottom: 6px;
  line-height: 1.6;
  font-size: 0.88rem;
}

/* ---- Leaflet overrides ---- */
.leaflet-container { font-family: inherit; }

/* ---- Price marker circles ---- */
.price-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 2.5px solid rgba(255,255,255,0.65);
  font-weight: 700;
  font-size: 11px;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,0.45);
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(0,0,0,0.38);
  transition: transform 0.12s, box-shadow 0.12s;
  width: 46px;
  height: 46px;
  line-height: 1.15;
  text-align: center;
}
.price-marker:hover {
  transform: scale(1.18);
  box-shadow: 0 6px 18px rgba(0,0,0,0.48);
  z-index: 9999 !important;
}

.price-marker.green  { background: linear-gradient(145deg, #43a047, #2e7d32); }
.price-marker.amber  { background: linear-gradient(145deg, #fb8c00, #e65100); }
.price-marker.red    { background: linear-gradient(145deg, #e53935, #b71c1c); }
.price-marker.grey   { background: linear-gradient(145deg, #9e9e9e, #757575); }
.price-marker.closed { background: linear-gradient(145deg, #bdbdbd, #9e9e9e); text-decoration: line-through; }

/* ---- Popup ---- */
.leaflet-popup-content-wrapper {
  border-radius: 14px !important;
  box-shadow: 0 8px 32px rgba(0,0,0,0.22) !important;
  padding: 0 !important;
  overflow: hidden;
}
.leaflet-popup-tip-container { margin-top: -1px; }

.leaflet-popup-content {
  margin: 0 !important;
  min-width: 250px;
  max-width: 310px;
}

.popup-card {
  padding: 14px 16px 12px;
}

/* Station identity */
.popup-name {
  font-weight: 700;
  font-size: 1rem;
  color: #0d1b2a;
  line-height: 1.25;
  margin-bottom: 2px;
}
.popup-meta {
  font-size: 0.78rem;
  color: #888;
  margin-bottom: 5px;
}
.popup-address {
  font-size: 0.82rem;
  color: #555;
  line-height: 1.4;
  margin-bottom: 11px;
}

/* Price chips */
.popup-prices-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 5px;
  margin-bottom: 11px;
}
.price-chip {
  background: #f4f6f9;
  border-radius: 8px;
  padding: 7px 9px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 4px;
}
.price-chip-label {
  font-size: 0.73rem;
  color: #777;
  font-weight: 500;
}
.price-chip-value {
  font-size: 0.88rem;
  font-weight: 700;
  color: #1b5e20;
}
.price-chip-value.not-sold {
  color: #ccc;
  font-weight: 400;
  font-size: 0.8rem;
}
.popup-no-prices {
  font-size: 0.82rem;
  color: #aaa;
  text-align: center;
  padding: 8px 0;
  margin-bottom: 8px;
}

/* Divider */
.popup-divider {
  border: none;
  border-top: 1px solid #eef0f3;
  margin: 9px 0;
}

/* Info rows */
.popup-info-row {
  font-size: 0.82rem;
  color: #444;
  margin-bottom: 7px;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Badges */
.popup-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 10px;
}
.badge {
  display: inline-block;
  border-radius: 5px;
  padding: 2px 7px;
  font-size: 0.71rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.badge-type  { background: #e8f5e9; color: #2e7d32; }
.badge-flag  { background: #fff3e0; color: #e65100; }
.badge-amenity { background: #e3f2fd; color: #1565c0; }

/* Maps button */
.popup-maps-btn {
  display: block;
  background: #2196f3;
  color: #fff;
  text-align: center;
  padding: 9px;
  border-radius: 9px;
  text-decoration: none;
  font-size: 0.83rem;
  font-weight: 600;
  margin-bottom: 9px;
  transition: background 0.15s;
}
.popup-maps-btn:hover { background: #1e88e5; }

/* Footer */
.popup-updated {
  font-size: 0.71rem;
  color: #c0c0c0;
  text-align: center;
}

/* ---- EV charge point markers ---- */
.cp-marker {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 2px solid rgba(255,255,255,0.65);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(0,0,0,0.38);
  transition: transform 0.12s, box-shadow 0.12s;
  line-height: 1;
}
.cp-marker:hover {
  transform: scale(1.15);
  box-shadow: 0 6px 18px rgba(0,0,0,0.45);
  z-index: 9999 !important;
}
.cp-icon  { font-size: 13px; }
.cp-count { font-size: 10px; font-weight: 700; }

.cp-marker--slow  { background: linear-gradient(145deg, #5ba3e8, #4A90D9); }
.cp-marker--fast  { background: linear-gradient(145deg, #b07fd4, #9B59B6); }
.cp-marker--rapid { background: linear-gradient(145deg, #2ed3b7, #1ABC9C); }

/* ---- EV popup styles ---- */
.cp-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 9px;
}
.badge-tier-slow  { background: #e3f2fd; color: #1565c0; }
.badge-tier-fast  { background: #f3e5f5; color: #6a1b9a; }
.badge-tier-rapid { background: #e0f7fa; color: #006064; }
.popup-connections { margin-bottom: 10px; }
.conn-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 6px 9px;
  background: #f4f6f9;
  border-radius: 7px;
  margin-bottom: 4px;
  font-size: 0.82rem;
}
.conn-type  { font-weight: 600; color: #333; }
.conn-power { color: #6a1b9a; font-weight: 700; white-space: nowrap; }

/* ---- Responsive — narrow portrait mobile ---- */
@media (max-width: 480px) {
  #header { padding: 9px 12px 8px; }

  #app-title { font-size: 0.95rem; }

  .btn-text { display: none; }

  #locate-btn { padding: 8px 11px; }

  #search-btn {
    padding: 9px 14px;
    font-size: 0.85rem;
  }

  #postcode-input {
    padding: 9px 12px;
    font-size: 0.9rem;
  }

  #radius-select {
    padding: 8px 8px;
    font-size: 0.82rem;
    min-width: 52px;
  }

  .leaflet-popup-content {
    min-width: 210px;
    max-width: 270px;
  }

  .popup-prices-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  #no-data-box {
    padding: 28px 24px;
  }
}
