:root {
  --bg: #fbf6ee;
  --surface: #ffffff;
  --text: #2b1d12;
  --muted: #7b6a5c;
  --line: #e7dccd;
  --brand: #7a3e12;
  --brand-2: #a45a1f;
  --brand-ink: #ffffff;
  --ok: #1f7a3d;
  --ok-bg: #e4f4e9;
  --bad: #b3261e;
  --bad-bg: #fbe6e4;
  --warn: #9a5b00;
  --warn-bg: #fff3d6;
  --info-bg: #e8eef8;
  --radius: 12px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1 { font-size: 1.5rem; margin: 0.4em 0 0.5em; line-height: 1.2; }
h2 { font-size: 1.15rem; margin: 1.2em 0 0.5em; }
h3 { font-size: 1.05rem; margin: 0; }
a { color: var(--brand); }
p { margin: 0.4em 0; }

/* header */
header { position: sticky; top: 0; z-index: 10; background: var(--brand); color: var(--brand-ink); }
.bar {
  display: flex; align-items: center; gap: 8px;
  max-width: 960px; margin: 0 auto; padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
}
.brand { color: inherit; text-decoration: none; font-weight: 700; font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spacer { flex: 1; }
.icon-btn, .link-btn {
  color: inherit; background: transparent; border: 1px solid rgba(255,255,255,.4);
  border-radius: 8px; padding: 6px 10px; font: inherit; font-size: .9rem; text-decoration: none; cursor: pointer;
}
.demo-banner { background: var(--warn-bg); color: var(--warn); text-align: center; padding: 6px 16px; font-size: .85rem; }

main { max-width: 960px; margin: 0 auto; padding: 8px 16px 64px; }
section.narrow, .narrow { max-width: 520px; margin-left: auto; margin-right: auto; }

/* cards */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; margin: 12px 0;
}
.card.alert { background: var(--warn-bg); border-color: #f0d9a2; }
.card h2 { margin-top: 0; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row.between { justify-content: space-between; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 480px) { .grid2 { grid-template-columns: 1fr; } }
.center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.error { color: var(--bad); margin: 0; }
.warn-text { color: var(--warn); }
.hint { color: var(--muted); font-style: italic; }

/* forms */
label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: .95rem; }
label.inline { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }
label.block { margin: 12px 0; }
input, select, textarea {
  font: inherit; font-weight: 400; color: var(--text); background: #fff;
  border: 1px solid #cdbfae; border-radius: 8px; padding: 10px 12px; min-height: 44px; width: 100%;
}
input[type=checkbox] { width: 20px; height: 20px; min-height: 0; accent-color: var(--brand); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-2); outline-offset: 1px; }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin: 0; }
legend { font-weight: 600; padding: 0 4px; }
.checks { display: flex; flex-wrap: wrap; gap: 8px 16px; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 8px 16px; border-radius: 10px; border: 1px solid #cdbfae;
  background: #fff; color: var(--text); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:hover { border-color: var(--brand-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { background: var(--brand-2); }
.btn.big { width: 100%; min-height: 52px; font-size: 1.05rem; margin-top: 8px; }
.btn.small { min-height: 36px; padding: 4px 10px; font-size: .875rem; }
.btn.link { border: 0; background: none; color: var(--brand); padding: 0; min-height: 0; text-decoration: underline; }
.btn:disabled { opacity: .5; cursor: default; }

/* status */
.status { font-weight: 600; }
.status.ok { color: var(--ok); }
.status.bad { color: var(--bad); }
.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .8rem; font-weight: 600; background: var(--info-bg); white-space: nowrap; }
.tag.submitted { background: var(--info-bg); color: #1f4a8a; }
.tag.confirmed { background: var(--ok-bg); color: var(--ok); }
.tag.delivered { background: #eee; color: #444; }
.tag.cancelled { background: #eee; color: #777; text-decoration: line-through; }
.tag.bad { background: var(--bad-bg); color: var(--bad); }

/* product cards (count + order) */
.product-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.product.invalid { border-color: var(--bad); box-shadow: 0 0 0 2px var(--bad-bg); }
.count-inputs { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 8px; }
.facts { list-style: none; padding: 0; margin: 8px 0; font-size: .92rem; }
.facts li { padding: 2px 0; }
.stepper { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.stepper input { width: 90px; text-align: center; font-size: 1.2rem; font-weight: 700; }
.stepper .unit { flex: 1; color: var(--muted); }
.btn.step { width: 52px; font-size: 1.4rem; padding: 0; }
.total-boxes { font-weight: 700; font-size: 1.1rem; text-align: right; }
ul.plain { list-style: none; padding: 0; margin: 0; }
ul.plain li { padding: 4px 0; border-bottom: 1px solid var(--line); }
ul.plain li:last-child { border: 0; }

/* admin */
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--line); margin: 8px 0 4px; overflow-x: auto; }
.tabs a { padding: 10px 14px; text-decoration: none; color: var(--muted); font-weight: 600; border-bottom: 3px solid transparent; margin-bottom: -2px; white-space: nowrap; }
.tabs a.active { color: var(--brand); border-color: var(--brand); }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; margin: 12px 0; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.tile span { display: block; color: var(--muted); font-size: .85rem; }
.tile b { font-size: 1.5rem; }
.tile.bad { background: var(--bad-bg); border-color: #f1c2bd; }
.tile.bad b { color: var(--bad); }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: .93rem; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: #f6efe4; font-size: .82rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; }
tr.missing td { background: #fff8f7; }
tr.inactive td { color: var(--muted); }
tr.total td { background: #f6efe4; }
td.actions { white-space: normal; min-width: 200px; }
td.actions .btn { margin: 2px 0; }
table.range input[type=number] { width: 90px; min-height: 36px; padding: 4px 8px; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 150%);
  background: #2b1d12; color: #fff; padding: 12px 18px; border-radius: 10px; max-width: calc(100% - 32px);
  transition: transform .2s ease; z-index: 50; box-shadow: 0 6px 20px rgba(0,0,0,.2); pointer-events: none;
}
.toast.show { transform: translate(-50%, 0); }
.toast.bad { background: var(--bad); }
.toast.warn { background: var(--warn); }

@media print {
  header, .demo-banner, .tabs, .no-print, .btn { display: none !important; }
  body { background: #fff; }
  .table-wrap { border: 0; }
}
