:root {
  --bg: #f6f7f5; --surface: #ffffff; --ink: #1c2421; --muted: #5f6b66; --line: #e2e6e3;
  --brand: #14532d; --brand-2: #1f7a45; --brand-soft: #e6f2ea;
  --warn: #9a5b00; --warn-soft: #fff4e0; --bad: #b42318; --bad-soft: #fdecea; --ok: #1f7a45; --ok-soft: #e6f2ea;
  --radius: 10px; --nav-w: 232px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; font-size: 15px; line-height: 1.45; }
h1 { font-size: 1.35rem; margin: 0 0 14px; }
h2 { font-size: 1.05rem; margin: 22px 0 10px; }
a { color: var(--brand-2); }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.center { display: grid; place-items: center; min-height: 60vh; }
.right { text-align: right; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Layout */
.shell { display: grid; grid-template-columns: var(--nav-w) 1fr; min-height: 100vh; }
.side { background: var(--brand); color: #fff; padding: 16px 10px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.side .brand { font-weight: 700; font-size: 1.1rem; padding: 4px 10px 2px; }
.side .who { font-size: 0.8rem; opacity: 0.8; padding: 0 10px 14px; }
.side a { display: block; color: #fff; text-decoration: none; padding: 8px 10px; border-radius: 8px; opacity: 0.9; }
.side a:hover { background: rgba(255,255,255,0.1); }
.side a.active { background: rgba(255,255,255,0.18); opacity: 1; font-weight: 600; }
.side .group { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em; opacity: 0.6; padding: 14px 10px 4px; }
.main { padding: 20px 24px 90px; max-width: 1200px; width: 100%; min-width: 0; }
@media (min-width: 821px) { .hide-desktop { display: none !important; } }
.topbar { display: flex; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 12px; flex-wrap: wrap; }
.status-pill { font-size: 0.8rem; padding: 3px 10px; border-radius: 99px; background: var(--ok-soft); color: var(--ok); }
.status-pill.off { background: var(--warn-soft); color: var(--warn); }
.bottomnav { display: none; }

@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .side { display: none; }
  .side.open { display: block; position: fixed; inset: 0 30% 0 0; z-index: 50; height: 100%; }
  .main { padding: 14px 12px 96px; }
  .bottomnav { display: flex; position: fixed; bottom: 0; left: 0; right: 0; background: var(--surface); border-top: 1px solid var(--line);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); z-index: 40; justify-content: space-around; }
  .bottomnav a { flex: 1; text-align: center; font-size: 0.72rem; color: var(--muted); text-decoration: none; padding: 4px 2px; }
  .bottomnav a b { display: block; font-size: 1.15rem; line-height: 1.2; }
  .bottomnav a.active { color: var(--brand); font-weight: 600; }
}

/* Components */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.kpi .label { font-size: 0.8rem; color: var(--muted); }
.kpi .value { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }
.kpi .sub { font-size: 0.8rem; color: var(--muted); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.row > * { flex: 1 1 150px; }
label { display: block; font-size: 0.82rem; color: var(--muted); margin-bottom: 10px; }
label > input, label > select, label > textarea { margin-top: 4px; }
input, select, textarea, button { font: inherit; }
input, select, textarea { width: 100%; padding: 9px 10px; border: 1px solid #cfd6d2; border-radius: 8px; background: #fff; color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-2); outline-offset: 0; border-color: transparent; }
input[type=checkbox] { width: auto; margin-right: 6px; }
.check { display: flex; align-items: center; color: var(--ink); font-size: 0.9rem; }
button, .btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 14px; border-radius: 8px; border: 1px solid #cfd6d2;
  background: #fff; color: var(--ink); cursor: pointer; text-decoration: none; font-weight: 500; white-space: nowrap; }
button.primary, .btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
button.danger { color: var(--bad); border-color: #f0c2bd; }
button.big { width: 100%; padding: 14px; font-size: 1.05rem; }
button.sm { padding: 4px 10px; font-size: 0.85rem; }
button:disabled { opacity: 0.55; cursor: default; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button.on { background: var(--brand-soft); border-color: var(--brand-2); color: var(--brand); font-weight: 600; }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: #f1f4f2; font-weight: 600; font-size: 0.8rem; color: var(--muted); position: sticky; top: 0; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f7faf8; }
tr.voided td { color: #98a29e; text-decoration: line-through; }
tfoot td { font-weight: 700; background: #f7f9f8; }

.badge { display: inline-block; font-size: 0.75rem; padding: 1px 8px; border-radius: 99px; background: #eef1ef; color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.low, .badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.out, .badge.negative, .badge.bad { background: var(--bad-soft); color: var(--bad); }
.alert { padding: 10px 12px; border-radius: 8px; background: var(--warn-soft); color: var(--warn); margin-bottom: 10px; font-size: 0.9rem; }
.alert.bad { background: var(--bad-soft); color: var(--bad); }
.alert.ok { background: var(--ok-soft); color: var(--ok); }

/* Selling screen */
.pick-list { max-height: 330px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; }
.pick { display: flex; justify-content: space-between; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; background: #fff; }
.pick:hover { background: var(--brand-soft); }
.pick:last-child { border-bottom: 0; }
.cart-line { display: grid; grid-template-columns: 1fr 92px 110px 30px; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.cart-line input { padding: 7px 8px; }
.qty { display: flex; align-items: center; gap: 4px; }
.qty button { padding: 6px 9px; }
.qty input { text-align: center; padding: 7px 2px; }
.total-bar { display: flex; justify-content: space-between; font-size: 1.2rem; font-weight: 700; padding: 12px 0; }
@media (max-width: 520px) { .cart-line { grid-template-columns: 1fr 86px 96px 28px; font-size: 0.88rem; } }

/* Chart */
.chart svg { width: 100%; height: 200px; display: block; }
.chart .bar { fill: #1f7a45; }
.chart .bar:hover { fill: #14532d; }
.chart .axis { stroke: #d5dbd8; }
.chart text { fill: var(--muted); font-size: 10px; }

dialog { border: 0; border-radius: 12px; padding: 0; width: min(560px, 94vw); max-height: 90vh; box-shadow: 0 20px 60px rgba(0,0,0,0.25); }
dialog::backdrop { background: rgba(10,20,15,0.45); }
dialog .dhead { padding: 14px 16px; border-bottom: 1px solid var(--line); font-weight: 700; display: flex; justify-content: space-between; }
dialog .dbody { padding: 16px; overflow-y: auto; max-height: calc(90vh - 120px); }
dialog .dfoot { padding: 12px 16px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; }

#toasts { position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 1000; display: grid; gap: 8px; width: min(440px, 92vw); }
.toast { background: var(--ink); color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,0.2); font-size: 0.92rem; }
.toast.bad { background: var(--bad); }
.toast.ok { background: var(--brand); }

.login { max-width: 380px; margin: 10vh auto; padding: 0 16px; }
.login .logo { font-size: 1.6rem; font-weight: 800; color: var(--brand); margin-bottom: 4px; }
.hide-mobile { }
@media (max-width: 820px) { .hide-mobile { display: none; } }
@media print { .side, .bottomnav, .topbar button { display: none !important; } .shell { display: block; } }
dialog .grid { grid-template-columns: repeat(auto-fit, minmax(105px, 1fr)); gap: 8px; }
dialog .kpi { padding: 8px 10px; margin-bottom: 8px; }
dialog .kpi .value { font-size: 1.02rem; }
