:root {
  --g9: #0b3b24; --g8: #14532d; --g7: #15803d; --g6: #16a34a; --g2: #bbf7d0; --g1: #dcfce7; --g0: #f0fdf4;
  --ink: #12261b; --muted: #5d6e64; --line: #dce8e0; --line2: #c7d7cc; --bg: #f5f9f6; --card: #fff;
  --amber: #a14b06; --amber-bg: #fef3c7; --amber-line: #fcd34d;
  --red: #b91c1c; --red-bg: #fee2e2;
  --r: 8px;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
}
* { box-sizing: border-box; }
html { font-size: 14px; -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg); line-height: 1.4; }
a { color: var(--g7); }
h1 { font-size: 1.3rem; margin: 0; letter-spacing: -.01em; }
h2 { font-size: .95rem; margin: 0 0 8px; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .mono { font-family: var(--mono); }
.err { color: var(--red); margin: 6px 0; }
.nowrap { white-space: nowrap; }
.hint { color: var(--muted); font-size: .8rem; margin: 8px 12px; }
.row { display: flex; align-items: center; flex-wrap: wrap; } .gap { gap: 8px; } .end { justify-content: flex-end; }
.stack { display: grid; gap: 12px; align-content: start; }

/* ---- top bar ---- */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px; height: 48px; padding: 0 16px; background: var(--g8); color: #fff; }
.brand { display: flex; align-items: center; gap: 8px; color: #fff; text-decoration: none; font-weight: 700; white-space: nowrap; }
.logo { width: 18px; height: 18px; border-radius: 4px; background: #fff; position: relative; flex: none; }
.logo::after { content: ""; position: absolute; inset: 4px; background: var(--g6); transform: rotate(45deg); border-radius: 1px; }
.topbar nav { display: flex; gap: 2px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.topbar nav a { color: #d1fae5; text-decoration: none; padding: 6px 10px; border-radius: 6px; white-space: nowrap; }
.topbar nav a:hover { background: rgba(255,255,255,.1); }
.topbar nav a.active { background: #fff; color: var(--g8); font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 10px; flex: none; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #9ca3af; }
.dot.ok { background: #4ade80; box-shadow: 0 0 0 3px rgba(74,222,128,.25); }
.dot.bad { background: #f87171; box-shadow: 0 0 0 3px rgba(248,113,113,.3); }
@media (max-width: 640px) { .brand-text { display: none; } .topbar { gap: 8px; padding: 0 10px; } .topbar nav a { padding: 6px 8px; } }

/* ---- layout ---- */
.wrap { max-width: 1240px; margin: 0 auto; padding: 16px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 12px; }
.card.pad0 { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.card-head h2 { margin: 0; }
.split { display: grid; grid-template-columns: minmax(0, 1fr) 290px; gap: 12px; align-items: start; }
@media (max-width: 980px) { .split { grid-template-columns: minmax(0, 1fr); } }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; align-items: end; }
.fld { display: grid; gap: 4px; font-size: .78rem; font-weight: 600; color: var(--muted); }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.filters .in { width: auto; }
.filters #q { flex: 1 1 220px; }
.filters label { display: flex; align-items: center; gap: 6px; font-size: .85rem; color: var(--muted); }

/* ---- inputs & buttons ---- */
.in { width: 100%; padding: 5px 8px; border: 1px solid var(--line2); border-radius: 6px; font: inherit; color: inherit; background: #fff; min-height: 30px; }
.in:focus { outline: 2px solid var(--g6); outline-offset: -1px; border-color: var(--g6); }
.in.num { text-align: right; font-variant-numeric: tabular-nums; }
.in.invalid { border-color: var(--red); background: #fff7f7; }
textarea.in { font-family: var(--mono); font-size: .85rem; resize: vertical; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 6px 12px; border: 1px solid var(--g7); border-radius: 6px; background: var(--g7); color: #fff; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--g8); border-color: var(--g8); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.ghost { background: #fff; color: var(--g8); border-color: var(--line2); }
.btn.ghost:hover { background: var(--g0); }
.btn.danger { background: #fff; color: var(--red); border-color: #fecaca; }
.btn.danger:hover { background: var(--red-bg); }
.btn.light { background: rgba(255,255,255,.12); border-color: rgba(255,255,255,.25); color: #fff; }
.btn.light:hover { background: rgba(255,255,255,.22); }
.btn.sm { padding: 3px 9px; font-size: .85rem; }
.btn.block { width: 100%; padding: 9px; font-size: 1rem; }
.icon-btn { border: 0; background: none; color: var(--muted); font-size: 1.15rem; line-height: 1; padding: 4px 6px; border-radius: 4px; cursor: pointer; }
.icon-btn:hover { background: var(--red-bg); color: var(--red); }
body:not(.is-admin) .admin-only { display: none !important; }
body.is-admin .guest-only { display: none !important; }

/* ---- tables ---- */
.table-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; }
.tbl th { position: sticky; top: 0; background: var(--g0); color: var(--muted); font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 5px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tbody tr:hover td { background: #fafdfb; }
.tbl tfoot td { font-weight: 700; background: var(--g0); border-bottom: 0; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl .group td { background: var(--g0); color: var(--g8); font-size: .72rem; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; padding-top: 8px; }
.tbl .empty { text-align: center; color: var(--muted); padding: 24px; }
.tbl a.id { font-family: var(--mono); font-weight: 600; text-decoration: none; }
.tbl a.id:hover { text-decoration: underline; }
td.ret.has, .ret-has { background: var(--amber-bg) !important; color: var(--amber); font-weight: 700; }
td.cub { font-weight: 700; color: var(--g8); }
.calc td { padding: 4px 6px; }
.calc .c-qty { width: 110px; }
.calc .c-notes { min-width: 110px; }

/* ---- KPIs ---- */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin: 12px 0; }
@media (max-width: 720px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: var(--r); padding: 8px 12px; min-width: 0; }
.kpi span { display: block; font-size: .7rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.kpi strong { display: block; font-size: 1.45rem; font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; }
.kpi.primary { background: var(--g8); border-color: var(--g8); color: #fff; }
.kpi.primary span { color: var(--g2); }
.kpi.warn.has { background: var(--amber-bg); border-color: var(--amber-line); }
.kpi.warn.has strong { color: var(--amber); }

/* ---- badges / chips ---- */
.badge { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: .75rem; font-weight: 700; border: 0; font-family: inherit; white-space: nowrap; }
.badge.pending { background: var(--amber-bg); color: var(--amber); }
.badge.done { background: var(--g1); color: var(--g8); }
button.badge { cursor: pointer; }
button.badge:hover { outline: 2px solid currentColor; outline-offset: 1px; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--g1); color: var(--g8); border-radius: 999px; padding: 2px 4px 2px 10px; font-weight: 600; font-size: .85rem; }
.chip button { border: 0; background: none; color: inherit; cursor: pointer; font-size: 1rem; line-height: 1; padding: 0 4px; }

/* ---- give back ---- */
.giveback.has { border-color: var(--amber-line); background: #fffbeb; }
.giveback.has h2 { color: var(--amber); }
.gb-list { list-style: none; margin: 0; padding: 0; }
.gb-list li { display: flex; justify-content: space-between; gap: 8px; padding: 4px 0; border-bottom: 1px dashed var(--amber-line); }
.gb-list li:last-child { border-bottom: 0; }
.gb-list b { color: var(--amber); font-variant-numeric: tabular-nums; }
.ok-line { color: var(--g7); font-weight: 600; margin: 0; }
.total-line { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.total-line strong { font-size: 1.3rem; color: var(--g8); }
.saved { margin-top: 10px; padding: 8px 10px; border-radius: 6px; background: var(--g1); color: var(--g9); font-size: .9rem; }
.saved a { font-family: var(--mono); font-weight: 700; }
.preview { min-height: 30px; display: flex; align-items: center; font-weight: 600; color: var(--g8); font-size: .9rem; }
details.bulk { margin-top: 12px; }
details.bulk summary { cursor: pointer; color: var(--g7); font-weight: 600; }
details.bulk textarea { margin: 8px 0; }

/* ---- receipt ---- */
.rc-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.rc-head h1 { font-family: var(--mono); font-size: 1.5rem; }
.meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px 16px; margin: 12px 0 0; }
.meta div { min-width: 0; }
.meta dt { font-size: .7rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.meta dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }

/* ---- picker ---- */
.picker { position: fixed; z-index: 60; max-height: 300px; max-width: calc(100vw - 16px); overflow: auto; background: #fff; border: 1px solid var(--line2); border-radius: 6px; box-shadow: 0 10px 28px rgba(10,40,25,.16); }
.picker-group { position: sticky; top: 0; background: var(--g0); color: var(--g8); font-size: .68rem; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; padding: 4px 10px; border-bottom: 1px solid var(--line); }
.picker-opt { display: flex; justify-content: space-between; gap: 14px; padding: 5px 10px; cursor: pointer; }
.picker-opt small { color: var(--muted); white-space: nowrap; }
.picker-opt.active, .picker-opt:hover { background: var(--g1); }
.picker-empty { padding: 8px 10px; color: var(--muted); }

/* ---- modal / toast ---- */
dialog.modal { border: 1px solid var(--line); border-radius: 10px; padding: 16px; width: min(360px, calc(100vw - 32px)); box-shadow: 0 20px 50px rgba(0,0,0,.2); }
dialog.modal::backdrop { background: rgba(8,30,18,.45); }
dialog.modal .in { margin: 8px 0; }
#toasts { position: fixed; right: 16px; bottom: 16px; z-index: 80; display: grid; gap: 8px; max-width: calc(100vw - 32px); }
.toast { background: var(--g8); color: #fff; padding: 8px 14px; border-radius: 6px; box-shadow: 0 6px 20px rgba(0,0,0,.18); font-weight: 600; }
.toast.error { background: var(--red); }

@media print {
  .no-print, .topbar, #toasts { display: none !important; }
  body { background: #fff; }
  .wrap { padding: 0; max-width: none; }
  .card { border: 0; padding: 0; }
  .tbl th { position: static; }
}
