/* ==========================================================================
   Calculadora de Ruta, Peajes y Coste de Viaje - Fijate Tools
   Estilos canónicos Midnight Slate, mapa Leaflet y controles responsivos
   ========================================================================== */

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

  /* Paleta Midnight Slate */
  --bg-primary: #0b0f17;
  --bg-card: rgba(18, 24, 38, 0.85);
  --bg-card-hover: rgba(26, 35, 54, 0.95);
  --bg-elevated: #161e2e;
  --bg-input: #101623;
  --border-color: rgba(255, 255, 255, 0.08);
  --border-hover: rgba(255, 255, 255, 0.18);

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

  /* Acentos temáticos */
  --color-brand: #3b82f6;
  --color-brand-hover: #2563eb;
  --color-brand-bg: rgba(59, 130, 246, 0.12);
  --color-brand-glow: rgba(59, 130, 246, 0.3);

  --color-emerald: #10b981;
  --color-emerald-bg: rgba(16, 185, 129, 0.12);
  --color-amber: #f59e0b;
  --color-cyan: #06b6d4;
  --color-danger: #ef4444;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.25);
  --shadow-md: 0 4px 12px -2px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 28px -4px rgba(0, 0, 0, 0.5);
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="light"] {
  --bg-primary: #f8fafc;
  --bg-card: #ffffff;
  --bg-card-hover: #f1f5f9;
  --bg-elevated: #f1f5f9;
  --bg-input: #ffffff;
  --border-color: #cbd5e1;
  --border-hover: #94a3b8;

  --text-main: #0f172a;
  --text-muted: #475569;
  --text-dim: #64748b;

  --color-brand-bg: rgba(59, 130, 246, 0.1);

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 12px 24px rgba(0, 0, 0, 0.08);
}

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

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

.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;
}

.tool-main-content {
  flex: 1 1 0%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* Colores utilitarios */
.color-emerald { color: #10b981 !important; }
.color-cyan { color: #06b6d4 !important; }
.color-amber { color: #f59e0b !important; }
.color-danger { color: #ef4444 !important; }

/* Hero informativo */
.cv-hero {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.15) 0%, rgba(16, 185, 129, 0.08) 100%);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.75rem 1.5rem;
  position: relative;
  overflow: hidden;
  backdrop-filter: blur(8px);
}

.cv-hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0.75rem;
  border-radius: var(--radius-full);
  background: var(--color-brand-bg);
  color: var(--color-brand);
  font-size: 0.8125rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.cv-hero-title {
  font-family: var(--font-heading);
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.25;
  margin-bottom: 0.5rem;
}

.cv-hero-desc {
  color: var(--text-muted);
  font-size: 0.9375rem;
  line-height: 1.6;
  max-width: 820px;
}

/* Cuadrícula de formulario */
.cv-grid-layout {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.5rem;
}

.cv-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;
}

.cv-card-header {
  padding: 1.25rem 1.25rem 0.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
  background: rgba(255, 255, 255, 0.01);
}

.cv-card-title-box {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-main);
}

.cv-card-title-box h3 {
  font-family: var(--font-heading);
  font-size: 1.0625rem;
  font-weight: 700;
}

.cv-tag-section {
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  background: var(--bg-elevated);
  color: var(--text-muted);
  border: 1px solid var(--border-color);
}

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

/* Campos de entrada */
.cv-field-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  position: relative;
}

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

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

.cv-label-sm {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-dim);
}

.cv-input {
  width: 100%;
  height: 44px;
  padding: 0 0.875rem;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  font-weight: 500;
  transition: var(--transition);
}

.cv-input:focus {
  outline: none;
  border-color: var(--color-brand);
  box-shadow: 0 0 0 3px var(--color-brand-bg);
}

.cv-input-action-wrap {
  display: flex;
  align-items: center;
  position: relative;
}

.cv-input-action-wrap .cv-input {
  padding-right: 48px;
}

.btn-geo-action, .btn-swap-locations {
  position: absolute;
  right: 6px;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.btn-geo-action:hover, .btn-swap-locations:hover {
  background: var(--color-brand-bg);
  color: var(--color-brand);
  border-color: var(--color-brand);
}

/* Suffix wrapper */
.cv-input-suffix-wrap {
  display: flex;
  align-items: center;
  position: relative;
  width: 100%;
}

.cv-input-suffix-wrap .cv-input {
  flex: 1 1 0%;
  width: 0;
  min-width: 0;
  padding-right: 70px;
  font-family: var(--font-mono);
  font-weight: 600;
}

.cv-suffix {
  position: absolute;
  right: 0.875rem;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-dim);
  pointer-events: none;
}

/* Desplegables select */
.cv-select {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  height: 44px;
  padding: 0 40px 0 0.875rem;
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  appearance: none;
  cursor: pointer;
  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%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  transition: var(--transition);
}

.cv-select:focus {
  outline: none;
  border-color: var(--color-brand);
  box-shadow: 0 0 0 3px var(--color-brand-bg);
}

.cv-select option, .cv-select optgroup {
  background-color: #101623;
  color: #f1f5f9;
}

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

.cv-info-badge {
  height: 44px;
  padding: 0 0.875rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-brand);
}

/* Autocomplete desplegable */
.cv-autocomplete-box {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 1000;
  background: var(--bg-elevated);
  border: 1px solid var(--border-hover);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  max-height: 220px;
  overflow-y: auto;
  display: none;
  margin-top: 4px;
}

.cv-ac-item {
  padding: 0.625rem 0.875rem;
  font-size: 0.875rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-main);
  transition: var(--transition);
}

.cv-ac-item:last-child {
  border-bottom: none;
}

.cv-ac-item:hover {
  background: var(--bg-card-hover);
  color: var(--color-brand);
}

/* Rutas rápidas */
.cv-quick-routes {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

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

.cv-chip-btn {
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.25rem 0.65rem;
  cursor: pointer;
  transition: var(--transition);
}

.cv-chip-btn:hover {
  background: var(--color-brand-bg);
  border-color: var(--color-brand);
  color: var(--color-brand);
}

/* Botón principal calcular */
.btn-calculate-route {
  width: 100%;
  height: 46px;
  background: linear-gradient(135deg, var(--color-brand) 0%, var(--color-brand-hover) 100%);
  border: none;
  border-radius: var(--radius-sm);
  color: #ffffff;
  font-size: 0.9375rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  box-shadow: 0 4px 14px var(--color-brand-glow);
  transition: var(--transition);
  margin-top: 0.25rem;
}

.btn-calculate-route:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px var(--color-brand-glow);
}

/* Panel de KPIs */
.cv-kpis-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
}

.cv-kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 0.5rem;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

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

.cv-kpi-highlight {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.12) 0%, rgba(18, 24, 38, 0.95) 100%);
  border-color: rgba(16, 185, 129, 0.4);
}

[data-theme="light"] .cv-kpi-highlight {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.12) 0%, #ffffff 100%);
}

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

.cv-kpi-label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-muted);
}

.cv-badge-status {
  font-size: 0.6875rem;
  font-weight: 700;
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-full);
  background: var(--color-emerald-bg);
  color: var(--color-emerald);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.cv-kpi-value {
  font-family: var(--font-mono);
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.cv-kpi-subtext {
  font-size: 0.75rem;
  color: var(--text-dim);
  line-height: 1.4;
}

/* Sección de Peajes */
.cv-peajes-section {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
}

.cv-peajes-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.cv-peajes-badge {
  font-family: var(--font-mono);
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--color-amber);
  background: rgba(245, 158, 11, 0.12);
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-full);
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.cv-tolls-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.cv-toll-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 0.875rem;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
}

.cv-toll-price {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--color-amber);
}

/* Mapa interactivo Leaflet */
.cv-map-section {
  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;
}

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

.cv-map-controls-bar {
  display: flex;
  gap: 4px;
  background: var(--bg-input);
  padding: 3px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}

.btn-map-layer {
  height: 30px;
  padding: 0 0.75rem;
  background: transparent;
  border: none;
  border-radius: calc(var(--radius-sm) - 2px);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.btn-map-layer.active {
  background: var(--color-brand-bg);
  color: var(--color-brand);
  font-weight: 700;
}

.cv-map-box {
  width: 100%;
  height: 420px;
  background: #0f172a;
  z-index: 10;
}

/* Barra de Acciones */
.cv-actions-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
}

.btn-whatsapp-share {
  height: 44px;
  padding: 0 1.5rem;
  background: linear-gradient(135deg, #25d366 0%, #128c7e 100%);
  border: none;
  border-radius: var(--radius-sm);
  color: #ffffff;
  font-size: 0.875rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  box-shadow: 0 4px 14px rgba(37, 211, 102, 0.3);
  transition: var(--transition);
}

.btn-whatsapp-share:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(37, 211, 102, 0.4);
}

.btn-copy-summary, .btn-print-route {
  height: 44px;
  padding: 0 1.25rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  transition: var(--transition);
}

.btn-copy-summary:hover, .btn-print-route:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-hover);
}

/* Guía de viaje */
.cv-guide-section {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
}

.cv-guide-heading {
  font-family: var(--font-heading);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 1.25rem;
}

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

.cv-guide-card {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.cv-guide-card h4 {
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--color-brand);
}

.cv-guide-card p {
  font-size: 0.8125rem;
  color: var(--text-muted);
  line-height: 1.6;
}

/* Modales */
.cv-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  z-index: 9999;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.cv-modal-box {
  background: var(--bg-elevated);
  border: 1px solid var(--border-hover);
  border-radius: var(--radius-lg);
  max-width: 400px;
  width: 100%;
  padding: 2rem 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  box-shadow: var(--shadow-lg);
}

.cv-modal-icon-box {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-full);
  background: var(--color-emerald-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 1rem;
}

/* Responsividad móvil */
@media (max-width: 900px) {
  .tool-with-sidebar {
    flex-direction: column;
  }
  .cv-grid-layout {
    grid-template-columns: 1fr;
  }
  .cv-kpis-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .cv-guide-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 540px) {
  .cv-kpis-grid {
    grid-template-columns: 1fr;
  }
  .cv-grid-2 {
    grid-template-columns: 1fr;
  }
  .cv-actions-bar button {
    width: 100%;
    justify-content: center;
  }
}

/* Modo de impresión */
@media print {
  body {
    background: #ffffff !important;
    color: #000000 !important;
  }
  .app-header, .tools-ad-banner-section, .tool-ad-sidebar, .fijate-footer, .cv-actions-bar, .btn-calculate-route {
    display: none !important;
  }
  .cv-card, .cv-kpi-card {
    border: 1px solid #cccccc !important;
    background: #ffffff !important;
    color: #000000 !important;
  }
  .cv-map-box {
    height: 300px !important;
  }
}
