:root {
  --ink: #1b2536;
  --ink-2: #546179;
  --ink-3: #8a94a6;
  --line: #e1e5ec;
  --wash: #f2f4f7;
  --paper: #ffffff;
  --green: #0b8a4a;
  --green-soft: #e3f4ea;
  --blue: #1d57c9;
  --blue-soft: #e5edfb;
  --up: #c2410c;
  --amber: #f2b600;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(27, 37, 54, .12), 0 6px 20px rgba(27, 37, 54, .12);
  --num: 'Barlow Condensed', 'Arial Narrow', sans-serif;
  --ui: 'Barlow', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font: 15px/1.4 var(--ui);
  color: var(--ink);
  background: var(--wash);
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--amber); outline-offset: 2px; }
svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

#map { position: fixed; inset: 0; background: #e9ecef; }

/* ---------- panel layout: mobile first ---------- */
#panel { display: contents; }

#controls {
  position: fixed;
  z-index: 10;
  top: calc(10px + var(--safe-top));
  left: 10px;
  right: 10px;
  display: grid;
  gap: 8px;
  padding: 10px;
  background: var(--paper);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

#sheet {
  position: fixed;
  z-index: 9;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  max-height: 64vh;
  padding: 0 14px calc(10px + var(--safe-bottom));
  background: var(--paper);
  border-radius: 18px 18px 0 0;
  box-shadow: 0 -4px 24px rgba(27, 37, 54, .16);
  transition: max-height .25s ease;
}
#sheet[data-state="peek"] #list-head,
#sheet[data-state="peek"] #list,
#sheet[data-state="peek"] #meta { display: none; }
#sheet[data-mode="detail"] #summary,
#sheet[data-mode="detail"] #list-head,
#sheet[data-mode="detail"] #list { display: none; }

#grab {
  align-self: stretch;
  height: 22px;
  border: 0;
  background: none;
  display: grid;
  place-items: center;
  flex: none;
}
#grab span { width: 40px; height: 4px; border-radius: 2px; background: var(--line); }

.fab {
  position: fixed;
  z-index: 8;
  right: 12px;
  bottom: calc(var(--sheet-h, 140px) + 12px);
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 0;
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow);
  display: grid;
  place-items: center;
  transition: bottom .25s ease;
}
.fab svg { width: 22px; height: 22px; }
.fab.busy svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (min-width: 860px) {
  #panel {
    display: flex;
    flex-direction: column;
    position: fixed;
    z-index: 10;
    top: 0;
    left: 0;
    bottom: 0;
    width: 400px;
    background: var(--paper);
    border-right: 1px solid var(--line);
  }
  #map { left: 400px; }
  #controls, #sheet {
    position: static;
    box-shadow: none;
    border-radius: 0;
    max-height: none;
  }
  #controls { padding: 14px 14px 12px; border-bottom: 1px solid var(--line); }
  #sheet { flex: 1; min-height: 0; padding-top: 6px; }
  #sheet[data-state="peek"] #list-head { display: flex; }
  #sheet[data-state="peek"] #list, #sheet[data-state="peek"] #meta { display: block; }
  #sheet[data-mode="detail"] #list-head, #sheet[data-mode="detail"] #list, #sheet[data-mode="detail"] #summary { display: none; }
  #grab { display: none; }
  .fab { bottom: 24px; right: 16px; }
}

/* ---------- search ---------- */
.search { position: relative; display: flex; align-items: center; }
.search-icon { position: absolute; left: 11px; width: 18px; height: 18px; color: var(--ink-3); pointer-events: none; }
#q {
  width: 100%;
  height: 42px;
  padding: 0 40px 0 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--wash);
  font-size: 16px;
  outline: none;
}
#q:focus { background: var(--paper); border-color: var(--ink-3); }
#q::-webkit-search-cancel-button { display: none; }
.icon-btn {
  position: absolute; right: 4px; width: 34px; height: 34px;
  border: 0; background: none; color: var(--ink-2); display: grid; place-items: center; border-radius: 8px;
}
.icon-btn svg { width: 18px; height: 18px; }

#suggest {
  position: absolute;
  top: 48px;
  left: -10px;
  right: -10px;
  max-height: 60vh;
  overflow-y: auto;
  background: var(--paper);
  border-radius: 0 0 var(--radius) var(--radius);
  box-shadow: 0 12px 24px rgba(27, 37, 54, .16);
  padding: 4px 0 8px;
  z-index: 20;
}
#suggest h4 { margin: 8px 16px 2px; font-size: 12px; font-weight: 600; color: var(--ink-3); }
#suggest button {
  display: flex; width: 100%; align-items: baseline; gap: 10px;
  padding: 9px 16px; border: 0; background: none; text-align: left;
}
#suggest button:hover, #suggest button.active { background: var(--wash); }
#suggest .s-main { flex: 1; min-width: 0; }
#suggest .s-main b { font-weight: 600; }
#suggest .s-main span { display: block; color: var(--ink-2); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#suggest .s-price { font: 700 18px/1 var(--num); }
#suggest .empty { padding: 10px 16px; color: var(--ink-2); }

/* ---------- segmented controls ---------- */
.seg { display: flex; gap: 2px; padding: 3px; border-radius: 10px; background: var(--wash); }
.seg button {
  flex: 1;
  min-height: 36px;
  border: 0;
  border-radius: 8px;
  background: none;
  font-weight: 600;
  color: var(--ink-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 6px;
  white-space: nowrap;
}
.seg button[aria-checked="true"] { background: var(--ink); color: #fff; }
.seg.fuel button { font: 700 18px/1 var(--num); letter-spacing: .01em; }
.seg button small { font-weight: 500; font-size: 12px; opacity: .75; }
.seg button:disabled { cursor: default; opacity: .55; }
.seg.mini button { min-height: 30px; font-size: 13px; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.dot.today { background: var(--green); }
.dot.tomorrow { background: var(--blue); }
.seg button[aria-checked="true"] .dot { box-shadow: 0 0 0 2px #fff; }

/* ---------- summary ---------- */
#summary { flex: none; padding: 2px 0 8px; }
.best { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; padding: 6px 0; width: 100%; border: 0; background: none; text-align: left; }
.best + .best { border-top: 1px solid var(--line); }
.best .tag { font-size: 12px; font-weight: 600; color: var(--ink-2); display: block; }
.best .price {
  font: 700 34px/1 var(--num);
  min-width: 82px;
  padding: 6px 8px 4px;
  border-radius: 8px;
  color: #fff;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.best.today .price { background: var(--green); }
.best.tomorrow .price { background: var(--blue); }
.best .who { min-width: 0; }
.best .who b { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.best .who span { display: block; color: var(--ink-2); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.best .km { color: var(--ink-2); font-size: 13px; white-space: nowrap; }
.count { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; color: var(--ink-2); font-size: 13px; margin: 4px 0 0; }
.link { flex: none; border: 0; background: none; padding: 4px 0; font-weight: 600; font-size: 14px; color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }
@media (min-width: 860px) { .link[data-act="toggle"] { display: none; } }
.more { padding: 12px 14px; color: var(--ink-2); font-size: 13px; border-top: 1px solid var(--line); }
@media (max-width: 859px) {
  .best { padding: 4px 0; gap: 10px; }
  .best .price { font-size: 28px; min-width: 70px; padding: 5px 6px 3px; }
  .seg button { min-height: 34px; }
  #controls { gap: 7px; padding: 8px; }
}
.note { margin: 6px 0; padding: 10px 12px; border-radius: 10px; background: var(--wash); color: var(--ink-2); font-size: 14px; }
.note button { margin-left: 6px; border: 0; background: var(--ink); color: #fff; border-radius: 6px; padding: 4px 10px; font-weight: 600; }

/* ---------- list ---------- */
#list-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 0 8px; flex: none; flex-wrap: wrap; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-2); }
.check input { width: 17px; height: 17px; accent-color: var(--ink); margin: 0; }
#list { list-style: none; margin: 0 -14px; padding: 0; overflow-y: auto; flex: 1; min-height: 0; overscroll-behavior: contain; }
#list li + li .row { border-top: 1px solid var(--line); }
.row {
  display: grid;
  grid-template-columns: 74px 1fr auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 14px;
  border: 0;
  background: none;
  text-align: left;
}
.row:hover { background: var(--wash); }
.row-price b { display: block; font: 700 26px/1 var(--num); font-variant-numeric: tabular-nums; }
.row.cheap-today .row-price b { color: var(--green); }
.row.cheap-tomorrow .row-price b { color: var(--blue); }
.row-price small { display: block; margin-top: 2px; font-size: 12px; font-weight: 600; color: var(--ink-2); }
.row-price small.down { color: var(--green); }
.row-price small.up { color: var(--up); }
.row-price small.best-tomorrow { color: var(--blue); }
.row-price small.best-today { color: var(--green); }
.row-main { min-width: 0; }
.row-main b { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-main span { display: block; color: var(--ink-2); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-km { color: var(--ink-2); font-size: 13px; text-align: right; white-space: nowrap; }
.flag { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 6px; border-radius: 4px; background: var(--wash); color: var(--ink-2); margin-left: 4px; vertical-align: 1px; }
.flag.warn { background: #fdecea; color: #a8321e; }
.down { color: var(--green); }
.up { color: var(--up); }
#meta { flex: none; margin: 8px 0 0; font-size: 12px; color: var(--ink-3); }
#meta a { color: inherit; }

/* ---------- detail ---------- */
#detail { overflow-y: auto; padding-bottom: 4px; }
.d-top { display: flex; align-items: flex-start; gap: 10px; }
.d-top h2 { flex: 1; margin: 0; font-size: 20px; line-height: 1.2; font-weight: 700; }
.d-top .icon-btn { position: static; flex: none; margin: -4px -8px 0 0; }
.d-addr { margin: 4px 0 12px; color: var(--ink-2); }
.d-prices { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.d-price { padding: 10px 12px; border-radius: 10px; background: var(--wash); }
.d-price span { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.d-price b { display: block; font: 700 36px/1.05 var(--num); font-variant-numeric: tabular-nums; }
.d-price.best-today { background: var(--green-soft); }
.d-price.best-today b { color: var(--green); }
.d-price.best-tomorrow { background: var(--blue-soft); }
.d-price.best-tomorrow b { color: var(--blue); }
.d-price small { font-size: 13px; font-weight: 600; }
.d-flags { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 0; }
.d-flags .flag { margin: 0; font-size: 12px; padding: 3px 8px; }
.d-actions { display: flex; gap: 8px; margin-top: 14px; }
.btn {
  flex: 1; min-height: 46px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--paper); font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  text-decoration: none; color: var(--ink);
}
.btn.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn svg { width: 18px; height: 18px; }

/* ---------- map markers ---------- */
.mk { cursor: pointer; }
.pin {
  position: relative;
  min-width: 46px;
  padding: 4px 7px 3px;
  border-radius: 7px;
  background: var(--ink);
  color: #fff;
  text-align: center;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .35);
  margin-bottom: 7px;
  transition: transform .12s ease;
}
.pin::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: -6px;
  margin-left: -6px;
  border: 6px solid transparent;
  border-bottom: 0;
  border-top-color: var(--tail, var(--ink));
}
.pin b { display: block; font: 700 18px/1 var(--num); font-variant-numeric: tabular-nums; letter-spacing: .01em; }
.pin small { display: block; font: 600 12px/1.1 var(--num); margin-top: 1px; }
.pin small.down { color: #6ee7a0; }
.pin small.up { color: #fdba8c; }
.pin small.flat { color: #b8c0cd; }
.pin.cheap-today { background: var(--green); --tail: var(--green); }
.pin.cheap-tomorrow { background: var(--blue); --tail: var(--blue); }
.pin.cheap-today.cheap-tomorrow { --tail: var(--blue); box-shadow: inset 0 -4px 0 var(--blue), 0 1px 3px rgba(0, 0, 0, .35); padding-bottom: 6px; }
.pin.cheap-today small, .pin.cheap-tomorrow small { color: rgba(255, 255, 255, .88); }
.pin.out { background: #9aa3b2; --tail: #9aa3b2; }
.pin.out b { text-decoration: line-through; }
.pin.none b { color: #b8c0cd; }
.mk.selected .pin { outline: 3px solid var(--amber); outline-offset: 1px; transform: scale(1.12); }

.cluster { display: flex; flex-direction: column; align-items: center; }
.cluster .ring {
  width: var(--d, 38px);
  height: var(--d, 38px);
  border-radius: 50%;
  background: var(--paper);
  border: 2px solid var(--ink);
  display: grid;
  place-items: center;
  font: 700 16px/1 var(--num);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
}
.cluster .from {
  margin-top: -6px;
  padding: 2px 5px 1px;
  border-radius: 5px;
  background: var(--ink);
  color: #fff;
  font: 700 14px/1 var(--num);
  font-variant-numeric: tabular-nums;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .3);
}
.cluster.cheap-today .ring { border-color: var(--green); }
.cluster.cheap-today .from { background: var(--green); }
.cluster.cheap-tomorrow:not(.cheap-today) .ring { border-color: var(--blue); }

.me { width: 20px; height: 20px; border-radius: 50%; background: var(--ink); border: 3px solid #fff; box-shadow: 0 0 0 6px rgba(242, 182, 0, .45), 0 1px 4px rgba(0, 0, 0, .4); }

/* map attribution tidy-up */
.maplibregl-ctrl-bottom-right, .maplibregl-ctrl-bottom-left { bottom: var(--sheet-h, 0px); transition: bottom .25s ease; }
@media (min-width: 860px) { .maplibregl-ctrl-bottom-right, .maplibregl-ctrl-bottom-left { bottom: 0; } }

/* ---------- toast ---------- */
#toast {
  position: fixed;
  z-index: 30;
  left: 50%;
  bottom: calc(var(--sheet-h, 140px) + 70px);
  transform: translateX(-50%);
  max-width: min(92vw, 420px);
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--ink);
  color: #fff;
  font-size: 14px;
  box-shadow: var(--shadow);
}
@media (min-width: 860px) { #toast { left: calc(400px + (100vw - 400px) / 2); bottom: 30px; } }

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