/* ==========================================================================
   Atlas de Fauna y Flora Silvestre de España - Estilos principales
   Estándar de diseño canónico fijate.com (Dark Mode nativo, acentos esmeralda)
   ========================================================================== */

:root {
  --bg-page: #0b0f17;
  --bg-card: #131b28;
  --bg-card-hover: #182335;
  --bg-surface: #1e293b;
  --border-color: #24344d;
  --border-focus: #10b981;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent: #10b981;
  --accent-hover: #059669;
  --accent-light: rgba(16, 185, 129, 0.15);
  --accent-glow: rgba(16, 185, 129, 0.3);
  --danger: #ef4444;
  --warning: #f59e0b;
  --info: #3b82f6;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  --shadow-card: 0 4px 20px -2px rgba(0, 0, 0, 0.5);
  --shadow-hover: 0 10px 30px -4px rgba(0, 0, 0, 0.7);
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-title: 'Outfit', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

[data-theme="light"] {
  --bg-page: #f1f5f9;
  --bg-card: #ffffff;
  --bg-card-hover: #f8fafc;
  --bg-surface: #e2e8f0;
  --border-color: #cbd5e1;
  --border-focus: #059669;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --accent: #059669;
  --accent-hover: #047857;
  --accent-light: rgba(5, 150, 105, 0.12);
  --accent-glow: rgba(5, 150, 105, 0.25);
  --shadow-card: 0 4px 20px -2px rgba(0, 0, 0, 0.08);
  --shadow-hover: 0 10px 30px -4px rgba(0, 0, 0, 0.15);
}

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

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

/* Layout institucional */
.tool-layout {
  max-width: 1280px;
  width: 100%;
  margin: 1.5rem auto 3.5rem;
  padding: 0 1rem;
  flex: 1 0 auto;
}

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

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

/* Barra lateral publicidad desktop */
.tool-ad-sidebar {
  display: none;
  width: 300px;
  flex-shrink: 0;
}

@media (min-width: 1536px) {
  .tool-ad-sidebar {
    display: block;
  }
}

.ad-sticky-box {
  position: sticky;
  top: 90px;
}

/* Panel de control de filtros */
.controls-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-card);
  margin-bottom: 1.5rem;
}

.controls-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

@media (min-width: 768px) {
  .controls-grid {
    grid-template-columns: 1.2fr 1fr;
  }
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.control-label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

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

.control-select {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  height: 46px;
  min-height: 40px;
  padding: 0 44px 0 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background-color: var(--bg-surface);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.95rem;
  appearance: none;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  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='%2310b981' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 16px;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
}

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

.control-select option,
.control-select optgroup {
  background-color: var(--bg-card);
  color: var(--text-primary);
  padding: 8px;
}

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

.control-input {
  width: 100%;
  height: 46px;
  min-height: 40px;
  padding: 0 40px 0 42px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background-color: var(--bg-surface);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.95rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}

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

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

.search-clear-btn {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  display: none;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
}

.search-clear-btn:hover {
  color: var(--text-primary);
}

/* Píldoras taxonómicas envolventes (flex-wrap: wrap sin scroll artificial) */
.taxa-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
}

.taxon-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  height: 40px;
  min-height: 40px;
  padding: 0 1rem;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-color);
  background-color: var(--bg-surface);
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}

.taxon-pill:hover {
  background-color: var(--bg-card-hover);
  border-color: var(--text-muted);
  color: var(--text-primary);
}

.taxon-pill.active {
  background-color: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
  box-shadow: 0 2px 10px var(--accent-glow);
  font-weight: 600;
}

/* Barra de herramientas de vista y estado */
.view-toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.25rem;
  padding: 0.75rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
}

.view-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.view-info strong {
  color: var(--text-primary);
}

.view-badge-park {
  background: var(--accent-light);
  color: var(--accent);
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 600;
}

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

.btn-view-mode {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  height: 36px;
  padding: 0 0.85rem;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-view-mode:hover {
  color: var(--text-primary);
}

.btn-view-mode.active {
  background: var(--bg-card);
  color: var(--text-primary);
  font-weight: 600;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

/* Ficha informativa del espacio */
.park-summary-card {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.08) 0%, rgba(19, 27, 40, 0.9) 100%);
  border: 1px solid rgba(16, 185, 129, 0.25);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.park-summary-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
}

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

.park-summary-ccaa {
  font-size: 0.85rem;
  color: var(--accent);
  font-weight: 600;
}

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

/* Grid de avistamientos */
.species-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.25rem;
  margin-bottom: 2rem;
}

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

.species-card:hover {
  transform: translateY(-4px);
  border-color: var(--accent);
  box-shadow: var(--shadow-hover);
}

.species-thumb-container {
  position: relative;
  width: 100%;
  height: 220px;
  background-color: #05080e;
  overflow: hidden;
}

.species-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.species-card:hover .species-thumb {
  transform: scale(1.05);
}

.species-badge-taxon {
  position: absolute;
  top: 10px;
  left: 10px;
  background: rgba(11, 15, 23, 0.85);
  backdrop-filter: blur(4px);
  color: #ffffff;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  border: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  gap: 4px;
}

.species-photos-count {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(11, 15, 23, 0.85);
  backdrop-filter: blur(4px);
  color: #ffffff;
  padding: 4px 8px;
  border-radius: var(--radius-full);
  font-size: 0.72rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 3px;
}

.species-info {
  padding: 1.15rem;
  display: flex;
  flex-direction: column;
  flex: 1;
  gap: 0.4rem;
}

.species-common-name {
  font-family: var(--font-title);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
  line-height: 1.3;
}

.species-scientific-name {
  font-size: 0.875rem;
  font-style: italic;
  color: var(--accent);
  margin: 0;
  font-weight: 500;
}

.species-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: auto;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border-color);
  font-size: 0.78rem;
  color: var(--text-muted);
}

.species-meta-date {
  display: flex;
  align-items: center;
  gap: 4px;
}

.species-btn-detail {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 100%;
  height: 40px;
  margin-top: 0.75rem;
  background-color: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

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

/* Vista Mapa Interactivo */
.map-container-wrapper {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-card);
  margin-bottom: 2rem;
}

#mapa-biodiversidad {
  width: 100%;
  height: 560px;
  background-color: #0b0f17;
}

@media (max-width: 768px) {
  #mapa-biodiversidad {
    height: 420px;
  }
}

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

.leaflet-popup-content {
  margin: 0 !important;
  line-height: 1.4 !important;
}

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

.map-popup-card {
  width: 260px;
  display: flex;
  flex-direction: column;
}

.map-popup-img {
  width: 100%;
  height: 140px;
  object-fit: cover;
}

.map-popup-body {
  padding: 10px 12px;
}

.map-popup-title {
  font-family: var(--font-title);
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text-primary);
  margin: 0 0 3px 0;
}

.map-popup-scientific {
  font-size: 0.8rem;
  font-style: italic;
  color: var(--accent);
  margin: 0 0 6px 0;
}

.map-popup-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.map-popup-btn {
  display: block;
  width: 100%;
  text-align: center;
  padding: 6px 0;
  background: var(--accent);
  color: #ffffff;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

/* Paginador */
.pagination-container {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1.5rem;
  margin-bottom: 2rem;
}

.btn-page {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  height: 42px;
  min-height: 40px;
  padding: 0 1.25rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-page:hover:not(:disabled) {
  background: var(--bg-surface);
  border-color: var(--accent);
}

.btn-page:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.page-indicator {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  color: var(--text-secondary);
  padding: 0 0.5rem;
}

/* Estado de carga y mensajes vacíos */
.status-state-box {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 3.5rem 1.5rem;
  text-align: center;
  margin-bottom: 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}

.spinner {
  width: 44px;
  height: 44px;
  border: 3px solid var(--border-color);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

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

.status-text {
  font-size: 0.9rem;
  color: var(--text-secondary);
  max-width: 460px;
  margin: 0;
}

/* Modal Canónico de Especie (Regla 251: position: fixed; inset: 0; z-index: 9999;) */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0, 0, 0, 0.78);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal-dialog {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 780px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.85);
  overflow: hidden;
  transform: scale(0.95);
  transition: transform 0.25s ease;
}

.modal-overlay.active .modal-dialog {
  transform: scale(1);
}

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

.modal-title-group {
  min-width: 0;
}

.modal-title {
  font-family: var(--font-title);
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
  line-height: 1.25;
}

.modal-subtitle {
  font-size: 0.9rem;
  font-style: italic;
  color: var(--accent);
  margin: 0;
}

.modal-close-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.2s;
}

.modal-close-btn:hover {
  background: var(--danger);
  border-color: var(--danger);
  color: #ffffff;
}

.modal-body {
  padding: 1.4rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.modal-gallery-main {
  position: relative;
  width: 100%;
  height: 380px;
  background: #000000;
  border-radius: var(--radius-md);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

@media (max-width: 640px) {
  .modal-gallery-main {
    height: 260px;
  }
}

.modal-main-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.modal-gallery-thumbs {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding-bottom: 4px;
}

.modal-thumb-btn {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
  padding: 0;
  overflow: hidden;
  cursor: pointer;
  background: #000;
  flex-shrink: 0;
}

.modal-thumb-btn.active {
  border-color: var(--accent);
}

.modal-thumb-btn img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.modal-info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  padding: 1rem;
}

.modal-info-item {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.modal-info-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 600;
}

.modal-info-val {
  font-size: 0.9rem;
  color: var(--text-primary);
  font-weight: 500;
}

.modal-footer {
  padding: 1rem 1.4rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  background: var(--bg-surface);
}

.modal-attribution {
  font-size: 0.78rem;
  color: var(--text-muted);
  max-width: 440px;
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
}

.btn-modal-action {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  height: 40px;
  min-height: 40px;
  padding: 0 1.1rem;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.2s;
}

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

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

.btn-modal-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-modal-secondary:hover {
  background: var(--bg-surface);
}

/* Toast de avisos no intrusivo (cero alerts) */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast-item {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-left: 4px solid var(--accent);
  color: var(--text-primary);
  padding: 0.85rem 1.25rem;
  border-radius: var(--radius-md);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
  font-size: 0.875rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  pointer-events: auto;
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
