:root {
  --azul: #1f3a5f;
  --azul-2: #2b4f7e;
  --azul-claro: #e7eef7;
  --acento: #d97a1e;
  --fondo: #f3f4f6;
  --panel: #ffffff;
  --borde: #d5d9e0;
  --borde-2: #e6e9ee;
  --texto: #1d2430;
  --texto-2: #5b6575;
  --ok: #1f7a4d;
  --alerta: #b7791f;
  --error: #b42318;
  --fila-alt: #f8fafc;
  --fila-sel: #d6e4f5;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 13px;
  color: var(--texto);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--fondo); }
.hidden { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- Ingreso ---------- */
.login { height: 100%; display: grid; place-items: center; background: linear-gradient(160deg, var(--azul) 0%, #13263f 100%); padding: 16px; }
.login-card { width: 100%; max-width: 360px; background: var(--panel); border-radius: 8px; padding: 28px; display: grid; gap: 14px; box-shadow: 0 20px 50px rgba(0,0,0,.35); }
.login-marca { display: flex; gap: 12px; align-items: center; margin-bottom: 6px; }
.login-titulo { font-size: 18px; font-weight: 600; }
.login-sub { color: var(--texto-2); }
.login-pie { color: var(--texto-2); font-size: 11px; text-align: center; }
.logo { width: 44px; height: 44px; font-size: 22px; border-radius: 8px; background: var(--acento); color: #fff; font-weight: 700; display: grid; place-items: center; letter-spacing: .5px; }
.logo.chico { width: 26px; height: 26px; font-size: 14px; border-radius: 5px; }
label { display: grid; gap: 4px; color: var(--texto-2); font-size: 12px; }
input, select, textarea { border: 1px solid var(--borde); border-radius: 4px; padding: 6px 8px; background: #fff; color: var(--texto); min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9cc0ea; border-color: var(--azul-2); }
input[readonly] { background: var(--fondo); }
.error { color: var(--error); min-height: 16px; }

/* ---------- Estructura ---------- */
.app { height: 100%; display: grid; grid-template-columns: 220px 1fr; grid-template-rows: 40px 1fr 24px; grid-template-areas: "barra barra" "menu area" "estado estado"; }
.barra { grid-area: barra; background: var(--azul); color: #fff; display: flex; align-items: center; justify-content: space-between; padding: 0 12px; }
.barra-marca { display: flex; gap: 10px; align-items: center; font-weight: 600; }
.barra-der { display: flex; gap: 8px; align-items: center; }
.usuario-info { opacity: .85; margin: 0 6px; }
.btn-barra { background: transparent; border: 1px solid rgba(255,255,255,.3); color: #fff; border-radius: 4px; padding: 3px 10px; cursor: pointer; }
.btn-barra:hover { background: rgba(255,255,255,.12); }
.badge { background: var(--acento); border-radius: 9px; padding: 0 6px; font-size: 11px; margin-left: 4px; }

.menu { grid-area: menu; background: #fff; border-right: 1px solid var(--borde); overflow-y: auto; padding: 8px 0; }
.menu-grupo { display: flex; align-items: center; gap: 6px; width: 100%; border: 0; background: none; text-align: left; cursor: pointer;
  padding: 9px 14px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .6px; color: var(--texto-2); border-top: 1px solid var(--borde-2); }
.menu-bloque:first-child .menu-grupo { border-top: 0; }
.menu-grupo:hover { color: var(--azul); background: var(--azul-claro); }
.menu-grupo .flecha { display: inline-block; width: 10px; font-size: 10px; transition: transform .15s; }
.menu-bloque.abierto .menu-grupo .flecha { transform: rotate(90deg); }
.menu-bloque .menu-items { display: none; padding-bottom: 6px; }
.menu-bloque.abierto .menu-items { display: block; }
.menu-item { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 6px 14px 6px 22px; cursor: pointer; border-left: 3px solid transparent; }
.menu-item:hover { background: var(--azul-claro); }
.menu-item.activo { background: var(--azul-claro); border-left-color: var(--azul); font-weight: 600; }
.menu-item.proximo { color: #9aa3af; cursor: default; }
.menu-item.proximo::after { content: " · Etapa " attr(data-etapa); font-size: 10px; }
.menu-item.proximo:hover { background: none; }

.area { grid-area: area; display: grid; grid-template-rows: 32px 1fr; min-width: 0; min-height: 0; }
.pestanas { display: flex; gap: 2px; background: #e4e7ec; padding: 4px 6px 0; overflow-x: auto; border-bottom: 1px solid var(--borde); }
.pestana { display: flex; align-items: center; gap: 8px; padding: 0 6px 0 12px; background: #f1f3f6; border: 1px solid var(--borde); border-bottom: 0; border-radius: 5px 5px 0 0; cursor: pointer; white-space: nowrap; color: var(--texto-2); }
.pestana.activa { background: var(--panel); color: var(--texto); font-weight: 600; }
.pestana .x { border: 0; background: none; cursor: pointer; color: var(--texto-2); padding: 0 4px; border-radius: 3px; }
.pestana .x:hover { background: #dde2e8; }
.ventanas { position: relative; min-height: 0; background: var(--panel); }
.ventana { position: absolute; inset: 0; display: flex; flex-direction: column; min-height: 0; }

.estado { grid-area: estado; background: #e4e7ec; border-top: 1px solid var(--borde); display: flex; justify-content: space-between; align-items: center; padding: 0 12px; font-size: 11px; color: var(--texto-2); }

/* ---------- Barra de herramientas ---------- */
.herramientas { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 8px 10px; border-bottom: 1px solid var(--borde-2); }
.herramientas .titulo { font-size: 15px; font-weight: 600; margin-right: 12px; }
.herramientas .espacio { flex: 1; }
.herramientas input[type=search] { width: 240px; }
.btn { border: 1px solid var(--borde); background: #fff; border-radius: 4px; padding: 5px 12px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--azul-claro); border-color: #b9c7da; }
.btn.primario { background: var(--azul); border-color: var(--azul); color: #fff; }
.btn.primario:hover { background: var(--azul-2); }
.btn.peligro { color: var(--error); }
.btn:disabled { opacity: .5; cursor: default; }

/* ---------- Grilla ---------- */
.grilla-cont { flex: 1; overflow: auto; min-height: 0; }
table.grilla { border-collapse: separate; border-spacing: 0; width: 100%; }
.grilla th { position: sticky; top: 0; background: #eef1f5; text-align: left; font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--borde); border-right: 1px solid var(--borde-2); white-space: nowrap; cursor: pointer; user-select: none; z-index: 1; }
.grilla th.num, .grilla td.num { text-align: right; }
.grilla td { padding: 4px 8px; border-bottom: 1px solid var(--borde-2); white-space: nowrap; max-width: 360px; overflow: hidden; text-overflow: ellipsis; }
.grilla tbody tr:nth-child(even) td { background: var(--fila-alt); }
.grilla tbody tr:hover td { background: #edf3fa; }
.grilla tbody tr.sel td { background: var(--fila-sel); }
.grilla tr.inactivo td { color: #9aa3af; }
.grilla td.editable input { width: 120px; text-align: right; padding: 2px 6px; }
.pie-grilla { padding: 5px 10px; font-size: 11px; color: var(--texto-2); border-top: 1px solid var(--borde-2); }
.vacio { padding: 40px; text-align: center; color: var(--texto-2); }
.etiqueta { display: inline-block; padding: 0 7px; border-radius: 9px; font-size: 11px; font-weight: 600; background: #eef1f5; }
.etiqueta.ok { background: #e3f4ea; color: var(--ok); }
.etiqueta.alerta { background: #fdf3e1; color: var(--alerta); }
.etiqueta.error { background: #fde8e6; color: var(--error); }

/* ---------- Diálogos ---------- */
.modal-fondo { position: fixed; inset: 0; background: rgba(15, 25, 40, .4); z-index: 50; display: grid; place-items: center; padding: 16px; }
.dialogo { background: var(--panel); border-radius: 8px; box-shadow: 0 18px 50px rgba(0,0,0,.3); width: 100%; max-width: 720px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; }
.dialogo-cab { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px; background: var(--azul); color: #fff; border-radius: 8px 8px 0 0; font-weight: 600; }
.dialogo-cab button { background: none; border: 0; color: #fff; font-size: 18px; cursor: pointer; }
.dialogo-cuerpo { padding: 16px; overflow-y: auto; }
.dialogo-pie { display: flex; justify-content: flex-end; gap: 8px; padding: 10px 16px; border-top: 1px solid var(--borde-2); }
.campos { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.campos .ancho { grid-column: 1 / -1; }
.campos label.check { display: flex; align-items: center; gap: 8px; color: var(--texto); padding-top: 18px; }
.seccion { margin-top: 18px; }
.seccion h4 { margin: 0 0 8px; font-size: 13px; color: var(--azul); border-bottom: 1px solid var(--borde-2); padding-bottom: 4px; }
.ayuda { color: var(--texto-2); font-size: 11px; margin: 4px 0 0; }
.subtabla { width: 100%; border-collapse: collapse; }
.subtabla th { text-align: left; font-weight: 600; font-size: 11px; color: var(--texto-2); padding: 4px; }
.subtabla td { padding: 3px 4px; }
.subtabla input, .subtabla select { width: 100%; }
.leyenda { background: #fdf3e1; color: #7a4d0b; border: 1px solid #f0d49c; border-radius: 4px; padding: 8px 10px; margin-bottom: 12px; font-weight: 600; }

/* ---------- Inicio ---------- */
.inicio { padding: 20px; overflow-y: auto; }
.inicio h2 { margin: 0 0 4px; font-size: 20px; }
.inicio .sub { color: var(--texto-2); margin-bottom: 18px; }
.tarjetas { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; margin-bottom: 20px; }
.tarjeta { border: 1px solid var(--borde); border-radius: 8px; padding: 14px; background: #fff; cursor: pointer; }
.tarjeta:hover { border-color: var(--azul-2); }
.tarjeta .num { font-size: 24px; font-weight: 600; color: var(--azul); }
.tarjeta .lbl { color: var(--texto-2); }
.tarjeta.alerta .num { color: var(--acento); }

/* ---------- Avisos ---------- */
.avisos { position: fixed; right: 16px; bottom: 36px; display: grid; gap: 8px; z-index: 100; }
.aviso { background: #1d2430; color: #fff; padding: 10px 14px; border-radius: 6px; max-width: 380px; box-shadow: 0 8px 20px rgba(0,0,0,.25); }
.aviso.error { background: var(--error); }
.aviso.alerta { background: var(--alerta); }
.aviso.ok { background: var(--ok); }

@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 40px auto 1fr 24px; grid-template-areas: "barra" "menu" "area" "estado"; }
  .menu { max-height: 30vh; border-right: 0; border-bottom: 1px solid var(--borde); }
  .usuario-info, #estado-atajos { display: none; }
  .herramientas input[type=search] { width: 100%; }
}
.marca-nombre { font-weight: 700; letter-spacing: .3px; }
.marca-sep { opacity: .5; }
#empresa-nombre { font-weight: 400; opacity: .9; }

/* ---------- Importación ---------- */
.imp-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 24px; }
.imp-grid .subtabla td:first-child { color: var(--texto-2); }
@media (max-width: 900px) { .imp-grid { grid-template-columns: 1fr; } }

/* ---------- Carga de comprobantes de compra ---------- */
.compra { flex: 1; overflow: auto; padding: 14px 16px 24px; display: grid; gap: 16px; align-content: start; }
.compra-cab { display: grid; grid-template-columns: minmax(280px, 2.4fr) repeat(6, minmax(110px, 1fr)); gap: 12px; align-items: start; }
.compra-cab .campo-prov { grid-column: 1; }
.fila-input { display: flex; gap: 6px; }
.fila-input input { flex: 1; }
.prov-info { font-size: 11px; color: var(--texto-2); margin-top: 4px; min-height: 14px; }
.compra-items { border: 1px solid var(--borde); border-radius: 6px; overflow: visible; }
.grilla.items th { position: static; }
.grilla.items td { padding: 3px 4px; overflow: visible; max-width: none; }
.grilla.items input, .grilla.items select { width: 100%; padding: 4px 6px; }
.grilla.items input.num { text-align: right; }
.grilla.items tbody tr:nth-child(even) td, .grilla.items tbody tr:hover td { background: transparent; }
.items-pie { display: flex; gap: 8px; align-items: center; padding: 8px; border-top: 1px solid var(--borde-2); flex-wrap: wrap; }
.x-linea { border: 0; background: none; color: var(--texto-2); font-size: 18px; cursor: pointer; padding: 0 6px; border-radius: 4px; }
.x-linea:hover { background: #fde8e6; color: var(--error); }
.compra-pie { display: grid; grid-template-columns: 1fr 440px; gap: 24px; align-items: start; }
.totales { display: grid; gap: 6px; width: 100%; max-width: 440px; }
.tot-fila { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.tot-fila > input { width: 140px; text-align: right; }
.tot-fila.iva span { display: flex; gap: 6px; }
.tot-fila.iva select { width: 104px; }
.tot-fila.iva input[data-iv=base] { width: 120px; text-align: right; }
.tot-fila.total { border-top: 2px solid var(--azul); padding-top: 8px; margin-top: 4px; font-size: 16px; }
.tot-fila.total b { color: var(--azul); }
.tot-fila.nota span { color: var(--texto-2); font-size: 12px; }
.tot-fila.control span { color: var(--texto-2); font-size: 12px; }
.desc-otros { border-color: transparent; padding-left: 0; width: 200px; color: var(--texto); }
.desc-otros:hover, .desc-otros:focus { border-color: var(--borde); padding-left: 6px; }
.control-msg { text-align: right; font-size: 12px; min-height: 16px; }
.control-msg.ok { color: var(--ok); }
.control-msg.mal { color: var(--error); font-weight: 600; }
.btn.enlace { border: 0; background: none; color: var(--azul-2); padding: 2px 0; }
.btn.enlace:hover { text-decoration: underline; background: none; }
.sugerencias { position: fixed; z-index: 200; background: #fff; border: 1px solid var(--borde); border-radius: 6px; box-shadow: 0 10px 30px rgba(0,0,0,.18); max-height: 320px; overflow-y: auto; }
.sug { padding: 6px 10px; cursor: pointer; display: flex; justify-content: space-between; gap: 16px; white-space: nowrap; }
.sug.marcada, .sug:hover { background: var(--azul-claro); }
.sug.vacia { color: var(--texto-2); cursor: default; }
.sug-det { color: var(--texto-2); font-size: 11px; }
.detalle-cab { display: grid; grid-template-columns: 2fr repeat(4, 1fr); gap: 12px; }
.detalle-cab .lbl { font-size: 11px; color: var(--texto-2); }
.btn.peligro.primario, .dialogo-pie .btn.peligro { color: var(--error); }
@media (max-width: 1100px) {
  .compra-cab { grid-template-columns: repeat(3, 1fr); }
  .compra-cab .campo-prov { grid-column: 1 / -1; }
  .compra-pie { grid-template-columns: 1fr; }
}
.bulto-campo { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; color: var(--texto); font-size: 13px; }
.bulto-campo input { width: 90px; text-align: right; }
.bulto-campo .ayuda { flex-basis: 100%; margin: 0; }
.equiv { font-size: 11px; color: var(--ok); margin-top: 2px; min-height: 0; }
.equiv:empty { display: none; }
.sug.aviso-dup { color: var(--alerta); font-size: 11px; white-space: normal; border-top: 1px solid var(--borde-2); }
.similares { margin-top: 6px; padding: 8px 10px; border: 1px solid #f0d49c; background: #fdf3e1; border-radius: 4px; font-size: 12px; color: #7a4d0b; }
.similares ul { margin: 4px 0 0; padding-left: 18px; }
.similares.bloqueo { border-color: #f3b8b1; background: #fde8e6; color: #8a1c12; }

/* Artículos compuestos */
.agregar-comp { margin-bottom: 8px; }
.agregar-comp input { width: 100%; max-width: 560px; }

/* Ventas */
.check-in { display: flex; align-items: center; gap: 6px; color: var(--texto-2); }
.herramientas .sep { width: 1px; height: 22px; background: var(--borde); margin: 0 4px; }
.ayuda-barra { padding: 6px 10px; font-size: 11px; color: var(--texto-2); background: #f7f9fb; border-bottom: 1px solid var(--borde-2); }
.pedido-cab { display: grid; grid-template-columns: minmax(280px, 2fr) 170px minmax(160px, 1fr) auto; gap: 12px; align-items: end; }
.pedido-cab label.check { display: flex; align-items: center; gap: 8px; color: var(--texto); padding-bottom: 6px; }
.cliente-info { display: flex; flex-wrap: wrap; gap: 6px 18px; align-items: center; margin: 10px 0; padding: 8px 10px; background: #f4f7fb; border: 1px solid var(--borde-2); border-radius: 4px; font-size: 12px; }
.pedido-items { margin-top: 4px; }
.pedido-items td input, .pedido-items td select { width: 100%; }
.pedido-items input.modificado { background: #fff4dc; border-color: #e3b453; }
.pedido-pie { display: grid; grid-template-columns: 1fr 360px; gap: 18px; margin-top: 12px; align-items: start; }
.pedido-pie textarea { width: 100%; }
.desc-cli { width: 64px; text-align: right; padding: 1px 4px; }
.leyenda .motivos { font-weight: normal; font-size: 12px; margin-top: 4px; }
.rojo { color: var(--error); font-weight: 600; }
.btn.chico { padding: 1px 8px; font-size: 11px; }
.grilla tr.recibo td { color: #1d6b3f; }
.cobranza .subtabla input, .cobranza .subtabla select { width: 100%; }
@media (max-width: 900px) { .pedido-cab, .pedido-pie { grid-template-columns: 1fr; } }
.cobranza > label input { width: 100%; margin-top: 4px; }

/* Conteo de stock */
.verde { color: var(--ok); font-weight: 600; }
.grilla.conteo td.editable input { width: 84px; }
.grilla.conteo tr.contado td { background: #f2f8f3; }
.login-card label.recordar { display: flex; align-items: center; gap: 8px; color: var(--texto); font-size: 13px; }

/* Informes */
.informes { display: grid; grid-template-columns: 270px 1fr; height: 100%; min-height: 0; }
.inf-lista { border-right: 1px solid var(--borde); overflow-y: auto; padding: 8px; display: grid; align-content: start; gap: 4px; background: #f7f9fb; }
.inf-lista button { text-align: left; border: 1px solid transparent; background: none; border-radius: 6px; padding: 8px 10px; cursor: pointer; display: grid; gap: 2px; color: var(--texto); }
.inf-lista button span { font-size: 11px; color: var(--texto-2); }
.inf-lista button:hover { background: var(--azul-claro); }
.inf-lista button.activo { background: #fff; border-color: var(--borde); box-shadow: inset 3px 0 0 var(--azul); }
.inf-cuerpo { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.inf-params { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grilla tfoot td { position: sticky; bottom: 0; background: #eef1f5; border-top: 1px solid var(--borde); padding: 6px 8px; }

.relacionados { border: 1px solid var(--borde-2); border-radius: 6px; padding: 8px 10px; margin-bottom: 10px; background: #f7f9fc; }
.relacionados .rel-tit { display: flex; gap: 12px; align-items: baseline; flex-wrap: wrap; margin-bottom: 6px; }

/* Tesorería */
.tes-tarjetas { display: flex; gap: 12px; padding: 10px 12px 0; flex-wrap: wrap; }
.tes-tarjeta { border: 1px solid var(--borde); border-radius: 8px; padding: 10px 16px; background: #fff; min-width: 210px; }
.tes-tarjeta[data-ir] { cursor: pointer; }
.tes-tarjeta[data-ir]:hover { border-color: var(--azul-2); }
.tes-tarjeta .lbl { color: var(--texto-2); font-size: 12px; }
.tes-tarjeta .num { font-size: 22px; font-weight: 600; color: var(--azul); }
.tes-tarjeta.principal { border-color: var(--azul); background: #f2f6fb; }
.op-tit { margin: 12px 0 6px; font-size: 13px; color: var(--azul); }
.cierre-resumen { border: 1px solid var(--borde-2); border-radius: 6px; padding: 8px 12px; background: #f7f9fc; }

.op-medio { border: 1px solid var(--borde-2); border-radius: 6px; padding: 8px 10px; margin-bottom: 8px; }
.op-medio .op-sub { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.op-medio table.items input, .op-medio table.items select { width: 100%; }
.btn.adjuntar { display: inline-block; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Vista previa de lo que se imprime */
#vista-previa { position: fixed; inset: 0; z-index: 90; background: #525a66; display: flex; flex-direction: column; }
#vista-previa .vp-barra { display: flex; align-items: center; gap: 8px; padding: 8px 14px; background: #1f2d44; color: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.25); }
#vista-previa .vp-titulo { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 45vw; }
#vista-previa .vp-paginas { color: #b9c4d6; font-size: 12px; }
#vista-previa .vp-barra select { padding: 5px 8px; border-radius: 6px; border: 0; }
#vista-previa .vp-hojas { flex: 1; overflow: auto; display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 20px 24px; }
#vista-previa .vp-hoja { background: #fff; box-shadow: 0 4px 18px rgba(0,0,0,.35); flex: none; }
#vista-previa .vp-imagen { max-width: 100%; height: auto; }
#vista-previa .vp-cargando { color: #fff; margin-top: 40px; }
#vista-previa .vp-marco { width: 100%; flex: 1; border: 0; background: #fff; }
#vista-previa .vp-barra .espacio { flex: 1; }
#vista-previa .vp-barra .btn:not(.primario) { color: #1f2d44; background: #fff; }
