:root {
  --cheap: #16a34a; --mid: #d97706; --pricey: #dc2626; --user: #2563eb;
  --bg: #fff; --fg: #111; --muted: #6b7280; --line: #e5e7eb; --soft: #f3f4f6;
  --panel-w: 380px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--fg); }
body { display: flex; flex-direction: column; height: 100dvh; overflow: hidden; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- Header ---------- */
header { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--bg);
  box-shadow: 0 1px 6px #0002; z-index: 1001; flex-wrap: wrap; }
.logo { white-space: nowrap; font-size: 17px; }
.search { flex: 1; min-width: 180px; }
.search input { width: 100%; padding: 9px 14px; border: 1px solid var(--line); border-radius: 999px; background: var(--soft);
  font-size: 15px; outline: none; }
.search input:focus { border-color: var(--fg); background: #fff; }

.seg { display: inline-flex; background: var(--soft); border-radius: 999px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 999px; cursor: pointer; font-size: 14px; white-space: nowrap; }
.seg button.active { background: var(--fg); color: #fff; }
.seg.small button { padding: 4px 9px; font-size: 13px; }

/* ---------- Layout ---------- */
main { flex: 1; min-height: 0; display: grid; grid-template-columns: var(--panel-w) 1fr; position: relative; }
#map { grid-column: 2; grid-row: 1; height: 100%; }
#panel { grid-column: 1; grid-row: 1; border-right: 1px solid var(--line); overflow-y: auto; background: var(--bg); }
.panel-body { padding: 12px 16px 24px; display: flex; flex-direction: column; gap: 12px; }
#handle { display: none; }
#locate { position: absolute; right: 12px; top: 90px; z-index: 1000; width: 40px; height: 40px; border-radius: 8px;
  border: 0; background: #fff; box-shadow: 0 1px 5px #0004; font-size: 18px; cursor: pointer; }

.row { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.radius span { font-size: 14px; } .radius input { flex: 1; } .radius output { font-weight: 700; min-width: 48px; text-align: right; }
.sort { font-size: 14px; display: flex; gap: 6px; align-items: center; }
.sort select { padding: 5px 6px; border-radius: 8px; border: 1px solid var(--line); background: #fff; max-width: 210px; }
.chip { border: 1px solid var(--line); background: #fff; padding: 5px 10px; border-radius: 999px; cursor: pointer; font-size: 13px; }
.chip[aria-pressed="true"] { background: var(--fg); color: #fff; border-color: var(--fg); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips .chip small { color: var(--muted); } .chips .chip[aria-pressed="true"] small { color: #ccc; }

.card { background: var(--soft); border-radius: 12px; padding: 10px 12px; font-size: 14px; }
#summary b { font-size: 18px; }
#summary .up { color: var(--pricey); } #summary .down { color: var(--cheap); }

/* ---------- List ---------- */
#list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
#list li { display: grid; grid-template-columns: 28px 1fr auto; gap: 8px; align-items: center; padding: 10px 4px;
  border-top: 1px solid var(--line); cursor: pointer; }
#list li:hover { background: var(--soft); }
#list .rank { font-weight: 700; color: var(--muted); text-align: center; }
#list li:nth-child(1) .rank { color: #ca8a04; font-size: 18px; }
#list .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#list .meta { font-size: 12px; color: var(--muted); }
#list .p { text-align: right; font-weight: 800; font-size: 16px; }
#list .p small { display: block; font-weight: 500; font-size: 11px; color: var(--muted); }
#list .empty { display: block; text-align: center; color: var(--muted); cursor: default; padding: 24px; }
mark { background: #fde68a; border-radius: 2px; }

/* ---------- Pins ---------- */
.pin { display: inline-block; padding: 3px 7px; border-radius: 8px; color: #fff; font-weight: 700; font-size: 12px;
  white-space: nowrap; box-shadow: 0 1px 4px #0005; border: 2px solid #fff; transform: translate(-50%, -50%); }
.pin.none { background: #888; }
.pin.cheap { background: var(--cheap); } .pin.mid { background: var(--mid); } .pin.pricey { background: var(--pricey); }
.pin.user { outline: 3px solid var(--user); }
.pin.tiny { width: 12px; height: 12px; padding: 0; border-radius: 50%; border-width: 1.5px; }
.pin.tiny.fav::after { content: none; }
.pin.best { font-size: 14px; padding: 4px 9px; }
.pin.fav::after { content: ' ⭐'; }
.pin.hot { transform: translate(-50%, -50%) scale(1.25); z-index: 1; }

/* ---------- Popup ---------- */
.popup h3 { margin: 0 0 2px; font-size: 16px; padding-right: 24px; }
.popup .sub { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.popup table { width: 100%; border-collapse: collapse; font-size: 14px; }
.popup td { padding: 4px 2px; border-top: 1px solid #eee; vertical-align: middle; }
.popup .price { font-weight: 700; white-space: nowrap; }
.badge { font-size: 10px; padding: 1px 5px; border-radius: 4px; background: #eee; color: #444; }
.badge.usuario { background: #dbeafe; color: var(--user); }
.votes button { border: 0; background: var(--soft); border-radius: 6px; padding: 2px 6px; cursor: pointer; font-size: 12px; }
.popup .actions { display: grid; grid-template-columns: 1fr 1fr auto auto; gap: 4px; margin-top: 8px; }
.popup .actions a, .popup .actions button { text-align: center; text-decoration: none; padding: 6px 8px; border-radius: 8px;
  border: 1px solid var(--line); background: #fff; color: var(--fg); cursor: pointer; font-size: 13px; }
.popup .actions .waze { background: #33ccff; border-color: #33ccff; color: #05344a; font-weight: 700; }
.popup form { display: flex; gap: 4px; margin-top: 8px; }
.popup form select, .popup form input { flex: 1; min-width: 0; padding: 6px; font-size: 14px; }
.popup form button { padding: 6px 10px; background: var(--user); color: #fff; border: 0; border-radius: 6px; cursor: pointer; }

#legend { font-size: 12px; display: flex; flex-wrap: wrap; gap: 10px; color: var(--muted); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: -1px; }
.dot.cheap { background: var(--cheap); } .dot.mid { background: var(--mid); } .dot.pricey { background: var(--pricey); }
.dot.user { background: #fff; outline: 3px solid var(--user); outline-offset: -3px; }
.me-dot { width: 16px; height: 16px; border-radius: 50%; background: var(--user); border: 3px solid #fff;
  box-shadow: 0 0 0 6px #2563eb33; transform: translate(-50%, -50%); }

#toast { position: fixed; left: 50%; top: 72px; transform: translateX(-50%); z-index: 2000; background: #111; color: #fff;
  padding: 8px 14px; border-radius: 8px; font-size: 14px; opacity: 0; transition: opacity .2s; pointer-events: none; max-width: calc(100% - 32px); }
#toast.show { opacity: 1; }

/* ---------- Móvil: el panel es una hoja que sube desde abajo ---------- */
@media (max-width: 767px) {
  header { gap: 8px; padding: 8px 12px; }
  .logo span { display: none; }
  .fuels { width: 100%; justify-content: space-between; }
  .fuels button { flex: 1; }
  main { display: block; }
  #map { position: absolute; inset: 0; }
  #locate { top: auto; bottom: 76px; right: 12px; }
  #panel { position: absolute; left: 0; right: 0; bottom: 0; z-index: 1000; border: 0; border-radius: 16px 16px 0 0;
    box-shadow: 0 -2px 12px #0003; max-height: 64px; overflow: hidden; transition: max-height .25s ease; }
  #panel.open { max-height: 72%; overflow-y: auto; }
  #panel.open ~ #locate { display: none; }
  #handle { display: flex; flex-direction: column; align-items: center; gap: 6px; width: 100%; border: 0; background: var(--bg);
    padding: 8px 16px 12px; cursor: pointer; position: sticky; top: 0; z-index: 1; font-weight: 600; }
  #handle i { width: 40px; height: 4px; border-radius: 4px; background: #d1d5db; }
}
@media (max-width: 767px) {
  #count::after { content: ' ▲'; }
  #panel.open #count::after { content: ' ▼'; }
}

.approx { font-size: 12px; color: var(--muted); margin: 8px 0 0; line-height: 1.35; }
.badge.estimado { background: #fef3c7; color: #92400e; }
#summary .approx b { font-size: inherit; }
