/* ==========================================================================
   Estilos Corporativos - Mapa de Fábricas Contaminantes y Macrogranjas (PRTR)
   fijate.com/tools/mapa-fabricas-contaminantes-macrogranjas-prtr/
   ========================================================================== */

:root {
  --font-main: 'Inter', system-ui, -apple-system, sans-serif;
  --font-heading: 'Outfit', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Tema claro corporativo */
  --bg-page: #f8fafc;
  --bg-card: #ffffff;
  --bg-card-subtle: #f1f5f9;
  --bg-input: #ffffff;
  --border-color: #e2e8f0;
  --border-subtle: #cbd5e1;

  --text-main: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;

  --primary: #0284c7;
  --primary-hover: #0369a1;
  --primary-subtle: #e0f2fe;
  --primary-border: #bae6fd;

  --accent-orange: #ea580c;
  --accent-orange-subtle: #ffedd5;
  --accent-purple: #7c3aed;
  --accent-purple-subtle: #f3e8ff;
  --accent-amber: #d97706;
  --accent-amber-subtle: #fef3c7;
  --accent-emerald: #059669;
  --accent-emerald-subtle: #d1fae5;
  --accent-red: #dc2626;
  --accent-red-subtle: #fee2e2;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.05);
}

/* Modo oscuro corporativo unificado conforme a Lección 529 */
[data-theme="dark"],
html.dark,
body.dark {
  --bg-page: #0b0f17;
  --bg-card: #131b26;
  --bg-card-subtle: #1a2434;
  --bg-input: #101623;
  --border-color: #243042;
  --border-subtle: #334155;

  --text-main: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --primary: #38bdf8;
  --primary-hover: #7dd3fc;
  --primary-subtle: rgba(56, 189, 248, 0.12);
  --primary-border: #0369a1;

  --accent-orange: #fb923c;
  --accent-orange-subtle: rgba(251, 146, 60, 0.15);
  --accent-purple: #a78bfa;
  --accent-purple-subtle: rgba(167, 139, 250, 0.15);
  --accent-amber: #fbbf24;
  --accent-amber-subtle: rgba(251, 191, 36, 0.15);
  --accent-emerald: #34d399;
  --accent-emerald-subtle: rgba(52, 211, 153, 0.15);
  --accent-red: #f87171;
  --accent-red-subtle: rgba(248, 113, 113, 0.15);

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.5), 0 2px 4px -2px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.6), 0 4px 6px -4px rgba(0, 0, 0, 0.5);
}

/* Base y contención */
*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  font-family: var(--font-main);
  background-color: var(--bg-page);
  color: var(--text-main);
  line-height: 1.5;
  overflow-x: clip;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  color: var(--text-main);
  margin-top: 0;
  line-height: 1.25;
}

.text-mono {
  font-family: var(--font-mono);
}

.font-semibold {
  font-weight: 600;
}

.font-bold {
  font-weight: 700;
}

/* Colores semánticos */
.text-orange { color: var(--accent-orange) !important; }
.text-purple { color: var(--accent-purple) !important; }
.text-amber { color: var(--accent-amber) !important; }
.text-emerald { color: var(--accent-emerald) !important; }
.text-red { color: var(--accent-red) !important; }
.text-primary { color: var(--primary) !important; }

/* Layout de la herramienta con sidebar canónico */
.main-wrapper.tool-layout {
  max-width: 1200px;
  margin: 1.5rem auto 3rem;
  padding: 0 1rem;
  box-sizing: border-box;
  flex: 1 0 auto;
  width: 100%;
}

.tool-with-sidebar {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
  width: 100%;
}

.tool-main-content {
  flex: 1 1 0%;
  min-width: 0;
  width: 100%;
}

/* Sidebar sticky desktop >= 1536px gestionado por ads.css */
.tool-ad-sidebar {
  flex: 0 0 300px;
  width: 300px;
}

/* Tarjeta Hero de Búsqueda */
.hero-search-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-sm);
}

.hero-badge-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-full);
  background: var(--primary-subtle);
  color: var(--primary);
  font-size: 0.8125rem;
  font-weight: 600;
  margin-bottom: 0.875rem;
}

.hero-title {
  font-size: 1.625rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  letter-spacing: -0.02em;
}

.hero-subtitle {
  color: var(--text-secondary);
  font-size: 0.9375rem;
  margin-bottom: 1.5rem;
  max-width: 900px;
}

/* Barra de búsqueda con input y geolocalización */
.search-bar-wrapper {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.search-input-box {
  position: relative;
  flex: 1 1 0%;
  min-width: 0;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 1rem;
  color: var(--text-muted);
  pointer-events: none;
}

.search-input {
  width: 100%;
  height: 46px;
  padding: 0 2.5rem 0 2.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-size: 0.9375rem;
  font-family: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.search-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-subtle);
}

.btn-clear-query {
  position: absolute;
  right: 0.75rem;
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.btn-clear-query:hover {
  background: var(--bg-card-subtle);
  color: var(--text-main);
}

.btn-geo-action {
  height: 46px;
  padding: 0 1.25rem;
  border-radius: var(--radius-md);
  background: var(--primary);
  color: #ffffff;
  border: none;
  font-size: 0.875rem;
  font-weight: 600;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s ease, transform 0.1s ease;
}

[data-theme="dark"] .btn-geo-action {
  color: #0b0f17;
  font-weight: 700;
}

.btn-geo-action:hover {
  background: var(--primary-hover);
}

/* Selector rápido de radio de distancia */
.radius-selector-area {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.radius-label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.radius-pills {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.radius-pill {
  height: 36px;
  min-height: 36px;
  padding: 0 0.875rem;
  border-radius: var(--radius-full);
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-size: 0.8125rem;
  font-weight: 600;
  font-family: var(--font-mono);
  cursor: pointer;
  transition: all 0.15s ease;
}

.radius-pill:hover {
  border-color: var(--border-subtle);
  color: var(--text-main);
}

.radius-pill.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

[data-theme="dark"] .radius-pill.active {
  color: #0b0f17;
  font-weight: 700;
}

/* Cuadrícula de filtros desplegables */
.filters-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.filter-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.filter-label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.select-wrapper {
  position: relative;
  width: 100%;
}

.select-wrapper::after {
  content: "";
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 12px;
  height: 8px;
  background-color: var(--text-muted);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  pointer-events: none;
}

.filter-select {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  height: 42px;
  padding: 0 40px 0 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-size: 0.875rem;
  font-family: inherit;
  appearance: none;
  cursor: pointer;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  transition: border-color 0.15s ease;
}

.filter-select option {
  background: var(--bg-card);
  color: var(--text-main);
  padding: 0.5rem;
}

.filter-select:focus {
  outline: none;
  border-color: var(--primary);
}

/* Barra de acciones inferiores de filtros y conmutador */
.filters-action-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border-color);
  flex-wrap: wrap;
}

.active-chips-area {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-full);
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.filter-chip-remove {
  background: transparent;
  border: none;
  padding: 0;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
}

.filter-chip-remove:hover {
  color: var(--accent-red);
}

.actions-right {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-left: auto;
}

.btn-text-reset {
  background: transparent;
  border: none;
  color: var(--accent-red);
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0.4rem 0.6rem;
  border-radius: var(--radius-sm);
  transition: background-color 0.15s ease;
}

.btn-text-reset:hover {
  background: var(--accent-red-subtle);
}

.view-switcher {
  display: inline-flex;
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 3px;
  gap: 3px;
}

.btn-switcher {
  height: 34px;
  padding: 0 0.875rem;
  border: none;
  background: transparent;
  border-radius: calc(var(--radius-md) - 3px);
  color: var(--text-secondary);
  font-size: 0.8125rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: all 0.15s ease;
}

.btn-switcher.active {
  background: var(--bg-card);
  color: var(--text-main);
  box-shadow: var(--shadow-sm);
}

/* Barra de métricas y KPIs */
.kpis-bar {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.875rem;
  margin-bottom: 1.5rem;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-sm);
}

.kpi-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.kpi-value {
  font-size: 1.375rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.1;
  margin-bottom: 0.25rem;
}

.kpi-subtext {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

/* SECCIÓN 1: Visor de Mapa Satélite */
.map-view-wrapper {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  margin-bottom: 2rem;
  box-shadow: var(--shadow-sm);
}

.map-header-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.map-section-title {
  font-size: 1.125rem;
  font-weight: 700;
  margin-bottom: 0.2rem;
}

.map-legend-hint {
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.map-layer-selector {
  display: flex;
  gap: 0.4rem;
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  padding: 3px;
}

.btn-layer-pill {
  height: 30px;
  padding: 0 0.75rem;
  border-radius: var(--radius-full);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-layer-pill.active {
  background: var(--primary);
  color: #ffffff;
}

[data-theme="dark"] .btn-layer-pill.active {
  color: #0b0f17;
  font-weight: 700;
}

.prtr-map-canvas {
  width: 100%;
  height: 540px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  overflow: hidden;
  z-index: 10;
}

/* Anti-colisión en controles Leaflet */
.leaflet-top.leaflet-left {
  top: 10px;
  left: 10px;
}

/* Adaptación de Leaflet a modo oscuro */
[data-theme="dark"] .leaflet-popup-content-wrapper {
  background: #131b26;
  color: #f8fafc;
  border: 1px solid #243042;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.7);
}

[data-theme="dark"] .leaflet-popup-tip {
  background: #131b26;
}

[data-theme="dark"] .leaflet-control-zoom a {
  background-color: #131b26;
  color: #f8fafc;
  border-color: #243042;
}

[data-theme="dark"] .leaflet-control-zoom a:hover {
  background-color: #1a2434;
}

/* Popup de Leaflet personalizado */
.prtr-popup {
  padding: 0.25rem;
  font-family: var(--font-main);
}

.prtr-popup-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-full);
  margin-bottom: 0.4rem;
}

.badge-macrogranja { background: var(--accent-orange-subtle); color: var(--accent-orange); }
.badge-quimica { background: var(--accent-purple-subtle); color: var(--accent-purple); }
.badge-residuos { background: var(--accent-amber-subtle); color: var(--accent-amber); }
.badge-cementera { background: var(--bg-card-subtle); color: var(--text-secondary); border: 1px solid var(--border-color); }
.badge-metal { background: var(--primary-subtle); color: var(--primary); }
.badge-energia { background: #fef9c3; color: #a16207; }
.badge-agro { background: var(--accent-emerald-subtle); color: var(--accent-emerald); }

.prtr-popup-title {
  font-size: 0.9375rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
  line-height: 1.3;
}

.prtr-popup-loc {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.prtr-popup-dist {
  font-size: 0.8125rem;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--primary);
  margin-bottom: 0.75rem;
}

.btn-popup-detail {
  display: block;
  width: 100%;
  padding: 0.4rem 0.75rem;
  background: var(--primary);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

[data-theme="dark"] .btn-popup-detail {
  color: #0b0f17;
  font-weight: 700;
}

.btn-popup-detail:hover {
  background: var(--primary-hover);
}

/* Barra de leyenda del mapa */
.map-legend-bar {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  margin-top: 0.875rem;
  flex-wrap: wrap;
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.legend-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid #ffffff;
  box-shadow: 0 0 2px rgba(0, 0, 0, 0.4);
}

.dot-macrogranja { background: #ea580c; }
.dot-quimica { background: #7c3aed; }
.dot-residuos { background: #d97706; }
.dot-cementera { background: #64748b; }
.dot-metal { background: #0284c7; }
.dot-energia { background: #eab308; }
.dot-agro { background: #059669; }

/* SECCIÓN 2: Listado y Tarjetas */
.cards-view-wrapper {
  margin-bottom: 2rem;
}

.cards-header-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.cards-section-title {
  font-size: 1.125rem;
  font-weight: 700;
  margin-bottom: 0;
}

.cards-order-label {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

.complexes-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.complex-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.complex-card:hover {
  transform: translateY(-2px);
  border-color: var(--primary-border);
  box-shadow: var(--shadow-md);
}

.card-top-meta {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.65rem;
}

.distance-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-full);
  background: var(--primary-subtle);
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 700;
  font-family: var(--font-mono);
  white-space: nowrap;
}

.card-title {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 0.35rem;
  line-height: 1.3;
}

.card-titular {
  font-size: 0.8125rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.card-location {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8125rem;
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
}

.card-substances-list {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
  flex: 1 0 auto;
}

.substance-chip {
  padding: 0.15rem 0.45rem;
  border-radius: var(--radius-sm);
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-secondary);
  font-family: var(--font-mono);
}

.card-footer-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border-color);
  margin-top: auto;
}

.impact-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  font-weight: 600;
}

.impact-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.impact-dot.alto { background: var(--accent-red); }
.impact-dot.medio { background: var(--accent-amber); }
.impact-dot.moderado { background: var(--accent-emerald); }

.btn-card-detail {
  padding: 0.4rem 0.875rem;
  border-radius: var(--radius-sm);
  background: var(--bg-card-subtle);
  color: var(--primary);
  border: 1px solid var(--border-color);
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-card-detail:hover {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

[data-theme="dark"] .btn-card-detail:hover {
  color: #0b0f17;
}

/* Estados de carga y vacío */
.state-box {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 3rem 1.5rem;
  text-align: center;
  margin-bottom: 1.5rem;
}

.state-box h4 {
  font-size: 1.125rem;
  margin-top: 1rem;
  margin-bottom: 0.5rem;
}

.state-box p {
  color: var(--text-secondary);
  font-size: 0.9375rem;
  max-width: 500px;
  margin: 0 auto 1.25rem;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border-color);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto;
}

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

.btn-pill-action {
  height: 40px;
  padding: 0 1.25rem;
  border-radius: var(--radius-full);
  background: var(--primary);
  color: #ffffff;
  border: none;
  font-weight: 600;
  cursor: pointer;
}

/* Paginación */
.pagination-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-top: 1.5rem;
}

.btn-pagination {
  height: 40px;
  padding: 0 1rem;
  border-radius: var(--radius-md);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  font-size: 0.875rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-pagination:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-pagination:not(:disabled):hover {
  background: var(--bg-card-subtle);
  border-color: var(--border-subtle);
}

.pagination-info {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

/* MODAL DE FICHA TÉCNICA Y EMISIONES */
.prtr-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(11, 15, 23, 0.7);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  overflow-y: auto;
}

.prtr-modal-dialog {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  max-width: 820px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: modalIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.96) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.prtr-modal-header {
  padding: 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  background: var(--bg-card-subtle);
}

.modal-badge-row {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.4rem;
  flex-wrap: wrap;
}

.modal-tag-badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-full);
  background: var(--primary-subtle);
  color: var(--primary);
}

.modal-impact-badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-full);
  background: var(--accent-red-subtle);
  color: var(--accent-red);
}

.modal-prtr-code {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-full);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
}

.modal-complex-name {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
  line-height: 1.3;
}

.modal-complex-location {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 0;
}

.btn-close-modal {
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  flex-shrink: 0;
}

.btn-close-modal:hover {
  background: var(--border-color);
  color: var(--text-main);
}

.prtr-modal-body {
  padding: 1.5rem;
  overflow-y: auto;
  flex: 1 1 auto;
}

.modal-summary-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.875rem;
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
  margin-bottom: 1.25rem;
}

.summary-cell {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.summary-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 600;
}

.summary-val {
  font-size: 0.875rem;
  color: var(--text-main);
}

.modal-tabs-bar {
  display: flex;
  gap: 0.5rem;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 1.25rem;
  overflow-x: auto;
}

.modal-tab-btn {
  padding: 0.6rem 1rem;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: all 0.15s ease;
}

.modal-tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.tab-section-intro {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

/* Tablas semánticas en modal */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
  text-align: left;
}

.data-table th {
  background: var(--bg-card-subtle);
  padding: 0.65rem 0.875rem;
  color: var(--text-secondary);
  font-weight: 600;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.data-table td {
  padding: 0.75rem 0.875rem;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-main);
  vertical-align: top;
}

.data-table tr:last-child td {
  border-bottom: none;
}

.data-table tr:hover td {
  background: var(--bg-card-subtle);
}

.substance-desc-box {
  margin-top: 0.35rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.odor-tag {
  color: var(--accent-orange);
  font-weight: 600;
}

.health-tag {
  color: var(--accent-red);
  font-weight: 600;
}

/* Métricas de residuos */
.waste-metrics-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}

.waste-metric-card {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
}

.waste-metric-label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.4rem;
}

.waste-metric-value {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 0.35rem;
}

.waste-metric-note {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Consejos para vivienda en modal */
.housing-advice-box {
  background: var(--primary-subtle);
  border: 1px solid var(--primary-border);
  border-radius: var(--radius-md);
  padding: 1.25rem;
}

.advice-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  color: var(--primary);
}

.advice-header h4 {
  font-size: 1rem;
  font-weight: 700;
  margin: 0;
  color: var(--primary);
}

.advice-distance-badge {
  display: inline-block;
  padding: 0.3rem 0.75rem;
  border-radius: var(--radius-full);
  background: var(--bg-card);
  border: 1px solid var(--primary-border);
  font-size: 0.8125rem;
  color: var(--text-main);
  margin-bottom: 0.875rem;
}

.advice-text-content {
  font-size: 0.875rem;
  line-height: 1.6;
  color: var(--text-main);
}

.prtr-modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-color);
  background: var(--bg-card-subtle);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
}

.btn-modal-action {
  height: 40px;
  padding: 0 1.25rem;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  transition: all 0.15s ease;
}

.btn-close-action {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
}

.btn-close-action:hover {
  background: var(--border-color);
}

.btn-copy-action {
  background: var(--primary);
  border: 1px solid var(--primary);
  color: #ffffff;
}

[data-theme="dark"] .btn-copy-action {
  color: #0b0f17;
  font-weight: 700;
}

.btn-copy-action:hover {
  background: var(--primary-hover);
}

/* Guía SEO y acordeón */
.seo-guide-section {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 2rem;
  margin-bottom: 2rem;
  box-shadow: var(--shadow-sm);
}

.guide-title {
  font-size: 1.375rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.guide-intro {
  color: var(--text-secondary);
  font-size: 0.9375rem;
  margin-bottom: 1.5rem;
  max-width: 800px;
}

.accordion-group {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.accordion-item {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-card);
}

.accordion-header {
  padding: 1rem 1.25rem;
  font-weight: 600;
  font-size: 0.9375rem;
  color: var(--text-main);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  user-select: none;
  background: var(--bg-card);
  transition: background-color 0.15s ease;
}

.accordion-header::-webkit-details-marker {
  display: none;
}

.accordion-header:hover {
  background: var(--bg-card-subtle);
}

.accordion-icon {
  color: var(--text-muted);
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.accordion-item[open] .accordion-icon {
  transform: rotate(180deg);
}

.accordion-body {
  padding: 1rem 1.25rem 1.25rem;
  border-top: 1px solid var(--border-color);
  color: var(--text-secondary);
  font-size: 0.875rem;
  line-height: 1.6;
}

.accordion-body p:last-child {
  margin-bottom: 0;
}

.accordion-body ul, .accordion-body ol {
  padding-left: 1.25rem;
  margin: 0.75rem 0;
}

.accordion-body li {
  margin-bottom: 0.4rem;
}

/* Toast de notificación temporal */
.toast-notice {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #0f172a;
  color: #f8fafc;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: 0.875rem;
  font-weight: 600;
  z-index: 2000;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  animation: toastIn 0.2s ease;
}

[data-theme="dark"] .toast-notice {
  background: #38bdf8;
  color: #0b0f17;
}

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

/* ==========================================================================
   Responsive y adaptaciones táctiles (móvil y tablet)
   ========================================================================== */
@media (max-width: 1024px) {
  .filters-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .kpis-bar {
    grid-template-columns: repeat(3, 1fr);
  }

  .complexes-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .hero-search-card {
    padding: 1.25rem;
  }

  .search-bar-wrapper {
    flex-direction: column;
  }

  .btn-geo-action {
    width: 100%;
    justify-content: center;
    height: 44px;
  }

  .filters-grid {
    grid-template-columns: 1fr;
  }

  .kpis-bar {
    grid-template-columns: repeat(2, 1fr);
  }

  .prtr-map-canvas {
    height: 400px;
  }

  .complexes-grid {
    grid-template-columns: 1fr;
  }

  .modal-summary-grid {
    grid-template-columns: 1fr;
  }

  .waste-metrics-grid {
    grid-template-columns: 1fr;
  }

  .actions-right {
    width: 100%;
    justify-content: space-between;
  }

  .map-header-tools {
    flex-direction: column;
    align-items: flex-start;
  }

  .map-layer-selector {
    width: 100%;
    justify-content: space-between;
  }

  .btn-layer-pill {
    flex: 1;
    text-align: center;
  }
}

@media (max-width: 480px) {
  .kpis-bar {
    grid-template-columns: 1fr;
  }

  .radius-selector-area {
    flex-direction: column;
    align-items: flex-start;
  }

  .radius-pills {
    width: 100%;
  }

  .radius-pill {
    flex: 1 1 30%;
    text-align: center;
  }
}
