/* Mobile-first. Designed for a small Android phone first, then widened. */
:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --text: #1f1d1a;
  --muted: #6b665f;
  --border: #dedad3;
  --brand: #6b3e26;
  --brand-text: #ffffff;
  --ok-bg: #e7f3ea; --ok-text: #1d5b2d;
  --err-bg: #fbe9e7; --err-text: #8a1f11;
  --radius: 8px;
}
* { 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;
}
a { color: var(--brand); }
h1 { font-size: 1.35rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 1.5rem 0 .5rem; }

.topbar { background: var(--brand); color: var(--brand-text); }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; padding: .6rem 1rem; max-width: 1100px; margin: 0 auto; }
.topbar a { color: var(--brand-text); text-decoration: none; font-weight: 600; }
.nav-desktop { display: none; }
.nav summary { list-style: none; cursor: pointer; padding: .4rem .7rem; border: 1px solid rgba(255,255,255,.5); border-radius: var(--radius); }
.nav summary::-webkit-details-marker { display: none; }
.nav ul { list-style: none; margin: 0; padding: .5rem 0; position: absolute; right: 1rem; left: 1rem; background: var(--surface); border-radius: var(--radius); box-shadow: 0 6px 24px rgba(0,0,0,.18); z-index: 10; }
.nav li a, .nav li button { display: block; width: 100%; text-align: left; padding: .8rem 1rem; color: var(--text); font: inherit; font-weight: 500; background: none; border: 0; cursor: pointer; }
.nav li a[aria-current="page"] { color: var(--brand); font-weight: 700; }

main { padding: 1rem; max-width: 1100px; margin: 0 auto; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.page-head { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }
.muted { color: var(--muted); font-size: .9rem; }
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; background: var(--bg); border: 1px solid var(--border); font-size: .8rem; }

.btn { display: inline-block; padding: .65rem 1rem; min-height: 44px; border-radius: var(--radius); border: 1px solid var(--brand); background: var(--brand); color: var(--brand-text); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; }
.btn-secondary { background: var(--surface); color: var(--brand); }
.btn-danger { background: var(--surface); color: var(--err-text); border-color: var(--err-text); }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1rem; }

.messages { list-style: none; padding: 0; margin: 0 0 1rem; }
.messages li { padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: .5rem; background: var(--ok-bg); color: var(--ok-text); }
.messages li.error { background: var(--err-bg); color: var(--err-text); }

form .field { margin-bottom: 1rem; }
label { display: block; font-weight: 600; margin-bottom: .25rem; }
.field.checkbox label { display: flex; gap: .5rem; align-items: center; font-weight: 500; }
input[type=text], input[type=email], input[type=tel], input[type=number], input[type=password], input[type=search], select, textarea {
  width: 100%; padding: .65rem .75rem; font: inherit; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); min-height: 44px;
}
input[type=checkbox] { width: 1.25rem; height: 1.25rem; }
.helptext { color: var(--muted); font-size: .85rem; margin-top: .2rem; }
.errorlist { list-style: none; padding: 0; margin: .25rem 0 0; color: var(--err-text); font-size: .9rem; }

.filters { display: grid; gap: .5rem; margin-bottom: 1rem; }

/* Lists are stacked cards on phones and become tables on wider screens. */
.list { list-style: none; padding: 0; margin: 0; }
.list li { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: .5rem; }
.list li a { display: block; padding: .75rem 1rem; color: var(--text); text-decoration: none; }
.list .title { font-weight: 600; }
.list .meta { color: var(--muted); font-size: .85rem; }

dl.details { display: grid; grid-template-columns: 1fr; gap: .25rem 1rem; margin: 0; }
dl.details dt { color: var(--muted); font-size: .85rem; margin-top: .5rem; }
dl.details dd { margin: 0; }

table.simple { width: 100%; border-collapse: collapse; background: var(--surface); }
table.simple th, table.simple td { text-align: left; padding: .5rem; border-bottom: 1px solid var(--border); }

.tiles { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.tile { display: block; padding: 1.25rem 1rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); text-decoration: none; color: var(--text); font-weight: 600; }

.qr svg { width: 220px; height: 220px; background: #fff; }
code.secret { word-break: break-all; }

@media (min-width: 720px) {
  .nav-mobile { display: none; }
  .nav-desktop { display: block; }
  .nav ul { position: static; display: flex; gap: .25rem; background: none; box-shadow: none; padding: 0; }
  .nav li a, .nav li button { color: var(--brand-text); padding: .4rem .7rem; border-radius: var(--radius); }
  .nav li a[aria-current="page"] { background: rgba(255,255,255,.18); color: var(--brand-text); }
  .filters { grid-template-columns: 2fr 1fr 1fr; }
  dl.details { grid-template-columns: 12rem 1fr; }
  dl.details dt { margin-top: 0; }
  main { padding: 1.5rem; }
}

/* Stock screens */
.row-split { display: flex; justify-content: space-between; align-items: baseline; gap: .75rem; }
.qty { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.qty.negative { color: var(--err-text); }
.status-draft { background: #fff6e0; border-color: #e8c66a; }
.status-posted { background: var(--ok-bg); border-color: #9ccaa8; color: var(--ok-text); }
.status-reversed { background: var(--err-bg); border-color: #e2a59c; color: var(--err-text); }
.line { border-top: 1px solid var(--border); padding-top: .75rem; margin-top: .75rem; }
.line-qty { display: grid; grid-template-columns: 1fr 7rem; gap: .5rem; }
.count-line.counted { border-left: 4px solid #9ccaa8; }
.inline-check { display: flex; gap: .5rem; align-items: center; font-weight: 500; }
@media (min-width: 720px) {
  .filters-4 { grid-template-columns: 2fr 1fr 1fr 1fr; }
  .filters-4 .inline-check { grid-column: 1 / -1; }
}
.labour { grid-template-columns: 1fr 1fr; }
.meta .negative, span.negative { color: var(--err-text); }

/* Costing */
.cost-row { display: grid; gap: .25rem; padding: .6rem 0; border-bottom: 1px solid var(--border); }
.cost-row:last-child { border-bottom: 0; }
.cost-row label { margin: 0; }
.cost-row label .muted { display: block; font-weight: 400; }
.money-input { display: grid; grid-template-columns: auto 1fr auto; gap: .5rem; align-items: center; }
.money-input input { text-align: right; }
.money-input span { color: var(--muted); font-size: .9rem; }
.pack-cost { font-weight: 700; color: var(--brand); margin: .25rem 0; }
table.breakdown { width: 100%; border-collapse: collapse; margin: .5rem 0; }
table.breakdown td { padding: .4rem 0; border-bottom: 1px solid var(--border); vertical-align: top; }
table.breakdown td.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; padding-left: .75rem; }
table.breakdown tr.total td { font-weight: 700; border-bottom: 0; }
p.negative { color: var(--err-text); }
@media (min-width: 720px) {
  .cost-row { grid-template-columns: 1fr 18rem; align-items: center; }
}

/* Purchasing */
.match-issues { margin: 0; padding-left: 1.2rem; color: var(--err-text); }
.match-issues li { margin-bottom: .4rem; }
.match-ok { color: var(--ok-text); margin: 0; }

/* Sales */
details.more summary { cursor: pointer; color: var(--brand); padding: .25rem 0 .5rem; }

/* Ledger reports */
table.report tr.section td { font-weight: 700; padding-top: 1rem; border-bottom: 2px solid var(--text); }
.result { padding: .6rem 0; border-bottom: 1px solid var(--border); }
.result.final { border-bottom: 0; font-size: 1.1rem; }
table.report.three { font-size: .9rem; table-layout: fixed; }
table.report.three td:first-child { width: 46%; overflow-wrap: anywhere; }
table.report.three td.num { padding-left: .4rem; }

/* Attachments */
.file-row { display: flex; align-items: center; justify-content: space-between; }
.file-row a { flex: 1; }
.link-button { background: none; border: 0; color: var(--err-text); font: inherit; padding: .75rem 1rem; cursor: pointer; }
details.brand summary { list-style: none; cursor: pointer; }
details.brand summary::-webkit-details-marker { display: none; }
details.brand[open] summary { margin-bottom: .5rem; }
.row-split.meta { flex-wrap: wrap; gap: .25rem .75rem; }
.row-split.meta span { white-space: nowrap; }

/* Header: "+ New" and the menu sit together on the right. */
.topbar-actions { display: flex; gap: .5rem; align-items: center; }
.nav.create summary { font-weight: 600; }
.nav.create ul { max-height: 70vh; overflow-y: auto; }

/* Home page */
.stat-grid { display: grid; gap: .75rem; grid-template-columns: 1fr; margin-bottom: .5rem; }
.card.stat { display: block; margin: 0; text-decoration: none; color: var(--text); }
.stat-label { color: var(--muted); font-size: .9rem; }
.stat-value { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-value.negative { color: var(--err-text); }
.card.stat .meta { color: var(--muted); font-size: .85rem; }
.card.stat .meta.negative { color: var(--err-text); }
@media (min-width: 600px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 900px) { .stat-grid { grid-template-columns: repeat(4, 1fr); } }

/* Charts: two validated categorical slots; text stays in text colours. */
:root { --series-1: #2a78d6; --series-2: #eb6834; }
.chart { margin: 0 0 1rem; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart .bar.series-1, .swatch.series-1 { fill: var(--series-1); background: var(--series-1); }
.chart .bar.series-2, .swatch.series-2 { fill: var(--series-2); background: var(--series-2); }
.chart .baseline { stroke: var(--border); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .hit { fill: transparent; }
.chart .month:hover .hit { fill: var(--bg); }
.legend { display: flex; gap: 1rem; font-size: .85rem; color: var(--muted); margin-bottom: .5rem; }
.swatch { display: inline-block; width: .75rem; height: .75rem; border-radius: 2px; margin-right: .35rem; vertical-align: -1px; }
.chart details { margin-top: .5rem; font-size: .9rem; }
.chart summary { cursor: pointer; color: var(--brand); }
table.breakdown th { text-align: left; font-size: .85rem; color: var(--muted); font-weight: 600; padding: .4rem 0; }
table.breakdown th.num { text-align: right; padding-left: .75rem; }
@media (min-width: 720px) {
  .topbar-inner { position: relative; }
  .nav.create ul { position: absolute; display: block; top: 100%; right: 1rem; left: auto; width: 16rem; padding: .5rem 0; background: var(--surface); box-shadow: 0 6px 24px rgba(0,0,0,.18); }
  .nav.create li a { color: var(--text); padding: .6rem 1rem; border-radius: 0; }
  .topbar-actions { order: 3; }
}
.badge.negative { color: var(--err-text); border-color: var(--err-text); background: var(--err-bg); }
