/* ============================================================================
   Subs & Subs — styles
   Warm & playful, light. Palette + font pairing borrowed from the workspace's
   "Ja tog na på" app; bottom-sheet mechanics mirror its history panel.
   8-pt spacing grid throughout.
   ========================================================================== */

/* ─── Reset & tokens ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:             #F8F6F2;
  --surface:        #FFFFFF;
  --surface-2:      #ECEAE4;
  --border:         #D8D4CC;
  --text:           #1C1C1A;
  --muted:          #9E9488;

  --terracotta:     #DF5814;  /* brand orange (matches the logo) — the primary highlight */
  --terracotta-deep:#B8460E;  /* darker shade for hover/active + filled-pin borders */
  --sage:           #5B7E62;
  --sage-soft:      #E4EBE2;
  --cream:          #F3ECE0;
  --danger:         #C45A5A;

  --font-display: 'alphabet-soup-pro', 'Cormorant Garamond', Georgia, serif; /* Alphabet Soup (Adobe Fonts) — the logo/title face; Cormorant is the fallback */
  --font-serif:   'Cormorant Garamond', Georgia, serif;                      /* elegant serif for the note + loading line */
  --font-ui:      'DM Sans', system-ui, sans-serif;
  --font-mono:    'Roboto Mono', ui-monospace, SFMono-Regular, monospace;

  --r-sm: 8px; --r-md: 14px; --r-lg: 20px; --r-pill: 999px;

  --s1: 4px; --s2: 8px; --s3: 16px; --s4: 24px; --s5: 32px; --s6: 40px; --s7: 48px;

  --shadow-sheet: 0 -8px 32px rgba(28, 28, 26, .12);
  --shadow-panel: 0 8px 36px rgba(28, 28, 26, .12);
  --shadow-card:  0 4px 20px rgba(28, 28, 26, .08);
  --shadow-pin:   0 2px 6px rgba(28, 28, 26, .28);

  --ease: cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

html { font-size: 16px; -webkit-tap-highlight-color: transparent; }

body {
  font-family: var(--font-ui);
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
  height: 100dvh;
}

/* ─── Map ─────────────────────────────────────────────────────────────────── */
#map {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: var(--surface-2);
}

/* Keep Leaflet zoom buttons clear of the panel and on-brand */
.leaflet-control-zoom {
  border: none !important;
  box-shadow: var(--shadow-card) !important;
  border-radius: var(--r-md) !important;
  overflow: hidden;
}
.leaflet-control-zoom a {
  background: var(--surface) !important;
  color: var(--text) !important;
  border: none !important;
}
.leaflet-control-zoom a:hover { background: var(--cream) !important; }

/* ─── Pins (Leaflet divIcon) ──────────────────────────────────────────────── */
/* Outer element — Leaflet positions this via `transform`, so it must stay
   transform-free. Size comes from the divIcon's iconSize. */
.pin {
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.pin-home { cursor: default; }

/* Bob wrapper — holds the disc AND the hover label, so they wobble together. */
.pin__bob { position: relative; width: 100%; height: 100%; }
/* Hover label — a small title tag above the pin (replaces Leaflet's default tooltip). */
.pin__label {
  position: absolute;
  left: 50%; bottom: 100%;
  transform: translateX(-50%);
  margin-bottom: 8px;
  padding: 4px 10px;
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 12px; font-weight: 600; letter-spacing: 0.01em;
  white-space: nowrap;
  box-shadow: var(--shadow-card);
  opacity: 0; pointer-events: none;
  transition: opacity .15s var(--ease);
}
.pin:hover .pin__label { opacity: 1; }

/* Inner disc — ALL colour, scaling and animation live here so they can never
   fight Leaflet's positioning transform on the outer element. */
.pin__in {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  overflow: hidden;            /* clip the square sub image to the round pin (no corners poking out) */
  background: var(--cream);
  border: 2px solid var(--terracotta);
  box-shadow: var(--shadow-pin);
  font-size: 17px; line-height: 1;
  transition: transform .2s var(--ease), opacity .2s, border-color .2s, background .2s, box-shadow .2s;
}
/* !important beats Leaflet's `.leaflet-marker-pane img { width: auto }` (higher specificity) */
.pin__img { width: 30px !important; height: auto; display: block; pointer-events: none; }
.pin-home .pin__in { background: var(--terracotta); border-color: var(--terracotta-deep); }
.pin-home .pin__in::after {
  content: ""; width: 9px; height: 9px; border-radius: 50%;
  background: #fff; box-shadow: 0 0 0 3px rgba(255,255,255,.35);
}
/* browse — everything clearly visible: reachable spots get a sage ring + gentle bob,
   the rest stay full-size and legible (just calmer), never faint enough to vanish */
.pin-sub.reachable .pin__in  { border-color: var(--sage); box-shadow: var(--shadow-pin), 0 0 0 4px rgba(91,126,98,.16); }
.pin-sub.reachable .pin__bob { animation: bob 2.4s var(--ease) infinite; }
.pin-sub.faded .pin__in     { border-color: var(--border); opacity: .92; }
/* a chosen spot (before the route is drawn) */
.pin-sub.selected .pin__in  { border-color: var(--terracotta-deep); border-width: 2.5px; transform: scale(1.12); }
/* once something is chosen / a route is up, the others shrink but stay clearly there */
.pin-sub.muted .pin__in     { transform: scale(.6); opacity: .8; border-color: var(--border); box-shadow: 0 1px 4px rgba(28,28,26,.22); }
/* the route's end point — a clear "you arrive here" marker */
.pin-sub.destination .pin__in {
  border: 3px solid var(--terracotta);
  transform: scale(1.36);
  box-shadow: 0 6px 16px rgba(28,28,26,.35), 0 0 0 6px rgba(223,88,20,.30);
}
.pin-sub.suggested .pin__in { border-color: var(--terracotta); animation: pulse 1.4s ease-out infinite; }
.pin-sub.shuffle .pin__in   { transform: scale(1.25); border-color: var(--terracotta); }

@keyframes bob   { 0%,100% { transform: translateY(0) scale(1); } 50% { transform: translateY(-4px) scale(1.04); } }
@keyframes pulse { 0% { box-shadow: var(--shadow-pin), 0 0 0 0 rgba(223,88,20,.5); }
                   100% { box-shadow: var(--shadow-pin), 0 0 0 16px rgba(223,88,20,0); } }

/* ─── Control surface: draggable bottom sheet (mobile) ────────────────────────
   The sheet snaps between a compact "peek" (just the slider + buttons, map
   dominant) and taller states. JS sets `height` in px per snap point; the peek
   zone is pinned at the top so the slider is always reachable, and the scroll
   zone below reveals the result card + spot list as the sheet grows. */
.panel {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 1000;
  display: flex; flex-direction: column;
  height: 44dvh;               /* sensible default before JS measures the snaps */
  overflow: hidden;            /* clip the pinned attribution bar to the rounded corners */
  background: var(--bg);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  box-shadow: var(--shadow-sheet);
  transition: height .38s var(--ease);
}
.panel.dragging { transition: none; }   /* follow the finger 1:1 while dragging */

/* Grip = a generous, easy-to-grab drag target; the visible bar sits inside it.
   touch-action:none lives HERE (not on .panel) so dragging the grip never scrolls
   — but the slider and scroll zone keep their normal touch behaviour. */
.panel__grip {
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  height: 26px; cursor: grab;
  touch-action: none;
}
.panel__grip:active { cursor: grabbing; }
.panel__handle {
  width: 40px; height: 4px;
  background: var(--border); border-radius: 2px;
  transition: background .15s, width .15s;
}
.panel__grip:active .panel__handle { background: var(--muted); width: 52px; }

.panel__peek {
  flex-shrink: 0;
  display: flex; flex-direction: column; gap: var(--s3);
  padding: 0 var(--s4) var(--s2);
}
.panel__scroll {
  flex: 1 1 auto; min-height: 0;   /* fill the rest, scroll, leave room for the pinned attribution */
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;             /* allow normal scrolling here, not sheet-drag */
  padding: var(--s2) var(--s4) var(--s4);
  display: flex; flex-direction: column; gap: var(--s4);
}
/* keep their natural height and let the zone scroll, instead of squashing
   children (the chip row collapsing to nothing) when content overflows */
.panel__scroll > * { flex-shrink: 0; }
.panel__scroll:empty { display: none; }

/* ─── Brand ───────────────────────────────────────────────────────────────── */
.brand { text-align: center; padding-top: 2px; }
.brand__logo {
  display: block;
  width: 42%;                  /* compact on mobile so the peek stays small + map dominant */
  max-width: 138px;
  height: auto;
  margin: 0 auto;
}

/* ─── Slider control ──────────────────────────────────────────────────────── */
.control { display: flex; flex-direction: column; gap: var(--s3); }
.control__label {
  font-family: var(--font-display);
  font-style: italic;
  font-size: clamp(20px, 5.5vw, 24px);
  font-weight: 400;
  line-height: 1.1;
}

.slider-wrap { position: relative; padding: var(--s3) 0 var(--s2); }

/* native range, custom-skinned */
input[type="range"].slider {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 8px; margin: 0;
  background: transparent; cursor: pointer;
}
input[type="range"].slider::-webkit-slider-runnable-track {
  height: 8px; border-radius: var(--r-pill);
  background: linear-gradient(to right,
    var(--terracotta) 0 var(--fill, 30%), var(--surface-2) var(--fill, 30%) 100%);
}
input[type="range"].slider::-moz-range-track {
  height: 8px; border-radius: var(--r-pill); background: var(--surface-2);
}
input[type="range"].slider::-moz-range-progress {
  height: 8px; border-radius: var(--r-pill); background: var(--terracotta);
}
input[type="range"].slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 28px; height: 28px; margin-top: -10px;
  border-radius: 50%;
  background: var(--terracotta);
  border: 4px solid var(--bg);
  box-shadow: var(--shadow-card);
  transition: transform .12s var(--ease);
}
input[type="range"].slider::-moz-range-thumb {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--terracotta); border: 4px solid var(--bg);
  box-shadow: var(--shadow-card);
}
input[type="range"].slider:active::-webkit-slider-thumb { transform: scale(1.12); }
input[type="range"].slider.bump::-webkit-slider-thumb   { transform: scale(1.22); }
input[type="range"].slider:focus-visible { outline: none; }
input[type="range"].slider:focus-visible::-webkit-slider-thumb { box-shadow: var(--shadow-card), 0 0 0 4px var(--sage-soft); }

/* ticks: one dot per eatery distance, positioned by JS */
.slider-ticks { position: absolute; left: 14px; right: 14px; top: 4px; height: 8px; pointer-events: none; }
.tick {
  position: absolute; top: 50%; width: 6px; height: 6px;
  margin: -3px 0 0 -3px; border-radius: 50%;
  background: var(--border); transition: background .2s, transform .2s;
}
.tick.in-range { background: var(--sage); transform: scale(1.3); }

.slider-readout { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s2); }
.slider-km { font-family: var(--font-mono); font-size: 28px; font-weight: 600; line-height: 1; font-variant-numeric: tabular-nums; }
.slider-km .unit { font-family: var(--font-ui); font-size: 14px; color: var(--muted); font-weight: 400; margin-left: 3px; }
.slider-count { font-size: 13px; color: var(--sage); font-weight: 500; text-align: right; }
.slider-count.zero { color: var(--muted); }

/* ─── Eatery chips ────────────────────────────────────────────────────────── */
/* Mobile: one swipeable row (keeps the sheet short). Desktop: wraps (see below). */
.chips {
  display: flex; gap: var(--s2);
  flex-wrap: nowrap; overflow-x: auto; overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch; touch-action: pan-x;
  padding-bottom: 2px; scrollbar-width: none;
  -webkit-mask-image: linear-gradient(to right, transparent 0, #000 12px, #000 calc(100% - 12px), transparent 100%);
          mask-image: linear-gradient(to right, transparent 0, #000 12px, #000 calc(100% - 12px), transparent 100%);
}
.chips::-webkit-scrollbar { display: none; }
.chip { flex: 0 0 auto; }
.chip {
  font-family: var(--font-ui); font-size: 13px; font-weight: 500;
  padding: 8px 14px; border-radius: var(--r-pill);
  background: var(--cream); color: var(--text);
  border: 1px solid var(--border);
  cursor: pointer; user-select: none;
  transition: background .15s, border-color .15s, color .15s, transform .08s, opacity .2s;
  display: inline-flex; align-items: center; gap: 6px;
}
.chip .chip__dist { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.chip:active { transform: scale(.96); }
.chip.in-range { border-color: var(--sage); }
.chip.in-range .chip__dist { color: var(--sage); }
.chip.selected {
  background: var(--terracotta); border-color: var(--terracotta-deep); color: #fff;
}
.chip.selected .chip__dist { color: rgba(255,255,255,.85); }
.chip.out { opacity: .5; }
.chip.out .chip__dist { color: var(--muted); }

/* ─── Actions ─────────────────────────────────────────────────────────────── */
.actions { display: flex; gap: var(--s2); }
.btn {
  flex: 1; font-family: var(--font-ui); font-size: 15px; font-weight: 600;
  padding: 14px 18px; border-radius: var(--r-md); border: 1.5px solid transparent;
  cursor: pointer; transition: background .15s, color .15s, border-color .15s, transform .08s, opacity .15s;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:active { transform: scale(.97); }
.btn--primary { background: var(--terracotta); color: #fff; }
.btn--primary:hover { background: var(--terracotta-deep); }
.btn--ghost { background: transparent; color: var(--terracotta); border-color: var(--terracotta); }
.btn--ghost:hover { background: var(--cream); }
.btn:disabled { opacity: .45; cursor: default; transform: none; }

/* ─── Stage: transient states (loading / result / error / suggestion) ─────── */
.stage:empty { display: none; }
.stage { display: flex; flex-direction: column; gap: var(--s3); animation: fadeUp .35s var(--ease); }

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

/* loading */
.loading { display: flex; align-items: center; gap: var(--s3); padding: var(--s2) 0; }
.loading__emoji { font-size: 28px; animation: hop .7s var(--ease) infinite; }
.loading__text { font-family: var(--font-serif); font-style: italic; font-size: 19px; color: var(--text); }
@keyframes hop { 0%,100% { transform: translateY(0) rotate(-4deg); } 50% { transform: translateY(-9px) rotate(4deg); } }

/* result card */
.card {
  background: var(--surface); border-radius: var(--r-md);
  box-shadow: var(--shadow-card); padding: var(--s4);
  display: flex; flex-direction: column; gap: var(--s3);
}
.card__head { display: flex; flex-direction: column; gap: var(--s1); }
.card__eyebrow { font-size: 10px; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.card__name { font-family: var(--font-display); font-size: 26px; font-weight: 400; line-height: 1.05; }
.card__stats { display: flex; gap: var(--s5); }
.card__stat { display: flex; flex-direction: column; gap: 2px; }
.card__stat-num { font-family: var(--font-mono); font-size: 22px; font-weight: 600; line-height: 1; font-variant-numeric: tabular-nums; }
.card__stat-num .unit { font-family: var(--font-ui); font-size: 13px; color: var(--muted); font-weight: 400; }
.card__stat-label { font-size: 10px; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.card__note {
  font-family: var(--font-serif); font-style: italic; font-size: 17px;
  line-height: 1.4; color: var(--text);
}
.card__links {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s2);
  padding-top: var(--s3); border-top: 1px solid var(--border);
}
.link-btn {
  font-size: 12px; font-weight: 600; letter-spacing: 0.04em; text-decoration: none;
  color: var(--sage); display: inline-flex; align-items: center; gap: 5px;
}
.link-btn:hover { color: var(--text); }
.text-btn {
  background: none; border: none; cursor: pointer;
  font-family: var(--font-ui); font-size: 12px; font-weight: 600; letter-spacing: 0.04em;
  color: var(--muted);
}
.text-btn:hover { color: var(--text); }

/* variant switcher (segmented) */
.variants { display: flex; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: var(--r-pill); }
.variant {
  flex: 1; border: none; cursor: pointer; background: transparent;
  font-family: var(--font-ui); font-size: 12px; font-weight: 600; color: var(--muted);
  padding: 8px 6px; border-radius: var(--r-pill); transition: background .15s, color .15s;
  display: flex; flex-direction: column; align-items: center; gap: 1px; line-height: 1.1;
}
.variant .variant__dist { font-size: 10px; font-weight: 500; }
.variant.active { background: var(--surface); color: var(--terracotta); box-shadow: var(--shadow-card); }

/* suggestion (no-match) + error */
.banner {
  background: var(--cream); border: 1.5px solid var(--border);
  border-radius: var(--r-md); padding: var(--s3);
  display: flex; flex-direction: column; gap: var(--s2);
}
.banner__text { font-size: 14px; line-height: 1.5; color: var(--text); }
.banner__text b { font-weight: 600; }
.banner--error { border-color: var(--danger); background: #FBEDED; }

/* ─── Footer (pace + attribution + demo hint) ─────────────────────────────── */
.foot { display: flex; flex-direction: column; gap: var(--s2); padding-top: var(--s2); border-top: 1px solid var(--border); }
.pace {
  align-self: center;
  display: inline-flex; align-items: center; gap: var(--s3);
  padding: 5px 7px 5px 16px;
  border: 1px solid var(--border); border-radius: var(--r-pill);
  background: var(--surface);
}
.pace__name { font-size: 11px; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.pace__ctrl { display: flex; align-items: center; gap: 4px; }
.pace__btn {
  width: 26px; height: 26px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); cursor: pointer; font-size: 16px; line-height: 1;
  display: flex; align-items: center; justify-content: center; transition: background .15s, border-color .15s;
}
.pace__btn:hover { background: var(--cream); border-color: var(--muted); }
.pace__val { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-weight: 600; font-size: 14px; min-width: 56px; text-align: center; }
.pace__val .unit { font-family: var(--font-ui); color: var(--muted); font-weight: 400; font-size: 12px; }

.demo-hint {
  font-size: 11px; color: var(--muted); line-height: 1.4;
  background: var(--surface-2); border-radius: var(--r-sm); padding: 8px 10px;
}
.demo-hint b { color: var(--terracotta-deep); font-weight: 600; }
.attribution {
  flex-shrink: 0;                       /* pinned at the bottom of the card */
  padding: 9px var(--s4);
  border-top: 1px solid var(--border);
  background: var(--bg);
  font-size: 10px; color: var(--muted); line-height: 1.4;
}
.attribution a { color: var(--muted); }

/* ─── Desktop: side panel (no sheet mechanics) ────────────────────────────── */
@media (min-width: 760px) {
  .panel {
    left: var(--s4); top: var(--s4); bottom: var(--s4); right: auto;
    width: 380px; height: auto;            /* top+bottom insets fix the height */
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-panel);
    transition: none; touch-action: auto;
  }
  .panel__grip { display: none; }
  .panel__peek { padding: var(--s5) var(--s5) 0; gap: var(--s4); }
  .panel__scroll { padding: var(--s4) var(--s5) var(--s5); gap: var(--s4); touch-action: auto; }
  .brand { padding-top: 0; }
  .brand__logo { width: 86%; max-width: 300px; }
  .chips {                                 /* back to a wrapping grid on desktop */
    flex-wrap: wrap; overflow: visible; touch-action: auto;
    -webkit-mask-image: none; mask-image: none;
  }
  .attribution { padding-left: var(--s5); padding-right: var(--s5); }
  .leaflet-control-zoom { margin-bottom: var(--s4) !important; margin-right: var(--s4) !important; }
}

/* ─── Reduced motion ──────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
