/* eDiPAS-Rural — hoja de estilos del shell PWA.
   Criterios: WCAG 2.1 AA, alto contraste, textos legibles, objetivos táctiles
   grandes (interfaz simplificada para personas mayores, apartado 2.8 de la memoria). */

:root {
  --color-bg: #f7f3ec;
  --color-surface: #ffffff;
  --color-ink: #26211c;
  --color-ink-soft: #4c443b;
  --color-brand: #4a3f35;
  --color-accent: #8a5a2b;
  --color-accent-ink: #ffffff;
  --color-border: #d8cfc2;
  --color-focus: #1a5fb4;
  --radius: 10px;
  --shadow: 0 2px 8px rgba(38, 33, 28, 0.18);
  font-size: 17px; /* base ligeramente mayor para legibilidad */
}

* { box-sizing: border-box; }

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

body {
  display: flex;
  flex-direction: column;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--color-bg);
  color: var(--color-ink);
  line-height: 1.5;
}

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

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--color-focus);
  color: #fff;
  padding: 0.6rem 1rem;
  z-index: 3000;
}
.skip-link:focus { left: 0; }

/* ---------- Cabecera ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.5rem 1rem;
  background: var(--color-brand);
  color: #fff;
}

.brand { display: flex; align-items: center; gap: 0.6rem; min-width: 0; }
.brand img { background: #fff; border-radius: 8px; padding: 2px; }
.brand-text h1 { margin: 0; font-size: 1.15rem; line-height: 1.2; }
.brand-text p { margin: 0; font-size: 0.8rem; opacity: 0.9; }

.header-actions { display: flex; align-items: center; gap: 0.5rem; }

.btn {
  min-height: 44px; /* objetivo táctil AA */
  min-width: 44px;
  padding: 0.45rem 0.9rem;
  border-radius: var(--radius);
  border: 2px solid transparent;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-secondary {
  background: #fff;
  color: var(--color-brand);
  border-color: #fff;
}
.btn-secondary:hover { background: #efe8dd; }

.badge {
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 700;
}
.badge-offline { background: #b3261e; color: #fff; }

/* Selector de idioma [ES | EN]: el activo queda resaltado. */
.lang-switch {
  display: inline-flex;
  border: 2px solid #fff;
  border-radius: var(--radius);
  overflow: hidden;
}
.lang-switch button {
  min-height: 40px;
  min-width: 44px;
  padding: 0.3rem 0.7rem;
  border: none;
  background: transparent;
  color: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.lang-switch button.active {
  background: #fff;
  color: var(--color-brand);
}

/* ---------- Distribución principal ---------- */
.app-main {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr minmax(300px, 380px);
  min-height: 0;
  position: relative;
}

#map { min-height: 0; height: 100%; z-index: 0; }

.panel {
  background: var(--color-surface);
  border-left: 1px solid var(--color-border);
  padding: 1rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.panel h2 { margin: 0 0 0.25rem; font-size: 1.1rem; }
.panel-count { margin: 0 0 0.75rem; color: var(--color-ink-soft); font-size: 0.9rem; }

.poi-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  flex: 1;
}

.poi-card {
  width: 100%;
  text-align: left;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.75rem 0.9rem;
  cursor: pointer;
  font: inherit;
  color: inherit;
}
.poi-card:hover { border-color: var(--color-accent); background: #f1e9dc; }
.poi-card strong { display: block; font-size: 1rem; }
.poi-card span { color: var(--color-ink-soft); font-size: 0.85rem; }

.panel-footer {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--color-border);
}
.panel-footer h3 { margin: 0 0 0.4rem; font-size: 0.95rem; }

.export-links { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.export-links a {
  display: inline-block;
  padding: 0.4rem 0.8rem;
  min-height: 44px;
  line-height: 1.9;
  border-radius: var(--radius);
  background: var(--color-accent);
  color: var(--color-accent-ink);
  text-decoration: none;
  font-weight: 700;
}
.export-links a:hover { background: #6f4820; }

.license { font-size: 0.8rem; color: var(--color-ink-soft); margin: 0.5rem 0 0; }

/* ---------- Ficha de detalle ---------- */
.detail {
  position: absolute;
  inset: 0;
  z-index: 1200;
  background: var(--color-surface);
  overflow-y: auto;
  padding: 1rem clamp(1rem, 4vw, 2.5rem) 2rem;
}

.btn-back {
  background: var(--color-brand);
  color: #fff;
  margin-bottom: 1rem;
}
.btn-back:hover { background: #372f27; }

.detail h2 { margin: 0 0 0.25rem; font-size: 1.5rem; }

.detail .meta-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.5rem 0 1rem;
  padding: 0;
  list-style: none;
}
.meta-chips li {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  padding: 0.25rem 0.7rem;
  font-size: 0.85rem;
}

.detail section { margin-bottom: 1.25rem; }
.detail section > h3 {
  margin: 0 0 0.4rem;
  font-size: 1.05rem;
  color: var(--color-accent);
  border-bottom: 2px solid var(--color-border);
  padding-bottom: 0.25rem;
}

.stone-table {
  width: 100%;
  border-collapse: collapse;
}
.stone-table th, .stone-table td {
  text-align: left;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--color-border);
  vertical-align: top;
}
.stone-table th { background: var(--color-bg); width: 38%; }

.detail-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; }
.btn-primary {
  background: var(--color-accent);
  color: var(--color-accent-ink);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}
.btn-primary:hover { background: #6f4820; }

.notice {
  background: #fdf3d7;
  border: 1px solid #d9b95c;
  border-radius: var(--radius);
  padding: 0.6rem 0.9rem;
  font-size: 0.9rem;
}

/* ---------- Vista previa en el mapa (popup) ---------- */
.poi-preview { font-size: 0.95rem; line-height: 1.45; }
.poi-preview .pv-name { margin: 0 0 0.15rem; font-size: 1.05rem; color: var(--color-ink); }
.poi-preview .pv-place { margin: 0 0 0.4rem; color: var(--color-ink-soft); font-size: 0.85rem; }
.poi-preview .pv-summary { margin: 0 0 0.45rem; font-style: italic; }
.poi-preview .pv-fact { margin: 0 0 0.25rem; font-size: 0.88rem; }
.poi-preview .pv-more {
  display: inline-block;
  margin-top: 0.4rem;
  padding: 0.35rem 0.75rem;
  background: var(--color-accent);
  color: var(--color-accent-ink);
  border-radius: var(--radius);
  text-decoration: none;
  font-weight: 700;
}
.poi-preview .pv-more:hover { background: #6f4820; }

/* ---------- Capa GPS (mi ubicación) ---------- */
.locate-btn {
  width: 44px;
  height: 44px;
  background: #fff;
  border: 2px solid rgba(0, 0, 0, 0.25);
  border-radius: 6px;
  font-size: 1.25rem;
  cursor: pointer;
  line-height: 1;
}
.locate-btn:hover { background: #f1e9dc; }
.locate-btn.active {
  background: var(--color-focus);
  border-color: var(--color-focus);
}

#locate-toast {
  position: absolute;
  left: 50%;
  bottom: 1.25rem;
  transform: translateX(-50%);
  z-index: 1100;
  background: var(--color-ink);
  color: #fff;
  padding: 0.6rem 1rem;
  border-radius: var(--radius);
  max-width: min(90%, 30rem);
  font-size: 0.95rem;
  box-shadow: var(--shadow);
}
#locate-toast[hidden] { display: none; }

/* ---------- Banner de cookies ---------- */
.cookie-banner {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 3000;
  background: var(--color-ink);
  color: #fff;
  padding: 0.9rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
  box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.3);
}
.cookie-banner p { margin: 0; max-width: 48rem; }
.cookie-banner a { color: #fff; }
.cookie-actions { display: flex; gap: 0.6rem; }

/* ---------- Foto en aportaciones ---------- */
.comment-photo {
  display: block;
  margin-top: 0.5rem;
  max-height: 180px;
  max-width: 100%;
  border-radius: 8px;
  border: 1px solid var(--color-border);
}
.consent-link { margin: 0; font-size: 0.9rem; }

/* ---------- Enlaces legales del pie ---------- */
.footer-legal { margin: 0.15rem 0 0 !important; }
.footer-legal a { color: #fff; }

/* ---------- Galería de fotografías ---------- */
.photo-gallery {
  display: flex;
  gap: 0.75rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
  margin: 0.75rem 0 1rem;
}
.photo-gallery figure {
  margin: 0;
  flex: 0 0 auto;
  max-width: min(320px, 80vw);
}
.photo-gallery img {
  display: block;
  height: 210px;
  max-width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  object-fit: cover;
}
.photo-gallery figcaption {
  font-size: 0.85rem;
  color: var(--color-ink-soft);
  padding-top: 0.25rem;
}
.photo-gallery .credit { font-style: italic; }

/* Las imágenes de la galería se amplían al pulsarlas */
.photo-zoom {
  display: block;
  border: none;
  padding: 0;
  background: none;
  cursor: zoom-in;
}

/* ---------- Visor de fotografías (lightbox) ---------- */
#lightbox {
  position: fixed;
  inset: 0;
  z-index: 4000;
  background: rgba(24, 19, 15, 0.93);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
#lightbox[hidden] { display: none; }
#lightbox figure {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  max-width: 92vw;
}
.lb-img {
  max-width: 92vw;
  max-height: 78vh;
  object-fit: contain;
  border-radius: 8px;
}
.lb-caption {
  color: #fff;
  font-size: 0.95rem;
  text-align: center;
  max-width: 80vw;
}
.lb-close, .lb-prev, .lb-next {
  position: absolute;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.55);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}
.lb-close:hover, .lb-prev:hover, .lb-next:hover { background: rgba(255, 255, 255, 0.28); }
.lb-close { top: 1rem; right: 1rem; }
.lb-prev { left: 0.75rem; top: 50%; transform: translateY(-50%); }
.lb-next { right: 0.75rem; top: 50%; transform: translateY(-50%); }

/* Miniatura en la vista previa del mapa */
.pv-photo {
  width: 100%;
  height: 120px;
  object-fit: cover;
  border-radius: 8px;
  margin-bottom: 0.4rem;
}

/* ---------- IA geoespacial (entorno cercano) ---------- */
.nearby-intro { color: var(--color-ink-soft); }

.nearby-wait {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 600;
  margin: 0.5rem 0 0.25rem;
}
.nearby-wait-note {
  margin: 0 0 0.5rem;
  font-size: 0.85rem;
  color: var(--color-ink-soft);
}
.spinner {
  width: 1.15em;
  height: 1.15em;
  flex: 0 0 auto;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: edipas-spin 0.9s linear infinite;
}
@keyframes edipas-spin { to { transform: rotate(360deg); } }
/* Con animaciones reducidas, el spinner queda estático pero los mensajes
   rotatorios siguen indicando progreso. */
.nearby-summary { font-style: italic; }
.nearby-cat { margin: 0.9rem 0 0.35rem; font-size: 1rem; }
.nearby-list { margin: 0 0 0.5rem; padding-left: 1.2rem; }
.nearby-list li { margin-bottom: 0.35rem; }
.nearby-list a { color: var(--color-accent); font-weight: 700; text-decoration: none; }
.nearby-list a:hover { text-decoration: underline; }
.nearby-disclaimer {
  margin-top: 0.75rem;
  font-size: 0.8rem;
  color: var(--color-ink-soft);
  border-top: 1px dashed var(--color-border);
  padding-top: 0.5rem;
}

/* ---------- Aportaciones ciudadanas ---------- */
.comment-list {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.comment-item {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.7rem 0.9rem;
}
.comment-item time { color: var(--color-ink-soft); font-size: 0.85rem; margin-left: 0.4rem; }
.comment-item p { margin: 0.35rem 0 0; }

.comment-empty { color: var(--color-ink-soft); }

#comment-form { display: flex; flex-direction: column; gap: 0.45rem; max-width: 40rem; }
#comment-form label { font-weight: 600; }
.demo-fields {
  background: var(--color-bg);
  border: 1px dashed var(--color-border);
  border-radius: var(--radius);
  padding: 0.6rem 0.8rem;
}
.demo-note { margin: 0 0 0.5rem; font-size: 0.85rem; color: var(--color-ink-soft); }
.demo-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }
@media (max-width: 480px) { .demo-grid { grid-template-columns: 1fr; } }
#comment-form select {
  width: 100%;
  font: inherit;
  padding: 0.5rem 0.6rem;
  border: 2px solid var(--color-border);
  border-radius: var(--radius);
  background: #fff;
  color: inherit;
}
#comment-form select:focus { border-color: var(--color-focus); outline: none; }

#comment-form input,
#comment-form textarea {
  font: inherit;
  padding: 0.55rem 0.7rem;
  border: 2px solid var(--color-border);
  border-radius: var(--radius);
  background: #fff;
  color: inherit;
}
#comment-form input:focus,
#comment-form textarea:focus { border-color: var(--color-focus); outline: none; }
#comment-form button { align-self: flex-start; margin-top: 0.35rem; }

.comment-feedback { min-height: 1.4em; font-weight: 600; margin: 0.25rem 0 0; }

/* Campo trampa (honeypot): invisible para personas, presente para bots. */
.hp-field {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
  margin: 0;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-weight: 600;
  cursor: pointer;
}
.check-row input[type="checkbox"] {
  width: 1.35rem;
  height: 1.35rem;
  accent-color: var(--color-accent);
}

/* ---------- Pie ---------- */
.app-footer {
  background: var(--color-brand);
  color: #fff;
  text-align: center;
  padding: 0.35rem 1rem;
}
.app-footer p { margin: 0; font-size: 0.8rem; opacity: 0.9; }

/* ---------- Móvil ---------- */
@media (max-width: 820px) {
  .app-main {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(45vh, 1fr) minmax(200px, 40vh);
  }
  .panel { border-left: none; border-top: 1px solid var(--color-border); }
  .brand-text p { display: none; }
}

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