:root {
  --bg: #f3f6fb;
  --panel: #ffffff;
  --border: #d9e2ec;
  --text: #1f2937;
  --muted: #6b7280;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
  --radius: 18px;
}

/* RESET */
* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
}

body {
  min-height: 100vh;
}

/* CONTENEDOR */
.app-shell {
  width: min(1500px, 94%);
  margin: 24px auto;
}

/* =========================
   TOPBAR
========================= */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}

.topbar-left h1 {
  margin: 0 0 6px;
  font-size: 1.6rem;
}

.topbar-left p {
  margin: 0;
  color: var(--muted);
}

/* BOTONES SUPERIORES */
.topbar-right {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

/* BOTONES PRINCIPALES */
button,
select {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 0.95rem;
}

/* HOVER */
button {
  cursor: pointer;
  transition: all 0.15s ease;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.08);
}

/* =========================
   BOTONES NUEVO DE DIFERENTES DESCARGAS
========================= */

/* Excel */
.btn-excel {
  background: #16a34a;
  color: #fff;
  border: none;
}

.btn-excel:hover {
  background: #15803d;
}

/* Descargar */
.btn-download {
  background: #2563eb;
  color: #fff;
  border: none;
}

.btn-download:hover {
  background: #1d4ed8;
}

/* Compartir */
.btn-share {
  background: #9333ea;
  color: #fff;
  border: none;
}

.btn-share:hover {
  background: #7e22ce;
}

/* Facebook */
.btn-facebook {
  background: #1877f2;
  color: #fff;
  border: none;
}

.btn-facebook:hover {
  background: #155ec9;
}

/* =========================
   LAYOUT PRINCIPAL
========================= */
.main-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 18px;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.panel h2 {
  margin-top: 0;
  margin-bottom: 16px;
  font-size: 1.15rem;
}

.panel label {
  display: block;
  margin: 14px 0 6px;
  font-weight: 600;
  font-size: 0.95rem;
}

.panel select {
  width: 100%;
}

.status-box {
  margin-top: 18px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #f8fafc;
  line-height: 1.5;
}

/* INFO PANEL */
.info-panel h3 {
  margin-top: 0;
  margin-bottom: 8px;
  font-size: 1rem;
}

.info-panel p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

/* MAPA */
.map-section {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px;
  min-height: 0;
  height: fit-content;
}

#map {
  width: 100%;
  height: 520px;
  min-height: 520px;
  border-radius: 14px;
  overflow: hidden;
  display: block;
}

/* LEYENDA */
.legend {
  background: rgba(255, 255, 255, 0.96);
  padding: 12px 14px;
  border-radius: 14px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.16);
  font-size: 13px;
  line-height: 1.5;
}

.legend h4 {
  margin: 0 0 10px;
  font-size: 13px;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.legend-color {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  border: 1px solid rgba(0, 0, 0, 0.15);
}

/* POPUP */
.leaflet-popup-content {
  line-height: 1.5;
}

/* RESPONSIVE */
@media (max-width: 1050px) {
  .main-layout {
    grid-template-columns: 1fr;
  }

  #map {
    height: 600px;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }
}

.hero-section {
  max-width: 1180px;
  margin: 28px auto 20px;
  padding: 55px 35px;
  border-radius: 28px;
  background: linear-gradient(135deg, #0f766e, #1d4ed8);
  color: white;
  box-shadow: 0 18px 45px rgba(15, 23, 42, 0.22);
}

.hero-content {
  max-width: 850px;
}

.hero-badge {
  display: inline-block;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
  font-weight: 700;
  margin-bottom: 18px;
}

.hero-section h1 {
  font-size: 42px;
  line-height: 1.1;
  margin: 0 0 16px;
}

.hero-section p {
  font-size: 18px;
  line-height: 1.6;
  opacity: 0.95;
  max-width: 760px;
}

.hero-actions {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 26px;
}

.hero-btn {
  border: none;
  border-radius: 14px;
  padding: 13px 18px;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
}

.hero-btn.primary {
  background: white;
  color: #0f172a;
}

.hero-btn.secondary {
  background: rgba(255,255,255,0.18);
  color: white;
  border: 1px solid rgba(255,255,255,0.35);
}

.territory-cards {
  max-width: 1180px;
  margin: 0 auto 20px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 16px;
}

.territory-card {
  background: white;
  border-radius: 20px;
  padding: 22px;
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.08);
  border: 1px solid #e2e8f0;
}

.territory-card h3 {
  margin: 0 0 8px;
  font-size: 20px;
  color: #0f172a;
}

.territory-card p {
  margin: 0;
  color: #64748b;
}

.stats-strip {
  max-width: 1180px;
  margin: 0 auto 25px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
}

.stats-strip div {
  background: #0f172a;
  color: white;
  border-radius: 18px;
  padding: 20px;
  text-align: center;
}

.stats-strip strong {
  display: block;
  font-size: 24px;
  margin-bottom: 6px;
}

.stats-strip span {
  color: #cbd5e1;
  font-size: 14px;
}

@media (max-width: 700px) {
  .hero-section {
    padding: 35px 22px;
    margin: 18px 14px;
  }

  .hero-section h1 {
    font-size: 30px;
  }
}

.territory-card img{
    width:100%;
    height:180px;
    object-fit:cover;
    border-radius:14px;
    margin-bottom:15px;
}

.territory-card{
    overflow:hidden;
    transition:all .3s ease;
}

.territory-card:hover{
    transform:translateY(-6px);
    box-shadow:0 15px 35px rgba(0,0,0,.15);
}
/* =========================
   ADVANCED DASHBOARD ADD-ONS
========================= */
.live-dashboard {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  margin: 18px 0 20px;
}

.dash-card {
  background: linear-gradient(180deg, #ffffff, #f8fafc);
  border: 1px solid var(--border, #dbe4ef);
  border-radius: 18px;
  padding: 18px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

.dash-card span {
  display: block;
  color: #64748b;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 7px;
}

.dash-card strong {
  color: #0f172a;
  font-size: 22px;
  line-height: 1.15;
}

.control-actions {
  margin: 14px 0;
}

.wide-action {
  width: 100%;
  padding: 12px 14px;
  border-radius: 14px;
  border: none;
  background: #0f172a;
  color: #fff;
  font-weight: 800;
  cursor: pointer;
}

.analysis-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 20px;
  margin-top: 24px;
}

.analysis-card {
  background: #ffffff;
  border: 1px solid var(--border, #dbe4ef);
  border-radius: 22px;
  padding: 22px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.card-head h2 {
  margin: 0;
  font-size: 22px;
  color: #0f172a;
}

.mini-btn {
  border: 1px solid #dbe4ef;
  background: #ffffff;
  border-radius: 999px;
  padding: 8px 12px;
  margin-left: 6px;
  font-weight: 800;
  cursor: pointer;
}

.mini-btn.active {
  background: #0f172a;
  color: #ffffff;
}

.ranking-list {
  margin: 0;
  padding-left: 24px;
}

.ranking-list li {
  padding: 10px 0;
  border-bottom: 1px solid #eef2f7;
  color: #334155;
}

.ranking-list strong {
  color: #0f172a;
}

.compare-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.compare-controls select,
#dataSearchInput {
  border: 1px solid #dbe4ef;
  border-radius: 12px;
  padding: 12px;
  font-size: 15px;
  background: #fff;
}

.comparison-output {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.compare-box {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 18px;
  padding: 16px;
}

.compare-box h3 {
  margin: 0 0 12px;
  font-size: 18px;
}

.compare-box p {
  margin: 8px 0;
  color: #334155;
}

.data-explorer-card {
  margin-top: 20px;
}

.table-wrap {
  max-height: 420px;
  overflow: auto;
  border: 1px solid #e2e8f0;
  border-radius: 16px;
}

#dataExplorerTable {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

#dataExplorerTable th,
#dataExplorerTable td {
  padding: 11px 12px;
  text-align: left;
  border-bottom: 1px solid #eef2f7;
  white-space: nowrap;
}

#dataExplorerTable th {
  position: sticky;
  top: 0;
  background: #0f172a;
  color: #ffffff;
  z-index: 1;
}

.territory-flag {
  display: inline-flex;
  font-size: 24px;
  margin-bottom: 8px;
}

.about-panel {
  margin-top: 20px;
}

.metadata-panel a {
  font-weight: 800;
  color: #2563eb;
}

.map-section:fullscreen {
  background: #e8f1f8;
  padding: 20px;
}

.map-section:fullscreen #map {
  height: calc(100vh - 40px) !important;
}

@media (max-width: 900px) {
  .analysis-grid,
  .comparison-output,
  .compare-controls {
    grid-template-columns: 1fr;
  }

  .card-head {
    align-items: flex-start;
    flex-direction: column;
  }
}

/* =========================
   FINAL LAYOUT POLISH
========================= */

.analysis-grid {
  align-items: stretch;
}

.analysis-card {
  min-height: 100%;
}

.ranking-card,
.comparison-card {
  display: flex;
  flex-direction: column;
}

.ranking-list {
  flex: 1;
}

.comparison-output {
  align-items: stretch;
}

.compare-box {
  min-height: 190px;
}

.data-explorer-card {
  margin-top: 24px;
}

.about-panel {
  margin-top: 24px;
}

/* Hace que el Data Explorer se vea mÃ¡s compacto y parejo */
.table-wrap {
  max-height: 360px;
}

/* Reduce espacios blancos internos */
.analysis-card {
  padding: 20px 22px;
}

/* Alinea mejor los tÃ­tulos */
.card-head {
  min-height: 44px;
}

/* Para que el panel derecho no quede gigante si hay poco contenido */
.comparison-card {
  justify-content: flex-start;
}

/* Suaviza separaciÃ³n entre secciones */
.app-shell > section {
  margin-bottom: 22px;
}

/* =========================================================
   UNIFORM LAYOUT FIX - 2026-06-24
   Keeps page margins, columns, and ranking panel aligned.
========================================================= */
:root {
  --page-width: min(1500px, 94vw);
}

.hero-section,
.territory-cards,
.stats-strip,
.app-shell {
  width: var(--page-width);
  max-width: var(--page-width);
}

.app-shell {
  margin: 24px auto;
}

.hero-section {
  margin-left: auto;
  margin-right: auto;
}

.territory-cards,
.stats-strip {
  margin-left: auto;
  margin-right: auto;
}

.live-dashboard {
  grid-template-columns: 1.35fr .9fr .9fr 1.1fr 1.1fr 1.1fr;
  align-items: stretch;
}

.dash-card {
  min-height: 130px;
  overflow: hidden;
}

.dash-card strong {
  overflow-wrap: anywhere;
  word-break: normal;
  font-size: clamp(18px, 1.35vw, 24px);
}

.main-layout {
  grid-template-columns: 320px minmax(0, 1fr);
  align-items: start;
}

#map {
  height: 560px;
  min-height: 560px;
}

.analysis-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 22px;
  margin-top: 22px;
  align-items: stretch;
}

.analysis-info-stack {
  display: flex;
  flex-direction: column;
  gap: 22px;
  min-width: 0;
  height: 620px;
}

.analysis-info-stack .panel {
  flex: 1;
  min-height: 0;
}

.ranking-card,
.comparison-card {
  height: 620px;
  min-height: 620px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.ranking-card .card-head,
.comparison-card .card-head {
  flex: 0 0 auto;
}

.ranking-list {
  flex: 1 1 auto;
  overflow-y: auto;
  padding-right: 10px;
  margin-bottom: 0;
}

.ranking-list li {
  padding: 7px 0;
  line-height: 1.25;
}

.compare-controls {
  grid-template-columns: 1fr;
  flex: 0 0 auto;
}

.comparison-output {
  grid-template-columns: 1fr;
  overflow-y: auto;
  padding-right: 4px;
}

.compare-box {
  min-height: auto;
}

.data-explorer-card {
  margin-top: 22px;
}

.app-shell > section {
  margin-bottom: 22px;
}

@media (max-width: 1200px) {
  .analysis-grid {
    grid-template-columns: 1fr;
  }

  .analysis-info-stack,
  .ranking-card,
  .comparison-card {
    height: auto;
    min-height: auto;
  }

  .ranking-list,
  .comparison-output {
    max-height: 520px;
  }

  .live-dashboard {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 700px) {
  :root {
    --page-width: min(100% - 28px, 1500px);
  }

  .live-dashboard {
    grid-template-columns: 1fr;
  }
}

