/* PML brand: Quicksand headings, Roboto body, PML Red #db241e primary, Beige #cf8e43 secondary */
:root {
  --red: #db241e;
  --red-dark: #b51c17;
  --red-tint: #fdecea;
  --beige: #cf8e43;
  --beige-dark: #a86f2f;
  --beige-text: #85561f; /* beige for text: 5:1 on the beige tint */
  --beige-tint: #faf1e6;
  --ink: #1f1f1f;
  --ink-2: #555;
  --ink-3: #696969; /* 5.4:1 on white – readable hints */
  --line: #e7e2dc;
  --bg: #f8f6f3;
  --card: #fff;
  --green: #1f8a4c;
  --green-tint: #e6f4ec;
  --amber: #b7791f;
  --amber-tint: #fdf3e1;
  --blue: #2b6cb0;
  --blue-tint: #e8f0fa;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 2px 8px rgba(0,0,0,.05);
  --font-head: 'Quicksand', system-ui, sans-serif;
  --font-body: 'Roboto', system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4, .brand, .kpi .val, .btn, .nav a, th {
  font-family: var(--font-head);
}
h1 { font-size: 24px; font-weight: 700; margin: 0; }
h2 { font-size: 18px; font-weight: 700; margin: 0 0 12px; }
h3 { font-size: 15px; font-weight: 700; margin: 0 0 8px; }
a { color: var(--red); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--ink-3); }
.small { font-size: 12px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* ---------- Layout ---------- */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
  background: #fff;
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 18px 16px;
  border-bottom: 4px solid var(--red);
}
.brand .logo {
  width: 40px; height: 40px; border-radius: 9px;
  background: var(--red); color: #fff;
  display: grid; place-items: center;
  font-weight: 700; font-size: 14px; letter-spacing: .5px;
}
.brand .name { font-weight: 700; font-size: 15px; line-height: 1.15; }
.brand .sub { font-size: 11px; color: var(--beige-text); font-weight: 600; letter-spacing: .3px; }
.nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav .group { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--ink-3); padding: 12px 10px 4px; font-family: var(--font-body); }
.nav a {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 12px; border-radius: 8px;
  color: var(--ink-2); font-weight: 600; font-size: 14px;
}
.nav a:hover { background: var(--beige-tint); text-decoration: none; color: var(--ink); }
.nav a.active { background: var(--red-tint); color: var(--red); }
.nav .count {
  background: var(--red); color: #fff; border-radius: 999px;
  font-size: 11px; padding: 1px 7px; font-family: var(--font-body);
}
.userbox { border-top: 1px solid var(--line); padding: 14px 18px; font-size: 13px; }
.userbox .who { font-weight: 500; }
.userbox .role { color: var(--beige-text); font-size: 12px; }
.userbox .links { margin-top: 8px; display: flex; gap: 12px; font-size: 12px; }

.main { padding: 24px 32px 48px; min-width: 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .crumbs { font-size: 12px; color: var(--ink-3); margin-bottom: 4px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

.main > .menu-toggle { display: none; }

/* ---------- Cards & KPIs ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 18px;
}
.card.flush { padding: 0; overflow: hidden; }
.card .card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card.flush .card-head { padding: 16px 20px 0; }
.grid { display: grid; gap: 16px; }
.grid.kpis { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 18px; }
.grid.two { grid-template-columns: 1fr 1fr; }
.kpi {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); border-left: 4px solid var(--beige);
  display: block; color: inherit;
}
a.kpi:hover { text-decoration: none; border-color: var(--beige); }
.kpi.red { border-left-color: var(--red); }
.kpi .label { color: var(--ink-2); font-size: 12px; }
.kpi .val { font-size: 28px; font-weight: 700; line-height: 1.2; }
.kpi.red .val { color: var(--red); }

.banner {
  border-radius: var(--radius); padding: 14px 18px; margin-bottom: 18px;
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  background: var(--beige-tint); border: 1px solid #efd9bd;
}
.banner.red { background: var(--red-tint); border-color: #f5c6c3; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; font-weight: 700; color: var(--ink-2); background: #fbfaf8; white-space: nowrap; }
tbody tr:hover { background: #fcfbf9; }
tr.clickable { cursor: pointer; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.cat td { background: var(--beige-tint); font-weight: 600; color: var(--beige-text); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; padding: 6px 12px; }
.empty { padding: 32px; text-align: center; color: var(--ink-3); }

.matrix td.cell { text-align: center; font-variant-numeric: tabular-nums; }
.matrix td.cell.zero { color: var(--ink-3); }
.matrix td.cell.low { background: var(--red-tint); color: var(--red); font-weight: 700; }
.matrix td:first-child { min-width: 200px; }
.matrix th.plant { text-align: center; }
.matrix td:first-child, .matrix th:first-child { position: sticky; left: 0; background: #fff; z-index: 1; }
.matrix th:first-child { background: #fbfaf8; }

/* ---------- Badges ---------- */
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 500;
  background: #eee; color: var(--ink-2); white-space: nowrap;
}
.badge.draft { background: #eee; color: #555; }
.badge.submitted { background: var(--amber-tint); color: var(--amber); }
.badge.approved { background: var(--blue-tint); color: var(--blue); }
.badge.rejected { background: var(--red-tint); color: var(--red); }
.badge.ordered { background: var(--beige-tint); color: var(--beige-text); }
.badge.delivered { background: #efe7fb; color: #6b46c1; }
.badge.received { background: var(--green-tint); color: var(--green); }
.badge.open { background: var(--red-tint); color: var(--red); }
.badge.in_progress { background: var(--amber-tint); color: var(--amber); }
.badge.resolved { background: var(--green-tint); color: var(--green); }
.badge.low { background: var(--red-tint); color: var(--red); }
.badge.ok { background: var(--green-tint); color: var(--green); }
.badge.kind { background: var(--beige-tint); color: var(--beige-text); }

/* ---------- Forms & buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent; border-radius: 8px;
  padding: 8px 16px; font-size: 14px; font-weight: 700; cursor: pointer;
  background: #fff; border-color: var(--line); color: var(--ink);
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { border-color: #cfc7bd; text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--red); color: #fff; border-color: var(--red); }
.btn.primary:hover { background: var(--red-dark); }
.btn.secondary { background: var(--beige); color: var(--ink); border-color: var(--beige); } /* dark text: readable on brand beige */
.btn.secondary:hover { background: #c07f36; }
.btn.danger { color: var(--red); border-color: #f0c2bf; }
.btn.danger:hover { background: var(--red-tint); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.link { border: 0; background: none; color: var(--red); padding: 0; font-weight: 600; }

label { display: block; font-size: 12px; font-weight: 500; color: var(--ink-2); margin-bottom: 4px; }
input, select, textarea {
  font: inherit; color: var(--ink);
  width: 100%; padding: 8px 10px;
  border: 1px solid #d9d3cb; border-radius: 8px; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--beige); box-shadow: 0 0 0 3px rgba(207,142,67,.18); }
input.qty { width: 96px; text-align: right; }
input[type=checkbox] { width: auto; }
textarea { min-height: 70px; resize: vertical; }
.field { margin-bottom: 14px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.toolbar { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .field { margin: 0; min-width: 160px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs a { padding: 9px 14px; color: var(--ink-2); font-family: var(--font-head); font-weight: 700; border-bottom: 3px solid transparent; margin-bottom: -1px; }
.tabs a:hover { text-decoration: none; color: var(--ink); }
.tabs a.active { color: var(--red); border-bottom-color: var(--red); }

/* ---------- Detail ---------- */
.meta-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(160px, 100%), 1fr)); gap: 14px 20px; }
.meta-grid .k { font-size: 12px; color: var(--ink-3); }
.meta-grid .v { font-weight: 500; }
.steps { display: flex; gap: 0; margin: 4px 0 18px; overflow-x: auto; }
.steps .step { flex: 1; min-width: 100px; text-align: center; font-size: 12px; color: var(--ink-3); position: relative; padding-top: 22px; }
.steps .step::before { content: ''; position: absolute; top: 6px; left: 50%; width: 12px; height: 12px; margin-left: -6px; border-radius: 50%; background: #ddd; z-index: 1; }
.steps .step::after { content: ''; position: absolute; top: 11px; left: -50%; width: 100%; height: 2px; background: #ddd; }
.steps .step:first-child::after { display: none; }
.steps .step.done { color: var(--ink); }
.steps .step.done::before, .steps .step.done::after { background: var(--red); }
.steps .step.current { color: var(--red); font-weight: 700; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 8px 0 8px 18px; border-left: 2px solid var(--line); position: relative; font-size: 13px; }
.timeline li::before { content: ''; position: absolute; left: -6px; top: 13px; width: 10px; height: 10px; border-radius: 50%; background: var(--beige); }

/* ---------- Login ---------- */
.login-page { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-hero {
  background: var(--red); color: #fff; padding: 56px; display: flex; flex-direction: column; justify-content: space-between;
  background-image: radial-gradient(circle at 85% 15%, rgba(255,255,255,.12) 0, transparent 40%), radial-gradient(circle at 10% 90%, rgba(207,142,67,.45) 0, transparent 45%);
}
.login-hero h1 { font-size: 38px; line-height: 1.15; max-width: 460px; }
.login-hero p { max-width: 440px; opacity: .92; font-size: 15px; }
.login-hero .logo { width: 64px; height: 64px; border-radius: 14px; background: #fff; color: var(--red); display: grid; place-items: center; font-family: var(--font-head); font-weight: 700; font-size: 20px; }
.login-hero ul { padding-left: 18px; opacity: .92; }
.login-form { display: grid; place-items: center; padding: 32px; }
.login-form .card { width: 100%; max-width: 380px; padding: 28px; }
.login-form .accent { height: 4px; width: 48px; background: var(--beige); border-radius: 2px; margin: 8px 0 20px; }

/* ---------- Modal & toast ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(20,20,20,.45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 520px; max-height: 90vh; overflow: auto; box-shadow: 0 10px 40px rgba(0,0,0,.2); }
.modal.wide { max-width: 760px; }
.modal header { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal header h2 { margin: 0; }
.modal .body { padding: 18px 20px; }
.modal footer { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
#toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); max-width: 360px; animation: slide .2s ease-out; }
.toast.error { background: var(--red); }
.toast.ok { background: var(--green); }
@keyframes slide { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

.add-row { display: flex; gap: 8px; margin-top: 12px; }
.add-row select { flex: 1; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 40; left: 0; top: 0; width: 260px; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 30px rgba(0,0,0,.15); }
  .sidebar.open { transform: none; }
  .main > .menu-toggle { display: inline-flex; margin-bottom: 12px; }
  .main { padding: 16px; }
  .grid.two { grid-template-columns: 1fr; }
  .login-page { grid-template-columns: 1fr; }
  .login-hero { padding: 32px 24px; }
  .login-hero h1 { font-size: 28px; }
}
@media print {
  .sidebar, .actions, .menu-toggle, .btn { display: none !important; }
  .shell { display: block; }
  .card { box-shadow: none; }
}

/* ---------- Charts ---------- */
.viz-card h2 { margin-bottom: 2px; }
.viz-card .viz-sub { font-size: 12px; color: var(--ink-3); margin-bottom: 14px; }
.viz-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--ink-2); margin-bottom: 10px; }
.viz-legend span { display: inline-flex; align-items: center; gap: 6px; }
.viz-legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.viz-legend i.tick { width: 2px; height: 12px; border-radius: 0; background: var(--ink); }
.viz-cols { position: relative; display: flex; gap: 10px; height: 200px; padding: 18px 0 22px 44px; }
.viz-grid { position: absolute; inset: 18px 0 22px 44px; pointer-events: none; }
.viz-grid div { position: absolute; left: 0; right: 0; border-top: 1px solid #efebe6; }
.viz-grid span { position: absolute; left: -44px; top: -8px; width: 38px; text-align: right; font-size: 11px; color: var(--ink-3); }
.viz-col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; position: relative; min-width: 0; }
.viz-stack { display: flex; flex-direction: column-reverse; gap: 2px; width: min(56px, 70%); margin: 0 auto; position: relative; }
.viz-stack .viz-seg:last-child { border-radius: 4px 4px 0 0; }
.viz-seg { min-height: 2px; cursor: default; transition: opacity .15s; }
.viz-seg:hover, .viz-hrow:hover .viz-hbar { opacity: .82; }
.viz-total { position: absolute; top: -17px; left: 50%; transform: translateX(-50%); font-size: 11px; font-weight: 500; color: var(--ink-2); white-space: nowrap; }
.viz-x { position: absolute; bottom: -20px; left: 0; right: 0; text-align: center; font-size: 11px; color: var(--ink-3); white-space: nowrap; }
.viz-hbars { display: flex; flex-direction: column; gap: 8px; }
.viz-hrow { display: grid; grid-template-columns: minmax(90px, 32%) 1fr; gap: 10px; align-items: center; font-size: 13px; }
.viz-hlabel { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
.viz-htrack { position: relative; display: flex; align-items: center; gap: 8px; height: 20px; }
.viz-hbar { height: 14px; border-radius: 0 4px 4px 0; min-width: 2px; }
.viz-hstack { display: flex; gap: 2px; height: 14px; min-width: 2px; }
.viz-hstack .viz-seg:last-child { border-radius: 0 4px 4px 0; }
.viz-hval { font-size: 12px; color: var(--ink-2); white-space: nowrap; }
.viz-target { position: absolute; top: 1px; bottom: 1px; width: 2px; background: var(--ink); }
.viz-multiples { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.viz-multi { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.viz-multi-head { display: flex; flex-direction: column; font-size: 13px; margin-bottom: 8px; }
.viz-multi-head span { font-size: 11px; color: var(--ink-3); }
.viz-mini { display: flex; gap: 4px; height: 70px; align-items: flex-end; }
.viz-mini-col { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; }
.viz-mini-col span { font-size: 10px; color: var(--ink-3); margin-top: 3px; }
.viz-mini-bar { width: 100%; background: var(--beige-dark); border-radius: 3px 3px 0 0; }
.viz-mini-bar.none { background: none; }
.viz-table { margin-top: 12px; font-size: 12px; }
.viz-table summary { cursor: pointer; color: var(--ink-3); }
.viz-empty { padding: 28px 12px; text-align: center; color: var(--ink-3); font-size: 13px; background: #fbfaf8; border-radius: 8px; }
#viz-tip { position: fixed; z-index: 70; pointer-events: none; background: var(--ink); color: #fff; font-size: 12px; padding: 6px 9px; border-radius: 6px; max-width: 260px; box-shadow: var(--shadow); }
#viz-tip[hidden] { display: none; }

/* ---------- Misc additions ---------- */
.item-brand { display: inline-block; font-size: 11px; color: var(--beige-text); background: var(--beige-tint); border-radius: 4px; padding: 0 5px; margin-left: 4px; }
.badge.cancelled { background: #eee; color: #777; text-decoration: line-through; }
.badge.overdue { background: var(--red-tint); color: var(--red); }
.badge.awaiting { background: #efe7fb; color: #6b46c1; }
input.invalid, select.invalid { border-color: var(--red) !important; box-shadow: 0 0 0 3px rgba(219,36,30,.15); }
input.warn { border-color: var(--amber); background: var(--amber-tint); }
.hint { font-size: 11px; color: var(--ink-3); }
.hint.warn { color: var(--amber); }
@media (max-width: 600px) {
  .viz-cols { gap: 4px; padding-left: 36px; }
  .viz-grid { left: 36px; }
  .viz-grid span { left: -36px; width: 32px; }
  .viz-x { font-size: 10px; }
  .viz-total { display: none; }
  .page-head h1 { font-size: 20px; }
  th, td { padding: 8px; }
}
.viz-bullet { display: grid; grid-template-columns: 1fr 96px; }
.viz-barea { position: relative; height: 20px; display: flex; align-items: center; }

/* Phone layout: hide secondary columns, show compact hints instead */
.show-sm { display: none; }
@media (max-width: 700px) {
  .hide-sm { display: none !important; }
  .show-sm { display: block; }
  input.qty { width: 72px; }
  .card { padding: 14px; }
  .card.flush { padding: 0; }
  .page-head .actions .btn { padding: 7px 12px; }
}

.print-only { display: none; }
@media print {
  .print-only { display: block; margin-bottom: 16px; }
  .print-only h1 { font-size: 20px; }
  .banner, .tabs, .toolbar, .viz-table, #toasts { display: none !important; }
  body { background: #fff; }
}

.help-steps { padding-left: 20px; margin: 0; }
.help-steps li { margin-bottom: 8px; line-height: 1.5; }

@media (max-width: 700px) {
  .grid.kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi { padding: 10px 12px; }
  .kpi .val { font-size: 22px; }
}

/* Phone: tables marked .stack-sm become one card per row, every field visible */
@media (max-width: 700px) {
  table.stack-sm thead { display: none; }
  table.stack-sm, table.stack-sm tbody, table.stack-sm tr, table.stack-sm td { display: block; width: 100%; }
  table.stack-sm tr { border-bottom: 6px solid var(--bg); padding: 10px 14px; }
  table.stack-sm tr.cat { padding: 0; border-bottom: 0; }
  table.stack-sm td { border: 0; padding: 4px 0; text-align: left; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
  table.stack-sm td[data-label]::before { content: attr(data-label); color: var(--ink-2); font-size: 12px; }
  table.stack-sm td.stack-title { font-weight: 600; font-size: 15px; padding-bottom: 6px; }
  table.stack-sm td input:not([type=checkbox]), table.stack-sm td select { max-width: 60%; }
  table.stack-sm input.qty { width: 110px; }
}
@media (max-width: 700px) {
  table.stack-sm tr:not(.cat) { display: flex; flex-direction: column; }
  table.stack-sm td.stack-title { order: -1; }
}

.attention ul { list-style: none; padding: 0; margin: 0; }
.attention li { padding: 8px 10px 8px 14px; border-left: 4px solid var(--amber); background: var(--amber-tint); border-radius: 6px; margin-bottom: 6px; }
.attention li.red { border-left-color: var(--red); background: var(--red-tint); }
.attention li a { color: var(--ink); font-weight: 500; }
.count-note { margin-top: 6px; font-size: 12px; min-width: 160px; }

/* Keyboard users can always see where they are */
.btn:focus-visible, a:focus-visible, input[type=checkbox]:focus-visible, summary:focus-visible {
  outline: 3px solid rgba(207,142,67,.7); outline-offset: 2px;
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* =================== Phone & tablet =================== */
.tabbar, .drawer-shade { display: none; }
@media (max-width: 900px) {
  /* Bottom tab bar replaces the hamburger menu */
  .tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
    background: #fff; border-top: 1px solid var(--line); box-shadow: 0 -2px 12px rgba(0,0,0,.06);
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
  }
  .tabbar a, .tabbar button {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    min-height: 54px; color: var(--ink-2); font: 600 11px var(--font-head); background: none; border: 0; position: relative;
    text-decoration: none; border-radius: 10px; cursor: pointer;
  }
  .tabbar a.active { color: var(--red); background: var(--red-tint); }
  .tabbar .count { position: absolute; top: 4px; left: calc(50% + 6px); background: var(--red); color: #fff; border-radius: 999px; font: 600 10px var(--font-body); padding: 1px 6px; }
  .main > .menu-toggle { display: none !important; }
  .main { padding: 14px 14px calc(84px + env(safe-area-inset-bottom)); }
  .sidebar { width: min(300px, 86vw); bottom: 0; height: auto; top: 0; }
  .drawer-shade:not([hidden]) { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 39; }
  #toasts { left: 12px; right: 12px; bottom: calc(76px + env(safe-area-inset-bottom)); }
  .toast { max-width: none; }
  /* Sticky save bars sit above the tab bar */
  .main [style*="position:sticky"] { bottom: calc(70px + env(safe-area-inset-bottom)) !important; }
}
@media (max-width: 700px) {
  /* 16px stops iPhones zooming into a box when it is tapped */
  input, select, textarea { font-size: 16px; }
  /* Comfortable thumb targets */
  .btn { min-height: 44px; }
  .btn.sm { min-height: 40px; padding: 8px 12px; }
  input[type=checkbox] { width: 22px; height: 22px; }
  .page-head { margin-bottom: 14px; }
  .page-head .actions { width: 100%; }
  .page-head .actions .btn { flex: 1 1 auto; }
  [data-act="print"], #print { display: none !important; }
  /* Tabs scroll sideways instead of wrapping into rows */
  .tabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .tabs a { white-space: nowrap; }
  .toolbar .field { flex: 1 1 140px; min-width: 0; }
  /* Pop-ups fill the screen with the buttons always reachable */
  .modal-backdrop { padding: 0; place-items: stretch; }
  .modal, .modal.wide { max-width: none; max-height: none; height: 100%; border-radius: 0; display: flex; flex-direction: column; }
  .modal .body { flex: 1; overflow-y: auto; }
  .modal footer { position: sticky; bottom: 0; background: #fff; padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
  .modal footer .btn { flex: 1; }
  /* Cards for list tables */
  table.stack-sm td.stack-full { display: block; text-align: center; }
  table.stack-sm td[data-label=""]::before { content: none; }
  table.stack-sm td.right { justify-content: flex-end; }
  table.stack-sm td.right .btn { flex: 1; }
  .card.flush .card-head { padding: 14px 14px 0; }
  .banner { padding: 12px 14px; }
  .banner .btn { width: 100%; }
  .login-hero ul, .login-hero > .small { display: none; }
  .login-hero { padding: 24px 20px; gap: 12px; }
  .login-form { padding: 16px; align-items: start; }
}

/* Quick-action buttons on dashboards */
.quick-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 18px; }
.quick { display: flex; flex-direction: column; gap: 2px; padding: 14px 16px; border-radius: 12px; background: #fff; border: 1px solid var(--line);
  box-shadow: var(--shadow); color: var(--ink); min-height: 72px; justify-content: center; }
.quick:hover { text-decoration: none; border-color: var(--beige); }
.quick strong { font-family: var(--font-head); font-size: 15px; display: flex; align-items: center; gap: 6px; }
.quick span { font-size: 12px; color: var(--ink-3); }
.quick.primary { background: var(--red); border-color: var(--red); color: #fff; }
.quick.primary span { color: rgba(255,255,255,.9); }
.qcount { background: var(--red); color: #fff; border-radius: 999px; font: 600 11px var(--font-body); padding: 1px 7px; }
.quick.primary .qcount { background: #fff; color: var(--red); }
@media (max-width: 700px) { .quick-row { grid-template-columns: 1fr 1fr; gap: 10px; } .quick { padding: 12px; min-height: 76px; } }

.filter-toggle { display: none; }
@media (max-width: 700px) {
  #filters .filter-toggle { display: inline-flex; align-self: flex-end; }
  #filters:not(.show-filters) > .field:not(:first-child), #filters:not(.show-filters) > button[type=submit] { display: none; }
  #filters > .field:first-child { flex: 1 1 60%; }
}
.quick strong .qcount { color: #fff; font-size: 11px; }
.quick.primary strong .qcount { color: var(--red); }

/* Order form: one rate per item for all its locations */
.fill-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 4px 0 10px; }
.fill-bar .fill-gst { display: inline-flex; gap: 6px; align-items: center; }
.fill-bar .fill-gst label { margin: 0; }
tr.grp td { background: var(--beige-tint); border-top: 2px solid #efd9bd; }
tr.in-grp td:first-child { padding-left: 24px; }
@media (max-width: 700px) {
  tr.grp { padding: 12px 14px !important; }
  tr.grp td.stack-full { text-align: left; }
  tr.grp td { background: var(--beige-tint) !important; }
}
.fill-bar .fill-gst label { white-space: nowrap; display: inline; font-size: 13px; }
.fill-bar .fill-gst select { width: auto; }

/* Chips: quick choices (vendor selection, delivery dates) */
.vendor-chips, .date-chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 0 0 12px; }
.date-chips { margin: 6px 0 0; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 12px; font: 500 13px var(--font-body); cursor: pointer; color: var(--ink); }
.chip b { background: var(--beige-tint); color: var(--beige-text); border-radius: 999px; padding: 0 6px; margin-left: 4px; font-size: 11px; }
.chip:hover { border-color: var(--beige); }
.chip.on { background: var(--red); border-color: var(--red); color: #fff; }
.chip.on b { background: #fff; color: var(--red); }
@media (max-width: 700px) { .chip { padding: 9px 14px; } }
