:root {
  --azul: #0a5a8a; --azul2: #0b6fa4; --amarillo: #f7c21f; --fondo: #eef2f5; --panel: #ffffff; --texto: #1c2733;
  --suave: #5b6b7c; --borde: #d6dee8; --verde: #4f7a2c; --lima: #c5d84a; --rojo: #c62828; --naranja: #ec8a2c; --sombra: 0 2px 10px rgba(10, 90, 138, .08);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.4 "Segoe UI", system-ui, sans-serif; color: var(--texto); background: var(--fondo); }
.oculto { display: none !important; }
button, input, select, textarea { font: inherit; }
h1 { font-size: 22px; margin: 0 0 14px; }
h2 { font-size: 17px; margin: 0 0 10px; }
a { color: var(--azul2); }

/* Barra superior */
.barra { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 14px; padding: 0 16px; height: 62px; border-bottom: 3px solid var(--amarillo);
  background: var(--azul); color: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.2); }
.marca { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; white-space: nowrap; }
.marca img { width: 44px; height: 44px; border-radius: 50%; background: #fff; }
.marca small { display: block; font-weight: 400; font-size: 11px; color: var(--lima); letter-spacing: .04em; }
.menu { display: flex; gap: 2px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.menu button { background: none; border: 0; color: #e3f0fa; padding: 7px 9px; font-size: 14px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.menu button:hover { background: rgba(255,255,255,.1); color: #fff; }
.menu button.activo { background: var(--amarillo); color: var(--azul); font-weight: 700; }
.derecha { display: flex; align-items: center; gap: 8px; }
.campana { position: relative; background: rgba(255,255,255,.12); border: 0; border-radius: 50%; width: 38px; height: 38px; cursor: pointer; font-size: 17px; }
.globo { position: absolute; top: -4px; right: -4px; background: var(--rojo); color: #fff; font-size: 11px; font-weight: 700; border-radius: 10px; padding: 1px 6px; }
.usuario { background: none; border: 1px solid rgba(255,255,255,.35); color: #fff; border-radius: 18px; padding: 6px 12px; cursor: pointer; white-space: nowrap; }
.franja { background: #fff4e0; color: #7a4300; border-bottom: 1px solid #f3c77a; padding: 8px 16px; font-size: 14px; cursor: pointer; }
.franja b { color: var(--rojo); }

main { padding: 18px; max-width: 1400px; margin: 0 auto; }
.panel { background: var(--panel); border-radius: 12px; padding: 16px; box-shadow: var(--sombra); margin-bottom: 16px; }
.fila { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.fila > * { min-width: 0; }
.crece { flex: 1; }
label.campo { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--suave); }
input, select, textarea { border: 1px solid var(--borde); border-radius: 8px; padding: 8px 10px; background: #fff; color: var(--texto); min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--azul2); outline-offset: -1px; border-color: var(--azul2); }
input[type=number] { text-align: right; }
.btn { border: 0; border-radius: 8px; padding: 9px 16px; cursor: pointer; background: var(--azul2); color: #fff; font-weight: 600; white-space: nowrap; }
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.sec { background: #e3eaf3; color: var(--azul); }
.btn.verde { background: var(--verde); }
.btn.rojo { background: var(--rojo); }
.btn.grande { padding: 14px 22px; font-size: 18px; }
.btn.chico { padding: 5px 10px; font-size: 13px; }
.enlace { background: none; border: 0; color: var(--azul2); cursor: pointer; padding: 2px 4px; text-decoration: underline; }

/* Tarjetas */
.tarjetas { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tarjeta { background: var(--panel); border-radius: 12px; padding: 14px 16px; box-shadow: var(--sombra); border-left: 5px solid var(--azul2); }
.tarjeta .t { color: var(--suave); font-size: 13px; }
.tarjeta .v { font-size: 24px; font-weight: 700; margin-top: 2px; }
.tarjeta .s { color: var(--suave); font-size: 12px; }
.tarjeta.verde { border-color: var(--verde); } .tarjeta.rojo { border-color: var(--rojo); } .tarjeta.amarillo { border-color: var(--amarillo); }
.tarjeta.click { cursor: pointer; }

/* Tablas */
.tabla-caja { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; color: var(--suave); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em;
  padding: 8px; border-bottom: 2px solid var(--borde); white-space: nowrap; }
td { padding: 8px; border-bottom: 1px solid #edf1f6; vertical-align: middle; }
tr:hover td { background: #f7f9fc; }
td.n, th.n { text-align: right; white-space: nowrap; }
.etq { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; background: #e3eaf3; color: var(--azul); white-space: nowrap; }
.etq.rojo { background: #fde3e3; color: var(--rojo); } .etq.verde { background: #dff3e8; color: var(--verde); } .etq.naranja { background: #fff0d9; color: var(--naranja); }
.vacio { color: var(--suave); text-align: center; padding: 24px; }
.sub { color: var(--suave); font-size: 12px; }

/* Punto de venta */
.pos { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 16px; align-items: start; }
.buscador { font-size: 18px; padding: 12px 14px; width: 100%; }
.resultados { max-height: 330px; overflow-y: auto; margin-top: 8px; border: 1px solid var(--borde); border-radius: 8px; }
.resultado { display: flex; justify-content: space-between; gap: 10px; padding: 9px 12px; cursor: pointer; border-bottom: 1px solid #edf1f6; }
.resultado:hover, .resultado.sel { background: #e8f1fc; }
.resultado .nom { font-weight: 600; }
.carrito td input { width: 90px; }
.carrito td select { width: 92px; }
.total-caja { position: sticky; top: 76px; }
.total-grande { font-size: 36px; font-weight: 800; color: var(--azul); text-align: right; margin: 6px 0 12px; }
.lineas-tot div { display: flex; justify-content: space-between; padding: 3px 0; }
.alternar { display: inline-flex; border: 1px solid var(--borde); border-radius: 8px; overflow: hidden; }
.alternar button { border: 0; background: #fff; padding: 8px 14px; cursor: pointer; }
.alternar button.on { background: var(--azul2); color: #fff; font-weight: 600; }
.cambio { font-size: 20px; font-weight: 700; color: var(--verde); text-align: right; }

/* Modal */
.fondo-modal { position: fixed; inset: 0; background: rgba(10, 25, 45, .5); z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 30px 12px; overflow-y: auto; }
.modal { background: #fff; border-radius: 14px; padding: 20px; width: min(760px, 100%); box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.modal.ancho { width: min(1000px, 100%); }
.rejilla { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; }
.acciones { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.nota { background: #f3f7fc; border-radius: 8px; padding: 10px 12px; font-size: 13px; color: var(--suave); margin: 10px 0; }

/* Avisos */
.avisos { position: fixed; right: 16px; bottom: 16px; z-index: 60; display: flex; flex-direction: column; gap: 8px; max-width: 380px; }
.aviso { background: var(--azul); color: #fff; padding: 12px 16px; border-radius: 10px; box-shadow: 0 4px 16px rgba(0,0,0,.25); animation: entra .2s ease-out; }
.aviso.error { background: var(--rojo); } .aviso.ok { background: var(--verde); } .aviso.alerta { background: #b35f00; }
@keyframes entra { from { transform: translateY(12px); opacity: 0; } }

/* Acceso */
.acceso { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px;
  background: linear-gradient(135deg, #0a5a8a 0%, #0b6fa4 55%, #4f7a2c 100%); }
.caja-acceso { background: #fff; border-radius: 16px; padding: 28px; width: min(400px, 100%); box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.caja-acceso img { width: 150px; display: block; margin: 0 auto 8px; }
.caja-acceso h1 { text-align: center; }
.caja-acceso label.campo { margin-bottom: 10px; }
.caja-acceso .btn { width: 100%; margin-top: 6px; }

/* Formularios CRUD (Productos, Clientes, Proveedores) */
.crud-botones { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--borde); }
.crud-botones .btn { min-width: 120px; }
.btn.amarillo { background: var(--amarillo); color: #3a2c00; }
.seleccionado td { background: #fff7d6 !important; }
tr.fila-click { cursor: pointer; }
.modo-form { font-size: 13px; font-weight: 600; padding: 3px 10px; border-radius: 10px; background: #e6f0d8; color: var(--verde); }
.modo-form.editando { background: #fff0d9; color: #9a5b00; }
.ticket .logo-ticket { display: block; width: 90px; margin: 0 auto 4px; filter: grayscale(1); }

/* Administración: permisos */
.permisos-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 10px; margin-top: 8px; }
.grupo-perm { background: #f6f9fc; border: 1px solid var(--borde); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.grupo-perm > b { color: var(--azul); font-size: 13px; text-transform: uppercase; letter-spacing: .03em; }
.casilla { display: flex; gap: 8px; align-items: flex-start; font-size: 14px; cursor: pointer; }
.casilla input { margin-top: 3px; }
.casilla input:disabled + * , .casilla:has(input:disabled) { color: var(--suave); cursor: default; }

/* Alertas de inventario */
.franja.franja-roja { background: #fde8e8; border-color: #f2b1b1; color: #7a1c1c; }
tr.fila-agotado td:first-child { box-shadow: inset 4px 0 0 var(--rojo); }
tr.fila-bajo td:first-child { box-shadow: inset 4px 0 0 var(--naranja); }

/* Factura de venta (tamaño carta) */
.modal.muy-ancho { width: min(1080px, 100%); }
.fac-previa { border: 1px solid var(--borde); border-radius: 8px; padding: 18px; background: #fff; overflow-x: auto; }
.factura { color: #1c2733; font-size: 13px; max-width: 900px; margin: 0 auto; }
.fac-cab { display: grid; grid-template-columns: 96px 1fr auto; gap: 16px; align-items: center; border-bottom: 3px solid #0b6fa4; padding-bottom: 12px; }
.fac-cab img { width: 96px; height: 96px; }
.fac-nombre { font-size: 24px; font-weight: 800; color: #0a5a8a; letter-spacing: .02em; }
.fac-lema { font-size: 11px; font-weight: 600; color: #4f7a2c; letter-spacing: .08em; margin-bottom: 4px; }
.fac-num { text-align: right; border: 2px solid #0b6fa4; border-radius: 10px; padding: 10px 14px; }
.fac-titulo { font-weight: 800; color: #0a5a8a; font-size: 15px; }
.fac-n { font-size: 20px; font-weight: 800; color: #c62828; margin: 2px 0; }
.fac-anulada { color: #c62828; font-weight: 800; border: 2px solid #c62828; text-align: center; margin-top: 4px; }
.fac-cli { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 20px; background: #f3f7fb; border: 1px solid #d6dee8; border-radius: 8px; padding: 10px 14px; margin: 14px 0; }
.fac-tabla th { background: #0b6fa4; color: #fff; text-transform: none; letter-spacing: 0; font-size: 12px; border: 0; }
.fac-tabla td { border-bottom: 1px solid #e3e9f0; }
.fac-tabla tr:nth-child(even) td { background: #f8fafc; }
.fac-tot { display: grid; grid-template-columns: 1fr 300px; gap: 20px; margin-top: 12px; }
.fac-tot table td { padding: 5px 8px; border: 0; }
.fac-total td { font-size: 17px; font-weight: 800; color: #fff; background: #0a5a8a; }
.fac-firmas { display: grid; grid-template-columns: 1fr 1fr; gap: 60px; margin-top: 50px; }
.fac-firmas div { border-top: 1px solid #333; text-align: center; padding-top: 4px; font-size: 12px; color: #555; }
.fac-pie { margin-top: 18px; text-align: center; font-size: 11px; color: #5b6b7c; border-top: 1px dashed #c8d2de; padding-top: 8px; }

/* Barras simples para reportes */
.barra-h { height: 10px; background: var(--azul2); border-radius: 5px; min-width: 2px; }

/* Ticket (vista previa y la impresión de 80 mm) */
.ticket { font-family: "Consolas", "Courier New", monospace; font-size: 12px; width: 300px; margin: 0 auto; color: #000; background: #fff;
  padding: 12px; border: 1px dashed #bbb; }
.ticket .c { text-align: center; } .ticket .r { text-align: right; }
.ticket hr { border: 0; border-top: 1px dashed #000; margin: 6px 0; }
.ticket table { font-size: 12px; } .ticket td { padding: 1px 0; border: 0; } .ticket tr:hover td { background: none; }
.ticket .grande { font-size: 15px; font-weight: 700; }
.ticket-impresion { display: none; }

@media print {
  body { background: #fff; }
  body > *:not(.ticket-impresion) { display: none !important; }
  .ticket-impresion { display: block !important; }
  .ticket-impresion .ticket { border: 0; width: 72mm; padding: 0; }
  @page { size: 80mm auto; margin: 3mm; }
  .ticket-impresion .factura { page: carta; max-width: none; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  @page carta { size: letter; margin: 12mm; }
}

@media (max-width: 960px) {
  .pos { grid-template-columns: 1fr; }
  .total-caja { position: static; }
  .marca span { display: none; }
}
@media (max-width: 600px) {
  main { padding: 10px; }
  .barra { padding: 0 8px; gap: 8px; }
  .usuario { max-width: 90px; overflow: hidden; text-overflow: ellipsis; }
}
