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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #0f172a;
  color: #e2e8f0;
  overflow: hidden;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
#header {
  position: fixed; inset: 0 0 auto 0; z-index: 1000;
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px; height: 56px;
  background: rgba(15,23,42,.97);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid #1e293b;
}

#brand {
  font-size: .95rem; font-weight: 700; color: #f8fafc;
  white-space: nowrap; letter-spacing: -.02em; flex-shrink: 0;
}

#price-bar {
  display: flex; align-items: center; gap: 6px;
  flex: 1; min-width: 0; overflow-x: auto;
}

.ph {
  background: #1e293b; border: 1px solid #334155;
  border-radius: 8px; padding: 5px 12px; flex-shrink: 0;
}
.ph.accent { border-color: #6366f1; background: #1e1b4b; }

.ph-lbl { display: block; font-size: .6rem; color: #64748b; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 1px; }
.ph-val { display: block; font-size: .95rem; font-weight: 700; color: #f1f5f9; }

.ph-sep { width: 1px; height: 28px; background: #334155; flex-shrink: 0; }

/* Header tab buttons */
#header-tabs { display: flex; gap: 4px; flex-shrink: 0; }
.htab {
  background: #1e293b; border: 1px solid #334155; border-radius: 6px;
  color: #94a3b8; font-size: .72rem; padding: 5px 10px; cursor: pointer;
  white-space: nowrap;
}
.htab:hover { background: #334155; color: #e2e8f0; }

/* Live indicator */
#live-wrap { display: flex; align-items: center; gap: 5px; margin-left: auto; flex-shrink: 0; }
#live-lbl  { font-size: .68rem; color: #64748b; }
.dot       { width: 8px; height: 8px; border-radius: 50%; background: #ca8a04; }
.dot.connected  { background: #22c55e; animation: pulse 2.5s infinite; }
.dot.error      { background: #ef4444; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.4} }

/* ── Expandable data panels ───────────────────────────────────────────────── */
.data-panel {
  position: fixed; top: 56px; left: 0; right: 0; z-index: 900;
  background: rgba(15,23,42,.98); border-bottom: 1px solid #1e293b;
  padding: 14px 20px; max-height: 260px; overflow-y: auto;
}

/* Spot prices */
.spot-group { margin-bottom: 12px; }
.spot-group-label { font-size: .7rem; color: #64748b; text-transform: uppercase; letter-spacing: .06em; margin-bottom: 8px; }
.spot-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.spot-card {
  background: #1e293b; border: 1px solid #334155; border-radius: 8px;
  padding: 8px 14px; min-width: 160px;
}
.spot-name  { font-size: .7rem; color: #94a3b8; margin-bottom: 3px; }
.spot-price { font-size: 1.05rem; font-weight: 700; color: #f1f5f9; }
.spot-unit  { font-size: .65rem; color: #475569; margin-top: 2px; }

/* Grades */
.grades-wrap { display: flex; gap: 10px; flex-wrap: wrap; }
.grade-card {
  background: #1e293b; border: 1px solid #334155; border-radius: 8px;
  padding: 10px 16px; min-width: 140px;
}
.grade-label  { font-size: .7rem; color: #94a3b8; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 4px; }
.grade-price  { font-size: 1.1rem; font-weight: 700; color: #f1f5f9; }
.grade-unit   { font-size: .75rem; color: #64748b; }
.grade-diff   { font-size: .75rem; color: #fb923c; margin-left: 4px; }
.grade-period { font-size: .65rem; color: #475569; margin-top: 4px; }

/* Chart panel */
#panel-chart { padding: 10px 16px 14px; height: 220px; }
#panel-chart canvas { height: 180px !important; }

.panel-loading { color: #64748b; font-size: .85rem; }
.panel-err     { color: #ef4444; font-size: .85rem; }

/* ── Map wrap ─────────────────────────────────────────────────────────────── */
#map-wrap {
  position: fixed; top: 56px; left: 0; right: 0; bottom: 0; z-index: 0;
}

#map { position: absolute; inset: 0; }

/* ── Search bar ──────────────────────────────────────────────────────────── */
#search-wrap {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  z-index: 500; width: min(420px, calc(100vw - 32px));
}

#search-box {
  display: flex; gap: 4px;
  background: rgba(15,23,42,.95); border: 1px solid #334155;
  border-radius: 10px; padding: 4px 6px; backdrop-filter: blur(12px);
}

#search-input {
  flex: 1; background: none; border: none; outline: none;
  color: #e2e8f0; font-size: .88rem; padding: 6px 8px;
}
#search-input::placeholder { color: #475569; }

#locate-btn {
  background: none; border: none; cursor: pointer;
  font-size: 1rem; padding: 4px 6px; border-radius: 6px; color: #94a3b8;
}
#locate-btn:hover { background: #1e293b; }

#search-results {
  display: none; list-style: none;
  background: rgba(15,23,42,.98); border: 1px solid #334155;
  border-radius: 8px; margin-top: 4px; overflow: hidden;
}
#search-results li {
  padding: 9px 14px; font-size: .82rem; color: #cbd5e1; cursor: pointer;
  border-bottom: 1px solid #1e293b; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#search-results li:last-child { border-bottom: none; }
#search-results li:hover { background: #1e293b; }
.sr-none { color: #64748b !important; cursor: default !important; }

/* ── Zoom hint ───────────────────────────────────────────────────────────── */
#zoom-hint {
  position: absolute; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: rgba(15,23,42,.88); color: #94a3b8;
  padding: 7px 18px; border-radius: 999px; font-size: .8rem;
  border: 1px solid #334155; pointer-events: none; backdrop-filter: blur(8px);
}

/* ── Get Gas Prices button ───────────────────────────────────────────────── */
#get-prices-btn {
  position: absolute; bottom: 24px; left: 50%; transform: translateX(-50%);
  z-index: 500;
  background: #4f46e5; border: none; border-radius: 999px;
  color: #fff; font-size: .88rem; font-weight: 700;
  padding: 10px 24px; cursor: pointer; backdrop-filter: blur(8px);
  box-shadow: 0 4px 14px rgba(79,70,229,.45); white-space: nowrap;
  transition: background .15s;
}
#get-prices-btn:hover:not(:disabled) { background: #4338ca; }
#get-prices-btn:disabled { opacity: .6; cursor: default; }

/* ── Station list panel ──────────────────────────────────────────────────── */
#station-panel {
  position: absolute; top: 0; right: -300px; bottom: 0; width: 280px;
  background: rgba(15,23,42,.97); border-left: 1px solid #1e293b;
  display: flex; flex-direction: column; z-index: 400;
  transition: right .25s ease; backdrop-filter: blur(12px);
}
#station-panel.open { right: 0; }

#sp-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; border-bottom: 1px solid #1e293b; flex-shrink: 0;
}
#sp-count { font-size: .78rem; color: #94a3b8; font-weight: 600; }
#sp-close {
  background: none; border: none; color: #64748b; cursor: pointer;
  font-size: .85rem; padding: 2px 6px; border-radius: 4px;
}
#sp-close:hover { background: #1e293b; color: #e2e8f0; }

#sp-list { flex: 1; overflow-y: auto; }

#sp-close-mobile { display: none; } /* shown only in mobile media query */

.sp-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-bottom: 1px solid #0f172a; cursor: pointer;
}
.sp-item:hover { background: #1e293b; }

.sp-price {
  width: 58px; height: 24px; border-radius: 12px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: .7rem; font-weight: 700; color: #fff;
}

.sp-info { min-width: 0; }
.sp-name { font-size: .8rem; color: #e2e8f0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sp-brand { font-size: .72rem; color: #64748b; }
.sp-dist  { font-size: .7rem; color: #475569; margin-top: 2px; }

.sp-empty { padding: 20px 14px; font-size: .82rem; color: #475569; text-align: center; line-height: 1.6; }

/* Station list toggle button */
#sp-toggle {
  position: absolute; bottom: 56px; right: 12px; z-index: 410;
  background: rgba(15,23,42,.95); border: 1px solid #334155;
  border-radius: 8px; color: #cbd5e1; font-size: .78rem;
  padding: 8px 14px; cursor: pointer; backdrop-filter: blur(8px);
}
#sp-toggle:hover { background: #1e293b; }

/* ── Marker pins ─────────────────────────────────────────────────────────── */
.pin {
  display: flex; align-items: center; justify-content: center;
  width: 72px; height: 26px; border-radius: 13px;
  color: #fff; font-size: .72rem; font-weight: 700;
  box-shadow: 0 2px 8px rgba(0,0,0,.4);
  border: 1.5px solid rgba(255,255,255,.25);
}

/* ── Popup ───────────────────────────────────────────────────────────────── */
.popup-name  { font-weight: 700; font-size: .95rem; color: #0f172a; margin-bottom: 2px; }
.popup-brand { font-size: .75rem; color: #64748b; margin-bottom: 6px; }
.popup-addr  { font-size: .75rem; color: #374151; margin-bottom: 8px; line-height: 1.4; }

.popup-price-row {
  background: #f0fdf4; border-radius: 7px; padding: 7px 10px; margin: 6px 0;
  display: flex; align-items: baseline; gap: 6px;
}
.popup-price { font-size: 1.2rem; font-weight: 800; color: #15803d; }
.popup-note  { font-size: .68rem; color: #6b7280; }

/* Grade price grid */
.popup-grades {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 5px;
  margin: 6px 0 3px;
}
.popup-grade-item {
  background: #f0fdf4; border-radius: 6px; padding: 5px 8px; text-align: center;
}
.popup-grade-name  { font-size: .65rem; color: #6b7280; text-transform: uppercase; letter-spacing: .04em; }
.popup-grade-price { font-size: .95rem; font-weight: 700; color: #15803d; }
.popup-price-note  { font-size: .66rem; color: #9ca3af; margin-bottom: 6px; }

/* Fuel type / amenity badges */
.popup-tags { display: flex; flex-wrap: wrap; gap: 4px; margin: 5px 0; }
.popup-tag {
  background: #e0f2fe; color: #0369a1;
  font-size: .65rem; font-weight: 600; padding: 2px 7px; border-radius: 999px;
}
.popup-tag-amenity { background: #fef3c7; color: #92400e; }

/* Hours / contact */
.popup-meta { font-size: .75rem; color: #374151; margin-top: 4px; }
.popup-meta a { color: #2563eb; text-decoration: none; }
.popup-meta a:hover { text-decoration: underline; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 640px) {

  /* Header: wrap into 2 rows */
  #brand { display: none; }
  #header {
    flex-wrap: wrap;
    height: auto;
    padding: 5px 10px;
    gap: 4px;
    row-gap: 3px;
  }

  /* Row 1: price bar scrolls horizontally */
  #price-bar {
    order: 1;
    flex: 0 0 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  #price-bar::-webkit-scrollbar { display: none; }

  /* Hide Brent and its separator — save space */
  #ph-brent, #ph-sep-crude { display: none; }

  .ph     { padding: 4px 9px; }
  .ph-val { font-size: .82rem; }

  /* Row 2: tabs left, live indicator right */
  #header-tabs { order: 2; flex: 1; }
  #live-wrap   { order: 2; margin-left: auto; }
  .htab        { padding: 6px 10px; font-size: .72rem; }

  /* Map and panels start below the taller 2-row header (~90px) */
  #map-wrap   { top: 90px; }
  .data-panel { top: 90px; }

  /* Station panel: full-screen slide-in, above all Leaflet controls */
  #station-panel { width: 100%; right: -100%; z-index: 1100; }
  #station-panel.open { right: 0; }

  /* Hide the small ✕ in the header — replaced by bottom close bar */
  #sp-close { display: none; }

  /* Sticky close bar at the bottom for thumb-friendly dismissal */
  #sp-close-mobile {
    display: flex; align-items: center; justify-content: center;
    padding: calc(14px + env(safe-area-inset-bottom, 0px)) 16px 14px;
    border-top: 1px solid #1e293b;
    background: rgba(15,23,42,.97);
    flex-shrink: 0;
    font-size: .85rem; color: #94a3b8; cursor: pointer;
    letter-spacing: .03em;
  }
  #sp-close-mobile:active { background: #1e293b; }

  /* Bigger touch targets in station list */
  .sp-item { padding: 13px 12px; }

  /* Buttons near the bottom: clear iOS home bar */
  #sp-toggle {
    bottom: calc(14px + env(safe-area-inset-bottom, 0px));
    padding: 10px 16px;
  }
  #get-prices-btn {
    bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    padding: 12px 28px;
    font-size: .92rem;
  }
  #zoom-hint {
    bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  }

  /* Search bar: tighten top gap */
  #search-wrap { top: 8px; }
  #search-input { font-size: .85rem; }

  /* Data panels: reduce padding, allow more scroll */
  .data-panel { padding: 10px 12px; max-height: 220px; }
  #panel-chart { height: 200px; }
}
