:root {
  --verde-oscuro: #2D5016;
  --verde-medio: #4A7C23;
  --verde-claro: #E8F5E0;
  --dorado: #8B8000;
  --texto: #333333;
  --bg: #F5F5F5;
  --blanco: #FFFFFF;
  --rojo: #EF5350;
  --naranja: #FF9800;
  --amarillo: #FDD835;
  --verde: #4CAF50;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--texto);
  min-height: 100vh;
}

/* LOGIN */
.login-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 500;
}
.login-box {
  background: white;
  padding: 30px;
  border-radius: 16px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.1);
  width: 90%;
  max-width: 340px;
  text-align: center;
}
.login-box h2 {
  color: var(--verde-oscuro);
  font-size: 18px;
  margin-top: 8px;
}
.login-box .logo {
  display: inline-block;
  background: var(--verde-oscuro);
  color: white;
  font-weight: 900;
  font-size: 24px;
  padding: 8px 20px;
  border-radius: 8px;
  letter-spacing: 3px;
}

/* HEADER */
.header {
  background: var(--verde-oscuro);
  color: white;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
.header .logo {
  background: white;
  color: var(--verde-oscuro);
  font-weight: 900;
  font-size: 18px;
  padding: 4px 10px;
  border-radius: 6px;
  letter-spacing: 2px;
}
.header h1 {
  font-size: 16px;
  font-weight: 600;
  flex: 1;
}

/* SAVE INDICATOR */
.save-indicator {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 6px;
  white-space: nowrap;
}
.save-indicator.saved { background: rgba(255,255,255,0.2); color: #C8E6C9; }
.save-indicator.saving { background: rgba(255,255,0,0.2); color: #FFF9C4; }
.save-indicator.save-error { background: rgba(255,0,0,0.3); color: #FFCDD2; }

/* NAVIGATION */
.nav-bar {
  display: flex;
  background: var(--blanco);
  border-bottom: 2px solid var(--verde-claro);
  overflow-x: auto;
}
.nav-bar button {
  flex: 1;
  padding: 12px 8px;
  border: none;
  background: none;
  font-size: 13px;
  font-weight: 600;
  color: #888;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
  min-width: 80px;
}
.nav-bar button.active {
  color: var(--verde-oscuro);
  border-bottom-color: var(--verde-medio);
}
.nav-bar button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* MAIN */
.main { padding: 16px; max-width: 600px; margin: 0 auto; }

/* SECTIONS */
.section { display: none; }
.section.active { display: block; }

/* FORMS */
.form-group {
  margin-bottom: 14px;
}
.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--verde-oscuro);
  margin-bottom: 4px;
  text-transform: uppercase;
}
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 12px;
  border: 2px solid #ddd;
  border-radius: 8px;
  font-size: 16px;
  transition: border-color 0.2s;
}
.form-group input:focus,
.form-group select:focus {
  border-color: var(--verde-medio);
  outline: none;
}
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* FIELD ERRORS */
.field-error {
  display: none;
  font-size: 12px;
  color: #C62828;
  margin-top: 3px;
}
.input-error {
  border-color: #C62828 !important;
}

/* BUTTONS */
.btn {
  display: block;
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.2s;
  min-height: 48px;
}
.btn:active { transform: scale(0.97); }
.btn-primary {
  background: var(--verde-oscuro);
  color: white;
}
.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-secondary {
  background: var(--verde-claro);
  color: var(--verde-oscuro);
}
.btn-danger {
  background: #FFEBEE;
  color: #C62828;
}
.btn-small {
  display: inline-block;
  width: auto;
  padding: 8px 16px;
  font-size: 13px;
  min-height: 36px;
}

/* DEFECT CHIPS */
.chips-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}
.chip {
  padding: 10px 14px;
  border: 2px solid #ddd;
  border-radius: 20px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
  background: white;
}
.chip.selected {
  background: var(--verde-oscuro);
  color: white;
  border-color: var(--verde-oscuro);
}

/* PHOTO UPLOAD */
.foto-upload-area {
  border: 2px dashed #ccc;
  border-radius: 10px;
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s;
  margin-top: 4px;
}
.foto-upload-area:hover,
.foto-upload-area.dragging {
  border-color: var(--verde-medio);
  background: var(--verde-claro);
}
.foto-upload-area .icon { font-size: 32px; margin-bottom: 4px; }
.foto-upload-area p { font-size: 13px; color: #888; }

.foto-preview-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
}
.foto-thumb {
  width: 80px;
  height: 80px;
  object-fit: cover;
  border-radius: 8px;
  border: 2px solid #ddd;
}
.foto-thumb-wrap {
  position: relative;
}
.foto-thumb-wrap .remove-foto {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--rojo);
  color: white;
  border: none;
  font-size: 14px;
  cursor: pointer;
  line-height: 22px;
  text-align: center;
}

/* PALLET LIST */
.pallet-list { margin-top: 16px; }
.pallet-item {
  background: white;
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 10px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  display: flex;
  align-items: center;
  gap: 12px;
}
.pallet-badge {
  width: 50px;
  height: 50px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 900;
  font-size: 14px;
  flex-shrink: 0;
}
.pallet-info { flex: 1; }
.pallet-info .pallet-num { font-weight: 700; font-size: 15px; }
.pallet-info .pallet-details { font-size: 12px; color: #888; margin-top: 2px; }
.pallet-info .pallet-defectos { font-size: 11px; color: #666; margin-top: 2px; }
.pallet-thumbs { display: flex; gap: 4px; margin-top: 4px; }
.pallet-mini-thumb {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid #ddd;
}
.pallet-actions { display: flex; gap: 6px; }
.pallet-actions button {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 16px;
}
.pallet-actions .edit-btn { background: #E3F2FD; color: #1565C0; }
.pallet-actions .delete-btn { background: #FFEBEE; color: #C62828; }

/* MINI RESUMEN */
.mini-resumen {
  background: white;
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 14px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}
.mini-progress {
  height: 6px;
  background: #eee;
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 8px;
}
.mini-progress-bar {
  height: 100%;
  background: var(--verde-medio);
  border-radius: 3px;
  transition: width 0.3s;
  width: 0%;
}
.mini-stats {
  font-size: 12px;
  color: #666;
  text-align: center;
}

/* MODE TOGGLE */
.mode-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}
.mode-toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--verde-oscuro);
}
.mode-label {
  font-size: 13px;
  color: var(--verde-oscuro);
  font-weight: 600;
}

/* KPI CARDS */
.kpi-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 20px;
}
.kpi-card {
  background: white;
  border-radius: 10px;
  padding: 16px;
  text-align: center;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}
.kpi-card .kpi-value {
  font-size: 32px;
  font-weight: 900;
}
.kpi-card .kpi-label {
  font-size: 11px;
  color: #888;
  margin-top: 4px;
  text-transform: uppercase;
}
.kpi-card.critical .kpi-value { color: #C62828; }
.kpi-card.good .kpi-value { color: #2E7D32; }
.kpi-card.normal .kpi-value { color: var(--verde-oscuro); }

/* RESUMEN TABLE */
.resumen-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  background: white;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}
.resumen-table th {
  background: var(--verde-oscuro);
  color: white;
  padding: 10px;
  text-align: left;
  font-size: 12px;
}
.resumen-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #eee;
}

/* HISTORIAL */
.historial-item {
  background: white;
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 10px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.historial-item h3 { font-size: 15px; color: var(--verde-oscuro); }
.historial-item p { font-size: 12px; color: #888; margin-top: 2px; }
.historial-item .badge {
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}
.badge-pdf { background: var(--verde-claro); color: var(--verde-oscuro); }
.badge-pending { background: #FFF9C4; color: #F57F17; }

/* LOADING */
.loading-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  justify-content: center;
  align-items: center;
}
.loading-overlay.active { display: flex; }
.loading-box {
  background: white;
  padding: 30px;
  border-radius: 14px;
  text-align: center;
}
.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #ddd;
  border-top-color: var(--verde-oscuro);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* EMPTY STATE */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: #888;
}
.empty-state .icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }

/* TOAST */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--verde-oscuro);
  color: white;
  padding: 12px 24px;
  border-radius: 10px;
  font-size: 14px;
  z-index: 300;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
  max-width: 90%;
  text-align: center;
}
.toast.show { opacity: 1; }
.toast.toast-error { background: #C62828; }
.toast.toast-warn { background: #E65100; }

/* HEADER USER */
.header-user {
  display: flex;
  align-items: center;
  gap: 8px;
}
.user-badge {
  background: rgba(255,255,255,0.2);
  color: white;
  font-weight: 700;
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 6px;
  cursor: pointer;
}
.btn-icon {
  background: none;
  border: none;
  color: rgba(255,255,255,0.7);
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}
.btn-icon:hover { color: white; }

/* SAVE BAR */
.save-bar {
  background: var(--verde-claro);
  text-align: center;
  padding: 2px 0;
}

/* ADMIN */
.admin-user-card {
  background: white;
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 10px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  display: flex;
  align-items: center;
  gap: 12px;
}
