/* Canarias Convive — estilos del mapa de agentes.
   Extraído del monolito index.html para reducir su tamaño y permitir
   cacheado independiente. Cargado via <link> desde index.html. */

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: 'Montserrat', sans-serif; color: #323232; -webkit-font-smoothing: antialiased; }
#container { display: flex; height: 100vh; height: 100dvh; }
#sidebar {
  width: 380px;
  background: #FFFFFF;
  border-right: 1px solid #E8E8E8;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#map { flex: 1; position: relative; }

.sidebar-header { padding: 22px 24px 14px; }
.sidebar-header h1 {
  font-size: 18px; font-weight: 700; color: #0D4E47;
  letter-spacing: -0.3px;
}
.sidebar-header p { font-size: 12px; color: #5F6B68; margin-top: 2px; }

.sidebar-search {
  padding: 4px 24px 16px;
  background: #FFF;
  border-bottom: 1px solid #F0F0F0;
}
.search-input {
  width: 100%; padding: 11px 14px 11px 38px;
  border: 1px solid #E0E0E0; border-radius: 8px;
  font-family: inherit; font-size: 13px;
  background: url("data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23999' stroke-width='2'%3E%3Ccircle cx='7' cy='7' r='5'/%3E%3Cpath d='M11 11l3 3'/%3E%3C/svg%3E") no-repeat 12px center;
  background-size: 16px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.search-input:focus { outline: none; border-color: #0D4E47; box-shadow: 0 0 0 3px rgba(13,78,71,0.1); }

.controls {
  display: flex; gap: 6px;
  padding: 12px 24px;
  background: #FAFAFA; border-bottom: 1px solid #F0F0F0;
}
.controls button {
  flex: 1; padding: 8px; font-family: inherit; font-size: 12px; font-weight: 600;
  background: #FFF; border: 1px solid #E0E0E0; border-radius: 6px;
  cursor: pointer; color: #555; transition: all 0.15s;
}
.controls button:hover { border-color: #0D4E47; color: #0D4E47; }
.controls button.active {
  background: #0D4E47; color: #FFF; border-color: #0D4E47;
  box-shadow: 0 1px 3px rgba(13,78,71,0.3);
}

details.sector-filter {
  padding: 12px 24px;
  border-bottom: 1px solid #F0F0F0;
  background: #FAFAFA;
}
details.sector-filter summary {
  cursor: pointer; font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.8px; color: #666;
  user-select: none; list-style: none;
  display: flex; align-items: center; gap: 6px;
}
details.sector-filter summary::-webkit-details-marker { display: none; }
details.sector-filter summary::before { content: '▸'; transition: transform 0.2s; display: inline-block; font-size: 10px; }
details.sector-filter[open] summary::before { transform: rotate(90deg); }

.sector-pills { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.sector-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: 100px;
  font-size: 11px; font-weight: 600; color: #444;
  background: #FFF; border: 1px solid #E0E0E0;
  cursor: pointer; transition: all 0.15s;
  user-select: none;
}
.sector-pill:hover { border-color: var(--c, #0D4E47); }
.sector-pill.selected {
  border-color: var(--c, #0D4E47);
  background: var(--c, #0D4E47);
  color: #FFF;
}
.sector-pill .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--c, #0D4E47);
  box-shadow: 0 0 0 1px rgba(0,0,0,.1);
}
.sector-pill.selected .dot { background: #FFF; box-shadow: none; }
.sector-pill .count { font-size: 10px; opacity: 0.75; margin-left: 2px; }
/* Atenúa pills cuyo conteo facetado por filtros activos es 0. Sigue
   siendo clicable por si el usuario quiere combinar con su selección. */
.sector-pill.empty:not(.selected) { opacity: 0.4; }

.results-header {
  padding: 12px 24px 8px;
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.9px;
  color: #5F6B68; font-weight: 700;
  background: #FFF;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.results-header strong { color: #0D4E47; font-weight: 700; }
.btn-clear {
  background: transparent;
  border: 1px solid #C8D2CF;
  border-radius: 100px;
  padding: 4px 11px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: #0D4E47;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}
.btn-clear:hover, .btn-clear:focus-visible {
  background: #0D4E47;
  color: #FFF;
  border-color: #0D4E47;
}
.btn-clear[hidden] { display: none; }

/* Los filtros y la lista comparten el alto disponible, cada uno con su propio
   scroll. Así, aunque el mapa vaya embebido (más bajo que pantalla completa),
   la lista de entidades nunca se queda en 0px. */
#filter-sections {
  flex: 1 1 0;
  min-height: 70px;
  overflow-y: auto;
}
.entity-list {
  flex: 2 1 0;
  min-height: 120px;
  overflow-y: auto;
  padding: 4px 16px 20px;
}
.entity-card {
  display: flex; align-items: center;
  padding: 10px 12px;
  background: #FFF;
  border: 1px solid #ECECEC; border-radius: 8px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 0.15s;
  gap: 10px;
  width: 100%;
  text-align: left;
  font-family: inherit;
  color: inherit;
}
.entity-card:hover {
  border-color: #0D4E47;
  box-shadow: 0 3px 12px rgba(13,78,71,0.1);
  transform: translateY(-1px);
}
.entity-card.selected {
  border-color: var(--c, #0D4E47);
  background: #F7FAF9;
  box-shadow: 0 0 0 1px var(--c, #0D4E47), 0 3px 12px rgba(13,78,71,0.12);
}
.entity-card .sector-bar {
  width: 4px; align-self: stretch; border-radius: 2px;
  background: var(--c, #999);
  flex-shrink: 0;
}
.entity-card .card-logo {
  width: 44px; height: 44px; flex-shrink: 0;
  border-radius: 8px; overflow: hidden;
  background: var(--c, #999);
  display: flex; align-items: center; justify-content: center;
  color: #FFF; font-weight: 700; font-size: 13px;
  letter-spacing: 0.5px;
}
.entity-card .card-logo img {
  width: 100%; height: 100%; object-fit: contain;
  background: #FFF;
}
.entity-card .card-body { flex: 1; min-width: 0; }
.entity-card .name {
  font-size: 13px; font-weight: 600; color: #222;
  margin-bottom: 4px; line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.entity-card .location {
  font-size: 11.5px; color: var(--c, #999);
  font-weight: 600; line-height: 1.3;
}
.entity-card .sector-label {
  font-size: 9.5px; color: #5F6B68;
  font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px;
  margin-top: 4px;
}

.empty {
  text-align: center; color: #5F6B68; padding: 36px 20px;
  font-size: 13px; font-style: italic;
}

.mapboxgl-popup-content {
  padding: 16px 18px; border-radius: 10px;
  font-family: 'Montserrat', sans-serif;
  max-width: 320px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.18);
}
.mapboxgl-popup-content h3 {
  font-size: 14px; color: #0D4E47;
  margin-bottom: 8px; line-height: 1.3;
}
.mapboxgl-popup-content .pop-pill {
  display: inline-block; font-size: 10px; text-transform: uppercase;
  letter-spacing: 0.6px; padding: 3px 9px; border-radius: 100px;
  color: #FFF; font-weight: 700; margin-bottom: 10px;
}
.mapboxgl-popup-content .pop-meta {
  font-size: 12px; color: #555; margin-bottom: 6px; line-height: 1.4;
}
.mapboxgl-popup-content .pop-meta strong { color: #333; }
.mapboxgl-popup-content .pop-links {
  display: flex; gap: 12px; margin-top: 12px;
  flex-wrap: wrap; font-size: 12px;
}
.mapboxgl-popup-content .pop-links a {
  color: #F55654; text-decoration: none; font-weight: 600;
}
.mapboxgl-popup-content .pop-links a:hover { text-decoration: underline; }

/* Lista de entidades co-ubicadas (cluster inseparable o marcadores apilados). */
.popup-entity-list {
  display: flex; flex-direction: column; gap: 4px;
  margin-top: 8px; max-height: 240px; overflow-y: auto;
}
.popup-entity {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 9px; border: 1px solid #ECECEC; border-radius: 7px;
  background: #FFF; cursor: pointer; text-align: left;
  font-family: inherit; font-size: 12px; font-weight: 600; color: #333;
  transition: all 0.15s;
}
.popup-entity:hover { border-color: #0D4E47; color: #0D4E47; background: #F2F8F7; }
.popup-entity .pe-dot {
  width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0;
  box-shadow: 0 0 0 1px rgba(0,0,0,.1);
}

/* Banner contextual del mapa: por defecto oculto (hidden). Solo se muestra
   cuando hay un aviso real (entidades descartadas por datos corruptos, etc.). */
.map-banner {
  position: absolute; bottom: 12px; left: 12px;
  background: rgba(13, 78, 71, 0.95); color: #FFF;
  padding: 8px 14px; border-radius: 6px; font-size: 12px; font-weight: 600;
  z-index: 1; box-shadow: 0 2px 10px rgba(0,0,0,.2);
  max-width: 360px; line-height: 1.4;
}
.map-banner[hidden] { display: none; }
.map-banner.warning { background: rgba(176, 82, 101, 0.95); }
:focus-visible {
  outline: 2px solid #0D4E47;
  outline-offset: 2px;
  border-radius: 4px;
}
.sector-pill:focus-visible, .entity-card:focus-visible, .controls button:focus-visible, .back-button:focus-visible {
  outline-offset: 2px;
}

/* Patrón estándar para texto solo accesible a lectores de pantalla. */
.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

.drag-handle { display: none; }

.detail-logo-block {
  display: flex; align-items: center; gap: 14px;
  margin-bottom: 14px;
}
.detail-logo {
  width: 64px; height: 64px;
  border-radius: 12px; overflow: hidden;
  background: var(--c, #999);
  display: flex; align-items: center; justify-content: center;
  color: #FFF; font-weight: 700; font-size: 22px;
  flex-shrink: 0;
}
.detail-logo img { width: 100%; height: 100%; object-fit: contain; background: #FFF; }
.detail-logo-block .detail-name { margin: 0; flex: 1; }

@media (max-width: 768px) {
  #container { flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden; position: relative; }
  #map { flex: 1; width: 100%; height: 100vh; height: 100dvh; }
  #sidebar {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    width: 100%;
    height: 72vh;
    border-right: 0;
    border-top: 1px solid #E8E8E8;
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -8px 28px rgba(0,0,0,0.2);
    transform: translateY(calc(100% - 156px));
    transition: transform 0.32s cubic-bezier(.4,.0,.2,1);
    z-index: 10;
  }
  #sidebar.expanded { transform: translateY(0) !important; }
  .drag-handle {
    display: block;
    position: relative;
    height: 40px;
    cursor: pointer;
    flex-shrink: 0;
    background: transparent;
    border: 0;
    width: 100%;
  }
  .drag-handle::before {
    content: '';
    position: absolute;
    top: 8px; left: 50%; transform: translateX(-50%);
    width: 44px; height: 4px;
    background: #CCC; border-radius: 2px;
  }
  /* Etiqueta visible: deja claro que el panel se desliza hacia arriba para ver
     filtros y entidades. La flecha se invierte al expandir (arriba = abrir,
     abajo = cerrar). */
  .drag-handle-hint {
    position: absolute;
    top: 18px; left: 50%; transform: translateX(-50%);
    font-size: 11px; font-weight: 700; color: #0D4E47;
    text-transform: uppercase; letter-spacing: 0.5px; white-space: nowrap;
  }
  .drag-handle-hint::after { content: " \25B2"; font-size: 9px; }
  #sidebar.expanded .drag-handle-hint { color: #5F6B68; }
  #sidebar.expanded .drag-handle-hint::after { content: " \25BC"; }
  .sidebar-header { padding-top: 4px; cursor: pointer; }
  .map-banner { bottom: 8px; left: 8px; font-size: 11px; padding: 6px 10px; max-width: calc(100% - 16px); }
}

.view-list { display: flex; flex-direction: column; flex: 1; overflow: hidden; }
.view-list.hidden { display: none; }
.view-detail { display: none; flex-direction: column; flex: 1; overflow-y: auto; }
.view-detail.active { display: flex; }

.back-button {
  display: flex; align-items: center; gap: 8px;
  padding: 14px 24px;
  background: #FAFAFA; border: 0; border-bottom: 1px solid #F0F0F0;
  cursor: pointer; width: 100%;
  font-family: inherit; font-size: 12px; font-weight: 600;
  color: #555; transition: all 0.15s;
  text-align: left;
}
.back-button:hover { background: #F2F2F2; color: #0D4E47; }
.back-button .arrow { font-size: 14px; line-height: 1; }

.detail-content { padding: 20px 24px 32px; }
.detail-name { font-size: 18px; font-weight: 700; color: #0D4E47; line-height: 1.3; margin-bottom: 10px; }
.detail-pill {
  display: inline-block; font-size: 10px; text-transform: uppercase;
  letter-spacing: 0.6px; padding: 4px 10px; border-radius: 100px;
  color: #FFF; font-weight: 700; margin-bottom: 18px;
}
.detail-section { margin-bottom: 16px; }
.detail-section-label {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.8px;
  color: #5F6B68; font-weight: 700; margin-bottom: 4px;
}
.detail-section-value {
  font-size: 13px; color: #333; line-height: 1.5;
}
.detail-section-value.loading { color: #BBB; font-style: italic; }
.detail-section-value.empty { color: #BBB; font-style: italic; }

.detail-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 20px; padding-top: 18px; border-top: 1px solid #F0F0F0; }
.detail-action {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 14px; border-radius: 8px;
  text-decoration: none; font-family: inherit; font-size: 13px; font-weight: 600;
  border: 1px solid #E0E0E0; background: #FFF; color: #444;
  cursor: pointer; transition: all 0.15s;
}
.detail-action:hover { border-color: #0D4E47; color: #0D4E47; background: #F2F8F7; }
.detail-action.primary { background: #0D4E47; color: #FFF; border-color: #0D4E47; }
.detail-action.primary:hover { background: #0a3d37; color: #FFF; }

.detail-links-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.detail-link-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px; border-radius: 100px;
  background: #F2F2F2; color: #444; text-decoration: none;
  font-size: 11px; font-weight: 600;
  transition: all 0.15s;
}
.detail-link-chip:hover { background: #F55654; color: #FFF; }

/* Botón "Volver a Canarias Convive": enlace fijo en la esquina superior
   derecha del viewport para regresar al sitio principal. z-index alto para
   quedar por encima del canvas y los controles de Mapbox. */
.back-to-site {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 1000;
  display: inline-flex;
  align-items: center;
  background: #0D4E47;
  color: #FFF;
  font-family: 'Montserrat', sans-serif;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  padding: 8px 14px;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.2);
  white-space: nowrap;
}
.back-to-site:hover { background: #0a3d37; color: #FFF; }

/* Los controles de Mapbox (zoom, brújula, pantalla completa) van en la esquina
   superior derecha, la misma que ocupa el botón "Volver a Canarias Convive".
   Los bajamos para que no se solapen. Aplica en PC y en móvil. */
.mapboxgl-ctrl-top-right { top: 56px; }

/* ─── Splash screen (Logo Mapa Canarias Convive · OptionC) ─────────────────────
   Aparece mientras Mapbox carga el estilo + los datos. La animación de entrada
   (kicker → islas → pines → wordmark) dura ~2.85s; tras verse completa el splash
   se desvanece. Pure CSS/SVG — sin dependencias externas (geometría ISTAC
   pre-calculada y horneada en el SVG). */
#splash {
  position: fixed; inset: 0; z-index: 9999; overflow: hidden;
  background: radial-gradient(120% 90% at 50% 38%, #fdfcf8 0%, #f6f4ef 65%, #ebe7da 100%);
  display: flex; align-items: center; justify-content: center;
  transition: opacity 0.55s ease, visibility 0.55s ease;
  font-family: 'Manrope', sans-serif; color: #33322e;
}
#splash.hidden { opacity: 0; visibility: hidden; pointer-events: none; }

/* Marco fijo 700×700 (mismo lienzo que el diseño original). Se escala al
   viewport con un transform en JS — así las posiciones en px son exactas. */
#splash-frame {
  position: relative; flex: none;
  width: 700px; height: 700px;
  transform-origin: center center;
}

.sp-kick {
  position: absolute; top: 80px; left: 0; right: 0; text-align: center;
  font-size: 13px; letter-spacing: .52em; text-transform: uppercase;
  color: #0d4e47; font-weight: 600;
}
.sp-kickrule {
  position: absolute; top: 108px; left: 50%; width: 36px; height: 1px;
  margin-left: -18px; background: #0d4e47; opacity: .55;
}

.sp-map { position: absolute; inset: 0; }
.sp-islands { position: absolute; inset: 0; }
.sp-islands path {
  fill: #d4d8c1; stroke: #aab285; stroke-width: 1.2;
  stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke;
}
.sp-dot {
  position: absolute; border-radius: 50%;
  box-shadow: 0 3px 8px -2px #00000040, 0 0 0 1.6px #fdfcf8;
  transform-origin: 50% 50%;
}

.sp-seal { position: absolute; top: 494px; left: 0; right: 0; text-align: center; }
.sp-rule {
  display: inline-block; width: 42px; height: 1px; background: #f55654;
  vertical-align: middle; transform-origin: center;
}
.sp-mark {
  display: block; font-family: 'Quicksand', sans-serif; font-weight: 600;
  font-size: 54px; letter-spacing: .012em; color: #33322e; line-height: 1;
  margin-top: 18px;
}
.sp-tag {
  display: block; margin-top: 22px; font-size: 12px; letter-spacing: .36em;
  text-transform: uppercase; color: #0d4e47; font-weight: 600;
}

@media (prefers-reduced-motion: no-preference) {
  .sp-kick     { opacity: 0; animation: spcFade .9s .15s ease both; }
  .sp-kickrule { transform: scaleX(0); animation: spcRule .7s .55s cubic-bezier(.2,.9,.25,1) both; }
  .sp-islands path { opacity: 0; animation: spcRise 1.1s .25s ease both; }
  .sp-dot      { opacity: 0; transform: scale(0);
                 animation: spcPop .9s cubic-bezier(.22,1.2,.36,1) forwards; }
  .sp-rule     { transform: scaleX(0); animation: spcRule .7s 1.45s cubic-bezier(.2,.9,.25,1) both; }
  .sp-mark     { opacity: 0; animation: spcFade 1.1s 1.55s ease both; }
  .sp-tag      { opacity: 0; animation: spcFade 1s 1.85s ease both; }
}
@keyframes spcPop  { to { opacity: 1; transform: scale(1); } }
@keyframes spcFade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes spcRise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes spcRule { to { transform: scaleX(1); } }
@media (max-width: 768px) {
  .mapboxgl-ctrl-top-right { top: 60px; }
}
