:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --surface-2: #efe9df;
  --ink: #1f1c18;
  --ink-2: #57514a;
  --ink-3: #857d73;
  --line: #e0d8cc;
  --brand: #2f5d3a;
  --brand-ink: #ffffff;
  --topbar: #2f5d3a;
  --wood: #a0622d;
  --good: #1f7a3d;  --good-bg: #e2f3e7;
  --warn: #8a5a00;  --warn-bg: #fdf0d3;
  --bad: #b3261e;   --bad-bg: #fbe3e1;
  --info: #1d5a8c;  --info-bg: #e2eef8;
  --bar: #2f5d3a;
  --radius: 14px;
  --tabbar-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15130f;
    --surface: #211e19;
    --surface-2: #2b2721;
    --ink: #f3eee6;
    --ink-2: #c3bbb0;
    --ink-3: #8f877c;
    --line: #3a352d;
    --brand: #5fa872;
    --topbar: #1c3523;
    --brand-ink: #0d1a10;
    --wood: #d99a5f;
    --good: #7fd498;  --good-bg: #183722;
    --warn: #f0c062;  --warn-bg: #3a2c10;
    --bad: #ff9d94;   --bad-bg: #44191a;
    --info: #8cc3f0;  --info-bg: #15304a;
    --bar: #6fbf83;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15130f;
  --surface: #211e19;
  --surface-2: #2b2721;
  --ink: #f3eee6;
  --ink-2: #c3bbb0;
  --ink-3: #8f877c;
  --line: #3a352d;
  --brand: #5fa872;
  --topbar: #1c3523;
  --brand-ink: #0d1a10;
  --wood: #d99a5f;
  --good: #7fd498;  --good-bg: #183722;
  --warn: #f0c062;  --warn-bg: #3a2c10;
  --bad: #ff9d94;   --bad-bg: #44191a;
  --info: #8cc3f0;  --info-bg: #15304a;
  --bar: #6fbf83;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  min-height: 100dvh;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
}
button, input, select, textarea { font: inherit; color: inherit; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--topbar); color: #fff;
}
.brand { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; min-width: 0; }
.brand .logo { display: block; height: 36px; width: auto; }
.brand-sub { font-size: 12.5px; opacity: .9; white-space: nowrap; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.theme-btn {
  width: 38px; height: 38px; border-radius: 999px; border: 1px solid rgba(255,255,255,.7);
  background: transparent; color: #fff; display: grid; place-items: center; padding: 0;
}
.theme-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.role-btn {
  border: 1px solid currentColor; background: transparent; color: inherit;
  border-radius: 999px; padding: 6px 12px; font-size: 14px; font-weight: 600;
}
.role-btn.mgr { background: #fff; color: #1c3523; border-color: #fff; }

/* Main */
.view { max-width: 760px; margin: 0 auto; padding: 14px 16px 90px; outline: none; }
h2.section { font-size: 15px; text-transform: uppercase; letter-spacing: .6px; color: var(--ink-2); margin: 22px 0 8px; }
h2.section:first-child { margin-top: 4px; }
.muted { color: var(--ink-3); }
.small { font-size: 13px; }

/* Controls */
.toolbar { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.search {
  flex: 1 1 200px; min-width: 0;
  padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface);
}
/* Stock: hamburger category menu */
.catbar { flex-wrap: nowrap; position: relative; }
.catmenu { position: static; flex: none; }
.catbtn {
  display: flex; align-items: center; gap: 6px; height: 100%; max-width: 46vw;
  padding: 0 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface);
  font-size: 14px; font-weight: 600; color: var(--ink); cursor: pointer;
}
.catbtn svg { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.catbtn-l { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.catbtn.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.catlist {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 30;
  max-height: min(60vh, 420px); overflow-y: auto; padding: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0,0,0,.18);
}
.catlist[hidden] { display: none; }
.catopt {
  display: flex; justify-content: space-between; align-items: center; width: 100%;
  padding: 12px; border: 0; border-radius: 10px; background: none; text-align: left;
  font-size: 15px; font-weight: 600; color: var(--ink); cursor: pointer;
}
.catopt:hover, .catopt:focus-visible { background: var(--surface-2); outline: none; }
.catopt.on { background: var(--ink); color: var(--bg); }
.catn { font-size: 13px; font-weight: 500; opacity: .7; }
/* Same menu used full-width on Deliveries, Milling and Manager */
.catbar.solo .catmenu { flex: 1; }
.catbar.solo .catbtn { width: 100%; max-width: none; min-height: 46px; font-size: 15px; }
.catbar.solo .catbtn-l { flex: 1; text-align: left; }
.catchev { transition: transform .15s; }
.catbtn[aria-expanded="true"] .catchev { transform: rotate(180deg); }

/* Cards */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin-bottom: 10px;
}
.card.tap { cursor: pointer; }
.card.tap:active { background: var(--surface-2); }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.row.top { align-items: flex-start; }
.grow { flex: 1; min-width: 0; }
.title { font-weight: 700; font-size: 17px; }
.sub { color: var(--ink-2); font-size: 14px; }
.meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.price { font-weight: 700; font-size: 17px; white-space: nowrap; }
.unit { color: var(--ink-3); font-size: 13px; font-weight: 500; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px; border-radius: 999px; font-size: 12.5px; font-weight: 700;
  background: var(--surface-2); color: var(--ink-2);
}
.badge.good { background: var(--good-bg); color: var(--good); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad  { background: var(--bad-bg);  color: var(--bad); }
.badge.info { background: var(--info-bg); color: var(--info); }

/* Quantity stepper */
.qty { display: flex; align-items: center; gap: 4px; margin-top: 10px; }
.qty button {
  width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface-2); font-size: 22px; font-weight: 700; line-height: 1;
}
.qty .n { min-width: 64px; text-align: center; font-weight: 800; font-size: 20px; }
.qty .lbl { color: var(--ink-3); font-size: 13px; margin-left: 4px; }
.qty.low .n { color: var(--bad); }

/* Action links in cards */
.actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); font-weight: 650; text-decoration: none; color: var(--ink);
}
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.danger { color: var(--bad); }
.btn.block { width: 100%; }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: 14px; }

/* Checkbox rows (yard work) */
.check {
  appearance: none; width: 28px; height: 28px; flex: none; border-radius: 8px;
  border: 2px solid var(--ink-3); background: var(--surface); display: grid; place-items: center;
}
.check:checked { background: var(--brand); border-color: var(--brand); }
.check:checked::after { content: "✓"; color: var(--brand-ink); font-weight: 900; }
.done .title { text-decoration: line-through; color: var(--ink-3); }

/* FAB */
.fab {
  position: fixed; right: 18px; bottom: calc(var(--tabbar-h) + 18px + env(safe-area-inset-bottom));
  width: 58px; height: 58px; border-radius: 18px; border: 0; z-index: 9;
  background: var(--wood); color: #fff; font-size: 32px; line-height: 1;
  box-shadow: 0 6px 18px rgba(0,0,0,.25);
}

/* Tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(6, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabbar button {
  border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; color: var(--ink-3); font-size: 10.5px; font-weight: 650; padding: 0;
}
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar button.active { color: var(--brand); }
.tabbar button[hidden] { display: none; }

/* Sheet (dialog) */
.sheet {
  width: 100%; max-width: 640px; max-height: 92dvh; margin: auto auto 0; padding: 0;
  border: 0; border-radius: 20px 20px 0 0; background: var(--surface); color: var(--ink);
}
@media (min-width: 700px) { .sheet { margin: auto; border-radius: 20px; } }
.sheet::backdrop { background: rgba(0,0,0,.45); }
.sheet form { display: flex; flex-direction: column; max-height: 92dvh; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 8px; }
.sheet-head h2 { margin: 0; font-size: 19px; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; border: 0; background: var(--surface-2); font-size: 16px; }
.sheet-body { overflow-y: auto; padding: 4px 16px 8px; }
.sheet-actions {
  display: flex; gap: 8px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}
.sheet-actions .btn { flex: 1; }

.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13px; font-weight: 700; color: var(--ink-2); margin-bottom: 4px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg);
  font-size: 16px; /* prevents iOS zoom */
}
.field textarea { min-height: 80px; resize: vertical; }
/* Side-by-side fields only when there's room; on phones they stack so dates never collide. */
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 0 10px; }
.grid2 > * { min-width: 0; }
.field input, .field select, .field textarea { display: block; min-width: 0; }
/* iPhone draws date/time boxes with their own size and centered text; make them match the other fields. */
.field input[type="date"], .field input[type="time"] {
  -webkit-appearance: none; appearance: none; min-height: 48px; line-height: 1.25; text-align: left;
}
.field input[type="date"]::-webkit-date-and-time-value { text-align: left; }
.field select { -webkit-appearance: none; appearance: none; min-height: 48px; padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23857d73' stroke-width='2.2' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 18px; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg label { flex: 1 1 auto; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: block; text-align: center; padding: 11px 10px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); font-weight: 650; font-size: 14px;
}
.seg input:checked + span { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.seg input:focus-visible + span { outline: 2px solid var(--wood); outline-offset: 2px; }

/* Dashboard */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.tile .k { font-size: 13px; color: var(--ink-2); font-weight: 650; }
.tile .v { font-size: 26px; font-weight: 800; letter-spacing: -.5px; margin-top: 2px; }
.tile .d { font-size: 12.5px; color: var(--ink-3); }
.tile.tap { cursor: pointer; }
@media (min-width: 600px) { .tiles { grid-template-columns: repeat(4, 1fr); } }

.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .axis { fill: var(--ink-3); font-size: 20px; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .bar { fill: var(--bar); }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .hit:hover + .bar, .chart .bar.hi { opacity: .75; }
.tip {
  position: absolute; pointer-events: none; transform: translate(-50%, -100%);
  background: var(--ink); color: var(--bg); padding: 6px 9px; border-radius: 8px; font-size: 13px; white-space: nowrap;
  opacity: 0; transition: opacity .1s;
}
.tip.show { opacity: 1; }

table.list { width: 100%; border-collapse: collapse; font-size: 14px; }
table.list th, table.list td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }
table.list th { font-size: 12px; color: var(--ink-3); text-transform: uppercase; letter-spacing: .4px; }
table.list td.num, table.list th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Facebook */
.fb-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.fb-wrap iframe { display: block; width: 100%; border: 0; }

.empty { text-align: center; padding: 34px 10px; color: var(--ink-3); }
.empty b { display: block; color: var(--ink-2); font-size: 17px; margin-bottom: 4px; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 90px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px); opacity: 0; transition: all .2s; z-index: 20;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: 14px;
  max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.notice {
  background: var(--warn-bg); color: var(--warn); border-radius: 12px; padding: 10px 12px; font-size: 14px; margin-bottom: 12px;
}

/* Manager price editor */
.pr-in {
  width: 88px; padding: 8px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg);
  text-align: right; font-size: 16px; font-variant-numeric: tabular-nums;
}
#price-save:disabled { background: var(--surface-2); color: var(--ink-3); border-color: var(--line); }
.savebar { position: sticky; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); margin: 12px -16px 0; padding: 10px 16px; background: var(--bg); border-top: 1px solid var(--line); }

/* Per-length price / count cells on the Stock tab */
.sizes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 10px; }
.sizes.one { grid-template-columns: 1fr; }
.sz {
  display: flex; flex-direction: column; align-items: flex-start; gap: 1px; text-align: left;
  padding: 8px 10px; min-height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2);
}
.sizes.one .sz { flex-direction: row; align-items: center; justify-content: space-between; }
.sz:active { border-color: var(--brand); }
.sz-l { font-size: 12.5px; font-weight: 700; color: var(--ink-2); }
.sz-p { font-size: 17px; font-weight: 800; }
.sz-q { font-size: 13px; font-weight: 700; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.sz-q small { font-weight: 500; color: var(--ink-3); }
.sz.low { border-color: var(--bad); }
.sz.low .sz-q { color: var(--bad); }

/* Length rows in the product form */
.size-row { display: grid; grid-template-columns: 1fr 1fr 40px; gap: 8px; margin-bottom: 8px; align-items: center; }
.size-row input { width: 100%; padding: 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); font-size: 16px; }

/* Manager price editor grid */
.pe-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.pe-grid label span { display: block; font-size: 12px; font-weight: 700; color: var(--ink-3); margin-bottom: 2px; }
.pe-grid .pr-in { width: 100%; }
@media (min-width: 600px) { .sizes, .pe-grid { grid-template-columns: repeat(6, 1fr); } }

/* Sign-in screen hides navigation */
body.gated .tabbar, body.gated .fab { display: none; }
#sync.offline { color: #ffd27a; font-weight: 700; }

/* Tappable address on delivery cards */
.addr {
  display: block; padding: 2px 0; border: 0; background: none; text-align: left; cursor: pointer;
  color: var(--info); font-size: 14px; font-weight: 600; text-decoration: underline; text-underline-offset: 3px;
}
.maplist { display: grid; gap: 8px; }
.eta-quick { display: flex; flex-wrap: wrap; gap: 6px; margin: -4px 0 12px; }
.eta-quick .btn { flex: 1 1 auto; }

/* Dollar sign inside money boxes */
.money-in { position: relative; display: block; }
.money-in .cur { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--ink-2); font-weight: 700; pointer-events: none; }
.field .money-in input { padding-left: 26px; }
.groupbox { margin-bottom: 12px; }
.groupbox-k { display: block; font-size: 13px; font-weight: 700; color: var(--ink-2); margin-bottom: 2px; }

/* Spreadsheet import / export */
.csvbox { margin-bottom: 14px; }
.csvsum { margin: 0 0 12px; padding-left: 20px; }
.csvsum li { margin: 4px 0; }
