:root {
  --primary: #1e3a8a;
  --primary-hover: #1e40af;
  --primary-light: #eff6ff;
  --secondary: #0d9488;
  --secondary-hover: #0f766e;
  --accent: #d97706;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #ea580c;
  --dark: #0f172a;
  --gray-800: #1e293b;
  --gray-700: #334155;
  --gray-600: #475569;
  --gray-500: #64748b;
  --gray-400: #94a3b8;
  --gray-200: #e2e8f0;
  --gray-100: #f1f5f9;
  --gray-50: #f8fafc;
  --surface: #ffffff;
  --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.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
  background-color: var(--gray-100);
  color: var(--gray-800);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* NAVBAR */
.navbar {
  background: linear-gradient(135deg, #1e3a8a 0%, #172554 100%);
  color: white;
  padding: 0.75rem 1.25rem;
  box-shadow: var(--shadow-md);
  position: sticky;
  top: 0;
  z-index: 50;
}

.nav-container {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  color: white;
}

.brand-icon {
  width: 42px;
  height: 42px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.brand-text h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.2;
}

.brand-text span {
  font-size: 0.75rem;
  color: #93c5fd;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

.nav-network-badge {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: #bfdbfe;
  cursor: pointer;
}
.nav-network-badge:hover {
  background: rgba(255, 255, 255, 0.2);
}
.pulse-dot {
  width: 8px;
  height: 8px;
  background-color: #22c55e;
  border-radius: 50%;
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(34, 197, 94, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(34, 197, 94, 0); }
}

/* TABS NAVIGATION */
.tab-navigation {
  background: var(--surface);
  border-bottom: 1px solid var(--gray-200);
  position: sticky;
  top: 61px;
  z-index: 40;
}

.tab-container {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  overflow-x: auto;
  scrollbar-width: none;
}
.tab-container::-webkit-scrollbar {
  display: none;
}

.tab-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.9rem 1.25rem;
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  color: var(--gray-600);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  white-space: nowrap;
  transition: var(--transition);
}

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

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

.tab-btn .badge {
  background: var(--gray-200);
  color: var(--gray-700);
  font-size: 0.7rem;
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-full);
}
.tab-btn.active .badge {
  background: var(--primary);
  color: white;
}

/* MAIN CONTENT */
.main-wrapper {
  max-width: 1400px;
  margin: 1.5rem auto;
  padding: 0 1rem;
  flex: 1;
  width: 100%;
}

.tab-pane {
  display: none;
  animation: fadeIn 0.25s ease-out;
}
.tab-pane.active {
  display: block;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* STATS GRID */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  gap: 1rem;
  transition: var(--transition);
}
.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
}
.stat-icon.blue { background: #dbeafe; color: #1d4ed8; }
.stat-icon.orange { background: #ffedd5; color: #c2410c; }
.stat-icon.green { background: #dcfce7; color: #15803d; }
.stat-icon.purple { background: #f3e8ff; color: #7e22ce; }

.stat-info h3 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--dark);
  line-height: 1.1;
}
.stat-info p {
  font-size: 0.8rem;
  color: var(--gray-500);
  font-weight: 500;
  margin-top: 0.15rem;
}

/* CARDS AND CONTAINERS */
.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--gray-200);
  box-shadow: var(--shadow-sm);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--gray-200);
  flex-wrap: wrap;
  gap: 0.75rem;
}

.card-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--dark);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.card-subtitle {
  font-size: 0.825rem;
  color: var(--gray-500);
}

/* BUTTONS */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  white-space: nowrap;
}

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

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

.btn-success {
  background-color: var(--success);
  color: white;
}
.btn-success:hover {
  background-color: #15803d;
}

.btn-outline {
  background-color: transparent;
  border-color: var(--gray-300);
  color: var(--gray-700);
}
.btn-outline:hover {
  background-color: var(--gray-100);
  border-color: var(--gray-400);
}

.btn-danger {
  background-color: var(--danger);
  color: white;
}
.btn-danger:hover {
  background-color: #b91c1c;
}

.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.75rem;
  border-radius: var(--radius-sm);
}

.btn-lg {
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  border-radius: var(--radius-md);
}

/* FORMS */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.825rem;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: 0.35rem;
}

.form-control {
  width: 100%;
  padding: 0.6rem 0.75rem;
  font-size: 0.875rem;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-md);
  background-color: var(--surface);
  color: var(--dark);
  transition: var(--transition);
  outline: none;
}
.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(30, 58, 138, 0.15);
}

textarea.form-control {
  min-height: 75px;
  resize: vertical;
}

/* DYNAMIC MOTOR ITEM ROW */
.motor-entry-card {
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius-md);
  padding: 1rem;
  margin-bottom: 1rem;
  position: relative;
  transition: var(--transition);
}
.motor-entry-card:hover {
  border-color: var(--primary);
  background: #fdfdfe;
}

.motor-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.motor-badge-num {
  background: var(--primary);
  color: white;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-full);
}

/* PHOTO UPLOAD & PREVIEW */
.photo-uploader {
  border: 2px dashed var(--gray-300);
  border-radius: var(--radius-md);
  padding: 1rem;
  text-align: center;
  background: white;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
  min-height: 120px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.photo-uploader:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}

.photo-uploader input[type="file"] {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.photo-preview {
  width: 100%;
  height: 110px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  display: none;
}
.photo-preview.visible {
  display: block;
}

/* SIGNATURE PAD BOX */
.signature-box {
  background: var(--surface);
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-md);
  padding: 0.75rem;
  margin-bottom: 1rem;
}

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

.sig-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--dark);
}

.signature-canvas-wrap {
  position: relative;
  width: 100%;
  height: 160px;
  background: #fcfcfc;
  border: 1px dashed var(--gray-300);
  border-radius: var(--radius-sm);
  touch-action: none;
}

.signature-canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
}

.sig-placeholder-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--gray-400);
  font-size: 0.85rem;
  pointer-events: none;
  user-select: none;
}

/* TABLES */
.table-responsive {
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--gray-200);
}

.custom-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.875rem;
  background: white;
}

.custom-table th {
  background-color: var(--gray-50);
  color: var(--gray-700);
  font-weight: 700;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--gray-200);
  white-space: nowrap;
}

.custom-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
}

.custom-table tr:hover td {
  background-color: #f8fafc;
}

/* BADGES */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.status-taller {
  background-color: #ffedd5;
  color: #9a3412;
  border: 1px solid #fdba74;
}

.status-entregado {
  background-color: #dcfce7;
  color: #166534;
  border: 1px solid #86efac;
}

.status-parcial {
  background-color: #fef9c3;
  color: #854d0e;
  border: 1px solid #fde047;
}

/* MODALS */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(3px);
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  overflow-y: auto;
}
.modal-backdrop.active {
  display: flex;
}

.modal-dialog {
  background: white;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 800px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modalScale 0.2s ease-out;
}
@keyframes modalScale {
  from { transform: scale(0.95); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--gray-50);
}
.modal-header h3 {
  font-size: 1.15rem;
  color: var(--dark);
  font-weight: 700;
}

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
  flex: 1;
}

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

.close-btn {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--gray-500);
  cursor: pointer;
  line-height: 1;
}
.close-btn:hover {
  color: var(--dark);
}

/* TOAST NOTIFICATIONS */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  background: white;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 0.85rem 1.25rem;
  font-size: 0.875rem;
  border-left: 4px solid var(--primary);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 280px;
  animation: slideIn 0.3s ease-out;
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }
@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* CHECKLIST TOGGLES IN CERTIFICATE */
.check-toggle-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.65rem;
}

.check-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  padding: 0.6rem 0.85rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  user-select: none;
}
.check-item:hover {
  background: #f1f5f9;
}
.check-item input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--success);
  cursor: pointer;
}

/* AUTO-UPPERCASE PARA CAMPOS CLAVE */
.motor-make,
.motor-model,
.motor-serial,
#ingreso-company,
#ingreso-dropoff-name,
#ingreso-received-name,
#dispatch-emp-name,
#dispatch-cli-name,
#client-name-input,
#client-contact-input {
  text-transform: uppercase;
}

/* RESPONSIVE QUERIES */
@media (max-width: 768px) {
  .nav-network-badge {
    display: none;
  }
  .card {
    padding: 1rem;
  }
  .form-grid {
    grid-template-columns: 1fr;
  }
  .tab-btn {
    padding: 0.75rem 0.9rem;
    font-size: 0.825rem;
  }
  .signature-canvas-wrap {
    height: 140px;
  }
}


/* ===== Acceso a Motores (login, cambio de clave y usuarios) ===== */
.acceso-fondo { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; background: var(--dark); }
.acceso-caja { width: 100%; max-width: 400px; background: var(--surface); border-radius: var(--radius-lg); padding: 1.75rem; box-shadow: var(--shadow-md); }
.acceso-caja h1 { font-size: 1.25rem; font-weight: 800; color: var(--dark); }
.acceso-caja p.sub { font-size: 0.85rem; color: var(--gray-500); margin: 0.25rem 0 1.25rem; }
.acceso-error { display: none; background: #fef2f2; border: 1px solid #fecaca; color: var(--danger); font-size: 0.85rem; font-weight: 600; padding: 0.6rem 0.75rem; border-radius: var(--radius-sm); margin-bottom: 0.75rem; }
.acceso-error.visible { display: block; }
.acceso-caja .btn { width: 100%; justify-content: center; }
.acceso-volver { display: block; text-align: center; margin-top: 1rem; font-size: 0.85rem; color: var(--primary); }
.nav-sesion { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.nav-usuario { font-size: 0.8rem; color: inherit; opacity: 0.85; }
[hidden] { display: none !important; }
:root { --gray-300: #cbd5e1; } /* el documento la usa en bordes pero no la define */
.nav-sesion .btn-outline { color: #fff; border-color: rgba(255, 255, 255, 0.55); background: transparent; }
.nav-sesion .btn-outline:hover { background: rgba(255, 255, 255, 0.15); color: #fff; }
@media (max-width: 640px) {
  #form-dispatch > .form-grid:first-child,
  #form-cert-quality .form-grid { grid-template-columns: 1fr !important; }
}
@media (max-width: 640px) {
  .btn-lg { white-space: normal; width: 100%; justify-content: center; }
}
.acceso-logo { display: block; width: 100%; max-width: 280px; height: auto; margin: 0 auto 1.25rem; }
.brand-logo { width: 52px; height: 52px; flex-shrink: 0; }
