:root {
  --primary:     #00A6B4;
  --primary-dk:  #007F8A;
  --danger:      #c62828;
  --warning:     #f9a825;
  --bg:          #f2f6f6;
  --card:        #ffffff;
  --text:        #202626;
  --text-muted:  #6f7d7d;
  --border:      #dde8e8;
  --radius:      10px;
  --shadow:      0 2px 10px rgba(0,0,0,.08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.hidden { display: none !important; }

/* ── Layout ── */
.topbar {
  background: var(--primary);
  color: #fff;
  padding: .8rem 1.2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .6rem;
}
.topbar h1 { font-size: 1.1rem; margin: 0; }
.topbar nav { display: flex; gap: .4rem; flex-wrap: wrap; }
.topbar nav a {
  color: #fff; text-decoration: none; font-size: .85rem;
  padding: .4rem .7rem; border-radius: 8px; background: rgba(255,255,255,.12);
}
.topbar nav a.activo { background: rgba(255,255,255,.28); font-weight: 600; }
#nav-entregas { background: #e67e22 !important; color: #fff !important; font-weight: 700; }
#nav-entregas.activo { background: #d35400 !important; }
.topbar .usuario-info { font-size: .8rem; opacity: .9; display:flex; align-items:center; gap:.6rem; }
.topbar button.link {
  background: none; border: none; color: #fff; text-decoration: underline;
  cursor: pointer; font-size: .8rem; padding: 0;
}

.container { max-width: 900px; margin: 0 auto; padding: 1.2rem; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.2rem;
  margin-bottom: 1.2rem;
}
.card h2 { margin-top: 0; font-size: 1.05rem; }

/* ── Forms ── */
label { display: block; font-size: .82rem; color: var(--text-muted); margin-bottom: .25rem; }
input, select, textarea {
  width: 100%;
  padding: .55rem .7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: .95rem;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.campo { margin-bottom: .8rem; }
.fila { display: flex; gap: .8rem; flex-wrap: wrap; }
.fila > .campo { flex: 1; min-width: 140px; }
.check { display: flex; align-items: center; gap: .5rem; }
.check input { width: auto; }

button, .btn {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: .6rem 1.1rem;
  font-size: .9rem;
  font-weight: 600;
  background: var(--primary);
  color: #fff;
  display: inline-flex;
  align-items: center;
  gap: .4rem;
}
button:hover, .btn:hover { background: var(--primary-dk); }
button:disabled { opacity: .55; cursor: not-allowed; }
.btn-outline { background: transparent; color: var(--primary); border: 1px solid var(--primary); }
.btn-outline:hover { background: rgba(106,27,154,.08); }
.btn-danger { background: var(--danger); }
.btn-sm { padding: .35rem .7rem; font-size: .8rem; }
.btn-full { width: 100%; justify-content: center; }

/* ── Tabla ── */
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: .5rem .4rem; border-bottom: 1px solid var(--border); }
th { color: var(--text-muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; }
tfoot td { font-weight: 700; }
td.num, th.num { text-align: right; }
td input { padding: .35rem .5rem; font-size: .85rem; }

/* Resalta en rojo el código/nombre recién escaneado — confirmación visual de
   que sí se detectó el producto, útil cuando el celular no vibra. */
.resaltado-nuevo { color: #c62828 !important; font-weight: 700; transition: color 1.8s ease; }
input.resaltado-nuevo { border-color: #c62828; }

.badge { display: inline-block; padding: .2rem .55rem; border-radius: 20px; font-size: .75rem; font-weight: 700; }
.badge-pagado { background: #e0f2e9; color: #1b7a43; }
.badge-pendiente { background: #fde8e8; color: var(--danger); }

.alerta {
  background: #fff3e0; border: 1px solid var(--warning);
  border-radius: var(--radius); padding: .8rem 1rem; margin-bottom: 1rem;
  font-size: .88rem; color: #8a5a00;
}

/* ── Toast ── */
.toast-container { position: fixed; bottom: 1.2rem; right: 1.2rem; display: flex; flex-direction: column; gap: .5rem; z-index: 9999; }
.toast { padding: .7rem 1rem; border-radius: var(--radius); color: #fff; font-size: .88rem; max-width: 320px; box-shadow: var(--shadow); animation: slideIn .2s ease; }
.toast-success { background: #2e7d32; }
.toast-error   { background: var(--danger); }
.toast-info    { background: #1565c0; }
@keyframes slideIn { from { transform: translateX(110%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ── Escáner ── */
#scanner-modal { position: fixed; inset: 0; z-index: 10000; display: flex; align-items: center; justify-content: center; }
#scanner-modal[hidden] { display: none !important; }
.scanner-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.75); }
.scanner-box { position: relative; z-index: 1; background: #000; border-radius: var(--radius); overflow: hidden; width: 340px; max-width: 96vw; }
.scanner-header { display: flex; justify-content: space-between; align-items: center; padding: .6rem 1rem; background: var(--primary); color: #fff; font-size: .95rem; font-weight: 600; }
.scanner-header button { background: none; border: none; color: #fff; font-size: 1.2rem; cursor: pointer; padding: 0 .2rem; }
#scanner-lector video { width: 100%; display: block; }

/* ── Impresión de ticket 80mm ── */
.ticket-print {
  width: 80mm;
  margin: 0 auto;
  background: #fff;
  padding: 4mm;
  font-family: 'Courier New', monospace;
  font-size: 11px;
  color: #000;
}
.ticket-print h2 { text-align: center; font-size: 13px; margin: 0 0 4px; }
.ticket-print .linea { border-top: 1px dashed #000; margin: 6px 0; }
.ticket-print table { width: 100%; font-size: 10.5px; }
.ticket-print td, .ticket-print th { border: none; padding: 1px 0; }
.ticket-print .total { font-size: 12px; font-weight: 700; text-align: right; }
.ticket-print .estado { text-align: center; font-weight: 700; margin-top: 6px; padding: 3px; border: 1px solid #000; }

/* ── Impresión de reporte (hoja normal, no 80mm) ── */
.reporte-print {
  background: #fff;
  color: #000;
  padding: 1cm;
  font-family: system-ui, sans-serif;
}
.reporte-print h2 { margin: 0 0 2px; }
.reporte-print .subtitulo { color: #555; font-size: .9rem; margin-bottom: 1rem; }
.reporte-print table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.reporte-print th, .reporte-print td { border: 1px solid #999; padding: .4rem .6rem; text-align: left; }
.reporte-print th.num, .reporte-print td.num { text-align: right; }

/* La gráfica va en su propia hoja, aparte de la tabla — así quien imprime
   decide si de plano quiere esa hoja o no. El tamaño del círculo NO se define
   aquí: se genera ya grande desde graficaPastel.js (ver comentario allá). */
.reporte-print .hoja-grafica {
  text-align: center;
  padding-top: 1.5cm;
}
.reporte-print .hoja-grafica h3 { margin-bottom: 1.5rem; font-size: 1.4rem; }

@media print {
  body * { visibility: hidden; }
  /* Los contenedores traen display:none inline para no estorbar en pantalla —
     hay que revertirlo aquí, si no, "visibility:visible" no sirve de nada
     porque un padre en display:none nunca se renderiza. */
  #ticket-imprimir-wrap  { display: block !important; }
  #reporte-imprimir-wrap { display: block !important; }
  .ticket-print, .ticket-print *   { visibility: visible; }
  .reporte-print, .reporte-print * { visibility: visible; }
  .ticket-print  { position: absolute; left: 0; top: 0; }
  .reporte-print { position: absolute; left: 0; top: 0; width: 100%; }
  .reporte-print .hoja-grafica { page-break-before: always; break-before: page; }
  /* El tamaño de hoja (@page) NO se define aquí: lo inyecta imprimirComo() en
     nav.js justo antes de imprimir, según sea ticket (8cm) o reporte (carta).
     Tener las dos reglas fijas aquí hacía que el reporte saliera dentro de una
     hoja de 8cm y la gráfica se viera diminuta. */
}

@media (max-width: 600px) {
  .container { padding: .7rem; }
  .fila { flex-direction: column; }
}
