:root {
  --bg: #f3f5f9; --panel: #ffffff; --ink: #172033; --muted: #64708a; --line: #e2e7ef;
  --pri: #1f4fd1; --pri-2: #163a9c; --pri-soft: #e8eefc;
  --ok: #138a52; --ok-soft: #e3f6ec; --warn: #b86a00; --warn-soft: #fff2dc;
  --bad: #c62f2f; --bad-soft: #fde8e8; --info: #0b7a99; --info-soft: #e0f4f9;
  --side: #121a2e; --side-ink: #c5cde0; --radius: 12px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 4px 14px rgba(16,24,40,.06);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; color: var(--ink); background: var(--bg); -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--pri); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.right { text-align: right; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.space { justify-content: space-between; }

/* Banda entorno de prueba */
.banda-prueba { background: repeating-linear-gradient(45deg, #ff9f1a, #ff9f1a 12px, #ffb347 12px, #ffb347 24px); color: #3b2300; text-align: center; font-weight: 700; font-size: 12px; letter-spacing: .08em; padding: 3px; }

/* Login */
.login-wrap { min-height: 100%; display: grid; place-items: center; padding: 24px 16px 90px; background: radial-gradient(1200px 600px at 10% -10%, #dfe8ff, transparent), radial-gradient(900px 500px at 110% 110%, #e5f5ee, transparent), var(--bg); }
.login-card { width: 100%; max-width: 380px; background: var(--panel); border-radius: 18px; box-shadow: 0 10px 40px rgba(16,24,40,.12); padding: 30px 26px; }
.login-card h1 { font-size: 22px; margin: 10px 0 2px; }
.login-logo { height: 56px; max-width: 220px; object-fit: contain; }
.login-marca { width: 56px; height: 56px; border-radius: 14px; background: var(--pri); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 22px; }
.entorno-switch { position: fixed; right: 16px; bottom: 16px; display: flex; background: var(--panel); border-radius: 999px; box-shadow: var(--shadow); padding: 4px; border: 1px solid var(--line); }
.entorno-switch button { border: 0; background: transparent; padding: 8px 14px; border-radius: 999px; cursor: pointer; font-weight: 600; font-size: 13px; color: var(--muted); }
.entorno-switch button.on.real { background: var(--ok); color: #fff; }
.entorno-switch button.on.prueba { background: #ff9f1a; color: #3b2300; }

/* Layout */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); padding: 14px 10px; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; }
.side .marca { display: flex; gap: 10px; align-items: center; padding: 6px 8px 16px; color: #fff; font-weight: 700; }
.side .marca img { height: 34px; max-width: 120px; object-fit: contain; background: #fff; border-radius: 6px; padding: 2px; }
.side .marca .logo-txt { width: 34px; height: 34px; border-radius: 9px; background: var(--pri); display: grid; place-items: center; font-weight: 800; }
.side nav a { display: flex; gap: 11px; align-items: center; padding: 10px 12px; border-radius: 9px; color: var(--side-ink); text-decoration: none; font-weight: 500; margin-bottom: 2px; }
.side nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.side nav a.on { background: var(--pri); color: #fff; }
.side nav a .ico { width: 22px; text-align: center; font-size: 17px; }
.side nav a .cnt { margin-left: auto; background: #ff9f1a; color: #2b1900; border-radius: 999px; font-size: 11px; font-weight: 800; padding: 1px 7px; }
.side .pie { margin-top: auto; font-size: 11px; color: #7d89a6; padding: 10px 12px 0; }
.main { min-width: 0; display: flex; flex-direction: column; }
.top { background: var(--panel); border-bottom: 1px solid var(--line); padding: 10px 18px; display: flex; gap: 12px; align-items: center; position: sticky; top: 0; z-index: 20; }
.top h2 { margin: 0; font-size: 18px; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.burger { display: none; }
.content { padding: 18px; max-width: 1400px; width: 100%; }
.chip-ent { font-size: 11px; font-weight: 800; padding: 3px 8px; border-radius: 999px; }
.chip-ent.real { background: var(--ok-soft); color: var(--ok); }
.chip-ent.prueba { background: #ffe7c2; color: #7a4600; }

/* Botones */
.btn { border: 1px solid var(--line); background: var(--panel); padding: 9px 14px; border-radius: 10px; cursor: pointer; font-weight: 600; display: inline-flex; gap: 7px; align-items: center; justify-content: center; white-space: nowrap; text-decoration: none; color: var(--ink); }
.btn:hover { border-color: #c8d0de; }
.btn.pri { background: var(--pri); border-color: var(--pri); color: #fff; }
.btn.pri:hover { background: var(--pri-2); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.bad { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.warn { background: #ff9f1a; border-color: #ff9f1a; color: #2b1900; }
.btn.wa { background: #1fa855; border-color: #1fa855; color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn.xl { padding: 16px 22px; font-size: 18px; border-radius: 14px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { border: 0; background: transparent; font-size: 20px; cursor: pointer; position: relative; padding: 6px 8px; border-radius: 8px; }
.icon-btn:hover { background: var(--bg); }
.icon-btn .dot { position: absolute; top: 0; right: 0; background: var(--bad); color: #fff; font-size: 10px; font-weight: 800; border-radius: 999px; padding: 1px 5px; }

/* Tarjetas y KPIs */
.card { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }
.card h3 { margin: 0 0 12px; font-size: 16px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; }
.kpi .v { font-size: 28px; font-weight: 800; line-height: 1.1; }
.kpi .l { color: var(--muted); font-size: 13px; }
.kpi.alerta .v { color: var(--warn); }
.kpi.link { cursor: pointer; }

/* Filtros y formularios */
.filtros { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; align-items: end; }
.campo { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.campo label { font-size: 12px; font-weight: 600; color: var(--muted); }
.campo input, .campo select, .campo textarea, input.in, select.in { width: 100%; border: 1px solid #d3dae6; border-radius: 9px; padding: 9px 11px; background: #fff; min-height: 40px; }
.campo input:focus, .campo select:focus, .campo textarea:focus, input.in:focus { outline: 2px solid var(--pri-soft); border-color: var(--pri); }
.campo input[readonly] { background: var(--bg); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.req::after { content: " *"; color: var(--bad); }
.check { display: flex; gap: 8px; align-items: center; padding: 6px 0; cursor: pointer; }
.check input { width: 18px; height: 18px; }

/* Tablas */
.tabla-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; background: #fafbfd; }
table.t td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.t tr.clic { cursor: pointer; }
table.t tr.clic:hover td { background: #f7f9fd; }
table.t td.num, table.t th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.t tfoot td { font-weight: 800; background: #fafbfd; }
.vacio { text-align: center; color: var(--muted); padding: 30px 10px; }

/* Badges */
.b { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.b.solicitado { background: #f1e8ff; color: #6a2fc0; }
.b.pendiente { background: var(--warn-soft); color: var(--warn); }
.b.validado { background: var(--info-soft); color: var(--info); }
.b.en_preparacion { background: #e6edff; color: var(--pri); }
.b.listo { background: var(--ok-soft); color: var(--ok); }
.b.expedido { background: #eceff4; color: #4a5468; }
.b.rechazado, .b.cancelado, .b.bad { background: var(--bad-soft); color: var(--bad); }
.b.ok { background: var(--ok-soft); color: var(--ok); }
.b.warn { background: var(--warn-soft); color: var(--warn); }
.b.gris { background: #eceff4; color: #4a5468; }
.b.ENTRADA { background: var(--ok-soft); color: var(--ok); }
.b.SALIDA { background: var(--bad-soft); color: var(--bad); }
.b.AJUSTE { background: var(--warn-soft); color: var(--warn); }
.b.UBICACION { background: var(--info-soft); color: var(--info); }

/* Pestañas */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs button { border: 0; background: transparent; padding: 10px 14px; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap; }
.tabs button.on { color: var(--pri); border-color: var(--pri); }

/* Modal */
.modal-fondo { position: fixed; inset: 0; background: rgba(15,22,40,.5); z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 24px 12px; overflow-y: auto; animation: fade .12s; }
.modal { background: var(--panel); border-radius: 16px; width: 100%; max-width: 640px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal.ancho { max-width: 1000px; }
.modal-cab { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.modal-cab h3 { margin: 0; font-size: 18px; flex: 1; }
.modal-cuerpo { padding: 18px 20px; }
.modal-pie { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
@keyframes fade { from { opacity: 0; } }

/* Toasts */
.toasts { position: fixed; top: 14px; right: 14px; z-index: 300; display: flex; flex-direction: column; gap: 8px; max-width: min(380px, calc(100vw - 28px)); }
.toast { background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 12px; box-shadow: var(--shadow); animation: fade .2s; }
.toast.ok { background: var(--ok); } .toast.bad { background: var(--bad); }

/* Notificaciones */
.notis { position: absolute; right: 12px; top: 54px; width: min(380px, calc(100vw - 24px)); background: var(--panel); border-radius: 14px; box-shadow: 0 12px 40px rgba(0,0,0,.18); z-index: 60; max-height: 70vh; overflow-y: auto; }
.noti { padding: 12px 16px; border-bottom: 1px solid var(--line); cursor: pointer; }
.noti.nueva { background: var(--pri-soft); }
.noti b { display: block; }
.menu-user { position: absolute; right: 12px; top: 54px; background: var(--panel); border-radius: 12px; box-shadow: 0 12px 40px rgba(0,0,0,.18); z-index: 60; min-width: 230px; padding: 6px; }
.menu-user button { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 10px 12px; border-radius: 8px; cursor: pointer; }
.menu-user button:hover { background: var(--bg); }

/* Banner versión */
.banner-version { position: fixed; left: 50%; transform: translateX(-50%); bottom: 18px; z-index: 200; background: var(--ink); color: #fff; border-radius: 999px; padding: 8px 8px 8px 18px; display: flex; gap: 12px; align-items: center; box-shadow: 0 10px 30px rgba(0,0,0,.25); }

/* Preparación (tablet) */
.prep-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; }
.prep { background: var(--panel); border-radius: 16px; box-shadow: var(--shadow); padding: 18px; border-top: 6px solid var(--info); display: flex; flex-direction: column; }
.prep.en_preparacion { border-top-color: var(--pri); }
.prep.listo { border-top-color: var(--ok); opacity: .85; }
.prep h3 { margin: 0; font-size: 22px; }
.prep .linea { display: flex; gap: 12px; align-items: center; padding: 12px; border: 1px solid var(--line); border-radius: 12px; margin-top: 8px; cursor: pointer; user-select: none; }
.prep .linea.hecha { background: var(--ok-soft); border-color: #a9dfc3; }
.prep .linea.hecha .txt { text-decoration: line-through; color: var(--muted); }
.prep .linea .cant { font-size: 24px; font-weight: 800; min-width: 54px; text-align: center; }
.prep .linea .ubi { font-size: 13px; font-weight: 800; background: var(--side); color: #fff; border-radius: 8px; padding: 4px 8px; }
.prep .tick { width: 28px; height: 28px; border-radius: 50%; border: 2px solid #c8d0de; display: grid; place-items: center; font-weight: 900; color: #fff; flex: none; }
.prep .linea.hecha .tick { background: var(--ok); border-color: var(--ok); }

/* Firma */
.pad-wrap { border: 2px dashed #c8d0de; border-radius: 12px; background: #fff; position: relative; touch-action: none; }
.pad-wrap canvas { width: 100%; height: 220px; display: block; touch-action: none; cursor: crosshair; }
.pad-wrap .linea-firma { position: absolute; left: 8%; right: 8%; bottom: 46px; border-bottom: 1px solid #c8d0de; pointer-events: none; }
.pad-wrap .hint { position: absolute; left: 0; right: 0; bottom: 18px; text-align: center; font-size: 12px; color: var(--muted); pointer-events: none; }
.firma-img { max-height: 110px; max-width: 100%; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.qr { width: 240px; height: 240px; image-rendering: pixelated; border-radius: 10px; }

/* Selector de stock en pedido */
.picker { max-height: 360px; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; }
.picker input.cant { width: 90px; text-align: right; }
.resumen-lineas { background: var(--pri-soft); border-radius: 10px; padding: 10px 14px; margin-top: 10px; }

/* Móvil y tablet */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 90; left: 0; top: 0; bottom: 0; width: 270px; transform: translateX(-100%); transition: transform .2s; box-shadow: 10px 0 40px rgba(0,0,0,.3); }
  .side.abierta { transform: none; }
  .burger { display: inline-block; }
  .content { padding: 12px; }
  .top { padding: 8px 10px; }
  .velo { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 80; }
}
.solo-movil { display: none; }
@media (max-width: 600px) {
  .solo-movil { display: inline-flex; }
  .filtros { grid-template-columns: 1fr 1fr; }
  .filtros > .campo:first-child { grid-column: 1 / -1; }
  .filtros:not(.abiertos) > :not(:first-child):not(.solo-movil) { display: none; }
  .t.responsive thead { display: none; }
  .t.responsive tr { display: block; border-bottom: 1px solid var(--line); padding: 8px 4px; }
  .t.responsive td { display: flex; justify-content: space-between; gap: 12px; border: 0; padding: 4px 6px; text-align: right; }
  .t.responsive td::before { content: attr(data-l); font-weight: 600; color: var(--muted); text-align: left; font-size: 12px; }
  .t.responsive td.num { text-align: right; }
  .modal-fondo { padding: 0; }
  .modal { border-radius: 0; min-height: 100%; }
  .kpi .v { font-size: 24px; }
  .prep-grid { grid-template-columns: 1fr; }
  .btn.oculta-movil-txt span { display: none; }
}
@media print {
  .side, .top, .no-print, .toasts { display: none !important; }
  .app { display: block; }
  body { background: #fff; }
}
