:root { --g: #2e7d32; --g2: #1b5e20; --bg: #f4f7f2; --card: #fff; --tx: #1f2a1f; --mut: #6b786b; --bd: #dfe6dc; --red: #c62828; --amb: #ef6c00; --blu: #1565c0; }
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--tx); font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 16px; -webkit-text-size-adjust: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0 0 .5rem; }
.hidden { display: none !important; }

/* layout */
.shell { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }
.top { background: var(--g); color: #fff; padding: calc(10px + env(safe-area-inset-top)) 14px 10px; display: flex; align-items: center; gap: 10px; position: sticky; top: 0; z-index: 20; }
.top h1 { font-size: 1.05rem; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top .btn { background: rgba(255,255,255,.15); color: #fff; border-color: transparent; }
main { flex: 1; padding: 14px; padding-bottom: calc(84px + env(safe-area-inset-bottom)); max-width: 1100px; width: 100%; margin: 0 auto; }
nav.tabs { position: fixed; bottom: 0; left: 0; right: 0; background: #fff; border-top: 1px solid var(--bd); display: flex; z-index: 30; padding-bottom: env(safe-area-inset-bottom); }
nav.tabs button { flex: 1; background: none; border: 0; padding: 8px 2px 7px; font-size: .72rem; color: var(--mut); display: flex; flex-direction: column; align-items: center; gap: 2px; position: relative; min-height: 56px; }
nav.tabs button .ic { font-size: 1.35rem; line-height: 1; }
nav.tabs button.on { color: var(--g); font-weight: 600; }
nav.tabs .dot { position: absolute; top: 4px; right: calc(50% - 22px); background: var(--red); color: #fff; border-radius: 10px; font-size: .65rem; padding: 1px 5px; }
@media (min-width: 900px) {
  .shell { flex-direction: row; flex-wrap: wrap; }
  .top { width: 100%; }
  nav.tabs { position: sticky; top: 56px; align-self: flex-start; flex-direction: column; width: 190px; height: calc(100vh - 56px); border-top: 0; border-right: 1px solid var(--bd); padding-top: 8px; }
  nav.tabs button { flex: 0 0 auto; flex-direction: row; gap: 10px; font-size: .95rem; padding: 12px 16px; justify-content: flex-start; min-height: 0; }
  nav.tabs .dot { position: static; margin-left: auto; }
  main { padding-bottom: 20px; flex: 1; min-width: 0; }
}

/* componentes */
.card { background: var(--card); border: 1px solid var(--bd); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.sb { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.mut { color: var(--mut); font-size: .88rem; }
.b { font-weight: 600; }
.btn { border: 1px solid var(--bd); background: #fff; border-radius: 10px; padding: 9px 14px; min-height: 42px; font-size: .95rem; }
.btn.pri { background: var(--g); color: #fff; border-color: var(--g); }
.btn.dan { color: var(--red); border-color: #e7b8b8; }
.btn.sm { padding: 5px 10px; min-height: 34px; font-size: .85rem; }
.btn:disabled { opacity: .5; }
input, select, textarea { border: 1px solid #c9d3c6; border-radius: 10px; padding: 9px 11px; width: 100%; background: #fff; min-height: 42px; }
textarea { min-height: 80px; resize: vertical; }
label { display: block; font-size: .82rem; color: var(--mut); margin: 8px 0 3px; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 8px; }
.chip { border: 1px solid var(--bd); background: #fff; border-radius: 20px; padding: 6px 13px; white-space: nowrap; font-size: .9rem; }
.chip.on { background: var(--g); color: #fff; border-color: var(--g); }
.badge { display: inline-block; font-size: .75rem; padding: 2px 9px; border-radius: 10px; background: #e8eee6; font-weight: 600; }
.st-nuevo { background: #fff3cd; color: #8a6100; } .st-preparando { background: #dbeafe; color: #1d4ed8; }
.st-listo { background: #d6f5dc; color: #1b6b2c; } .st-entregado { background: #e5e7eb; color: #4b5563; } .st-cancelado { background: #fde0e0; color: var(--red); }
.grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.kpi { background: #fff; border: 1px solid var(--bd); border-radius: 12px; padding: 12px; }
.kpi .v { font-size: 1.5rem; font-weight: 700; color: var(--g2); }
table.t { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.t td, table.t th { padding: 6px 4px; border-bottom: 1px solid var(--bd); text-align: left; }
table.t td.r, table.t th.r { text-align: right; }
.bars { display: flex; align-items: flex-end; gap: 6px; height: 110px; margin-top: 8px; }
.bars div { flex: 1; background: #a5d6a7; border-radius: 4px 4px 0 0; position: relative; min-height: 2px; }
.bars div.cur { background: var(--g); }
.bars span { position: absolute; bottom: -18px; left: 0; right: 0; text-align: center; font-size: .7rem; color: var(--mut); }
.grid2 { display: grid; gap: 0 12px; grid-template-columns: 1fr; }
.grid3 { display: grid; gap: 0 10px; grid-template-columns: 1fr 1fr 1fr; }
.grid3 .nm { grid-column: 1 / -1; }
details.card > summary { padding: 4px 0; }
.top .lbl { display: none; }
@media (min-width: 640px) { .grid2 { grid-template-columns: 1fr 1fr; } .grid3 { grid-template-columns: 2fr 1fr 1fr 1fr; } .grid3 .nm { grid-column: auto; } .top .lbl { display: inline; } }

/* modal */
.ov { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.modal { background: #fff; width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; border-radius: 16px 16px 0 0; padding: 16px; padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
@media (min-width: 640px) { .ov { align-items: center; } .modal { border-radius: 16px; } }

/* chat */
.chat { background: #e8efe4; border-radius: 12px; padding: 10px; height: 52vh; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: 82%; padding: 7px 10px; border-radius: 12px; white-space: pre-wrap; word-wrap: break-word; font-size: .95rem; line-height: 1.3; }
.msg.in { background: #fff; align-self: flex-start; border-top-left-radius: 3px; }
.msg.out { background: #d9fdd3; align-self: flex-end; border-top-right-radius: 3px; }
.msg small { display: block; color: var(--mut); font-size: .68rem; margin-top: 2px; text-align: right; }

/* login / toast */
.login { max-width: 360px; margin: 14vh auto; padding: 22px; }
.login img { width: 84px; display: block; margin: 0 auto 10px; border-radius: 18px; }
#toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(90px + env(safe-area-inset-bottom)); background: #222; color: #fff; padding: 10px 16px; border-radius: 22px; z-index: 99; opacity: 0; pointer-events: none; transition: opacity .2s; max-width: 90vw; text-align: center; }
#toast.on { opacity: 1; }
.err { color: var(--red); font-size: .9rem; }
.flag { color: var(--red); font-weight: 700; }

/* v2: catálogo con 3 listas, pesaje, importación, cuentas */
.pl3 { display: grid; gap: 10px; grid-template-columns: 1fr; margin-top: 8px; }
.pl { background: #f7faf5; border: 1px solid var(--bd); border-radius: 10px; padding: 8px 10px; }
@media (min-width: 760px) { .pl3 { grid-template-columns: repeat(3, 1fr); } }
input.w { min-width: 70px; width: 100%; padding: 6px 8px; min-height: 36px; }
table.imp { font-size: .84rem; }
table.imp th select { min-width: 120px; font-size: .8rem; min-height: 34px; padding: 4px; }
table.imp tr.mut td { opacity: .55; }
.up { color: var(--red); font-weight: 600; } .down { color: var(--g2); font-weight: 600; }
@media print { body > *:not(.ov), .ov > .modal ~ * { display: none !important; } .shell { display: none !important; } .ov { position: static; background: none; } .modal { max-height: none; box-shadow: none; } .modal .row button, .modal details { display: none !important; } }

/* v3: con muchas pestañas, la barra de abajo se desliza en el celular */
@media (max-width: 899px) { nav.tabs { overflow-x: auto; } nav.tabs button { flex: 0 0 auto; min-width: 66px; } }

/* v3.2: consultador de precios */
.pres .pnm { font-size: 1.35rem; font-weight: 700; color: var(--tx); line-height: 1.2; }
.pl-row { display: grid; grid-template-columns: 1fr auto; column-gap: 10px; align-items: baseline; padding: 8px 10px; margin-top: 6px; border: 1px solid var(--bd); border-radius: 10px; background: #fafcf9; }
.pl-row .ln { font-weight: 600; } .pl-row .pv { font-size: 1.15rem; text-align: right; } .pl-row .pu { grid-column: 1 / -1; font-size: .82rem; color: var(--mut); }
.pl-row.hl { background: #e8f5e9; border: 2px solid var(--g); padding: 12px 12px; } .pl-row.hl .pv { font-size: 2rem; color: var(--g2); } .pl-row.hl .ln { font-size: 1.05rem; color: var(--g2); }
.pl-row .np { color: var(--mut); font-weight: 400; font-size: .95rem; }
.sug { display: flex; justify-content: space-between; gap: 10px; align-items: center; width: 100%; text-align: left; background: #fff; border: 0; border-bottom: 1px solid var(--bd); padding: 11px 4px; font: inherit; color: inherit; cursor: pointer; min-height: 48px; }
.sug:hover, .sug:focus { background: #f1f8f1; outline: none; } .pl-sug { padding-bottom: 4px; }
.pban { margin-top: 10px; padding: 10px 12px; background: #fff8e1; border: 1px solid #ffe08a; border-radius: 10px; }
.cam { position: relative; margin-top: 10px; border-radius: 12px; overflow: hidden; background: #000; max-width: 560px; }
.cam video { width: 100%; display: block; max-height: 55vh; object-fit: cover; }
.cam .aim { position: absolute; left: 10%; right: 10%; top: 28%; bottom: 28%; border: 3px solid rgba(255,255,255,.9); border-radius: 12px; box-shadow: 0 0 0 9999px rgba(0,0,0,.25); pointer-events: none; }
