/* ===== Sistema Bodega · estilos ===== */
:root {
  --bg: #f5f3ee;
  --panel: #ffffff;
  --texto: #1f2421;
  --muted: #6b716c;
  --borde: #e3e0d8;
  --primario: #1f6f4a;
  --primario-2: #185a3c;
  --primario-suave: #e4f1ea;
  --acento: #e8a33a;
  --rojo: #c0392b;
  --rojo-suave: #fbe9e7;
  --ambar-suave: #fdf3e1;
  --azul: #2c6db3;
  --azul-suave: #e7f0fa;
  --sidebar: #17211c;
  --sidebar-txt: #c9d3cd;
  --radio: 10px;
  --sombra: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  background: var(--bg); color: var(--texto); font-size: 15px; line-height: 1.45;
}
a { color: var(--primario); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .5em; line-height: 1.2; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.num, td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.mono { font-family: var(--mono); }
.verde { color: var(--primario); }
.rojo { color: var(--rojo); }
.ambar { color: #a86b0c; }
.fw { font-weight: 600; }
.nowrap { white-space: nowrap; }

/* ----- Estructura ----- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px; flex-shrink: 0; background: var(--sidebar); color: var(--sidebar-txt);
  position: sticky; top: 0; height: 100vh; overflow-y: auto; padding-bottom: 24px;
}
.marca { display: flex; gap: 10px; align-items: center; padding: 18px 16px; border-bottom: 1px solid rgba(255,255,255,.08); }
.marca-logo { font-size: 28px; }
.marca strong { display: block; color: #fff; font-size: 1rem; }
.marca small { color: #8fa197; font-size: .78rem; }
.menu { display: flex; flex-direction: column; padding: 10px 8px; }
.menu a, .menu-salir {
  color: var(--sidebar-txt); padding: 8px 12px; border-radius: 8px; font-size: .92rem; display: flex;
  justify-content: space-between; align-items: center; text-decoration: none;
}
.menu a:hover, .menu-salir:hover { background: rgba(255,255,255,.06); color: #fff; }
.menu a.activo { background: rgba(255,255,255,.1); color: #fff; font-weight: 600; }
.menu a.vender { background: var(--primario); color: #fff; font-weight: 700; margin-bottom: 8px; justify-content: center; }
.menu a.vender:hover, .menu a.vender.activo { background: #24845a; }
.menu-titulo { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: #6e8076; padding: 14px 12px 4px; }
.menu-salir { background: none; border: 0; width: 100%; text-align: left; cursor: pointer; font: inherit; }
.badge-alerta { background: var(--acento); color: #2a1c00; font-size: .72rem; font-weight: 700; border-radius: 10px; padding: 1px 7px; }

.contenido { flex: 1; min-width: 0; padding: 0 24px 40px; }
.barra { display: flex; align-items: center; gap: 12px; padding: 18px 0 14px; }
.barra h1 { font-size: 1.35rem; margin: 0; flex: 1; }
.btn-menu { display: none; background: none; border: 1px solid var(--borde); border-radius: 8px; font-size: 20px; padding: 4px 10px; cursor: pointer; }
.barra .btn-vender-top { display: none; }
.velo { display: none; }

@media (max-width: 900px) {
  .sidebar { position: fixed; left: -260px; z-index: 50; transition: left .2s; }
  .sidebar.abierto { left: 0; }
  .velo.visible { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 40; }
  .btn-menu { display: inline-block; }
  .barra .btn-vender-top { display: inline-flex; }
  .contenido { padding: 0 14px 40px; }
}

/* ----- Paneles ----- */
.panel { background: var(--panel); border: 1px solid var(--borde); border-radius: var(--radio); box-shadow: var(--sombra); padding: 16px; margin-bottom: 16px; }
.panel-cab { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.panel-cab h2 { margin: 0; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-2-1 { grid-template-columns: 2fr 1fr; }
@media (max-width: 900px) { .g2, .g3, .g-2-1 { grid-template-columns: minmax(0, 1fr); } }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--borde); border-radius: var(--radio); padding: 14px 16px; box-shadow: var(--sombra); }
.kpi .lbl { font-size: .8rem; color: var(--muted); }
.kpi .val { font-size: 1.45rem; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }
.kpi .sub { font-size: .8rem; color: var(--muted); margin-top: 2px; }
.kpi.verde { border-left: 4px solid var(--primario); }
.kpi.ambar { border-left: 4px solid var(--acento); }
.kpi.rojo { border-left: 4px solid var(--rojo); }
.kpi.azul { border-left: 4px solid var(--azul); }

/* ----- Tablas ----- */
.tabla-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { text-align: left; font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 2px solid var(--borde); white-space: nowrap; }
td { padding: 8px 10px; border-bottom: 1px solid var(--borde); vertical-align: middle; }
tr:hover td { background: #faf9f6; }
tr.anulado td { color: #9aa09c; text-decoration: line-through; }
tr.anulado td.no-tachar { text-decoration: none; }
tfoot td { font-weight: 700; border-top: 2px solid var(--borde); border-bottom: 0; }
.vacio { text-align: center; color: var(--muted); padding: 28px 10px; }

/* ----- Etiquetas ----- */
.tag { display: inline-block; font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 20px; background: #eee; color: #444; white-space: nowrap; }
.tag-verde { background: var(--primario-suave); color: var(--primario-2); }
.tag-rojo { background: var(--rojo-suave); color: var(--rojo); }
.tag-ambar { background: var(--ambar-suave); color: #8a5a08; }
.tag-azul { background: var(--azul-suave); color: var(--azul); }
.tag-gris { background: #ecebe7; color: #6b716c; }

/* ----- Formularios ----- */
label { display: block; font-size: .85rem; font-weight: 600; color: #3d433f; margin-bottom: 12px; }
label .ayuda { font-weight: 400; color: var(--muted); font-size: .78rem; display: block; margin-top: 3px; }
input, select, textarea {
  display: block; width: 100%; margin-top: 4px; font: inherit; font-weight: 400; color: var(--texto);
  padding: 9px 11px; border: 1px solid #cfcbc1; border-radius: 8px; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(31,111,74,.25); border-color: var(--primario); }
input[type=checkbox], input[type=radio] { display: inline-block; width: auto; margin: 0 6px 0 0; vertical-align: middle; }
.check { display: flex; align-items: center; font-weight: 500; }
.fila-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0 14px; }
.filtros { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin-bottom: 14px; }
.filtros label { margin: 0; min-width: 130px; }
.filtros .crece { flex: 1; min-width: 180px; }
.input-grupo { display: flex; align-items: stretch; margin-top: 4px; }
.input-grupo input { margin-top: 0; border-radius: 8px 0 0 8px; }
.input-grupo span { background: #f0eee8; border: 1px solid #cfcbc1; border-left: 0; padding: 0 10px; display: flex; align-items: center; border-radius: 0 8px 8px 0; color: var(--muted); font-size: .85rem; }

/* ----- Botones ----- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600; font-size: .9rem;
  padding: 9px 14px; border-radius: 8px; border: 1px solid #cfcbc1; background: #fff; color: var(--texto); cursor: pointer;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { background: #f6f5f1; text-decoration: none; }
.btn-primario { background: var(--primario); border-color: var(--primario); color: #fff; }
.btn-primario:hover { background: var(--primario-2); }
.btn-peligro { color: var(--rojo); border-color: #e7b6b0; }
.btn-peligro:hover { background: var(--rojo-suave); }
.btn-chico { padding: 5px 10px; font-size: .82rem; }
.btn-bloque { width: 100%; }
.btn-grande { padding: 14px 18px; font-size: 1.05rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.acciones { display: flex; gap: 8px; flex-wrap: wrap; }

/* ----- Alertas ----- */
.alerta { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; font-size: .92rem; }
.alerta-ok { background: var(--primario-suave); color: var(--primario-2); border: 1px solid #c3e1d1; }
.alerta-error { background: var(--rojo-suave); color: #8e2a1f; border: 1px solid #f1c6bf; }
.alerta-info { background: var(--azul-suave); color: #1f4f82; border: 1px solid #c8dcf1; }
.alerta-ambar { background: var(--ambar-suave); color: #7a4f05; border: 1px solid #f2dcb0; }

/* ----- Barras (gráficos simples sin librerías) ----- */
.barras { display: flex; align-items: flex-end; gap: 4px; height: 160px; padding-top: 10px; }
.barras .col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; min-width: 0; }
.barras .b { width: 100%; max-width: 34px; background: var(--primario); border-radius: 4px 4px 0 0; min-height: 2px; position: relative; }
.barras .b.utl { background: var(--acento); }
.barras .col small { font-size: .68rem; color: var(--muted); margin-top: 4px; white-space: nowrap; }
.barras .col:hover .b { opacity: .8; }
.barra-h { background: #eceae4; border-radius: 6px; height: 8px; overflow: hidden; min-width: 60px; }
.barra-h span { display: block; height: 100%; background: var(--primario); border-radius: 6px; }
.leyenda { display: flex; gap: 14px; font-size: .78rem; color: var(--muted); }
.leyenda i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }

/* ----- Punto de venta ----- */
.pos { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 16px; align-items: start; }
@media (max-width: 1000px) { .pos { grid-template-columns: minmax(0, 1fr); } }
.buscador { position: relative; }
.buscador input { font-size: 1.1rem; padding: 13px 14px; }
.resultados { position: absolute; z-index: 20; left: 0; right: 0; top: 100%; background: #fff; border: 1px solid var(--borde); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.12); max-height: 380px; overflow-y: auto; margin-top: 4px; }
.resultados .item { padding: 10px 12px; display: flex; justify-content: space-between; gap: 10px; cursor: pointer; border-bottom: 1px solid #f1efe9; }
.resultados .item:hover, .resultados .item.sel { background: var(--primario-suave); }
.resultados .item small { color: var(--muted); }
.carrito td { padding: 7px 6px; }
.carrito input.cant { width: 82px; padding: 6px 8px; text-align: right; margin: 0; }
.carrito input.precio { width: 84px; padding: 6px 8px; text-align: right; margin: 0; }
.carrito select { padding: 5px 6px; margin: 0; width: auto; font-size: .82rem; }
.quitar { background: none; border: 0; color: var(--rojo); font-size: 18px; cursor: pointer; padding: 0 6px; }
.total-pos { font-size: 2.1rem; font-weight: 800; text-align: right; font-variant-numeric: tabular-nums; }
.tipo-venta { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 12px; }
.tipo-venta input { display: none; }
.tipo-venta label { margin: 0; text-align: center; border: 1px solid #cfcbc1; border-radius: 8px; padding: 10px; cursor: pointer; font-weight: 700; }
.tipo-venta input:checked + span { color: #fff; }
.tipo-venta label:has(input:checked) { background: var(--primario); border-color: var(--primario); color: #fff; }
.tipo-venta label.credito:has(input:checked) { background: var(--acento); border-color: var(--acento); color: #2a1c00; }
.metodos { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 12px; }
.metodos label { margin: 0; border: 1px solid #cfcbc1; border-radius: 20px; padding: 5px 12px; cursor: pointer; font-weight: 600; font-size: .82rem; }
.metodos input { display: none; }
.metodos label:has(input:checked) { background: var(--texto); color: #fff; border-color: var(--texto); }
.cliente-sel { background: var(--ambar-suave); border: 1px solid #f2dcb0; border-radius: 8px; padding: 8px 10px; display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 10px; }
.vuelto { font-size: 1.2rem; font-weight: 700; }

/* ----- Modal ----- */
.modal-fondo { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: none; align-items: center; justify-content: center; z-index: 100; padding: 16px; }
.modal-fondo.visible { display: flex; }
.modal { background: #fff; border-radius: 12px; padding: 20px; width: 100%; max-width: 460px; max-height: 92vh; overflow-y: auto; }
.modal h2 { margin-bottom: 14px; }

/* ----- Ficha / definición ----- */
.ficha { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: .92rem; }
.ficha dt { color: var(--muted); }
.ficha dd { margin: 0; font-weight: 600; }

.calc-precio { background: var(--primario-suave); border-radius: 8px; padding: 12px; margin-bottom: 12px; font-size: .9rem; }
.calc-precio strong { font-size: 1.15rem; }

/* ----- Login ----- */
.login-body { display: flex; min-height: 100vh; align-items: center; justify-content: center; background: var(--sidebar); padding: 16px; }
.login-card { background: #fff; border-radius: 14px; padding: 30px 26px; width: 100%; max-width: 360px; text-align: center; }
.login-card label { text-align: left; }
.login-logo { font-size: 46px; }
.login-card h1 { font-size: 1.3rem; margin: 6px 0 2px; }
.login-card p { margin: 0 0 18px; }

/* ----- Ticket / impresión ----- */
.ticket { width: 76mm; margin: 0 auto; font-family: var(--mono); font-size: 12px; color: #000; padding: 6px; }
.ticket h1 { font-size: 15px; text-align: center; margin: 0; }
.ticket .c { text-align: center; }
.ticket table { font-size: 12px; }
.ticket td, .ticket th { padding: 2px 0; border: 0; }
.ticket hr { border: 0; border-top: 1px dashed #000; margin: 6px 0; }
.solo-impresion { display: none; }
@media print {
  .no-print, .sidebar, .barra, .velo, .filtros, .btn { display: none !important; }
  .solo-impresion { display: block; }
  body { background: #fff; }
  .contenido { padding: 0; }
  .panel { box-shadow: none; border: 0; padding: 0; }
  @page { margin: 8mm; }
}

/* ----- Escáner con cámara ----- */
.escaner-modal { max-width: 520px; }
.escaner-video { width: 100%; min-height: 220px; background: #111; border-radius: 10px; overflow: hidden; }
.escaner-video video { width: 100% !important; display: block; }
.escaner-estado { text-align: center; margin-top: 8px; font-weight: 600; font-size: .95rem; min-height: 1.4em; }
.escaner-estado.bien { color: var(--primario); }
.escaner-estado.mal { color: var(--rojo); }
.btn-cam { font-size: 1.15rem; padding: 0 14px; }
.con-cam { display: flex; gap: 6px; align-items: stretch; }
.con-cam input { flex: 1; min-width: 0; }
.con-cam .btn { margin-top: 4px; }

/* ----- Toma de inventario ----- */
.conteo-top { position: sticky; top: 0; z-index: 10; background: var(--bg); padding-bottom: 6px; }
.conteo-ultimo { background: var(--primario-suave); border: 1px solid #c3e1d1; border-radius: 10px; padding: 12px 14px; display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; }
.conteo-ultimo .n { font-size: 1.8rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.dif-mas { color: var(--azul); font-weight: 700; }
.dif-menos { color: var(--rojo); font-weight: 700; }
.input-conteo { width: 90px; text-align: right; padding: 6px 8px; margin: 0; }
.progreso { height: 8px; background: #e6e3db; border-radius: 6px; overflow: hidden; }
.progreso span { display: block; height: 100%; background: var(--primario); }
