:root {
  --bg: #0e0e10;
  --bg-elev: #16161a;
  --bg-card: #1c1c21;
  --bg-card-hover: #23232a;
  --fg: #f5f5f5;
  --fg-dim: #9a9aa3;
  --fg-faint: #6a6a72;
  --border: #2a2a30;
  --accent: #ff6b35;
  --accent-fg: #ffffff;
  --good: #7dd87a;
  --warn: #ffd166;
  --bad: #ef6b6b;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.6);
  --radius: 8px;
  --radius-sm: 6px;
  --sidebar-w: 360px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Helvetica Neue", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
}

/* ──────────────── Sidebar ──────────────── */

#sidebar {
  background: var(--bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 100%;
}

#sidebar > header {
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

#sidebar h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.accent {
  color: var(--accent);
}

.tagline {
  margin: 4px 0 12px;
  font-size: 12px;
  color: var(--fg-dim);
}

.icon-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--fg);
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.icon-btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent);
  color: var(--accent);
}
.icon-btn.active {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}

.controls {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.sort-toggle {
  display: flex;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  font-size: 12px;
  font-weight: 600;
}
.sort-btn {
  flex: 1;
  background: transparent;
  border: 0;
  color: var(--fg-dim);
  padding: 6px 10px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.sort-btn:hover {
  color: var(--fg);
}
.sort-btn.active {
  background: var(--accent);
  color: var(--accent-fg);
}

.price-filter {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--fg-dim);
  flex: 1;
  min-width: 0;
}
.filter-label {
  color: var(--fg-faint);
}
.filter-value {
  color: var(--fg);
  font-weight: 600;
  min-width: 32px;
  text-align: right;
}
input[type="range"] {
  flex: 1;
  min-width: 0;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--border);
  border-radius: 2px;
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}
input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}

.stats {
  font-size: 11px;
  color: var(--fg-faint);
  font-feature-settings: "tnum";
}

/* ──────────────── Shop list ──────────────── */

#shop-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}

.shop-card {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: start;
  gap: 12px;
  cursor: pointer;
  transition: background 0.12s;
}
.shop-card:hover, .shop-card:focus-visible {
  background: var(--bg-elev);
  outline: none;
}
.shop-card.selected {
  background: var(--bg-card);
  border-left: 3px solid var(--accent);
  padding-left: 13px;
}

.shop-card .name {
  font-weight: 600;
  font-size: 14px;
  margin: 0 0 2px;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.shop-card .meta {
  font-size: 11px;
  color: var(--fg-dim);
  display: flex;
  gap: 8px;
  align-items: center;
  font-feature-settings: "tnum";
}
.shop-card .meta .dot {
  color: var(--fg-faint);
}
.shop-card .price {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  font-feature-settings: "tnum";
  text-align: right;
  line-height: 1.1;
  min-width: 56px;
}
.shop-card .price .source {
  font-size: 9px;
  font-weight: 500;
  color: var(--fg-faint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: block;
  margin-top: 2px;
}

.empty-state {
  padding: 32px 16px;
  text-align: center;
  color: var(--fg-dim);
  font-size: 13px;
}

.sidebar-foot {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--fg-dim);
  flex-shrink: 0;
}
.sidebar-foot details summary {
  cursor: pointer;
  color: var(--fg);
  font-weight: 600;
  font-size: 12px;
}
.sidebar-foot details[open] summary {
  margin-bottom: 8px;
}
.sidebar-foot p {
  margin: 4px 0;
  line-height: 1.5;
}
.sidebar-foot a {
  color: var(--accent);
  text-decoration: none;
}
.sidebar-foot a:hover {
  text-decoration: underline;
}

/* ──────────────── Map pane ──────────────── */

#map-pane {
  position: relative;
  height: 100%;
}

#map {
  position: absolute;
  inset: 0;
  background: #1a1a1d;
}

.floating-btn {
  position: absolute;
  bottom: 24px;
  right: 16px;
  z-index: 500;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--fg);
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  transition: background 0.15s, color 0.15s;
}
.floating-btn:hover {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
}
.floating-btn.hidden {
  display: none;
}

/* ──────────────── Map pins ──────────────── */

.price-pin {
  background: var(--accent);
  color: var(--accent-fg);
  border-radius: 14px;
  padding: 3px 9px;
  font-weight: 700;
  font-size: 12px;
  border: 2px solid var(--bg);
  box-shadow: var(--shadow-sm);
  white-space: nowrap;
  font-feature-settings: "tnum";
  line-height: 1.2;
  transform-origin: center bottom;
  transition: transform 0.15s;
}
.price-pin.selected {
  background: var(--good);
  transform: scale(1.2);
  z-index: 1000;
}

.gray-pin {
  width: 8px;
  height: 8px;
  background: #3a3a42;
  border: 1px solid #20202a;
  border-radius: 50%;
}

.you-pin {
  width: 16px;
  height: 16px;
  background: #4c8bf5;
  border: 3px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 3px rgba(76, 139, 245, 0.3), var(--shadow-md);
}

/* ──────────────── Map popups ──────────────── */

.leaflet-popup-content-wrapper {
  background: var(--bg-card);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 0;
}
.leaflet-popup-tip {
  background: var(--bg-card);
  border: 1px solid var(--border);
}
.leaflet-popup-close-button {
  color: var(--fg-dim) !important;
  padding: 8px 8px 0 0 !important;
}
.leaflet-popup-content {
  margin: 12px 14px;
  min-width: 220px;
  font-size: 13px;
  line-height: 1.45;
}
.popup-name {
  font-weight: 600;
  font-size: 15px;
  margin: 0 0 4px;
}
.popup-price {
  color: var(--accent);
  font-size: 26px;
  font-weight: 700;
  margin: 6px 0 2px;
  font-feature-settings: "tnum";
  line-height: 1.1;
}
.popup-source-text {
  color: var(--fg-dim);
  font-size: 11px;
  font-style: italic;
  margin: 6px 0 4px;
}
.popup-meta {
  color: var(--fg-dim);
  font-size: 11px;
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.popup-meta a {
  color: var(--accent);
  text-decoration: none;
}
.popup-meta a:hover {
  text-decoration: underline;
}
.recency-badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-left: 6px;
}
.recency-fresh { background: rgba(125, 216, 122, 0.15); color: var(--good); }
.recency-ok    { background: rgba(255, 209, 102, 0.15); color: var(--warn); }
.recency-stale { background: rgba(239, 107, 107, 0.15); color: var(--bad); }
.gray-popup-msg {
  color: var(--fg-faint);
  font-style: italic;
  margin: 4px 0 0;
}

/* ──────────────── Leaflet overrides ──────────────── */

.leaflet-control-zoom {
  border: 1px solid var(--border) !important;
}
.leaflet-control-zoom a {
  background: var(--bg-card) !important;
  color: var(--fg) !important;
  border-bottom: 1px solid var(--border) !important;
}
.leaflet-control-zoom a:hover {
  background: var(--bg-card-hover) !important;
}
.leaflet-control-attribution {
  background: rgba(14, 14, 16, 0.8) !important;
  color: var(--fg-faint) !important;
  font-size: 10px !important;
}
.leaflet-control-attribution a {
  color: var(--fg-dim) !important;
}

/* ──────────────── Mobile bottom sheet ──────────────── */

.sheet-toggle {
  display: none;
}

@media (max-width: 768px) {
  body {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
  }
  #map-pane {
    grid-row: 1;
  }
  #sidebar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    height: 50vh;
    max-height: 60vh;
    border-right: none;
    border-top: 1px solid var(--border);
    border-radius: 18px 18px 0 0;
    transform: translateY(calc(100% - 130px));
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-lg);
  }
  #sidebar.expanded {
    transform: translateY(0);
  }
  #sidebar > header {
    padding-top: 22px;
  }
  #sidebar > header::before {
    content: "";
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 38px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
  }
  .floating-btn {
    bottom: calc(50vh + 12px);
  }
  #sidebar.expanded ~ #map-pane .floating-btn {
    bottom: calc(60vh + 12px);
  }

  .sheet-toggle {
    display: none; /* The drag handle in header serves this role */
  }
}

@media (max-width: 480px) {
  #sidebar h1 {
    font-size: 16px;
  }
  .shop-card {
    padding: 10px 14px;
  }
}
