/* DM Sans is kept with the app so it looks the same with no connection. */
@font-face {
  font-family: 'DM Sans';
  src: url('fonts/DMSans.ttf') format('truetype');
  font-weight: 100 1000;
  font-style: normal;
  font-display: swap;
}

:root {
  --layout: wide; /* app.js reads this, so the phone width lives only in this file */
  --ink: #000;
  --paper: #fff;
  --page: #f2f2f2;
  --hover: #f5f5f5;
  --muted: #5e5e5e;
  --rule: #e4e4e4;
  --rule-strong: #c9c9c9;
  --warn: #b3261e;
  --sans: 'DM Sans', system-ui, sans-serif;
  --radius: 4px;
  --control: 44px;
  --check: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5' fill='none' stroke='%23fff' stroke-width='2.6'/%3E%3C/svg%3E");
  --magnifier: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ccircle cx='10.5' cy='10.5' r='6.5' fill='none' stroke='%23000' stroke-width='1.8'/%3E%3Cpath d='M15.5 15.5L21 21' stroke='%23000' stroke-width='1.8'/%3E%3C/svg%3E");
  --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 9l6 6 6-6' fill='none' stroke='%23000' stroke-width='2'/%3E%3C/svg%3E");
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  display: grid;
  grid-template-columns: 224px minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  margin: 0;
  overflow: hidden;
  background: var(--page);
  color: var(--ink);
  font: 15px/1.4 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }

/* Sidebar */

.sidebar { display: flex; flex-direction: column; gap: 6px; padding: 24px 14px; background: var(--ink); color: var(--paper); }
.sidebar-brand { padding: 0 10px 24px; font-size: 13px; font-weight: 700; letter-spacing: .16em; line-height: 1.5; text-transform: uppercase; }
.brand-short { display: none; }
.nav-item {
  position: relative;
  display: flex;
  width: 100%;
  border: 0;
  background: none;
  text-align: left;
  align-items: center;
  gap: 12px;
  height: var(--control);
  padding: 0 12px;
  border-radius: var(--radius);
  color: var(--paper);
  font-weight: 500;
  text-decoration: none;
}
.nav-item.active { background: var(--paper); color: var(--ink); font-weight: 700; }
.nav-item:not(.active):hover { background: #1f1f1f; }
.nav-item svg { flex: none; width: 20px; height: 20px; }
.nav-count {
  min-width: 22px;
  height: 22px;
  margin-left: auto;
  padding: 0 7px;
  border-radius: 11px;
  background: var(--paper);
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
  line-height: 22px;
  text-align: center;
}
.nav-item.active .nav-count { background: var(--ink); color: var(--paper); }
.nav-count:empty { display: none; }

/* Page frame */

.main { display: grid; grid-template-rows: 64px auto minmax(0, 1fr); min-width: 0; }
.main > .setup, .main > .content, .main > .review, .main > .outbox { grid-row: 3; }

/* Orders waiting to send: stays on every screen until they go. Ring = waiting, red = refused. */
.outbox-banner { grid-row: 2; display: flex; align-items: center; gap: 14px; padding: 12px 28px; background: var(--ink); color: var(--paper); }
.outbox-banner[data-state="problem"] { background: var(--warn); }
.banner-dot { flex: none; width: 12px; height: 12px; border: 2px solid var(--paper); border-radius: 50%; }
.outbox-banner[data-state="sending"] .banner-dot { background: var(--paper); }
.banner-text { flex: 1; min-width: 0; margin: 0; font-size: 13px; }
.banner-text strong { display: block; font-size: 16px; }
.outbox-banner .banner-btn { flex: none; border-color: var(--paper); background: none; color: var(--paper); }
.outbox-banner .banner-btn:hover { background: rgb(255 255 255 / .14); }
.outbox-banner .banner-btn:disabled, .outbox-banner .banner-btn:disabled:hover { border-color: var(--paper); background: none; color: var(--paper); cursor: default; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 28px;
  border-bottom: 1px solid var(--rule);
  background: var(--paper);
}
.topbar { gap: 24px; }
.topbar h1 { flex: none; margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; }

.save-status { display: flex; align-items: center; gap: 8px; min-width: 0; color: var(--muted); font-size: 13px; }
.save-status::before { content: ''; flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--ink); }
.save-status:has(.save-text:empty)::before { display: none; }
/* Two lines at most, so a long warning can't spill out of the bar */
.save-text { display: -webkit-box; overflow: hidden; line-height: 1.3; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.save-status.warn { color: var(--warn); font-weight: 600; }
.save-status.warn::before { background: var(--warn); }

.topbar-side { display: flex; align-items: center; gap: 18px; min-width: 0; }

/* Tablet status: solid dot = works offline, ring = getting ready, red = needs attention */
.tablet-chip {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 14px 0 12px;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  background: var(--paper);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
.tablet-chip:hover { border-color: var(--ink); }
.chip-dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--ink); }
.tablet-chip[data-state="waiting"] .chip-dot { background: none; box-shadow: inset 0 0 0 1.5px var(--ink); }
.tablet-chip[data-state="problem"] { border-color: var(--warn); color: var(--warn); }
.tablet-chip[data-state="problem"] .chip-dot { background: var(--warn); }
.chip-sub { color: var(--muted); font-weight: 500; }
.chip-sub::before { content: '\00B7'; margin-right: 8px; }
.chip-sub:empty { display: none; }

/* First open: the price list hasn't downloaded yet */

.setup { display: grid; place-items: center; padding: 40px 28px; overflow-y: auto; }
.setup-card {
  width: min(540px, 100%);
  padding: 34px 36px 32px;
  border: 1px solid var(--rule);
  border-top: 3px solid var(--ink);
  border-radius: var(--radius);
  background: var(--paper);
}
.setup-kicker { margin: 0 0 10px; color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
.setup h2 { margin: 0 0 12px; font-size: 26px; font-weight: 700; letter-spacing: -.01em; line-height: 1.15; }
.setup-text { margin: 0; font-size: 16px; line-height: 1.5; }
.setup-detail { margin: 14px 0 0; color: var(--warn); font-size: 14px; font-weight: 600; }
.setup-detail:empty { display: none; }
.setup .btn { height: 52px; margin-top: 24px; padding: 0 28px; font-size: 15px; }

/* The access code: typed once, so it's big and spaced out to make a typo easy to spot */
.code-form { margin-top: 26px; padding-top: 22px; border-top: 1px solid var(--rule); }
.code-form label { display: block; margin-bottom: 8px; color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
.code-form input[type="text"] { height: 56px; padding: 0 16px; border-color: var(--ink); font-size: 19px; font-weight: 600; letter-spacing: .06em; }
.code-form input[type="text"]:disabled { border-color: var(--rule-strong); background: var(--hover); color: var(--muted); }
.code-form .btn { width: 100%; margin-top: 14px; }

.content {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 20px;
  align-items: start;
  padding: 24px 28px 40px;
  overflow-y: auto;
}
.col { display: grid; gap: 20px; min-width: 0; }

.card { padding: 20px 22px; border: 1px solid var(--rule); border-radius: var(--radius); background: var(--paper); }
.card-head { display: flex; justify-content: space-between; align-items: baseline; }
.card-title { display: block; margin: 0 0 16px; font-size: 16px; font-weight: 700; }
.card-head .card-title { margin: 0; }

/* Fields */

.detail-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
.field > label, .field-label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 600; }
.optional { color: var(--muted); font-weight: 400; }

input[type="text"], input[type="search"], select, textarea, .readonly {
  display: block;
  width: 100%;
  height: var(--control);
  padding: 0 12px;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  background-color: var(--paper);
  font-size: 15px;
  appearance: none;
}
textarea { height: auto; padding: 10px 12px; resize: vertical; }
select { padding-right: 34px; background: var(--paper) var(--chevron) no-repeat right 10px center / 16px; cursor: pointer; }
input[type="text"]:focus-visible, input[type="search"]:focus-visible, select:focus-visible, textarea:focus-visible {
  border-color: var(--ink);
  outline: none;
  box-shadow: 0 0 0 1px var(--ink);
}
input::placeholder, textarea::placeholder { color: var(--muted); }
.readonly { display: flex; align-items: center; background: var(--hover); color: var(--muted); }

/* Searchable dropdowns */

.combo { position: relative; }
.combo-panel {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  left: 0;
  z-index: 10;
  max-height: 340px;
  padding: 4px;
  overflow-y: auto;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: 0 8px 24px rgb(0 0 0 / .12);
}
.combo-panel[hidden] { display: none; }
.combo-hint { margin: 0; padding: 12px 10px; color: var(--muted); font-size: 14px; }

.option { display: flex; align-items: center; gap: 12px; min-height: var(--control); padding: 6px 10px; border-radius: 3px; cursor: pointer; }
.option:hover, .option.active { background: var(--hover); }
.option.active { box-shadow: inset 3px 0 0 var(--ink); }
.option.current { font-weight: 700; }
.option-main { flex: 1; min-width: 0; }
.option-code { font-weight: 700; letter-spacing: .03em; }
.option-side { color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.option.added .option-side { color: var(--ink); font-weight: 600; }
.tickbox { flex: none; width: 20px; height: 20px; border: 1.5px solid var(--ink); border-radius: 2px; }
.option.added .tickbox { background: var(--ink) var(--check) center / 16px no-repeat; }

/* Buttons */

.btn {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  height: var(--control);
  padding: 0 18px;
  border: 1px solid var(--ink);
  border-radius: var(--radius);
  background: var(--paper);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--ink); color: var(--paper); }
.btn.primary:hover { background: #262626; }
.btn:disabled, .btn:disabled:hover { border-color: var(--rule); background: var(--rule); color: var(--muted); cursor: not-allowed; }

/* Products */

.add-bar { display: flex; gap: 10px; margin: 16px -22px 0; padding: 12px 22px; border-block: 1px solid var(--rule); background: var(--hover); }
.add-bar .combo { flex: 1; }
.add-bar input, .dialog-tools input { padding-left: 40px; background: var(--paper) var(--magnifier) no-repeat 12px center / 20px; }

.lines-table { width: 100%; border-collapse: collapse; }
.lines-table th {
  padding: 14px 6px 8px;
  border-bottom: 1px solid var(--ink);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .06em;
  text-align: left;
  text-transform: uppercase;
  white-space: nowrap;
}
.lines-table td { padding: 10px 6px; border-bottom: 1px solid var(--rule); vertical-align: top; }
.lines-table th:first-child, .lines-table td:first-child { padding-left: 0; }
.lines-table th:last-child, .lines-table td:last-child { padding-right: 0; }
.lines-table .num { text-align: right; }
.lines-table .center { text-align: center; }

.p-name { padding-top: 2px; font-weight: 600; }
.p-meta { color: var(--muted); font-size: 13px; }
.p-problem { margin-top: 2px; color: var(--warn); font-size: 13px; font-weight: 600; }
.sub { margin-top: 4px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.p-problem:empty, .sub:empty { display: none; }
.c-price .sub { text-align: right; }

.money, .stepper {
  display: flex;
  align-items: center;
  height: var(--control);
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  background: var(--paper);
}
.money:focus-within, .stepper:focus-within { border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); }
.money { width: 96px; margin-left: auto; }
.money span { padding-left: 10px; color: var(--muted); }
.lines-table .money input, .lines-table .stepper input { height: 100%; border: 0; border-radius: 0; box-shadow: none; font-variant-numeric: tabular-nums; }
.lines-table .money input { padding: 0 10px 0 4px; text-align: right; }
.stepper { width: 120px; }
.stepper button { width: 36px; height: 100%; border: 0; background: none; font-size: 20px; line-height: 1; }
.stepper button:hover { background: var(--hover); }
.lines-table .stepper input { width: 48px; padding: 0; border-inline: 1px solid var(--rule); font-weight: 700; text-align: center; }
.c-unit select { width: 120px; }
.c-unit .muted { display: block; padding-top: 11px; }

.check { width: 22px; height: 22px; margin: 11px 0 0; border: 1.5px solid var(--ink); border-radius: 2px; background: var(--paper); cursor: pointer; appearance: none; }
.check:checked { background: var(--ink) var(--check) center / 16px no-repeat; }

.lines-table .c-total { padding-top: 21px; font-variant-numeric: tabular-nums; font-weight: 700; text-align: right; white-space: nowrap; }
.remove { width: 32px; height: var(--control); border: 0; background: none; color: var(--muted); font-size: 22px; }
.remove:hover { color: var(--ink); }

.empty { margin: 0; padding: 28px 0 8px; color: var(--muted); text-align: center; }
.empty.error { color: var(--warn); }

/* Summary */

.summary { position: sticky; top: 20px; }
.switch-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-block: 1px solid var(--rule);
  font-weight: 600;
  cursor: pointer;
}
.switch {
  position: relative;
  width: 48px;
  height: 28px;
  margin: 0;
  border: 1.5px solid var(--ink);
  border-radius: 14px;
  background: var(--paper);
  cursor: pointer;
  appearance: none;
  transition: background .15s;
}
.switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background: var(--ink);
  transition: transform .15s;
}
.switch:checked { background: var(--ink); }
.switch:checked::after { background: var(--paper); transform: translateX(20px); }

.totals { margin: 8px 0 0; }
.t-row { display: flex; justify-content: space-between; align-items: baseline; padding: 5px 0; font-variant-numeric: tabular-nums; }
.t-row dt { color: var(--muted); }
.t-row dd { margin: 0; font-weight: 500; }
.t-row.grand { margin-top: 8px; padding-top: 14px; border-top: 1px solid var(--ink); }
.t-row.grand dt { color: var(--ink); font-weight: 700; }
.t-row.grand dd { font-size: 26px; font-weight: 700; letter-spacing: -.01em; }

.blockers { margin: 16px 0 0; padding: 12px 14px; border-radius: var(--radius); background: var(--hover); color: var(--muted); font-size: 13px; list-style: none; }
.blockers li + li { margin-top: 4px; }
.blockers:empty { display: none; }

.actions { display: grid; gap: 10px; margin-top: 16px; }
.actions .primary { height: 52px; font-size: 15px; }

/* Browse dialog */

dialog {
  width: min(760px, calc(100vw - 48px));
  height: min(760px, calc(100dvh - 64px));
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 20px 60px rgb(0 0 0 / .3);
}
dialog[open] { display: flex; flex-direction: column; }
dialog::backdrop { background: rgb(0 0 0 / .45); }

.dialog-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px 0; }
.dialog-head h2 { margin: 0; font-size: 20px; font-weight: 700; }
.dialog-tools { padding: 14px 22px 0; border-bottom: 1px solid var(--rule); }

.brands { display: flex; gap: 8px; padding: 12px 0 14px; overflow-x: auto; scrollbar-width: none; }
.brands::-webkit-scrollbar { display: none; }
.brands button {
  flex: none;
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  background: var(--paper);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
}
.brands button[aria-pressed="true"] { border-color: var(--ink); background: var(--ink); color: var(--paper); }

.browse-list { flex: 1; min-height: 0; padding: 0 18px 18px; overflow-y: auto; outline: none; }
.group-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  margin: 0;
  padding: 16px 4px 6px;
  border-bottom: 1px solid var(--ink);
  background: var(--paper);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
}
.group-head .muted { font-weight: 500; letter-spacing: .04em; }

/* This tablet dialog */

dialog.dialog-small { width: min(540px, calc(100vw - 48px)); height: fit-content; max-height: calc(100dvh - 64px); }
.facts { min-height: 0; margin: 14px 22px 0; padding: 0; overflow-y: auto; border-top: 1px solid var(--ink); }
.fact { display: grid; grid-template-columns: 136px minmax(0, 1fr); gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--rule); }
.fact dt { color: var(--muted); font-size: 14px; }
.fact dd { margin: 0; font-weight: 600; }
.fact.warn dd { color: var(--warn); }
.fact-note { display: block; margin-top: 2px; color: var(--muted); font-size: 13px; font-weight: 400; }
.dialog-foot { display: flex; justify-content: flex-end; padding: 18px 22px 22px; }

/* Review */

.review { padding: 20px 28px 40px; overflow-y: auto; }
.review-bar { display: flex; align-items: center; gap: 10px; max-width: 210mm; margin: 0 auto; }
.review-note { flex: 1; margin: 0; color: var(--muted); font-size: 14px; }
.send-note { max-width: 210mm; margin: 6px auto 16px; color: var(--muted); font-size: 13px; text-align: right; }
.send-note.warn { color: var(--warn); font-weight: 600; }
.sheet { max-width: 210mm; margin: 0 auto; padding: 14mm; background: var(--paper); box-shadow: 0 2px 14px rgb(0 0 0 / .12); }

/* Outbox */

.outbox { padding: 24px 28px 40px; overflow-y: auto; }
.outbox-note { margin: 6px 0 4px; color: var(--muted); font-size: 14px; }
.outbox-table td { vertical-align: middle; }
.outbox-table .num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.outbox-table td.num { font-weight: 600; }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 28px;
  padding: 0 10px;
  border: 1px solid var(--ink);
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}
.pill::before { content: ''; width: 8px; height: 8px; border-radius: 50%; box-shadow: inset 0 0 0 1.5px currentColor; }
.pill[data-state="sent"] { background: var(--ink); color: var(--paper); }
.pill[data-state="sent"]::before, .pill[data-state="sending"]::before { background: currentColor; }
.pill[data-state="problem"] { border-color: var(--warn); color: var(--warn); }
.outbox-table .sub { white-space: normal; }

/* Narrower screens: tablet landscape and down */

@media (max-width: 1279px) {
  body { grid-template-columns: 64px minmax(0, 1fr); }
  .sidebar { padding: 24px 10px; }
  .sidebar-brand { padding: 0 0 24px; text-align: center; }
  .brand-full, .nav-label { display: none; }
  .nav-count { position: absolute; top: 3px; right: 3px; min-width: 18px; height: 18px; padding: 0 5px; font-size: 11px; line-height: 18px; }
  .outbox-banner { padding: 12px 20px; }
  .outbox { padding: 20px; }
  .brand-short { display: block; }
  .nav-item { justify-content: center; padding: 0; }
  .content { grid-template-columns: minmax(0, 1fr) 280px; gap: 16px; padding: 20px; }
}

@media (max-width: 900px) {
  .content { grid-template-columns: minmax(0, 1fr); }
  .summary { position: static; }
  .detail-grid { grid-template-columns: minmax(0, 1fr); }
  .topbar { padding: 0 20px; }
  .chip-sub { display: none; }
}

/* Phones (the reps' iPhones): tabs along the bottom, one card per product line, total bar.
   Wider screens keep the layout above. */

.m-bar, .m-label, .m-only { display: none; }

@media (max-width: 699px) {
  :root { --layout: phone; }
  body { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
  .main { grid-row: 1; grid-template-rows: auto auto minmax(0, 1fr); }

  /* Tabs along the bottom instead of the sidebar */
  .sidebar { grid-row: 2; flex-direction: row; gap: 6px; padding: 6px 10px calc(6px + env(safe-area-inset-bottom)); }
  .sidebar-brand { display: none; }
  .nav-item { flex: 1; flex-direction: column; justify-content: center; gap: 3px; height: 54px; padding: 0; font-size: 11px; font-weight: 600; }
  .nav-item .nav-label { display: block; }
  .nav-count { top: 5px; right: auto; left: calc(50% + 5px); }

  /* Top bar: title and status chip. The save line only shows when it's a warning. */
  .topbar { flex-wrap: wrap; gap: 6px 12px; height: auto; min-height: 56px; padding: 8px 16px; }
  .topbar h1 { font-size: 20px; }
  .topbar-side { display: contents; }
  .tablet-chip { height: 36px; margin-left: auto; padding: 0 12px 0 10px; }
  .save-status { order: 3; flex-basis: 100%; }
  .save-status:not(.warn) { display: none; }

  .outbox-banner { gap: 10px; padding: 10px 16px; }
  .banner-text strong { font-size: 15px; }
  .outbox-banner .banner-btn { height: 38px; padding: 0 12px; }

  .content { gap: 12px; padding: 12px 12px 0; }
  .col { gap: 12px; }
  .card { padding: 16px; }
  .card-title { margin-bottom: 12px; }
  .add-bar { gap: 8px; margin: 12px -16px 0; padding: 10px 16px; }
  .add-bar .btn { padding: 0 14px; }
  .combo { scroll-margin-top: 12px; }

  /* iPhones zoom into any box under 16px when it's tapped */
  input[type="text"], input[type="search"], select, textarea { font-size: 16px; }

  /* Each product line becomes a card */
  .content .lines-table thead { display: none; }
  .content .lines-table, .content .lines-table tbody { display: block; }
  .content .lines-table tr {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas: "product product remove" "qty unit unit" "price free total";
    align-items: start;
    gap: 12px 12px;
    padding: 14px 0;
    border-bottom: 1px solid var(--rule);
  }
  .content .lines-table td { display: block; padding: 0; border: 0; }
  .lines-table .c-product { grid-area: product; align-self: start; }
  .lines-table .c-remove { grid-area: remove; justify-self: end; margin: -10px -6px 0 0; }
  .lines-table .c-qty { grid-area: qty; }
  .lines-table .c-unit { grid-area: unit; display: flex; align-items: center; gap: 10px; }
  .c-unit .sub { margin: 0; }
  .c-unit .muted { padding: 0; }
  .lines-table .c-price { grid-area: price; display: grid; gap: 4px; }
  .lines-table .c-price .sub { text-align: left; }
  .money { width: 120px; margin-left: 0; }
  /* Free and the total line up with the price box, below its label */
  .content .lines-table .c-free { grid-area: free; padding-top: 21px; text-align: left; }
  .free-label { display: inline-flex; align-items: center; gap: 8px; height: var(--control); font-weight: 600; cursor: pointer; }
  .free-label .check { margin: 0; }
  .content .lines-table .c-total { grid-area: total; padding-top: 31px; font-size: 17px; }
  .m-label { display: inline; color: var(--muted); font-size: 12px; font-weight: 600; }
  .m-only { display: inline; }

  /* Total and Review stay on screen at the bottom of the order */
  .summary #review { display: none; }
  .m-bar {
    position: sticky;
    bottom: 0;
    z-index: 5;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin: 0 -12px;
    padding: 10px 16px;
    border-top: 1px solid var(--rule-strong);
    background: var(--paper);
    box-shadow: 0 -6px 18px rgb(0 0 0 / .06);
  }
  .m-bar-total { display: grid; min-width: 0; }
  .m-bar-label { color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
  .m-bar-total strong { font-size: 22px; font-variant-numeric: tabular-nums; line-height: 1.15; }
  .m-bar-hint { overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
  .m-bar-hint:empty { display: none; }
  .m-bar .btn { flex: none; height: 48px; padding: 0 20px; font-size: 15px; }

  /* Review: buttons stack, Send full width */
  .review { padding: 12px 12px 24px; }
  .review-bar { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .review-note { order: -1; grid-column: 1 / -1; }
  .review-bar #sendOrder { order: 3; grid-column: 1 / -1; height: 52px; font-size: 15px; }
  .send-note { margin: 8px 0 12px; text-align: left; }
  .sheet { padding: 16px; border: 1px solid var(--rule); box-shadow: none; }

  /* Outbox: one card per order */
  .outbox { padding: 12px 12px 24px; }
  .outbox-table thead { display: none; }
  .outbox-table, .outbox-table tbody { display: block; }
  .outbox-table tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "store total" "ref lines" "status status";
    gap: 4px 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--rule);
  }
  .outbox-table td { display: block; padding: 0; border: 0; }
  .outbox-table .o-store { grid-area: store; }
  .outbox-table .o-total { grid-area: total; font-size: 16px; }
  .outbox-table .o-ref { grid-area: ref; font-size: 13px; }
  .outbox-table .o-lines { grid-area: lines; color: var(--muted); font-size: 13px; font-weight: 400; }
  .outbox-table .o-status { grid-area: status; padding-top: 6px; }

  /* Browse fills the screen; the tablet panel nearly does */
  dialog { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border-radius: 0; }
  dialog.dialog-small { width: calc(100vw - 24px); height: fit-content; max-height: calc(100dvh - 24px); margin: auto; border-radius: 6px; }
  .dialog-head { padding: 14px 16px 0; }
  .dialog-tools { padding: 12px 16px 0; }
  .browse-list { padding: 0 10px calc(16px + env(safe-area-inset-bottom)); }
  .facts { margin: 12px 16px 0; }
  .fact { grid-template-columns: 104px minmax(0, 1fr); gap: 12px; }
  .dialog-foot { padding: 16px; }

  .setup { padding: 24px 16px; }
  .setup-card { padding: 24px 20px; }
  .setup h2 { font-size: 22px; }
}

/* The purchase order on a phone screen: one block per line. Screen only:
   the PDF and printing keep the pinned A4 layout the PO to Sage Helper reads. */
@media screen and (max-width: 699px) {
  .sheet .po { font-size: 14px; }
  .sheet .po-brand { font-size: 10px; }
  .sheet .po-title { font-size: 20px; }
  .sheet .po-meta { grid-template-columns: minmax(0, 1fr); gap: 12px; padding: 12px 0; }
  .sheet .po-store strong { font-size: 20px; }
  .sheet .po-facts { grid-template-columns: 1fr 1fr; gap: 8px 16px; }
  .sheet .po-facts dd { font-size: 14px; white-space: normal; }
  .sheet .po-lines { display: block; margin-top: 4px; }
  .sheet .po-lines thead { display: none; }
  .sheet .po-lines tbody { display: block; }
  .sheet .po-lines tr { position: relative; display: block; padding: 10px 92px 10px 0; border-bottom: 1px solid #bbb; }
  .sheet .po-lines td { display: inline; padding: 0; border: 0; }
  .sheet .po-lines td:nth-child(3) { color: #555; }
  .sheet .po-lines td:nth-child(3)::after { content: ''; display: block; height: 2px; }
  .sheet .po-lines td:nth-child(n+4):nth-child(-n+7) { font-size: 13px; }
  .sheet .po-lines td:nth-child(4)::after { content: ' \00D7'; font-weight: 400; }
  .sheet .po-lines td:nth-child(6)::before { content: '('; }
  .sheet .po-lines td:nth-child(6)::after { content: ' singles)'; }
  .sheet .po-lines td:nth-child(7)::before { content: 'at '; }
  .sheet .po-lines td:nth-child(8) { position: absolute; top: 10px; right: 0; font-size: 15px; }
  .sheet .po-totals { width: 100%; }
  .sheet .po-extra { grid-template-columns: minmax(0, 1fr); gap: 12px; }
}

/* Printing (Download PDF) prints the purchase order only */

@page { size: A4; margin: 14mm; }

@media print {
  body { display: block; height: auto; overflow: visible; background: #fff; }
  .sidebar, .topbar, .outbox-banner, .content, .setup, .outbox, .review-bar, .send-note, dialog { display: none !important; }
  .main, .review { display: block; padding: 0; overflow: visible; }
  .sheet { max-width: none; margin: 0; padding: 0; box-shadow: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
