:root {
  --fondo: #f3f5f8; --panel: #ffffff; --borde: #e1e6ee; --texto: #1b2433; --tenue: #667085;
  --primario: #1f3a5f; --primario-2: #2b5a8f; --acento: #0e9f6e; --peligro: #d92d20; --alerta: #dc8a00;
  --menu: #14243b; --menu-texto: #c7d2e3; --radio: 10px; --sombra: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif; background: var(--fondo); color: var(--texto); font-size: 14px; }
.oculto { display: none !important; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 10px; text-transform: uppercase; letter-spacing: .04em; color: var(--tenue); }
.tenue { color: var(--tenue); }
.error { color: var(--peligro); white-space: pre-line; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.mono { font-family: Consolas, "Cascadia Mono", monospace; letter-spacing: .02em; }
a { color: var(--primario-2); }

/* acceso */
.acceso { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #14243b, #2b5a8f); padding: 16px; }
.acceso-caja { background: #fff; border-radius: 14px; padding: 28px; width: 100%; max-width: 380px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.marca-grande { font-size: 20px; font-weight: 700; margin-bottom: 18px; color: var(--primario); }

/* estructura */
#app { display: flex; min-height: 100vh; }
#menu { width: 232px; background: var(--menu); color: var(--menu-texto); display: flex; flex-direction: column; position: fixed; inset: 0 auto 0 0; z-index: 30; overflow-y: auto; }
.marca { padding: 18px 18px 14px; font-weight: 700; color: #fff; font-size: 16px; display: flex; gap: 8px; align-items: center; }
.logo { color: #4fb3ff; }
#menu nav { display: flex; flex-direction: column; padding: 0 8px; flex: 1; }
#menu nav a { color: var(--menu-texto); text-decoration: none; padding: 8px 10px; border-radius: 8px; display: flex; gap: 10px; align-items: center; }
#menu nav a i { font-style: normal; width: 18px; text-align: center; opacity: .8; }
#menu nav a:hover { background: rgba(255,255,255,.07); color: #fff; }
#menu nav a.activo { background: #2b5a8f; color: #fff; }
#menu .grupo { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; opacity: .5; padding: 14px 10px 4px; }
.pie-menu { padding: 14px 18px; border-top: 1px solid rgba(255,255,255,.08); font-size: 13px; }
.pie-menu .btn.enlace { color: #9ec5ff; padding: 4px 0; }
#cuerpo { margin-left: 232px; flex: 1; min-width: 0; display: flex; flex-direction: column; }
#barra { position: sticky; top: 0; z-index: 20; background: var(--panel); border-bottom: 1px solid var(--borde); padding: 10px 20px; display: flex; gap: 12px; align-items: center; }
#busqueda-global { flex: 1; max-width: 560px; }
#busqueda-global input { width: 100%; padding: 9px 12px; border-radius: 8px; border: 1px solid var(--borde); background: var(--fondo); font-size: 14px; }
#indicador-lector { font-size: 12px; color: var(--acento); white-space: nowrap; }
#indicador-lector.leyendo { color: #fff; background: var(--acento); border-radius: 6px; padding: 2px 8px; }
#btn-menu { display: none; }
main#vista { padding: 22px; max-width: 1400px; width: 100%; }
.encabezado { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }

/* componentes */
.panel { background: var(--panel); border: 1px solid var(--borde); border-radius: var(--radio); padding: 16px; box-shadow: var(--sombra); margin-bottom: 16px; }
.rejilla { display: grid; gap: 16px; }
.r2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.r3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.r4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.r-venta { grid-template-columns: minmax(0, 1.6fr) minmax(300px, 1fr); }
.kpi { background: var(--panel); border: 1px solid var(--borde); border-radius: var(--radio); padding: 14px 16px; box-shadow: var(--sombra); }
.kpi .t { font-size: 12px; color: var(--tenue); text-transform: uppercase; letter-spacing: .04em; }
.kpi .v { font-size: 24px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .s { font-size: 12px; color: var(--tenue); margin-top: 2px; }
.kpi.verde .v { color: var(--acento); }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--tenue); font-weight: 600; margin-bottom: 10px; }
input, select, textarea { font: inherit; color: var(--texto); padding: 8px 10px; border: 1px solid #cfd6e1; border-radius: 8px; background: #fff; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9ec5ff; border-color: var(--primario-2); }
.campos { display: grid; gap: 0 12px; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.fila { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.fila.fin { justify-content: flex-end; }
.fila > label { margin-bottom: 0; }
.chequeo { flex-direction: row; align-items: center; gap: 6px; font-weight: 500; color: var(--texto); }
.btn { font: inherit; border: 1px solid #cfd6e1; background: #fff; color: var(--texto); padding: 8px 14px; border-radius: 8px; cursor: pointer; font-weight: 600; white-space: nowrap; }
.btn:hover { background: #f5f7fa; }
.btn.primario { background: var(--primario); border-color: var(--primario); color: #fff; }
.btn.primario:hover { background: var(--primario-2); }
.btn.verde { background: var(--acento); border-color: var(--acento); color: #fff; }
.btn.peligro { color: var(--peligro); border-color: #f3b8b3; }
.btn.grande { padding: 12px 20px; font-size: 16px; }
.btn.ancho { width: 100%; }
.btn.chico { padding: 4px 9px; font-size: 12px; }
.btn.enlace { background: none; border: none; padding: 0; color: var(--primario-2); }
.btn.icono { padding: 6px 10px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.escaner { position: relative; }
.escaner input { width: 100%; font-size: 20px; padding: 14px 16px 14px 46px; border: 2px solid var(--primario-2); border-radius: 10px; font-family: Consolas, monospace; letter-spacing: .04em; }
.escaner::before { content: "▥"; position: absolute; left: 16px; top: 50%; transform: translateY(-50%); font-size: 20px; color: var(--primario-2); }
.escaner.ok input { border-color: var(--acento); background: #ecfdf3; }
.escaner.mal input { border-color: var(--peligro); background: #fef3f2; }
.mensaje-escaner { min-height: 22px; margin-top: 6px; font-weight: 600; white-space: pre-line; }
.mensaje-escaner.ok { color: var(--acento); }
.mensaje-escaner.mal { color: var(--peligro); }
.mensaje-escaner.alerta { color: var(--alerta); }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; color: var(--tenue); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; padding: 8px; border-bottom: 1px solid var(--borde); background: #f8fafc; position: sticky; top: 0; }
td { padding: 8px; border-bottom: 1px solid #eef1f5; vertical-align: middle; }
tr.clic { cursor: pointer; }
tr.clic:hover td { background: #f5f9ff; }
tfoot td { font-weight: 700; border-top: 2px solid var(--borde); }
.tabla-scroll { overflow: auto; max-height: 65vh; border: 1px solid var(--borde); border-radius: 8px; }
.tabla-scroll table th { z-index: 1; }
td input.precio { width: 120px; text-align: right; }
.tabla-ancha { overflow-x: auto; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.e-disponible { background: #dcfae6; color: #067647; }
.e-vendido { background: #e0eaff; color: #2b4ea2; }
.e-prestamo { background: #fef0c7; color: #93370d; }
.e-garantia { background: #fce7f6; color: #9e165f; }
.e-devuelto_proveedor, .e-baja { background: #f2f4f7; color: #475467; }
.e-anulada { background: #fee4e2; color: #b42318; }
.e-activa { background: #dcfae6; color: #067647; }
.e-pendiente { background: #fef0c7; color: #93370d; }

.alertas { display: flex; flex-direction: column; gap: 8px; }
.alerta { padding: 10px 12px; border-radius: 8px; background: #fffaeb; border: 1px solid #fedf89; color: #93370d; display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.alerta.info { background: #eff8ff; border-color: #b2ddff; color: #175cd3; }
.alerta.mal { background: #fef3f2; border-color: #fecdca; color: #b42318; }

.total-grande { font-size: 30px; font-weight: 800; text-align: right; font-variant-numeric: tabular-nums; }
.linea-total { display: flex; justify-content: space-between; padding: 4px 0; }
.tarjeta-unidad { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px 18px; }
.tarjeta-unidad div b { display: block; font-size: 11px; color: var(--tenue); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 2px; }
.linea-tiempo { list-style: none; padding: 0; margin: 0; border-left: 2px solid var(--borde); margin-left: 6px; }
.linea-tiempo li { padding: 0 0 12px 16px; position: relative; }
.linea-tiempo li::before { content: ""; position: absolute; left: -7px; top: 4px; width: 12px; height: 12px; border-radius: 50%; background: var(--primario-2); border: 2px solid #fff; }
.linea-tiempo .f { font-size: 12px; color: var(--tenue); }
.vacio { text-align: center; color: var(--tenue); padding: 30px 10px; }
.pestanas { display: flex; gap: 4px; border-bottom: 1px solid var(--borde); margin-bottom: 14px; flex-wrap: wrap; }
.pestanas button { background: none; border: none; padding: 9px 14px; font: inherit; font-weight: 600; color: var(--tenue); cursor: pointer; border-bottom: 2px solid transparent; }
.pestanas button.activo { color: var(--primario); border-bottom-color: var(--primario); }

.grafico svg { width: 100%; height: 200px; display: block; }
.grafico .barra { fill: #2b5a8f; }
.grafico .barra:hover { fill: #0e9f6e; }

.conteo-semaforo { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 12px 0; }
.conteo-semaforo div { border-radius: 10px; padding: 12px; text-align: center; font-weight: 700; font-size: 26px; }
.conteo-semaforo span { display: block; font-size: 12px; font-weight: 600; opacity: .8; }
.s-esp { background: #f2f4f7; } .s-ok { background: #dcfae6; color: #067647; } .s-falta { background: #fee4e2; color: #b42318; } .s-sobra { background: #fef0c7; color: #93370d; }
.destello-ok { animation: dok .6s; } .destello-mal { animation: dmal .6s; }
@keyframes dok { 0% { box-shadow: 0 0 0 6px rgba(14,159,110,.5); } 100% { box-shadow: none; } }
@keyframes dmal { 0% { box-shadow: 0 0 0 6px rgba(217,45,32,.5); } 100% { box-shadow: none; } }

/* modal y avisos */
.modal { position: fixed; inset: 0; background: rgba(16,24,40,.55); z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; }
.modal-caja { background: #fff; border-radius: 14px; width: 100%; max-width: 860px; padding: 22px; position: relative; box-shadow: 0 25px 60px rgba(0,0,0,.3); }
.modal-cerrar { position: absolute; right: 14px; top: 12px; border: none; background: none; font-size: 18px; cursor: pointer; color: var(--tenue); }
#avisos { position: fixed; right: 18px; bottom: 18px; z-index: 200; display: flex; flex-direction: column; gap: 8px; max-width: 420px; }
.aviso { background: #1b2433; color: #fff; padding: 12px 16px; border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.25); white-space: pre-line; animation: entra .2s; }
.aviso.ok { background: #067647; } .aviso.mal { background: #b42318; }
@keyframes entra { from { transform: translateY(10px); opacity: 0; } }

/* recibo */
.recibo { max-width: 360px; margin: 0 auto; font-size: 13px; color: #000; }
.recibo h2 { text-align: center; margin: 0; }
.recibo .centro { text-align: center; }
.recibo table td, .recibo table th { padding: 4px 2px; border-bottom: 1px dashed #bbb; background: none; position: static; }
.recibo .total { font-size: 18px; font-weight: 800; text-align: right; margin-top: 8px; }
#zona-impresion { display: none; }
@media print {
  body > *:not(#zona-impresion) { display: none !important; }
  #zona-impresion { display: block !important; }
  @page { margin: 8mm; }
}

@media (max-width: 1250px) {
  .r-venta { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 1000px) {
  .r4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .r3, .r2 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 760px) {
  #menu { transform: translateX(-100%); transition: transform .2s; }
  #menu.abierto { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.4); }
  #cuerpo { margin-left: 0; }
  #btn-menu { display: inline-block; }
  #indicador-lector { display: none; }
  main#vista { padding: 14px; }
  .r4 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .kpi .v { font-size: 19px; }
  .conteo-semaforo { grid-template-columns: repeat(2, 1fr); }
  .ocultar-movil { display: none; }
  .modal { padding: 0; }
  .modal-caja { border-radius: 0; min-height: 100vh; }
}

/* ---------- lector con cámara ---------- */
.escaner { display: flex; gap: 8px; align-items: stretch; }
.escaner input { flex: 1; min-width: 0; }
.btn-camara { white-space: nowrap; font-size: 15px; padding: 0 14px; }
#btn-camara-global { font-size: 18px; }
.camara-capa { position: fixed; inset: 0; z-index: 300; background: rgba(0,0,0,.85); display: flex; align-items: center; justify-content: center; padding: 10px; }
.camara-caja { background: #fff; border-radius: 12px; width: min(720px, 100%); max-height: 100%; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.camara-cabeza { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.camara-video { position: relative; background: #000; border-radius: 8px; overflow: hidden; aspect-ratio: 16 / 9; }
.camara-video video { width: 100%; height: 100%; object-fit: cover; display: block; }
.camara-guia { position: absolute; left: 7%; right: 7%; top: 36%; bottom: 36%; border: 3px solid rgba(255,255,255,.9); border-radius: 8px; box-shadow: 0 0 0 9999px rgba(0,0,0,.35); transition: border-color .15s; }
.camara-guia span { position: absolute; left: 4%; right: 4%; top: 50%; height: 2px; background: #ff3b30; opacity: .85; }
.camara-guia.detectando { border-color: #fdb022; }
.camara-guia.leido { border-color: #12b76a; box-shadow: 0 0 0 9999px rgba(18,183,106,.25); }
.camara-estado { font-size: 15px; min-height: 22px; }
.camara-estado.ok { color: var(--acento); font-weight: 600; }
.camara-estado.mal { color: var(--peligro); font-weight: 600; }
.camara-estado.alerta { color: var(--alerta); font-weight: 600; }
.camara-botones { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.camara-linterna.activo { background: #fdb022; border-color: #fdb022; }
.camara-lista { margin: 0; padding-left: 22px; max-height: 30vh; overflow-y: auto; font-family: Consolas, monospace; font-size: 14px; }
.camara-lista li.ok { color: var(--acento); }
.camara-lista li.mal { color: var(--peligro); }
.camara-lista small { font-family: system-ui, sans-serif; }
@media (max-width: 700px) {
  .camara-capa { padding: 0; }
  .camara-caja { border-radius: 0; height: 100%; }
  .camara-video { aspect-ratio: 3 / 4; }
  .camara-guia { top: 40%; bottom: 40%; left: 4%; right: 4%; }
}

/* ---------- garantías ---------- */
.gar { display: inline-block; border-radius: 6px; padding: 1px 8px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.gar-vigente { background: #ecfdf3; color: #067647; }
.gar-porvencer { background: #fffaeb; color: #b54708; }
.gar-vencida { background: #fef3f2; color: #b42318; }
.gar-sin { background: #f2f4f7; color: #475467; }
select.garantia { min-width: 110px; }
