/* =====================================================================
   POS Snacks — hoja de estilos única
   Mobile first. Botones grandes, pocos elementos por pantalla (§24).
   ===================================================================== */

:root {
  --verde:        #1f6f4a;
  --verde-claro:  #2f9464;
  --verde-suave:  #e7f4ed;
  --ambar:        #b7791f;
  --rojo:         #c0392b;
  --azul:         #2b6cb0;

  --fondo:        #f5f6f8;
  --superficie:   #ffffff;
  --superficie-2: #f0f2f5;
  --borde:        #e2e5ea;
  --texto:        #1a1d21;
  --texto-suave:  #6b7280;

  --radio:        14px;
  --radio-sm:     10px;
  --sombra:       0 1px 2px rgba(16, 24, 40, .06), 0 4px 12px rgba(16, 24, 40, .06);
  --alto-topbar:  56px;
  --alto-bottom:  62px;
  --rail:         232px;
  --safe-bottom:  env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --fondo:        #14171a;
    --superficie:   #1c2024;
    --superficie-2: #23282d;
    --borde:        #2e343a;
    --texto:        #e8eaed;
    --texto-suave:  #9aa3ad;
    --verde-suave:  #14312a;
    --sombra:       0 1px 2px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--fondo);
  color: var(--texto);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

h1, h2, h3 { margin: 0 0 .4em; line-height: 1.25; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: .95rem; }
p  { margin: 0 0 .6em; }
a  { color: var(--verde); text-decoration: none; }

.muted     { color: var(--texto-suave); font-size: .9rem; }
.nowrap    { white-space: nowrap; }
.text-right{ text-align: right; }
.hidden    { display: none !important; }

/* ---------- Splash / carga ---------- */
.splash { display: grid; place-items: center; min-height: 100vh; }

.spinner {
  width: 34px; height: 34px;
  border: 3px solid var(--borde);
  border-top-color: var(--verde);
  border-radius: 50%;
  animation: girar .8s linear infinite;
}

@keyframes girar { to { transform: rotate(360deg); } }

/* ---------- Login / instalador ---------- */
.auth-body { display: grid; place-items: center; min-height: 100vh; padding: 20px; }

.public-body { min-height: 100vh; }

.public-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
}

.public-contact { text-align: center; }
.public-contact h1 { margin-bottom: 6px; font-size: 1rem; font-weight: 600; color: var(--texto-suave); }
.public-contact a { font-size: 1.05rem; }

.public-login {
  position: fixed;
  left: 16px;
  bottom: calc(14px + var(--safe-bottom));
  padding: 6px;
  font-size: .75rem;
  color: var(--texto-suave);
  opacity: .65;
}

.public-login:hover,
.public-login:focus { opacity: 1; color: var(--verde); }

.auth-card {
  width: 100%;
  max-width: 400px;
  margin: 8vh auto;
  padding: 26px 22px;
  background: var(--superficie);
  border-radius: var(--radio);
  box-shadow: var(--sombra);
}

.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.brand-mark { font-size: 1.8rem; }
.brand h1 { margin: 0; }
.back-public { display: block; margin-top: 18px; text-align: center; font-size: .8rem; color: var(--texto-suave); }

/* ---------- Formularios ---------- */
label {
  display: block;
  margin-bottom: 14px;
  font-size: .85rem;
  font-weight: 600;
  color: var(--texto-suave);
}

input, select, textarea {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 12px 13px;
  font: inherit;
  font-weight: 400;
  color: var(--texto);
  background: var(--superficie);
  border: 1px solid var(--borde);
  border-radius: var(--radio-sm);
  appearance: none;
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--verde-claro);
  outline-offset: -1px;
  border-color: var(--verde-claro);
}

textarea { min-height: 76px; resize: vertical; }

.row { display: flex; gap: 12px; }
.row > * { flex: 1; min-width: 0; }

.form-error { color: var(--rojo); font-size: .87rem; font-weight: 600; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 46px;
  padding: 11px 16px;
  font: inherit;
  font-weight: 600;
  color: var(--texto);
  background: var(--superficie);
  border: 1px solid var(--borde);
  border-radius: var(--radio-sm);
  cursor: pointer;
  user-select: none;
}

.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-primary { background: var(--verde); border-color: var(--verde); color: #fff; }
.btn-danger  { background: var(--rojo);  border-color: var(--rojo);  color: #fff; }
.btn-ghost   { background: transparent; border-color: transparent; color: var(--verde); }
.btn-block   { display: flex; width: 100%; }
.btn-sm      { min-height: 36px; padding: 6px 11px; font-size: .85rem; }
.btn-lg      { min-height: 54px; font-size: 1.05rem; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 40px; height: 40px;
  font-size: 1.2rem;
  color: inherit;
  background: transparent;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
}

/* ---------- Layout ---------- */
.app.is-loading .splash { display: grid; }

.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 6px;
  height: var(--alto-topbar);
  padding: 0 6px;
  background: var(--verde);
  color: #fff;
}

.topbar-title { flex: 1; margin: 0; font-size: 1.05rem; font-weight: 600; }

/* El botón + vive en la barra inferior; en escritorio esa barra no existe. */
.solo-escritorio { display: none; }

.content {
  padding: calc(var(--alto-topbar) + 14px) 14px calc(var(--alto-bottom) + var(--safe-bottom) + 24px);
  max-width: 1100px;
  margin: 0 auto;
}

/* Navegación inferior (móvil) */
.bottombar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-around;
  height: calc(var(--alto-bottom) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--superficie);
  border-top: 1px solid var(--borde);
}

.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  flex: 1;
  padding: 6px 0;
  font-size: .68rem;
  font-weight: 600;
  color: var(--texto-suave);
}

.tab span { font-size: 1.25rem; line-height: 1; }
.tab.is-active { color: var(--verde); }

.fab {
  display: grid;
  place-items: center;
  width: 54px; height: 54px;
  margin-top: -20px;
  font-size: 1.9rem;
  line-height: 1;
  color: #fff;
  background: var(--verde);
  border: 3px solid var(--fondo);
  border-radius: 50%;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(31, 111, 74, .4);
}

/* Rail lateral (escritorio) */
.rail { display: none; }

@media (min-width: 900px) {
  .rail {
    position: fixed;
    top: var(--alto-topbar);
    bottom: 0; left: 0;
    z-index: 20;
    display: flex;
    flex-direction: column;
    gap: 2px;
    width: var(--rail);
    padding: 14px 10px;
    overflow-y: auto;
    background: var(--superficie);
    border-right: 1px solid var(--borde);
  }

  .rail a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 13px;
    font-weight: 600;
    color: var(--texto);
    border-radius: var(--radio-sm);
  }

  .rail a.is-active { background: var(--verde-suave); color: var(--verde); }
  .rail a span { width: 22px; font-size: 1.1rem; }

  .content { padding-left: calc(var(--rail) + 22px); padding-right: 22px; padding-bottom: 40px; max-width: none; }
  .bottombar { display: none; }
  .topbar [data-action="toggle-menu"] { display: none; }
  .solo-escritorio { display: grid; }
}

/* ---------- Tarjetas y rejillas ---------- */
.card {
  padding: 16px;
  margin-bottom: 14px;
  background: var(--superficie);
  border: 1px solid var(--borde);
  border-radius: var(--radio);
  box-shadow: var(--sombra);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.card-head h2 { margin: 0; }

.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

.kpi {
  padding: 14px;
  background: var(--superficie);
  border: 1px solid var(--borde);
  border-radius: var(--radio);
}

.kpi-label { font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; color: var(--texto-suave); }
.kpi-value { font-size: 1.5rem; font-weight: 700; line-height: 1.2; }
.kpi-extra { font-size: .8rem; color: var(--texto-suave); }
.kpi.positivo .kpi-value { color: var(--verde); }
.kpi.negativo .kpi-value { color: var(--rojo); }

/* ---------- Listas ---------- */
.list { display: flex; flex-direction: column; }

.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 4px;
  text-align: left;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--borde);
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.list-item:last-child { border-bottom: 0; }
.list-item .li-main { flex: 1; min-width: 0; }
.list-item .li-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .li-sub { font-size: .8rem; color: var(--texto-suave); }
.list-item .li-side { text-align: right; white-space: nowrap; }

.empty { padding: 34px 12px; text-align: center; color: var(--texto-suave); }
.empty-icon { font-size: 2.2rem; display: block; margin-bottom: 6px; }

/* ---------- Chips y badges ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; }
.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: 0 0 auto;
  padding: 7px 13px;
  font-size: .85rem;
  font-weight: 600;
  color: var(--texto-suave);
  background: var(--superficie);
  border: 1px solid var(--borde);
  border-radius: 999px;
  cursor: pointer;
}

.chip.is-active { background: var(--verde); border-color: var(--verde); color: #fff; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  font-size: .72rem;
  font-weight: 700;
  border-radius: 999px;
  background: var(--superficie-2);
  color: var(--texto-suave);
}

.badge-ok    { background: var(--verde-suave); color: var(--verde); }
.badge-warn  { background: #fdf3e0; color: var(--ambar); }
.badge-error { background: #fdeceb; color: var(--rojo); }

/* ---------- Tablas ---------- */
.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: 9px 8px; text-align: left; border-bottom: 1px solid var(--borde); }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .03em; color: var(--texto-suave); }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ---------- POS ---------- */
.pos { display: grid; gap: 14px; }

@media (min-width: 900px) {
  .pos { grid-template-columns: 1fr 380px; align-items: start; }
  .pos-cart { position: sticky; top: calc(var(--alto-topbar) + 20px); }
}

.pos-search { position: relative; margin-bottom: 10px; }
.pos-search input { padding-left: 38px; }
.pos-search::before { content: "🔍"; position: absolute; left: 12px; top: 12px; opacity: .6; }

.pos-results { max-height: 46vh; overflow-y: auto; }

.pos-prod {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px 6px;
  text-align: left;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--borde);
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.pos-prod:disabled { opacity: .5; }
.pos-prod-main { flex: 1; min-width: 0; }
.pos-prod-name { font-weight: 600; }
.pos-prod-meta { font-size: .78rem; color: var(--texto-suave); }
.pos-prod-price { font-weight: 700; white-space: nowrap; }

.cart-line { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--borde); }
.cart-line-main { flex: 1; min-width: 0; }
.cart-line-name { font-weight: 600; font-size: .92rem; }
.cart-line-meta { font-size: .78rem; color: var(--texto-suave); }

.qty { display: flex; align-items: center; gap: 4px; }
.qty button {
  width: 34px; height: 34px;
  font-size: 1.15rem; font-weight: 700;
  color: var(--texto);
  background: var(--superficie-2);
  border: 1px solid var(--borde);
  border-radius: 8px;
  cursor: pointer;
}
.qty input { width: 56px; margin: 0; padding: 6px 4px; text-align: center; }

.totales { margin-top: 10px; font-variant-numeric: tabular-nums; }
.totales div { display: flex; justify-content: space-between; padding: 3px 0; font-size: .92rem; }
.totales .total-final { padding-top: 8px; margin-top: 6px; border-top: 2px solid var(--borde); font-size: 1.25rem; font-weight: 700; }

.pagos { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 12px 0; }

/* ---------- Hoja modal (bottom sheet) ---------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(10, 14, 18, .5);
  animation: aparecer .15s ease;
}

@keyframes aparecer { from { opacity: 0; } }
@keyframes subir { from { transform: translateY(22px); opacity: .6; } }

.sheet {
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  overflow-y: auto;
  padding: 18px 16px calc(20px + var(--safe-bottom));
  background: var(--superficie);
  border-radius: var(--radio) var(--radio) 0 0;
  animation: subir .18s ease;
}

@media (min-width: 700px) {
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: var(--radio); max-height: 88vh; }
}

.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.sheet-head h2 { margin: 0; }
.sheet-actions { display: flex; gap: 10px; margin-top: 8px; }
.sheet-actions .btn { flex: 1; }

.menu-list { display: flex; flex-direction: column; gap: 8px; }
.menu-list .btn { justify-content: flex-start; min-height: 52px; font-size: 1rem; }

/* ---------- Avisos ---------- */
.alert { padding: 12px 14px; margin-bottom: 14px; border-radius: var(--radio-sm); font-size: .9rem; }
.alert p:last-child { margin-bottom: 0; }
.alert-ok    { background: var(--verde-suave); color: var(--verde); }
.alert-error { background: #fdeceb; color: var(--rojo); }
.alert-warn  { background: #fdf3e0; color: var(--ambar); }

/* ---------- Toasts ---------- */
.toast-root {
  position: fixed;
  left: 50%;
  bottom: calc(var(--alto-bottom) + var(--safe-bottom) + 14px);
  z-index: 90;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: max-content;
  max-width: 92vw;
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  padding: 11px 16px;
  font-size: .9rem;
  font-weight: 600;
  color: #fff;
  background: #23282d;
  border-radius: 999px;
  box-shadow: var(--sombra);
  animation: subir .18s ease;
}

.toast.error { background: var(--rojo); }
.toast.ok    { background: var(--verde); }

/* ---------- Gráfica de barras simple ---------- */
.chart { display: flex; align-items: flex-end; gap: 3px; height: 120px; margin-top: 8px; }
.chart-bar { flex: 1; min-width: 3px; background: var(--verde-claro); border-radius: 3px 3px 0 0; opacity: .85; }
.chart-bar:hover { opacity: 1; }
.chart-axis { display: flex; justify-content: space-between; font-size: .72rem; color: var(--texto-suave); margin-top: 4px; }
