/* ═══ RESET & BASE ═══ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #1a56db;
  --primary-dark: #1544b5;
  --primary-light: #e8effc;
  --success: #059669;
  --warning: #d97706;
  --danger: #dc2626;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --radius: 10px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.06);
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,.1), 0 4px 6px rgba(0,0,0,.05);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

body {
  font-family: var(--font);
  background: var(--gray-100);
  color: var(--gray-800);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  height: 100dvh;
}

.screen { display: none; height: 100dvh; }
.screen.active { display: flex; flex-direction: column; }
.hidden { display: none !important; }

/* ═══ LOGIN ═══ */
#login-screen {
  justify-content: center;
  align-items: center;
  background: linear-gradient(135deg, #1e3a5f 0%, #1a56db 50%, #2563eb 100%);
  padding: 20px;
}

.login-container {
  background: white;
  border-radius: 16px;
  padding: 40px 32px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
}

.login-logo {
  text-align: center;
  margin-bottom: 32px;
}

.logo-icon {
  font-size: 48px;
  margin-bottom: 8px;
}

.login-logo h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--gray-900);
}

.login-subtitle {
  color: var(--gray-500);
  font-size: 14px;
  margin-top: 4px;
}

.form-group {
  margin-bottom: 18px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: 6px;
}

.form-group input {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--gray-300);
  border-radius: 8px;
  font-size: 15px;
  font-family: var(--font);
  transition: border-color .2s, box-shadow .2s;
  outline: none;
}

.form-group input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(26,86,219,.15);
}

.error-msg {
  background: #fef2f2;
  color: var(--danger);
  font-size: 13px;
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 16px;
  border: 1px solid #fecaca;
}

.btn {
  border: none;
  border-radius: 8px;
  font-family: var(--font);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s, transform .1s;
  padding: 12px 20px;
}

.btn:active { transform: scale(.98); }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-block { width: 100%; }

.btn-text, .btn-loading { vertical-align: middle; }

.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin .6s linear infinite;
  vertical-align: middle;
}

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

.login-footer {
  text-align: center;
  font-size: 12px;
  color: var(--gray-400);
  margin-top: 24px;
}

/* ═══ APP HEADER ═══ */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: white;
  border-bottom: 1px solid var(--gray-200);
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.header-logo { font-size: 28px; flex-shrink: 0; }

.header-info { min-width: 0; }

.header-info h2 {
  font-size: 15px;
  font-weight: 700;
  color: var(--gray-900);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-rfc {
  font-size: 12px;
  color: var(--gray-400);
  font-weight: 500;
}

.header-right {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.icon-btn {
  background: none;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  padding: 8px;
  cursor: pointer;
  color: var(--gray-600);
  transition: background .2s, color .2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:hover {
  background: var(--gray-100);
  color: var(--gray-800);
}

/* ═══ TABS ═══ */
.app-tabs {
  display: flex;
  background: white;
  border-bottom: 1px solid var(--gray-200);
  flex-shrink: 0;
}

.tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 8px;
  border: none;
  background: none;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  color: var(--gray-500);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color .2s, border-color .2s;
}

.tab:hover { color: var(--gray-700); }
.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.tab svg { flex-shrink: 0; }

/* ═══ TAB CONTENT ═══ */
.tab-content {
  display: none;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

.tab-content.active { display: flex; flex-direction: column; }

.tab-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px 16px 8px;
  flex-shrink: 0;
}

.tab-header h3 {
  font-size: 16px;
  font-weight: 700;
  color: var(--gray-900);
}

.badge {
  background: var(--primary-light);
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  padding: 2px 10px;
  border-radius: 100px;
}

/* ═══ MAP ═══ */
.map-container {
  flex: 1;
  min-height: 300px;
}

.map-legend {
  display: flex;
  gap: 16px;
  padding: 8px 16px;
  background: white;
  border-top: 1px solid var(--gray-200);
  font-size: 12px;
  color: var(--gray-600);
  flex-shrink: 0;
  flex-wrap: wrap;
}

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

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

.legend-dot.en_transito { background: var(--primary); }
.legend-dot.en_carga { background: var(--warning); }
.legend-dot.en_descarga { background: var(--success); }

/* ═══ CARD LIST ═══ */
.card-list {
  padding: 8px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
}

.loading-placeholder {
  text-align: center;
  padding: 40px;
  color: var(--gray-400);
}

.loading-placeholder .spinner {
  border-color: rgba(107,114,128,.2);
  border-top-color: var(--gray-400);
}

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--gray-400);
}

.empty-state-icon { font-size: 40px; margin-bottom: 8px; }
.empty-state p { font-size: 14px; }

/* ─── Viaje Card ─── */
.viaje-card {
  background: white;
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-200);
  cursor: pointer;
  transition: box-shadow .2s, border-color .2s;
}

.viaje-card:hover {
  box-shadow: var(--shadow);
  border-color: var(--primary);
}

.viaje-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.viaje-folio {
  font-size: 14px;
  font-weight: 700;
  color: var(--gray-900);
}

.viaje-estado {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 100px;
  text-transform: uppercase;
  letter-spacing: .3px;
}

.estado-en_transito { background: #dbeafe; color: #1e40af; }
.estado-en_carga { background: #fef3c7; color: #92400e; }
.estado-en_descarga { background: #d1fae5; color: #065f46; }
.estado-programado { background: var(--gray-100); color: var(--gray-600); }
.estado-despachado { background: #ede9fe; color: #5b21b6; }
.estado-completado, .estado-entregado, .estado-liquidado {
  background: #d1fae5; color: #065f46;
}

.viaje-route {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--gray-700);
  margin-bottom: 8px;
}

.route-arrow {
  color: var(--gray-400);
  flex-shrink: 0;
}

.route-city {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.viaje-meta {
  display: flex;
  gap: 14px;
  font-size: 12px;
  color: var(--gray-500);
  flex-wrap: wrap;
}

.viaje-meta span {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ═══ PAGINATION ═══ */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 16px;
  flex-shrink: 0;
}

.pagination button {
  padding: 8px 16px;
  border: 1px solid var(--gray-300);
  border-radius: 6px;
  background: white;
  font-family: var(--font);
  font-size: 13px;
  cursor: pointer;
  color: var(--gray-700);
}

.pagination button:hover:not(:disabled) { background: var(--gray-50); }
.pagination button:disabled { opacity: .4; cursor: default; }

.pagination .page-info {
  font-size: 13px;
  color: var(--gray-500);
}

/* ═══ MODAL ═══ */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.4);
}

.modal-content {
  position: relative;
  background: white;
  width: 100%;
  max-width: 500px;
  max-height: 85dvh;
  border-radius: 16px 16px 0 0;
  display: flex;
  flex-direction: column;
  animation: slideUp .25s ease-out;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-200);
  flex-shrink: 0;
}

.modal-header h3 {
  font-size: 16px;
  font-weight: 700;
}

.modal-header .icon-btn {
  font-size: 22px;
  border: none;
  padding: 4px 8px;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

/* ─── Detalle del viaje ─── */
.detail-section {
  margin-bottom: 20px;
}

.detail-section-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--gray-400);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 10px;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.detail-item label {
  display: block;
  font-size: 11px;
  color: var(--gray-400);
  font-weight: 500;
  margin-bottom: 2px;
}

.detail-item span {
  font-size: 14px;
  font-weight: 600;
  color: var(--gray-800);
}

.detail-route-box {
  background: var(--gray-50);
  border-radius: 8px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.detail-route-point {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.route-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid var(--primary);
  flex-shrink: 0;
  margin-top: 4px;
}

.route-dot.dest {
  background: var(--primary);
}

.route-line {
  width: 2px;
  height: 24px;
  background: var(--gray-300);
  margin-left: 4px;
}

.route-point-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--gray-800);
}

.route-point-state {
  font-size: 12px;
  color: var(--gray-500);
}

/* ─── Timeline ─── */
.timeline {
  position: relative;
  padding-left: 24px;
}

.timeline::before {
  content: '';
  position: absolute;
  left: 7px;
  top: 4px;
  bottom: 4px;
  width: 2px;
  background: var(--gray-200);
}

.timeline-item {
  position: relative;
  padding-bottom: 18px;
}

.timeline-item:last-child { padding-bottom: 0; }

.timeline-dot {
  position: absolute;
  left: -20px;
  top: 4px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--gray-300);
  border: 2px solid white;
  box-shadow: 0 0 0 2px var(--gray-200);
}

.timeline-item.completada .timeline-dot { background: var(--success); box-shadow: 0 0 0 2px #d1fae5; }
.timeline-item.activa .timeline-dot { background: var(--primary); box-shadow: 0 0 0 2px #dbeafe; }

.timeline-nombre {
  font-size: 14px;
  font-weight: 600;
  color: var(--gray-800);
}

.timeline-tipo {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--gray-400);
  margin-left: 6px;
}

.timeline-fechas {
  font-size: 12px;
  color: var(--gray-500);
  margin-top: 2px;
}

/* ─── ETA Box ─── */
.eta-box {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  padding: 14px;
  text-align: center;
}

.eta-label {
  font-size: 12px;
  font-weight: 600;
  color: #3b82f6;
  margin-bottom: 4px;
}

.eta-value {
  font-size: 22px;
  font-weight: 700;
  color: #1e40af;
}

.eta-detail {
  font-size: 12px;
  color: #60a5fa;
  margin-top: 2px;
}

/* ─── GPS Info ─── */
.gps-info {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.gps-item {
  background: var(--gray-50);
  border-radius: 8px;
  padding: 10px 14px;
  flex: 1;
  min-width: 100px;
  text-align: center;
}

.gps-item label {
  display: block;
  font-size: 11px;
  color: var(--gray-400);
  font-weight: 500;
}

.gps-item span {
  font-size: 16px;
  font-weight: 700;
  color: var(--gray-800);
}

/* ═══ LEAFLET CUSTOM ═══ */
.truck-popup .leaflet-popup-content-wrapper {
  border-radius: 10px;
  box-shadow: var(--shadow-md);
}

.truck-popup .leaflet-popup-content {
  margin: 12px 16px;
  font-family: var(--font);
  font-size: 13px;
}

.popup-folio {
  font-weight: 700;
  font-size: 14px;
  color: var(--gray-900);
  margin-bottom: 4px;
}

.popup-route {
  color: var(--gray-600);
  margin-bottom: 4px;
}

.popup-speed {
  font-weight: 600;
}

.truck-marker {
  background: var(--primary);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  box-shadow: 0 2px 8px rgba(26,86,219,.4);
  border: 2px solid white;
}

/* ═══ RESPONSIVE ═══ */
@media (min-width: 768px) {
  .modal-content {
    border-radius: 16px;
    margin-bottom: 40px;
    max-height: 80dvh;
  }

  .modal {
    align-items: center;
  }
}
