/* Estilos principales - Retrasos de trenes en España en tiempo real */
:root {
  --font-main: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-heading: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Tema claro */
  --bg-page: #f8fafc;
  --bg-card: #ffffff;
  --bg-card-subtle: #f1f5f9;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border-color: #e2e8f0;
  --border-focus: #3b82f6;

  /* Semáforo de puntualidad */
  --color-ontime: #10b981;
  --color-ontime-bg: #ecfdf5;
  --color-minor: #f59e0b;
  --color-minor-bg: #fffbeb;
  --color-moderate: #f97316;
  --color-moderate-bg: #fff7ed;
  --color-severe: #ef4444;
  --color-severe-bg: #fef2f2;

  --color-primary: #2563eb;
  --color-primary-hover: #1d4ed8;
  --color-primary-light: #eff6ff;

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

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

[data-theme="dark"] {
  --bg-page: #0b0f17;
  --bg-card: #131c2e;
  --bg-card-subtle: #1a253a;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --border-color: #24324c;
  --border-focus: #60a5fa;

  --color-ontime-bg: rgba(16, 185, 129, 0.15);
  --color-minor-bg: rgba(245, 158, 11, 0.15);
  --color-moderate-bg: rgba(249, 115, 22, 0.15);
  --color-severe-bg: rgba(239, 68, 68, 0.2);

  --color-primary-light: rgba(37, 99, 235, 0.2);
}

/* Base */
*, *::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;
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  margin-top: 0;
  color: var(--text-main);
  font-weight: 700;
  letter-spacing: -0.02em;
}

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

/* Layout canónico */
.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%;
}

/* Barra superior de sincronización en vivo */
.live-sync-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-md);
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow-sm);
}

.sync-status-indicator {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.875rem;
  color: var(--text-muted);
}

.pulse-dot {
  width: 10px;
  height: 10px;
  background-color: var(--color-ontime);
  border-radius: 50%;
  position: relative;
  display: inline-block;
}

.pulse-dot::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: inherit;
  border-radius: 50%;
  animation: pulse-ring 2s cubic-bezier(0.215, 0.61, 0.355, 1) infinite;
}

@keyframes pulse-ring {
  0% { transform: scale(0.95); opacity: 0.8; }
  70% { transform: scale(2.4); opacity: 0; }
  100% { transform: scale(2.4); opacity: 0; }
}

.sync-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-refresh {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  font-size: 0.825rem;
  font-weight: 600;
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 38px;
}

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

.btn-refresh svg {
  transition: transform 0.4s ease;
}

.btn-refresh.spinning svg {
  animation: spin 1s linear infinite;
}

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

/* Tarjetas KPI en cuadrícula */
.kpi-metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

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

.kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

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

.kpi-title {
  font-size: 0.825rem;
  text-transform: none;
  color: var(--text-muted);
  font-weight: 600;
}

.kpi-icon {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-card-subtle);
  color: var(--text-main);
}

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

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

.badge-ontime { color: var(--color-ontime); font-weight: 700; }
.badge-delayed { color: var(--color-severe); font-weight: 700; }

/* Sección de controles y buscador */
.controls-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-sm);
}

.search-input-group {
  position: relative;
  margin-bottom: 1rem;
}

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

.search-input-field {
  width: 100%;
  padding: 0.85rem 1rem 0.85rem 2.85rem;
  font-size: 0.95rem;
  font-family: var(--font-main);
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  outline: none;
  min-height: 44px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.search-input-field:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

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

.category-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.pill-btn {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-full);
  font-size: 0.825rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
}

.pill-btn:hover {
  background: var(--color-primary-light);
  color: var(--color-primary);
  border-color: var(--color-primary);
}

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

.status-select-wrap {
  min-width: 180px;
}

.select-custom {
  width: 100%;
  min-height: 40px;
  padding: 0.5rem 2.5rem 0.5rem 0.85rem;
  font-size: 0.85rem;
  font-family: var(--font-main);
  background: var(--bg-card-subtle);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  outline: none;
  cursor: pointer;
  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='%2364748b' stroke-width='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 0.75rem center;
}

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

/* Contenedor del mapa Leaflet */
.map-section-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  margin-bottom: 2rem;
  box-shadow: var(--shadow-sm);
}

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

.map-title {
  font-size: 1.15rem;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.map-legend {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  font-size: 0.775rem;
  color: var(--text-muted);
}

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

.legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
}

.legend-dot.ontime { background: var(--color-ontime); }
.legend-dot.minor { background: var(--color-minor); }
.legend-dot.moderate { background: var(--color-moderate); }
.legend-dot.severe { background: var(--color-severe); }

#train-map {
  width: 100%;
  height: 480px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border-color);
  background: #0b0f17;
  z-index: 1;
}

/* Marcador Leaflet personalizado para tren */
.leaflet-train-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: #ffffff;
  font-weight: 700;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
  transition: transform 0.2s ease;
  cursor: pointer;
}

.leaflet-train-marker:hover {
  transform: scale(1.25);
  z-index: 1000 !important;
}

/* Pestañas de navegación de contenidos */
.tabs-navigation {
  display: flex;
  border-bottom: 2px solid var(--border-color);
  margin-bottom: 1.5rem;
  gap: 0.5rem;
  overflow-x: auto;
}

.tab-btn {
  background: none;
  border: none;
  padding: 0.85rem 1.25rem;
  font-size: 0.95rem;
  font-family: var(--font-heading);
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  position: relative;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  min-height: 42px;
}

.tab-btn:hover {
  color: var(--color-primary);
}

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

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* Muro de trenes con mayores retrasos */
.delays-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

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

.train-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-focus);
}

.train-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.75rem;
  gap: 0.5rem;
}

.train-badge-pill {
  font-size: 0.725rem;
  font-weight: 700;
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-full);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.delay-badge {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  font-weight: 700;
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.delay-badge.severe {
  background: var(--color-severe-bg);
  color: var(--color-severe);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.delay-badge.moderate {
  background: var(--color-moderate-bg);
  color: var(--color-moderate);
  border: 1px solid rgba(249, 115, 22, 0.3);
}

.delay-badge.minor {
  background: var(--color-minor-bg);
  color: var(--color-minor);
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.delay-badge.ontime {
  background: var(--color-ontime-bg);
  color: var(--color-ontime);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.train-route {
  margin-bottom: 0.75rem;
}

.route-stations {
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 0.25rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

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

.route-next {
  font-size: 0.8rem;
  color: var(--text-muted);
}

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

.train-speed {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-muted);
}

.btn-card-action {
  background: var(--color-primary-light);
  color: var(--color-primary);
  border: none;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
}

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

/* Calculadora interactiva de indemnización */
.calculator-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  margin-bottom: 2rem;
  box-shadow: var(--shadow-sm);
}

.calc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.calc-input-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.calc-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
}

.calc-input {
  width: 100%;
  min-height: 44px;
  padding: 0.65rem 0.85rem;
  font-size: 0.95rem;
  font-family: var(--font-main);
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  outline: none;
}

.calc-input:focus {
  border-color: var(--border-focus);
}

.quick-delay-buttons {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  margin-top: 0.35rem;
}

.btn-quick-min {
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  min-height: 32px;
}

.btn-quick-min:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

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

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

.result-badge {
  font-size: 0.85rem;
  font-weight: 700;
  padding: 0.3rem 0.8rem;
  border-radius: var(--radius-full);
}

.result-badge.eligible {
  background: var(--color-ontime-bg);
  color: var(--color-ontime);
}

.result-badge.not-eligible {
  background: var(--bg-card);
  color: var(--text-muted);
}

.result-amounts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
}

.amount-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 1rem;
}

.amount-label {
  font-size: 0.775rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.amount-value {
  font-family: var(--font-mono);
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text-main);
}

.result-notes {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.btn-claim-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  background: var(--color-primary);
  color: #ffffff;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
  min-height: 44px;
  align-self: flex-start;
  transition: background-color 0.2s ease;
}

.btn-claim-link:hover {
  background: var(--color-primary-hover);
}

/* Guía de derechos y FAQ */
.faq-section {
  margin-top: 2.5rem;
  margin-bottom: 2rem;
}

.faq-title {
  font-size: 1.4rem;
  margin-bottom: 1rem;
}

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

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

.faq-question {
  padding: 1rem 1.25rem;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.faq-question::-webkit-details-marker {
  display: none;
}

.faq-question::after {
  content: '+';
  font-size: 1.3rem;
  font-weight: 400;
  color: var(--text-muted);
}

.faq-item[open] .faq-question::after {
  content: '−';
}

.faq-answer {
  padding: 0 1.25rem 1.25rem;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.6;
}

/* Modal accesible de tren */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 10000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  max-width: 540px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.5rem;
  box-shadow: var(--shadow-lg);
  position: relative;
  transform: translateY(20px);
  transition: transform 0.2s ease;
}

.modal-overlay.active .modal-content {
  transform: translateY(0);
}

.modal-close-btn {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.2rem;
  min-height: 36px;
}

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

/* Responsividad */
@media (max-width: 900px) {
  .tool-with-sidebar {
    gap: 1.5rem;
  }
}

@media (max-width: 640px) {
  .tool-layout {
    margin: 1rem auto 2rem;
    padding: 0 0.75rem;
  }

  .kpi-metrics-grid {
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
  }

  .kpi-card {
    padding: 0.85rem;
  }

  .kpi-value {
    font-size: 1.45rem;
  }

  #train-map {
    height: 360px;
  }

  .filters-row {
    flex-direction: column;
    align-items: stretch;
  }

  .status-select-wrap {
    width: 100%;
  }

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