:root {
  --bg: #f8fafc;
  --card-bg: #ffffff;
  --primary: #1e3a8a;
  --primary-hover: #1d4ed8;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --success: #15803d;
  --success-bg: #dcfce7;
  --warning: #b45309;
  --warning-bg: #fef3c7;
  --danger: #b91c1c;
  --danger-bg: #fee2e2;
  --info: #0369a1;
  --info-bg: #e0f2fe;
}

* { 
  box-sizing: border-box; 
  margin: 0; 
  padding: 0; 
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; 
}

/* 1. Control global del documento: flujo vertical libre y natural */
html, body { 
  height: auto;
  min-height: 100vh;
  overflow-x: hidden;
  overflow-y: auto;
  background-color: var(--bg); 
  color: var(--text); 
  padding-bottom: 60px; 
}

/* Barra Superior */
.top-bar {
  background-color: var(--primary);
  color: white;
  padding: 12px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.top-bar h1 { font-size: 16px; font-weight: 600; }
.view-switch { display: flex; background: rgba(255,255,255,0.15); border-radius: 8px; padding: 3px; }
.view-btn {
  background: none; border: none; color: white; padding: 6px 14px;
  font-size: 13px; font-weight: 500; cursor: pointer; border-radius: 6px; transition: background 0.2s;
}
.view-btn.active { background: white; color: var(--primary); }

.container { 
  max-width: 1100px; 
  margin: 24px auto; 
  padding: 0 16px; 
  height: auto;
  overflow: visible;
}

.card {
  background: var(--card-bg); 
  border-radius: 12px; 
  border: 1px solid var(--border);
  padding: 20px; 
  margin-bottom: 20px; 
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  height: auto;
  overflow: visible;
}

.badge { display: inline-block; padding: 4px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }

/* Barra de Progreso */
.progress-container { margin: 16px 0; }
.progress-label { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 6px; }
.progress-bar-bg { background: #e2e8f0; height: 10px; border-radius: 6px; overflow: hidden; }
.progress-bar-fill { background: #22c55e; height: 100%; width: 0%; transition: width 0.4s ease; }

/* Drag & Drop con Miniaturas */
.dnd-pool {
  background: #f8fafc; border: 2px dashed #cbd5e1; border-radius: 10px;
  padding: 16px; min-height: 110px; display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin-bottom: 20px;
}
.cargo-card {
  background: white; border: 1px solid #cbd5e1; border-radius: 8px;
  padding: 8px 12px; display: flex; align-items: center; gap: 10px;
  cursor: grab; box-shadow: 0 2px 4px rgba(0,0,0,0.06); user-select: none;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.cargo-card:hover { transform: translateY(-2px); box-shadow: 0 4px 8px rgba(0,0,0,0.1); }
.cargo-card:active { cursor: grabbing; }

.cargo-thumb {
  width: 44px; height: 44px; border-radius: 6px; object-fit: cover;
  border: 1px solid #e2e8f0; cursor: zoom-in;
}
.cargo-card .meta { font-size: 12px; }
.cargo-card .meta strong { display: block; font-size: 13px; color: var(--text); }
.cargo-card .btn-zoom {
  border: none; background: #e0f2fe; color: var(--info); border-radius: 4px;
  font-size: 10px; padding: 2px 6px; font-weight: 600; cursor: pointer; margin-top: 2px;
}

.drop-slot {
  border: 2px dashed #94a3b8; background: #f8fafc; border-radius: 8px;
  padding: 8px 12px; min-height: 52px; display: flex; align-items: center; justify-content: space-between;
  color: var(--text-muted); font-size: 12px; transition: background 0.2s, border-color 0.2s;
}
.drop-slot * { pointer-events: none; }
.drop-slot.dragover { background: #e0f2fe; border-color: var(--info); }
.drop-slot.filled { border-style: solid; border-color: #86efac; background: #f0fdf4; }

/* Filas de Informes */
.muni-section-header {
  background: #f1f5f9; padding: 10px 14px; font-size: 14px; font-weight: 700;
  color: var(--primary); border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.report-row {
  display: grid; grid-template-columns: 2fr 1.2fr 1.5fr; gap: 16px;
  align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--border);
}
.report-row:last-child { border-bottom: none; }
.report-title { font-size: 14px; font-weight: 600; }
.report-sub { font-size: 12px; color: var(--text-muted); }

/* Notas */
.notes-box { background: #f8fafc; border-radius: 8px; padding: 14px; margin-top: 16px; }
.note-item { font-size: 13px; margin-bottom: 8px; }
.note-item strong { color: var(--primary); }

/* 2. Vista Móvil (Sin scroll trapping en PC ni teléfono) */
.mobile-frame {
  max-width: 460px; 
  margin: 0 auto; 
  background: white; 
  border-radius: 20px;
  border: 4px solid #334155; 
  overflow: visible; 
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  height: auto;
}
.mobile-header { 
  background: var(--primary); 
  color: white; 
  padding: 16px; 
  border-radius: 16px 16px 0 0;
}
.mobile-content { 
  padding: 16px; 
  height: auto; 
  max-height: none; 
  overflow: visible; 
}

.btn-mobile {
  width: 100%; background: var(--primary); color: white; border: none; padding: 12px;
  border-radius: 8px; font-weight: 600; font-size: 14px; cursor: pointer;
  display: flex; justify-content: center; align-items: center; gap: 8px; margin-bottom: 12px;
}
.btn-mobile:hover { background: var(--primary-hover); }
.btn-secondary { background: #e2e8f0; color: var(--text); border: none; padding: 8px 16px; border-radius: 6px; font-size: 13px; cursor: pointer; }
.btn-secondary:hover { background: #cbd5e1; }
.m-muni-card { border: 1px solid var(--border); border-radius: 8px; margin-bottom: 14px; overflow: hidden; }
.m-muni-title { background: #f1f5f9; padding: 8px 12px; font-size: 13px; font-weight: 700; color: var(--primary); border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; }
.m-report-item { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.m-report-item:last-child { border-bottom: none; }

/* Indicadores de Urgencia */
.urgencia-tag { font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 4px; display: inline-block; margin-right: 4px; }
.urgencia-alta { background: var(--danger-bg); color: var(--danger); }
.urgencia-media { background: var(--warning-bg); color: var(--warning); }
.urgencia-baja { background: var(--success-bg); color: var(--success); }

/* Sincronización */
.sync-container { display: flex; align-items: center; gap: 6px; font-size: 11px; opacity: 0.9; }
.sync-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.sync-dot.pulse { background-color: #22c55e; box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7); animation: pulse-green 2s infinite; }
.sync-dot.paused { background-color: #94a3b8; animation: none; }

@keyframes pulse-green {
  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); }
}

/* Modales */
.modal-backdrop {
  position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
  background: rgba(15, 23, 42, 0.6); display: flex; justify-content: center; align-items: center; z-index: 200;
}
.modal-card {
  background: white; border-radius: 12px; width: 100%; max-width: 440px;
  padding: 24px; box-shadow: 0 10px 25px rgba(0,0,0,0.2);
}
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 4px; color: var(--text); }
.form-group input, .form-group select { width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.btn-primary {
  background: var(--primary); color: white; border: none; padding: 8px 16px;
  border-radius: 6px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

/* Dropzone Masiva */
.dropzone {
  border: 2px dashed #94a3b8; background: #f8fafc; border-radius: 8px;
  padding: 24px; text-align: center; cursor: pointer; color: var(--primary);
  font-weight: 500; font-size: 13px; transition: all 0.2s ease;
}
.dropzone:hover { background: #f1f5f9; border-color: var(--primary); }

.matched-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 12px; background: #f8fafc; border: 1px solid var(--border);
  border-radius: 6px; margin-bottom: 8px; font-size: 13px; gap: 10px;
}
.matched-item strong { color: var(--primary); }
.matched-badge { font-size: 11px; padding: 2px 8px; border-radius: 12px; font-weight: 600; }

/* Lightbox Modal */
.lightbox-card {
  background: white; border-radius: 12px; padding: 16px; max-width: 90vw; max-height: 90vh;
  display: flex; flex-direction: column; align-items: center;
}
.lightbox-img {
  max-width: 100%; max-height: 75vh; object-fit: contain; border-radius: 8px; border: 1px solid var(--border);
}

.hidden { display: none !important; }

/* Botón de Eliminar Lote */
.btn-danger-icon {
  background: #fee2e2;
  border: 1px solid #fca5a5;
  border-radius: 6px;
  padding: 5px 8px;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  transition: all 0.2s ease;
}
.btn-danger-icon:hover {
  background: #f87171;
}

/* Grupos del Header */
.top-bar-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.lote-group {
  display: flex;
  gap: 6px;
  align-items: center;
}

/* 3. Adaptación Responsiva Integral para Teléfonos Móviles */
@media (max-width: 768px) {
  .container {
    margin: 8px auto;
    padding: 0 8px;
  }

  .top-bar {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 12px !important;
    padding: 12px 14px !important;
  }

  .top-bar-brand {
    width: 100% !important;
  }

  .top-bar-actions {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 10px !important;
    width: 100% !important;
  }

  .lote-group {
    display: flex !important;
    width: 100% !important;
    gap: 6px !important;
  }

  .lote-group select {
    flex: 1 1 auto !important;
    min-width: 0 !important;
  }

  .view-switch {
    display: flex !important;
    width: 100% !important;
  }

  .view-switch .view-btn {
    flex: 1 !important;
    text-align: center !important;
    padding: 8px 6px !important;
    font-size: 12px !important;
  }

  /* Integración completa de la vista de campo al viewport del smartphone */
  .mobile-frame {
    max-width: 100% !important;
    width: 100% !important;
    margin: 0 !important;
    border: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
  }

  .mobile-header {
    border-radius: 0 !important;
  }

  .mobile-content {
    padding: 12px 4px !important;
    max-height: none !important;
    overflow-y: visible !important;
  }

  /* Ajuste de columnas en filas de informes si se ven en móvil */
  .report-row {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }
}