:root {
  --bg: #f5f6f4;
  --card: #ffffff;
  --text: #1c2120;
  --muted: #69716f;
  --line: #e3e6e3;
  --brand: #0f7a55;
  --brand-soft: #e4f3ec;
  --wa: #1fa855;
  --danger: #c0392b;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 14px rgba(0,0,0,.05);
  --radius: 14px;
  --err-bg: #fde8e6; --err-fg: #a8281b;
  --warn-bg: #fff8e1;
  --rol-admin-bg: #efe5ff; --rol-admin-fg: #6b3fc0;
  --rol-op-bg: #e6eefc; --rol-op-fg: #2d5bb8;
  color-scheme: light;
}
/* Tema: automático (según el equipo), o elegido a mano con <html data-theme="light|dark"> */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121514;
    --card: #1b1f1e;
    --text: #e9ecea;
    --muted: #9aa3a0;
    --line: #2b302e;
    --brand: #3cc48f;
    --brand-soft: #1d3329;
    --shadow: none;
    --err-bg: #3a1d1a; --err-fg: #ff9f94;
    --warn-bg: #3a3014;
    --rol-admin-bg: #2e2441; --rol-admin-fg: #c8a8ff;
    --rol-op-bg: #1d2a40; --rol-op-fg: #9cbcff;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121514;
  --card: #1b1f1e;
  --text: #e9ecea;
  --muted: #9aa3a0;
  --line: #2b302e;
  --brand: #3cc48f;
  --brand-soft: #1d3329;
  --shadow: none;
  --err-bg: #3a1d1a; --err-fg: #ff9f94;
  --warn-bg: #3a3014;
  --rol-admin-bg: #2e2441; --rol-admin-fg: #c8a8ff;
  --rol-op-bg: #1d2a40; --rol-op-fg: #9cbcff;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 80px;
}
button { font: inherit; cursor: pointer; color: inherit; }
input, textarea { font: inherit; color: inherit; }

/* ---------- Encabezado ---------- */
.top {
  position: sticky; top: 0; z-index: 10;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 12px 16px 0;
}
.top-row { display: flex; align-items: center; gap: 12px; max-width: 1200px; margin: 0 auto; }
.top h1 { font-size: 19px; margin: 0; flex: 1; letter-spacing: -.01em; }
.cart-btn {
  display: flex; align-items: center; gap: 6px;
  background: var(--brand); color: #fff; border: 0;
  border-radius: 999px; padding: 8px 14px; font-weight: 600;
}
.cart-btn b {
  background: #fff; color: var(--brand); border-radius: 999px;
  min-width: 22px; padding: 0 6px; font-size: 13px; text-align: center;
}
.search {
  display: flex; align-items: center; gap: 8px;
  max-width: 1200px; margin: 10px auto 0;
  background: var(--bg); border: 1px solid var(--line); border-radius: 12px;
  padding: 0 12px; color: var(--muted);
}
.search:focus-within { border-color: var(--brand); }
.search input { flex: 1; border: 0; background: none; outline: none; padding: 11px 0; font-size: 16px; }
.cuenta-btn {
  display: flex; align-items: center; gap: 6px; max-width: 150px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 999px; padding: 7px 12px; font-weight: 600;
}
.admin-link {
  display: flex; align-items: center; gap: 4px; text-decoration: none; white-space: nowrap;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 999px; padding: 7px 12px; font-weight: 600; font-size: 14px;
}
.admin-link:hover { border-color: var(--brand); color: var(--brand); }
@media (max-width: 420px) { .admin-link { padding: 7px 9px; } .admin-link span { display: none; } }
.btn-panel {
  display: block; text-align: center; text-decoration: none; border-radius: 12px; padding: 12px;
  font-weight: 700; background: var(--brand-soft); color: var(--brand);
}
.cuenta-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cuenta-btn.on { border-color: var(--brand); color: var(--brand); }
@media (max-width: 420px) {
  .top h1 { font-size: 16px; }
  .cuenta-btn { padding: 7px 9px; max-width: 110px; }
  .cart-btn span { display: none; }
}

/* Precio bloqueado (sin sesión) */
.bloqueado {
  display: flex; align-items: center; gap: 6px; width: 100%;
  border: 1px dashed var(--line); background: none; border-radius: 10px;
  padding: 7px 8px; font-size: 12.5px; font-weight: 600; color: var(--muted); text-align: left;
}
.bloqueado:hover { border-color: var(--brand); color: var(--brand); }

/* ---------- Ventana de cuenta ---------- */
.modal {
  position: fixed; inset: 0; z-index: 35; background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center; padding: 16px; overflow-y: auto;
}
.modal-caja {
  position: relative; background: var(--card); width: min(400px, 100%);
  border-radius: 18px; padding: 20px 18px 18px; box-shadow: 0 10px 40px rgba(0,0,0,.3);
}
.modal-cerrar { position: absolute; top: 12px; right: 12px; }
.tabs { display: flex; gap: 4px; background: var(--bg); border-radius: 12px; padding: 4px; margin: 0 44px 14px 0; }
.tabs button { flex: 1; border: 0; background: none; border-radius: 9px; padding: 8px; font-weight: 600; color: var(--muted); }
.tabs button.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); }
.form { display: grid; gap: 12px; }
.form h2 { margin: 0 44px 0 0; font-size: 19px; }
.form-intro { margin: 0; color: var(--muted); font-size: 13.5px; }
.form label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.form input, .form textarea {
  border: 1px solid var(--line); background: var(--bg); border-radius: 10px;
  padding: 11px; font-size: 16px; resize: vertical; color: var(--text);
}
.form input:focus, .form textarea:focus { outline: none; border-color: var(--brand); }
.form input[readonly] { opacity: .7; }
.btn-principal {
  border: 0; border-radius: 12px; padding: 13px; font-weight: 700; font-size: 15px;
  background: var(--brand); color: #fff;
}
.btn-principal:disabled { opacity: .6; cursor: wait; }
.btn-salir { border: 1px solid var(--line); background: none; border-radius: 12px; padding: 11px; color: var(--danger); font-weight: 600; }
.enlace { border: 0; background: none; color: var(--brand); font-weight: 600; padding: 4px; }
.form-msg { margin: 12px 0 0; padding: 10px 12px; border-radius: 10px; font-size: 13.5px; background: var(--brand-soft); color: var(--brand); }
.form-msg.error { background: var(--err-bg); color: var(--err-fg); }

.scan-btn {
  flex: none; display: grid; place-items: center;
  width: 38px; height: 38px; margin-right: -6px;
  border: 0; border-radius: 10px; background: none; color: var(--brand);
}
.scan-btn:hover { background: var(--brand-soft); }

/* ---------- Lector de código de barra ---------- */
.scanner { position: fixed; inset: 0; z-index: 40; background: #000; display: grid; place-items: center; }
.scanner video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scan-marco {
  position: relative; width: min(80vw, 340px); aspect-ratio: 16 / 9;
  border: 3px solid rgba(255,255,255,.9); border-radius: 14px;
  box-shadow: 0 0 0 100vmax rgba(0,0,0,.45); overflow: hidden;
}
.scan-linea {
  position: absolute; left: 6%; right: 6%; top: 50%; height: 2px;
  background: #ff3b30; box-shadow: 0 0 8px #ff3b30; animation: scan 1.6s ease-in-out infinite alternate;
}
@keyframes scan { from { top: 15%; } to { top: 85%; } }
.scan-texto {
  position: absolute; left: 16px; right: 16px; bottom: calc(40px + env(safe-area-inset-bottom));
  margin: 0; text-align: center; color: #fff; font-weight: 600; text-shadow: 0 1px 4px rgba(0,0,0,.6);
}
.scan-cerrar {
  position: absolute; top: calc(16px + env(safe-area-inset-top)); right: 16px;
  width: 44px; height: 44px; border-radius: 50%; border: 0;
  background: rgba(0,0,0,.55); color: #fff; font-size: 20px;
}

.chips {
  display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none;
  max-width: 1200px; margin: 0 auto; padding: 10px 0 12px;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--card);
  border-radius: 999px; padding: 6px 12px; font-size: 13px; white-space: nowrap;
}
.chip small { color: var(--muted); margin-left: 4px; }
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.chip.on small { color: rgba(255,255,255,.8); }

/* ---------- Lista ---------- */
main { max-width: 1200px; margin: 0 auto; padding: 12px 16px; }
.resumen { color: var(--muted); font-size: 13px; margin: 4px 0 12px; }
.aviso {
  background: #fff6dc; color: #6b5200; border: 1px solid #f0dc9a;
  padding: 10px 12px; border-radius: 10px; font-size: 13px; margin-bottom: 12px;
}
.grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
}
@media (min-width: 700px) { .grid { grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 16px; } }

.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid var(--line);
  display: flex; flex-direction: column; overflow: hidden;
}
.foto {
  aspect-ratio: 1; background: #fff; display: grid; place-items: center;
  border: 0; border-bottom: 1px solid var(--line); position: relative; padding: 0; width: 100%;
}
.nombre[data-detalle] { cursor: pointer; }
.nombre[data-detalle]:hover { text-decoration: underline; }

/* Selector unidad / paquete / bulto */
.sel:empty { display: none; }
.pres { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.pres button {
  position: relative; flex: 1 1 auto; border: 1px solid var(--line); background: var(--bg);
  border-radius: 8px; padding: 5px 6px; font-size: 11.5px; font-weight: 600; color: var(--muted); white-space: nowrap;
}
.pres button.on { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); }
.pres i {
  position: absolute; top: -7px; right: -5px; font-style: normal;
  background: var(--brand); color: #fff; border-radius: 999px; font-size: 10px; min-width: 16px; padding: 0 4px; line-height: 16px;
}
.consultar { font-size: 15px !important; color: var(--muted) !important; }
.pill {
  display: inline-block; margin: 3px 0 2px; font-size: 11px; font-weight: 700;
  background: var(--brand-soft); color: var(--brand); border-radius: 6px; padding: 1px 6px;
}

/* ---------- Detalle del producto ---------- */
.detalle {
  position: fixed; inset: 0; z-index: 25; background: rgba(0,0,0,.5);
  display: flex; align-items: flex-end; justify-content: center; overflow-y: auto;
}
@media (min-width: 700px) { .detalle { align-items: center; padding: 24px; } }
.det-caja {
  position: relative; background: var(--card); width: min(860px, 100%);
  border-radius: 18px 18px 0 0; max-height: 92vh; overflow-y: auto;
}
@media (min-width: 700px) { .det-caja { border-radius: 18px; } }
.det-cerrar { position: absolute; top: 12px; right: 12px; z-index: 2; box-shadow: var(--shadow); }
#detalleCuerpo { display: grid; }
@media (min-width: 700px) { #detalleCuerpo { grid-template-columns: 1fr 1fr; } }
.det-foto { position: relative; background: #fff; aspect-ratio: 1; display: grid; place-items: center; }
.det-foto img { width: 100%; height: 100%; object-fit: contain; padding: 16px; }
.det-foto .sin { font-size: 60px; }
.det-info { padding: 16px 16px calc(20px + env(safe-area-inset-bottom)); }
.det-info h2 { margin: 0 40px 6px 0; font-size: 19px; line-height: 1.25; }
.det-desc { margin: 0 0 8px; color: var(--muted); font-size: 13px; }
.det-info h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 16px 0 6px; }
.det-pres { list-style: none; margin: 0; padding: 0; }
.det-pres li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.det-pres .precio { flex: 1; margin: 0; padding: 0; }
.det-pres .ctrl { width: 128px; flex: none; }
.det-pres .add, .det-pres .qty { margin: 0; }
.det-tabla { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; font-size: 13px; }
.det-tabla dt { color: var(--muted); }
.det-tabla dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }
.foto img { width: 100%; height: 100%; object-fit: contain; padding: 8px; }
.foto .sin { color: #b5bcb9; font-size: 34px; }
.tag-agotado {
  position: absolute; top: 8px; left: 8px;
  background: var(--danger); color: #fff; font-size: 11px; font-weight: 700;
  padding: 3px 8px; border-radius: 6px; text-transform: uppercase; letter-spacing: .03em;
}
.info { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.cod { font-size: 11px; color: var(--muted); }
.nombre {
  font-size: 14px; font-weight: 600; line-height: 1.25; margin: 0;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.presen { font-size: 12px; color: var(--muted); }
.precio { margin-top: auto; padding-top: 6px; }
.precio b { font-size: 18px; color: var(--brand); }
.precio small { display: block; color: var(--muted); font-size: 12px; }
.add {
  margin-top: 8px; width: 100%; border: 0; border-radius: 10px;
  background: var(--brand-soft); color: var(--brand); font-weight: 700; padding: 9px;
}
.add:disabled { opacity: .5; cursor: not-allowed; }
.qty {
  margin-top: 8px; display: flex; align-items: center; justify-content: space-between;
  background: var(--brand); color: #fff; border-radius: 10px; overflow: hidden;
}
.qty button { background: none; border: 0; color: #fff; width: 40px; height: 38px; font-size: 20px; font-weight: 700; }
.qty input {
  width: 50px; text-align: center; background: none; border: 0; color: #fff;
  font-weight: 700; font-size: 16px; outline: none; -moz-appearance: textfield;
}
.qty input::-webkit-outer-spin-button, .qty input::-webkit-inner-spin-button { -webkit-appearance: none; }

.skel { height: 300px; border-radius: var(--radius); background: linear-gradient(90deg, var(--card) 25%, var(--line) 50%, var(--card) 75%); background-size: 200% 100%; animation: sk 1.2s infinite; }
@keyframes sk { to { background-position: -200% 0; } }
.nada { grid-column: 1 / -1; text-align: center; color: var(--muted); padding: 40px 0; }

.mas { text-align: center; margin: 20px 0; }
.mas button {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px;
  padding: 10px 22px; font-weight: 600;
}

/* ---------- Barra inferior ---------- */
.barra-pedido {
  position: fixed; left: 16px; right: 16px; bottom: 16px; z-index: 15;
  max-width: 560px; margin: 0 auto;
  display: flex; align-items: center; gap: 10px;
  background: var(--text); color: var(--bg); border: 0; border-radius: 14px;
  padding: 14px 16px; box-shadow: 0 8px 24px rgba(0,0,0,.25);
}
.barra-pedido b { font-size: 16px; }
.barra-ver { margin-left: auto; font-weight: 600; }

/* ---------- Panel del pedido ---------- */
.velo { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 20; }
.panel {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 21;
  width: min(440px, 100%); background: var(--card);
  display: flex; flex-direction: column;
  transform: translateX(100%); transition: transform .25s ease;
}
.panel.open { transform: none; }
.panel-head { display: flex; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.panel-head h2 { margin: 0; font-size: 18px; flex: 1; }
.x { border: 0; background: var(--bg); width: 34px; height: 34px; border-radius: 50%; }
.panel-body { flex: 1; overflow-y: auto; padding: 8px 16px; }
.items { list-style: none; margin: 0; padding: 0; }
.item { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); align-items: center; }
.item img, .item .ph { width: 52px; height: 52px; object-fit: contain; background: #fff; border-radius: 8px; border: 1px solid var(--line); flex: none; }
.item .txt { flex: 1; min-width: 0; }
.item .txt p { margin: 0; font-size: 13px; font-weight: 600; line-height: 1.25; }
.item .txt small { color: var(--muted); font-size: 12px; }
.item .ctrl { flex: none; }
.item .qty { margin: 0; width: 112px; flex: none; }
.item .qty button { width: 32px; height: 32px; font-size: 17px; }
.item .qty input { width: 40px; font-size: 14px; }
.vacio { text-align: center; color: var(--muted); padding: 30px 0; }
.datos { display: grid; gap: 10px; padding: 14px 0; }
.datos label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.datos input, .datos textarea {
  border: 1px solid var(--line); background: var(--bg); border-radius: 10px;
  padding: 10px; font-size: 16px; resize: vertical;
}
.panel-foot { border-top: 1px solid var(--line); padding: 14px 16px calc(14px + env(safe-area-inset-bottom)); display: grid; gap: 10px; }
.total-row { display: flex; justify-content: space-between; align-items: baseline; }
.total-row b { font-size: 22px; }
.wa {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--wa); color: #fff; border: 0; border-radius: 12px; padding: 14px; font-weight: 700; font-size: 16px;
}
.wa:disabled { opacity: .5; cursor: not-allowed; }
.acciones { display: flex; gap: 8px; }
.acciones button { flex: 1; border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 9px; font-size: 14px; }
.acciones .peligro { color: var(--danger); }

.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); z-index: 30;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px;
}

/* Escalas de precio por cantidad */
.escala-tip { display: block; color: var(--brand) !important; font-size: 11.5px; }
.escala-tip b { font-size: 11.5px !important; color: var(--brand) !important; }
.pill.escala { background: var(--warn-bg); color: #b07c00; }

/* Aviso de precios no oficiales */
.nota-precios {
  margin: 0 0 10px; padding: 9px 12px; border-radius: 10px; font-size: 13px;
  background: var(--warn-bg); color: var(--text); border: 1px solid rgba(224, 161, 0, .35);
}
.panel-foot .nota-precios { margin: 0; font-size: 12px; }

/* Calificación */
.calif {
  display: inline-flex; align-items: center; gap: 4px; align-self: flex-start;
  border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: 3px 9px; font-size: 12px; color: var(--muted);
}
.calif:hover { border-color: #e0a100; }
.calif b { color: var(--text); font-size: 12px; }
.calif small { font-size: 11px; }
.estrellas span { color: var(--line); }
.estrellas span.on { color: #f5a623; }
.estrellas.grande { font-size: 20px; letter-spacing: 1px; }
.det-calif { display: grid; gap: 6px; margin: 6px 0 4px; padding: 10px 12px; background: var(--bg); border-radius: 12px; }
.det-calif:empty { display: none; }
.det-calif .prom { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.det-calif .prom b { font-size: 18px; }
.det-calif small { color: var(--muted); font-size: 12.5px; }
.tu-calif { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; }
.tu-calif small { margin-right: 6px; }
.estrella { border: 0; background: none; font-size: 28px; line-height: 1; padding: 2px; color: var(--line); cursor: pointer; }
.estrella.on, .tu-calif:hover .estrella { color: #f5a623; }
.tu-calif .estrella:hover ~ .estrella { color: var(--line); }

/* ---------- Tarjetas uniformes: cada parte mide lo mismo en todas ---------- */
.card .cod { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; min-height: 1.4em; line-height: 1.4; }   /* aunque no tenga código, ocupa su línea */
.card .nombre { -webkit-line-clamp: 3; line-height: 1.25; min-height: calc(1.25em * 3); }
.card .calif { height: 24px; }
.card .sel, .card .sel:empty { display: block; min-height: 28px; }
.card .pres { flex-wrap: nowrap; gap: 3px; margin-top: 0; }
.card .pres button { flex: 1 1 0; min-width: 0; padding: 5px 2px; font-size: 11px; text-align: center; }
.card .precio { margin-top: auto; min-height: 62px; }
.card .precio small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .precio .escala-tip ~ .escala-tip { display: none; }      /* en la tarjeta, solo la primera escala */
.card .precio .bloqueado { min-height: 40px; }

/* ---------- Productos nuevos ---------- */
.tag-nuevo {
  position: absolute; top: 8px; left: 8px;
  background: var(--brand); color: #fff; font-size: 11px; font-weight: 700;
  padding: 3px 8px; border-radius: 6px; text-transform: uppercase; letter-spacing: .03em;
}
.chip.chip-nuevo:not(.on) { border-color: var(--brand); color: var(--brand); font-weight: 600; }
.nuevos { background: var(--brand-soft); border-radius: var(--radius); padding: 12px 0 14px; margin: 0 0 16px; }
.nuevos-cab { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 12px 10px; }
.nuevos-cab h2 { margin: 0; font-size: 16px; }
.nuevos-ver { border: 0; background: none; color: var(--brand); font-weight: 600; font-size: 13px; padding: 4px 0; white-space: nowrap; cursor: pointer; }
.nuevos-fila {
  display: grid; grid-auto-flow: column; grid-auto-columns: 160px; gap: 12px;
  overflow-x: auto; padding: 0 12px 4px; scroll-snap-type: x mandatory; scrollbar-width: thin;
}
.nuevos-fila .card { scroll-snap-align: start; }
@media (min-width: 700px) { .nuevos-fila { grid-auto-columns: 210px; gap: 16px; } }

/* «Todos» y «Nuevos» fijos a la izquierda; los demás departamentos pasan por debajo */
.chips-fijos {
  position: sticky; left: 0; z-index: 2; flex: none;
  display: flex; gap: 8px; padding-right: 10px;
  background: var(--card);
  box-shadow: 12px 0 10px -8px rgba(0,0,0,.18);
}
