:root {
  --g: #2f6b3a; --g2: #e5f0e1; --ink: #1d2a1f; --mut: #66756a; --bg: #f5f7f2;
  --card: #fff; --red: #c0392b; --line: #dfe6db; --tabh: 62px;
  color-scheme: light;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  font: 18px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--ink);
  padding-bottom: calc(var(--tabh) + env(safe-area-inset-bottom) + 20px);
  -webkit-text-size-adjust: 100%;
}
body.hascart { padding-bottom: calc(var(--tabh) + env(safe-area-inset-bottom) + 96px); }
button { font: inherit; color: inherit; cursor: pointer; }

.top { position: sticky; top: 0; z-index: 5; background: var(--g); color: #fff;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 12px; }
.top h1 { margin: 0 auto; font-size: 24px; max-width: 608px; }
main { padding: 16px; max-width: 640px; margin: 0 auto; }

.tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; display: flex;
  height: calc(var(--tabh) + env(safe-area-inset-bottom)); padding: 4px 4px env(safe-area-inset-bottom);
  background: #fff; border-top: 1px solid var(--line); }
.tabs button { flex: 1; border: 0; background: none; font-size: 24px; border-radius: 12px; margin: 2px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; color: var(--mut); }
.tabs button span { font-size: 12px; font-weight: 600; }
.tabs button.on { background: var(--g2); color: var(--g); }

/* Vender */
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.tile { position: relative; text-align: left; border: 2px solid var(--line); background: var(--card);
  border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 3px; min-height: 100px; }
.tile b { font-size: 18px; line-height: 1.2; overflow-wrap: anywhere; }
.tile .price { font-size: 20px; font-weight: 700; color: var(--g); margin-top: auto; }
.tile .stock { font-size: 14px; color: var(--mut); }
.tile.out { opacity: .55; }
.tile.sel { border-color: var(--g); background: var(--g2); opacity: 1; }
.badge { position: absolute; top: -8px; right: -6px; background: var(--g); color: #fff; border-radius: 999px;
  min-width: 32px; height: 32px; padding: 0 8px; display: grid; place-items: center; font-weight: 800; font-size: 16px;
  box-shadow: 0 2px 6px rgba(0,0,0,.2); }
.low { color: var(--red) !important; font-weight: 700; }

#cartbar { position: fixed; left: 0; right: 0; z-index: 9; padding: 8px 12px;
  bottom: calc(var(--tabh) + env(safe-area-inset-bottom)); }
.cartbtn { width: 100%; max-width: 616px; margin: 0 auto; display: flex; align-items: center; gap: 12px;
  background: var(--g); color: #fff; border: 0; border-radius: 16px; padding: 16px 18px;
  box-shadow: 0 6px 20px rgba(0,0,0,.22); }
.cartbtn b { margin-left: auto; font-size: 21px; }
.cartbtn .go { background: rgba(255,255,255,.18); padding: 6px 12px; border-radius: 10px; font-weight: 700; }

/* Generic */
.btn { border: 0; border-radius: 12px; padding: 14px 18px; background: var(--g2); color: var(--g); font-weight: 700; }
.btn.primary { background: var(--g); color: #fff; }
.btn.danger { background: #fbe9e7; color: var(--red); }
.btn.ghost { background: transparent; color: var(--mut); }
.btn.block { display: block; width: 100%; }
.btn.big { padding: 18px; font-size: 20px; }
.btn:disabled { opacity: .4; }
.search, .field input { width: 100%; font: inherit; font-size: 18px; padding: 14px; border: 2px solid var(--line);
  border-radius: 12px; background: #fff; color: var(--ink); -webkit-appearance: none; appearance: none; }
.search { margin-bottom: 12px; }
input:focus { outline: none; border-color: var(--g); }
.list { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; background: var(--card);
  border: 2px solid var(--line); border-radius: 14px; padding: 13px 14px; }
.row .main { flex: 1; min-width: 0; }
.row .main b { display: block; overflow-wrap: anywhere; }
.row .sub { display: block; font-size: 15px; color: var(--mut); }
.row .right { text-align: right; font-weight: 800; font-size: 20px; white-space: nowrap; }
.row .right small { display: block; font-size: 12px; color: var(--mut); font-weight: 600; }
.row.pick.on { border-color: var(--g); background: var(--g2); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px; margin-bottom: 12px; }
.card p { margin: 6px 0; }
h2 { font-size: 19px; margin: 22px 0 10px; }
.alert { background: #fff3dc; color: #6e4500; border-radius: 12px; padding: 12px 14px; margin: 12px 0; font-size: 16px; }
.alert .btn { margin-top: 8px; padding: 10px 14px; font-size: 16px; }
.muted { color: var(--mut); } .center { text-align: center; } .small { font-size: 14px; }
.debt { color: var(--red); }
.ok { color: var(--g); }
.empty { text-align: center; padding: 36px 12px; }
.empty .icon { font-size: 60px; }
.empty p { color: var(--mut); }
.tag { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px;
  background: #fff3dc; color: #6e4500; margin-left: 6px; vertical-align: 2px; }

/* Reportes */
.seg { display: flex; background: #e4e9e0; border-radius: 12px; padding: 4px; margin-bottom: 12px; }
.seg button { flex: 1; border: 0; background: none; font-size: 16px; font-weight: 700; padding: 10px 0;
  border-radius: 9px; color: var(--mut); }
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.nav button { font-size: 26px; width: 48px; height: 48px; border-radius: 12px; background: #fff; border: 1px solid var(--line); }
.nav button:disabled { opacity: .3; }
.nav b { font-size: 18px; text-align: center; }
.nav b::first-letter { text-transform: uppercase; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.stat small { display: block; color: var(--mut); font-size: 14px; font-weight: 600; }
.stat b { font-size: 22px; }
.stat.wide { grid-column: span 2; background: var(--g); color: #fff; border: 0; }
.stat.wide small { color: #cfe5ca; }
.stat.wide b { font-size: 32px; }
.bar { height: 8px; background: var(--g2); border-radius: 99px; margin-top: 6px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--g); border-radius: 99px; }

/* Sheet */
#sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.42); z-index: 20;
  display: flex; align-items: flex-end; justify-content: center; }
#sheet-backdrop[hidden] { display: none; }
#sheet { background: var(--bg); width: 100%; max-width: 640px; max-height: 92vh; max-height: 92dvh; overflow: auto;
  border-radius: 20px 20px 0 0; padding: 18px 16px calc(24px + env(safe-area-inset-bottom));
  -webkit-overflow-scrolling: touch; overscroll-behavior: contain; animation: up .18s ease-out; }
@keyframes up { from { transform: translateY(40px); } to { transform: none; opacity: 1; } }
.sheethead { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.sheethead h2 { margin: 4px 0 0; font-size: 22px; overflow-wrap: anywhere; }
.x { flex: none; border: 0; background: #e4e9e0; border-radius: 999px; width: 40px; height: 40px; font-size: 18px; }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 15px; color: var(--mut); margin-bottom: 6px; font-weight: 700; }
.inline { display: flex; gap: 8px; }
.inline input { flex: 1; min-width: 0; }
.line { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 12px; margin-bottom: 8px; }
.line .lname { font-weight: 700; }
.lrow { display: flex; align-items: center; gap: 10px; justify-content: space-between; margin-top: 8px; flex-wrap: wrap; }
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper button { width: 46px; height: 46px; border-radius: 12px; border: 0; background: var(--g2); color: var(--g);
  font-size: 26px; font-weight: 800; line-height: 1; }
.stepper span { min-width: 34px; text-align: center; font-weight: 800; font-size: 20px; }
.pricein { display: flex; align-items: center; gap: 6px; font-size: 15px; color: var(--mut); font-weight: 600; }
.pricein input { width: 110px; font: inherit; font-size: 18px; padding: 10px; border: 2px solid var(--line);
  border-radius: 10px; text-align: right; color: var(--ink); background: #fff; }
.lsub { text-align: right; font-weight: 800; margin-top: 6px; }
.total { display: flex; justify-content: space-between; align-items: baseline; font-size: 22px; font-weight: 800; padding: 10px 4px; }
.actions { display: grid; gap: 10px; margin-top: 10px; }
.actions.two { grid-template-columns: 1fr 1fr; }
.hist { display: flex; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.hist:last-child { border-bottom: 0; }
.hist .sub { font-size: 14px; color: var(--mut); }
.hist b { white-space: nowrap; }
button.hist { width: 100%; background: none; border: 0; border-bottom: 1px solid var(--line); text-align: left; }

#toast { position: fixed; left: 50%; transform: translateX(-50%); z-index: 30; background: #1d2a1f; color: #fff;
  bottom: calc(var(--tabh) + env(safe-area-inset-bottom) + 96px); padding: 12px 18px; border-radius: 12px;
  font-size: 16px; max-width: calc(100% - 32px); text-align: center; box-shadow: 0 6px 20px rgba(0,0,0,.25); }
