/**
 * Fijate Tools - Mapa de Apellidos de España y Origen de tu Linaje
 * Estilos canónicos corporativos, cartografía coroplética y controles táctiles
 */

:root {
  --font-main: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-heading: 'Outfit', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Paleta base clara */
  --bg-primary: #f8fafc;
  --bg-card: #ffffff;
  --bg-card-subtle: #f1f5f9;
  --bg-input: #ffffff;
  --border-color: #e2e8f0;
  --border-focus: #f59e0b;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;

  --accent-gold: #f59e0b;
  --accent-gold-hover: #d97706;
  --accent-red: #e11d48;
  --accent-blue: #2563eb;

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

[data-theme="dark"] {
  --bg-primary: #0b0f17;
  --bg-card: #111827;
  --bg-card-subtle: #1e293b;
  --bg-input: #0f172a;
  --border-color: #1e293b;
  --border-focus: #f59e0b;
  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;

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

/* =========================================================================
   1. RESET Y ESTRUCTURA CANÓNICA
   ========================================================================= */
*, *::before, *::after {
  box-sizing: border-box;
}

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

.tool-layout {
  max-width: 1200px;
  width: 100%;
  margin: 1.5rem auto 3rem;
  padding: 0 1rem;
  flex: 1 0 auto;
}

.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%;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

/* Tipografías auxiliares */
.font-mono {
  font-family: var(--font-mono);
}

.text-amber {
  color: var(--accent-gold);
}

.text-muted {
  color: var(--text-muted);
}


/* =========================================================================
   3. SECCIÓN HERO Y FORMULARIO DE BÚSQUEDA
   ========================================================================= */
.lineage-hero-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 1rem;
  padding: 1.75rem;
  box-shadow: var(--shadow-md);
  position: relative;
  overflow: hidden;
}

.lineage-hero-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, #f59e0b, #e11d48, #3b82f6);
}

.hero-header-box {
  margin-bottom: 1.5rem;
}

.hero-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent-gold);
  background: rgba(245, 158, 11, 0.12);
  padding: 0.25rem 0.65rem;
  border-radius: 9999px;
  margin-bottom: 0.5rem;
}

.hero-title {
  font-family: var(--font-heading);
  font-size: 1.85rem;
  font-weight: 800;
  margin: 0 0 0.5rem;
  color: var(--text-primary);
  line-height: 1.25;
}

.hero-subtitle {
  font-size: 0.98rem;
  color: var(--text-secondary);
  margin: 0;
  max-width: 750px;
}

.lineage-form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.25rem;
}

@media (min-width: 768px) {
  .lineage-form-grid {
    grid-template-columns: 1fr 1fr auto;
    align-items: flex-end;
  }
}

.form-field-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.form-label {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-primary);
}

.form-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.form-input-icon {
  position: absolute;
  left: 0.9rem;
  font-size: 1.1rem;
  color: var(--text-muted);
  pointer-events: none;
}

.form-input-text {
  width: 100%;
  height: 46px;
  min-height: 40px;
  padding: 0 1rem 0 2.6rem;
  font-family: var(--font-main);
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 0.6rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-input-text:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.2);
}

.btn-primary-action {
  height: 46px;
  min-height: 40px;
  padding: 0 1.5rem;
  font-family: var(--font-heading);
  font-size: 1.05rem;
  font-weight: 700;
  color: #ffffff;
  background: linear-gradient(135deg, #f59e0b, #d97706);
  border: none;
  border-radius: 0.6rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  box-shadow: 0 4px 10px rgba(245, 158, 11, 0.3);
  transition: transform 0.1s ease, filter 0.15s ease;
  width: 100%;
}

.btn-primary-action:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

.btn-primary-action:active {
  transform: translateY(1px);
}

/* Sugerencias y presets rápidos */
.presets-container {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px dashed var(--border-color);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.presets-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.btn-preset-surname {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  background-color: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: 9999px;
  padding: 0.3rem 0.75rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-preset-surname:hover {
  color: var(--text-primary);
  background-color: rgba(245, 158, 11, 0.15);
  border-color: var(--accent-gold);
}

/* =========================================================================
   4. TARJETAS KPIS DE LINAJE
   ========================================================================= */
.kpi-cockpit-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
}

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

.kpi-card-cuna {
  border-color: rgba(245, 158, 11, 0.4);
  background: linear-gradient(180deg, var(--bg-card) 0%, rgba(245, 158, 11, 0.05) 100%);
}

.kpi-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.kpi-label {
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.kpi-badge {
  font-size: 0.75rem;
  font-weight: 700;
  background: rgba(245, 158, 11, 0.15);
  color: var(--accent-gold);
  padding: 0.15rem 0.45rem;
  border-radius: 0.3rem;
}

.kpi-value-row {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin: 0.2rem 0;
}

.kpi-value-main {
  font-family: var(--font-heading);
  font-size: 2.1rem;
  font-weight: 800;
  line-height: 1.1;
  color: var(--text-primary);
}

.kpi-value-rate {
  font-family: var(--font-mono);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent-gold);
}

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

/* =========================================================================
   5. CONTENEDOR DEL MAPA Y CONTROLES
   ========================================================================= */
.map-section-wrapper {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 1rem;
  padding: 1.25rem;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

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

.map-view-tabs {
  display: inline-flex;
  background-color: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  padding: 0.2rem;
  gap: 0.2rem;
}

.map-view-tab {
  background: transparent;
  border: none;
  font-family: var(--font-heading);
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-secondary);
  padding: 0.4rem 0.85rem;
  border-radius: 0.35rem;
  cursor: pointer;
  transition: all 0.15s ease;
  min-height: 36px;
}

.map-view-tab:hover {
  color: var(--text-primary);
}

.map-view-tab.active {
  background-color: var(--bg-card);
  color: var(--accent-gold);
  box-shadow: var(--shadow-sm);
}

.map-quick-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.btn-map-control {
  background-color: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-family: var(--font-main);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.35rem 0.75rem;
  border-radius: 0.4rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 36px;
  transition: all 0.15s ease;
}

.btn-map-control:hover {
  background-color: var(--border-color);
}

.btn-map-control.active {
  border-color: var(--accent-gold);
  color: var(--accent-gold);
}

/* Lienzo del mapa */
.map-canvas-container {
  position: relative;
  width: 100%;
  height: 540px;
  border-radius: 0.75rem;
  overflow: hidden;
  border: 1px solid var(--border-color);
  background-color: #0b0f17;
}

@media (max-width: 768px) {
  .map-canvas-container {
    height: 400px;
  }
}

#lineage-map {
  width: 100%;
  height: 100%;
  background: #0b0f17;
}

/* Leyenda del mapa */
.map-legend-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background-color: var(--bg-card-subtle);
  border-radius: 0.6rem;
  border: 1px solid var(--border-color);
}

.legend-scale-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.legend-gradient-bar {
  width: 140px;
  height: 12px;
  border-radius: 9999px;
  background: linear-gradient(90deg, #3b82f6 0%, #0ea5e9 25%, #10b981 50%, #f59e0b 75%, #e11d48 100%);
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.legend-label-rate {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

/* Tooltips de Leaflet estilizados */
.fijate-custom-tooltip {
  background: rgba(15, 23, 42, 0.95) !important;
  border: 1px solid #f59e0b !important;
  border-radius: 0.5rem !important;
  color: #f8fafc !important;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5) !important;
  padding: 0.75rem !important;
}

.lineage-map-tooltip {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 180px;
}

.tooltip-title {
  font-family: var(--font-heading);
  font-size: 1rem;
  font-weight: 700;
  color: #ffffff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
  padding-bottom: 0.25rem;
  margin-bottom: 0.2rem;
}

.tooltip-ccaa {
  font-size: 0.78rem;
  font-weight: 400;
  color: #94a3b8;
}

.tooltip-cradle-badge {
  font-size: 0.75rem;
  font-weight: 700;
  background: rgba(245, 158, 11, 0.2);
  color: #f59e0b;
  padding: 0.2rem 0.4rem;
  border-radius: 0.25rem;
  margin-bottom: 0.25rem;
  text-align: center;
}

.tooltip-row {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.82rem;
}

.tooltip-lbl {
  color: #94a3b8;
}

.tooltip-val {
  font-weight: 600;
  color: #ffffff;
}

/* =========================================================================
   6. FICHAS HERÁLDICAS Y ETIMOLOGÍA
   ========================================================================= */
.heraldic-section-wrapper {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
}

@media (min-width: 900px) {
  .heraldic-section-wrapper {
    grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
  }
}

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

.heraldic-card-header {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 1rem;
}

.heraldic-crest-wrapper {
  width: 75px;
  height: 90px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  padding: 0.4rem;
}

.crest-svg {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

.heraldic-header-text {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.heraldic-badge {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--accent-gold);
  letter-spacing: 0.05em;
}

.heraldic-surname {
  font-family: var(--font-heading);
  font-size: 1.85rem;
  font-weight: 800;
  margin: 0;
  color: var(--text-primary);
  line-height: 1.1;
}

.heraldic-type {
  font-size: 0.88rem;
  color: var(--text-secondary);
}

.heraldic-body {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.heraldic-item {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.heraldic-lbl {
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
}

.heraldic-desc {
  font-size: 0.95rem;
  color: var(--text-secondary);
  margin: 0;
  line-height: 1.5;
}

.heraldic-meta-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
}

.heraldic-meta-box {
  background-color: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  padding: 0.6rem 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.meta-box-lbl {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
}

.meta-box-val {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text-primary);
}

.heraldic-blazon {
  background: rgba(245, 158, 11, 0.06);
  border-left: 3px solid var(--accent-gold);
  padding: 0.75rem 1rem;
  border-radius: 0 0.5rem 0.5rem 0;
}

.blazon-text {
  font-size: 0.88rem;
  font-style: italic;
  color: var(--text-secondary);
  margin: 0.35rem 0 0;
  line-height: 1.45;
}

/* =========================================================================
   7. GRÁFICO DE BARRAS HORIZONTAL
   ========================================================================= */
.chart-section-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 1rem;
  padding: 1.5rem;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.chart-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chart-title {
  font-family: var(--font-heading);
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0;
  color: var(--text-primary);
}

.chart-bars-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.chart-row {
  display: grid;
  grid-template-columns: 140px 1fr;
  align-items: center;
  gap: 1rem;
}

@media (max-width: 600px) {
  .chart-row {
    grid-template-columns: 110px 1fr;
    gap: 0.5rem;
  }
}

.chart-label-col {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  overflow: hidden;
}

.chart-rank {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  width: 22px;
}

.chart-name {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.badge-mini-cuna {
  font-size: 0.68rem;
  font-weight: 700;
  background-color: rgba(225, 29, 72, 0.15);
  color: var(--accent-red);
  padding: 0.1rem 0.35rem;
  border-radius: 0.25rem;
}

.chart-bar-col {
  position: relative;
  height: 28px;
  background-color: var(--bg-card-subtle);
  border-radius: 0.35rem;
  overflow: hidden;
  display: flex;
  align-items: center;
  padding: 0 0.6rem;
}

.chart-bar-fill {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  background: linear-gradient(90deg, #3b82f6, #f59e0b);
  border-radius: 0.35rem;
  opacity: 0.75;
  transition: width 0.4s ease;
}

.is-cradle-row .chart-bar-fill {
  background: linear-gradient(90deg, #f59e0b, #e11d48);
  opacity: 0.9;
}

.chart-bar-value {
  position: relative;
  z-index: 2;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-primary);
}

.chart-count-muted {
  font-weight: 400;
  color: var(--text-muted);
}

/* =========================================================================
   8. MODAL DE TARJETA PARA COMPARTIR
   ========================================================================= */
.custom-modal-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  z-index: 9999;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.custom-modal-overlay.active {
  display: flex;
}

.custom-modal-box {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 1rem;
  max-width: 850px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.modal-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-family: var(--font-heading);
  font-size: 1.35rem;
  font-weight: 700;
  margin: 0;
  color: var(--text-primary);
}

.btn-close-modal {
  background: transparent;
  border: none;
  font-size: 1.5rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.2rem 0.5rem;
}

.modal-canvas-wrapper {
  width: 100%;
  border-radius: 0.5rem;
  overflow: hidden;
  border: 1px solid var(--border-color);
  background: #0b0f17;
  display: flex;
  justify-content: center;
}

#lineage-share-canvas {
  width: 100%;
  height: auto;
  max-width: 100%;
  display: block;
}

.modal-actions-row {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

/* =========================================================================
   9. GUÍA SEO Y ACORDEÓN DE PREGUNTAS FRECUENTES
   ========================================================================= */
.seo-guide-section {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 1rem;
  padding: 2rem 1.75rem;
  box-shadow: var(--shadow-sm);
  margin-top: 1.5rem;
}

.seo-guide-title {
  font-family: var(--font-heading);
  font-size: 1.6rem;
  font-weight: 800;
  margin: 0 0 1rem;
  color: var(--text-primary);
}

.seo-guide-text {
  font-size: 0.98rem;
  color: var(--text-secondary);
  line-height: 1.65;
  margin-bottom: 1.25rem;
}

.seo-faq-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

.seo-faq-item {
  border: 1px solid var(--border-color);
  border-radius: 0.6rem;
  overflow: hidden;
  background-color: var(--bg-card-subtle);
}

.seo-faq-summary {
  font-family: var(--font-heading);
  font-size: 1.05rem;
  font-weight: 700;
  padding: 1rem 1.25rem;
  cursor: pointer;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.seo-faq-content {
  padding: 0 1.25rem 1.25rem;
  font-size: 0.95rem;
  color: var(--text-secondary);
  line-height: 1.6;
}
