:root {
  --bg: #f8f9fa;
  --bg-elev: #ffffff;
  --bg-card: #ffffff;
  --ink: #212529;
  --muted: #6c757d;
  --accent: #0d6efd;
  --accent-ink: #ffffff;
  --accent-2: #fd7e14;
  --danger: #dc3545;
  --line: #dee2e6;
  --shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.1);
  --radius: 0.5rem;
  --tab-h: 56px;
  --top-h: 56px;
  --font-display: "Fraunces", Georgia, serif;
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}
body {
  font-family: var(--font-body);
  color: var(--ink);
  background: #e9ecef;
  -webkit-font-smoothing: antialiased;
}

/* Full-viewport shell — avoids short map on mobile browsers */
#app {
  position: fixed;
  inset: 0;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  left: 0;
  right: 0;
  display: grid;
  grid-template-rows: var(--top-h) minmax(0, 1fr) calc(var(--tab-h) + env(safe-area-inset-bottom, 0px));
  background: var(--bg);
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  height: var(--top-h);
  background: #fff;
  border-bottom: 1px solid var(--line);
  z-index: 40;
}
.brand { display: flex; gap: 0.55rem; align-items: center; min-width: 0; }
.brand-logo {
  display: block;
  height: 2rem;
  width: auto;
  max-width: min(180px, 55vw);
  object-fit: contain;
  object-position: left center;
}
.brand-mark {
  width: 1.75rem; height: 1.75rem; border-radius: 0.375rem;
  background: linear-gradient(135deg, #0d6efd, #20c997);
  flex-shrink: 0;
}
.brand-name {
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  display: block;
  line-height: 1.1;
  color: var(--ink);
}
.brand-city { color: var(--muted); font-size: 0.75rem; white-space: nowrap; }

.icon-btn {
  width: 2.25rem; height: 2.25rem;
  border-radius: 0.375rem;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  display: grid;
  place-items: center;
  cursor: pointer;
  font-size: 1.15rem;
  line-height: 1;
  padding: 0;
}
.icon-btn:hover { color: var(--accent); border-color: var(--accent); }

.views {
  position: relative;
  min-height: 0;
  overflow: hidden;
}
.view {
  position: absolute;
  inset: 0;
  overflow: hidden;
}
.view[hidden] { display: none !important; }

.map-shell,
#map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
#map {
  z-index: 1;
  background: #ced4da;
}

.radius-chip {
  position: absolute;
  top: 0.75rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  background: #fff;
  border: 1px solid var(--line);
  padding: 0.3rem 0.75rem;
  border-radius: 50rem;
  font-size: 0.75rem;
  color: var(--muted);
  box-shadow: 0 0.125rem 0.25rem rgba(0,0,0,0.075);
}

.cat-chips {
  position: absolute;
  left: 0; right: 0;
  bottom: 0.75rem;
  z-index: 30;
  display: flex;
  gap: 0.4rem;
  padding: 0 0.75rem;
  overflow-x: auto;
  scrollbar-width: none;
}
.cat-chips::-webkit-scrollbar { display: none; }
.cat-chips.static {
  position: static;
  padding: 0 0 0.75rem;
}

.chip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 50rem;
  padding: 0.4rem 0.8rem;
  font: 500 0.8rem var(--font-body);
  cursor: pointer;
  box-shadow: 0 0.125rem 0.25rem rgba(0,0,0,0.06);
}
.chip.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.chip-ico { font-size: 0.9rem; line-height: 1; }

/* Bootstrap-like bottom nav */
.tabbar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  align-items: stretch;
  height: calc(var(--tab-h) + env(safe-area-inset-bottom, 0px));
  padding: 0 0 env(safe-area-inset-bottom, 0px);
  background: #fff;
  border-top: 1px solid var(--line);
  z-index: 50;
}
.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  margin: 0;
  padding: 0.35rem 0.25rem;
  border: 0;
  border-top: 2px solid transparent;
  border-radius: 0;
  background: transparent;
  color: #6c757d;
  font: 400 0.7rem/1.2 var(--font-body);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.tab .bi {
  font-size: 1.25rem;
  line-height: 1;
}
.tab:hover { color: #495057; }
.tab.active {
  color: var(--accent);
  border-top-color: var(--accent);
  font-weight: 600;
  background: transparent;
}

.geo-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  padding: 0.75rem 0.9rem;
  margin-bottom: 0.85rem;
  border: 1px solid #cfe2ff;
  border-radius: var(--radius);
  background: #e7f1ff;
  color: #084298;
  font-size: 0.875rem;
}
.geo-banner.warn {
  background: #fff3cd;
  border-color: #ffecb5;
  color: #664d03;
}
.geo-banner .btn {
  flex: 0 0 auto;
  white-space: nowrap;
}

.panel-scroll {
  height: 100%;
  overflow: auto;
  padding: 1rem;
  background: var(--bg);
}
.panel-head h1 {
  font-family: var(--font-display);
  font-size: 1.5rem;
  margin: 0 0 0.15rem;
  letter-spacing: -0.02em;
}
.panel-head .muted { margin: 0.55rem 0 0.85rem; }

.radius-control {
  margin: 0.75rem 0 0.15rem;
  padding: 0.65rem 0.75rem 0.55rem;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.radius-control-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
  margin-bottom: 0.35rem;
  font-size: 0.82rem;
  color: var(--muted);
}
.radius-control-top strong {
  color: var(--accent);
  font-size: 0.95rem;
  font-weight: 600;
}
.radius-control input[type="range"] {
  width: 100%;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}
.radius-ends {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 0.15rem;
}

.card-grid {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.place-card {
  border: 1px solid var(--line);
  padding: 0;
  text-align: left;
  background: #fff;
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  color: inherit;
  box-shadow: 0 0.125rem 0.25rem rgba(0,0,0,0.05);
  width: 100%;
  font: inherit;
}
.place-card-media {
  position: relative;
  aspect-ratio: 16 / 10;
  background: #e9ecef;
  overflow: hidden;
}
.place-card-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.place-card-badge {
  position: absolute;
  left: 0.65rem;
  bottom: 0.65rem;
  background: rgba(33, 37, 41, 0.8);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.25rem 0.5rem;
  border-radius: 0.25rem;
}
.place-card-play {
  position: absolute;
  right: 0.65rem;
  top: 0.65rem;
  width: 2rem; height: 2rem;
  border-radius: 50%;
  background: rgba(13, 110, 253, 0.9);
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 0.7rem;
}
.place-card-body { padding: 0.75rem 0.85rem 0.9rem; }
.place-card-body h3 {
  margin: 0 0 0.25rem;
  font-size: 1.05rem;
  font-weight: 600;
}
.place-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  color: var(--muted);
  font-size: 0.8rem;
}
.stars { color: var(--accent-2); font-weight: 600; }

.sheet {
  border: 1px solid var(--line);
  border-radius: 0.75rem 0.75rem 0 0;
  padding: 0;
  width: min(560px, 100%);
  max-width: 100%;
  max-height: min(90vh, 960px);
  max-height: min(90dvh, 960px);
  overflow: hidden;
  flex-direction: column;
  background: #fff;
  color: var(--ink);
  box-shadow: var(--shadow);
  box-sizing: border-box;
  /* Anclado abajo en móvil: evita que el teclado/viewport corte el scroll */
  position: fixed;
  left: 50%;
  right: auto;
  top: auto;
  bottom: 0;
  margin: 0;
  transform: translateX(-50%);
}
/* Solo visible cuando el <dialog> está abierto (si no, tapa la app) */
dialog.sheet:not([open]) { display: none; }
dialog.sheet[open] {
  display: flex;
  flex-direction: column;
}
.sheet.ficha { width: min(640px, 100%); }
.sheet::backdrop { background: rgba(33, 37, 41, 0.45); }

/* El scroll va en el cuerpo interno (el dialog solo no desplaza bien en varios móviles) */
.sheet > form,
.sheet > #ally-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  padding-bottom: max(1.15rem, env(safe-area-inset-bottom, 0px));
}

.sheet form, .sheet > form { padding: 1.15rem; padding-bottom: max(1.15rem, env(safe-area-inset-bottom, 0px)); }
.sheet h2 {
  font-family: var(--font-display);
  margin: 0 0 0.5rem;
  font-size: 1.4rem;
}
.sheet label {
  display: grid;
  gap: 0.3rem;
  margin-bottom: 0.75rem;
  font-size: 0.8rem;
  color: var(--muted);
}
.sheet input, .sheet select, .sheet textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 0.375rem;
  padding: 0.55rem 0.75rem;
  font: 400 0.95rem var(--font-body);
  box-sizing: border-box;
}

.ficha-hero { position: relative; background: #e9ecef; }
.ficha-media-main {
  position: relative;
  aspect-ratio: 16 / 11;
  overflow: hidden;
  background: #e9ecef;
}
.ficha-media-main img,
.ficha-media-main video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.ficha-media-main iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}
.ficha-close {
  position: absolute;
  top: 0.65rem;
  right: 0.65rem;
  z-index: 5;
  width: 2rem; height: 2rem;
  border-radius: 0.375rem;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-size: 1.1rem;
  cursor: pointer;
  line-height: 1;
}
.ficha-thumbs {
  display: flex;
  gap: 0.4rem;
  padding: 0.5rem 0.75rem;
  overflow-x: auto;
  background: #f8f9fa;
  border-bottom: 1px solid var(--line);
}
.ficha-thumbs button {
  flex: 0 0 auto;
  width: 4.5rem;
  height: 3.25rem;
  border-radius: 0.375rem;
  border: 2px solid transparent;
  padding: 0;
  overflow: hidden;
  cursor: pointer;
  background: #dee2e6;
  position: relative;
}
.ficha-thumbs button.active { border-color: var(--accent); }
.ficha-thumbs img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.ficha-thumbs .thumb-video::after {
  content: "▶";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0,0,0,0.35);
  color: #fff;
  font-size: 0.75rem;
}
.ficha-content { padding: 1rem 1.15rem 1.35rem; }
.ally-meta {
  display: flex;
  gap: 0.55rem;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 0.8rem;
  margin-bottom: 0.75rem;
}
.cat-pill {
  background: rgba(13, 110, 253, 0.1);
  color: var(--accent);
  padding: 0.15rem 0.5rem;
  border-radius: 0.25rem;
  font-weight: 600;
  font-size: 0.72rem;
}
.ficha-toolbar {
  display: flex;
  gap: 0.5rem;
  margin: 0.85rem 0 0.35rem;
}
.icon-action {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 0.375rem;
  padding: 0.45rem 0.75rem;
  font: 500 0.85rem var(--font-body);
  cursor: pointer;
}
.icon-action .bi { font-size: 1.1rem; color: var(--accent); }
.icon-action[aria-expanded="true"] {
  border-color: var(--accent);
  background: #e7f1ff;
}
.action-menu {
  margin: 0.35rem 0 0.75rem;
  padding: 0.5rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: #f8f9fa;
}
.action-menu[hidden] { display: none !important; }
.action-menu-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.35rem;
}
.action-menu-grid .action-menu-hint {
  grid-column: 1 / -1;
}
.action-menu button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  width: 100%;
  border: 0;
  background: #fff;
  text-align: center;
  padding: 0.7rem 0.35rem;
  border-radius: 0.5rem;
  font: 500 0.72rem/1.2 var(--font-body);
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 0.05rem 0.15rem rgba(0,0,0,0.04);
}
.action-menu button:hover { background: #e7f1ff; }
.action-menu .bi { font-size: 1.25rem; color: var(--accent); line-height: 1; }
.action-menu-hint {
  margin: 0.15rem 0 0;
  font-size: 0.8rem;
  color: #198754;
  text-align: center;
}

.rating-label {
  display: block;
  margin-bottom: 0.4rem;
  font-size: 0.82rem;
  color: var(--muted);
}
.star-rating {
  position: relative;
  margin-bottom: 0.9rem;
  outline: none;
}
.star-rating .star-track {
  position: relative;
  height: 2.4rem;
  border-radius: 999px;
  background: #e9ecef;
  overflow: hidden;
  cursor: pointer;
  touch-action: none;
  user-select: none;
}
.star-rating .star-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 100%;
  background: linear-gradient(90deg, #ffc107, #ffca2c);
  border-radius: 999px;
  pointer-events: none;
  transition: width 0.08s linear;
}
.star-rating .star-glyphs {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  align-items: center;
  justify-items: center;
  font-size: 1.15rem;
  pointer-events: none;
  z-index: 1;
}
.star-rating .star-glyphs .bi {
  color: rgba(33, 37, 41, 0.28);
}
.star-rating .star-ends {
  display: flex;
  justify-content: space-between;
  margin-top: 0.35rem;
  font-size: 0.78rem;
  color: var(--muted);
}
.star-rating #rating-value-label {
  color: var(--accent-2);
  font-weight: 600;
}
.star-rating input[type="range"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 2.4rem;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 2;
}

.ficha-actions {
  display: flex;
  gap: 0.5rem;
  margin: 1rem 0 0.5rem;
}
.review {
  border-top: 1px solid var(--line);
  padding: 0.7rem 0;
  font-size: 0.9rem;
}
.booking-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  margin-bottom: 0.65rem;
}
.reserve-title {
  font-family: var(--font-display);
  margin: 1.25rem 0 0.35rem;
  font-size: 1.25rem;
}
.menu-cat { margin: 0.75rem 0; }
.menu-cat h4 {
  margin: 0 0 0.4rem;
  font-size: 0.95rem;
  font-family: var(--font-display);
}
.menu-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--line);
}
.menu-qty {
  width: 4rem;
  flex-shrink: 0;
}
.tips-box {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.65rem 0.85rem;
  margin: 0.75rem 0;
}
.tips-row { flex-wrap: wrap; gap: 0.35rem; margin-bottom: 0.5rem; }
.tip-btn.active, .tip-btn:focus { border-color: var(--accent); color: var(--accent); }
.cal-preview {
  background: #f7f7f5;
  border-radius: var(--radius);
  padding: 0.65rem 0.85rem;
  margin: 0.5rem 0 0.75rem;
}
.cal-preview.error { color: #b42318; }
.reserve-summary { margin: 0.5rem 0 0.75rem; }
.small { font-size: 0.8rem; }

.menu-gallery {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.65rem 0.85rem;
  margin: 0.75rem 0;
}
.ficha-menu {
  margin: 0.75rem 0 1rem;
  padding: 0.75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255,255,255,0.55);
}
.icon-action.active {
  color: var(--accent);
  border-color: var(--accent);
}
.menu-card-view { cursor: default; }
.menu-gallery summary {
  cursor: pointer;
  font-weight: 600;
  font-family: var(--font-display);
}
.menu-gallery-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem;
  margin-top: 0.75rem;
}
.menu-card {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin: 0;
}
.menu-card img, .menu-card-ph {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 0.5rem;
  background: #eceae4;
}
.menu-card-body { display: flex; flex-direction: column; gap: 0.2rem; }
.menu-card .menu-qty { width: 100%; }

.price-cal { margin: 0.75rem 0; }
.pc-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}
.pc-weekdays, .pc-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.pc-weekdays {
  text-align: center;
  font-size: 0.72rem;
  color: var(--muted, #6b7280);
  font-weight: 600;
  margin-bottom: 4px;
}
.pc-cell {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  min-height: 58px;
  padding: 4px 2px;
  text-align: center;
  cursor: pointer;
  font: inherit;
  color: inherit;
}
.pc-cell.empty { border: 0; background: transparent; }
.pc-cell.past, .pc-cell.blocked { opacity: 0.35; cursor: default; }
.pc-cell.avail .pc-price { color: #1a7f4b; font-size: 0.68rem; font-weight: 600; }
.pc-cell.selected {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.pc-cell.selected .pc-price { color: #fff; }
.pc-day { display: block; font-weight: 600; font-size: 0.85rem; }
.pc-price { display: block; }
.account-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.15rem;
}

.btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 0.375rem;
  padding: 0.55rem 0.9rem;
  font: 500 0.9rem var(--font-body);
  cursor: pointer;
}
.btn.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--accent);
}
.btn.block { width: 100%; }
.auth-oauth { margin-bottom: 0.75rem; }
a.auth-google.btn {
  display: flex;
  width: 100%;
  justify-content: center;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  box-sizing: border-box;
}
a.auth-google.btn:hover { border-color: var(--accent); color: var(--accent); }
.auth-or {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0.85rem 0 0.15rem;
  font-size: 0.8rem;
}
.auth-or::before,
.auth-or::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--line);
}
.row { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.5rem; }
.muted { color: var(--muted); font-size: 0.85rem; }
.error { color: var(--danger); font-size: 0.9rem; }
.ok { color: #198754; }
.empty {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--muted);
}

.leaflet-container { font: 400 12px var(--font-body); background: #ced4da; }
.leaflet-control-attribution {
  background: rgba(255,255,255,0.85) !important;
  color: var(--muted) !important;
  font-size: 10px !important;
}
.leaflet-control-attribution a { color: var(--accent) !important; }
.leaflet-control-zoom a {
  background: #fff !important;
  color: var(--ink) !important;
  border-color: var(--line) !important;
}

.pin {
  width: 32px; height: 32px; border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  border: 2px solid #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  display: grid; place-items: center;
}
.pin span { transform: rotate(45deg); font-size: 13px; line-height: 1; }
.pin.gastronomia { background: #198754; }
.pin.alojamiento { background: #0d6efd; }
.pin.comercio { background: #fd7e14; }
.pin.transporte { background: #6f42c1; }
.pin.eventos { background: #c2410c; }

.ticket-qr {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  padding: 0.75rem;
  margin: 0.5rem 0;
  background: rgba(0, 0, 0, 0.04);
  border-radius: 12px;
}
.ticket-qr canvas { width: 160px; height: 160px; }
.ticket-qr .holder { font-size: 0.9rem; text-align: center; }
.ticket-qr .code { font-size: 0.75rem; opacity: 0.7; word-break: break-all; }
.user-dot {
  width: 14px; height: 14px; border-radius: 50%;
  background: #0d6efd;
  border: 2px solid #fff;
  box-shadow: 0 0 0 6px rgba(13,110,253,0.25);
}

@media (min-width: 720px) {
  #app {
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
  }
  .sheet {
    border-radius: var(--radius);
    top: 50%;
    bottom: auto;
    transform: translate(-50%, -50%);
    max-height: min(85vh, 960px);
    max-height: min(85dvh, 960px);
  }
}
