/**
 * Mapa de Castillos y Fortalezas de España
 * Estilos canónicos de la herramienta
 */

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

  /* Colores tema oscuro (Midnight Slate con acentos dorados medievales) */
  --bg-body: #0b0f17;
  --bg-card: #131a26;
  --bg-card-hover: #192233;
  --bg-card-subtle: #0f1520;
  --border-color: #1e293b;
  --border-focus: #f59e0b;

  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --text-dim: #64748b;

  --accent-gold: #f59e0b;
  --accent-gold-light: rgba(245, 158, 11, 0.12);
  --accent-amber: #d97706;
  --accent-red: #ef4444;
  --accent-red-light: rgba(239, 68, 68, 0.12);
  --accent-emerald: #10b981;
  --accent-emerald-light: rgba(16, 185, 129, 0.12);
  --accent-blue: #3b82f6;
  --accent-blue-light: rgba(59, 130, 246, 0.12);
  --accent-purple: #a855f7;

  /* Tipos de fortalezas */
  --type-roquero: #f59e0b;
  --type-alcazaba: #10b981;
  --type-templario: #ef4444;
  --type-palaciego: #3b82f6;
  --type-mudejar: #f97316;
  --type-amurallado: #8b5cf6;

  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.45);
}

body.theme-light {
  --bg-body: #f8fafc;
  --bg-card: #ffffff;
  --bg-card-hover: #f1f5f9;
  --bg-card-subtle: #f8fafc;
  --border-color: #e2e8f0;
  --border-focus: #d97706;

  --text-main: #0f172a;
  --text-muted: #475569;
  --text-dim: #94a3b8;

  --accent-gold: #d97706;
  --accent-gold-light: rgba(217, 119, 6, 0.08);
  --accent-red: #dc2626;
  --accent-emerald: #059669;
  --accent-blue: #2563eb;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.1);
}

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

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

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-title);
  font-weight: 700;
  color: var(--text-main);
}

.tool-layout {
  max-width: 1200px;
  margin: 1.5rem auto 3rem;
  padding: 0 1rem;
  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;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* ==========================================================================
   KPI BARRA DE ESTADO
   ========================================================================== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.1rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.kpi-card:hover {
  transform: translateY(-2px);
  border-color: rgba(245, 158, 11, 0.4);
}

.kpi-icon-wrap {
  width: 46px;
  height: 46px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.icon-amber {
  background: rgba(245, 158, 11, 0.15);
  color: var(--accent-gold);
}

.icon-red {
  background: rgba(239, 68, 68, 0.15);
  color: var(--accent-red);
}

.icon-emerald {
  background: rgba(16, 185, 129, 0.15);
  color: var(--accent-emerald);
}

.icon-blue {
  background: rgba(59, 130, 246, 0.15);
  color: var(--accent-blue);
}

.kpi-content {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

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

.kpi-value {
  font-family: var(--font-mono);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.2;
  margin: 0.15rem 0;
}

.kpi-detail {
  font-size: 0.72rem;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ==========================================================================
   RUTAS MEDIEVALES TEMÁTICAS
   ========================================================================== */
.routes-section {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  box-shadow: var(--shadow-sm);
}

.routes-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.routes-title {
  font-size: 1.15rem;
  line-height: 1.2;
}

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

.btn-clear-route {
  padding: 0.35rem 0.85rem;
  min-height: 36px;
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid var(--accent-red);
  color: var(--accent-red);
  border-radius: var(--radius-md);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-clear-route:hover {
  background: var(--accent-red);
  color: #fff;
}

.routes-pills-scroll {
  display: flex;
  gap: 0.65rem;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: thin;
}

.route-card-pill {
  flex: 0 0 auto;
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.65rem 1rem;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  min-width: 220px;
  max-width: 280px;
  transition: all 0.2s ease;
}

.route-card-pill:hover {
  border-color: var(--accent-gold);
  transform: translateY(-2px);
}

.route-card-pill.active {
  background: var(--accent-gold-light);
  border-color: var(--accent-gold);
  box-shadow: 0 0 0 1px var(--accent-gold);
}

.route-pill-title {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 0.2rem;
}

.route-card-pill.active .route-pill-title {
  color: var(--accent-gold);
}

.route-pill-desc {
  font-size: 0.74rem;
  color: var(--text-muted);
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ==========================================================================
   PANEL DE CONTROLES (BUSCADOR, COMUNIDAD Y TIPOLOGÍAS)
   ========================================================================== */
.controls-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  box-shadow: var(--shadow-sm);
}

.controls-top-row {
  display: flex;
  gap: 1rem;
  align-items: center;
  flex-wrap: wrap;
}

.search-wrap {
  position: relative;
  flex: 1 1 260px;
  min-width: 220px;
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
  pointer-events: none;
}

.search-input {
  width: 100%;
  height: 44px;
  padding: 0 40px 0 42px;
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-family: var(--font-main);
  font-size: 0.92rem;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

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

.btn-clear-search {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.3rem;
  cursor: pointer;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.filter-dropdowns-row {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
}

.select-wrap {
  position: relative;
  min-width: 210px;
}

.custom-select {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  height: 44px;
  padding: 0 40px 0 14px;
  background-color: var(--bg-card-subtle);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-family: var(--font-main);
  font-size: 0.88rem;
  appearance: none;
  background-image: 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' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 16px;
  cursor: pointer;
  outline: none;
  transition: border-color 0.2s ease;
}

.custom-select:focus {
  border-color: var(--border-focus);
}

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

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

.btn-view-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding: 0 14px;
  border-radius: calc(var(--radius-md) - 2px);
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-main);
  font-size: 0.86rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-view-toggle.active {
  background: var(--accent-gold);
  color: #ffffff;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

body.theme-light .btn-view-toggle.active {
  background: var(--accent-gold);
  color: #ffffff;
}

.btn-view-toggle:hover:not(.active) {
  color: var(--text-main);
}

/* Barra de filtros por tipología */
.types-filter-bar {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: thin;
}

.types-filter-bar::-webkit-scrollbar {
  height: 4px;
}

.types-filter-bar::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

.btn-filter-pill {
  white-space: nowrap;
  padding: 0.45rem 0.95rem;
  min-height: 40px;
  border-radius: 9999px;
  border: 1px solid var(--border-color);
  background: var(--bg-card-subtle);
  color: var(--text-muted);
  font-family: var(--font-main);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-filter-pill:hover {
  border-color: var(--accent-gold);
  color: var(--text-main);
}

.btn-filter-pill.active {
  background: var(--accent-gold-light);
  border-color: var(--accent-gold);
  color: var(--accent-gold);
  font-weight: 600;
}

/* ==========================================================================
   LISTADO Y TARJETAS DE FORTALEZAS
   ========================================================================== */
.castles-status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
  padding: 0 0.25rem;
}

.active-filter-indicator {
  font-size: 0.78rem;
  color: var(--text-dim);
}

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

.castle-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.castle-card:hover {
  transform: translateY(-3px);
  border-color: rgba(245, 158, 11, 0.45);
  box-shadow: var(--shadow-md);
}

.castle-card-header {
  padding: 1.15rem 1.25rem 0.85rem;
  border-bottom: 1px solid rgba(30, 41, 59, 0.6);
}

body.theme-light .castle-card-header {
  border-bottom: 1px solid var(--border-color);
}

.castle-header-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}

.castle-type-tag {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 6px;
  display: inline-block;
}

.tag-roquero { background: rgba(245, 158, 11, 0.12); color: var(--type-roquero); }
.tag-alcazaba { background: rgba(16, 185, 129, 0.12); color: var(--type-alcazaba); }
.tag-templario { background: rgba(239, 68, 68, 0.12); color: var(--type-templario); }
.tag-palaciego { background: rgba(59, 130, 246, 0.12); color: var(--type-palaciego); }
.tag-mudejar { background: rgba(249, 115, 22, 0.12); color: var(--type-mudejar); }
.tag-amurallado { background: rgba(139, 92, 246, 0.12); color: var(--type-amurallado); }

.castle-century-badge {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: var(--text-dim);
}

.castle-name {
  font-size: 1.18rem;
  line-height: 1.25;
  margin-bottom: 0.25rem;
}

.castle-location {
  font-size: 0.8rem;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 4px;
}

.castle-card-body {
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  flex: 1 1 auto;
}

.castle-origin-row {
  font-size: 0.82rem;
  color: var(--text-muted);
  display: flex;
  gap: 6px;
  align-items: baseline;
}

.castle-origin-label {
  color: var(--text-dim);
  font-weight: 500;
}

.castle-elements-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.element-pill {
  font-size: 0.72rem;
  padding: 2px 7px;
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  color: var(--text-muted);
}

.castle-desc-preview {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.castle-card-footer {
  padding: 0.75rem 1.25rem 1rem;
  display: flex;
  gap: 0.65rem;
}

.btn-card-primary {
  flex: 1 1 0%;
  min-height: 40px;
  background: var(--accent-gold);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-main);
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background 0.2s ease;
}

.btn-card-primary:hover {
  background: var(--accent-amber);
}

.btn-card-gps {
  min-height: 40px;
  padding: 0 12px;
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-family: var(--font-main);
  font-size: 0.82rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  text-decoration: none;
  transition: all 0.2s ease;
}

.btn-card-gps:hover {
  border-color: var(--accent-gold);
  color: var(--accent-gold);
}

/* ==========================================================================
   VISTA DE MAPA INTERACTIVO
   ========================================================================== */
.map-view {
  width: 100%;
}

.map-wrapper-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.map-top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding: 0.25rem 0.5rem;
}

.map-legend {
  display: flex;
  gap: 1rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  flex-wrap: wrap;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.dot-roquero { background: var(--type-roquero); }
.dot-alcazaba { background: var(--type-alcazaba); }
.dot-templario { background: var(--type-templario); }
.dot-palaciego { background: var(--type-palaciego); }
.dot-mudejar { background: var(--type-mudejar); }

.btn-map-locate {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 14px;
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-family: var(--font-main);
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-map-locate:hover {
  border-color: var(--accent-gold);
  color: var(--text-main);
}

.interactive-map {
  width: 100%;
  height: 560px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  z-index: 10;
}

/* Popups de Leaflet */
.leaflet-popup-content-wrapper {
  background: var(--bg-card) !important;
  color: var(--text-main) !important;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md) !important;
  box-shadow: var(--shadow-md) !important;
}

.leaflet-popup-tip {
  background: var(--bg-card) !important;
  border: 1px solid var(--border-color);
}

.map-popup-box {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 200px;
}

.map-popup-title {
  font-family: var(--font-title);
  font-weight: 700;
  font-size: 0.98rem;
  color: var(--text-main);
}

.map-popup-info {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.btn-map-popup-action {
  margin-top: 4px;
  width: 100%;
  min-height: 34px;
  background: var(--accent-gold);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

/* ==========================================================================
   GUÍA EDUCATIVA
   ========================================================================== */
.card-info-guide {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.guide-header {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
}

.guide-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  background: var(--accent-gold-light);
  color: var(--accent-gold);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.guide-title {
  font-size: 1.25rem;
  margin-bottom: 0.2rem;
}

.guide-subtitle {
  font-size: 0.88rem;
  color: var(--text-muted);
}

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

.guide-item {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.1rem;
}

.guide-item-title {
  font-size: 0.95rem;
  color: var(--accent-gold);
  margin-bottom: 0.4rem;
}

.guide-item p {
  font-size: 0.84rem;
  color: var(--text-muted);
  line-height: 1.55;
}

/* ==========================================================================
   MODAL DE DETALLE Y FICHA HISTÓRICA
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(5px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  animation: modalFadeIn 0.2s ease-out;
}

@keyframes modalFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 780px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
}

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  position: sticky;
  top: 0;
  background: var(--bg-card);
  z-index: 2;
}

.modal-category-badge {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--accent-gold-light);
  color: var(--accent-gold);
  display: inline-block;
  margin-bottom: 0.35rem;
}

.modal-title {
  font-size: 1.4rem;
  line-height: 1.2;
}

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

.btn-close-modal {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 2rem;
  line-height: 1;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

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

.modal-body {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.modal-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
  gap: 1rem;
}

.spinner {
  width: 38px;
  height: 38px;
  border: 3px solid rgba(245, 158, 11, 0.2);
  border-top-color: var(--accent-gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Ficha técnica en modal */
.modal-specs-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.85rem;
}

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

.modal-spec-label {
  font-size: 0.72rem;
  color: var(--text-dim);
}

.modal-spec-value {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-main);
  margin-top: 0.2rem;
}

.modal-history-section {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.modal-section-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent-gold);
}

.modal-history-text {
  font-size: 0.88rem;
  line-height: 1.6;
  color: var(--text-muted);
}

.modal-elements-box {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.modal-nearby-section {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.nearby-castles-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.nearby-castle-card {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.75rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.nearby-castle-card:hover {
  border-color: var(--accent-gold);
  transform: translateY(-2px);
}

.nearby-castle-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nearby-castle-name {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-main);
}

.nearby-castle-dist {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: var(--accent-gold);
  font-weight: 600;
}

.modal-actions-bar {
  display: flex;
  gap: 0.75rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border-color);
}

.btn-action-gps {
  flex: 1 1 0%;
  min-height: 44px;
  background: #2563eb;
  color: #fff;
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.88rem;
}

.btn-action-share {
  min-height: 44px;
  padding: 0 16px;
  background: #25d366;
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
}

/* ==========================================================================
   RESPONSIVE (MÓVIL Y TABLETS)
   ========================================================================== */
@media (max-width: 1024px) {
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .castles-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .modal-specs-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 768px) {
  .kpi-grid {
    grid-template-columns: 1fr;
  }
  .controls-top-row {
    flex-direction: column;
    align-items: stretch;
  }
  .search-wrap {
    width: 100%;
  }
  .filter-dropdowns-row {
    flex-direction: column;
    align-items: stretch;
  }
  .select-wrap {
    width: 100%;
  }
  .view-toggle-group {
    width: 100%;
    justify-content: center;
  }
  .btn-view-toggle {
    flex: 1;
    justify-content: center;
  }
  .castles-grid {
    grid-template-columns: 1fr;
  }
  .guide-grid {
    grid-template-columns: 1fr;
  }
  .interactive-map {
    height: 420px;
  }
  .modal-specs-grid {
    grid-template-columns: 1fr;
  }
  .nearby-castles-grid {
    grid-template-columns: 1fr;
  }
  .modal-actions-bar {
    flex-direction: column;
  }
}
