:root {
  --panel-width: 23vw;
  --panel-min: 280px;
  --panel-max: 360px;
  --bg: #fdfdfd;
  --text: #1a1a1a;
  --muted: #888;
  --border: #e0e0e0;
  --accent: #00d99f;
  --radius: 3px;
  --drawer-width: 380px;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body, html { height: 100%; font-family: 'DM Sans', sans-serif; color: var(--text); overflow: hidden; }
#app { display: flex; height: 100%; width: 100%; }
/* ---- PANEL IZQUIERDO ---- */
#panel {
  width: clamp(var(--panel-min), var(--panel-width), var(--panel-max));
  height: 100%;
  background: var(--bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 10;
  transition: margin-left 0.35s ease;
  flex-shrink: 0;
  position: relative;
}
#panel.closed { margin-left: calc(-1 * clamp(var(--panel-min), var(--panel-width), var(--panel-max))); }
#panel-header { padding: 22px 18px 10px; }
#panel-header h1 {
  font-family: 'DM Serif Display', serif;
  font-size: 1.22rem; line-height: 1.3; font-weight: 400;
}
#panel-body {
  flex: 1; padding: 0 18px;
  display: flex; flex-direction: column; gap: 14px;
  overflow-y: auto;
}
/* ---- BUSCADORES ---- */
.search-box { position: relative; }
.search-box input {
  width: 100%; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-family: 'DM Sans', sans-serif; font-size: 0.82rem; outline: none;
}
.search-box input:focus { border-color: var(--accent); }
.search-box input::placeholder { color: #bbb; }
.search-results {
  display: none; position: absolute;
  top: 100%; left: 0; right: 0;
  background: #fff;
  border: 1px solid var(--border); border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  max-height: 200px; overflow-y: auto; z-index: 100;
}
.search-item {
  padding: 7px 10px; font-size: 0.8rem; cursor: pointer;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.search-item:hover { background: #f5f5f5; }
.search-item span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-count {
  font-size: 0.7rem; color: var(--muted);
  background: #f0f0f0; padding: 1px 6px; border-radius: 8px; flex-shrink: 0;
}
/* Chips de palabra clave */
#keyword-tag { display: none; flex-wrap: wrap; gap: 4px; }
.keyword-chip {
  font-size: 0.72rem; background: #e8faf4;
  border: 1px solid var(--accent); border-radius: 4px;
  padding: 2px 8px; color: #00a87a; cursor: default;
  display: inline-flex; align-items: center; gap: 4px;
}
.chip-x { cursor: pointer; font-size: 0.85rem; line-height: 1; }
.chip-x:hover { color: #007a58; }
/* ---- BOTONES TIPO ---- */
.btn-group { display: flex; gap: 6px; }
.btn-group button {
  flex: 1; padding: 7px 4px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: #fff; font-family: 'DM Sans', sans-serif;
  font-size: 0.72rem; font-weight: 600; cursor: pointer; transition: all 0.15s;
}
.btn-group button:hover { background: #f5f5f5; }
.btn-group button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
/* ---- FILTRO PARTIDOS ---- */
.filter-section label {
  display: block; font-size: 0.72rem; font-weight: 600;
  color: var(--muted); text-transform: uppercase;
  letter-spacing: 0.5px; margin-bottom: 6px;
}
#partido-btns { display: flex; flex-wrap: wrap; gap: 6px; }
.partido-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--border); border-radius: 4px;
  background: #fff; font-family: 'DM Sans', sans-serif;
  font-size: 0.82rem; font-weight: 500; cursor: pointer;
  transition: all 0.15s; color: var(--text); white-space: nowrap;
}
.partido-btn:hover { background: #f5f5f5; }
.partido-btn.active { border-color: currentColor; background: #f0fdf8; font-weight: 700; }
.partido-dot {
  display: inline-block; width: 10px; height: 10px;
  border-radius: 50%; flex-shrink: 0;
}
#btn-clear-partidos {
  font-size: 0.7rem; color: var(--muted); background: none; border: none;
  cursor: pointer; padding: 3px 0 0;
  font-family: 'DM Sans', sans-serif; text-decoration: underline; display: none;
}
#btn-clear-partidos:hover { color: var(--text); }
#btn-clear-partidos.visible { display: inline-block; }
/* ---- LEYENDA ---- */
#leyenda {
  position: fixed; top: 12px; right: 12px; z-index: 50;
  width: 290px; background: rgba(253,253,253,0.92);
  backdrop-filter: blur(4px);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 8px 10px; font-size: 0.82rem; color: #555; line-height: 1.5;
  pointer-events: none;
}
.legend-bar {
  height: 10px; width: 100%;
  background: linear-gradient(to right, #c7e9c0 0%, #74c476 40%, #41ab5d 60%, #238b45 80%, #005a32 100%);
  border-radius: 3px; margin: 6px 0 3px;
}
.legend-labels { display: flex; justify-content: space-between; font-size: 0.65rem; color: var(--muted); }
.legend-dot {
  display: inline-block; width: 8px; height: 8px;
  border-radius: 50%; margin-right: 4px; vertical-align: middle;
}
/* ---- ACCIONES ---- */
.action-btns { display: flex; flex-wrap: wrap; gap: 6px; }
.action-btns label { width: 100%; margin-bottom: 0; }
.action-btns button {
  flex: 1; padding: 8px 0;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: #fff; font-family: 'DM Sans', sans-serif;
  font-size: 0.8rem; cursor: pointer; transition: background 0.15s;
}
.action-btns button:hover { background: #f5f5f5; }
/* ---- CLEAR ALL ---- */
#btn-clear-all {
  width: 100%; padding: 10px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: #fff; font-family: 'DM Sans', sans-serif;
  font-size: 0.82rem; font-weight: 600; color: var(--muted);
  cursor: pointer; transition: all 0.15s;
}
#btn-clear-all:hover { background: #fff0f0; border-color: #ffb3b3; color: #cc0000; }
/* ---- FOOTER ---- */
#panel-footer { padding: 14px 18px; display: flex; justify-content: space-between; align-items: center; }
#btn-close-panel {
  background: none; border: none; font-family: 'DM Sans', sans-serif;
  font-size: 0.83rem; color: var(--muted); cursor: pointer;
}
#btn-close-panel:hover { color: var(--text); }
#btn-info {
  background: none; border: 1px solid var(--border); border-radius: 50%;
  width: 24px; height: 24px; font-size: 0.72rem; font-weight: 700;
  color: var(--muted); cursor: pointer; display: flex; align-items: center; justify-content: center;
}
#btn-info:hover { color: var(--text); border-color: #bbb; }
/* ---- BOTÓN REABRIR ---- */
#btn-open-panel {
  display: none; position: absolute; left: 12px; top: 12px; z-index: 20;
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 14px; flex-direction: column; gap: 4px; max-width: 220px;
}
#btn-open-panel.visible { display: flex; }
#btn-open-title { font-family: 'DM Serif Display', serif; font-size: 0.88rem; line-height: 1.3; }
#btn-open-trigger {
  background: none; border: none; font-size: 0.72rem; color: var(--muted);
  cursor: pointer; padding: 0; font-family: 'DM Sans', sans-serif; text-align: left;
}
#btn-open-trigger:hover { color: var(--text); }
/* ---- MAPA ---- */
#map-wrap { flex: 1; position: relative; }
#map { position: absolute; inset: 0; }
/* ---- POPUP ---- */
.maplibregl-popup-content {
  font-family: 'DM Sans', sans-serif; padding: 0 !important;
  border-radius: 3px !important; overflow: hidden; min-width: 260px; max-width: 310px;
}
.popup-card { padding: 14px 16px; }
.popup-nav {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 16px; background: #fafafa; border-bottom: 1px solid #eee;
  font-size: 1rem; color: var(--muted);
}
.popup-nav button {
  background: none; border: none; font-size: 1.8rem;
  cursor: pointer; color: var(--muted); padding: 0 4px;
}
.popup-nav button:hover { color: var(--text); }
.popup-pregunta { font-size: 0.85rem; line-height: 1.45; margin-bottom: 10px; }
.popup-partido { font-weight: 700; font-size: 0.95rem; margin-bottom: 2px; }
.popup-autores { font-size: 0.8rem; color: var(--muted); margin-bottom: 10px; }
.popup-link {
  display: inline-block; font-size: 0.78rem;
  color: var(--accent); text-decoration: none; font-weight: 600;
}
.popup-link:hover { text-decoration: underline; }
/* ---- POPUP RESUMEN (municipios grandes) ---- */
.popup-resumen { padding: 16px 18px; text-align: center; }
.popup-resumen-n {
  display: inline-block;
  background: #01f3b3;
  color: #111;
  font-weight: 700;
  font-size: 1.1rem;
  padding: 3px 10px;
  border-radius: 4px;
  margin-bottom: 4px;
}
.popup-resumen-muni { font-weight: 700; font-size: 1.05rem; margin-bottom: 20px; }
.popup-resumen-text { font-size: 1rem; color: #555; margin-bottom: 4px; line-height: 1.4; }
.popup-resumen-btn {
  display: inline-block;
  background: #01f3b3;
  color: #1a1a1a;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.82rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  padding: 8px 18px;
  cursor: pointer;
  transition: background 0.15s;
}
.popup-resumen-btn:hover { background: #00dfa3; }
/* ===== DRAWER LATERAL DERECHO ===== */
#drawer {
  position: fixed;
  top: 0; right: 0;
  width: var(--drawer-width);
  max-width: 90vw;
  height: 100%;
  background: var(--bg);
  border-left: 1px solid var(--border);
  z-index: 200;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.3s ease;
}
#drawer.open { transform: translateX(0); }
#drawer-header {
  padding: 18px 18px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}
#drawer-header-text { flex: 1; }
#drawer-muni-name {
  font-family: 'DM Serif Display', serif;
  font-size: 1.1rem;
  font-weight: 400;
  line-height: 1.3;
}
#drawer-muni-count {
  display: inline-block;
  background: #01f3b3;
  color: #1a1a1a;
  font-weight: 700;
  font-size: 0.85rem;
  padding: 2px 8px;
  border-radius: 4px;
  margin-top: 4px;
}
#btn-close-drawer {
  background: none; border: none;
  font-size: 1.4rem; cursor: pointer;
  color: var(--muted); padding: 0;
  line-height: 1;
}
#btn-close-drawer:hover { color: var(--text); }
/* Filtros del drawer */
#drawer-filters {
  padding: 12px 18px;
  display: flex; gap: 8px;
  border-bottom: 1px solid var(--border);
}
#drawer-search {
  flex: 1; padding: 7px 10px;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-family: 'DM Sans', sans-serif; font-size: 0.8rem; outline: none;
}
#drawer-search:focus { border-color: var(--accent); }
#drawer-partido-filter {
  padding: 7px 8px;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-family: 'DM Sans', sans-serif; font-size: 0.8rem;
  background: #fff; cursor: pointer;
}
/* Lista de preguntas */
#drawer-list {
  flex: 1;
  overflow-y: auto;
  padding: 0;
}
.drawer-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 18px;
  border-bottom: 1px solid #f0f0f0;
  align-items: flex-start;
  transition: background 0.1s;
}
.drawer-row:hover { background: #fafafa; }
.drawer-partido-tag {
  align-self: flex-start;
  flex-shrink: 0;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 3px;
  color: #fff;
  white-space: nowrap;
  margin-top: 2px;
}
.drawer-pregunta-text {
  font-size: 0.82rem;
  line-height: 1.4;
  color: var(--text);
  flex: 1;
}
.drawer-pregunta-link {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.75rem;
  font-weight: 600;
  margin-left: 6px;
  white-space: nowrap;
}
.drawer-pregunta-link:hover { text-decoration: underline; }
.drawer-autores {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 3px;
}
/* Contador de resultados */
#drawer-result-count {
  padding: 6px 18px;
  font-size: 0.72rem;
  color: var(--muted);
  background: #fafafa;
  border-bottom: 1px solid var(--border);
}
/* ---- MODAL INFO ---- */
#info-modal {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.35); z-index: 9999;
  align-items: center; justify-content: center;
}
#info-modal .modal-box {
  background: #fff; border-radius: 8px; padding: 24px 28px;
  max-width: 420px; width: 90%; font-size: 0.82rem; line-height: 1.6;
}
#info-modal h3 { font-family: 'DM Serif Display', serif; margin-bottom: 10px; font-weight: 400; }
#info-modal a { color: var(--accent); }
#info-modal .modal-close {
  margin-top: 14px; background: none; border: 1px solid var(--border);
  border-radius: var(--radius); padding: 6px 16px;
  font-family: 'DM Sans', sans-serif; cursor: pointer;
}
.maplibregl-ctrl-scale {
  font-family: 'DM Sans', sans-serif; font-size: 0.7rem;
  background: rgba(255,255,255,0.85); border-color: var(--muted); color: var(--text);
}
/* ---- RESPONSIVE ---- */
@media (max-width: 700px) {
  :root { --panel-min: 100vw; --panel-max: 100vw; --panel-width: 100vw; --drawer-width: 100vw; }
  html {
    font-size: 18px;
  }
  #panel { position: absolute; left: 0; top: 0; height: 100%; z-index: 100; }
  #panel.closed { margin-left: -100vw; }
  #leyenda { top: auto; bottom: 10px; left: 10px; font-size: 0.65rem; max-width: 240px; }
  #drawer { width: 100vm; left: auto; right: 0; max-width: 100vw; overflow-x: hidden;}
}
