/* ── Fuentes ── */
@import url('https://fonts.googleapis.com/css2?family=Space+Mono:wght@400;700&family=DM+Sans:wght@300;400;600&display=swap');

/* ── Variables ── */
:root {
  --bg:        #0b0f1a;
  --panel:     #111827;
  --panel2:    #1a2236;
  --border:    #1f2d45;
  --accent:    #5eead4;
  --accent2:   #7dd3fc;
  --warn:      #fbbf24;
  --danger:    #ef4444;
  --text:      #e2e8f0;
  --muted:     #64748b;
  --mono:      'Space Mono', monospace;
  --sans:      'DM Sans', sans-serif;
  --radius:    8px;
  --shadow:    0 4px 24px rgba(0,0,0,.5);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Header ── */
header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  z-index: 1000;
  flex-shrink: 0;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--mono);
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: .03em;
}

.logo svg { width: 28px; height: 28px; }

.logo span em {
  font-style: normal;
  color: var(--muted);
  font-weight: 400;
}

.stats-bar {
  display: flex;
  gap: 20px;
  margin-left: auto;
  align-items: center;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1px;
}

.stat-val {
  font-family: var(--mono);
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
}

.stat-lbl {
  font-size: 10px;
  color: var(--muted);
  letter-spacing: .08em;
  text-transform: uppercase;
}

.sep { width: 1px; height: 28px; background: var(--border); }

@keyframes spin { to { transform: rotate(360deg); } }

.last-update {
  font-size: 11px;
  color: var(--muted);
  font-family: var(--mono);
  white-space: nowrap;
}

/* ── Layout ── */
.main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Mapa ── */
#map {
  flex: 1;
  background: #0d1520;
}

.leaflet-tile-pane { filter: saturate(.85); }

/* ── Buscador en header ── */
.search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 10px;
  width: 14px;
  height: 14px;
  color: var(--muted);
  pointer-events: none;
  flex-shrink: 0;
  transition: color .2s;
}

.search-wrap:focus-within .search-icon { color: var(--accent); }

.search-input {
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 7px 14px 7px 32px;
  color: var(--text);
  font-family: var(--sans);
  font-size: 13px;
  outline: none;
  width: 220px;
  transition: border-color .2s, box-shadow .2s;
}

.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(94,234,212,.12);
}

.search-input::placeholder { color: var(--muted); }

.search-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: 300px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 2000;
  max-height: 220px;
  overflow-y: auto;
  display: none;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.search-dropdown.open { display: block; }

.search-result {
  padding: 9px 14px;
  border-bottom: 1px solid rgba(31,45,69,.6);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: background .12s;
}

.search-result:last-child { border-bottom: none; }
.search-result:hover, .search-result.active { background: var(--panel2); }

.node-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot-recent  { background: var(--accent); box-shadow: 0 0 6px var(--accent); }
.dot-active  { background: var(--accent2); }
.dot-old     { background: var(--muted); }
.dot-gateway { background: var(--warn); box-shadow: 0 0 6px var(--warn); }
.dot-router  { background: #fb923c; box-shadow: 0 0 6px #fb923c; }

.result-name {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.result-meta {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── Panel de detalle ── */
.detail-panel {
  position: absolute;
  bottom: calc(32px + 20px);
  left: 20px;
  width: 320px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  z-index: 500;
  display: none;
  font-size: 13px;
}

.detail-panel.visible { display: block; animation: slideUp .2s ease; }

@keyframes slideUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.detail-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.detail-title {
  font-family: var(--mono);
  font-size: 14px;
  font-weight: 700;
  flex: 1;
}

.detail-close {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 2px;
}

.detail-close:hover { color: var(--text); }

.detail-body { padding: 14px 16px; }

.mal-config-banner {
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 10px 12px;
  margin-bottom: 10px;
  background: rgba(239,68,68,.08);
  border: 1px solid rgba(239,68,68,.35);
  border-radius: 6px;
  font-size: 11px;
  color: var(--muted);
  line-height: 1.5;
}

.mal-config-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.mal-config-row svg { flex-shrink: 0; }

.mal-config-banner strong { color: var(--text); }

.mal-config-stat { font-size: 11px; }

.mal-config-link {
  appearance: none;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  color: #f97316;
  text-decoration: none;
  font-family: var(--mono);
  font-size: 10px;
  align-self: flex-start;
}
.mal-config-link:hover { text-decoration: underline; }

.mal-config-issue {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  padding: 1px 0;
}
.mal-config-issue::before {
  content: '●';
  font-size: 8px;
  flex-shrink: 0;
}
.mal-config-issue.issue-critical { color: #ef4444; }
.mal-config-issue.issue-critical::before { color: #ef4444; }
.mal-config-issue.issue-high { color: #f97316; }
.mal-config-issue.issue-high::before { color: #f97316; }
.mal-config-issue.issue-medium { color: #eab308; }
.mal-config-issue.issue-medium::before { color: #eab308; }

/* ── Issue chips (tabla modal) ── */
.mc-issues { min-width: 180px; }

.issue-chip {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 10px;
  white-space: nowrap;
  margin: 2px 2px 2px 0;
}
.issue-chip.critical {
  background: rgba(239,68,68,.12);
  color: #ef4444;
  border: 1px solid rgba(239,68,68,.3);
}
.issue-chip.high {
  background: rgba(249,115,22,.12);
  color: #f97316;
  border: 1px solid rgba(249,115,22,.3);
}
.issue-chip.medium {
  background: rgba(234,179,8,.10);
  color: #eab308;
  border: 1px solid rgba(234,179,8,.3);
}
.issue-none { color: var(--muted); font-size: 11px; }

/* ── Modal reporte de nodo ── */
.nr-inner { max-width: 560px; }

.nr-header { margin-bottom: 12px; }

/* Indicador fijo/móvil */
.nr-mobility {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 11px;
  margin-bottom: 16px;
  line-height: 1.5;
}
.nr-mobility strong { color: var(--text); }
.nr-mob-icon { font-size: 14px; flex-shrink: 0; }
.nr-mobility-fixed  { background: rgba(94,234,212,.08); border: 1px solid rgba(94,234,212,.2); color: var(--muted); }
.nr-mobility-mobile { background: rgba(125,211,252,.08); border: 1px solid rgba(125,211,252,.2); color: var(--muted); }

.nr-hop {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 11px;
  margin-bottom: 16px;
  line-height: 1.5;
}
.nr-hop strong { color: var(--text); }
.nr-hop-icon  { font-size: 14px; flex-shrink: 0; }
.nr-hop-warn  { color: #fb923c; }
.nr-hop-ok       { background: rgba(94,234,212,.08);  border: 1px solid rgba(94,234,212,.2);  color: var(--muted); }
.nr-hop-high     { background: rgba(251,146,60,.10);  border: 1px solid rgba(251,146,60,.3);  color: var(--muted); }
.nr-hop-critical { background: rgba(248,113,113,.10); border: 1px solid rgba(248,113,113,.3); color: var(--muted); }

/* Chip fijo/móvil en tabla */
.mob-chip {
  display: inline-block;
  font-size: 9px;
  padding: 1px 5px;
  border-radius: 3px;
  vertical-align: middle;
  margin-left: 4px;
  font-family: var(--mono);
}
.mob-fixed  { background: rgba(94,234,212,.12);  color: #5eead4; }
.mob-mobile { background: rgba(125,211,252,.12); color: #7dd3fc; }

/* Sub-info en barras de desglose */
.nr-bar-col { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nr-bar-sub { display: flex; gap: 10px; font-size: 10px; color: var(--muted); font-family: var(--mono); }
.nr-node-name { font-family: var(--mono); font-size: 14px; font-weight: 700; color: var(--text); margin-bottom: 4px; }
.nr-node-meta { font-size: 11px; color: var(--muted); }

.nr-section-title {
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  margin: 18px 0 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.nr-issue {
  padding: 10px 12px;
  border-radius: 6px;
  margin-bottom: 8px;
  border-left: 3px solid;
}
.nr-issue-critical { background: rgba(239,68,68,.07);  border-color: #ef4444; }
.nr-issue-high     { background: rgba(249,115,22,.07); border-color: #f97316; }
.nr-issue-medium   { background: rgba(234,179,8,.07);  border-color: #eab308; }

.nr-issue-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}
.nr-issue-desc { font-size: 11px; color: var(--muted); line-height: 1.5; margin-bottom: 6px; }
.nr-issue-fix  { font-size: 11px; color: var(--muted); font-family: var(--mono); }
.nr-issue-fix strong { color: var(--text); }

.nr-no-issues { font-size: 12px; color: var(--muted); padding: 10px 0; }

.nr-breakdown { display: flex; flex-direction: column; gap: 6px; }

.nr-bar-row {
  display: grid;
  grid-template-columns: 100px 1fr 90px;
  align-items: start;
  gap: 8px;
  font-size: 11px;
  padding: 3px 0;
}
.nr-bar-flagged .nr-bar-label { color: var(--text); font-weight: 600; }
.nr-bar-label { color: var(--muted); white-space: nowrap; }
.nr-bar-track { background: var(--panel2); border-radius: 3px; height: 6px; overflow: hidden; }
.nr-bar-fill  { height: 100%; background: var(--accent2); border-radius: 3px; transition: width .3s; }
.nr-bar-flagged .nr-bar-fill { background: #f97316; }
.nr-bar-num  { font-family: var(--mono); color: var(--text); text-align: right; white-space: nowrap; }
.nr-bar-pct  { color: var(--muted); }

.nr-meshview { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--border); }
.nr-meshview a { color: #f97316; text-decoration: none; font-family: var(--mono); font-size: 11px; }
.nr-meshview a:hover { text-decoration: underline; }

.detail-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  border-bottom: 1px solid rgba(31,45,69,.4);
}

.detail-row:last-child { border: none; }

.detail-key {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.detail-val {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text);
  text-align: right;
  max-width: 55%;
  word-break: break-all;
}

.detail-val.accent { color: var(--accent); }

/* ── Leyenda ── */
.legend {
  position: absolute;
  bottom: calc(32px + 20px);
  right: 20px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  z-index: 500;
  font-size: 11px;
}

.legend-title {
  font-family: var(--mono);
  color: var(--muted);
  font-size: 10px;
  letter-spacing: .1em;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
  color: var(--text);
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.legend-sep {
  border: none;
  border-top: 1px solid var(--border);
  margin: 7px 0;
}

.legend-line { flex-shrink: 0; }

.legend-edge[data-edge] {
  cursor: pointer;
  transition: opacity .15s;
  user-select: none;
}
.legend-edge[data-edge]:not(.active) {
  opacity: .35;
  text-decoration: line-through;
}

/* ── Empty state ── */
.empty-state {
  padding: 40px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.empty-state svg { margin-bottom: 12px; opacity: .3; }

/* ── Cookie banner ── */
/* ── Hint bubble (novedades) ── */
.hint-bubble {
  position: fixed;
  background: var(--panel);
  border: 1px solid var(--accent2);
  border-radius: var(--radius);
  padding: 10px 28px 10px 12px;
  font-size: 11px;
  color: var(--muted);
  font-family: var(--sans);
  line-height: 1.55;
  max-width: 200px;
  z-index: 490;
  box-shadow: 0 4px 20px rgba(0,0,0,.5);
}

.hint-bubble strong { color: var(--accent2); }

.hint-bubble-close {
  position: absolute;
  top: 5px;
  right: 7px;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  padding: 2px;
}
.hint-bubble-close:hover { color: var(--text); }

.hint-bubble.hidden { display: none; }

/* Flecha apuntando a la derecha (desktop: burbuja a la izquierda de la leyenda) */
.hint-bubble.arrow-right::after {
  content: '';
  position: absolute;
  right: -7px;
  top: 50%;
  transform: translateY(-50%);
  border: 7px solid transparent;
  border-right: none;
  border-left-color: var(--accent2);
}

/* Flecha apuntando hacia abajo (móvil: burbuja encima de la leyenda) */
.hint-bubble.arrow-down::after {
  content: '';
  position: absolute;
  bottom: -7px;
  left: 18px;
  border: 7px solid transparent;
  border-bottom: none;
  border-top-color: var(--accent2);
}

.cookie-banner {
  position: fixed;
  bottom: calc(32px + env(safe-area-inset-bottom) + 12px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--panel);
  border: 1px solid rgba(251,191,36,.3);
  border-radius: var(--radius);
  box-shadow: 0 4px 24px rgba(0,0,0,.6);
  padding: 10px 16px;
  z-index: 8000;
  max-width: 560px;
  width: calc(100vw - 40px);
  animation: slideUp .25s ease;
}

.cookie-banner.hidden { display: none; }
body[data-cookie-ok="1"] .cookie-banner { display: none; }

.cookie-text {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--muted);
  font-family: var(--sans);
  flex: 1;
  line-height: 1.5;
}

.cookie-text svg { flex-shrink: 0; }
.cookie-text strong { color: var(--text); font-weight: 600; }

.cookie-btn {
  flex-shrink: 0;
  background: rgba(94,234,212,.1);
  border: 1px solid rgba(94,234,212,.35);
  border-radius: 6px;
  color: var(--accent);
  font-family: var(--mono);
  font-size: 11px;
  padding: 5px 14px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
  white-space: nowrap;
}

.cookie-btn:hover {
  background: rgba(94,234,212,.2);
  border-color: var(--accent);
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 20px;
  font-size: 13px;
  font-family: var(--mono);
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s;
}

.toast.show { opacity: 1; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ── Footer ── */
.app-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 max(16px, env(safe-area-inset-left));
  padding-bottom: env(safe-area-inset-bottom);
  height: calc(32px + env(safe-area-inset-bottom));
  flex-shrink: 0;
  background: var(--panel);
  border-top: 1px solid var(--border);
  box-shadow: inset 0 1px 0 rgba(94,234,212,.06);
  font-size: 11px;
  color: var(--muted);
  font-family: var(--mono);
  z-index: 600;
}

.footer-left {
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
  min-width: 0;
}

.footer-source {
  font-size: 10px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.footer-source a {
  color: var(--muted);
  text-decoration: none;
  transition: color .15s;
}

.footer-source a:hover { color: var(--accent); }

.footer-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  margin-left: 12px;
}

.footer-gh {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--muted);
  text-decoration: none;
  font-size: 10px;
  transition: border-color .15s, color .15s, box-shadow .15s;
}

.footer-gh:hover {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 8px rgba(94,234,212,.15);
}

.footer-version {
  background: rgba(94,234,212,.08);
  border: 1px solid rgba(94,234,212,.25);
  border-radius: 4px;
  padding: 2px 7px;
  font-size: 10px;
  color: var(--accent);
  letter-spacing: .05em;
}

/* ── Botón mal configurados ── */
.noopt-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  background: rgba(249,115,22,.12);
  border: 1px solid rgba(249,115,22,.35);
  border-radius: var(--radius);
  color: #f97316;
  font-family: var(--mono);
  font-size: 11px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s;
  flex-shrink: 0;
}
.noopt-btn:hover { background: rgba(249,115,22,.22); }

/* ── Modal mal configurados ── */
.malconfig-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 9500;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.malconfig-modal.open { display: flex; }

.malconfig-inner {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  max-width: 860px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.malconfig-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.malconfig-subtitle { font-weight: 400; color: var(--muted); font-size: 11px; }

.malconfig-header-right {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
}

.malconfig-updated {
  font-size: 11px;
  color: var(--muted);
}

.malconfig-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}

.malconfig-close {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 16px;
  padding: 4px 6px;
  line-height: 1;
}
.malconfig-close:hover { color: var(--text); }

.malconfig-tabs {
  display: flex;
  gap: 8px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  align-items: center;
}

.malconfig-filter-select {
  padding: 4px 10px;
  padding-right: 24px;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  cursor: pointer;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%2364748b'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  transition: all .15s;
}
.malconfig-filter-select:hover,
.malconfig-filter-select:focus {
  background-color: rgba(249,115,22,.1);
  border-color: rgba(249,115,22,.4);
  color: #f97316;
}

.malconfig-content {
  overflow-y: auto;
  overflow-x: auto;
  flex: 1;
  padding: 0 18px 18px;
}

.malconfig-empty {
  padding: 40px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

.malconfig-table {
  width: 100%;
  min-width: 640px;
  border-collapse: collapse;
  font-size: 12px;
  margin-top: 12px;
}

.malconfig-table th {
  text-align: center;
  padding: 8px 10px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .06em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
  background: var(--panel);
}

.malconfig-table td {
  padding: 9px 10px;
  border-bottom: 1px solid rgba(31,45,69,.4);
  vertical-align: middle;
  text-align: center;
}

.malconfig-table tr:last-child td { border-bottom: none; }
.malconfig-table tr:hover td { background: rgba(255,255,255,.02); }

.mc-row { cursor: pointer; }

/* Col 6 (Ver) fija a la derecha para que sea visible sin hacer scroll */
.malconfig-table th:nth-child(6),
.malconfig-table td.mc-action {
  position: sticky;
  right: 0;
  background: var(--panel);
  box-shadow: -8px 0 8px -8px rgba(0,0,0,.35);
}
.malconfig-table tr:hover td.mc-action { background: var(--panel2); }

.mc-rank {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  width: 30px;
}

.mc-name { min-width: 160px; }

.mc-longname {
  color: var(--text);
  font-weight: 600;
  margin-bottom: 2px;
}

.mc-id {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
}

.mc-preset {
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 7px;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
  white-space: nowrap;
}

.mc-num {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text);
}
.mc-muted { color: var(--muted); }

.mc-link {
  appearance: none;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  color: #f97316;
  text-decoration: none;
  font-family: var(--mono);
  font-size: 11px;
  white-space: nowrap;
}
.mc-link:hover { text-decoration: underline; }

.nr-back {
  appearance: none;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  margin-right: 10px;
}
.nr-back:hover { color: var(--text); }

/* ── Stats tab nav ── */
.malconfig-nav {
  display: flex;
  gap: 2px;
  padding: 0 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--panel);
}
.mc-tab {
  appearance: none;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  cursor: pointer;
  font-family: var(--mono);
  font-size: 11px;
  padding: 8px 12px 6px;
  margin-bottom: -1px;
  transition: color .15s, border-color .15s;
  letter-spacing: .03em;
}
.mc-tab:hover   { color: var(--text); }
.mc-tab.active  { color: var(--text); border-bottom-color: #f97316; }

/* ── Stats content ── */
.mcs-wrap {
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 16px 18px;
}

/* Summary cards */
.mcs-summary {
  display: flex;
  gap: 10px;
}
.mcs-card {
  flex: 1;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 14px;
  text-align: center;
}
.mcs-card-val  { font-family: var(--mono); font-size: 24px; font-weight: 700; color: var(--text); line-height: 1.1; }
.mcs-card-lbl  { font-size: 10px; color: var(--muted); margin-top: 4px; text-transform: uppercase; letter-spacing: .04em; }
.mcs-card-pct  { font-family: var(--mono); font-size: 12px; margin-top: 3px; }
.mcs-card-warn { border-color: rgba(249,115,22,.3); }
.mcs-card-warn .mcs-card-val { color: #f97316; }
.mcs-card-ok   { border-color: rgba(94,234,212,.25); }
.mcs-card-ok .mcs-card-val   { color: #5eead4; }

.mcs-scope-note {
  font-size: 11px;
  color: var(--muted);
  background: rgba(255,255,255,.03);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 7px 10px;
  margin-top: -10px;
}

/* Section title */
.mcs-section-title {
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 10px;
}
.mcs-subtitle { font-weight: 400; text-transform: none; letter-spacing: 0; }

/* Bar chart */
.mcs-bar-list { display: flex; flex-direction: column; gap: 6px; }
.mcs-bar-row  { display: grid; grid-template-columns: 180px 1fr 34px; align-items: center; gap: 8px; }
.mcs-ccaa-list .mcs-bar-row { grid-template-columns: 150px 1fr 34px; }
.mcs-bar-lbl  { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mcs-bar-track { background: var(--panel2); border-radius: 3px; height: 7px; overflow: hidden; }
.mcs-bar-fill  { height: 100%; background: #f97316; border-radius: 3px; transition: width .3s; }
.mcs-bar-accent { background: var(--accent2); }
.mcs-bar-num  { font-family: var(--mono); font-size: 11px; color: var(--text); text-align: right; }

/* Two pie charts side by side */
.mcs-pies {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
.mcs-pie-section {}
.mcs-pie-row {
  display: flex;
  align-items: center;
  gap: 14px;
}
.mcs-pie-legend {
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1;
  min-width: 0;
}
.mcs-pie-item  { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); }
.mcs-pie-dot   { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.mcs-pie-label { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mcs-pie-count { font-family: var(--mono); color: var(--text); white-space: nowrap; }
.mcs-pie-pct   { color: var(--muted); }
.mcs-pie-total { font-size: 10px; color: var(--muted); margin-top: 5px; padding-top: 6px; border-top: 1px solid var(--border); }

/* Chart tooltip */
.mcs-tooltip {
  position: fixed;
  z-index: 10000;
  display: none;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 10px 13px;
  pointer-events: none;
  box-shadow: 0 4px 20px rgba(0,0,0,.5);
  min-width: 150px;
}
.mcs-tooltip.visible { display: block; }
.mcs-tip-date     { font-family: var(--mono); font-size: 10px; color: var(--muted); margin-bottom: 5px; }
.mcs-tip-main     { font-family: var(--mono); font-size: 18px; font-weight: 700; color: #f97316; line-height: 1.1; }
.mcs-tip-main span { font-size: 11px; font-weight: 400; color: var(--muted); }
.mcs-tip-analyzed { font-size: 10px; color: var(--muted); margin-top: 2px; margin-bottom: 6px; }
.mcs-tip-sev      { display: flex; flex-direction: column; gap: 3px; margin-top: 7px; padding-top: 7px; border-top: 1px solid var(--border); font-size: 11px; color: var(--muted); }
.mcs-tip-sev div  { display: flex; align-items: center; gap: 6px; }
.mcs-tip-dot      { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.mcs-tip-sev strong { color: var(--text); }

/* Line chart */
.mcs-chart-empty {
  font-size: 11px;
  color: var(--muted);
  padding: 20px 0;
  text-align: center;
}

/* ── Filtros ── */
.filter-toggle-btn {
  display: none; /* solo visible en móvil, posicionado en el mapa */
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 1000; /* por encima de los panes de Leaflet */
  width: 32px;
  height: 32px;
  align-items: center;
  justify-content: center;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  cursor: pointer;
  transition: all .15s;
  box-shadow: var(--shadow);
}

.filter-toggle-btn svg { width: 15px; height: 15px; }

.filter-toggle-btn.active {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(94,234,212,.1);
}

.filter-panel {
  position: absolute;
  bottom: calc(32px + 20px);
  left: 20px;
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.fchip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 11px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
  opacity: .45;
  text-decoration: line-through;
}

.fchip.active {
  color: var(--text);
  opacity: 1;
  text-decoration: none;
}

.fchip.active:hover { border-color: var(--accent); }

.fchip-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.fchip-line { flex-shrink: 0; }

.filter-sep {
  border: none;
  border-top: 1px solid var(--border);
  margin: 6px 0;
  width: 100%;
}

/* ── Zoom control ── */
.map-zoom-ctrl {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 10px;
}

.map-zoom-btn {
  width: 32px;
  height: 32px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  transition: all .15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.map-zoom-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Nodo seleccionado ── */
.spread-cluster {
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #1e293b;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.4);
  transform-origin: center;
  animation: sc-in 0.22s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
}
.spread-cluster.sc-out {
  animation: sc-out 0.18s ease-in forwards;
}
.spread-cluster span {
  font-family: 'Space Mono', monospace;
  font-size: 11px;
  font-weight: 700;
  color: #1e293b;
  line-height: 1;
}
@keyframes sc-in {
  from { transform: scale(0.3); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}
@keyframes sc-out {
  from { transform: scale(1);   opacity: 1; }
  to   { transform: scale(0.3); opacity: 0; }
}

.sel-marker {
  position: relative;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sel-pulse {
  position: absolute;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid;
  animation: sel-pulse 1.6s ease-out infinite;
}

.sel-pulse2 {
  animation-delay: .8s;
}

.sel-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1.5px solid #1e293b;
  position: relative;
  z-index: 1;
  flex-shrink: 0;
}

@keyframes sel-pulse {
  0%   { transform: scale(.2); opacity: 1; }
  100% { transform: scale(1.3); opacity: 0; }
}

/* ── Leaflet overrides ── */
.leaflet-popup-content-wrapper {
  background: var(--panel) !important;
  border: 1px solid var(--border) !important;
  border-radius: 8px !important;
  box-shadow: var(--shadow) !important;
  color: var(--text) !important;
  font-family: var(--sans) !important;
  font-size: 13px !important;
}

.leaflet-popup-tip { background: var(--panel) !important; }
.leaflet-popup-close-button { color: var(--muted) !important; }

/* ── Loading overlay ── */
#loading {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9000;
  gap: 20px;
  transition: opacity .4s;
}

#loading.hidden { opacity: 0; pointer-events: none; }

.loader-ring {
  width: 48px;
  height: 48px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

.loader-text {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--muted);
  letter-spacing: .1em;
}

/* ── Modo embed (?embed en la URL) ── */
body.embed-mode header {
  background: transparent;
  border: none;
  padding: 0;
  position: absolute;
  top: 10px;
  right: 10px;
  width: auto;
  z-index: 1000;
}

body.embed-mode .logo,
body.embed-mode .stat,
body.embed-mode .sep,
body.embed-mode .last-update {
  display: none;
}

body.embed-mode .stats-bar {
  margin-left: 0;
}

body.embed-mode .search-input {
  background: var(--panel);
  box-shadow: var(--shadow);
  border-color: var(--border);
}

body.embed-mode .app-footer { display: none; }

/* Ocultar columna Preset en modo embed, independientemente del ancho del iframe */
body.embed-mode .malconfig-table th:nth-child(3),
body.embed-mode .malconfig-table td:nth-child(3) { display: none; }

/* ── Buscador sin resultados ─────────────────────────────────────────────── */
.search-no-results {
  padding: 10px 14px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.search-more {
  padding: 7px 14px;
  color: var(--muted);
  font-size: 11px;
  text-align: center;
  border-top: 1px solid var(--border);
  font-style: italic;
}

@media (max-width: 768px) {
  body.embed-mode .filter-toggle-btn {
    top: 58px; /* debajo del buscador flotante */
  }
}

@media (max-width: 768px) {
  .malconfig-modal { padding: 0; align-items: flex-end; }
  .malconfig-inner { max-height: 92dvh; border-radius: var(--radius) var(--radius) 0 0; }

  .malconfig-table { min-width: 0; }

  /* Ocultar columna Preset en móvil (Problemas se mantiene visible) */
  .malconfig-table th:nth-child(3),
  .malconfig-table td:nth-child(3) { display: none; }

  /* Ocultar columna Ver en móvil: la fila completa es clicable */
  .malconfig-table th:nth-child(6),
  .malconfig-table td.mc-action { display: none; }

  .malconfig-updated { display: none; }

  /* Stats en móvil */
  .mcs-pies { grid-template-columns: 1fr; }
  .mcs-bar-row { grid-template-columns: 130px 1fr 30px; }
  .mcs-ccaa-list .mcs-bar-row { grid-template-columns: 110px 1fr 30px; }
  .mcs-summary { gap: 6px; }
  .mcs-card-val { font-size: 18px; }
}

@media (max-width: 768px) {
  /* ── Header compacto ── */
  header {
    padding: 8px 12px;
    padding-top: max(8px, env(safe-area-inset-top));
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
    gap: 10px;
  }

  .logo svg { width: 20px; height: 20px; }

  .logo span { font-size: 11px; }

  .logo span em { display: none; }

  .stats-bar { gap: 10px; flex: 1; }

  /* Ocultar stats y separadores en móvil */
  .stat, .sep, .last-update { display: none; }

  /* Buscador ocupa el espacio restante */
  .search-wrap { flex: 1; }

  .search-input {
    width: 100%;
    font-size: 14px; /* evita zoom automático en iOS */
  }

  .search-dropdown {
    width: 100vw;
    left: auto;
    right: -12px;
    border-radius: 0 0 var(--radius) var(--radius);
  }

  /* ── Panel de detalle: bottom sheet ── */
  .detail-panel {
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    border-radius: 14px 14px 0 0;
    max-height: 55vh;
    overflow-y: auto;
    z-index: 700;
  }

  .detail-panel.visible {
    animation: slideUpMobile .25s ease;
  }

  @keyframes slideUpMobile {
    from { transform: translateY(100%); opacity: 0; }
    to   { transform: translateY(0);   opacity: 1; }
  }

  /* ── Filtros: fila horizontal scrollable ── */
  /* ── Botón filtro flotante en el mapa ── */
  .filter-toggle-btn { display: flex; }

  /* ── Panel filtros como dropdown ── */
  .filter-panel {
    display: none;
    position: absolute;
    bottom: auto;
    left: auto;
    width: 190px;
    flex-direction: column;
    gap: 4px;
    padding: 8px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    z-index: 2000;
  }

  .filter-panel.open { display: flex; }

  .fchip { width: 100%; }

  body.detail-open .filter-panel { display: none !important; }

  /* ── Leyenda: solo líneas en móvil (izquierda) ── */
  .legend {
    display: block;
    padding: 7px 12px;
    bottom: calc(32px + env(safe-area-inset-bottom) + 36px);
    left: 10px;
    right: auto;
  }
  .legend-title,
  .legend-item:not(.legend-edge),
  .legend-sep { display: none; }
  .legend-item.legend-edge { margin-bottom: 4px; }

  /* ── Cookie banner en móvil: apilado vertical ── */
  .cookie-banner {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    bottom: calc(32px + env(safe-area-inset-bottom) + 8px);
  }
  .cookie-text { font-size: 11px; }
  .cookie-btn  { align-self: flex-end; }

  /* ── Con panel abierto: JS posiciona la leyenda; atribución detrás ── */
  body.detail-open .leaflet-bottom {
    z-index: 600;
  }
  .legend-item.legend-edge:last-child { margin-bottom: 0; }

  /* ── Zoom y filtro más grandes para touch ── */
  .map-zoom-btn {
    width: 40px;
    height: 40px;
    font-size: 22px;
  }

  .filter-toggle-btn {
    width: 40px;
    height: 40px;
  }

  .filter-toggle-btn svg { width: 18px; height: 18px; }

  .noopt-label { display: none; }
}
