:root {
  /* ---- Colores de la tabla de pedidos (heredados de la planilla original: NO SE TOCAN) ---- */
  --gris-header: #d9d9d9;
  --gris-borde: #c7c7c7;
  --verde-separador: #a9d18e;
  --rojo-cliente: #e8342a;
  --negro-recoge: #1a1a1a;
  --azul-producto: #1f4e79;

  /* ---- Colores de marca (Artesanales AA) — usados en el resto de la app ---- */
  --marca-verde-oscuro: #5b7364;
  --marca-verde-oscuro-hover: #48594d;
  --marca-verde-claro: #a4b1a0;
  --marca-dorado: #bd923d;
  --marca-crema: #fff6e6;

  --fondo: var(--marca-crema);
  --texto: #1a1a1a;
  --azul-accion: var(--marca-verde-oscuro);
  --azul-accion-hover: var(--marca-verde-oscuro-hover);
  --peligro: #c0392b;
  --sombra: 0 6px 24px rgba(0,0,0,0.14);
  --escala-tabla: 1; /* controla el tamaño de letra de la tabla de Pedidos */
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden; /* evita que cualquier elemento haga desbordar la página entera en pantallas angostas */
}

body {
  margin: 0;
  background: var(--fondo);
  color: var(--texto);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 12px 20px;
  background: #fff;
  border-bottom: 2px solid var(--marca-verde-claro);
  position: sticky;
  top: 0;
  z-index: 5;
}

.topbar-marca { display: flex; align-items: center; gap: 10px; }
.logo-topbar { height: 40px; width: auto; display: block; }
.topbar h1 {
  font-size: 1.1rem;
  margin: 0;
  letter-spacing: 0.2px;
  color: var(--marca-verde-oscuro);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.nav-tabs {
  display: flex;
  gap: 4px;
  background: #f1efe7;
  border-radius: 8px;
  padding: 3px;
}
.nav-tab {
  border: none;
  background: transparent;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  color: #6b6b6b;
  cursor: pointer;
}
.nav-tab.activo {
  background: #fff;
  color: var(--marca-verde-oscuro);
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}

.estado-conexion {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: #555;
}
.punto-conexion {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #2e9e5b;
  display: inline-block;
}
.estado-conexion.desconectado .punto-conexion { background: #c0392b; }

.usuario-activo {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  background: rgba(164, 177, 160, 0.28);
  padding: 6px 10px;
  border-radius: 7px;
}
.btn-link {
  background: none;
  border: none;
  color: var(--marca-verde-oscuro);
  text-decoration: underline;
  cursor: pointer;
  font-size: 0.8rem;
  padding: 0;
}

/* Blindaje: cualquier elemento con [hidden] SIEMPRE debe ocultarse,
   sin importar qué otra regla de "display" tenga su clase. */
[hidden] { display: none !important; }

.vista[hidden] { display: none; }

.barra-herramientas {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 16px 0 0;
}
.titulo-vista { margin: 0; font-size: 1.05rem; flex: 1; }

.filtro-fecha {
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 6px;
}
.filtro-fecha input {
  padding: 8px;
  border: 1px solid var(--gris-borde);
  border-radius: 6px;
  font-size: 0.85rem;
  max-width: 150px;
}

.btn {
  border: none;
  border-radius: 7px;
  padding: 10px 14px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease;
  min-height: 40px;
}
.btn:active { transform: translateY(1px); }
.btn-primario { background: var(--azul-accion); color: #fff; }
.btn-primario:hover { background: var(--azul-accion-hover); }
.btn-secundario { background: #eee7d8; color: var(--texto); }
.btn-secundario:hover { background: #e3dac5; }
.btn-peligro { background: #fdecea; color: var(--peligro); }
.btn-peligro:hover { background: #f9d6d2; }
.btn-chico { padding: 6px 10px; font-size: 0.8rem; min-height: 34px; }
.btn-nuevo { margin-left: auto; }

main { padding: 0 20px 40px; }
#areaImprimir { margin-top: 14px; }

/* ========================================================================
   TABLA DE PEDIDOS
   Arquitectura: dos <table> independientes (encabezado y cuerpo) dentro
   de un mismo contenedor. El encabezado NUNCA se desplaza verticalmente
   (no usa position:sticky, que en algunos navegadores desalinea las
   columnas al combinarse con anchos fijos). El scroll horizontal mueve
   ambas tablas a la vez porque comparten el mismo contenedor ancho;
   el scroll vertical solo aplica al cuerpo. Los anchos de columna viven
   en JS (anchoColumnas) y se aplican a AMBOS <colgroup> a la vez, así que
   encabezado y filas quedan siempre perfectamente alineados.
   ======================================================================== */

.tabla-wrapper {
  background: #fff;
  border-radius: 10px;
  overflow-x: auto;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.tabla-interior {
  display: inline-block;
  min-width: 100%;
}

.tabla-body-scroll {
  max-height: calc(100vh - 300px);
  overflow-y: auto;
  overflow-x: hidden;
}

.tabla-pedidos {
  border-collapse: collapse;
  table-layout: fixed;
}
.tabla-pedidos-header { margin-bottom: 0; }

.tabla-pedidos thead th {
  background: var(--gris-header);
  text-align: center;
  font-weight: 700;
  font-size: calc(0.78rem * var(--escala-tabla));
  letter-spacing: 0.4px;
  padding: 10px 12px;
  border: 1px solid #bfbfbf;
  position: relative;
  overflow: hidden;
  white-space: nowrap;
}

.tabla-pedidos td {
  padding: 9px 12px;
  border: 1px solid #e4e4e4;
  font-size: calc(0.88rem * var(--escala-tabla));
  font-weight: 700;
  text-align: center;
  vertical-align: top;
  white-space: nowrap;
  overflow: hidden;
}

.tabla-pedidos td.col-nota,
.tabla-pedidos td.col-nombre,
.tabla-pedidos td.col-producto,
.tabla-pedidos td.col-tamano {
  white-space: normal;
  word-break: break-word;
}

.col-drag { cursor: grab; color: #999; }
.col-fecha { white-space: nowrap; color: #555; font-size: calc(0.8rem * var(--escala-tabla)); }

.nombre-cliente { color: var(--rojo-cliente); font-weight: 700; }
.sufijo-barrio { color: var(--rojo-cliente); font-weight: 700; }
.sufijo-recoge { color: var(--negro-recoge); font-weight: 700; }

.producto-texto { color: var(--azul-producto); font-weight: 600; }
.tamano-texto { color: var(--azul-producto); font-weight: 600; }

.grupo-pedido:not(:last-child) tr:last-child td {
  border-bottom: 9px solid var(--verde-separador);
}

.ayuda-tabla { font-size: 0.78rem; color: #888; margin-top: 10px; }

/* ---------- Manijas para redimensionar columnas ---------- */
.resizer {
  position: absolute;
  top: 0;
  right: 0;
  width: 8px;
  height: 100%;
  cursor: col-resize;
  touch-action: none;
}
.resizer:hover, .resizer.redimensionando {
  background: var(--marca-dorado);
  opacity: 0.6;
}

.btn-editar-fila {
  background: none;
  border: none;
  color: #888;
  cursor: pointer;
  font-size: 0.85rem;
  text-decoration: underline;
  padding: 6px 2px;
  min-height: 32px;
}
.btn-editar-fila:hover { color: var(--azul-accion); }

.vacio-mensaje {
  text-align: center;
  color: #888;
  padding: 40px 0;
}

/* ---------- Arrastrar y soltar pedidos ---------- */
.drag-handle {
  cursor: grab;
  font-size: 0.9rem;
  letter-spacing: -2px;
  user-select: none;
}
.grupo-pedido { transition: opacity 0.15s ease; }
.grupo-pedido.arrastrando { opacity: 0.35; }
.grupo-pedido.sobre-arrastre-arriba > tr:first-child td {
  box-shadow: inset 0 3px 0 0 var(--azul-accion);
}
.grupo-pedido.sobre-arrastre-abajo > tr:last-child td {
  box-shadow: inset 0 -3px 0 0 var(--azul-accion);
}

/* ---------- Pantalla de acceso (login) ---------- */
.pantalla-login {
  display: flex;
  justify-content: center;
  padding: 60px 16px;
  min-height: 100vh;
  background: var(--marca-crema);
}
.tarjeta-login {
  background: #fff;
  border-radius: 12px;
  box-shadow: var(--sombra);
  padding: 28px 26px;
  width: 100%;
  max-width: 360px;
  text-align: center;
  align-self: flex-start;
}
.logo-login { width: 130px; height: auto; margin-bottom: 12px; }
.tarjeta-login h2 { margin: 0 0 6px; font-size: 1.2rem; color: var(--marca-verde-oscuro); }
.tarjeta-login p { color: #666; font-size: 0.85rem; margin: 0 0 16px; }
.tarjeta-login form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.tarjeta-login input { text-align: left; }

/* ---------- Tabla de roles ---------- */
.tabla-roles {
  border-collapse: collapse;
  width: 100%;
}
.tabla-roles th {
  background: #eef1ea;
  text-align: left;
  font-size: 0.78rem;
  letter-spacing: 0.4px;
  padding: 10px 12px;
  border: 1px solid #d7ded2;
  position: sticky;
  top: 0;
  z-index: 2;
}
.tabla-roles td {
  padding: 10px 12px;
  border: 1px solid #e4e4e4;
  font-size: 0.9rem;
}
.tabla-wrapper-roles { max-height: calc(100vh - 200px); overflow-y: auto; }
.modal-chico { max-width: 420px; }

/* ---------- Tabla de entregas ---------- */
.tabla-entregas {
  border-collapse: collapse;
  width: 100%;
}
.tabla-entregas th {
  background: var(--gris-header);
  text-align: left;
  font-size: 0.78rem;
  letter-spacing: 0.4px;
  padding: 10px 12px;
  border: 1px solid #bfbfbf;
  position: sticky;
  top: 0;
  z-index: 2;
}
.tabla-entregas td {
  padding: 9px 12px;
  border: 1px solid #e4e4e4;
  font-size: 0.87rem;
  vertical-align: middle;
}
.tabla-entregas .col-codigo { text-align: center; width: 60px; font-weight: 700; }
.tabla-entregas .col-barrio { width: 160px; font-weight: 600; color: #555; }
.tabla-entregas .col-estado { width: 120px; }
.tabla-entregas .col-recogido { width: 190px; font-size: 0.78rem; color: #555; }
.tabla-entregas .col-entregado { width: 230px; font-size: 0.78rem; color: #555; }
.tabla-entregas .col-acciones-entrega { width: 160px; text-align: right; }
.tabla-entregas tr.inicio-grupo-barrio td {
  border-top: 4px solid var(--marca-verde-claro);
}

.badge-estado {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.3px;
}
.badge-pendiente { background: #f1efe7; color: #6b6b6b; }
.badge-en_camino { background: #fdf1d9; color: var(--marca-dorado); }
.badge-entregado { background: #e5efe2; color: var(--marca-verde-oscuro); }

.enlace-mapa { color: var(--azul-producto); font-size: 0.76rem; text-decoration: underline; }
.miniatura-firma {
  width: 46px;
  height: 26px;
  object-fit: contain;
  border: 1px solid var(--gris-borde);
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
  vertical-align: middle;
  margin-left: 6px;
}
.celda-firmas-reposicion { display: flex; gap: 4px; align-items: center; }
.celda-firmas-reposicion .miniatura-firma { margin-left: 0; }

.btn-recoger, .btn-entregar {
  border: none;
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 0.76rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.btn-recoger { background: var(--marca-dorado); color: #fff; }
.btn-recoger:hover { background: #a37c31; }
.btn-entregar { background: var(--marca-verde-oscuro); color: #fff; }
.btn-entregar:hover { background: var(--marca-verde-oscuro-hover); }
.btn-recoger:disabled, .btn-entregar:disabled { opacity: 0.6; cursor: wait; }
.btn-reabrir {
  background: none;
  border: none;
  color: var(--peligro);
  font-size: 0.72rem;
  text-decoration: underline;
  cursor: pointer;
  margin-top: 4px;
  display: block;
}

/* ---------- Chips de filtro por estado (Entregas) ---------- */
.filtro-estado { display: flex; gap: 6px; flex-wrap: wrap; }
.chip-estado {
  border: 1px solid var(--gris-borde);
  background: #fff;
  color: #555;
  border-radius: 20px;
  padding: 7px 13px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}
.chip-estado.activo {
  background: var(--marca-verde-oscuro);
  border-color: var(--marca-verde-oscuro);
  color: #fff;
}

/* ---------- Modal de firma ---------- */
.modal-firma { max-width: 460px; }
.texto-firma-info { font-size: 0.85rem; color: #555; margin: 0 0 12px; }
.lienzo-firma-wrapper {
  position: relative;
  border: 2px dashed var(--gris-borde);
  border-radius: 10px;
  overflow: hidden;
  background: #fafafa;
}
.lienzo-firma { width: 100%; height: 200px; display: block; touch-action: none; cursor: crosshair; }
.placeholder-firma {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  color: #bbb;
  font-size: 0.9rem;
  pointer-events: none;
}
.estado-ubicacion { font-size: 0.78rem; color: #777; margin: 10px 0 0; }
.imagen-firma-grande { width: 100%; border-radius: 8px; background: #fafafa; border: 1px solid var(--gris-borde); }

/* ---------- KPIs (Pedidos) ---------- */
.barra-kpis {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  padding: 16px 0 0;
}
.kpi {
  background: #fff;
  border-radius: 10px;
  padding: 10px 18px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  display: flex;
  flex-direction: column;
  min-width: 90px;
}
.kpi-numero { font-size: 1.35rem; font-weight: 800; color: var(--marca-verde-oscuro); }
.kpi.kpi-ok .kpi-numero { color: var(--marca-dorado); }
.kpi-etiqueta { font-size: 0.72rem; color: #888; }

.input-buscar {
  max-width: 220px;
  padding: 9px 10px;
}

/* ---------- Tabla de actividad ---------- */
.tabla-actividad { border-collapse: collapse; width: 100%; }
.tabla-actividad th {
  background: #eef1ea;
  text-align: left;
  font-size: 0.78rem;
  padding: 10px 12px;
  border: 1px solid #d7ded2;
  position: sticky;
  top: 0;
}
.tabla-actividad td { padding: 9px 12px; border: 1px solid #e4e4e4; font-size: 0.85rem; }
.tabla-actividad .col-fecha-act { white-space: nowrap; color: #777; font-size: 0.78rem; width: 160px; }

/* ---------- Notificaciones flotantes (toasts) ---------- */
.contenedor-toasts {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 50;
}
.toast {
  background: #2a2a2a;
  color: #fff;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 0.85rem;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  max-width: 320px;
  animation: toast-entrada 0.2s ease;
}
.toast-exito { background: var(--marca-verde-oscuro); }
@keyframes toast-entrada {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Catálogo (productos y tamaños) ---------- */
.tabla-catalogo { border-collapse: collapse; width: 100%; }
.tabla-catalogo th {
  background: #eef1ea;
  text-align: left;
  font-size: 0.78rem;
  padding: 10px 12px;
  border: 1px solid #d7ded2;
  position: sticky;
  top: 0;
}
.tabla-catalogo td {
  padding: 9px 12px;
  border: 1px solid #e4e4e4;
  font-size: 0.88rem;
}
.muestra-color {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 4px;
  border: 1px solid rgba(0,0,0,0.15);
  vertical-align: middle;
  margin-right: 4px;
}

.fila-color { display: flex; align-items: center; gap: 8px; }
.fila-color input[type="color"] {
  width: 42px;
  height: 38px;
  padding: 2px;
  cursor: pointer;
}

.texto-ayuda-segmentos { font-size: 0.76rem; color: #888; margin: 4px 0 10px; }

.fila-segmento {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}
.fila-segmento .segmento-color { width: 42px; height: 38px; padding: 2px; cursor: pointer; }

.vista-previa-segmentos-wrapper {
  margin-top: 14px;
  padding: 12px;
  background: #fafafa;
  border-radius: 8px;
  border: 1px solid var(--gris-borde);
}
.vista-previa-etiqueta { font-size: 0.76rem; color: #888; display: block; margin-bottom: 4px; }
.vista-previa-segmentos { font-size: 1rem; font-weight: 700; }

.campo-checkbox { margin-top: 4px; }
.label-checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--texto);
  font-weight: 500;
  cursor: pointer;
}
.label-checkbox input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--azul-accion);
}

/* ---------- Modal ---------- */
.modal-fondo {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
  z-index: 20;
}

.modal-fondo[hidden] {
  display: none;
}

.modal {
  background: #fff;
  border-radius: 12px;
  width: 100%;
  max-width: 720px;
  box-shadow: var(--sombra);
  padding: 22px 24px 24px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}
.modal-header h2 { margin: 0; font-size: 1.1rem; }

.btn-cerrar {
  background: none;
  border: none;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  color: #888;
  min-width: 40px;
  min-height: 40px;
}
.btn-cerrar:hover { color: #222; }

.fila-form {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.campo {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-width: 140px;
}
.campo-crece { flex: 2; }

.campo label {
  font-size: 0.78rem;
  color: #555;
  font-weight: 600;
}

input, textarea {
  padding: 10px;
  border: 1px solid var(--gris-borde);
  border-radius: 7px;
  font-size: 16px;
  font-family: inherit;
  width: 100%;
}
input:focus, textarea:focus {
  outline: 2px solid var(--azul-accion);
  outline-offset: 1px;
}

/* Todo lo que se escribe en el formulario de pedidos se ve en mayúscula
   mientras se escribe (el servidor también lo guarda así). El correo y
   la contraseña quedan exceptuados para no romper su formato real. */
#formPedido input[type="text"],
#formPedido textarea,
#buscarPedido {
  text-transform: uppercase;
}

.subtitulo { font-size: 0.9rem; margin: 16px 0 8px; }

.fila-item {
  display: grid;
  grid-template-columns: 2fr 0.7fr 1.3fr 1.3fr auto;
  gap: 8px;
  margin-bottom: 8px;
  align-items: center;
}

.btn-quitar-item {
  background: #fdecea;
  color: var(--peligro);
  border: none;
  border-radius: 6px;
  width: 36px;
  height: 38px;
  cursor: pointer;
  font-size: 1.1rem;
}
.btn-quitar-item:hover { background: #f9d6d2; }

.error-form {
  background: #fdecea;
  color: var(--peligro);
  padding: 8px 10px;
  border-radius: 7px;
  font-size: 0.85rem;
  margin-top: 10px;
}

.modal-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid #eee;
}
.modal-footer-derecha { display: flex; gap: 8px; }

/* ---------- Filtro de categorías (Pedidos) ---------- */
.filtro-categorias-wrapper { position: relative; }
.contador-chip {
  background: var(--marca-dorado);
  color: #fff;
  border-radius: 999px;
  font-size: 0.68rem;
  padding: 1px 6px;
  margin-left: 4px;
  font-weight: 700;
}
.menu-filtro-categorias {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  background: #fff;
  border-radius: 10px;
  box-shadow: var(--sombra);
  padding: 10px;
  min-width: 220px;
  max-height: 280px;
  overflow-y: auto;
  z-index: 15;
}
.menu-filtro-categorias[hidden] { display: none; }
.opcion-categoria-filtro {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
  font-size: 0.85rem;
  cursor: pointer;
  border-radius: 6px;
}
.opcion-categoria-filtro:hover { background: #f5f5f0; }
.opcion-categoria-filtro input { width: 16px; height: 16px; accent-color: var(--azul-accion); flex: none; }
.opcion-categoria-filtro .muestra-color { flex: none; }
.mensaje-sin-categorias { font-size: 0.8rem; color: #888; padding: 6px 4px; }

/* ---------- Control de tamaño de letra ---------- */
.control-tamano-letra {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  background: #fff;
  border-radius: 8px;
  padding: 4px 8px;
  border: 1px solid var(--gris-borde);
}
.btn-ajuste-letra {
  border: none;
  background: #eee7d8;
  border-radius: 5px;
  width: 26px;
  height: 26px;
  font-size: 0.72rem;
  font-weight: 700;
  cursor: pointer;
}
.btn-ajuste-letra:hover { background: var(--marca-verde-claro); color: #fff; }
#valorTamanoLetra { font-size: 0.75rem; color: #666; min-width: 34px; text-align: center; }

/* ---------- Rango de impresión ---------- */
.barra-impresion { padding-top: 8px; }
.etiqueta-rango { font-size: 0.85rem; font-weight: 600; color: #555; }
.input-rango { max-width: 160px; }
.ayuda-rango { font-size: 0.74rem; color: #999; }

/* ---------- Paleta de colores de acceso rápido ---------- */
.paleta-colores {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 6px;
}
.chip-color-rapido {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: 2px solid #fff;
  outline: 1px solid var(--gris-borde);
  cursor: pointer;
  padding: 0;
}
.chip-color-rapido:hover { outline: 2px solid var(--marca-verde-oscuro); }

/* ---------- Vista Métricas ---------- */
.grid-metricas {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
  margin-top: 16px;
  width: 100%;
}
.tarjeta-metrica {
  background: #fff;
  border-radius: 12px;
  padding: 16px 18px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.tarjeta-metrica h3 { margin: 0 0 4px; font-size: 0.95rem; }
.subtexto-metrica { font-size: 0.76rem; color: #888; margin: 0 0 12px; }
.tabla-wrapper-metrica { max-height: 260px; overflow-y: auto; }
.tabla-metrica { border-collapse: collapse; width: 100%; }
.tabla-metrica th {
  background: #eef1ea;
  text-align: left;
  font-size: 0.74rem;
  padding: 7px 9px;
  border: 1px solid #d7ded2;
  position: sticky;
  top: 0;
}
.tabla-metrica td { padding: 7px 9px; border: 1px solid #eee; font-size: 0.82rem; }

.mapa-calor {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 8px;
}
.celda-calor {
  border-radius: 8px;
  padding: 10px 8px;
  text-align: center;
  color: #fff;
  font-size: 0.78rem;
  font-weight: 700;
  text-shadow: 0 1px 2px rgba(0,0,0,0.25);
}
.celda-calor .celda-calor-num { display: block; font-size: 1.1rem; }

.lista-barras { display: flex; flex-direction: column; gap: 8px; }
.fila-barra { display: flex; align-items: center; gap: 8px; font-size: 0.8rem; }
.fila-barra .etiqueta-barra { width: 130px; flex: none; color: #555; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fila-barra .pista-barra { flex: 1; background: #f1efe7; border-radius: 20px; height: 16px; overflow: hidden; }
.fila-barra .relleno-barra { height: 100%; background: var(--marca-verde-oscuro); border-radius: 20px; }
.fila-barra .valor-barra { width: 40px; flex: none; text-align: right; font-weight: 700; color: var(--marca-verde-oscuro); }

/* ---------- Empaque ---------- */
.tabla-empaque { border-collapse: collapse; width: 100%; }
.tabla-empaque th {
  background: var(--gris-header);
  text-align: center;
  font-weight: 700;
  font-size: 0.78rem;
  padding: 10px 12px;
  border: 1px solid #bfbfbf;
  position: sticky;
  top: 0;
}
.tabla-empaque td {
  padding: 8px 12px;
  border: 1px solid #e4e4e4;
  font-size: 0.87rem;
  font-weight: 700;
  text-align: center;
}
.tabla-empaque tr.separador-empaque td { border-top: 6px solid var(--verde-separador); }
.col-acciones-empaque { text-align: right; white-space: nowrap; }
.texto-empacado-por { display: block; font-size: 0.72rem; color: #888; font-weight: 500; margin-bottom: 2px; }

.lista-verificacion-empaque { display: flex; flex-direction: column; gap: 6px; margin: 10px 0; }
.item-verificacion-empaque {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px 12px;
  background: #fafafa;
  border: 1px solid var(--gris-borde);
  border-radius: 8px;
  font-size: 0.87rem;
}
.item-verificacion-empaque .info-item-empaque { flex: 1; min-width: 160px; }
.control-cantidad-empaque { display: flex; align-items: center; gap: 6px; flex: none; }
.input-ud-empaque {
  width: 64px;
  padding: 7px 8px;
  text-align: center;
  font-weight: 700;
  border: 1px solid var(--gris-borde);
  border-radius: 6px;
}
.etiqueta-de-total { font-size: 0.78rem; color: #888; white-space: nowrap; }
.btn-todo-empaque {
  border: 1px solid var(--marca-verde-claro);
  background: #fff;
  color: var(--marca-verde-oscuro);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 0.74rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.btn-todo-empaque:hover { background: var(--marca-verde-claro); color: #fff; }
.item-verificacion-empaque.marcado-presente { border-color: var(--marca-verde-claro); background: #f3f8f1; }
.item-verificacion-empaque.marcado-faltante { border-color: var(--marca-dorado); }
.item-verificacion-empaque .etiqueta-estado-item { font-size: 0.72rem; font-weight: 700; padding: 2px 8px; border-radius: 10px; flex: none; }
.item-verificacion-empaque.marcado-presente .etiqueta-estado-item { background: #e5efe2; color: var(--marca-verde-oscuro); }
.item-verificacion-empaque.marcado-faltante .etiqueta-estado-item { background: #fdf1d9; color: var(--marca-dorado); }
.resumen-verificacion-empaque { font-size: 0.82rem; color: #666; margin: 4px 0 14px; font-weight: 600; }
.badge-parcial { background: #fdf1d9; color: var(--marca-dorado); }

/* ---------- Foto de entrega (cámara) ---------- */
.etiqueta-foto-entrega { display: block; font-size: 0.78rem; color: #555; font-weight: 600; margin: 14px 0 6px; }
.zona-foto-entrega {
  border: 2px dashed var(--gris-borde);
  border-radius: 10px;
  padding: 14px;
  text-align: center;
  background: #fafafa;
}
.placeholder-foto-entrega { display: flex; flex-direction: column; align-items: center; }
.previa-foto-entrega { max-width: 100%; max-height: 220px; border-radius: 8px; display: block; margin: 0 auto 8px; }

/* ---------- Ajustes / Google Drive ---------- */
.texto-redirect-uri {
  font-family: monospace;
  font-size: 0.78rem;
  background: #fafafa;
  border: 1px solid var(--gris-borde);
  border-radius: 6px;
  padding: 8px 10px;
  word-break: break-all;
  margin: 0 0 14px;
}
.estado-conexion-drive { margin-bottom: 14px; font-size: 0.88rem; }
.etiqueta-rango-activo {
  font-size: 0.82rem;
  color: var(--marca-verde-oscuro);
  font-weight: 600;
  background: rgba(164, 177, 160, 0.28);
  padding: 6px 12px;
  border-radius: 20px;
}

/* ---------- Responsive: tablet ---------- */
@media (max-width: 780px) {
  .fila-item { grid-template-columns: 1fr 1fr; }
  .fila-item .item-producto { grid-column: 1 / -1; }
  .fila-item .item-nota { grid-column: 1 / -1; }
}

/* ---------- Responsive: móvil ---------- */
@media (max-width: 640px) {
  .topbar { padding: 10px 14px; }
  .topbar h1 { font-size: 1.0rem; }
  .logo-topbar { height: 32px; }
  .topbar-actions { justify-content: flex-start; }
  .btn-nuevo { margin-left: 0; width: 100%; order: 10; }

  main { padding: 10px; }

  .modal-fondo { padding: 0; align-items: stretch; }
  .modal {
    max-width: none;
    width: 100%;
    min-height: 100%;
    border-radius: 0;
    padding: 16px 16px 90px;
  }
  .fila-item { grid-template-columns: 1fr; }
  .fila-item .item-producto,
  .fila-item .item-ud,
  .fila-item .item-tamano,
  .fila-item .item-nota { grid-column: 1 / -1; }
  .btn-quitar-item { justify-self: end; width: 44px; }

  .modal-footer { position: sticky; bottom: -16px; background: #fff; margin: 14px -16px -90px; padding: 12px 16px calc(12px + 90px); }
  .modal-footer-derecha { width: 100%; }
  .modal-footer-derecha .btn { flex: 1; }

  /* Componentes agregados después del primer pase responsive: se aseguran
     de no forzar un ancho mínimo mayor al de la pantalla. */
  .barra-kpis, .barra-herramientas, .filtro-estado { width: 100%; }
  .kpi { flex: 1 1 calc(50% - 8px); min-width: 0; }
  .input-buscar, .input-rango, .control-tamano-letra { max-width: none; width: 100%; }
  .filtro-categorias-wrapper { width: 100%; }
  .filtro-categorias-wrapper .btn { width: 100%; }
  .menu-filtro-categorias { left: 0; right: 0; width: auto; max-width: calc(100vw - 40px); }
  .barra-impresion { flex-wrap: wrap; }
  .ayuda-rango { width: 100%; }
  .grid-metricas { grid-template-columns: 1fr; }
  .tabla-wrapper-metrica { max-height: 220px; }
  .fila-color { flex-wrap: wrap; }
  .paleta-colores { max-width: 100%; }
  .fila-segmento { grid-template-columns: auto 1fr auto; }
  .texto-redirect-uri { font-size: 0.7rem; }
}

/* ---------- Impresión ---------- */
.titulo-impresion { display: none; }

@media print {
  body * { visibility: hidden; }
  .area-imprimir, .area-imprimir * { visibility: visible; }
  .area-imprimir {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    padding: 0;
  }
  /* Pedidos excluidos del rango elegido en "Imprimir" */
  .oculto-impresion, .oculto-impresion * { display: none !important; visibility: hidden !important; }
  .titulo-impresion {
    display: block;
    font-size: 1.2rem;
    margin: 0 0 14px;
  }
  .tabla-wrapper { box-shadow: none; border-radius: 0; overflow-x: visible; }
  .tabla-pedidos { width: auto !important; table-layout: auto; }
  .tabla-body-scroll { max-height: none; overflow-y: visible; }
  .tabla-pedidos th, .tabla-pedidos td { font-size: 11px; padding: 6px 8px; }
  /* Al imprimir la tabla de pedidos solo se muestran: COD, NOMBRE, PRODUCTO, UD, TAMAÑO, NOTA */
  col[data-col="drag"], col[data-col="acciones"], col[data-col="fecha"] { display: none; }
  .col-acciones, .tabla-pedidos th.col-acciones,
  .col-drag, .tabla-pedidos th.col-drag,
  .col-fecha, .tabla-pedidos th.col-fecha { display: none; }
  .resizer { display: none; }
  .ayuda-tabla { display: none; }
  .vacio-mensaje { visibility: visible; }
  .tabla-entregas th, .tabla-entregas td { font-size: 11px; padding: 6px 8px; }
  .no-imprimir, .col-estado, .col-acciones-entrega,
  .tabla-entregas th.col-estado, .tabla-entregas th.col-acciones-entrega { display: none; }
}
