/* ==========================================================================
   Cuaderno de mantenimiento de vehículos • Fijate Tools
   Diseño canónico corporativo (Dark/Light) conforme a la guía de estilo
   ========================================================================== */

:root {
  /* Paleta base modo oscuro (por defecto) */
  --bg-main: #0a0d14;
  --bg-card: #121722;
  --bg-card-subtle: #181f2e;
  --bg-input: #1a2234;
  --border-color: #242f44;
  --border-focus: #3b82f6;

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

  --accent-primary: #3b82f6;
  --accent-primary-hover: #2563eb;
  --accent-success: #10b981;
  --accent-warning: #f59e0b;
  --accent-danger: #ef4444;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 12px -1px rgba(0, 0, 0, 0.35);
  --radius-md: 10px;
  --radius-lg: 14px;
}

[data-theme="light"] {
  --bg-main: #f8fafc;
  --bg-card: #ffffff;
  --bg-card-subtle: #f1f5f9;
  --bg-input: #ffffff;
  --border-color: #cbd5e1;
  --border-focus: #2563eb;

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

  --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 16px -2px rgba(0, 0, 0, 0.1);
}

/* 1. Reseteo y fuentes globales */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background-color: var(--bg-main);
  color: var(--text-main);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  overflow-x: clip;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1, h2, h3, h4, h5, h6 {
  font-family: 'Outfit', sans-serif;
  color: var(--text-main);
  line-height: 1.3;
}

.mono-font, .stat-number, .timeline-km, .timeline-cost {
  font-family: 'JetBrains Mono', monospace;
}

/* 2. Layout principal de la herramienta */
.tool-layout {
  max-width: 1200px;
  margin: 1.5rem auto 3rem;
  padding: 0 1rem;
  width: 100%;
  flex: 1;
}

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

/* 3. Barra de control superior del vehículo */
.vehicle-selector-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-sm);
}

.selector-flex {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
}

.selector-main {
  flex: 1 1 260px;
  min-width: 0;
}

.selector-label {
  display: block;
  font-size: 0.825rem;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
  font-weight: 500;
}

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

/* Desplegables <select> conforme a reglas estrictas */
select, .form-control {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  height: 42px;
  padding: 0 2.5rem 0 0.85rem;
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--text-main);
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  appearance: none;
  -webkit-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%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.85rem center;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
}

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

select:focus, .form-control:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

textarea.form-control {
  height: auto;
  min-height: 80px;
  padding: 0.75rem;
  background-image: none;
  white-space: normal;
}

/* 4. Botones */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  height: 42px;
  min-height: 42px;
  padding: 0 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.btn-primary {
  background-color: var(--accent-primary);
  color: #ffffff;
}

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

.btn-secondary {
  background-color: var(--bg-card-subtle);
  color: var(--text-main);
  border-color: var(--border-color);
}

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

.btn-icon-subtle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.825rem;
  font-weight: 500;
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

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

.btn-icon-subtle.text-danger:hover {
  color: var(--accent-danger);
}

/* 5. Banner y estadísticas del vehículo */
.vehicle-banner-card {
  background: linear-gradient(135deg, var(--bg-card) 0%, var(--bg-card-subtle) 100%);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-md);
}

.vehicle-banner-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 1rem;
}

.vehicle-banner-title {
  font-size: 1.4rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.vehicle-meta-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.4rem;
}

.badge-plate {
  font-family: 'JetBrains Mono', monospace;
  background: #ffffff;
  color: #0f172a;
  font-weight: 700;
  padding: 0.2rem 0.55rem;
  border-radius: 4px;
  font-size: 0.825rem;
  border: 1px solid #94a3b8;
  letter-spacing: 0.5px;
}

.badge-type {
  background: rgba(59, 130, 246, 0.15);
  color: var(--accent-primary);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.2rem 0.6rem;
  border-radius: 6px;
}

.badge-year {
  background: var(--bg-input);
  color: var(--text-muted);
  font-size: 0.8rem;
  padding: 0.2rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--border-color);
}

/* Cuadrícula de estadísticas clave */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
}

.stat-item {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.85rem 1rem;
  text-align: center;
}

.stat-label {
  font-size: 0.775rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-number {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text-main);
}

.stat-highlight {
  color: var(--accent-primary);
}

/* 6. Alertas preventivas */
.alerts-container {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.alerta-card {
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
  padding: 0.85rem 1rem;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
}

.alerta-card.urgencia-alta {
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.35);
  color: #fca5a5;
}

.alerta-card.urgencia-alta .alerta-icono {
  color: var(--accent-danger);
}

.alerta-card.urgencia-alta .alerta-titulo {
  color: #f87171;
}

.alerta-card.urgencia-media {
  background: rgba(245, 158, 11, 0.12);
  border-color: rgba(245, 158, 11, 0.35);
  color: #fcd34d;
}

.alerta-card.urgencia-media .alerta-icono {
  color: var(--accent-warning);
}

.alerta-card.urgencia-media .alerta-titulo {
  color: #fbbf24;
}

.alerta-card.urgencia-baja {
  background: rgba(59, 130, 246, 0.1);
  border-color: rgba(59, 130, 246, 0.3);
  color: #93c5fd;
}

.alerta-card.urgencia-baja .alerta-icono {
  color: var(--accent-primary);
}

.alerta-card.urgencia-baja .alerta-titulo {
  color: #60a5fa;
}

.alerta-titulo {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 0.15rem;
}

.alerta-desc {
  font-size: 0.85rem;
  color: var(--text-main);
  opacity: 0.9;
}

/* 7. Barra de acciones y filtros */
.timeline-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.btn-filter-chip {
  background: var(--bg-card-subtle);
  color: var(--text-muted);
  border: 1px solid var(--border-color);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.35rem 0.75rem;
  border-radius: 20px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-filter-chip:hover {
  color: var(--text-main);
  border-color: var(--text-muted);
}

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

/* 8. Línea de tiempo (Timeline) */
.timeline-container {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  position: relative;
}

.timeline-card {
  display: flex;
  gap: 1rem;
  position: relative;
}

.timeline-marker {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 0 0 24px;
}

.marker-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent-primary);
  border: 3px solid var(--bg-main);
  box-shadow: 0 0 0 2px var(--accent-primary);
  z-index: 2;
  margin-top: 1.2rem;
}

.marker-line {
  width: 2px;
  flex: 1;
  background: var(--border-color);
  margin-top: 4px;
}

.timeline-card:last-child .marker-line {
  display: none;
}

.timeline-box {
  flex: 1 1 0%;
  min-width: 0;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.timeline-box:hover {
  border-color: var(--border-focus);
}

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

.timeline-title-area {
  flex: 1 1 200px;
}

.timeline-date {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-right: 0.5rem;
}

.timeline-km {
  font-size: 0.825rem;
  font-weight: 700;
  color: var(--accent-primary);
  background: rgba(59, 130, 246, 0.1);
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
}

.timeline-concept {
  font-size: 1.1rem;
  font-weight: 700;
  margin-top: 0.35rem;
  margin-bottom: 0.35rem;
}

.timeline-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}

.badge-cat {
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--bg-card-subtle);
  color: var(--text-muted);
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  border: 1px solid var(--border-color);
}

.badge-taller {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.timeline-cost-area {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.4rem;
}

.timeline-cost {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text-main);
}

.btn-badge-factura {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: rgba(16, 185, 129, 0.15);
  color: var(--accent-success);
  border: 1px solid rgba(16, 185, 129, 0.3);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.25rem 0.55rem;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-badge-factura:hover {
  background: rgba(16, 185, 129, 0.25);
}

.timeline-notes {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
  white-space: pre-line;
}

.timeline-next {
  margin-top: 0.6rem;
  font-size: 0.825rem;
  color: var(--accent-warning);
  background: rgba(245, 158, 11, 0.08);
  padding: 0.35rem 0.6rem;
  border-radius: 6px;
  border-left: 3px solid var(--accent-warning);
}

.timeline-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.85rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--border-color);
}

/* 9. Estado vacío */
.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  background: var(--bg-card);
  border: 1px dashed var(--border-color);
  border-radius: var(--radius-lg);
  margin-top: 1rem;
}

.empty-state-icon {
  font-size: 2.5rem;
  margin-bottom: 0.75rem;
}

.empty-state-title {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 0.35rem;
}

.empty-state-desc {
  font-size: 0.9rem;
  color: var(--text-muted);
  max-width: 440px;
  margin: 0 auto 1.25rem;
}

/* 10. Modales canónicos */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 9999;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

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

.modal-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
  transform: translateY(15px);
  transition: transform 0.25s ease;
}

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

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

.modal-title {
  font-size: 1.2rem;
  font-weight: 700;
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: color 0.2s;
}

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

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

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-color);
}

/* Campos de formulario */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

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

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

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

/* Subida y previsualización de facturas */
.factura-upload-zone {
  border: 2px dashed var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
  text-align: center;
  background: var(--bg-input);
  cursor: pointer;
  transition: border-color 0.2s;
}

.factura-upload-zone:hover {
  border-color: var(--border-focus);
}

.factura-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.5rem 0.75rem;
  margin-top: 0.5rem;
}

.factura-preview-thumb {
  width: 50px;
  height: 50px;
  object-fit: cover;
  border-radius: 4px;
}

/* Visor de facturas */
.visor-factura-container {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  border-radius: var(--radius-md);
  max-height: 70vh;
  overflow: hidden;
}

.visor-factura-img {
  max-width: 100%;
  max-height: 65vh;
  object-fit: contain;
}

/* 11. Responsive para móviles conforme a normas */
@media (max-width: 768px) {
  .tool-layout {
    margin: 1rem auto 2rem;
    padding: 0 0.75rem;
  }

  .tool-with-sidebar {
    flex-direction: column;
    gap: 1rem;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .form-row, .form-row-3 {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }

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

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

  .btn {
    width: 100%;
  }

  .timeline-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .timeline-controls .btn-primary {
    width: 100%;
  }

  .timeline-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .timeline-cost-area {
    align-items: flex-start;
  }

  .modal-card {
    max-height: 95vh;
  }

  .modal-footer {
    flex-direction: column;
  }
}
