/* Al Tanto — estilos
   Limpio, moderno, móvil primero, sobrio y vendible. */

:root {
  --brand: #0d5c46;
  --brand-dark: #093f30;
  --brand-soft: #e3f0ea;
  --ink: #17251f;
  --muted: #5d6f67;
  --bg: #f4f6f3;
  --card: #ffffff;
  --line: #dde5df;
  --danger: #b3261e;
  --danger-soft: #fbeae9;
  --warn: #8a5a00;
  --warn-soft: #fdf3d7;
  --usd: #1d4ed8;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(16, 42, 33, 0.08), 0 4px 14px rgba(16, 42, 33, 0.05);
}

* { box-sizing: border-box; }

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

/* Sin zoom de doble toque al pulsar repetido (iOS): los botones responden al instante.
   El zoom de pellizco sigue funcionando; esto solo quita el zoom del doble toque. */
button, a { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.45;
}

.hidden { display: none !important; }
.center { text-align: center; }

.view { max-width: 960px; margin: 0 auto; padding: 16px 14px 110px; }

h1, h2, h3 { margin: 0 0 8px; line-height: 1.2; }
h1 { font-size: 1.55rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; }

/* ---------- barra sin conexión ---------- */
.offline-bar {
  position: sticky; top: 0; z-index: 60;
  background: #7c2d12; color: #fff;
  padding: 8px 14px; font-size: 0.88rem; text-align: center;
}

/* ---------- acceso ---------- */
.auth-wrap { max-width: 480px; margin: 12px auto 0; }
.brand { text-align: center; margin-bottom: 18px; }
.brand-logo { width: 100%; max-width: 272px; height: auto; background: #fff; border: 1px solid var(--line); border-radius: 18px; padding: 12px 16px; }
.brand-sub { color: var(--muted); margin: 4px 0 0; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }

.trust ul { margin: 6px 0 0; padding-left: 20px; color: var(--muted); font-size: 0.93rem; }
.trust li { margin-bottom: 6px; }

/* ---------- formularios y botones ---------- */
label { display: block; font-size: 0.9rem; font-weight: 600; margin-bottom: 12px; }
input, select, textarea {
  width: 100%; margin-top: 5px;
  padding: 11px 12px;
  border: 1.5px solid var(--line); border-radius: 10px;
  font: inherit; font-weight: 400; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
input[readonly] { background: #f0f3f0; color: var(--muted); }

.form-grid { display: grid; grid-template-columns: 1fr; gap: 0 14px; }
@media (min-width: 640px) { .form-grid { grid-template-columns: 1fr 1fr; } }

.btn {
  appearance: none; border: 1.5px solid transparent; cursor: pointer;
  border-radius: 10px; padding: 11px 18px; font: inherit; font-weight: 600;
  background: #e8ede9; color: var(--ink); display: inline-block; text-align: center;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-secondary { background: #fff; border-color: var(--brand); color: var(--brand); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--muted); padding: 8px 14px; }
.btn-link { background: none; border: none; color: var(--brand); padding: 8px 4px; font-weight: 600; }
.btn-block { display: block; width: 100%; margin-top: 8px; }
.btn-big { font-size: 1.12rem; padding: 15px; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-small { padding: 6px 12px; font-size: 0.88rem; }
.btn[disabled] { opacity: 0.55; pointer-events: none; }

.form-msg { min-height: 1.2em; font-size: 0.92rem; margin: 10px 0 0; }
.form-msg.error { color: var(--danger); }
.form-msg.ok { color: var(--brand); }
.hint { color: var(--muted); font-size: 0.9rem; }
.row-gap { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; }

/* pestañas */
.tabs-mini { display: flex; gap: 6px; margin-bottom: 14px; }
.tab-mini {
  flex: 1; padding: 10px; border-radius: 10px; border: 1.5px solid var(--line);
  background: #fff; font: inherit; font-weight: 600; cursor: pointer; color: var(--muted);
}
.tab-mini.active { background: var(--brand); border-color: var(--brand); color: #fff; }

/* pestañas principales: píldoras con icono, 3 por fila */
.main-tabs {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px;
}
.tab {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 14px 8px; border-radius: 999px; border: 1.5px solid #e2e8e3;
  background: #fff; font: inherit; font-weight: 600; cursor: pointer; color: var(--brand-dark);
  box-shadow: 0 1px 4px rgba(16, 42, 33, 0.08), 0 3px 10px rgba(16, 42, 33, 0.05);
  min-width: 0;
}
.tab svg { width: 22px; height: 22px; flex: 0 0 auto; }
.tab span { overflow-wrap: anywhere; }
.tab.active {
  background: var(--brand); border-color: var(--brand); color: #fff;
  box-shadow: 0 4px 14px rgba(13, 92, 70, 0.35);
}
@media (max-width: 560px) {
  .main-tabs { gap: 8px; }
  .tab { padding: 12px 4px; font-size: 0.88rem; gap: 6px; }
  .tab svg { width: 20px; height: 20px; }
}

/* ---------- encabezado ---------- */
.topbar {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 10px;
  margin-bottom: 14px;
}
.topbar-title { margin-bottom: 2px; }
.topbar-sub { color: var(--muted); margin: 0; font-size: 0.9rem; }

.badge {
  background: var(--warn-soft); color: var(--warn); border-radius: 999px;
  padding: 2px 10px; font-size: 0.8rem; font-weight: 700; white-space: nowrap;
}
.badge.bad { background: var(--danger-soft); color: var(--danger); }

/* ---------- tarjetas de cifras ---------- */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
@media (min-width: 720px) { .stats-grid { grid-template-columns: repeat(4, 1fr); } }
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px;
}
.stat .stat-label { color: var(--muted); font-size: 0.82rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.02em; }
.stat .stat-value { font-size: 1.35rem; font-weight: 800; margin-top: 3px; }
.stat .stat-sub { color: var(--muted); font-size: 0.85rem; }

.two-col { display: grid; grid-template-columns: 1fr; gap: 0; }
@media (min-width: 720px) { .two-col { grid-template-columns: 1fr 1fr; gap: 16px; } }

/* gráfico de barras */
.chart { display: flex; align-items: flex-end; gap: 8px; height: 140px; padding-top: 8px; }
.chart-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 5px; min-width: 0; }
.chart-bar { width: 100%; max-width: 44px; background: var(--brand); border-radius: 6px 6px 0 0; min-height: 3px; }
.chart-col.today .chart-bar { background: var(--brand-dark); outline: 2px solid var(--brand-soft); }
.chart-val { font-size: 0.72rem; color: var(--muted); white-space: nowrap; }
.chart-day { font-size: 0.78rem; color: var(--muted); font-weight: 600; }

/* listas */
.list-row {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 11px 2px; border-bottom: 1px solid var(--line);
}
.list-row:last-child { border-bottom: none; }
.list-main { min-width: 0; flex: 1 1 auto; }
.list-title { font-weight: 700; overflow-wrap: break-word; }
.list-sub { color: var(--muted); font-size: 0.86rem; }
.list-side { text-align: right; flex: 0 0 auto; }
.list-amount { font-weight: 800; }
.empty { color: var(--muted); padding: 10px 2px; }

/* filas con acciones: información arriba, botones a todo el ancho */
.list-row-stack { flex-direction: column; align-items: stretch; }
.list-row-stack .list-actions { margin-top: 10px; }
.list-row-stack .list-actions .btn { flex: 1 1 auto; }
.row-pills { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }

/* pantallas estrechas: ninguna fila se aprieta hasta romperse */
@media (max-width: 560px) {
  .list-row { flex-wrap: wrap; }
  .list-side { text-align: left; }
  .pos-tools { flex-wrap: wrap; }
}

.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 0.78rem; font-weight: 700; }
.pill.ok { background: var(--brand-soft); color: var(--brand-dark); }
.pill.bad { background: var(--danger-soft); color: var(--danger); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.usd { background: #e2e9fb; color: var(--usd); }
.pill.grey { background: #eceff1; color: var(--muted); }

/* ---------- vender ---------- */
.pos-tools { display: flex; gap: 8px; margin-bottom: 12px; }
.pos-tools input { margin-top: 0; flex: 1; }
.pos-tools .btn { flex: 0 0 auto; }
.pos-tools select { margin-top: 0; flex: 0 1 auto; max-width: 36%; }
.pos-tools input { min-width: 0; }

.pos-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; padding-bottom: 16px; }
.pos-item {
  background: var(--card); border: 1.5px solid var(--line); border-radius: var(--radius);
  padding: 13px; text-align: left; cursor: pointer; font: inherit; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 3px; min-height: 96px;
}
.pos-item:active { border-color: var(--brand); background: var(--brand-soft); }
.pos-item.out { opacity: 0.5; }
.pos-name { font-weight: 700; overflow-wrap: anywhere; }
.pos-code { color: var(--muted); font-size: 0.8rem; }
.pos-price { font-weight: 800; color: var(--brand-dark); margin-top: auto; }
.pos-stock { font-size: 0.82rem; color: var(--muted); }
.pos-stock.low { color: var(--danger); font-weight: 700; }

#scan-box { margin-bottom: 12px; }
#scan-video { width: 100%; border-radius: var(--radius); background: #000; max-height: 300px; }

.cart-bar {
  position: sticky; bottom: 10px; z-index: 40;
  background: var(--card); border: 1.5px solid var(--brand); border-radius: var(--radius);
  box-shadow: 0 8px 30px rgba(9, 63, 48, 0.22); padding: 14px;
}
.cart-head { display: flex; justify-content: space-between; align-items: center; }
.cart-item { display: flex; align-items: center; gap: 8px; padding: 7px 0; border-bottom: 1px dashed var(--line); }
.cart-item-name { flex: 1; min-width: 0; overflow-wrap: anywhere; font-weight: 600; }
.qty-ctrl { display: flex; align-items: center; gap: 6px; }
.qty-btn {
  width: 32px; height: 32px; border-radius: 50%; border: 1.5px solid var(--brand);
  background: #fff; color: var(--brand); font-size: 1.05rem; font-weight: 800; cursor: pointer; line-height: 1;
  user-select: none; -webkit-user-select: none;
}
.qty-num { min-width: 26px; text-align: center; font-weight: 800; }
.cart-item-sub { font-weight: 700; min-width: 76px; text-align: right; }
.cart-totals { padding: 10px 0 2px; font-size: 1.05rem; }
.cart-totals .total-line { display: flex; justify-content: space-between; font-weight: 800; }
.cart-pay { margin-top: 8px; }

.invoice table { width: 100%; border-collapse: collapse; margin: 10px 0; }
.invoice th, .invoice td { padding: 7px 6px; border-bottom: 1px solid var(--line); text-align: left; font-size: 0.94rem; }
.invoice td.num, .invoice th.num { text-align: right; }
.invoice .inv-head { text-align: center; margin-bottom: 6px; }
.invoice .inv-total { text-align: right; font-size: 1.15rem; font-weight: 800; }

/* ---------- historial / cierre ---------- */
.voided { opacity: 0.62; }
.diff-line { font-weight: 700; min-height: 1.3em; }
.diff-line.bad { color: var(--danger); }
.diff-line.ok { color: var(--brand); }

/* cantidad manual del carrito, selector de rol y tasa */
.qty-input { width: 62px; text-align: center; font-weight: 700; margin-top: 0; padding: 7px 2px; }
.list-side select { width: auto; max-width: 180px; margin-top: 0; }
.rate-now { font-size: 1.12rem; margin: 4px 0 2px; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 999px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3); z-index: 100; max-width: 92vw; text-align: center;
  font-size: 0.94rem;
}

/* impresión de factura: solo la factura */
@media print {
  body * { visibility: hidden; }
  #invoice-box, #invoice-box * { visibility: visible; }
  #invoice-box { position: absolute; inset: 0; border: none; box-shadow: none; }
  .no-print { display: none !important; }
}
