/* ============================================================================
   INDICARIA — layout.css
   Arquitectura de vistas A / B / C
   NO modifica styles.css existente.

   v1.0 — Capa 1
   v2.0 — Dark topbar + dark slider bar (profesional, sin perder legibilidad).
           Contador de indicadores por categoría (.sb-cat-count).
           Categorías colapsadas: flecha apunta derecha, rota a 90° al abrir.
   ============================================================================ */

:root {
  /* Tipografía */
  --font-sans:  'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono:  'DM Mono', 'SFMono-Regular', Consolas, monospace;

  /* Vista A — interfaz del mapa */
  --a-bg:         #f2f1ed;
  --a-surface:    #ffffff;
  --a-border:     #e4e2db;
  --a-border2:    #ccc9bf;
  --a-text:       #1a1c22;
  --a-text2:      #4a4d57;
  --a-muted:      #8a8d99;
  --a-accent:     #2563eb;
  --a-accent-s:   rgba(37, 99, 235, 0.10);
  --a-accent-g:   rgba(37, 99, 235, 0.20);

  /* v2: Topbar y slider — superficie oscura profesional */
  --chrome-bg:        #161b27;
  --chrome-border:    rgba(255, 255, 255, 0.08);
  --chrome-text:      #e8ecf5;
  --chrome-text2:     #9aa3b8;
  --chrome-muted:     #5a6178;
  --chrome-accent:    #4fffb0;
  --chrome-accent-s:  rgba(79, 255, 176, 0.12);
  --chrome-btn-bg:    rgba(255, 255, 255, 0.06);
  --chrome-btn-hover: rgba(255, 255, 255, 0.10);

  /* Sidebar — siempre oscuro */
  --sb-bg:        #13161f;
  --sb-text:      #c8ccd8;
  --sb-muted:     #464c5e;
  --sb-border:    rgba(255, 255, 255, 0.06);
  --sb-hover:     rgba(255, 255, 255, 0.05);
  --sb-active:    rgba(79, 255, 176, 0.08);
  --sb-accent:    #4fffb0;

  /* Vistas B y C */
  --b-bg:         #0f1117;
  --b-surface:    #161b27;
  --b-surface2:   #1c2235;
  --b-border:     rgba(255, 255, 255, 0.07);
  --b-border2:    rgba(255, 255, 255, 0.13);
  --b-text:       #e8ecf5;
  --b-muted:      #5a6178;
  --b-accent:     #4fffb0;
  --b-accent-s:   rgba(79, 255, 176, 0.10);

  /* Categorías */
  --cat-economia:   #f59e0b;
  --cat-salud:      #10b981;
  --cat-demografia: #8b5cf6;
  --cat-educacion:  #ef4444;
  --cat-ambiente:   #38bdf8;
  --cat-governance: #8b5cf6;

  /* Layout */
  --sb-width:     272px;
  --topbar-h:     56px;
  --slider-h:     72px;
  --radius-sm:    8px;
  --radius-md:    12px;
  --radius-lg:    16px;
  --shadow-sm:    0 2px 8px rgba(0,0,0,0.07);
  --shadow-md:    0 4px 20px rgba(0,0,0,0.10);
  --shadow-lg:    0 8px 40px rgba(0,0,0,0.15);

  --t-fast:   0.12s ease;
  --t-mid:    0.20s ease;
  --t-slow:   0.30s ease;
}

/* ── RESET ────────────────────────────────────────────────────────────────── */
.indicaria-app *, .indicaria-app *::before, .indicaria-app *::after { box-sizing: border-box; }

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

/* ============================================================================
   ROUTER DE VISTAS
   ============================================================================ */
.view { display: none; width: 100%; height: 100vh; overflow: hidden; font-family: var(--font-sans); }
.view.active { display: flex; }
#view-A { flex-direction: row; background: var(--a-bg); }
#view-B { flex-direction: column; background: var(--b-bg); }
#view-C { flex-direction: column; background: var(--b-bg); }

/* ============================================================================
   SIDEBAR (Vista A)
   ============================================================================ */
.ind-sidebar {
  width: var(--sb-width);
  min-width: var(--sb-width);
  background: var(--sb-bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 4px 0 28px rgba(0,0,0,0.22);
  z-index: 10;
  transition: transform var(--t-slow);
}

.sb-head {
  padding: 20px 18px 14px;
  border-bottom: 1px solid var(--sb-border);
  flex-shrink: 0;
}

.sb-logo {
  font-family: 'Syne', var(--font-sans);
  font-size: 20px; font-weight: 800;
  color: #ffffff; letter-spacing: -0.5px; text-decoration: none;
}
.sb-logo em { color: var(--sb-accent); font-style: normal; }

.sb-search { margin-top: 12px; position: relative; }
.sb-search input {
  width: 100%;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.09);
  border-radius: var(--radius-sm);
  padding: 8px 12px 8px 32px;
  color: #ffffff; font-family: var(--font-sans); font-size: 13px;
  outline: none; transition: border-color var(--t-mid);
}
.sb-search input::placeholder { color: var(--sb-muted); }
.sb-search input:focus { border-color: var(--sb-accent); }
.sb-search-icon {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  color: var(--sb-muted); font-size: 13px; pointer-events: none;
}

.sb-body {
  flex: 1; overflow-y: auto; padding: 8px 0;
  scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.07) transparent;
}
.sb-body::-webkit-scrollbar { width: 4px; }
.sb-body::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.07); border-radius: 2px; }

.sb-section-sep {
  padding: 14px 18px 5px;
  font-size: 10px; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--sb-muted);
  display: flex; align-items: center; gap: 8px;
}
.sb-section-sep::after { content: ''; flex: 1; height: 1px; background: var(--sb-border); }

/* Lista de países */
.sb-country-list { padding: 2px 8px 10px; }
.sb-country-item {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 10px; border-radius: var(--radius-sm);
  cursor: pointer; transition: background var(--t-fast);
}
.sb-country-item:hover { background: var(--sb-hover); }
.sb-country-item:focus { outline: 2px solid var(--sb-accent); outline-offset: -2px; }

.sb-country-icon {
  width: 26px; height: 18px; border-radius: 3px;
  background: rgba(255,255,255,0.08);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono); font-size: 9px; font-weight: 500;
  color: rgba(255,255,255,0.5); letter-spacing: 0.05em; flex-shrink: 0;
  border: 1px solid rgba(255,255,255,0.06);
}
.sb-country-name { font-size: 13px; color: var(--sb-text); flex: 1; }
.sb-country-val  { font-family: var(--font-mono); font-size: 10px; color: var(--sb-muted); white-space: nowrap; }

/* Acordeones de categorías */
.sb-cat { margin-bottom: 2px; }

.sb-cat-header {
  display: flex; align-items: center; gap: 9px; padding: 9px 18px;
  cursor: pointer; user-select: none; transition: background var(--t-fast);
}
.sb-cat-header:hover { background: var(--sb-hover); }

.sb-cat-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.sb-cat-label { font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--sb-muted); flex: 1; }

/* v2: contador de indicadores por categoría */
.sb-cat-count {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--sb-muted);
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 10px;
  padding: 1px 6px;
  line-height: 1.4;
  transition: opacity var(--t-fast);
}
.sb-cat.open .sb-cat-count { opacity: 0.5; }

.sb-cat-arrow {
  color: var(--sb-muted); font-size: 9px;
  transition: transform var(--t-mid);
  display: flex; align-items: center;
}
/* v2: cerrado por defecto, rota 90° al abrir */
.sb-cat-arrow { transform: rotate(0deg); }
.sb-cat.open .sb-cat-arrow { transform: rotate(90deg); }

.sb-cat-list { display: none; padding: 2px 0 6px; }
.sb-cat.open .sb-cat-list { display: block; }

/* Items de indicador */
.sb-ind-item {
  display: flex; align-items: flex-start; gap: 0;
  padding: 8px 18px 8px 35px;
  cursor: pointer; transition: background var(--t-fast);
  position: relative; border: none; background: transparent;
  width: 100%; text-align: left;
}
.sb-ind-item:hover { background: var(--sb-hover); }
.sb-ind-item.active { background: var(--sb-active); }
.sb-ind-item.active::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0;
  width: 3px; background: var(--sb-accent); border-radius: 0 2px 2px 0;
}
.sb-ind-name { font-size: 13px; color: var(--sb-text); line-height: 1.3; display: block; }
.sb-ind-item.active .sb-ind-name { color: #ffffff; font-weight: 500; }
.sb-ind-years { font-family: var(--font-mono); font-size: 10px; color: var(--sb-muted); margin-top: 1px; display: block; }

.sb-foot {
  padding: 12px 18px; border-top: 1px solid var(--sb-border);
  font-size: 11px; color: var(--sb-muted); flex-shrink: 0;
}

/* ── SIDEBAR MOBILE ────────────────────────────────────────────────────────── */
.sb-mobile-toggle {
  display: none;
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  z-index: 300; background: var(--sb-bg);
  border: 1px solid rgba(255,255,255,0.1); border-radius: 100px;
  padding: 10px 20px; color: #fff; font-family: var(--font-sans);
  font-size: 13px; font-weight: 500; cursor: pointer;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4); gap: 8px; align-items: center;
}
.sb-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 200; backdrop-filter: blur(2px); }
.sb-overlay.open { display: block; }

/* ============================================================================
   VISTA A — MAPA PRINCIPAL
   ============================================================================ */
.map-main { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }

/* ── v2: TOPBAR OSCURO ────────────────────────────────────────────────────── */
.map-topbar {
  background: var(--chrome-bg);
  border-bottom: 1px solid var(--chrome-border);
  padding: 0 20px;
  min-height: var(--topbar-h);
  height: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  flex-wrap: wrap;
  padding-top: 8px;
  padding-bottom: 8px;
}

.map-topbar-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--chrome-text);
  letter-spacing: -0.2px;
  line-height: 1.2;
}

.map-topbar-meta {
  font-size: 11px;
  color: var(--chrome-muted);
  font-family: var(--font-mono);
  white-space: nowrap;
  display: block;
  margin-top: 1px;
}

/* Badge de año — adapt al chrome oscuro */
.map-year-badge {
  background: var(--chrome-accent-s);
  border: 1px solid rgba(79, 255, 176, 0.25);
  color: var(--chrome-accent);
  font-family: var(--font-mono);
  font-size: 13px; font-weight: 500;
  padding: 5px 12px; border-radius: var(--radius-sm);
  white-space: nowrap;
  margin-left: auto;
}

/* Botón reset — adapt al chrome oscuro */
.map-btn-reset {
  padding: 6px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--chrome-border);
  background: var(--chrome-btn-bg);
  font-family: var(--font-sans); font-size: 12px;
  color: var(--chrome-text2); cursor: pointer;
  transition: all var(--t-fast); white-space: nowrap;
}
.map-btn-reset:hover { background: var(--chrome-btn-hover); color: var(--chrome-text); }

/* Canvas del mapa */
.map-canvas { flex: 1; position: relative; overflow: hidden; }

/* ── v2: SLIDER BAR OSCURO ────────────────────────────────────────────────── */
.map-slider-bar {
  background: var(--chrome-bg);
  border-top: 1px solid var(--chrome-border);
  padding: 10px 24px 12px;
  flex-shrink: 0;
  min-height: var(--slider-h);
}

.map-slider-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }

.map-slider-label {
  font-size: 10px;
  color: var(--chrome-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.map-slider-year {
  font-family: var(--font-mono);
  font-size: 15px; font-weight: 500;
  color: var(--chrome-accent);
}

/* Input range sobre fondo oscuro */
.map-slider-input {
  width: 100%; -webkit-appearance: none;
  height: 3px; border-radius: 4px; outline: none; cursor: pointer;
  background: linear-gradient(
    to right,
    var(--chrome-accent) 0%,
    var(--chrome-accent) var(--pct, 80%),
    rgba(255,255,255,0.12) var(--pct, 80%),
    rgba(255,255,255,0.12) 100%
  );
}
.map-slider-input::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--chrome-bg);
  border: 2.5px solid var(--chrome-accent);
  box-shadow: 0 0 8px rgba(79,255,176,0.35);
  transition: transform var(--t-fast); cursor: pointer;
}
.map-slider-input::-webkit-slider-thumb:hover { transform: scale(1.2); }
.map-slider-input::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--chrome-bg); border: 2.5px solid var(--chrome-accent); cursor: pointer;
}

.map-slider-ticks { display: flex; justify-content: space-between; margin-top: 6px; }
.map-slider-tick {
  font-family: var(--font-mono); font-size: 9px;
  color: var(--chrome-muted);
  text-align: center; line-height: 1;
}
.map-slider-tick::before {
  content: ''; display: block; width: 1px; height: 3px;
  background: currentColor; margin: 0 auto 2px;
  opacity: 0.4;
}
.map-slider-tick.active { color: var(--chrome-text2); }

/* ============================================================================
   VISTA B — COUNTRY PROFILE
   ============================================================================ */
.cp-topbar {
  background: var(--b-surface); border-bottom: 1px solid var(--b-border);
  padding: 0 28px; height: var(--topbar-h);
  display: flex; align-items: center; gap: 0; flex-shrink: 0;
}
.cp-back-btn {
  display: flex; align-items: center; gap: 7px;
  background: transparent; border: none; font-family: var(--font-sans);
  font-size: 13px; color: var(--b-muted); cursor: pointer;
  padding: 0 18px 0 0; border-right: 1px solid var(--b-border);
  margin-right: 18px; height: 100%; transition: color var(--t-fast);
}
.cp-back-btn:hover { color: var(--b-text); }
.cp-country-chip {
  display: flex; align-items: center; justify-content: center;
  width: 32px; height: 22px; background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.1); border-radius: 4px;
  font-family: var(--font-mono); font-size: 10px; font-weight: 500;
  color: rgba(255,255,255,0.6); letter-spacing: 0.05em; margin-right: 10px; flex-shrink: 0;
}
.cp-country-name { font-family: 'Syne', var(--font-sans); font-size: 17px; font-weight: 700; color: var(--b-text); }
.cp-region { font-size: 11px; color: var(--b-muted); font-family: var(--font-mono); margin-left: 10px; padding-left: 10px; border-left: 1px solid var(--b-border); }
.cp-topbar-right { margin-left: auto; text-align: right; flex-shrink: 0; }
.cp-pib-val { font-family: var(--font-mono); font-size: 14px; font-weight: 500; color: var(--b-accent); }
.cp-pib-lbl { font-size: 10px; color: var(--b-muted); }

.cp-breadcrumb {
  padding: 9px 28px; background: var(--b-surface); border-bottom: 1px solid var(--b-border);
  display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--b-muted); font-family: var(--font-mono); flex-shrink: 0;
}
.cp-breadcrumb-link { cursor: pointer; transition: color var(--t-fast); background: transparent; border: none; font-family: var(--font-mono); font-size: 11px; color: var(--b-muted); padding: 0; }
.cp-breadcrumb-link:hover { color: var(--b-text); }
.cp-breadcrumb-sep { opacity: 0.35; }
.cp-breadcrumb-current { color: var(--b-text); }

.cp-tabs {
  display: flex; gap: 6px; padding: 11px 28px; background: var(--b-bg);
  border-bottom: 1px solid var(--b-border); flex-shrink: 0; overflow-x: auto; scrollbar-width: none;
}
.cp-tabs::-webkit-scrollbar { display: none; }
.cp-tab {
  display: flex; align-items: center; gap: 6px; padding: 6px 14px;
  border-radius: 100px; border: 1px solid var(--b-border); background: transparent;
  color: var(--b-muted); font-family: var(--font-sans); font-size: 12px; font-weight: 500;
  cursor: pointer; transition: all var(--t-fast); white-space: nowrap;
}
.cp-tab:hover { border-color: var(--b-border2); color: var(--b-text); }
.cp-tab.active { background: var(--b-accent-s); border-color: rgba(79,255,176,0.25); color: var(--b-accent); }
.cp-tab-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }

.cp-body { flex: 1; overflow-y: auto; padding: 22px 28px 40px; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.07) transparent; }
.cp-body::-webkit-scrollbar { width: 4px; }
.cp-body::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.07); border-radius: 2px; }

.cp-section { margin-bottom: 28px; }
.cp-section-title { font-size: 10px; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.cp-section-title::after { content: ''; flex: 1; height: 1px; background: var(--b-border); }

.cp-cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(255px, 1fr)); gap: 12px; }

/* ── CARDS ──────────────────────────────────────────────────────────────── */
.ind-card {
  background: var(--b-surface); border: 1px solid var(--b-border);
  border-radius: var(--radius-md); padding: 16px; cursor: pointer;
  transition: all var(--t-mid); position: relative; overflow: hidden;
}
.ind-card::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px; background: var(--card-cat-color, transparent); opacity: 0.55; transition: opacity var(--t-mid); }
.ind-card:hover { border-color: var(--b-border2); box-shadow: 0 8px 32px rgba(0,0,0,0.28); transform: translateY(-1px); }
.ind-card:hover::before { opacity: 1; }
.ind-card:focus { outline: 2px solid var(--b-accent); outline-offset: 2px; }

.card-icon { width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; color: var(--card-cat-color, var(--b-muted)); opacity: 0.8; }
.card-icon svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.card-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.card-trend-badge { font-size: 10px; padding: 2px 7px; border-radius: 100px; font-weight: 500; font-family: var(--font-mono); white-space: nowrap; }
.card-trend-badge.up   { background: rgba(16,185,129,0.15); color: #34d399; }
.card-trend-badge.down { background: rgba(239,68,68,0.15);  color: #f87171; }
.card-trend-badge.flat { background: rgba(255,255,255,0.06); color: var(--b-muted); }
.card-name { font-size: 13px; font-weight: 600; color: var(--b-text); margin-bottom: 2px; letter-spacing: -0.1px; }
.card-source { font-size: 10px; color: var(--b-muted); font-family: var(--font-mono); margin-bottom: 12px; }
.card-chart { height: 64px; position: relative; margin-bottom: 10px; }
.card-chart svg { width: 100%; height: 100%; overflow: visible; }
.card-footer { display: flex; align-items: flex-end; justify-content: space-between; padding-top: 8px; border-top: 1px solid var(--b-border); }
.card-value { font-family: var(--font-mono); font-size: 17px; font-weight: 500; color: var(--b-text); letter-spacing: -0.5px; }
.card-unit { font-size: 10px; color: var(--b-muted); margin-bottom: 1px; }
.card-years { font-size: 10px; color: var(--b-muted); font-family: var(--font-mono); }

@keyframes ind-card-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.ind-card { animation: ind-card-in 0.28s ease both; }

/* ============================================================================
   VISTA C — INDICADOR EXPANDIDO
   ============================================================================ */
.ic-topbar { background: var(--b-surface); border-bottom: 1px solid var(--b-border); padding: 0 28px; height: var(--topbar-h); display: flex; align-items: center; gap: 14px; flex-shrink: 0; }
.ic-back-btn { display: flex; align-items: center; gap: 7px; background: transparent; border: none; font-family: var(--font-sans); font-size: 13px; color: var(--b-muted); cursor: pointer; padding: 0 16px 0 0; border-right: 1px solid var(--b-border); margin-right: 2px; height: 100%; transition: color var(--t-fast); }
.ic-back-btn:hover { color: var(--b-text); }
.ic-body { flex: 1; overflow-y: auto; padding: 24px 32px 48px; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.07) transparent; }
.ic-body::-webkit-scrollbar { width: 4px; }
.ic-body::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.07); border-radius: 2px; }
.ic-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 22px; gap: 20px; }
.ic-ind-name { font-family: 'Syne', var(--font-sans); font-size: 22px; font-weight: 700; color: var(--b-text); letter-spacing: -0.5px; margin-bottom: 4px; }
.ic-ind-meta { font-size: 12px; color: var(--b-muted); font-family: var(--font-mono); }
.ic-big-val { font-family: var(--font-mono); font-size: 32px; font-weight: 500; letter-spacing: -1.5px; text-align: right; }
.ic-big-unit { font-size: 11px; color: var(--b-muted); text-align: right; margin-top: 2px; }
.ic-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 20px; }
.ic-stat { background: var(--b-surface); border: 1px solid var(--b-border); border-radius: 10px; padding: 13px 15px; }
.ic-stat-val { font-family: var(--font-mono); font-size: 15px; font-weight: 500; color: var(--b-text); margin-bottom: 3px; }
.ic-stat-lbl { font-size: 10px; color: var(--b-muted); }
.ic-chart-wrap { background: var(--b-surface); border: 1px solid var(--b-border); border-radius: var(--radius-md); padding: 20px 20px 16px; margin-bottom: 20px; }
.ic-chart-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; flex-wrap: wrap; gap: 8px; }
.ic-chart-title { font-size: 11px; font-weight: 600; color: var(--b-muted); text-transform: uppercase; letter-spacing: 0.08em; }
.ic-chart-legend { display: flex; gap: 16px; font-size: 11px; color: var(--b-muted); font-family: var(--font-mono); align-items: center; flex-wrap: wrap; }
.ic-legend-item { display: flex; align-items: center; gap: 5px; }
.ic-legend-line { display: inline-block; width: 20px; height: 2px; border-radius: 2px; }
.ic-chart-area { height: 220px; position: relative; }
.ic-chart-area svg { width: 100%; height: 100%; overflow: visible; }
.ic-table-wrap { background: var(--b-surface); border: 1px solid var(--b-border); border-radius: var(--radius-md); overflow: hidden; }
.ic-table-head { padding: 13px 18px; border-bottom: 1px solid var(--b-border); display: flex; align-items: center; justify-content: space-between; }
.ic-table-title { font-size: 11px; font-weight: 600; color: var(--b-muted); text-transform: uppercase; letter-spacing: 0.08em; }
.ic-table-note { font-size: 10px; color: var(--b-muted); font-family: var(--font-mono); }
.ic-table { width: 100%; border-collapse: collapse; }
.ic-table thead tr { border-bottom: 1px solid var(--b-border); }
.ic-table th { padding: 8px 18px; font-size: 10px; font-weight: 600; color: var(--b-muted); text-transform: uppercase; letter-spacing: 0.06em; text-align: left; font-family: var(--font-mono); }
.ic-table th.right { text-align: right; }
.ic-table tbody tr { border-bottom: 1px solid rgba(255,255,255,0.03); transition: background var(--t-fast); }
.ic-table tbody tr:hover { background: rgba(255,255,255,0.03); }
.ic-table tbody tr.highlighted { background: rgba(79,255,176,0.05); }
.ic-table tbody tr:last-child { border-bottom: none; }
.ic-table td { padding: 9px 18px; font-size: 12px; color: var(--b-text); font-family: var(--font-mono); }
.ic-table td.right { text-align: right; }
.td-bar-wrap { display: flex; align-items: center; gap: 8px; }
.td-bar { height: 4px; border-radius: 2px; background: var(--b-accent); opacity: 0.45; min-width: 2px; }
.td-delta { font-size: 10px; padding: 1px 5px; border-radius: 4px; font-family: var(--font-mono); }
.td-delta.pos { color: #34d399; background: rgba(16,185,129,0.12); }
.td-delta.neg { color: #f87171; background: rgba(239,68,68,0.12); }
.td-delta.neu { color: var(--b-muted); }

/* ============================================================================
   LEYENDA FLOTANTE ENRIQUECIDA — Auditoría P1 resuelto
   Posición: bottom-left del canvas. Fondo semitransparente oscuro.
   En mobile < 768px: colapso a botón circular.
   ============================================================================ */

/* Contenedor flotante */
.map-legend-float {
  position: absolute;
  bottom: 16px;
  left: 16px;
  z-index: 1000;
  width: 220px;
  background: rgba(15, 23, 42, 0.88);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
  font-family: var(--font-sans);
  transition: opacity var(--t-mid);
}
.map-legend-float:hover { opacity: 1; }

/* Título del indicador */
.leg-title {
  font-size: 11px;
  font-weight: 600;
  color: #F1F5F9;
  letter-spacing: -0.1px;
  margin-bottom: 9px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Barra de gradiente continua */
.leg-gradient {
  width: 100%;
  height: 10px;
  border-radius: 4px;
  margin-bottom: 4px;
}

/* Labels rango min / max */
.leg-range {
  display: flex;
  justify-content: space-between;
  margin-bottom: 5px;
}
.leg-range-min,
.leg-range-max {
  font-family: var(--font-mono);
  font-size: 10px;
  color: #94A3B8;
}

/* Método de clasificación */
.leg-method {
  font-size: 10px;
  color: #64748B;
  font-style: italic;
  margin-bottom: 8px;
}

/* Footer: sin datos + cobertura */
.leg-footer {
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding-top: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  flex-wrap: wrap;
}
.leg-nodata-row {
  display: flex;
  align-items: center;
  gap: 5px;
}
.leg-nodata-chip {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  background: #8B9099;   /* v13: nuevo color sin datos — contrasta con fondo oceánico */
  flex-shrink: 0;
}
.leg-nodata-label {
  font-size: 10px;
  color: #94A3B8;
}
.leg-coverage {
  font-family: var(--font-mono);
  font-size: 10px;
  color: #64748B;
  text-align: right;
}

/* ── Mobile: colapso de leyenda ──────────────────────────────────────────── */
/* En < 768px la leyenda se oculta y aparece un botón circular */
.leg-mobile-btn {
  display: none;
  position: absolute;
  bottom: 16px;
  left: 16px;
  z-index: 1001;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(15, 23, 42, 0.90);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #94A3B8;
  font-size: 16px;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.4);
  transition: all var(--t-fast);
}
.leg-mobile-btn:hover { color: #F1F5F9; border-color: rgba(255, 255, 255, 0.25); }

/* ============================================================================
   ============================================================================ */
@media (max-width: 1024px) {
  :root { --sb-width: 240px; }
  .ic-stats { grid-template-columns: repeat(2, 1fr); }
  .cp-cards-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
}

@media (max-width: 767px) {
  /* Leyenda flotante: colapso a botón en mobile */
  .map-legend-float {
    display: none;
  }
  .map-legend-float.mobile-open {
    display: block;
    bottom: 80px; /* por encima del toggle de sidebar */
    width: calc(100% - 32px);
    max-width: 320px;
  }
  .leg-mobile-btn {
    display: flex;
  }


  #view-A { flex-direction: column; }
  .ind-sidebar {
    position: fixed; bottom: 0; left: 0; right: 0; top: auto;
    width: 100%; min-width: 100%; height: 70vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    transform: translateY(100%); transition: transform var(--t-slow);
    z-index: 250; box-shadow: 0 -8px 40px rgba(0,0,0,0.4);
  }
  .ind-sidebar.mobile-open { transform: translateY(0); }
  .ind-sidebar::before {
    content: ''; display: block; width: 36px; height: 4px;
    background: rgba(255,255,255,0.15); border-radius: 2px; margin: 10px auto 6px;
  }
  .sb-mobile-toggle { display: flex; }
  .map-main { height: 100vh; }
  .map-topbar { padding: 8px 12px; gap: 8px; flex-wrap: wrap; }
  .map-topbar-meta { display: none; }
  .map-slider-bar { padding: 8px 12px 10px; }
  .cp-topbar { padding: 0 14px; }
  .cp-region { display: none; }
  .cp-body { padding: 14px 14px 32px; }
  .ic-body { padding: 16px 14px 32px; }
  .ic-stats { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .ic-header { flex-direction: column; gap: 10px; }
  .ic-big-val { font-size: 24px; text-align: left; }
  .cp-cards-grid { grid-template-columns: 1fr; }
  .ic-table-wrap { overflow-x: auto; }
  .ic-table { min-width: 500px; }
  .ic-table .hide-mobile { display: none; }
}

@media print {
  #view-A, #view-C { display: none !important; }
  #view-B { display: block !important; height: auto !important; }
  .cp-topbar, .cp-tabs { position: static; }
  .cp-body { overflow: visible; }
  .ind-card { break-inside: avoid; }
}
