/* ============================================================
   DQ-Market — estilos (mobile-first, sin dependencias externas)
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }

:root {
  --green: #15803d;
  --green-2: #16a34a;
  --green-bg: #ecfdf5;
  --green-line: #86efac;
  --ink: #0b1220;
  --ink-2: #334155;
  --muted: #475569;
  --line: #e5e9ef;
  --bg: #f4f6f8;
  --card: #ffffff;
  --danger: #dc2626;
  --warn: #d97706;
  --nav-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --r: 16px;
}

html, body { margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
  font-size: 16px;
  line-height: 1.35;
}

[hidden] { display: none !important; }
body.con-hoja { overflow: hidden; }
button, input, select, textarea { font-family: inherit; font-size: 16px; }
button { cursor: pointer; }
h1, h2, h3, h4, p { margin: 0; }

/* Iconos SVG (sprite) */
.ic {
  width: 22px; height: 22px; flex: 0 0 auto;
  fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}
.ic-sm { width: 18px; height: 18px; }

/* ---------- utilidades ---------- */
.stack { display: flex; flex-direction: column; gap: 8px; }
.grow { flex: 1 1 auto; min-width: 0; }
.tiny { font-size: 12px; color: var(--muted); line-height: 1.4; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.center { text-align: center; }
.mono-num { font-variant-numeric: tabular-nums; }

/* ---------- botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 18px;
  border: 1px solid transparent; border-radius: 12px;
  background: #eef2f6; color: var(--ink);
  font-weight: 700; font-size: 15px;
  transition: transform .08s ease, filter .15s ease, background .15s ease;
  touch-action: manipulation;
}
.btn:active { transform: scale(.975); }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn-primary { background: var(--green); color: #fff; }
.btn-ghost { background: #fff; border-color: var(--line); color: var(--ink-2); }
.btn-danger { background: #fee2e2; color: #b91c1c; }
.btn-lg { min-height: 56px; width: 100%; font-size: 17px; border-radius: 14px; }
.btn-sm { min-height: 44px; padding: 0 14px; font-size: 14px; border-radius: 10px; }
.btn-icon {
  width: 44px; height: 44px; min-height: 44px; padding: 0;
  background: transparent; border: 1px solid var(--line); color: var(--ink-2); border-radius: 12px;
}
.btn-icon.danger { color: var(--danger); border-color: #fecaca; background: #fff5f5; }

/* ---------- login ---------- */
.login {
  min-height: 100dvh;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: calc(28px + var(--safe-t)) 22px calc(28px + var(--safe-b));
  background: radial-gradient(120% 60% at 50% 0%, #e8f6ee 0%, var(--bg) 60%);
}
.login-logo { width: 168px; max-width: 60vw; height: auto; object-fit: contain; border-radius: 16px; }
.login h1 { font-size: 24px; letter-spacing: -.02em; }
.login .sub { color: var(--muted); font-size: 14px; text-align: center; margin-bottom: 6px; }
.login form { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 12px; }
.login .note { max-width: 380px; }
.install-hint {
  margin-top: 8px; max-width: 380px; width: 100%;
  background: #fff; border: 1px dashed var(--line); border-radius: 14px;
  padding: 12px 14px; display: flex; gap: 10px; align-items: flex-start;
}

/* ---------- campos ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .field > span {
  font-size: 11px; font-weight: 800; letter-spacing: .04em;
  text-transform: uppercase; color: var(--muted);
}
/* valor del pasillo elegido: se lee de un vistazo, sin buscar el chip */
.field > span b {
  color: var(--green); font-size: 13px; font-weight: 800;
  text-transform: none; letter-spacing: 0;
}
input[type="text"], input[type="email"], input[type="password"], input[type="search"], select {
  width: 100%; min-height: 52px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 12px;
  background: #fff; color: var(--ink); outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, select:focus {
  border-color: var(--green-2);
  box-shadow: 0 0 0 3px rgba(22, 163, 74, .14);
}
.inputline { display: flex; gap: 8px; align-items: stretch; }
.inputline input { flex: 1 1 auto; }
.err { color: var(--danger); font-size: 13px; font-weight: 600; }

/* switch */
.switch {
  display: flex; align-items: center; gap: 10px;
  min-height: 44px; font-size: 14px; color: var(--ink-2); font-weight: 600;
}
.switch input { width: 22px; height: 22px; accent-color: var(--green); flex: 0 0 auto; }

/* ---------- cabecera fija ---------- */
#topbar {
  position: sticky; top: 0; z-index: 30;
  background: rgba(255, 255, 255, .97);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  padding: calc(8px + var(--safe-t)) 14px 10px;
}
.tb-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.budget-btn {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 44px; padding: 0 8px 0 0;
  background: none; border: 0; color: var(--muted);
  font-size: 11px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase;
}
.budget-btn b { color: var(--ink); font-size: 12px; letter-spacing: 0; }
.tb-nums { display: flex; align-items: flex-end; justify-content: space-between; margin-top: 2px; }
.tb-spent { font-size: 30px; font-weight: 800; letter-spacing: -.03em; line-height: 1.1; }
.tb-iva { display: block; font-size: 11px; color: var(--muted); font-weight: 600; margin-top: 1px; }
.tb-left { font-size: 13px; font-weight: 800; text-align: right; }
.tb-left small { display: block; font-size: 11px; color: var(--muted); font-weight: 600; }
.ok { color: var(--green); }
.warn { color: var(--warn); }
.bad { color: var(--danger); }
.bar { margin-top: 8px; height: 8px; border-radius: 99px; background: #e7ecf1; overflow: hidden; }
.bar > i { display: block; height: 100%; width: 0%; border-radius: 99px; background: var(--green-2); transition: width .3s ease, background .3s ease; }

/* menú de cuenta */
.pop {
  position: absolute; right: 12px; top: calc(100% - 4px); z-index: 45;
  min-width: 210px; background: #fff; border: 1px solid var(--line);
  border-radius: 14px; box-shadow: 0 12px 32px rgba(2, 12, 27, .16);
  padding: 6px; overflow: hidden;
}
.pop-mail { padding: 8px 10px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--line); }
.pop-item {
  display: flex; align-items: center; gap: 8px; width: 100%;
  min-height: 44px; padding: 0 10px; background: none; border: 0;
  border-radius: 10px; font-size: 14px; font-weight: 700; color: var(--ink-2); text-align: left;
}
.pop-item:active { background: #f1f5f9; }
.pop-item.danger { color: var(--danger); }

/* ---------- pantallas ---------- */
.screen { padding: 12px 14px calc(var(--nav-h) + var(--safe-b) + 96px); }
.sec-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; margin: 16px 2px 8px;
}
.sec-head:first-child { margin-top: 2px; }
.sec-head h2 { font-size: 12px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.pill {
  display: inline-block; min-width: 20px; padding: 1px 7px; border-radius: 99px;
  background: #eef2f6; color: var(--ink-2); font-size: 11px; font-weight: 800; text-align: center;
}
.pill.green { background: var(--green-bg); color: var(--green); }

/* tarjetas / filas */
.card {
  display: block; width: 100%; text-align: left;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r);
  padding: 12px 14px;
}
.rowlink { display: flex; align-items: center; gap: 12px; min-height: 64px; }
.ico-box {
  width: 40px; height: 40px; border-radius: 12px; flex: 0 0 auto;
  display: grid; place-items: center; background: var(--green-bg); color: var(--green);
}
.row { display: flex; align-items: center; gap: 10px; background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; }
.row:active { background: #f8fafc; }
.row-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1 1 auto; }
.row-main-btn { background: none; border: 0; padding: 0; font: inherit; color: inherit; text-align: left; }
.row-title { font-weight: 700; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { font-size: 13px; color: var(--muted); font-weight: 600; }
.badge-iva {
  display: inline-block; font-size: 10px; font-weight: 800; letter-spacing: .03em;
  background: #e0edff; color: #1e40af; border-radius: 5px; padding: 1px 5px; margin-left: 4px;
}
.price-tag { font-weight: 800; font-size: 15px; color: var(--green); white-space: nowrap; }
.item-done .row-title { color: var(--muted); text-decoration: line-through; font-weight: 600; }

.cat-head {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase;
  color: #475569; padding: 10px 4px 2px;
}
.cat-head .ic { width: 14px; height: 14px; color: var(--green); }

.empty {
  border: 1px dashed #d6dde5; border-radius: 14px; background: #fff;
  padding: 18px 14px; text-align: center; color: var(--muted); font-size: 13px;
}
.empty .ic { width: 26px; height: 26px; color: #cbd5e1; display: block; margin: 0 auto 6px; }

/* chips */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; min-height: 44px; padding: 0 14px;
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); border-radius: 99px; background: #fff;
  font-size: 14px; font-weight: 600; color: var(--ink-2); white-space: nowrap;
}
.chip:active { background: var(--green-bg); border-color: var(--green-line); }
.chip.on { background: var(--green); border-color: var(--green); color: #fff; }

/* lista activa */
.list-badge {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--green-bg); border: 1px solid var(--green-line);
  border-radius: 12px; padding: 8px 12px; font-size: 13px; color: #14532d; font-weight: 600;
}
.list-badge b { font-weight: 800; }

/* buscador */
.search { position: relative; display: flex; align-items: center; }
.search .ic { position: absolute; left: 12px; color: var(--muted); pointer-events: none; }
.search input { padding-left: 40px; }

/* barra resumen (súper) */
.sum-bar {
  position: fixed; left: 0; right: 0;
  bottom: calc(var(--nav-h) + var(--safe-b)); z-index: 35;
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 10px 16px;
  background: #0b1220; color: #fff; font-size: 13px; font-weight: 700;
}
.sum-bar b { font-size: 17px; }
.sum-bar .ic { color: #94a3b8; }
.sum-inner { display: flex; align-items: center; gap: 8px; }

/* navegación inferior */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: grid; grid-template-columns: repeat(3, 1fr);
  height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: rgba(255, 255, 255, .97);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  background: none; border: 0; color: var(--muted); font-size: 11px; font-weight: 700;
  position: relative;
}
.tab b {
  position: absolute; top: 6px; left: 50%; margin-left: 4px;
  min-width: 18px; height: 18px; padding: 0 4px; border-radius: 99px;
  background: var(--green); color: #fff; font-size: 10px; line-height: 18px; text-align: center;
}
.tab.on { color: var(--green); }
.tab.on .ic { stroke-width: 2.3; }

/* FAB */
.fab {
  position: fixed; right: 16px; z-index: 41;
  bottom: calc(var(--nav-h) + var(--safe-b) + 64px);
  width: 58px; height: 58px; border-radius: 50%; border: 0;
  background: var(--green); color: #fff;
  box-shadow: 0 10px 24px rgba(21, 128, 61, .38);
  display: grid; place-items: center;
  transition: transform .1s ease;
}
.fab:active { transform: scale(.92); }
.fab .ic { width: 26px; height: 26px; stroke-width: 2.6; }

/* ---------- hojas (bottom sheets) ---------- */
.backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(9, 15, 28, .45);
  opacity: 0; transition: opacity .22s ease;
}
.backdrop.on { opacity: 1; }

.sheet {
  position: fixed; left: 0; right: 0; bottom: var(--kb, 0px); z-index: 60;
  display: flex; flex-direction: column;
  background: #fff; border-radius: 22px 22px 0 0;
  box-shadow: 0 -12px 40px rgba(2, 12, 27, .22);
  transform: translateY(102%);
  transition: transform .28s cubic-bezier(.2, .85, .25, 1), bottom .15s ease;
  max-height: 94dvh;
}
.sheet.open { transform: none; }
.sheet.tall { height: 92dvh; }
.grab { width: 38px; height: 4px; border-radius: 99px; background: #dbe2ea; margin: 8px auto 0; flex: 0 0 auto; }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 16px 6px; flex: 0 0 auto;
}
.sheet-head h3 { font-size: 17px; font-weight: 800; letter-spacing: -.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-body { padding: 6px 16px 14px; overflow-y: auto; -webkit-overflow-scrolling: touch; flex: 1 1 auto; }
.sheet-body > * + * { margin-top: 10px; }
.sheet-foot {
  flex: 0 0 auto; padding: 10px 16px calc(10px + var(--safe-b));
  border-top: 1px solid var(--line); background: #fff;
  display: flex; flex-direction: column; gap: 8px;
}

/* sugerencias del buscador de producto */
.sug { display: flex; flex-direction: column; gap: 6px; }
.sug-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  min-height: 48px; padding: 8px 12px; text-align: left;
  background: #f8fafc; border: 1px solid var(--line); border-radius: 12px;
  font-size: 15px; font-weight: 600; color: var(--ink);
}
.sug-item:active { background: var(--green-bg); border-color: var(--green-line); }
.sug-item .row-sub { font-weight: 600; }

/* stepper cantidad */
.stepper {
  display: flex; align-items: stretch; height: 52px;
  border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: #fff;
}
.stepper button {
  width: 46px; border: 0; background: #f1f5f9; color: var(--ink);
  display: grid; place-items: center;
}
.stepper button:active { background: #e2e8f0; }
.stepper input {
  flex: 1 1 auto; width: 100%; min-width: 0; min-height: 0;
  border: 0; border-radius: 0; text-align: center;
  font-size: 18px; font-weight: 800; padding: 0 2px;
}
.stepper input:focus { box-shadow: none; }

/* precio */
.priceline {
  display: flex; align-items: center; height: 52px;
  border: 1px solid var(--line); border-radius: 12px; background: #fff; overflow: hidden;
}
.priceline span { padding: 0 4px 0 14px; font-size: 20px; font-weight: 700; color: var(--muted); }
.priceline input {
  flex: 1 1 auto; min-width: 0; min-height: 0; border: 0; border-radius: 0;
  padding: 0 12px 0 4px; font-size: 22px; font-weight: 800; letter-spacing: -.01em;
}
.priceline input:focus { box-shadow: none; }
.priceline:focus-within { border-color: var(--green-2); box-shadow: 0 0 0 3px rgba(22, 163, 74, .14); }

.addgrid { display: grid; grid-template-columns: 118px 1fr; gap: 10px; align-items: end; }

.total-preview {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--green-bg); border: 1px solid var(--green-line);
  border-radius: 14px; padding: 10px 14px;
}
.total-preview span { font-size: 12px; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; color: #047857; }
.total-preview b { font-size: 24px; font-weight: 800; letter-spacing: -.02em; color: #065f46; }
.total-preview small { display: block; font-size: 11px; color: #047857; font-weight: 600; }

/* KPIs */
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: var(--r); padding: 12px; text-align: center; }
.kpi span { display: block; font-size: 10px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.kpi b { display: block; font-size: 21px; font-weight: 800; letter-spacing: -.02em; margin-top: 3px; }
.kpi small { display: block; font-size: 11px; color: var(--muted); font-weight: 600; margin-top: 2px; }

/* detalle historial */
.hist-detail { border-top: 1px dashed var(--line); margin-top: 10px; padding-top: 8px; display: none; }
.hist-detail.open { display: block; }
.hist-line { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; padding: 5px 0; border-bottom: 1px solid #f1f5f9; }
.hist-line:last-of-type { border-bottom: 0; }

/* aviso offline */
.offline-bar {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: #b45309; color: #fff; font-size: 12px; font-weight: 700;
  padding: 6px 10px;
}
.offline-bar .ic { width: 16px; height: 16px; }

/* toasts */.toasts {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + var(--safe-b) + 78px);
  z-index: 90; display: flex; flex-direction: column-reverse; gap: 6px;
  align-items: center; pointer-events: none; width: max-content; max-width: 92vw;
}
.toast {
  background: #1e293b; color: #fff; border-radius: 10px;
  padding: 9px 14px; font-size: 13px; font-weight: 700;
  box-shadow: 0 8px 22px rgba(0, 0, 0, .28);
  opacity: 0; transform: translateY(8px); transition: opacity .2s, transform .2s;
  max-width: 92vw;
}
.toast.show { opacity: 1; transform: none; }
.toast.ok { background: #15803d; }
.toast.warn { background: #b45309; color: #fff; }
.toast.err { background: #b91c1c; }

/* pista del carrito dentro de la hoja de alta */
#addHint { font-size: 13px; font-weight: 700; color: var(--ink-2); }
#addHint b { color: var(--green); }

/* catálogo sin pie: deja aire para la barra gestual */
#sheetCat .sheet-body { padding-bottom: calc(14px + var(--safe-b)); }

/* escáner */
.scan-overlay {
  position: fixed; inset: 0; z-index: 95; background: #000;
  display: flex; flex-direction: column;
}
.scan-overlay video { flex: 1 1 auto; width: 100%; height: 100%; object-fit: cover; }
.scan-overlay .scan-hint {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 16px calc(16px + var(--safe-b)) 24px;
  color: #fff; text-align: center; font-size: 13px; font-weight: 600;
  background: linear-gradient(to top, rgba(0, 0, 0, .7), transparent);
}
.scan-frame {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -58%);
  width: 74%; max-width: 320px; aspect-ratio: 16 / 9;
  border: 2px solid rgba(255, 255, 255, .9); border-radius: 14px;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .28);
}

@media (min-width: 640px) {
  /* en pantallas grandes: columna centrada tipo móvil */
  #topbar { max-width: 560px; margin-left: auto; margin-right: auto; }
  .screen { max-width: 560px; margin-left: auto; margin-right: auto; }
  .tabbar {
    left: 50%; transform: translateX(-50%); width: 560px;
    border-radius: 18px 18px 0 0;
    border-left: 1px solid var(--line); border-right: 1px solid var(--line);
  }
  .sheet { max-width: 560px; left: 50%; transform: translate(-50%, 102%); }
  .sheet.open { transform: translate(-50%, 0); }
  .sum-bar {
    left: 50%; transform: translateX(-50%); width: 560px;
    border-radius: 14px; bottom: calc(var(--nav-h) + var(--safe-b) + 8px);
  }
  .fab { right: calc(50vw - 280px + 16px); }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
