/* ── Reset & Variables ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --azul:        #0D1B2A;
  --azul-med:    #1B3A5C;
  --azul-claro:  #2E6DA4;
  --verde:       #27AE60;
  --naranja:     #E67E22;
  --rojo:        #E74C3C;
  --amarillo:    #F1C40F;
  --gris:        #7F8C8D;
  --gris-claro:  #ECF0F1;
  --bg:          #0F1923;
  --bg-card:     #162232;
  --bg-input:    #1E2F44;
  --texto:       #E8EDF2;
  --texto-dim:   #8FA3B8;
  --borde:       #2A3F57;
  --radio:       10px;
  --radio-sm:    6px;
  --sombra:      0 4px 20px rgba(0,0,0,.4);
  --trans:       .2s ease;
}

html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--texto);
  min-height: 100vh;
  line-height: 1.5;
}

/* ── Tipografía ─────────────────────────────────────────────────────────── */
h1 { font-size: 1.6rem; font-weight: 700; }
h2 { font-size: 1.2rem; font-weight: 700; }
h3 { font-size: 1rem;   font-weight: 600; }
p  { color: var(--texto-dim); font-size: .9rem; }

/* ── Layout base ────────────────────────────────────────────────────────── */
.app-shell {
  max-width: 600px;
  margin: 0 auto;
  padding: 0 0 80px;
}

/* ── Header ─────────────────────────────────────────────────────────────── */
.header {
  background: var(--azul-med);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 2px solid var(--azul-claro);
}
.header .logo { font-size: 1.3rem; font-weight: 800; color: var(--texto); letter-spacing: 1px; }
.header .logo span { color: var(--naranja); }
.header .subtitle { font-size: .75rem; color: var(--texto-dim); }
.header .back-btn {
  background: none;
  border: none;
  color: var(--texto);
  font-size: 1.4rem;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}
.header-title { flex: 1; }
.header-title h2 { font-size: 1rem; color: var(--texto); margin: 0; }
.header-title p  { font-size: .75rem; color: var(--texto-dim); margin: 0; }

/* ── Cards ──────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--borde);
  border-radius: var(--radio);
  padding: 18px;
  margin: 12px 16px;
}
.card-tight { padding: 12px 16px; }

/* ── Botones ─────────────────────────────────────────────────────────────── */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 15px 20px;
  border: none;
  border-radius: var(--radio);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity var(--trans), transform var(--trans);
  text-decoration: none;
  color: white;
}
.btn:active { transform: scale(.97); opacity: .85; }
.btn-primary  { background: var(--azul-claro); }
.btn-success  { background: var(--verde); }
.btn-warning  { background: var(--naranja); }
.btn-danger   { background: var(--rojo); }
.btn-ghost    { background: transparent; border: 1.5px solid var(--borde); color: var(--texto); }
.btn-sm       { padding: 10px 16px; font-size: .875rem; }
.btn-xs       { padding: 7px 12px; font-size: .8rem; }
.btn-icon     { width: auto; padding: 10px 14px; }

/* ── Formularios ────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  color: var(--texto-dim);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 6px;
}
.form-control {
  width: 100%;
  background: var(--bg-input);
  border: 1.5px solid var(--borde);
  border-radius: var(--radio-sm);
  padding: 12px 14px;
  font-size: 1rem;
  color: var(--texto);
  outline: none;
  transition: border-color var(--trans);
  -webkit-appearance: none;
}
.form-control:focus { border-color: var(--azul-claro); }
.form-control::placeholder { color: var(--gris); }
textarea.form-control { resize: vertical; min-height: 80px; }
select.form-control { cursor: pointer; }

/* Grid de dos columnas */
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .4px;
}
.badge-success { background: rgba(39,174,96,.15); color: var(--verde); }
.badge-warning { background: rgba(230,126,34,.15); color: var(--naranja); }
.badge-danger  { background: rgba(231,76,60,.15);  color: var(--rojo); }
.badge-info    { background: rgba(46,109,164,.2);  color: var(--azul-claro); }

/* ── Lista de items ──────────────────────────────────────────────────────── */
.list-item {
  display: flex;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--borde);
  gap: 12px;
  cursor: pointer;
  transition: background var(--trans);
}
.list-item:last-child { border-bottom: none; }
.list-item:active { background: rgba(255,255,255,.04); }
.list-item-icon {
  width: 42px;
  height: 42px;
  background: var(--azul-med);
  border-radius: var(--radio-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}
.list-item-body { flex: 1; min-width: 0; }
.list-item-body h3 { font-size: .95rem; color: var(--texto); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item-body p  { font-size: .8rem; color: var(--texto-dim); margin-top: 2px; }
.list-item-arrow { color: var(--texto-dim); font-size: 1rem; }

/* ── Métricas destacadas ─────────────────────────────────────────────────── */
.metrics-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.metric-card {
  background: var(--bg-input);
  border: 1px solid var(--borde);
  border-radius: var(--radio-sm);
  padding: 12px 10px;
  text-align: center;
}
.metric-card .val {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--azul-claro);
  line-height: 1.1;
}
.metric-card .lbl {
  font-size: .72rem;
  color: var(--texto-dim);
  text-transform: uppercase;
  letter-spacing: .4px;
  margin-top: 2px;
}

/* ── Fotos ────────────────────────────────────────────────────────────────── */
.foto-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.foto-slot {
  background: var(--bg-input);
  border: 2px dashed var(--borde);
  border-radius: var(--radio-sm);
  aspect-ratio: 4/3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  overflow: hidden;
  position: relative;
  transition: border-color var(--trans);
}
.foto-slot:active { border-color: var(--azul-claro); }
.foto-slot.has-foto { border-style: solid; border-color: var(--azul-claro); }
.foto-slot img { width: 100%; height: 100%; object-fit: cover; position: absolute; inset: 0; }
.foto-slot .foto-label {
  font-size: .75rem;
  color: var(--texto-dim);
  text-align: center;
  padding: 4px;
  z-index: 1;
  pointer-events: none;
}
.foto-slot .foto-icon { font-size: 1.6rem; margin-bottom: 4px; }
.foto-slot .foto-remove {
  position: absolute;
  top: 4px; right: 4px;
  background: rgba(231,76,60,.9);
  color: white;
  border: none;
  border-radius: 50%;
  width: 24px; height: 24px;
  font-size: .75rem;
  cursor: pointer;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
}
input[type="file"].hidden-file { display: none; }

/* ── Escáner ────────────────────────────────────────────────────────────── */
.scanner-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.9);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}
.scanner-overlay.hidden { display: none; }
#scanner-video {
  width: 100%;
  max-width: 400px;
  border-radius: var(--radio);
  border: 2px solid var(--azul-claro);
}
.scanner-frame {
  position: relative;
  width: 100%;
  max-width: 400px;
}
.scanner-line {
  position: absolute;
  left: 10%;
  right: 10%;
  height: 2px;
  background: var(--naranja);
  top: 50%;
  animation: scan 2s linear infinite;
  box-shadow: 0 0 6px var(--naranja);
}
@keyframes scan { 0%,100% { top: 20%; } 50% { top: 80%; } }
.scanner-hint { color: var(--texto-dim); font-size: .85rem; text-align: center; }

/* ── Checkboxes ─────────────────────────────────────────────────────────── */
.check-group { display: flex; flex-direction: column; gap: 10px; }
.check-item  { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.check-item input[type="checkbox"] {
  width: 20px; height: 20px;
  accent-color: var(--azul-claro);
  cursor: pointer;
  flex-shrink: 0;
}
.check-item span { font-size: .95rem; color: var(--texto); }

/* ── Sección producto dentro de tarima ──────────────────────────────────── */
.producto-card {
  background: var(--bg-input);
  border: 1px solid var(--borde);
  border-radius: var(--radio-sm);
  margin-bottom: 10px;
  overflow: hidden;
}
.producto-card-header {
  display: flex;
  align-items: center;
  padding: 12px 14px;
  gap: 10px;
  background: rgba(46,109,164,.12);
  border-bottom: 1px solid var(--borde);
}
.producto-card-header .prod-name { flex: 1; font-size: .9rem; font-weight: 600; color: var(--texto); }
.producto-card-header .prod-upc  { font-size: .75rem; color: var(--texto-dim); }
.producto-card-body { padding: 12px 14px; }

/* ── Lotes ──────────────────────────────────────────────────────────────── */
.lote-card {
  background: var(--azul);
  border: 1px solid var(--borde);
  border-radius: var(--radio-sm);
  padding: 12px;
  margin-bottom: 8px;
}
.lote-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.lote-header h4 { font-size: .85rem; color: var(--texto-dim); }
.vida-util-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: .75rem;
  font-weight: 700;
}
.vida-util-chip.ok      { background: rgba(39,174,96,.15); color: var(--verde); }
.vida-util-chip.warning { background: rgba(241,196,15,.15); color: var(--amarillo); }
.vida-util-chip.danger  { background: rgba(231,76,60,.15);  color: var(--rojo); }

/* ── Sección Incidencias ────────────────────────────────────────────────── */
.incidencia-section {
  border: 1px solid rgba(231,76,60,.3);
  border-radius: var(--radio-sm);
  padding: 12px;
  margin-top: 10px;
  background: rgba(231,76,60,.05);
}
.incidencia-section h4 { color: var(--rojo); font-size: .85rem; margin-bottom: 10px; }

/* ── Empty state ──────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--texto-dim);
}
.empty-state .icon { font-size: 3rem; margin-bottom: 12px; display: block; }
.empty-state h3 { color: var(--texto); margin-bottom: 6px; }

/* ── Toast ────────────────────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  width: calc(100% - 32px);
  max-width: 360px;
}
.toast {
  background: var(--bg-card);
  border: 1px solid var(--borde);
  border-radius: var(--radio-sm);
  padding: 12px 16px;
  font-size: .875rem;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: var(--sombra);
  animation: slideUp .3s ease;
}
.toast.success { border-left: 3px solid var(--verde); }
.toast.error   { border-left: 3px solid var(--rojo); }
.toast.info    { border-left: 3px solid var(--azul-claro); }
@keyframes slideUp { from { opacity:0; transform: translateY(20px); } to { opacity:1; transform: translateY(0); } }

/* ── Spinner ──────────────────────────────────────────────────────────────── */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid rgba(255,255,255,.2);
  border-top-color: white;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Loading overlay ─────────────────────────────────────────────────────── */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
}
.loading-overlay.hidden { display: none; }
.loading-box {
  background: var(--bg-card);
  border-radius: var(--radio);
  padding: 30px 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}
.loading-box p { color: var(--texto-dim); font-size: .875rem; }

/* ── Modal ────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  z-index: 800;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--bg-card);
  border-radius: var(--radio) var(--radio) 0 0;
  border: 1px solid var(--borde);
  border-bottom: none;
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px 16px 40px;
  animation: slideIn .25s ease;
}
@keyframes slideIn { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.modal-header h2 { font-size: 1.1rem; }
.modal-close {
  background: none;
  border: none;
  color: var(--texto-dim);
  font-size: 1.4rem;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}

/* ── Folio chip ─────────────────────────────────────────────────────────── */
.folio-chip {
  background: rgba(46,109,164,.15);
  border: 1px solid var(--azul-claro);
  color: var(--azul-claro);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: .8rem;
  font-weight: 700;
  letter-spacing: .5px;
}

/* ── Search bar ─────────────────────────────────────────────────────────── */
.search-bar {
  position: relative;
  margin: 12px 16px;
}
.search-bar input {
  width: 100%;
  background: var(--bg-card);
  border: 1.5px solid var(--borde);
  border-radius: 24px;
  padding: 12px 16px 12px 44px;
  font-size: .95rem;
  color: var(--texto);
  outline: none;
}
.search-bar input:focus { border-color: var(--azul-claro); }
.search-bar .search-icon {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--texto-dim);
  pointer-events: none;
}

/* ── Divider ─────────────────────────────────────────────────────────────── */
.divider {
  height: 1px;
  background: var(--borde);
  margin: 16px 0;
}

/* ── Utilidades ─────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.text-center { text-align: center; }
.text-right  { text-align: right; }
.text-verde  { color: var(--verde); }
.text-rojo   { color: var(--rojo); }
.text-naranja { color: var(--naranja); }
.text-dim    { color: var(--texto-dim); }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.gap-1 { gap: 8px; }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-col { display: flex; flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.rounded { border-radius: var(--radio-sm); }
.p-page { padding: 16px; }

/* ── Página dashboard ────────────────────────────────────────────────────── */
.dashboard-hero {
  background: linear-gradient(135deg, var(--azul-med) 0%, var(--azul) 100%);
  padding: 28px 20px 24px;
  border-bottom: 2px solid var(--borde);
}
.dashboard-hero .logo-big { font-size: 2rem; font-weight: 900; letter-spacing: 2px; color: var(--texto); }
.dashboard-hero .logo-big span { color: var(--naranja); }
.dashboard-hero p { color: var(--texto-dim); font-size: .875rem; margin-top: 4px; }
.btn-hero {
  background: var(--azul-claro);
  padding: 20px;
  border-radius: var(--radio);
  font-size: 1.1rem;
  font-weight: 700;
  gap: 12px;
}
.btn-hero .btn-icon-big { font-size: 1.6rem; }

/* ── Estado indicator dot ────────────────────────────────────────────────── */
.estado-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.estado-dot.bueno   { background: var(--verde); }
.estado-dot.regular { background: var(--naranja); }
.estado-dot.malo    { background: var(--rojo); }

/* ── Scrollbar ──────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--borde); border-radius: 2px; }

/* ═══════════════════════════════════════════════════════════════════════════
   RESPONSIVE — Desktop ≥ 768px
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Sidebar oculto en móvil ─────────────────────────────────────────────── */
.sidebar { display: none; }

/* ── Clases de layout dashboard (móvil por defecto) ─────────────────────── */
.dashboard-actions { padding: 20px 16px 0; display: flex; flex-direction: column; gap: 12px; }
.dashboard-actions-sec { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.dashboard-hero-left { display: flex; flex-direction: column; gap: 2px; }

@media (min-width: 768px) {

  /* ── Layout: sidebar fija + contenido ─────────────────────────────────── */
  .app-shell {
    max-width: 1200px;
    margin: 0 auto;
    min-height: 100vh;
    display: flex;
    flex-direction: row;
    align-items: stretch;
    padding: 0;
  }

  /* ── Sidebar ─────────────────────────────────────────────────────────── */
  .sidebar {
    display: flex;
    flex-direction: column;
    width: 230px;
    min-width: 230px;
    background: var(--bg-card);
    border-right: 1px solid var(--borde);
    height: 100vh;
    position: sticky;
    top: 0;
    overflow-y: auto;
    flex-shrink: 0;
    z-index: 200;
  }
  .sidebar-logo {
    font-size: 1.1rem;
    font-weight: 900;
    letter-spacing: 2px;
    color: var(--texto);
    padding: 24px 20px 20px;
    border-bottom: 1px solid var(--borde);
  }
  .sidebar-logo span { color: var(--naranja); }
  .sidebar-nav {
    display: flex;
    flex-direction: column;
    padding: 12px 0;
    flex: 1;
  }
  .sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 20px;
    color: var(--texto-dim);
    text-decoration: none;
    font-size: .9rem;
    font-weight: 500;
    border: none;
    background: none;
    cursor: pointer;
    width: 100%;
    text-align: left;
    transition: background var(--trans), color var(--trans);
    line-height: 1.4;
  }
  .sidebar-link:hover { background: rgba(46,109,164,.12); color: var(--texto); }
  .sidebar-link.active {
    background: rgba(46,109,164,.2);
    color: var(--azul-claro);
    border-right: 3px solid var(--azul-claro);
    font-weight: 600;
  }
  .sidebar-bottom {
    padding: 12px 0;
    border-top: 1px solid var(--borde);
  }
  .sidebar-link.danger { color: var(--rojo); }
  .sidebar-link.danger:hover { background: rgba(231,76,60,.1); color: var(--rojo); }

  /* ── Contenido principal ─────────────────────────────────────────────── */
  .main-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    height: 100vh;
  }

  /* ── Header en desktop ───────────────────────────────────────────────── */
  .header { padding: 16px 28px; }
  .back-btn { display: none; }
  .header-title h2 { font-size: 1.2rem; }

  /* ── Dashboard hero: header PC con logo izq y salir der ──────────────── */
  .dashboard-hero {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 20px 28px !important;
    background: var(--bg-card);
    border-bottom: 1px solid var(--borde);
    position: static !important;
  }
  .dashboard-hero .logo-big { font-size: 1.5rem; }
  .dashboard-hero > .btn-ghost {
    position: static !important;
    top: auto !important;
    right: auto !important;
    width: auto;
  }

  /* ── Cards: más margen en desktop ────────────────────────────────────── */
  .card { margin: 16px 28px; }

  /* ── Search bar ──────────────────────────────────────────────────────── */
  .search-bar { margin: 16px 28px; }

  /* ── Lista items: más padding ────────────────────────────────────────── */
  .list-item { padding: 16px 28px; }

  /* ── Métricas: 3 cols más grandes ────────────────────────────────────── */
  .metrics-grid { gap: 20px; }
  .metric-card { padding: 20px 16px; }
  .metric-card .val { font-size: 2.2rem; }

  /* ── Dashboard acciones: 3 columnas ─────────────────────────────────── */
  .dashboard-actions {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 20px;
    padding: 24px 28px !important;
  }
  .dashboard-actions-sec { display: contents; }
  .btn-hero { font-size: 1rem; padding: 20px 16px; }

  /* ── Acciones tarimas: fila en lugar de columna ──────────────────────── */
  .tarimas-acciones {
    flex-direction: row !important;
    padding: 0 28px !important;
  }
  .tarimas-acciones > .btn { flex: 0 0 auto; }
  .tarimas-acciones-sec { display: flex !important; }

  /* ── Sección títulos ─────────────────────────────────────────────────── */
  .section-title-wrap { padding: 20px 28px 8px !important; }

  /* ── Lista tarimas / recientes ───────────────────────────────────────── */
  #lista-tarimas { padding: 0 28px !important; }
  #lista-recientes { margin: 0 28px !important; }
  #lista-productos { padding: 0; }

  /* ── Modal: centrado (no bottom sheet) ───────────────────────────────── */
  .modal-overlay { align-items: center; }
  .modal {
    border-radius: var(--radio);
    max-width: 580px;
    width: 90%;
    max-height: 88vh;
    padding: 32px;
  }

  /* ── Botones de acción no full-width en header ───────────────────────── */
  .header .btn { width: auto; }

  /* ── Spacer inferior ─────────────────────────────────────────────────── */
  .app-shell > .main-content > div[style*="height:24px"] { height: 32px; }

}
