/* Sistema de Ventas - estilos (mobile first) */
:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #16202a;
  --muted: #5b6b7a;
  --line: #dde3ea;
  --brand: #0f766e;
  --brand-dark: #0b5a54;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --err: #b91c1c;
  --err-bg: #fee2e2;
  --ok: #166534;
  --ok-bg: #dcfce7;
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1418;
    --card: #182028;
    --text: #e7edf3;
    --muted: #98a6b4;
    --line: #2a3541;
    --brand: #14b8a6;
    --brand-dark: #0d9488;
    --warn: #fbbf24;
    --warn-bg: #3a2c0a;
    --err: #fca5a5;
    --err-bg: #3b1414;
    --ok: #86efac;
    --ok-bg: #0f2e1a;
  }
}

* { box-sizing: border-box; }

/* El atributo hidden tiene que ganarle a cualquier display de las clases (ej: .btn, .paybar) */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
}
body.login { padding-bottom: 0; display: grid; min-height: 100vh; align-items: center; }

h1 { font-size: 1.4rem; margin: .2rem 0 1rem; }
a { color: var(--brand); }
small { color: var(--muted); }

.container { max-width: 760px; margin: 0 auto; padding: 16px; }
.container--narrow { max-width: 420px; }

/* ---------- barra superior y navegación inferior ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--brand); color: #fff;
}
.topbar__brand { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.topbar__brand strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar__brand small { color: rgba(255,255,255,.8); }
.topbar .btn--ghost { color: #fff; border-color: rgba(255,255,255,.5); }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 4px; font-size: .78rem; text-decoration: none; color: var(--muted);
}
.tabbar a span { font-size: 1.3rem; line-height: 1; }
.tabbar a.is-active { color: var(--brand); font-weight: 600; }

/* ---------- componentes ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.center { text-align: center; }

.btn {
  display: inline-block; border: 1px solid var(--brand); background: var(--brand); color: #fff;
  padding: 12px 18px; border-radius: 10px; font: inherit; font-weight: 600; text-decoration: none;
  cursor: pointer; min-height: 44px; text-align: center;
}
.btn:hover { background: var(--brand-dark); }
.btn--ghost { background: transparent; color: var(--brand); }
.btn--ghost:hover { background: rgba(15,118,110,.08); }
.btn--block { display: block; width: 100%; }

.row { display: flex; align-items: center; gap: 8px; }
.row--between { justify-content: space-between; }
.row--wrap { flex-wrap: wrap; }
.row > input { flex: 1; min-width: 0; }

.alert { padding: 12px 14px; border-radius: 10px; margin-bottom: 12px; font-size: .95rem; }
.alert--ok    { background: var(--ok-bg);   color: var(--ok); }
.alert--error { background: var(--err-bg);  color: var(--err); }

/* ---------- formularios ---------- */
.field { display: block; margin-bottom: 14px; }
.field > span:first-child { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=email], input[type=password], input[type=search], select, textarea {
  width: 100%; padding: 12px; font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; min-height: 44px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
input:disabled { opacity: .6; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check { display: flex; align-items: center; gap: 10px; margin: 6px 0 14px; }
.check input { width: 22px; height: 22px; }
.hint { color: var(--muted); font-size: .85rem; margin: -6px 0 12px; }

.search { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 14px; }
.search input[type=search] { flex: 1; min-width: 0; }

/* ---------- escáner ---------- */
.scanner { margin-bottom: 14px; }
.scanner video { width: 100%; border-radius: var(--radius); background: #000; max-height: 50vh; object-fit: cover; }

/* ---------- lista de productos ---------- */
.list { list-style: none; padding: 0; margin: 0 0 16px; }
.item {
  display: flex; justify-content: space-between; gap: 12px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 8px;
}
.item--off { opacity: .55; }
.item > .thumb, .results .thumb, .line__top > .thumb { flex: 0 0 48px; width: 48px; height: 48px; border-radius: 8px; object-fit: cover; background: var(--line); }
.thumb--vacia { display: flex; align-items: center; justify-content: center; font-weight: 700; color: var(--muted); }
.item > .item__main, .results .item__main, .line__top > .item__main { flex: 1 1 auto; }
.item__main, .item__side { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.item__main strong { overflow-wrap: anywhere; }
.item__side { text-align: right; align-items: flex-end; flex-shrink: 0; }
.warn { color: var(--warn); font-weight: 600; }
.tag { display: inline-block; align-self: flex-start; padding: 1px 8px; border-radius: 99px; background: var(--line); font-size: .72rem; }
.tag--web { background: var(--ok-bg); color: var(--ok); }
.pager { display: flex; justify-content: space-between; gap: 8px; }

/* ---------- inicio ---------- */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; }
.stat:first-child { grid-column: 1 / -1; }
.stat strong { font-size: 1.5rem; }
.stat--warn { background: var(--warn-bg); border-color: transparent; }
.stat--warn strong { color: var(--warn); }

/* ---------- tablas ---------- */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.table .cut { overflow-wrap: anywhere; min-width: 6rem; }   /* celdas con texto libre (nombres, errores): si no tienen espacios, se cortan en vez de ensanchar la tabla */
.table th { font-size: .8rem; color: var(--muted); font-weight: 600; }
.table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.table--totals .total td { font-size: 1.15rem; border-top: 2px solid var(--text); }
.card h2, h2 { font-size: 1.05rem; margin: 0 0 .6rem; }
.btn--off { opacity: .35; pointer-events: none; }
.pager--top { align-items: center; margin-bottom: 14px; }
input[type=date] { padding: 10px; font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; min-height: 44px; }

/* ---------- punto de venta ---------- */
.pos__search { display: flex; gap: 8px; margin-bottom: 10px; }
.pos__search input { flex: 1; }
.results .item { padding: 0; }
.results button {
  all: unset; box-sizing: border-box; display: flex; justify-content: space-between; gap: 12px;
  width: 100%; padding: 12px 14px; cursor: pointer;
}
.results button:focus-visible { outline: 2px solid var(--brand); border-radius: var(--radius); }
.line { flex-direction: column; gap: 10px; }
.line__top { display: flex; justify-content: space-between; gap: 12px; }
.line__ctrl { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.qty { display: flex; align-items: center; gap: 6px; }
.qty button {
  width: 44px; height: 44px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font-size: 1.3rem; cursor: pointer;
}
.qty input { width: 84px; text-align: center; padding: 10px 6px; }
.paybar-space { height: 84px; }
.paybar {
  position: fixed; left: 0; right: 0; bottom: calc(60px + env(safe-area-inset-bottom)); z-index: 9;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px; background: var(--card); border-top: 1px solid var(--line);
  box-shadow: 0 -4px 12px rgba(0, 0, 0, .08);
}
.paybar strong { font-size: 1.4rem; }
.paybar .btn { min-width: 140px; }

.modal { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, .55); display: flex; align-items: flex-end; justify-content: center; }
.modal__panel {
  background: var(--card); width: 100%; max-width: 520px; max-height: 94vh; overflow: auto;
  border-radius: 16px 16px 0 0; padding: 16px; padding-bottom: calc(16px + env(safe-area-inset-bottom));
}
.big { font-size: 1.6rem; font-weight: 700; }
.payrow { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; margin-bottom: 8px; align-items: center; }
.payrow__act { display: flex; gap: 6px; }
.payrow__note { grid-column: 1 / -1; margin: -2px 0 0; color: var(--muted); }
.payrow__act .btn { padding: 8px 12px; }
.status { font-weight: 600; margin: 12px 0; }
.status--ok { color: var(--ok); }
.status--bad { color: var(--warn); }

/* ---------- ticket ---------- */
.ticket { max-width: 420px; margin-inline: auto; margin-bottom: 16px; }
.ticket__meta { margin: 10px 0; }
details.card summary { cursor: pointer; font-weight: 600; }

@media print {
  .topbar, .tabbar, .noprint, .paybar { display: none !important; }
  body { background: #fff; color: #000; padding: 0; }
  .card { border: 0; padding: 0; }
  .ticket { max-width: 80mm; margin: 0; }
}

@media (min-width: 720px) {
  .paybar { bottom: 0; }
  .modal { align-items: center; }
  .modal__panel { border-radius: 16px; }
  .tabbar { position: static; border-top: 0; border-bottom: 1px solid var(--line); justify-content: center; }
  .tabbar a { flex: 0 0 auto; flex-direction: row; gap: 8px; padding: 12px 20px; font-size: .95rem; }
  body { padding-bottom: 0; }
}

/* Cliente en el punto de venta */
.clientbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 12px; }
.clientbar__act { display: flex; gap: 6px; }
.modal--top { z-index: 30; }
.modal__panel .results button { width: 100%; text-align: left; }

/* Menú "Más" */
.menu .item { padding: 0; }
.menu__link { display: flex; align-items: center; gap: 14px; width: 100%; padding: 14px 16px; text-decoration: none; color: inherit; min-height: 60px; }
.menu__icon { font-size: 1.6rem; width: 2rem; text-align: center; }

/* Fotos en el formulario de producto */
.fotos { list-style: none; display: flex; flex-wrap: wrap; gap: 10px; padding: 0; margin: 6px 0 10px; }
.fotos li { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.fotos img { width: 90px; height: 90px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }

/* ---- Reportes ---- */
.subtabs { display: flex; gap: 4px; margin: 4px 0 12px; border-bottom: 1px solid var(--line); }
.subtabs a { padding: 8px 14px; text-decoration: none; color: var(--muted); border-bottom: 3px solid transparent; font-weight: 600; }
.subtabs a[aria-current="page"] { color: var(--brand); border-bottom-color: var(--brand); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 8px; -webkit-overflow-scrolling: touch; }
.chip { flex: none; padding: 6px 12px; border: 1px solid var(--line); border-radius: 99px; text-decoration: none; color: var(--text); background: var(--card); font-size: .9rem; white-space: nowrap; }
.chip--on { background: var(--brand); border-color: var(--brand); color: #fff; }
.filtro { padding: 10px 14px; margin-bottom: 12px; }
.filtro summary { cursor: pointer; }
.filtro form { margin-top: 12px; }
.stats--rep .stat { min-width: 0; }
.stats--rep .stat strong { font-size: clamp(1.05rem, 5vw, 1.3rem); white-space: nowrap; }
.stats--rep .stat .big { font-size: clamp(1.4rem, 7vw, 1.8rem); }
.rank { display: inline-block; min-width: 1.4em; color: var(--muted); font-size: .8rem; }
.table tr.total td { border-top: 2px solid var(--text); }
.chart { margin: 0 0 16px; }
.chart figcaption { margin-bottom: 4px; }
.chart__read { min-height: 1.4em; margin: 0 0 8px; font-size: .9rem; color: var(--text); }
.chart__bars { display: flex; align-items: flex-end; gap: 2px; height: 150px; border-bottom: 1px solid var(--line); background: linear-gradient(var(--line) 1px, transparent 1px) 0 0 / 100% 50% repeat-y; }
.chart .bar { flex: 1 1 0; min-width: 6px; height: 100%; padding: 0; border: 0; background: transparent; position: relative; cursor: pointer; }
.chart .bar::after { content: ""; position: absolute; left: 12%; right: 12%; bottom: 0; height: var(--h); background: var(--brand); border-radius: 4px 4px 0 0; }
.chart .bar--vacia::after { height: 2px; background: var(--line); border-radius: 0; }
.chart .bar:hover::after, .chart .bar:focus-visible::after { filter: brightness(1.25); }
.chart .bar:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.chart__axis { display: flex; justify-content: space-between; font-size: .75rem; color: var(--muted); margin-top: 4px; }
.tabla-alt { margin-top: 12px; }
.tabla-alt summary { cursor: pointer; color: var(--brand); font-size: .9rem; }
