/* Los colores y medidas de toda la app, en un solo sitio */
:root {
  --ink: #1C1F24;          /* texto y botones secundarios */
  --granite: #6D7178;      /* texto secundario (el granito de Compostela) */
  --mist: #EEF0EC;         /* fondos de chips y campos */
  --line: #DFE2DC;         /* separadores */
  --paper: #FFFFFF;        /* hojas y tarjetas */
  --wine: #B0124A;         /* el color de la marca: pines y acciones principales (vino Mencía) */
  --wine-dark: #8C0E3B;
  --wine-soft: #F8E7ED;
  --gold: #E8A800;         /* estrellas y puntos */
  --ok: #1F8A4C;
  --ok-soft: #E3F3E9;
  --error: #C2361F;
  --error-soft: #FBE9E5;

  --display: 'Bricolage Grotesque', system-ui, sans-serif;
  --text: 'Atkinson Hyperlegible Next', system-ui, sans-serif;

  --radius-sheet: 28px;
  --radius-control: 16px;
  --shadow-float: 0 6px 24px rgba(28, 31, 36, 0.16);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body, #root { height: 100%; margin: 0; }

body {
  font-family: var(--text);
  font-size: 16px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--mist);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

h1, h2, h3 { font-family: var(--display); font-weight: 800; line-height: 1.1; margin: 0; letter-spacing: -0.01em; }
h1 { font-size: 28px; }
h2 { font-size: 22px; }
h3 { font-size: 17px; font-weight: 600; }
p { margin: 0; }

button, input, textarea, select { font: inherit; color: inherit; }

:focus-visible { outline: 3px solid var(--wine); outline-offset: 2px; }

.muted { color: var(--granite); }
.small { font-size: 14px; }

/* ---------- Botones ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 0 22px;
  border: 0; border-radius: var(--radius-control);
  font-weight: 700; font-size: 16px;
  cursor: pointer; transition: transform 0.1s, background 0.15s;
  text-decoration: none;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { cursor: not-allowed; opacity: 0.45; transform: none; }
.btn-primary { background: var(--wine); color: #fff; }
.btn-primary:not(:disabled):active { background: var(--wine-dark); }
.btn-dark { background: var(--ink); color: #fff; }
.btn-ghost { background: var(--mist); color: var(--ink); }
.btn-block { width: 100%; }
.btn-small { min-height: 40px; padding: 0 16px; font-size: 15px; border-radius: 12px; }

.icon-btn {
  display: grid; place-items: center;
  width: 48px; height: 48px; border: 0; border-radius: 50%;
  background: var(--paper); color: var(--ink);
  box-shadow: var(--shadow-float); cursor: pointer;
}
.icon-btn:active { transform: scale(0.94); }
.icon-btn.plain { box-shadow: none; background: var(--mist); width: 40px; height: 40px; }

/* ---------- Mapa ---------- */

.map { position: fixed; inset: 0; z-index: 0; background: #E8EAE6; }
.leaflet-container { font-family: var(--text); }
/* El mapa de OpenStreetMap tiene mucho color: se apaga para que los únicos colores fuertes sean los pines */
.leaflet-tile-pane { filter: saturate(0.25) contrast(0.92) brightness(1.06); }
.leaflet-control-attribution { font-size: 10px; background: rgba(255, 255, 255, 0.7) !important; }

/* El pin: una píldora con la nota del local y un pico que apunta al sitio exacto */
.pin-icon { background: none; border: 0; }
.pin {
  position: absolute; left: 50%; bottom: 6px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 3px;
  padding: 5px 9px; border-radius: 999px;
  background: var(--wine); color: #fff;
  font-family: var(--display); font-weight: 800; font-size: 14px; white-space: nowrap;
  box-shadow: 0 3px 10px rgba(176, 18, 74, 0.35);
  transition: transform 0.15s, background 0.15s;
}
.pin::after {
  content: ''; position: absolute; left: 50%; bottom: -6px; transform: translateX(-50%);
  border: 6px solid transparent; border-bottom: 0; border-top-color: var(--wine);
}
.pin .star { color: #FFD873; font-size: 11px; }
.pin.is-new { background: var(--paper); color: var(--wine); }
.pin.is-new::after { border-top-color: var(--paper); }
.pin.is-selected { background: var(--ink); color: #fff; transform: translateX(-50%) scale(1.18); z-index: 10; }
.pin.is-selected::after { border-top-color: var(--ink); }

/* Con el mapa alejado, cada local es un punto (ver MapView) */
.dot {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--wine); border: 3px solid #fff;
  box-shadow: 0 2px 8px rgba(176, 18, 74, 0.45);
}
.dot.is-new { background: #fff; border-color: var(--wine); }

.me-dot {
  width: 18px; height: 18px; border-radius: 50%;
  background: #2D6CDF; border: 3px solid #fff;
  box-shadow: 0 0 0 6px rgba(45, 108, 223, 0.2);
}

/* ---------- Capa superior del mapa: búsqueda, filtros y botones ---------- */

.top-bar {
  position: fixed; z-index: 500; left: 0; right: 0; top: 0;
  padding: calc(var(--safe-top) + 12px) 16px 0;
  display: grid; gap: 10px; pointer-events: none;
}
/* La barra no tapa el mapa: solo sus botones reciben los toques, el hueco entre ellos deja tocar los pines */
.top-row { display: flex; gap: 10px; align-items: center; pointer-events: none; }
.top-row > * { pointer-events: auto; }

.search {
  flex: 1; display: flex; align-items: center; gap: 10px;
  height: 52px; padding: 0 16px; border-radius: 999px;
  background: var(--paper); box-shadow: var(--shadow-float);
}
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; font-size: 16px; }
.search input::placeholder { color: var(--granite); }
.search input::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; display: none; }
.search-clear { border: 0; background: var(--mist); width: 28px; height: 28px; border-radius: 50%; cursor: pointer; display: grid; place-items: center; }

.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding-bottom: 4px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; height: 38px; padding: 0 16px; border-radius: 999px;
  border: 0; background: var(--paper); box-shadow: 0 2px 8px rgba(28, 31, 36, 0.12);
  font-weight: 700; font-size: 15px; cursor: pointer;
}
.chip[aria-pressed='true'] { background: var(--ink); color: #fff; }

.points-pill {
  display: flex; align-items: center; gap: 6px;
  height: 48px; padding: 0 16px 0 12px; border-radius: 999px;
  background: var(--paper); box-shadow: var(--shadow-float);
  font-family: var(--display); font-weight: 800; font-size: 17px; border: 0; cursor: pointer;
}
.points-pill .coin {
  width: 24px; height: 24px; border-radius: 50%; background: var(--gold); color: #fff;
  display: grid; place-items: center; font-size: 13px;
}

.badge-wrap { position: relative; }
.badge {
  position: absolute; top: -2px; right: -2px; min-width: 20px; height: 20px; padding: 0 5px;
  border-radius: 999px; background: var(--wine); color: #fff; font-size: 12px; font-weight: 700;
  display: grid; place-items: center; border: 2px solid #fff;
}

.side-buttons {
  position: fixed; z-index: 500; right: 16px;
  bottom: calc(var(--safe-bottom) + 24px);
  display: grid; gap: 12px; transition: bottom 0.3s;
}
.side-buttons.lifted { bottom: calc(var(--safe-bottom) + 44vh); }

.map-status {
  position: fixed; z-index: 500; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--safe-bottom) + 28px);
  padding: 12px 18px; border-radius: 999px; background: var(--ink); color: #fff;
  font-weight: 600; font-size: 15px; box-shadow: var(--shadow-float); white-space: nowrap;
}
.map-status button { margin-left: 10px; background: none; border: 0; color: #FFD873; font-weight: 700; cursor: pointer; }

/* ---------- Hoja inferior ---------- */

.scrim { position: fixed; inset: 0; z-index: 900; background: rgba(28, 31, 36, 0.35); animation: fade 0.2s; }

.sheet {
  position: fixed; z-index: 1000; left: 0; right: 0; bottom: 0;
  max-height: calc(100% - var(--safe-top) - 24px);
  display: flex; flex-direction: column;
  background: var(--paper); border-radius: var(--radius-sheet) var(--radius-sheet) 0 0;
  box-shadow: 0 -8px 30px rgba(28, 31, 36, 0.18);
  padding-bottom: var(--safe-bottom);
  animation: rise 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
  transition: height 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.sheet.peek { height: 42vh; }
.sheet.full { height: calc(100% - var(--safe-top) - 24px); }
.sheet.auto { height: auto; }

.sheet-handle {
  flex: none; display: grid; place-items: center; height: 28px; width: 100%;
  border: 0; background: none; cursor: grab; touch-action: none;
}
.sheet-handle::before { content: ''; width: 44px; height: 5px; border-radius: 3px; background: var(--line); }
.sheet-body { flex: 1; overflow-y: auto; padding: 0 20px 24px; overscroll-behavior: contain; }
.sheet-head { display: flex; align-items: flex-start; gap: 12px; }
.sheet-head > div { flex: 1; min-width: 0; }

@keyframes rise { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Ficha del local ---------- */

.meta-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; margin-top: 8px; font-size: 15px; }
.rating { display: inline-flex; align-items: center; gap: 4px; font-weight: 700; }
.rating .star { color: var(--gold); }
.price { font-weight: 700; letter-spacing: 1px; }
.price .off { color: var(--line); }

.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.tag { padding: 4px 10px; border-radius: 999px; background: var(--mist); font-size: 14px; font-weight: 600; }

.quick-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }

.section { margin-top: 28px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }

.rewards { display: flex; gap: 12px; overflow-x: auto; margin: 0 -20px; padding: 2px 20px 6px; scroll-snap-type: x mandatory; scrollbar-width: none; }
.rewards::-webkit-scrollbar { display: none; }
.reward {
  flex: none; width: 76%; max-width: 300px; scroll-snap-align: start;
  display: flex; flex-direction: column; gap: 6px;
  padding: 16px; border-radius: 20px; background: var(--wine-soft);
}
.reward .cost { font-family: var(--display); font-weight: 800; font-size: 26px; color: var(--wine); line-height: 1; }
.reward .cost small { font-size: 14px; font-weight: 600; }
.reward p { font-size: 14px; color: var(--granite); flex: 1; }
.reward .btn { margin-top: 6px; }
.reward .missing { font-size: 14px; font-weight: 600; color: var(--wine-dark); }

.review { padding: 14px 0; border-top: 1px solid var(--line); }
.review:first-of-type { border-top: 0; padding-top: 0; }
.review-head { display: flex; justify-content: space-between; gap: 8px; font-size: 15px; }
.review-head strong { font-weight: 700; }
.review p { margin-top: 4px; }

.stars-input { display: flex; gap: 4px; justify-content: center; margin: 8px 0 16px; }
.stars-input button {
  width: 52px; height: 52px; border: 0; background: none; cursor: pointer;
  font-size: 38px; line-height: 1; color: var(--line); transition: transform 0.1s, color 0.1s;
}
.stars-input button.on { color: var(--gold); }
.stars-input button:active { transform: scale(1.2); }

.info-row { display: flex; align-items: center; gap: 12px; padding: 14px 0; border-top: 1px solid var(--line); text-decoration: none; color: inherit; }
.info-row:first-of-type { border-top: 0; }
.info-row svg { flex: none; color: var(--granite); }

.empty { padding: 18px; border-radius: 16px; background: var(--mist); text-align: center; color: var(--granite); font-size: 15px; }
button.empty { width: 100%; border: 0; cursor: pointer; font: inherit; }

/* ---------- Formularios ---------- */

.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label { font-weight: 700; font-size: 15px; }
.field input, .field textarea {
  width: 100%; min-height: 52px; padding: 14px 16px;
  border: 2px solid transparent; border-radius: var(--radius-control);
  background: var(--mist); font-size: 16px; outline: 0;
}
.field textarea { min-height: 96px; resize: vertical; }
.field input:focus, .field textarea:focus { border-color: var(--ink); background: var(--paper); }
.field .hint { font-size: 14px; color: var(--granite); }
.field .hint.bad { color: var(--error); }
.field input[aria-invalid='true'] { border-color: var(--error); }

.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; border-radius: 16px; background: var(--mist); margin: 16px 0 20px; }
.segmented button { min-height: 44px; border: 0; border-radius: 12px; background: none; font-weight: 700; cursor: pointer; }
.segmented button[aria-pressed='true'] { background: var(--paper); box-shadow: 0 1px 4px rgba(28, 31, 36, 0.12); }

.alert { padding: 12px 14px; border-radius: 14px; font-size: 15px; font-weight: 600; margin-bottom: 14px; }
.alert.error { background: var(--error-soft); color: var(--error); }
.alert.ok { background: var(--ok-soft); color: var(--ok); }

/* ---------- Pantallas completas (canjes, perfil, QR) ---------- */

.screen {
  position: fixed; inset: 0; z-index: 1100; overflow-y: auto;
  background: var(--paper);
  padding: calc(var(--safe-top) + 12px) 20px calc(var(--safe-bottom) + 24px);
  animation: slide 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes slide { from { transform: translateX(100%); } to { transform: translateX(0); } }
.screen-head { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }

.ticket {
  width: 100%; display: flex; align-items: center; gap: 14px; text-align: left;
  padding: 16px; margin-bottom: 10px; border: 0; border-radius: 20px;
  background: var(--mist); cursor: pointer;
}
.ticket.pending { background: var(--wine-soft); }
.ticket .ticket-icon { flex: none; width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; background: var(--paper); color: var(--wine); }
.ticket > div { flex: 1; min-width: 0; }
.ticket strong { display: block; font-weight: 700; }
.status { font-size: 13px; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: var(--paper); white-space: nowrap; }
.status.PENDING { color: var(--wine); }
.status.USED { color: var(--ok); }
.status.EXPIRED { color: var(--granite); }
.status.CANCELLED { color: var(--granite); }

.qr-screen { display: flex; flex-direction: column; align-items: center; text-align: center; }
.qr-card { margin: 12px 0 18px; padding: 20px; border-radius: 28px; background: #fff; box-shadow: 0 10px 40px rgba(28, 31, 36, 0.14); }
.qr-card svg { display: block; width: min(68vw, 300px); height: auto; }
.countdown { width: min(68vw, 300px); height: 6px; border-radius: 3px; background: var(--mist); overflow: hidden; margin-top: 16px; }
.countdown div { height: 100%; background: var(--wine); transition: width 1s linear; }
.code { font-family: var(--display); font-weight: 800; font-size: 22px; letter-spacing: 2px; margin-top: 6px; }
.gained { display: flex; align-items: center; gap: 8px; margin-top: 14px; padding: 10px 18px; border-radius: 999px; background: var(--ok); color: #fff; font-weight: 800; font-size: 18px; animation: pop 0.35s cubic-bezier(0.2, 1.4, 0.4, 1); }
.done-mark { width: 120px; height: 120px; border-radius: 50%; background: var(--ok); color: #fff; display: grid; place-items: center; margin: 40px 0 20px; animation: pop 0.35s cubic-bezier(0.2, 1.4, 0.4, 1); }
@keyframes pop { from { transform: scale(0.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.big-points { display: flex; align-items: center; gap: 14px; padding: 20px; border-radius: 24px; background: var(--ink); color: #fff; margin: 8px 0 20px; }
.big-points .coin { width: 52px; height: 52px; border-radius: 50%; background: var(--gold); display: grid; place-items: center; font-family: var(--display); font-weight: 800; font-size: 22px; }
.big-points strong { font-family: var(--display); font-size: 40px; font-weight: 800; line-height: 1; }

.how { display: grid; gap: 12px; margin: 8px 0 24px; padding: 0; list-style: none; counter-reset: step; }
.how li { display: flex; gap: 12px; align-items: flex-start; counter-increment: step; }
.how li::before { content: counter(step); flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--wine-soft); color: var(--wine); font-weight: 700; display: grid; place-items: center; font-size: 14px; }

/* ---------- Avisos ---------- */

.toast {
  position: fixed; z-index: 2000; left: 16px; right: 16px; top: calc(var(--safe-top) + 12px);
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; border-radius: 18px; background: var(--ink); color: #fff;
  font-weight: 600; box-shadow: var(--shadow-float);
  animation: drop 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.toast.ok { background: var(--ok); }
.toast.error { background: var(--error); }
@keyframes drop { from { transform: translateY(-120%); } to { transform: translateY(0); } }

.skeleton { border-radius: 10px; background: linear-gradient(90deg, var(--mist), #F7F8F5, var(--mist)); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

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

/* En un ordenador la app se ve como un móvil centrado: está pensada para el móvil */
@media (min-width: 640px) {
  .sheet, .screen, .toast { left: 50%; right: auto; width: 480px; transform: translateX(-50%); }
  .screen { animation: none; }
  .sheet { animation: none; }
  .top-bar { max-width: 480px; margin: 0 auto; }
}

/* En un ordenador ancho el mapa sigue a pantalla completa y lo que se abre encima va en una columna a la izquierda.
   El mapa no cambia de tamaño, así que Leaflet no necesita invalidateSize() */
@media (min-width: 900px) {
  .sheet, .screen { left: 0; right: auto; width: 420px; transform: none; border-radius: 0; box-shadow: var(--shadow-float); }
  .sheet.peek, .sheet.full { top: 0; height: 100%; max-height: none; }
  .sheet.auto { border-radius: 0 var(--radius-sheet) 0 0; }
  .sheet-handle, [data-action="size"] { display: none; }
  .sheet-body { padding-top: 20px; }
  /* La barra y los puntos van a la derecha de la columna, para que el panel no los tape */
  .top-bar { left: 420px; margin: 0; max-width: 480px; }
  .side-buttons.lifted { bottom: calc(var(--safe-bottom) + 24px); }
}

.ticket:disabled { cursor: default; color: inherit; opacity: 1; }

/* hidden oculta un elemento aunque su clase le ponga display (.search-clear, .badge...) */
[hidden] { display: none !important; }
