:root {
  --primario: #0f766e;
  --primario-soft: #ccfbf1;
  --azul-edit: #3b82f6;
  --azul-soft: #eff6ff;
  --oscuro: #020617;
  --texto: #0f172a;
  --borde: #e5e7eb;
  --fondo: #f8fafc;
  --blanco: #ffffff;
  --ok: #16a34a;
  --pend: #dc2626;
  --naranja: #f97316;
  --gris-claro: #f1f5f9;
}

body.dark-mode {
  --fondo: #0f172a;
  /* Slate 900 */
  --blanco: #1e293b;
  /* Slate 800 */
  --texto: #f1f5f9;
  /* Slate 100 */
  --borde: #334155;
  /* Slate 700 */
  --primario-soft: #115e59;
  /* Teal 800 */
  --azul-soft: #1e3a8a;
  /* Blue 900 */
  --gris-claro: #334155;
  /* Slate 700 */

  /* Ajustes específicos para inputs en dark mode */
  input,
  select,
  textarea {
    background-color: #0f172a !important;
    color: #f1f5f9 !important;
    border-color: #475569 !important;
  }

  /* TEXTO INVISIBLE FIX */
  h3,
  .step-indicator {
    color: #cbd5e1 !important;
    border-bottom-color: #334155 !important;
  }

  /* TABLAS */
  th {
    background-color: #1e293b !important;
    color: #e2e8f0 !important;
  }

  tbody tr:hover {
    background-color: #1e293b !important;
  }

  /* FILTROS */
  .filtro-check {
    background-color: #1e293b !important;
    color: #e2e8f0 !important;
    border-color: #334155 !important;
  }

  .filtro-check:hover {
    background-color: #334155 !important;
  }

  /* KPI y RESULTADOS */
  .kpi-results {
    background: rgba(15, 23, 42, 0.6) !important;
  }

  .kpi-box span {
    color: #f1f5f9 !important;
  }

  .res-ingreso {
    color: #38bdf8 !important;
  }

  /* Light blue for dark mode */

  /* BOTONES */
  .btn-cargar-obs {
    background-color: #334155 !important;
    color: #e2e8f0 !important;
    border-color: #475569 !important;
  }

  .btn-cargar-obs:hover {
    background-color: var(--primario-soft) !important;
    color: var(--primario) !important;
  }

  /* ARREGLO FINAL TABLA: Forzar fondo oscuro en filas para pisar el inline style de JS */
  tbody tr {
    background-color: var(--blanco) !important;
  }

  /* Tags en dark mode */
  .tag-camara {
    color: #38bdf8 !important;
  }

  .tag-bulto {
    color: #fed7aa !important;
  }
}

/* Clases para tags (Light Mode por defecto) */
.tag-camara {
  color: #0369a1;
}

.tag-bulto {
  color: #7c2d12;
}

* {
  box-sizing: border-box
}

body {
  margin: 0;
  padding: 16px;
  background: var(--fondo);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu;
  color: var(--texto);
}

.card {
  max-width: 1200px;
  margin: auto;
  background: var(--blanco);
  border-radius: 12px;
  padding: 18px;
  border: 1px solid var(--borde);
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

h2 {
  margin: 0 0 12px;
  font-size: 20px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: space-between;
}

h3 {
  margin: 22px 0 10px;
  font-size: 15px;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: #475569;
  border-bottom: 1px solid var(--borde);
  padding-bottom: 5px;
}

/* ===== SPINNER & BUTTONS ===== */
button {
  background: var(--primario);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

button:hover {
  filter: brightness(.9);
}

button:disabled {
  background: #94a3b8;
  cursor: not-allowed;
}

.btn-sec {
  background: #475569;
}

.btn-blue {
  background: var(--azul-edit);
}

.btn-orange {
  background: var(--naranja);
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: #ffffff;
  animation: spin 0.8s ease-in-out infinite;
}

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

select {
  padding: 10px;
  border-radius: 6px;
  border: 1px solid var(--borde);
  background: #f9fafb;
  font-size: 14px;
  width: 100%;
  cursor: pointer;
}

select:focus {
  outline: none;
  background: #fff;
  border-color: var(--primario);
  box-shadow: 0 0 0 2px rgba(15, 118, 110, .15);
}



/* ===== TOGGLE SWITCH ===== */
.theme-switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 26px;
}

.theme-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  -webkit-transition: .4s;
  transition: .4s;
}

.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  -webkit-transition: .4s;
  transition: .4s;
}

input:checked+.slider {
  background-color: var(--primario);
}

input:focus+.slider {
  box-shadow: 0 0 1px var(--primario);
}

input:checked+.slider:before {
  -webkit-transform: translateX(24px);
  -ms-transform: translateX(24px);
  transform: translateX(24px);
}

/* Rounded sliders */
.slider.round {
  border-radius: 34px;
}

.slider.round:before {
  border-radius: 50%;
}

/* Agregamos iconos dentro del slider (opcional) */
.slider:after {
  content: '☀️';
  color: white;
  display: block;
  position: absolute;
  transform: translate(-50%, -50%);
  top: 50%;
  left: 70%;
  font-size: 12px;
  font-family: system-ui;
}

input:checked+.slider:after {
  content: '🌙';
  left: 30%;
}

/* ===== TABS ===== */
.tabs {
  display: flex;
  gap: 10px;
  margin-bottom: 15px;
  border-bottom: 2px solid var(--borde);
  padding-bottom: 10px;
  margin-top: 20px;
}

.tab-btn {
  background: transparent;
  color: #64748b;
  border: none;
  font-size: 16px;
  font-weight: 600;
  padding: 8px 16px;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.2s;
}

.tab-btn:hover {
  background: var(--gris-claro);
  color: var(--texto);
}

.tab-btn.activo {
  background: var(--primario-soft);
  color: var(--primario);
  font-weight: 700;
}

/* ===== FORM ===== */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  align-items: center;
}

input {
  padding: 10px;
  border-radius: 6px;
  border: 1px solid var(--borde);
  background: #f9fafb;
  font-size: 14px;
  width: 100%;
}

input:focus {
  outline: none;
  background: #fff;
  border-color: var(--primario);
  box-shadow: 0 0 0 2px rgba(15, 118, 110, .15);
}

.check-box-container {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  padding: 8px 12px;
  border-radius: 6px;
  color: var(--primario);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  height: 42px;
}

.check-box-container input {
  width: auto;
  margin: 0;
  accent-color: var(--primario);
  cursor: pointer;
}

/* ===== SECCION KPI ===== */
.kpi-section {
  background: var(--primario-soft);
  padding: 15px;
  border-radius: 8px;
  margin-top: 15px;
  border: 1px solid #99f6e4;
}

.kpi-row {
  display: flex;
  flex-wrap: wrap;
  gap: 20px;
  align-items: flex-start;
  justify-content: space-between;
}

.kpi-box strong {
  font-size: 13px;
  color: var(--primario);
  display: block;
  text-transform: uppercase;
}

.kpi-box span {
  font-size: 26px;
  font-weight: 800;
  color: var(--oscuro);
}

.kpi-global {
  border-right: 1px solid #99f6e4;
  padding-right: 20px;
  min-width: 120px;
}

.kpi-calc-area {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.kpi-inputs {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.kpi-inputs input {
  padding: 8px;
  width: 135px;
}

.kpi-results {
  display: flex;
  gap: 20px;
  margin-left: 10px;
  background: rgba(255, 255, 255, 0.6);
  padding: 5px 15px;
  border-radius: 6px;
}

.res-ingreso {
  color: #0369a1 !important;
}

.res-proceso {
  color: var(--ok) !important;
}

/* ===== FILTROS TABLA ===== */
.filtros {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  align-items: center;
}

.filtro-check {
  display: flex;
  align-items: center;
  gap: 5px;
  background: white;
  border: 1px solid var(--borde);
  padding: 0 10px;
  height: 42px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  color: #475569;
  cursor: pointer;
  user-select: none;
}

.filtro-check:hover {
  background: var(--gris-claro);
  border-color: var(--primario);
}

.filtro-check input {
  width: auto;
  margin: 0;
  cursor: pointer;
}

/* ===== TABLA PC ===== */
.tabla-container {
  max-height: 55vh;
  overflow-y: auto;
  overflow-x: auto;
  border: 1px solid var(--borde);
  border-radius: 10px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th {
  background: #f1f5f9;
  color: #475569;
  font-weight: 600;
  padding: 12px 9px;
  text-align: left;
  position: sticky;
  top: 0;
  z-index: 10;
}

td {
  padding: 10px 9px;
  border-top: 1px solid var(--borde);
  white-space: nowrap;
}

tbody tr:hover {
  filter: brightness(0.97);
}

.estado-ok {
  color: var(--ok);
  font-weight: 700;
}

.estado-pend {
  color: var(--pend);
  font-weight: 700;
}

/* ===== ESCANER PERSONALIZADO ===== */
.scanner-box {
  width: 100% !important;
  max-width: 500px !important;
  height: 80vh;
  max-height: 500px;
  position: relative;
  border: none !important;
}

#reader video {
  object-fit: cover;
  border-radius: 12px;
}

.scanner-laser {
  position: absolute;
  top: 0;
  left: 10%;
  right: 10%;
  height: 2px;
  background: #ef4444;
  box-shadow: 0 0 4px #ef4444;
  z-index: 10;
  animation: scanLine 2s infinite ease-in-out;
  opacity: 0.8;
}

@keyframes scanLine {
  0% {
    top: 10%;
    opacity: 0;
  }

  10% {
    opacity: 1;
  }

  90% {
    opacity: 1;
  }

  100% {
    top: 90%;
    opacity: 0;
  }
}

/* ===== MODALES ===== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(2, 6, 23, 0.6);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(2px);
}

/* Asegúrate de que esto exista o agrégalo */
.modal-overlay.activo {
  display: flex;
  /* O block, dependiendo de como centres tus modales */
  visibility: visible;
  opacity: 1;
}

.modal-box {
  background: var(--blanco);
  padding: 24px;
  border-radius: 12px;
  width: 90%;
  max-width: 450px;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  border: 1px solid var(--borde);
  animation: fadeIn 0.2s ease-out;
  display: flex;
  flex-direction: column;
}

.modal-header {
  font-size: 18px;
  font-weight: 700;
  color: var(--primario);
  margin-bottom: 15px;
  border-bottom: 1px solid var(--borde);
  padding-bottom: 10px;
}

.modal-box-edit {
  background: var(--blanco);
  padding: 24px;
  border-radius: 12px;
  width: 90%;
  max-width: 400px;
  box-shadow: 0 10px 25px -5px rgba(59, 130, 246, 0.25);
  border: 1px solid #bfdbfe;
  border-top: 5px solid var(--azul-edit);
  animation: slideIn 0.2s ease-out;
  display: flex;
  flex-direction: column;
}

.modal-header-edit {
  font-size: 18px;
  font-weight: 700;
  color: var(--azul-edit);
  margin-bottom: 15px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-body {
  margin-bottom: 15px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: auto;
  flex-wrap: wrap;
}

.step-indicator {
  font-size: 13px;
  color: #64748b;
  margin-bottom: 8px;
  font-weight: 600;
}

/* ===== ANIMACION EXITO ===== */
.success-circle {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: #dcfce7;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 15px auto;
  border: 2px solid var(--ok);
}

.success-icon {
  font-size: 32px;
  color: var(--ok);
  font-weight: bold;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ===== MOBILE ===== */
@media(max-width:768px) {
  body {
    padding: 10px
  }

  h2 {
    font-size: 18px
  }

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

  .kpi-row {
    flex-direction: column;
    gap: 15px;
  }

  .kpi-global {
    border-right: none;
    border-bottom: 1px solid #99f6e4;
    padding-bottom: 15px;
    width: 100%;
  }

  .kpi-calc-area {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }

  .kpi-inputs {
    width: 100%;
  }

  .kpi-inputs input {
    flex: 1;
  }

  .kpi-results {
    margin-left: 0;
    justify-content: space-around;
    margin-top: 10px;
  }

  .filtros {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    align-items: stretch;
  }

  /* Inputs de texto y fecha ocupan todo el ancho (2 columnas) */
  #filtroTexto,
  #filtroFecha,
  .filtros button {
    grid-column: span 2;
    width: 100%;
  }

  /* Los checkbox se acomodan en la grilla (1 columna c/u, o ajustamos) */
  .filtro-check {
    justify-content: center;
    /* Centrar contenido en celular */
  }

  /* IMPORTANTE: Evitar que el input checkbox se estire al 100% */
  .filtros input:not([type="checkbox"]) {
    width: 100%;
  }

  button {
    padding: 12px;
  }

  thead {
    display: none;
  }

  .tabla-container {
    border: none;
    overflow: visible;
  }

  table {
    min-width: 100%;
  }

  tbody tr {
    display: block;
    margin-bottom: 16px;
    border: 1px solid var(--borde);
    border-radius: 8px;
    padding: 12px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.03);
  }

  tbody td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-top: none;
    border-bottom: 1px solid #f1f5f9;
    white-space: normal;
    font-size: 14px;
  }

  tbody td:last-child {
    border-bottom: none;
    display: block;
    padding-top: 15px;
    text-align: center;
  }

  tbody td::before {
    content: attr(data-label);
    font-weight: 700;
    color: #475569;
    margin-right: 12px;
  }

  tbody td:last-child::before {
    display: none;
  }

  tbody td:last-child button {
    width: 100%;
    padding: 12px;
    font-size: 16px;
  }
}

/* --- ESTILOS AGREGADOS PARA LA FUNCIONALIDAD NUEVA --- */
.spinner-grande {
  width: 50px;
  height: 50px;
  border: 5px solid var(--primario-soft);
  border-top: 5px solid var(--primario);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

#modalCargando {
  backdrop-filter: blur(4px);
  flex-direction: column;
}

#modalCargando p {
  font-family: system-ui, -apple-system, sans-serif;
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0% {
    opacity: 0.5;
  }

  50% {
    opacity: 1;
  }

  100% {
    opacity: 0.5;
  }
}

.btn-cargar-obs {
  background: #f1f5f9;
  color: #475569;
  border: 1px solid var(--borde);
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  border-radius: 4px;
  margin-top: 5px;
  display: inline-block;
}

.btn-cargar-obs:hover {
  background: var(--primario-soft);
  color: var(--primario);
}

/* ===== ANIMACIONES Y MEJORAS UI ===== */
@keyframes cascadeIn {
  from {
    opacity: 0;
    transform: translateY(15px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.cascade-item {
  opacity: 0;
  /* Inicia invisible */
  animation: cascadeIn 0.5s ease-out forwards;
}

/* Mejoras visuales generales */
.card {
  box-shadow: 0 10px 30px -5px rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(229, 231, 235, 0.8);
  backdrop-filter: blur(5px);
}

input,
select {
  transition: all 0.2s ease;
  border: 1px solid #e2e8f0;
}

input:focus,
select:focus {
  transform: translateY(-1px);
  box-shadow: 0 4px 6px -1px rgba(15, 118, 110, 0.1);
}

button {
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

button:active {
  transform: scale(0.97);
}

tbody tr:hover {
  transform: scale(1.005);
  background-color: #f8fafc;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02);
  z-index: 1;
  position: relative;
  transition: all 0.1s ease;
}