/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:      #0a0a0a;
  --surface: #111111;
  --border:  #222222;
  --subtle:  #161616;
  --text:    #f0ece4;
  --muted:   #6b6055;
  --accent:  #D94B1E;
  --accent-dim: rgba(217,75,30,0.12);
  --header-h: 60px;
  --panel-w:  320px;
}

html { height: 100%; }

body {
  font-family: 'IBM Plex Mono', monospace;
  background: var(--bg);
  color: var(--text);
  height: 100%;
  overflow: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ── Header ── */
header {
  height: var(--header-h);
  background: #0a0a0a;
  border-bottom: 1px solid var(--accent);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px 0 16px;
  flex-shrink: 0;
  gap: 16px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.logo-img {
  height: 34px;
  width: auto;
  object-fit: contain;
  filter: brightness(0) invert(1);
  opacity: 0.9;
}

.header-titles {
  display: flex;
  flex-direction: column;
  gap: 0;
  line-height: 1;
}

header h1 {
  font-family: 'Syne', sans-serif;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  letter-spacing: -0.02em;
}

.header-sub {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.6rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.18em;
  margin-top: 2px;
}

/* ── Breadcrumb ── */
#breadcrumb {
  display: flex;
  align-items: center;
  gap: 0;
  font-size: 0.72rem;
  flex-wrap: nowrap;
  overflow: hidden;
  font-family: 'IBM Plex Mono', monospace;
}

.crumb {
  color: var(--muted);
  padding: 3px 8px;
  border-radius: 2px;
  white-space: nowrap;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: 0.03em;
}

.crumb:not(.active) {
  cursor: pointer;
  transition: color .15s, background .15s;
}
.crumb:not(.active):hover { color: var(--accent); background: var(--accent-dim); }
.crumb.active { color: var(--text); }
.crumb:not(:last-child)::after {
  content: '›';
  color: #333;
  margin-left: 8px;
  font-size: 0.9rem;
}

/* ── Layout ── */
#main {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

#map {
  flex: 1;
  min-height: 0;
}

/* ── Variables del panel ── */
#panel {
  --p-accent:     #D94B1E;
  --p-accent-dim: rgba(217, 75, 30, 0.1);
  --p-bg:         #0e0c0a;
  --p-bg2:        #131008;
  --p-text:       #f0ece4;
  --p-muted:      #5a5248;
  --p-border:     #1f1c19;
  --p-subtle:     #121008;
}

/* ── Panel lateral ── */
#panel {
  width: var(--panel-w);
  background: var(--p-bg);
  border-left: 1px solid var(--p-border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  min-height: 0;
  overflow: hidden;
  position: relative;
  color: var(--p-text);
}

/* Línea de acento vertical izquierda */
#panel::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 2px;
  background: var(--p-accent);
  z-index: 1;
}

#panel-header {
  padding: 22px 20px 18px 24px;
  border-bottom: 1px solid var(--p-border);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--p-bg);
}

#panel-title {
  font-family: 'Syne', sans-serif;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--p-text);
  line-height: 1.15;
  letter-spacing: -0.03em;
}

.btn-back {
  background: transparent;
  border: 1px solid var(--p-border);
  color: var(--p-muted);
  padding: 6px 14px 6px 10px;
  border-radius: 2px;
  cursor: pointer;
  font-size: 0.65rem;
  text-align: left;
  transition: border-color .18s, color .18s, background .18s, transform .15s;
  width: fit-content;
  font-family: 'IBM Plex Mono', monospace;
  letter-spacing: .08em;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: 6px;
}
.btn-back::before {
  content: '←';
  font-size: 0.8rem;
  line-height: 1;
  transition: transform .15s;
}
.btn-back:hover {
  border-color: var(--p-accent);
  color: var(--p-accent);
  background: var(--p-accent-dim);
}
.btn-back:hover::before {
  transform: translateX(-2px);
}
.btn-back.hidden { display: none; }

#panel-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 20px 18px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
#panel-body::-webkit-scrollbar { width: 2px; }
#panel-body::-webkit-scrollbar-track { background: transparent; }
#panel-body::-webkit-scrollbar-thumb { background: var(--p-accent); opacity: .4; }

@keyframes panel-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
#panel-body > * {
  animation: panel-in .22s ease forwards;
  flex-shrink: 0;
}

/* ── Secciones del panel ── */
.panel-hint {
  font-size: 0.75rem;
  color: var(--p-muted);
  line-height: 1.75;
  border-left: 2px solid var(--p-border);
  padding-left: 12px;
  letter-spacing: 0.01em;
}

/* Encabezados de sección */
.dept-list h3,
.legend h3,
.layers-toggle h3 {
  font-size: 0.55rem;
  text-transform: uppercase;
  letter-spacing: .22em;
  color: var(--p-muted);
  margin-bottom: 12px;
  font-family: 'IBM Plex Mono', monospace;
}

/* Lista de departamentos */
.dept-list ul { list-style: none; }
.dept-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 2px;
  cursor: pointer;
  font-size: 0.82rem;
  font-family: 'Syne', sans-serif;
  font-weight: 600;
  letter-spacing: -.01em;
  color: var(--p-text);
  margin-bottom: 1px;
  transition: background .15s, color .15s, padding-left .15s;
  border-left: 2px solid transparent;
}
.dept-list li::before {
  content: '';
  width: 7px; height: 7px;
  border-radius: 1px;
  background: var(--dot, #444);
  flex-shrink: 0;
  transition: transform .15s;
}
.dept-list li:hover {
  background: var(--p-accent-dim);
  color: var(--p-accent);
  padding-left: 18px;
  border-left-color: var(--p-accent);
}
.dept-list li:hover::before {
  transform: scale(1.3) rotate(45deg);
  background: var(--p-accent);
}

/* Stats */
.stats {
  display: flex;
  flex-direction: column;
  gap: 0;
  background: var(--p-subtle);
  border: 1px solid var(--p-border);
  border-radius: 2px;
  overflow: hidden;
  padding: 0 14px;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 10px 0;
  border-bottom: 1px solid var(--p-border);
  gap: 8px;
}
.stat-row:last-child { border-bottom: none; }
.stat-label {
  color: var(--p-muted);
  flex-shrink: 0;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-family: 'IBM Plex Mono', monospace;
}
.stat-value {
  color: var(--p-text);
  font-weight: 600;
  text-align: right;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.8rem;
  letter-spacing: .02em;
}

/* Source label — sello editorial */
.stat-source-label {
  font-size: 0.53rem;
  text-transform: uppercase;
  letter-spacing: .22em;
  color: var(--p-accent);
  background: var(--p-accent-dim);
  border-bottom: 1px solid rgba(217,75,30,0.2);
  padding: 7px 14px;
  display: flex;
  align-items: center;
  font-family: 'IBM Plex Mono', monospace;
  font-weight: 600;
  margin: 0 -14px;
}
.stat-source-label::before { display: none; }

/* Megaproyectos */
.megaproyectos {
  margin: 0 -14px;
  border-top: 1px solid var(--p-border);
  padding: 8px 14px 6px;
  background: rgba(217,75,30,0.04);
}
.mega-header {
  font-size: 0.53rem;
  text-transform: uppercase;
  letter-spacing: .18em;
  color: var(--p-accent);
  font-family: 'IBM Plex Mono', monospace;
  margin-bottom: 6px;
  opacity: .7;
}
.mega-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 0;
  font-size: 0.73rem;
  border-bottom: 1px solid var(--p-border);
}
.mega-item:last-child { border-bottom: none; }
.mega-name { color: var(--p-muted); padding-left: 8px; font-size: 0.71rem; }

.community-list {
  list-style: none;
  padding: 0;
  margin: 4px 0 0;
  max-height: 160px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--p-border) transparent;
}
.community-list li {
  padding: 5px 0;
  font-size: 0.75rem;
  color: var(--p-text);
  border-bottom: 1px solid var(--p-border);
  letter-spacing: 0.01em;
}
.community-list li:last-child { border-bottom: none; }

/* Placeholder carga afectaciones */
.afect-loading {
  display: flex;
  justify-content: center;
  padding: 12px;
  opacity: 0.25;
}
#panel .spinner { border-top-color: var(--p-accent); }

/* Leyenda */
.legend {
  background: var(--p-subtle);
  border: 1px solid var(--p-border);
  border-radius: 2px;
  padding: 12px 14px;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.72rem;
  color: var(--p-muted);
  margin-bottom: 8px;
  transition: color .15s;
  letter-spacing: 0.02em;
}
.legend-item:last-child { margin-bottom: 0; }
.legend-item:hover { color: var(--p-text); }
.legend-dot {
  width: 9px; height: 9px;
  border-radius: 1px;
  flex-shrink: 0;
}

/* Toggle de capas */
.layers-toggle { display: flex; flex-direction: column; gap: 6px; }
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--p-muted);
  padding: 4px 0;
}
.toggle-row label { display: flex; align-items: center; gap: 8px; cursor: pointer; transition: color .15s; letter-spacing: 0.02em; }
.toggle-row label:hover { color: var(--p-text); }
.toggle-row input[type=checkbox] { accent-color: var(--p-accent); }

/* Tags */
.tag {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 2px;
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  font-family: 'IBM Plex Mono', monospace;
}
.tag-resguardo { background: rgba(255,107,53,0.1); color: #FF6B35; border: 1px solid rgba(255,107,53,0.28); }
.tag-consejo   { background: rgba(78,205,196,0.08); color: #4ECDC4; border: 1px solid rgba(78,205,196,0.28); }
.tag-vereda    { background: rgba(168,216,168,0.08); color: #A8D8A8; border: 1px solid rgba(168,216,168,0.28); }

/* ── Loading screen ── */
#loading {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  gap: 0;
}

.loading-logo {
  height: 56px;
  width: auto;
  filter: brightness(0) invert(1);
  opacity: 0.85;
  margin-bottom: 24px;
  animation: loading-pulse 2s ease-in-out infinite;
}

@keyframes loading-pulse {
  0%, 100% { opacity: 0.85; }
  50% { opacity: 0.5; }
}

.loading-title {
  font-family: 'Syne', sans-serif;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
  margin-bottom: 4px;
}

.loading-sub {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.58rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.22em;
  margin-bottom: 32px;
}

#loading p {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.68rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-top: 16px;
}

.spinner {
  width: 24px; height: 24px;
  border: 2px solid #1a1a1a;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Loading overlay inside map */
.map-loading {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(10,10,10,0.9);
  border: 1px solid #222;
  border-radius: 2px;
  padding: 7px 16px;
  font-size: 0.68rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 999;
  font-family: 'IBM Plex Mono', monospace;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  box-shadow: 0 4px 16px rgba(0,0,0,.6);
}
.map-loading .spinner { width: 12px; height: 12px; border-width: 2px; }

/* ── Tooltips del mapa ── */
.map-tooltip {
  background: #0e0e0e !important;
  border: 1px solid #2a2a2a !important;
  color: #f0ece4 !important;
  border-radius: 2px !important;
  font-size: 0.75rem !important;
  font-family: 'IBM Plex Mono', monospace !important;
  padding: 6px 10px !important;
  box-shadow: 0 4px 12px rgba(0,0,0,.6) !important;
  line-height: 1.5 !important;
  letter-spacing: 0.01em !important;
}
.map-tooltip::before { display: none !important; }
