:root {
  --rojo: #ce1126;
  --azul: #0a3161;
  --blanco: #ffffff;
  --fondo: #f4f6fa;
  --texto: #1c2430;
  --gris: #6b7686;
  --borde: #dbe2ec;
  --radio: 14px;
  --header-h: 76px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--fondo);
  color: var(--texto);
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  min-height: 100vh;
}

/* Encabezado */
.app-header {
  position: sticky; top: 0; z-index: 500;
  display: flex; align-items: center; gap: 12px;
  min-height: var(--header-h);
  padding: 10px 14px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: linear-gradient(135deg, var(--azul) 0%, #123f7d 60%, var(--rojo) 140%);
  color: var(--blanco);
  box-shadow: 0 2px 8px rgba(0,0,0,.18);
}
.logo { width: 52px; height: 52px; border-radius: 14px; background: #fff; flex: none; }
.brand { flex: 1; min-width: 0; }
.brand h1 { margin: 0; font-size: 1.35rem; letter-spacing: .5px; }
.slogan { margin: 2px 0 0; font-size: .78rem; line-height: 1.25; opacity: .95; }
.slogan span { display: block; }

/* Botones */
.btn {
  border: none; border-radius: 12px; cursor: pointer;
  font-size: 1rem; padding: 12px 16px; min-height: 48px;
  touch-action: manipulation;
}
.btn-primary { background: var(--rojo); color: #fff; font-weight: 700; }
.btn-primary:active { filter: brightness(.92); }
.btn-ghost { background: rgba(255,255,255,.16); color: #fff; }
main .btn-ghost { background: #e8edf5; color: var(--azul); }
.btn-danger { background: #fff; color: var(--rojo); border: 1px solid var(--rojo); }
.btn-block { width: 100%; margin-top: 10px; }

/* Vistas */
.view { padding: 14px 14px 90px; max-width: 720px; margin: 0 auto; }

/* Buscador y filtros */
.search-bar input {
  width: 100%; font-size: 1.05rem; padding: 13px 14px;
  border: 1px solid var(--borde); border-radius: var(--radio); background: #fff;
}
.filters { display: flex; gap: 8px; margin: 10px 0; flex-wrap: wrap; }
.filters select {
  flex: 1; min-width: 140px; font-size: .95rem; padding: 12px 10px; min-height: 48px;
  border: 1px solid var(--borde); border-radius: var(--radio); background: #fff;
}

/* Pestañas */
.tabs { display: flex; gap: 8px; margin: 4px 0 12px; }
.tab {
  flex: 1; padding: 12px; min-height: 48px; font-size: 1rem; font-weight: 600;
  border: 1px solid var(--borde); border-radius: var(--radio); background: #fff; color: var(--gris);
}
.tab.active { background: var(--azul); color: #fff; border-color: var(--azul); }

/* Tarjetas */
.cards { display: grid; gap: 12px; }
.card {
  background: #fff; border: 1px solid var(--borde); border-radius: var(--radio);
  padding: 14px; cursor: pointer;
}
.card h3 { margin: 0 0 4px; font-size: 1.08rem; color: var(--azul); }
.card .meta { font-size: .88rem; color: var(--gris); margin: 2px 0; }
.card .cat {
  display: inline-block; font-size: .75rem; font-weight: 700; color: var(--rojo);
  background: #fdeef0; border-radius: 999px; padding: 3px 10px; margin-bottom: 6px;
}
.card img.cover { width: 100%; height: 170px; object-fit: cover; border-radius: 10px; margin-bottom: 8px; }
.empty { text-align: center; color: var(--gris); padding: 40px 10px; }

/* Mapa */
#map { height: 62vh; min-height: 380px; border-radius: var(--radio); border: 1px solid var(--borde); background: #e5e9f0; z-index: 1; }
.map-error {
  text-align: center; color: var(--gris); background: #fff;
  border: 1px dashed var(--borde); border-radius: var(--radio); padding: 26px; margin-top: 10px;
}

/* Ficha */
.detail { background: #fff; border: 1px solid var(--borde); border-radius: var(--radio); padding: 16px; }
.detail h2 { margin: 0 0 6px; color: var(--azul); }
.detail .meta { color: var(--gris); font-size: .92rem; margin: 3px 0; }
.detail .desc { margin: 12px 0; line-height: 1.5; white-space: pre-wrap; }
.gallery { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 10px 0; }
.gallery img { width: 100%; height: 150px; object-fit: cover; border-radius: 10px; }
.gallery img.portada { grid-column: 1 / -1; height: 220px; }
.owner-actions { display: flex; gap: 8px; margin-top: 14px; }
.owner-actions .btn { flex: 1; }
#detail-map { height: 240px; border-radius: var(--radio); border: 1px solid var(--borde); margin-top: 12px; z-index: 1; }
.contact-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.contact-row a.btn { text-decoration: none; display: inline-block; text-align: center; }

/* Formularios */
.form { display: grid; gap: 12px; background: #fff; border: 1px solid var(--borde); border-radius: var(--radio); padding: 16px; }
.form label { display: grid; gap: 6px; font-size: .92rem; font-weight: 600; color: var(--azul); }
.form input, .form select, .form textarea {
  font-size: 1rem; padding: 12px; min-height: 48px;
  border: 1px solid var(--borde); border-radius: 10px; width: 100%; font-weight: 400; color: var(--texto);
  font-family: inherit;
}
.form textarea { min-height: 0; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.error { color: var(--rojo); font-size: .9rem; margin: 0; }
h2 { color: var(--azul); }

/* Toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(24px + env(safe-area-inset-bottom));
  background: #222; color: #fff; padding: 12px 18px; border-radius: 999px;
  font-size: .95rem; z-index: 1000; box-shadow: 0 4px 14px rgba(0,0,0,.3);
  max-width: 90vw; text-align: center;
}

@media (min-width: 720px) {
  .gallery { grid-template-columns: repeat(4, 1fr); }
  .brand h1 { font-size: 1.6rem; }
}

/* Usuarios conectados */
.online-badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: .85rem; font-weight: 600; color: #fff;
  background: rgba(255,255,255,.15); border-radius: 999px; padding: 4px 10px;
  white-space: nowrap;
}
.online-badge .dot {
  width: 8px; height: 8px; border-radius: 50%; background: #4caf50;
  box-shadow: 0 0 6px #4caf50;
}

/* Social: me gusta / seguir */
.social-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
.vote-btn, .follow-btn {
  border: 1px solid #ddd; background: #fff; border-radius: 999px;
  padding: 8px 14px; font-size: 1rem; cursor: pointer; font-family: inherit;
}
.vote-btn:active, .follow-btn:active { transform: scale(.96); }
.vote-btn.active { background: #e3f2fd; border-color: #0a3161; }
.follow-btn.active { background: #e8f5e9; border-color: #2e7d32; color: #2e7d32; font-weight: 700; }

.ok { color: #2e7d32; font-size: .9rem; margin: 0; }

/* Modal de conectados */
.modal {
  position: fixed; inset: 0; z-index: 2000;
  background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal[hidden] { display: none; }
.modal-box {
  background: #fff; border-radius: 12px; padding: 20px;
  max-width: 360px; width: 100%; max-height: 70vh; overflow-y: auto;
}
.modal-box h3 { margin: 0 0 12px; color: var(--azul); }
.online-list { list-style: none; margin: 0 0 16px; padding: 0; }
.online-list li {
  padding: 8px 0; border-bottom: 1px solid #eee; font-size: .95rem;
}
.online-list li:last-child { border-bottom: none; }
.online-list .contact { color: #888; font-size: .8rem; }
#online-badge { cursor: pointer; }

.user-link {
  background: none; border: none; padding: 0; margin: 0;
  font: inherit; color: var(--azul); cursor: pointer; text-align: left; width: 100%;
}
.user-link:active { opacity: .6; }
.activity-title { font-weight: 700; color: var(--azul); margin-top: 8px; }
.activity-back { border-bottom: 2px solid #eee; margin-bottom: 4px; }

/* Banner de video promocional */
.promo-banner {
  position: relative; margin: 0 0 12px; border-radius: 12px; overflow: hidden;
  background: #000;
}
.promo-banner video { width: 100%; display: block; max-height: 420px; }
.promo-close {
  position: absolute; top: 8px; right: 8px; z-index: 2;
  width: 32px; height: 32px; border-radius: 50%; border: none;
  background: rgba(0,0,0,.6); color: #fff; font-size: 1.2rem; cursor: pointer;
}

/* Widget de chat del asistente */
.chat-fab {
  position: fixed; bottom: 20px; right: 20px; z-index: 200;
  width: 56px; height: 56px; border-radius: 50%; border: none;
  background: #d42a2a; font-size: 1.6rem; cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,.3);
}
.chat-panel {
  position: fixed; bottom: 88px; right: 20px; z-index: 200;
  width: min(340px, calc(100vw - 40px)); height: 440px; max-height: 60vh;
  display: flex; flex-direction: column;
  background: #fff; border-radius: 14px; overflow: hidden;
  box-shadow: 0 8px 28px rgba(0,0,0,.3);
}
.chat-head {
  background: #d42a2a; color: #fff; padding: 12px 14px;
  display: flex; justify-content: space-between; align-items: center;
  font-weight: 600;
}
.chat-x { background: none; border: none; color: #fff; font-size: 1.4rem; cursor: pointer; }
.chat-body { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; background: #f7f7f7; }
.chat-msg { max-width: 85%; padding: 9px 12px; border-radius: 12px; font-size: .92rem; line-height: 1.4; white-space: pre-line; }
.chat-msg.bot { background: #fff; border: 1px solid #e0e0e0; align-self: flex-start; border-bottom-left-radius: 4px; }
.chat-msg.user { background: #d42a2a; color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.chat-msg.typing { color: #888; font-style: italic; }
.chat-input-row { display: flex; gap: 8px; padding: 10px; background: #fff; border-top: 1px solid #eee; }
.chat-input-row input { flex: 1; border: 1px solid #ddd; border-radius: 20px; padding: 9px 14px; font-size: .92rem; outline: none; }
#chat-send { width: 40px; height: 40px; border-radius: 50%; border: none; background: #d42a2a; color: #fff; font-size: 1rem; cursor: pointer; }

.chat-backdrop {
  position: fixed; inset: 0; z-index: 199;
  background: rgba(0,0,0,.25);
}
.chat-panel { z-index: 200; }
.chat-x {
  min-width: 44px; min-height: 44px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.6rem;
}

/* El atributo hidden debe imponerse sobre display:flex */
.chat-panel[hidden], .chat-backdrop[hidden], #promo-banner[hidden] { display: none !important; }
