/* ==========================================================================
   Mapa de dónde vivir en España según tu sueldo - Estilos canónicos
   ========================================================================== */

:root,
[data-theme="dark"] {
  --font-main: 'Inter', system-ui, -apple-system, sans-serif;
  --font-heading: 'Outfit', 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --bg-app: #080c14;
  --bg-card: #111827;
  --bg-card-elevated: #172033;
  --bg-input: #0b1220;
  --bg-hover: rgba(255, 255, 255, 0.05);
  --border-color: rgba(255, 255, 255, 0.11);
  --border-focus: #38bdf8;

  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-soft: #cbd5e1;

  --primary: #38bdf8;
  --primary-color: #38bdf8;
  --primary-light: rgba(56, 189, 248, 0.14);
  --primary-glow: rgba(56, 189, 248, 0.25);

  --status-holgado: #10b981;
  --status-holgado-bg: rgba(16, 185, 129, 0.15);
  --status-asequible: #38bdf8;
  --status-asequible-bg: rgba(56, 189, 248, 0.15);
  --status-tension: #f59e0b;
  --status-tension-bg: rgba(245, 158, 11, 0.16);
  --status-inaccesible: #ef4444;
  --status-inaccesible-bg: rgba(239, 68, 68, 0.16);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-card: 0 12px 28px -8px rgba(0, 0, 0, 0.45);
  --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  color-scheme: dark;
}

[data-theme="light"] {
  --bg-app: #f1f5f9;
  --bg-card: #ffffff;
  --bg-card-elevated: #f8fafc;
  --bg-input: #ffffff;
  --bg-hover: rgba(15, 23, 42, 0.04);
  --border-color: #cbd5e1;
  --border-focus: #0284c7;

  --text-main: #0f172a;
  --text-muted: #475569;
  --text-soft: #334155;

  --primary: #0284c7;
  --primary-color: #0284c7;
  --primary-light: rgba(2, 132, 199, 0.1);
  --primary-glow: rgba(2, 132, 199, 0.18);

  --status-holgado: #059669;
  --status-holgado-bg: rgba(5, 150, 105, 0.12);
  --status-asequible: #0284c7;
  --status-asequible-bg: rgba(2, 132, 199, 0.12);
  --status-tension: #d97706;
  --status-tension-bg: rgba(217, 119, 6, 0.12);
  --status-inaccesible: #dc2626;
  --status-inaccesible-bg: rgba(220, 38, 38, 0.12);

  --shadow-card: 0 8px 24px -6px rgba(15, 23, 42, 0.08);
  --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23475569' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  color-scheme: light;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

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

h1, h2, h3, h4, h5, h6,
.brand-title,
.section-title,
.hero-title {
  font-family: var(--font-heading);
}

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

.tool-layout {
  margin-top: 1.25rem;
  margin-bottom: 3rem;
  flex: 1 0 auto;
}

.is-hidden {
  display: none !important;
}

/* ==========================================================================
   BARRA RÁPIDA (.tool-quick-bar)
   ========================================================================== */
.tool-quick-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow-card);
}

.quick-presets,
.quick-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.quick-bar-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-right: 0.25rem;
}

.btn-preset,
.btn-ghost-sm {
  min-height: 40px;
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-input);
  color: var(--text-soft);
  font-family: var(--font-main);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
}

.btn-preset:hover,
.btn-ghost-sm:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.btn-preset.is-active {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

/* ==========================================================================
   PANEL DE CONFIGURACIÓN DEL HOGAR Y VIVIENDA
   ========================================================================== */
.controls-hero-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: clamp(1.1rem, 2.2vw, 1.65rem);
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow-card);
}

.controls-top-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--primary-light);
  color: var(--primary);
  border: 1px solid rgba(56, 189, 248, 0.28);
  padding: 0.28rem 0.72rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.hero-title {
  margin: 0 0 0.3rem 0;
  font-size: clamp(1.25rem, 2.3vw, 1.65rem);
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.25;
}

.hero-subtitle {
  margin: 0;
  font-size: 0.92rem;
  color: var(--text-muted);
  max-width: 720px;
}

.btn-share-card {
  min-height: 42px;
  padding: 0.55rem 1.05rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--primary);
  background: linear-gradient(135deg, var(--primary), #0284c7);
  color: #ffffff;
  font-family: var(--font-main);
  font-size: 0.86rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  box-shadow: 0 6px 16px -4px var(--primary-glow);
  transition: transform 0.16s ease, filter 0.16s ease;
}

.btn-share-card:hover {
  transform: translateY(-1px);
  filter: brightness(1.06);
}

.controls-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
}

.control-block {
  background: var(--bg-card-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.95rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  min-width: 0;
}

.control-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.segmented-group {
  display: flex;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 3px;
}

.seg-btn {
  flex: 1 1 0%;
  min-height: 36px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-main);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.16s ease;
  padding: 0.35rem 0.5rem;
}

.seg-btn.is-active {
  background: var(--primary);
  color: #0b1220;
  font-weight: 700;
}

[data-theme="light"] .seg-btn.is-active {
  color: #ffffff;
}

.input-suffix-wrap {
  display: flex;
  align-items: center;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  overflow: hidden;
  min-height: 42px;
  width: 100%;
}

.input-suffix-wrap:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.form-input {
  flex: 1 1 0%;
  width: 0;
  min-width: 0;
  min-height: 40px;
  border: none;
  background: transparent;
  color: var(--text-main);
  font-family: var(--font-mono);
  font-size: 0.96rem;
  font-weight: 600;
  padding: 0.45rem 0.75rem;
  outline: none;
}

.input-suffix {
  padding: 0 0.75rem;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-muted);
  user-select: none;
}

.range-slider {
  width: 100%;
  accent-color: var(--primary);
  cursor: pointer;
  height: 24px;
}

.surface-chips {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.chip-btn {
  min-height: 34px;
  padding: 0.25rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  background: var(--bg-input);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  flex: 1 1 auto;
}

.chip-btn.is-active {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
}

/* Select canónico */
.form-select {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 42px;
  padding: 0.5rem 40px 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background-color: var(--bg-input);
  color: var(--text-main);
  font-family: var(--font-main);
  font-size: 0.88rem;
  font-weight: 600;
  appearance: none;
  -webkit-appearance: none;
  background-image: var(--select-arrow);
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px 16px;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  cursor: pointer;
}

.form-select:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.form-select option {
  background-color: var(--bg-card);
  color: var(--text-main);
}

[data-theme="light"] .form-select option {
  background-color: #ffffff;
  color: #0f172a;
}

.mortgage-options-box {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px dashed var(--border-color);
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.85rem;
}

.mortgage-field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  min-width: 0;
}

/* ==========================================================================
   COCKPIT DE KPIS
   ========================================================================== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}

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

.kpi-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-muted);
}

.kpi-value {
  font-size: clamp(1.35rem, 2.2vw, 1.75rem);
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.2;
}

.kpi-value.accent {
  color: var(--primary);
}

.kpi-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* ==========================================================================
   VISOR CARTOGRÁFICO LEAFLET + FICHA PROVINCIAL
   ========================================================================== */
.map-and-detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr);
  gap: 1.25rem;
  align-items: stretch;
  margin-bottom: 1.5rem;
}

.map-card,
.detail-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.1rem;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.map-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin-bottom: 0.85rem;
}

.map-btn-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.btn-map-tool {
  min-height: 40px;
  padding: 0.38rem 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-input);
  color: var(--text-soft);
  font-family: var(--font-main);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.16s ease;
}

.btn-map-tool:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.btn-map-tool.is-active {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

.map-canvas-wrap {
  position: relative;
  width: 100%;
  height: 490px;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border-color);
  background: #0b0f17;
}

#housing-map {
  width: 100%;
  height: 100%;
}

.map-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 1.1rem;
  margin-top: 0.85rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border-color);
  font-size: 0.78rem;
  color: var(--text-soft);
}

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

.legend-swatch {
  width: 13px;
  height: 13px;
  border-radius: 4px;
  display: inline-block;
  flex-shrink: 0;
}

.swatch-holgado { background: #10b981; }
.swatch-asequible { background: #38bdf8; }
.swatch-tension { background: #f59e0b; }
.swatch-inaccesible { background: #ef4444; }

/* Tooltip de Leaflet */
.leaflet-tooltip.housing-leaflet-tooltip {
  background: #0f172a;
  color: #f8fafc;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 10px;
  padding: 0.65rem 0.8rem;
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.45);
  font-family: var(--font-main);
}

.leaflet-tooltip.housing-leaflet-tooltip::before {
  border-top-color: #0f172a;
}

.map-tooltip-card {
  min-width: 210px;
}

.map-tooltip-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.92rem;
}

.map-tooltip-ccaa {
  font-size: 0.75rem;
  color: #94a3b8;
  margin-bottom: 0.45rem;
}

.map-tooltip-metrics {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.78rem;
}

.map-tooltip-metrics > div {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
}

/* Ficha provincial */
.detail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.65rem;
}

.detail-ccaa {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--text-muted);
  display: block;
}

.detail-title {
  margin: 0.15rem 0 0 0;
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--text-main);
}

.status-pill,
.tooltip-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.26rem 0.65rem;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 700;
  white-space: nowrap;
}

.status-pill.status-holgado,
.tooltip-pill.status-holgado {
  background: var(--status-holgado-bg);
  color: var(--status-holgado);
  border: 1px solid rgba(16, 185, 129, 0.35);
}

.status-pill.status-asequible,
.tooltip-pill.status-asequible {
  background: var(--status-asequible-bg);
  color: var(--status-asequible);
  border: 1px solid rgba(56, 189, 248, 0.35);
}

.status-pill.status-tension,
.tooltip-pill.status-tension {
  background: var(--status-tension-bg);
  color: var(--status-tension);
  border: 1px solid rgba(245, 158, 11, 0.35);
}

.status-pill.status-inaccesible,
.tooltip-pill.status-inaccesible {
  background: var(--status-inaccesible-bg);
  color: var(--status-inaccesible);
  border: 1px solid rgba(239, 68, 68, 0.35);
}

.detail-profile {
  margin: 0 0 0.9rem 0;
  font-size: 0.88rem;
  color: var(--text-soft);
}

.detail-effort-box {
  background: var(--bg-card-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.85rem;
  margin-bottom: 0.9rem;
}

.detail-effort-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.86rem;
  margin-bottom: 0.45rem;
}

.effort-bar-track {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  overflow: hidden;
}

.effort-bar-track.mini {
  height: 7px;
}

.effort-bar-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.25s ease;
}

.effort-bar-fill.status-holgado { background: var(--status-holgado); }
.effort-bar-fill.status-asequible { background: var(--status-asequible); }
.effort-bar-fill.status-tension { background: var(--status-tension); }
.effort-bar-fill.status-inaccesible { background: var(--status-inaccesible); }

.detail-verdict {
  margin: 0.5rem 0 0 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.detail-metrics-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.7rem;
  margin-bottom: 0.85rem;
}

.detail-metric {
  background: var(--bg-card-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.7rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.dm-label {
  font-size: 0.74rem;
  color: var(--text-muted);
  font-weight: 600;
}

.dm-val {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--text-main);
}

.dm-val.text-ok { color: var(--status-holgado); }
.dm-val.text-bad { color: var(--status-inaccesible); }

.dm-sub {
  font-size: 0.73rem;
  color: var(--text-muted);
}

.detail-extra-strip {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding: 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  color: var(--text-soft);
  margin-bottom: 0.9rem;
}

.detail-actions {
  margin-top: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.btn-primary-sm,
.btn-secondary-sm {
  flex: 1 1 auto;
  min-height: 40px;
  padding: 0.5rem 0.85rem;
  border-radius: var(--radius-sm);
  font-family: var(--font-main);
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
}

.btn-primary-sm {
  border: 1px solid var(--primary);
  background: var(--primary);
  color: #0b1220;
}

[data-theme="light"] .btn-primary-sm {
  color: #ffffff;
}

.btn-secondary-sm {
  border: 1px solid var(--border-color);
  background: var(--bg-input);
  color: var(--text-main);
}

/* ==========================================================================
   RANKING FILTRABLE Y TABLA COMPARATIVA
   ========================================================================== */
.explorer-section-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: clamp(1.1rem, 2vw, 1.5rem);
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-card);
}

.explorer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.section-title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text-main);
}

.results-badge {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 700;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  background: var(--primary-light);
  color: var(--primary);
}

.filters-bar {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1.15rem;
}

.filter-field {
  min-width: 0;
}

.form-text-input {
  width: 100%;
  min-height: 42px;
  padding: 0.5rem 0.8rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-input);
  color: var(--text-main);
  font-family: var(--font-main);
  font-size: 0.88rem;
}

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

.ranking-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.4rem;
}

.ranking-item-card {
  text-align: left;
  background: var(--bg-card-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.8rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  color: var(--text-main);
  font-family: var(--font-main);
  transition: border-color 0.16s ease, transform 0.16s ease;
}

.ranking-item-card:hover {
  border-color: var(--primary);
  transform: translateY(-1px);
}

.ranking-item-card.is-selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-light);
}

.ranking-item-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.45rem;
}

.ranking-pos {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--primary);
}

.ranking-names {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.ranking-names strong {
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ranking-names span {
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ranking-item-mid {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.84rem;
}

.table-scroll-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  -webkit-overflow-scrolling: touch;
}

.comparison-table {
  width: 100%;
  min-width: 780px;
  border-collapse: collapse;
  font-size: 0.86rem;
}

.comparison-table th,
.comparison-table td {
  padding: 0.75rem 0.85rem;
  border-bottom: 1px solid var(--border-color);
  text-align: left;
  vertical-align: middle;
}

.comparison-table th {
  background: var(--bg-card-elevated);
  font-family: var(--font-heading);
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-soft);
  white-space: nowrap;
}

.comparison-table tbody tr {
  cursor: pointer;
  transition: background-color 0.14s ease;
}

.comparison-table tbody tr:hover {
  background: var(--bg-hover);
}

.comparison-table tbody tr.is-selected {
  background: var(--primary-light);
}

.td-sub {
  display: block;
  font-size: 0.73rem;
  color: var(--text-muted);
}

.btn-table-focus {
  min-height: 36px;
  min-width: 54px;
  padding: 0.3rem 0.65rem;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  background: var(--bg-input);
  color: var(--primary);
  font-weight: 700;
  font-size: 0.78rem;
  cursor: pointer;
}

.empty-state,
.empty-table-cell {
  padding: 1.5rem;
  text-align: center;
  color: var(--text-muted);
}

/* ==========================================================================
   MODAL ACCESIBLE
   ========================================================================== */
.app-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(2, 6, 23, 0.76);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.app-modal-overlay.is-open {
  display: flex;
}

.app-modal {
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.55);
}

.app-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
}

.app-modal-header h3 {
  margin: 0;
  font-size: 1.15rem;
}

.app-modal-close {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background: var(--bg-input);
  color: var(--text-main);
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
}

.app-modal-body {
  padding: 1.15rem 1.25rem;
  font-size: 0.92rem;
  color: var(--text-soft);
}

.app-modal-body h4 {
  margin: 1rem 0 0.45rem 0;
  color: var(--text-main);
}

.app-modal-body ul {
  margin: 0.35rem 0 0.75rem 1.15rem;
  padding: 0;
}

.modal-note {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.app-modal-footer {
  padding: 0.9rem 1.25rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
}

.btn-modal-primary {
  min-height: 40px;
  padding: 0.5rem 1.25rem;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: #0b1220;
  font-weight: 700;
  cursor: pointer;
}

[data-theme="light"] .btn-modal-primary {
  color: #ffffff;
}

/* ==========================================================================
   ADAPTACIÓN RESPONSIVA (TABLET Y MÓVIL)
   ========================================================================== */
@media (max-width: 1120px) {
  .controls-grid,
  .kpi-grid,
  .ranking-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .map-and-detail-grid {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 680px) {
  .controls-grid,
  .kpi-grid,
  .ranking-grid,
  .mortgage-options-box,
  .filters-bar {
    grid-template-columns: 1fr;
  }

  .btn-share-card,
  .btn-preset,
  .btn-ghost-sm,
  .btn-map-tool {
    width: 100%;
  }

  .quick-presets,
  .quick-controls {
    width: 100%;
  }

  .map-canvas-wrap {
    height: 360px;
  }

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