/* Control de Despachos · Nor-Pan. Primero celular; dos columnas desde 1000 px. */
:root {
  --azul: #222D80; --naranja: #EB690B; --naranja2: #FF6600;
  --bg: #f3f5f9; --surface: #ffffff; --surface2: #f7f8fb; --fg: #141a33; --muted: #5b6478; --line: #dde2ec;
  --accent: #222D80; --accent-fg: #ffffff; --accent-soft: #e6e9f7;
  --pend: #8a5200; --pend-bg: #fdf0d8;
  --prep: #1d4fb8; --prep-bg: #e3ecfb;
  --ok: #17693c; --ok-bg: #def3e6;
  --danger: #b42318; --danger-bg: #fde8e6;
  --sombra: 0 1px 2px rgba(20, 26, 51, .06), 0 2px 8px rgba(20, 26, 51, .05);
  --radio: 12px;
  --f: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "Cascadia Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c1020; --surface: #151a2e; --surface2: #1a2037; --fg: #e7eaf3; --muted: #9ba4bb; --line: #2a3150;
    --accent: #93a4ff; --accent-fg: #0c1020; --accent-soft: #232b52;
    --pend: #f4b860; --pend-bg: #3a2a10; --prep: #8db4ff; --prep-bg: #17284c; --ok: #6bd59b; --ok-bg: #12301f;
    --danger: #ff8a7c; --danger-bg: #3d1915; --sombra: none;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 16px/1.45 var(--f); min-height: 100vh; overflow-wrap: anywhere; }
img { max-width: 100%; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--naranja2); outline-offset: 2px; }

/* ---------- barra superior ---------- */
.barra { position: sticky; top: 0; z-index: 30; background: var(--surface); border-bottom: 1px solid var(--line);
  padding: calc(env(safe-area-inset-top, 0px) + 8px) max(12px, env(safe-area-inset-right)) 8px max(12px, env(safe-area-inset-left)); }
.barra-in { max-width: 1240px; margin: 0 auto; display: flex; align-items: center; gap: 12px; }
.marca { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--fg); min-width: 0; }
.marca img { height: 30px; width: auto; flex: none; }
.marca .titulo { font-weight: 700; font-size: 1.02rem; letter-spacing: -.01em; white-space: nowrap; border-left: 2px solid var(--naranja); padding-left: 10px; }
.barra .espacio { flex: 1; }
.btn-menu { display: flex; align-items: center; gap: 8px; background: var(--surface2); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px 6px 6px; cursor: pointer; max-width: 46vw; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--azul); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: .85rem; flex: none; }
.btn-menu .nom { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; font-size: .92rem; }
.menu { position: absolute; right: max(12px, env(safe-area-inset-right)); top: calc(100% + 4px); background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 8px 28px rgba(0,0,0,.18); min-width: 230px; padding: 6px; display: flex; flex-direction: column; }
.menu .quien { padding: 8px 12px 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; font-size: .88rem; color: var(--muted); }
.menu .quien b { display: block; color: var(--fg); font-size: 1rem; }
.menu button { text-align: left; background: none; border: 0; padding: 11px 12px; border-radius: 8px; cursor: pointer; font-size: .98rem; }
.menu button:hover { background: var(--surface2); }

/* ---------- contenedor ---------- */
.pagina { max-width: 1240px; margin: 0 auto; padding: 14px max(12px, env(safe-area-inset-left)) calc(110px + env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-right)); }
.grid { display: grid; grid-template-columns: 1fr; gap: 18px; align-items: start; }
@media (min-width: 1000px) {
  .grid { grid-template-columns: 360px minmax(0, 1fr); }
  .pagina { padding-bottom: 40px; }
  #panelNuevo { position: sticky; top: 72px; max-height: calc(100vh - 88px); overflow: auto; }
}
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radio); padding: 16px; box-shadow: var(--sombra); }
.panel h2 { margin: 0 0 12px; font-size: 1.08rem; }

/* ---------- contadores ---------- */
.contadores { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-bottom: 12px; }
.contador { border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 8px 10px; text-align: left; cursor: pointer; display: flex; flex-direction: column; gap: 0; min-width: 0; }
.contador b { font: 700 1.45rem/1.1 var(--mono); font-variant-numeric: tabular-nums; }
.contador span { font-size: .74rem; color: var(--muted); font-weight: 600; line-height: 1.2; }
.contador.p b { color: var(--pend); } .contador.r b { color: var(--prep); } .contador.o b { color: var(--ok); } .contador.h b { color: var(--naranja); }
.contador span { overflow-wrap: normal; word-break: normal; hyphens: manual; }
@media (max-width: 420px) { .contador { padding: 8px 8px; } .contador span { font-size: .7rem; } .btn-menu .nom { display: none; } .btn-menu { padding: 4px; } }
@media (max-width: 360px) { .contador b { font-size: 1.2rem; } .contador span { font-size: .66rem; } }

/* ---------- pestañas y filtros ---------- */
.lista-cab { position: sticky; top: 55px; z-index: 20; background: var(--bg); padding: 6px 0 10px; margin: 0 -2px; }
@media (min-width: 1000px) { .lista-cab { position: static; background: none; } }
.pestanas { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 3px; background: var(--surface2); border: 1px solid var(--line); border-radius: 12px; padding: 3px; }
.pestanas button { border: 0; background: transparent; color: var(--muted); padding: 9px 4px; border-radius: 9px; font-weight: 600; font-size: .9rem; cursor: pointer; white-space: nowrap; }
.pestanas button[aria-pressed="true"] { background: var(--surface); color: var(--fg); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.pestanas .n { font-family: var(--mono); font-size: .8rem; color: var(--muted); margin-left: 3px; }
.filtros { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.filtros .buscar { grid-column: 1 / -1; position: relative; }
.btn-filtros { display: none; }
/* En el celular: búsqueda y botón «Filtrar» en una fila; día y medio aparecen al tocarlo */
@media (max-width: 699px) {
  .filtros { grid-template-columns: 1fr 1fr; }
  .filtros .buscar { grid-column: 1 / 2; grid-row: 1; }
  .btn-filtros { display: inline-flex; grid-column: 2 / 3; grid-row: 1; min-height: 46px; padding: 8px 12px; }
  .filtros { grid-template-columns: 1fr auto; }
  .filtros select { display: none; grid-column: 1 / -1; }
  .filtros.abiertos select { display: block; }
  .btn-filtros.activos { border-color: var(--naranja2); color: var(--naranja); }
}
.filtros .buscar input { padding-left: 38px; }
.filtros .buscar svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--muted); pointer-events: none; }
@media (min-width: 700px) { .filtros { grid-template-columns: 1fr 1fr 2fr; } .filtros .buscar { grid-column: auto; } }
.barra-pdf { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 2px 0 10px; }
.barra-pdf .meta { flex: 1 1 180px; }

/* ---------- controles ---------- */
label, .lbl { display: flex; flex-direction: column; gap: 5px; font-size: .78rem; font-weight: 700; letter-spacing: .03em; text-transform: uppercase; color: var(--muted); }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
  width: 100%; background: var(--surface2); border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; font-size: 16px;
  text-transform: none; letter-spacing: normal; font-weight: 400; color: var(--fg); min-height: 46px; }
textarea { min-height: 90px; resize: vertical; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 34px; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border-radius: 10px; padding: 11px 16px; min-height: 46px; font-weight: 600; font-size: .98rem;
  cursor: pointer; border: 1px solid transparent; text-decoration: none; line-height: 1.2; text-align: center; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primario { background: var(--accent); color: var(--accent-fg); }
.btn.naranja { background: var(--naranja2); color: #fff; }
.btn.secundario { background: var(--surface); color: var(--fg); border-color: var(--line); }
.btn.secundario:hover:not(:disabled) { border-color: var(--muted); }
.btn.peligro { background: var(--danger); color: #fff; }
.btn.chico { min-height: 38px; padding: 7px 12px; font-size: .9rem; }
.btn.ancho { width: 100%; }
.enlace { background: none; border: 0; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; padding: 8px 4px; cursor: pointer; font-size: .9rem; }
.enlace.rojo { color: var(--danger); }
.msg { border-radius: 10px; padding: 10px 12px; font-size: .92rem; }
.msg.err { background: var(--danger-bg); color: var(--danger); }
.msg.ok { background: var(--ok-bg); color: var(--ok); }
.msg.info { background: var(--accent-soft); color: var(--fg); }
.meta { font-size: .82rem; color: var(--muted); }

/* ---------- formulario de pedido ---------- */
.form { display: flex; flex-direction: column; gap: 14px; }
.dos { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.dia-btns { display: grid; grid-template-columns: 1fr 1fr 1.4fr; gap: 6px; }
.dia-btns button { border: 1px solid var(--line); background: var(--surface2); border-radius: 10px; min-height: 46px; font-weight: 600; cursor: pointer; }
.dia-btns button[aria-pressed="true"] { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.prod-filas { display: flex; flex-direction: column; gap: 8px; }
.prod-fila { display: grid; grid-template-columns: 1fr 1fr auto; gap: 6px; padding: 8px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface2); }
.prod-fila .pnom { grid-column: 1 / 3; }
.prod-fila input { background: var(--surface); min-height: 42px; padding: 9px 10px; }
.prod-fila .quitar { grid-row: 1; grid-column: 3; width: 42px; height: 42px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); font-size: 1.2rem; cursor: pointer; }
.prod-fila .quitar:disabled { visibility: hidden; }

/* hoja para el formulario en el celular */
@media (max-width: 999px) {
  #panelNuevo { position: fixed; inset: 0; z-index: 60; border-radius: 0; border: 0; overflow: auto; padding: calc(env(safe-area-inset-top, 0px) + 12px) 14px calc(env(safe-area-inset-bottom, 0px) + 20px); }
  #panelNuevo:not(.abierto) { display: none; }
  body.hoja-abierta { overflow: hidden; }
}
.hoja-cab { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.hoja-cab h2 { margin: 0; flex: 1; }
.cerrar-hoja { width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface2); font-size: 1.3rem; cursor: pointer; }
@media (min-width: 1000px) { .cerrar-hoja.solo-celu { display: none; } }

.fab { position: fixed; right: max(16px, env(safe-area-inset-right)); bottom: calc(18px + env(safe-area-inset-bottom, 0px)); z-index: 40;
  background: var(--naranja2); color: #fff; border: 0; border-radius: 999px; padding: 15px 22px; font-weight: 700; font-size: 1.02rem;
  box-shadow: 0 6px 20px rgba(235, 105, 11, .45); cursor: pointer; display: flex; align-items: center; gap: 8px; }
@media (min-width: 1000px) { .fab { display: none; } }

/* ---------- tarjetas de pedido ---------- */
.lista { display: flex; flex-direction: column; gap: 10px; }
.pedido { background: var(--surface); border: 1px solid var(--line); border-left: 5px solid var(--line); border-radius: var(--radio); padding: 13px 14px; box-shadow: var(--sombra);
  display: grid; grid-template-columns: 1fr; gap: 10px; }
.pedido.pendiente { border-left-color: var(--pend); }
.pedido.preparado { border-left-color: var(--prep); }
.pedido.despachado { border-left-color: var(--ok); }
@media (min-width: 700px) { .pedido { grid-template-columns: minmax(0, 1fr) 250px; } }
.p-info { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.p-top { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; }
.num { font: 700 1.05rem var(--mono); }
.chip { font-size: .76rem; font-weight: 700; padding: 3px 8px; border-radius: 6px; border: 1px solid var(--line); white-space: nowrap; }
.chip.fecha { font-family: var(--mono); border: 0; color: var(--muted); padding-left: 0; padding-right: 0; font-weight: 600; }
.chip.estado { text-transform: uppercase; letter-spacing: .05em; border: 0; border-radius: 999px; }
.chip.estado.pendiente { background: var(--pend-bg); color: var(--pend); }
.chip.estado.preparado { background: var(--prep-bg); color: var(--prep); }
.chip.estado.despachado { background: var(--ok-bg); color: var(--ok); }
.chip.dia-hoy { background: var(--prep-bg); color: var(--prep); border: 0; }
.chip.dia-manana { border-style: dashed; color: var(--muted); }
.chip.dia-despues { color: var(--muted); }
.chip.atrasado { background: var(--danger-bg); color: var(--danger); border: 0; }
.cliente { font-weight: 700; font-size: 1.02rem; }
.prods { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.prods .cant { font: 700 .98rem var(--mono); }
.prods .cod { font: .8rem var(--mono); color: var(--muted); }
.obs { margin: 0; white-space: pre-line; font-size: .9rem; color: var(--muted); }
.preparo { font-size: .9rem; }
.fotos { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.fotos .lbl { width: 100%; font-size: .72rem; }
.foto { position: relative; line-height: 0; }
.foto button.ver { padding: 0; border: 0; background: none; cursor: zoom-in; line-height: 0; border-radius: 8px; }
.foto img, .doc .vista { width: 62px; height: 62px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); background: var(--surface2); }
.foto .x { position: absolute; top: -8px; right: -8px; width: 28px; height: 28px; border-radius: 50%; background: var(--danger); color: #fff; border: 2px solid var(--surface); cursor: pointer; font-size: 1rem; line-height: 1; padding: 0; }
.p-acc { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.docs { display: flex; gap: 10px; flex-wrap: wrap; }
.doc { display: flex; flex-direction: column; align-items: center; gap: 3px; background: none; border: 0; padding: 0; cursor: zoom-in; color: var(--accent); font-size: .78rem; font-weight: 600; width: 72px; }
.doc .pdf { display: grid; place-items: center; font: 700 .85rem var(--mono); color: var(--danger); background: var(--danger-bg); }
.falta { font-size: .85rem; color: var(--pend); }
.paso-box { border: 1px solid var(--line); border-radius: 10px; padding: 10px; display: flex; flex-direction: column; gap: 8px; background: var(--surface2); }
.paso-box .archivo-elegido { display: flex; gap: 10px; align-items: center; font-size: .88rem; }
.paso-box .archivo-elegido img { width: 52px; height: 52px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }
.fila-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.fila-btns .btn { flex: 1 1 auto; }
.links { display: flex; gap: 4px 12px; flex-wrap: wrap; }
.confirmar { border: 1px solid var(--danger); border-radius: 10px; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.historia { font-size: .8rem; color: var(--muted); }
.vacio { text-align: center; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radio); padding: 34px 16px; background: var(--surface); }
.vacio strong { display: block; color: var(--fg); margin-bottom: 4px; }
.mas { display: flex; justify-content: center; margin-top: 12px; }
.resaltado { animation: brillo 1.6s ease-out 1; }
@keyframes brillo { from { box-shadow: 0 0 0 4px var(--naranja2); } to { box-shadow: var(--sombra); } }

/* ---------- visor ---------- */
.visor { position: fixed; inset: 0; z-index: 80; background: rgba(6, 9, 18, .94); display: flex; flex-direction: column; color: #fff;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px); }
.visor-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px 12px; }
.visor-bar .tit { flex: 1 1 160px; font-weight: 600; }
.visor-bar button, .visor-bar a { background: rgba(255,255,255,.14); color: #fff; border: 1px solid rgba(255,255,255,.28); border-radius: 9px; padding: 9px 12px; text-decoration: none; cursor: pointer; font-size: .92rem; }
.visor-bar button:disabled { opacity: .35; }
.visor-img { flex: 1; min-height: 0; overflow: auto; display: flex; align-items: center; justify-content: center; padding: 0 10px 12px; touch-action: pan-x pan-y pinch-zoom; }
.visor-img img { max-width: 100%; max-height: 100%; object-fit: contain; background: #fff; border-radius: 4px; cursor: zoom-in; }
.visor-img.zoom { align-items: flex-start; justify-content: flex-start; }
.visor-img.zoom img { max-width: none; max-height: none; cursor: zoom-out; }

/* ---------- ingreso ---------- */
.ingreso { min-height: 100vh; display: grid; place-items: center; padding: 20px; background:
  radial-gradient(1200px 500px at 110% -10%, rgba(255, 102, 0, .16), transparent 60%), radial-gradient(900px 500px at -20% 110%, rgba(34, 45, 128, .18), transparent 60%), var(--bg); }
.ingreso .caja { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 26px 22px; box-shadow: 0 10px 40px rgba(20, 26, 51, .12); }
.ingreso .logo { display: block; height: 44px; margin: 0 auto 6px; }
.ingreso h1 { text-align: center; font-size: 1.25rem; margin: 6px 0 18px; }
.ingreso .form { gap: 14px; }
.ver-clave { position: relative; }
.ver-clave button { position: absolute; right: 6px; bottom: 6px; height: 34px; border: 0; background: none; color: var(--muted); cursor: pointer; font-size: .85rem; padding: 0 8px; }

/* ---------- usuarios y cuenta ---------- */
.tabla-usuarios { display: flex; flex-direction: column; gap: 8px; }
.usuario-fila { display: grid; grid-template-columns: 1fr; gap: 8px; border: 1px solid var(--line); border-radius: 12px; padding: 12px; background: var(--surface); }
@media (min-width: 760px) { .usuario-fila { grid-template-columns: minmax(0, 1fr) auto; align-items: center; } }
.usuario-fila.inactivo { opacity: .6; }
.rol { font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--fg); }
.clave-nueva { font: 700 1.3rem var(--mono); letter-spacing: .04em; background: var(--surface2); border: 1px dashed var(--accent); border-radius: 10px; padding: 12px; text-align: center; user-select: all; }
.volver { margin-bottom: 12px; }
.aviso-instalar { display: flex; gap: 10px; align-items: flex-start; }
.aviso-instalar .txt { flex: 1; font-size: .9rem; }
.conexion { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(86px + env(safe-area-inset-bottom, 0px)); z-index: 70; background: #222; color: #fff; padding: 9px 14px; border-radius: 999px; font-size: .88rem; box-shadow: 0 4px 16px rgba(0,0,0,.3); }
@media (min-width: 1000px) { .conexion { bottom: 18px; } }
.toast { position: fixed; left: 50%; transform: translateX(-50%); top: calc(64px + env(safe-area-inset-top, 0px)); z-index: 90; background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: .92rem; box-shadow: 0 6px 20px rgba(0,0,0,.25); max-width: calc(100vw - 24px); }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
