/* ---------------------------------------------------------
   VIBRA · sistema visual
   Base neutra oscura + degradado atardecer SOLO como acento.
   (Auditoria de marca, correccion 2: nada de degradado en todo.)
   --------------------------------------------------------- */

/* Auto-alojada (no Google Fonts en directo) para no depender de un origen
   externo en tiempo real ni tener que abrir font-src en el CSP (ver
   server/index.js) - solo subset "latin" (cubre acentos/ñ del español),
   variable en un unico archivo para los pesos 400-800. */
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 400 800;
  font-display: swap;
  src: url('/fonts/Inter-Variable.woff2') format('woff2');
}

:root {
  --bg: #1C191C;
  --surface: #241F25;
  --surface-2: #2C262E;

  /* Tarjetas claras del wireframe sobre fondo oscuro. */
  --panel: #C9D2E2;
  --panel-ink: #23262E;
  --line: rgba(243, 239, 247, 0.10);
  --line-strong: rgba(243, 239, 247, 0.18);
  --ink: #F3EFF7;
  --muted: #A79FB3;
  --faint: #6E6878;

  --orange: #F0A468;
  --pink: #FF6B93;
  --purple: #A78BFA;
  --blue: #7C9BF0;
  --sunset: linear-gradient(100deg, var(--orange) 0%, var(--pink) 42%, var(--purple) 78%, var(--blue) 100%);

  /* Semanticos: separados del acento de marca. */
  --ok: #46C79A;
  --warn: #E8B44D;
  --danger: #F2545B;
  --safety: #4CC8CE;

  --radius: 14px;
  --radius-sm: 9px;
  --tap: 44px;

  /* Se mantiene aparte del cuerpo a proposito: es lo que le da a VIBRA su
     toque "app amigable" en titulares/logo, no es una fuente generica del
     navegador como si lo era --font-body. */
  --font-display: ui-rounded, "SF Pro Rounded", "Segoe UI Variable Display", "Segoe UI", system-ui, sans-serif;
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-data: "Cascadia Code", Consolas, ui-monospace, monospace;

  /* Fondo semitransparente de la barra inferior/cabecera con blur -- variable
     aparte (no --surface) porque necesita su propia opacidad por tema. */
  --chrome-bg: rgba(20, 18, 24, 0.96);
}

/* ---------------- tema claro ----------------
   Los colores de marca (acentos, degradado atardecer, semanticos) se quedan
   igual en los dos temas a proposito: es la identidad de VIBRA, no cambia
   con el tema. Solo se invierten los neutros (fondo/superficie/texto). */
[data-theme="light"] {
  --bg: #FAF9FB;
  --surface: #FFFFFF;
  --surface-2: #F1EFF5;

  --panel: #E3E8F5;
  --panel-ink: #23262E;
  --line: rgba(28, 25, 32, 0.10);
  --line-strong: rgba(28, 25, 32, 0.18);
  --ink: #1C191C;
  --muted: #635C6B;
  --faint: #948FA0;

  --chrome-bg: rgba(255, 255, 255, 0.92);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--purple); }

/* Iconos SVG en linea (ver public/js/icons.js): tamano por defecto a juego
   con el texto que los acompana, heredan color via currentColor solos. */
.icon {
  width: 1.15em;
  height: 1.15em;
  display: inline-block;
  vertical-align: -0.18em;
  flex-shrink: 0;
}
/* Insignias pequenas de tamano fijo (ej. lapiz sobre el avatar), donde el
   contexto de font-size no da un tamano fiable via em. */
.icon-xs { width: 11px; height: 11px; vertical-align: middle; flex-shrink: 0; }

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

:focus-visible {
  outline: 2px solid var(--purple);
  outline-offset: 2px;
  border-radius: 6px;
}

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

/* ---------------- marca ---------------- */

.wordmark {
  font-family: var(--font-display);
  font-weight: 800;
  letter-spacing: 0.02em;
  background: var(--sunset);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  line-height: 1.05;
}

.eyebrow {
  font-family: var(--font-data);
  font-size: 0.68rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--faint);
}

/* ---------------- botones ---------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: var(--tap);
  padding: 0.6rem 1.3rem;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  color: var(--ink);
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.12s ease, border-color 0.12s ease;
}
.btn:hover { border-color: var(--purple); }
.btn:active { transform: scale(0.97); }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--sunset);
  border: none;
  color: #14101B;
  font-weight: 700;
}
.btn-primary:hover { filter: brightness(1.08); }

.btn-ghost { background: transparent; }
.btn-danger { border-color: rgba(242, 84, 91, 0.5); color: var(--danger); background: rgba(242, 84, 91, 0.08); }
.btn-block { width: 100%; }
.btn-sm { min-height: 34px; padding: 0.3rem 0.85rem; font-size: 0.85rem; }

/* ---------------- formularios ---------------- */

.field { display: flex; flex-direction: column; gap: 0.35rem; }
.field label { font-size: 0.8rem; color: var(--muted); font-weight: 600; }
.input, .select, .textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 0.6rem 0.85rem;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--ink);
}
.textarea { min-height: 84px; resize: vertical; }
.input::placeholder, .textarea::placeholder { color: var(--faint); }
.input:focus, .select:focus, .textarea:focus { border-color: var(--purple); outline: none; }

/* ---------------- chips ---------------- */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.18rem 0.65rem;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--line);
  white-space: nowrap;
}
.chip-ok { color: var(--ok); border-color: rgba(70, 199, 154, 0.35); background: rgba(70, 199, 154, 0.10); }
.chip-warn { color: var(--warn); border-color: rgba(232, 180, 77, 0.35); background: rgba(232, 180, 77, 0.10); }
.chip-danger { color: var(--danger); border-color: rgba(242, 84, 91, 0.35); background: rgba(242, 84, 91, 0.10); }
.chip-safety { color: var(--safety); border-color: rgba(76, 200, 206, 0.35); background: rgba(76, 200, 206, 0.10); }

.verified-badge { vertical-align: -3px; margin-left: 2px; flex-shrink: 0; }
.verified-pro { display: inline-grid; place-items: center; width: 18px; height: 18px; background: var(--sunset); border-radius: 50%; clip-path: polygon(50% 0%, 61% 15%, 79% 9%, 85% 26%, 100% 34%, 93% 50%, 100% 66%, 85% 74%, 79% 91%, 61% 85%, 50% 100%, 39% 85%, 21% 91%, 15% 74%, 0% 66%, 7% 50%, 0% 34%, 15% 26%, 21% 9%, 39% 15%); }
.verified-pro svg { width: 10px; height: 10px; stroke: #fff; stroke-width: 3; fill: none; }
.chip-accent { color: var(--purple); border-color: rgba(167, 139, 250, 0.35); background: rgba(167, 139, 250, 0.10); }

/* ---------------- avisos ---------------- */

.toast-host {
  position: fixed;
  left: 50%;
  bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 90;
  width: min(420px, calc(100vw - 32px));
}
.toast {
  padding: 0.7rem 1rem;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  font-size: 0.9rem;
  animation: toast-in 0.2s ease;
}
.toast-ok { border-left: 3px solid var(--ok); }
.toast-err { border-left: 3px solid var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------------- popup enriquecido del mapa ---------------- */
/* A proposito claro/blanco, no oscuro como el resto de la app: la portada
   del plan es la protagonista, y un recuadro negro encima de la foto
   quedaba plano. Colores fijos (no var(--ink)/var(--surface)) porque esta
   tarjeta no cambia con el tema oscuro del resto de la app. */
.rich-plan-popup {
  width: 260px;
  overflow: hidden;
  border-radius: 20px;
  background: #fff;
}
.popup-media-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.2rem;
  background: #f0f0f0;
}

.rich-plan-popup-list {
  width: 270px;
  padding: 0.9rem;
  max-height: 320px;
  overflow-y: auto;
  background: #fff;
  color: #1a1a1a;
}
.rich-plan-popup-list h4 { color: #14101B; }
.popup-list-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0;
  border-top: 1px solid #eee;
  cursor: pointer;
}
.popup-list-row:first-of-type { border-top: none; }
.popup-list-row .muted { color: #777; }
.popup-list-thumb {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  flex-shrink: 0;
  font-size: 1.2rem;
}
.maplibregl-popup-content:has(.rich-plan-popup) {
  padding: 0;
  border-radius: 20px;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.25), 0 0 0 1px rgba(255,255,255,0.08);
}
.maplibregl-popup-tip { display: none; }

/* ---------------- tarjeta del plan (bottom sheet, al tocar un pin) ---------------- */
/* Igual que .rich-plan-popup: claro/blanco a proposito, no hereda el tema
   oscuro. Emerge desde abajo como .sheet, pero con su propia mecanica (no
   openSheet/#sheet-host) porque su estetica es fija, no la del resto de hojas. */
.pin-card-backdrop {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(6, 5, 9, 0.75);
  display: flex; align-items: flex-end; justify-content: center;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s ease;
}
.pin-card-backdrop.open { opacity: 1; pointer-events: auto; }
.pin-card {
  position: relative;
  width: min(480px, 100%);
  /* dvh, no vh: en movil con la barra de direcciones visible, 88vh se mide
     contra el viewport "grande" (como si estuviera oculta) y deja la
     tarjeta mas alta que el hueco real, cortando el CTA de abajo. */
  max-height: 88dvh;
  overflow-y: auto;
  background: #fff; color: #1a1a1a;
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.4);
  transform: translateY(100%);
  transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}
.pin-card-backdrop.open .pin-card { transform: translateY(0); }
.pin-card-media {
  width: 100%;
  height: 170px;
  object-fit: cover;
  display: block;
  border-radius: 24px 24px 0 0;
}
.pin-card-close {
  position: absolute; top: 12px; right: 12px; z-index: 1;
  width: 32px; height: 32px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.92); border: none; color: #14101B;
  font-size: 1rem; cursor: pointer;
  display: grid; place-items: center;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.22);
}
.pin-card-body { padding: 1.1rem 1.2rem 1.4rem; }
/* Serifa a proposito (unica excepcion tipografica del sistema, ver arriba):
   es lo que le da el toque elegante a esta tarjeta en concreto. */
.pin-card-title {
  font-family: Georgia, "Iowan Old Style", "Times New Roman", serif;
  font-size: 1.45rem;
  font-weight: 700;
  color: #14101B;
  line-height: 1.25;
  margin: 0 0 0.75rem;
}
.pin-card-creator { display: flex; align-items: center; gap: 0.55rem; margin-bottom: 0.7rem; }
.pin-card-creator .avatar {
  width: 32px; height: 32px;
  background: #f0f0f0; border-color: #e6e6e6; color: #14101B;
}
.pin-card-creator span { font-size: 0.86rem; color: #333; }
.pin-card-desc { font-size: 0.92rem; line-height: 1.5; color: #444; margin: 0 0 1.15rem; }
.pin-card-cta {
  display: block; width: 100%; box-sizing: border-box;
  text-align: center; text-decoration: none;
  background: #111; color: #fff; border: none; border-radius: 999px;
  padding: 0.95rem 1rem; margin-top: 0.6rem;
  font-weight: 700; font-size: 0.82rem;
  text-transform: uppercase; letter-spacing: 0.03em;
  cursor: pointer; transition: transform 0.12s ease, filter 0.12s ease;
}
.pin-card-cta:hover { filter: brightness(1.25); }
.pin-card-cta:active { transform: scale(0.98); }
.pin-card-cta:disabled { opacity: 0.5; cursor: not-allowed; }
.pin-card-cta-secondary {
  background: transparent; color: #14101B; border: 1.5px solid #ddd;
}
.pin-card-cta-secondary:hover { filter: none; background: #f7f7f7; }

/* ---------------- utilidades ---------------- */

.stack { display: flex; flex-direction: column; gap: 1rem; }
.row { display: flex; align-items: center; gap: 0.6rem; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.center { text-align: center; }
.hidden { display: none !important; }
.tabular { font-variant-numeric: tabular-nums; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--surface-2); border: 1px solid var(--line);
  display: grid; place-items: center; font-weight: 700; font-size: 0.85rem;
  color: var(--purple); flex-shrink: 0; overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }

.empty {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--muted);
  border: none;
  border-radius: 0;
}
.empty strong { display: block; color: var(--ink); margin-bottom: 0.3rem; font-family: var(--font-display); }

/* ---------------- messages redesign ---------------- */
.msg-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 0.5rem;
  margin-bottom: 0.9rem;
}
.msg-title {
  font-family: var(--font-display);
  font-size: 1.5rem;
  margin: 0;
  color: var(--ink);
}
.msg-filter-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--muted);
  display: grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
}
.msg-filter-btn:active { transform: scale(0.92); }

.msg-tabs {
  display: flex;
  gap: 0.6rem;
  padding: 0 0.5rem;
  margin-bottom: 1.2rem;
}
.msg-tab {
  flex: 1;
  border-radius: 50px;
  border: none;
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  font-size: 0.85rem;
  cursor: pointer;
}
.msg-tab[aria-pressed="true"] {
  background: linear-gradient(90deg, #9B51E0, #F2994A);
  color: #fff;
}

.msg-filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 0.9rem;
}
.mf-section-title {
  font-family: var(--font-data);
  font-size: 0.68rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--faint);
  margin: 1rem 0 0.5rem;
}
.mf-section-title:first-of-type { margin-top: 0.6rem; }

.chat-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: #C9D2E2; /* Light gray-blue from mockup */
  border-radius: 20px;
  padding: 1rem;
  border: none;
  width: 100%;
  cursor: pointer;
  transition: transform 0.1s;
}
.chat-card:active {
  transform: scale(0.98);
}
.chat-avatar {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  background: #6E6878; /* Dark gray from mockup */
  flex-shrink: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  color: #fff;
  font-weight: bold;
}
.chat-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.chat-content {
  flex: 1;
  min-width: 0;
  text-align: left;
  color: #111;
}
.chat-content h3 {
  margin: 0 0 0.2rem 0;
  font-size: 1.1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-content p {
  margin: 0;
  font-size: 0.9rem;
  color: #444;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Map Pins */
.pin-me {
  width: 18px;
  height: 18px;
  background: var(--primary);
  border: 3px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(255,59,92,0.3), 0 2px 4px rgba(0,0,0,0.2);
}

.pin-friend {
  display: flex;
  flex-direction: column;
  align-items: center;
  transform: translateY(-50%);
  cursor: pointer;
}
.pin-friend-label {
  background: rgba(0,0,0,0.8);
  color: #fff;
  padding: 4px 8px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  margin-bottom: 4px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
  display: flex;
  flex-direction: column;
  align-items: center;
  white-space: nowrap;
}
.pin-friend-label small {
  font-size: 0.6rem;
  opacity: 0.8;
  font-weight: 400;
}
.pin-friend-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid var(--primary);
  overflow: hidden;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}
.pin-friend-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.pin-friend-avatar-fallback {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-2);
}

.pin-venue {
  display: flex;
  flex-direction: column;
  align-items: center;
  transform: translateY(-50%);
  cursor: pointer;
}
.pin-venue-dot {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--pink), var(--purple));
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  border: 2px solid #fff;
  box-shadow: 0 4px 12px rgba(255,107,147,0.4);
  margin-bottom: 4px;
}

/* Patrocinado/sistema pero NO sync de Ticketmaster (cuenta VIBRA Oficial, o
   un enlace de venta propio de un admin/rrpp real): dorado, con entrada. */
.pin-venue-system .pin-venue-dot {
  background: var(--warn);
  box-shadow: 0 4px 12px rgba(232,180,77,0.45);
}

/* Sync automatico de Ticketmaster: azul, para no confundirlo con el
   contenido curado a mano de arriba. Color propio, sin usar su logo. */
.pin-venue-ticketmaster .pin-venue-dot {
  background: var(--blue);
  box-shadow: 0 4px 12px rgba(124,155,240,0.45);
}

/* Agenda de un ayuntamiento (ver server/madridOpenDataSync.js y
   server/barcelonaOpenDataSync.js) sin reclamar: turquesa, tercer color
   distinto de dorado/azul para no confundirlo con patrocinado ni con
   Ticketmaster. Mismo color para todos los ayuntamientos - lo que
   distingue de cual es cada uno es el texto de la ficha, no el color. */
.pin-venue-opendata .pin-venue-dot {
  background: var(--safety);
  box-shadow: 0 4px 12px rgba(76,200,206,0.45);
}

/* Un solo plan de una persona real: su avatar en vez del punto generico.
   Halo difuminado naranja/dorado (marca de "pin de creador") + un pequeño
   triángulo en la base que apunta a la coordenada exacta. El borde de color
   (morado normal / azul pro, ver mas abajo) se mantiene aparte del halo
   para no perder esa distinción de quién organiza. */
.pin-venue-avatar {
  position: relative;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid var(--purple);
  overflow: hidden;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
  box-shadow: 0 4px 12px rgba(167,139,250,0.4), 0 0 22px 7px rgba(240,164,104,0.38);
  margin-bottom: 4px;
}
.pin-venue-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.pin-venue-avatar::after {
  content: "";
  position: absolute;
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid rgba(20, 16, 27, 0.82);
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.25));
}

/* Cuenta profesional (pro/rrpp): mismo formato de avatar, borde azul para
   no confundirla ni con el sistema (dorado) ni con una persona normal (morado). */
.pin-venue-person-pro .pin-venue-avatar {
  border-color: var(--blue);
  box-shadow: 0 4px 12px rgba(124,155,240,0.4), 0 0 22px 7px rgba(240,164,104,0.38);
}
.pin-venue-label {
  background: #fff;
  color: #000;
  padding: 3px 8px;
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  max-width: 120px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---- Panel profesional: tiles centro de mando ---- */
.rrpp-tiles {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.rrpp-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  padding: 1rem 0.5rem;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface-2);
  cursor: pointer;
  color: var(--ink);
  transition: transform 0.1s, box-shadow 0.1s;
}
.rrpp-tile:active { transform: scale(0.95); }
.rrpp-tile-icon { font-size: 1.6rem; line-height: 1; }
.rrpp-tile-label { font-size: 0.78rem; font-weight: 600; text-align: center; }
