/* Components: buttons, fields, tables, badges, type-ahead, line grid, panels. */

/* ---------- buttons ---------- */
.btn {
  font: inherit; font-size: var(--text-sm); font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; gap: var(--space-2xs); white-space: nowrap;
  padding: 8px 14px; border-radius: var(--radius); border: 1px solid var(--rule);
  background: var(--surface); color: var(--ink); text-decoration: none;
  transition: background 0.15s var(--ease-out), border-color 0.15s var(--ease-out);
}
.btn:hover { background: var(--paper-2); border-color: var(--ink-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--surface); }
.btn.primary:hover { background: var(--accent-ink); }
.btn.danger { color: var(--bad); border-color: color-mix(in oklch, var(--bad) 40%, var(--rule)); }
.btn.danger.solid { background: var(--bad); color: var(--surface); border-color: var(--bad); }
.btn.quiet { border-color: transparent; background: transparent; color: var(--ink-2); padding-inline: 8px; }
.btn.quiet:hover { background: var(--paper-2); color: var(--ink); }
.btn[disabled], .btn[aria-busy="true"] { opacity: 0.55; cursor: progress; }
/* Issue 713: a button the app knows is not allowed is grey (aria-disabled) with its reason as visible text beside it, on phone and desktop. */
.btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }
.blocked-reason { display: block; margin-top: var(--space-xs); font-size: var(--text-sm); font-weight: 600; line-height: 1.35; color: var(--ink-2); }
.blocked-reason:empty { display: none; }
.btn.icon { padding: 6px 9px; line-height: 1; }

/* ---------- fields ---------- */
.fields { display: grid; gap: var(--space-md) var(--space-lg); grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
.field { display: grid; gap: var(--space-2xs); align-content: start; min-width: 0; }
.field.wide { grid-column: span 2; }
.field > label, .field > .label { font-size: var(--text-xs); font-weight: 600; color: var(--ink-2); letter-spacing: 0.02em; }
.field .hint { font-size: var(--text-xs); color: var(--ink-3); }
.field .hint.warn { color: var(--warn); font-weight: 600; }
.req::after { content: " *"; color: var(--accent-ink); }
input, select, textarea {
  font: inherit; font-size: var(--text-md); color: var(--ink); width: 100%; min-width: 0;
  padding: 7px 10px; border: 1px solid var(--edge); border-radius: var(--radius); background: var(--surface);
}
input:hover, select:hover { border-color: var(--ink-3); }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--focus); outline-offset: 0; border-color: var(--focus); }
input[aria-invalid="true"] { border-color: var(--bad); background: var(--bad-tint); }
input.need { border-color: var(--warn); background: var(--warn-tint); }
input.num { text-align: right; }

.seg { display: inline-flex; border: 1px solid var(--rule); border-radius: var(--radius); background: var(--surface); padding: 2px; gap: 2px; }
.seg button, .seg label {
  font: inherit; font-size: var(--text-sm); font-weight: 600; border: 0; background: transparent; color: var(--ink-2);
  padding: 5px 12px; border-radius: 4px; cursor: pointer;
}
.seg button[aria-pressed="true"], .seg label:has(input:checked) { background: var(--paper-3); color: var(--ink); }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.seg label:has(input:focus-visible) { outline: 2px solid var(--focus); }

.toolbar { display: flex; flex-wrap: wrap; gap: var(--space-sm); align-items: center; margin-bottom: var(--space-md); }
.toolbar input[type="search"] { max-width: 280px; }
.toolbar label { max-width: 100%; min-width: 0; }
.toolbar select { width: auto; max-width: 100%; min-width: 0; }
.toolbar .count { margin-left: auto; font-size: var(--text-sm); color: var(--ink-2); }
.check { display: inline-flex; gap: var(--space-xs); align-items: center; font-size: var(--text-sm); font-weight: 500; cursor: pointer; }
.check input { width: auto; accent-color: var(--accent); }

/* ---------- tables (ledger) ---------- */
.table-wrap { position: relative; overflow-x: auto; border: 1px solid var(--rule); border-radius: var(--radius-lg); background: var(--surface); }
table.ledger { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.ledger th {
  text-align: left; font-weight: 600; font-size: var(--text-xs); color: var(--ink-2); letter-spacing: 0.03em;
  padding: 9px 12px; border-bottom: 1px solid var(--rule); background: var(--paper-2); white-space: nowrap;
}
.ledger th button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
.ledger th[aria-sort] button { color: var(--ink); }
.ledger td { padding: 8px 12px; border-bottom: 1px solid var(--rule-soft); vertical-align: middle; }
.ledger tbody tr:last-child td { border-bottom: 0; }
.ledger .n { text-align: right; white-space: nowrap; }
.ledger tr.link { cursor: pointer; }
.ledger tr.link:hover td { background: var(--paper); }
.ledger tfoot td { border-top: 2px solid var(--rule); border-bottom: 0; font-weight: 700; background: var(--paper-2); }
.ledger .muted, .muted { color: var(--ink-3); }
.ledger .short { color: var(--bad); font-weight: 800; font-size: var(--text-md); font-family: var(--font-display); }
.ledger .zero { color: var(--ink-3); }
.ledger a.rowlink { color: var(--ink); text-decoration: none; font-weight: 600; }
.ledger a.rowlink:hover { text-decoration: underline; }
.pname { display: inline-flex; gap: var(--space-xs); align-items: baseline; }
.ledger td .pname { min-width: 200px; }
.code { font-size: var(--text-xs); font-weight: 600; color: var(--ink-3); letter-spacing: 0.02em; }

/* ---------- badges + messages ---------- */
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: var(--text-xs); font-weight: 600; white-space: nowrap; border: 1px solid transparent; }
.st-draft { background: var(--paper-3); color: var(--ink-2); }
.st-confirmed { background: var(--ok-tint); color: var(--ok); }
.st-part_dispatched { background: var(--warn-tint); color: var(--warn); }
.st-dispatched { background: var(--info-tint); color: var(--info); }
.st-closed { background: transparent; color: var(--ink-2); border-color: var(--rule); }
.st-cancelled { background: transparent; color: var(--ink-3); border-color: var(--rule); text-decoration: line-through; }
.badge.web, .badge.web-req { background: transparent; color: var(--info); border-color: var(--info); }
.badge.stock { background: var(--info-tint); color: var(--info); margin-left: var(--space-xs); }
.badge.late { background: var(--accent); color: var(--surface); letter-spacing: 0.06em; text-transform: uppercase; }
.inline-msg:empty { display: none; }
.inline-msg { white-space: pre-line; font-size: var(--text-sm); padding: var(--space-xs) var(--space-sm); border-radius: var(--radius); }
.inline-msg.err { background: var(--bad-tint); color: var(--bad); font-weight: 600; }
.inline-msg.ok { background: var(--ok-tint); color: var(--ok); }
.inline-msg.warn { background: var(--warn-tint); color: var(--warn); }
/* A one-time notice on the login screen: 3 pulses in 2 s, then still. Only transform, background and border colour move. */
.inline-msg.pulse { border: 1px solid var(--warn); animation: notice-pulse 0.67s ease-in-out 3; }
@keyframes notice-pulse {
  50% { transform: scale(1.03); background: color-mix(in oklch, var(--warn) 35%, var(--warn-tint)); border-color: var(--ink); }
}
@media (prefers-reduced-motion: reduce) {
  .inline-msg.pulse { animation: none; background: color-mix(in oklch, var(--warn) 35%, var(--warn-tint)); border: 2px solid var(--ink); }
}
.loading { color: var(--ink-3); padding: var(--space-lg) 0; }
.empty { padding: var(--space-2xl) var(--space-lg); text-align: left; max-width: 60ch; }
.empty h2 { margin-bottom: var(--space-xs); }
.empty p { color: var(--ink-2); margin-bottom: var(--space-md); }

/* ---------- type-ahead ---------- */
.cb-wrap { position: relative; }
.cb-list {
  position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 4px); min-width: 300px;
  max-height: 320px; overflow-y: auto; list-style: none; background: var(--surface);
  border: 1px solid var(--rule); border-radius: var(--radius); box-shadow: 0 8px 24px oklch(0.25 0.03 55 / 0.14);
  padding: var(--space-2xs);
}
.cb-list li { padding: 7px 10px; border-radius: 4px; cursor: pointer; display: flex; justify-content: space-between; gap: var(--space-sm); font-size: var(--text-sm); }
.cb-list li[aria-selected="true"] { background: var(--paper-3); }
.cb-list .cb-extra { color: var(--accent-ink); font-weight: 600; border-top: 1px solid var(--rule-soft); }
.cb-list .cb-empty { color: var(--ink-3); cursor: default; }
.cb-list .meta { color: var(--ink-3); font-size: var(--text-xs); white-space: nowrap; }

/* ---------- panels ---------- */
.panel { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-lg); padding: var(--space-lg); }
.panel + .panel { margin-top: var(--space-md); }
.panel > h2 { margin-bottom: var(--space-md); }
.panel.tint { background: var(--paper-2); }
.form-actions { display: flex; flex-wrap: wrap; gap: var(--space-xs); align-items: center; margin-top: var(--space-lg); }
.dl { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: var(--space-sm) var(--space-lg); font-size: var(--text-sm); }
.dl dt { font-size: var(--text-xs); color: var(--ink-3); }
.dl dd { font-weight: 600; }
.confirm-step { display: flex; flex-wrap: wrap; gap: var(--space-xs); align-items: center; padding: var(--space-xs) var(--space-sm); border: 1px solid var(--bad); border-radius: var(--radius); background: var(--bad-tint); font-size: var(--text-sm); color: var(--bad); }
.choices { display: grid; gap: var(--space-xs); }
.choice { display: grid; grid-template-columns: auto 1fr; gap: 2px var(--space-sm); padding: var(--space-sm); border: 1px solid var(--rule); border-radius: var(--radius); cursor: pointer; background: var(--surface); }
.choice:has(input:checked) { border-color: var(--brand); background: var(--paper-2); }
.choice input { width: auto; grid-row: span 2; margin-top: 4px; accent-color: var(--brand); }
.choice b { font-size: var(--text-sm); }
.choice span { font-size: var(--text-xs); color: var(--ink-2); grid-column: 2; }
.log { list-style: none; display: grid; }
.log li { display: flex; gap: var(--space-md); justify-content: space-between; padding: var(--space-xs) 0; border-bottom: 1px solid var(--rule-soft); font-size: var(--text-sm); }
.refused-list { list-style: none; display: grid; }
.refused-list li { display: flex; flex-wrap: wrap; gap: var(--space-sm) var(--space-md); align-items: center; padding: var(--space-xs) 0; border-bottom: 1px solid var(--rule-soft); font-size: var(--text-sm); }
.refused-list li img { max-width: 80px; height: auto; }
.refused-list li > span { flex: 1 1 12rem; min-width: 0; overflow-wrap: anywhere; }

/* Segmented nav of links (Settings tabs) */
.seg a { font-size: var(--text-sm); font-weight: 600; color: var(--ink-2); padding: 5px 12px; border-radius: 4px; text-decoration: none; }
.seg a[aria-current="page"] { background: var(--paper-3); color: var(--ink); }
.seg a:focus-visible { outline: 2px solid var(--focus); }
.set-tabs { margin-bottom: var(--space-md); }
.set-tabs.im-tabs { flex-wrap: wrap; } /* issue 174 rows 28-32: six tabs wrap on a phone */

/* Group header row inside a ledger (family) */
.ledger tr.group-row th { text-align: left; font-family: var(--font-display, inherit); font-size: var(--text-sm); letter-spacing: .04em;
  background: var(--paper-2); color: var(--ink-2); padding: 6px 10px; border-top: 1px solid var(--rule); }

/* Items on website */
.wi-count { font-size: var(--text-md, 1rem); font-weight: 600; margin-bottom: var(--space-sm); }
.wi-group { margin-bottom: var(--space-lg); max-width: 760px; }
.wi-group-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-sm); border-bottom: 1px solid var(--rule); padding-bottom: 4px; }
.wi-group-head h2 { font-size: var(--text-md, 1rem); margin: 0; margin-right: auto; }
.wi-group > summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; }
.wi-group-tools { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-sm); padding: var(--space-xs) 0; }
.wi-meta { display: flex; align-items: center; gap: var(--space-sm); font-variant-numeric: tabular-nums; }
.wi-meta .n { min-width: 5ch; text-align: right; }

/* Website draft edit (issue 124): a list, not a wide table, so a phone needs no side scroll. Touch targets are 44px. */
.edit-lines { list-style: none; margin: 0 0 var(--space-sm); padding: 0; border-top: 1px solid var(--rule); }
.edit-lines li { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-xs) var(--space-sm); padding: var(--space-xs) 0; border-bottom: 1px solid var(--rule); }
.edit-name { flex: 1 1 12rem; min-width: 0; overflow-wrap: anywhere; }
.stepper { display: inline-flex; align-items: center; gap: var(--space-xs); }
.stepper b { min-width: 2ch; text-align: center; font-variant-numeric: tabular-nums; }
.stepper .btn, .edit-lines [data-remove], .edit-add .btn { min-width: 44px; min-height: 44px; }
.edit-lines input[type="number"] { width: 7rem; max-width: 100%; min-height: 44px; }
.cn-parts { list-style: none; margin: 0; padding: 0; flex: 0 0 100%; }
.edit-lines .cn-parts li { border: 0; padding: 0; }
.cn-settle, .cn-new { flex: 0 0 100%; min-width: 0; }
.cn-settle fieldset.seg { display: flex; flex-wrap: wrap; margin: var(--space-sm) 0; }
.cn-settle fieldset.seg legend { float: none; flex: 0 0 100%; padding: 0 0 var(--space-2xs); }
@media (max-width: 640px) {
  fieldset.seg { flex-wrap: wrap; max-width: 100%; } /* the payment Mode group grows with each mode the owner adds */
}
.cn-new summary { min-height: 44px; display: flex; align-items: center; cursor: pointer; font-weight: 600; }
.edit-add { display: flex; flex-wrap: wrap; align-items: end; gap: var(--space-xs); margin-bottom: var(--space-md); }
.edit-add select { flex: 1 1 12rem; min-height: 44px; }

/* Manual stock change and stock count (issue 132): lists that wrap, so a 360px phone needs no side scroll. */
.sa-panel { margin-bottom: var(--space-md); }
.sa-panel .sa-onhand { color: var(--ink-2); margin: 0 0 var(--space-sm); }
.sa-hist { list-style: none; margin: var(--space-sm) 0 0; padding: 0; border-top: 1px solid var(--rule); }
.sa-hist li { display: flex; flex-wrap: wrap; gap: 2px var(--space-sm); padding: var(--space-xs) 0; border-bottom: 1px solid var(--rule); font-size: var(--text-sm); }
.sa-hist .n { font-weight: 700; font-variant-numeric: tabular-nums; }
.sa-hist .sa-note { flex: 1 1 100%; color: var(--ink-2); overflow-wrap: anywhere; }
.sc-list { list-style: none; margin: 0 0 var(--space-sm); padding: 0; border-top: 1px solid var(--rule); }
.sc-list li { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-xs) var(--space-sm); padding: var(--space-xs) 0; border-bottom: 1px solid var(--rule); }
.sc-name { flex: 1 1 12rem; min-width: 0; overflow-wrap: anywhere; }
.sc-have, .sc-diff { font-variant-numeric: tabular-nums; min-width: 4ch; text-align: right; }
.sc-place { font-size: var(--text-sm); color: var(--ink-3); white-space: nowrap; } /* issue 174 rows 58-61: bin label on a count row */
.sc-list input { width: 7rem; min-height: 44px; }
.sc-unit { color: var(--ink-2); min-width: 2.5ch; }
/* Issue 823: Save stays in reach below a long count list. */
.sc-bar { position: sticky; bottom: 0; z-index: 10; background: var(--surface); padding-block: var(--space-xs); border-top: 1px solid var(--rule); }
.sc-err { flex: 1 0 100%; color: var(--bad); font-size: var(--text-sm); font-weight: 600; }
.sc-err:empty { display: none; }
.sc-diff.neg { color: var(--bad); font-weight: 700; }
.sc-diff.pos { color: var(--ok); font-weight: 700; }

/* Bulk confirm on the website drafts list (#10). The tick box sits in a 44px square hit area. */
.ledger th.bk, .ledger td.bk { width: 44px; padding: 0; }
.bk-hit { display: flex; align-items: center; justify-content: center; min-width: 44px; min-height: 44px; cursor: pointer; }
.bk-hit input { width: 22px; height: 22px; accent-color: var(--accent); }
.bk-bar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-sm); margin-bottom: var(--space-sm); }
.bk-bar .btn { min-height: 44px; }
.bk-res { flex-basis: 100%; min-width: 0; overflow-wrap: anywhere; }
.bk-res ul { margin: var(--space-xs) 0 0; padding-left: 1.2em; }
.bc-bar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-sm); margin-bottom: var(--space-sm); max-width: 100%; }
.bc-bar .btn { min-height: 44px; }
.bc-reason { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-xs); flex: 1 1 100%; min-width: 0; font-size: var(--text-sm); }
.bc-reason input { flex: 1 1 12em; min-width: 0; max-width: 100%; }

/* Returns: Find sits next to the order number at its own width; reason and disposition share a row. */
.ret-lookup { grid-template-columns: minmax(200px, 20rem) auto; align-items: end; }
.ret-lookup .btn { width: auto; }
.ret-top { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.ret-top .field:first-child { grid-column: 1 / -1; max-width: 32rem; }
@media (max-width: 640px) { .ret-lookup, .ret-top { grid-template-columns: 1fr; } }
/* Amount check before staff save money (#98): the amount is large so a wrong figure is easy to see. */
.amount-confirm { margin-top: var(--space-sm); padding: var(--space-sm); border: 2px solid var(--rule); border-radius: var(--radius); background: var(--surface); }
.amount-confirm p { margin: 0 0 var(--space-xs); }
.amount-confirm .ac-amt { font-size: var(--text-2xl); font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }
.amount-confirm .ac-party { color: var(--ink-2); }
.amount-confirm .btn { min-height: 44px; }
.amount-confirm .ac-what { font-weight: 700; }

/* Stop order (176): Up and Down for a stop on the route. Large targets for a phone. */
.stop-move { display: flex; gap: 8px; }
.stop-move .btn { flex: 1; min-height: 44px; justify-content: center; }

/* Login end warning (issue 826): inline bar above the notices. */
.login-end { display: flex; gap: var(--space-sm); align-items: center; justify-content: space-between; flex-wrap: wrap; padding: var(--space-sm) var(--space-xl); border-bottom: 1px solid var(--rule); background: var(--warn-tint); }
.login-end[hidden] { display: none; }
.login-end .btn { min-height: 44px; }
/* Notice strip (issue 174, row 188): unread notices for the role, under the season bar. */
.notices { display: grid; gap: var(--space-2xs); padding: var(--space-sm) var(--space-xl); border-bottom: 1px solid var(--rule); background: var(--warn-tint); }
.notices .notice { display: flex; gap: var(--space-sm); align-items: flex-start; justify-content: space-between; flex-wrap: wrap; }
.notices .notice p { margin: 0; color: var(--ink-2); font-size: var(--text-sm); }
.notices .notice .btn { min-height: 44px; }
.notices .notice-alert a { display: inline-flex; align-items: center; min-height: 44px; color: var(--ink); text-decoration: underline; } /* owner alert lines (issue 715) */
fieldset.picks { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: var(--space-2xs) var(--space-md); }
fieldset.picks legend { width: 100%; font-size: var(--text-xs); font-weight: 600; color: var(--ink-2); margin-bottom: var(--space-2xs); }
fieldset.picks .check { min-height: 44px; display: inline-flex; align-items: center; gap: var(--space-2xs); }

/* Assemblies (issue 174, A14 S3): component rows and the need preview. */
.asm-row { align-items: end; margin-bottom: var(--space-sm); }
.asm-need { margin: var(--space-xs) 0 var(--space-sm); padding-left: 1.2em; }
.asm-need li.short, .asm-need b.short { color: var(--warn); font-weight: 600; }

/* Batch-wise stock (row 165 FEFO): red = expired lot, amber = lot near expiry. */
.ledger tr.lot-expired td { background: var(--bad-tint); color: var(--bad); }
.ledger tr.lot-soon td { background: var(--warn-tint); }
.lot-first { color: var(--ok, var(--ink)); white-space: nowrap; }
/* ---------- goods QC (bakery S2): status colours ---------- */
.qc-fail { background: var(--bad-tint); color: var(--bad); }
.qc-pending { background: var(--warn-tint); color: var(--warn); }
.qc-pass { background: var(--ok-tint); color: var(--ok); }
.qc-none { background: var(--paper-3); color: var(--ink-2); }
li.qc-fail { background: var(--bad-tint); }

/* Counter sale (issue 497): the quantity and rate boxes and the remove button are 44px touch targets. */
.counter-sale .ledger input, .counter-sale .ledger .rm { min-height: 44px; }
.counter-sale .ledger .rm { min-width: 44px; }

/* Phone tap areas (issue 672): every button, field, select and checkbox row is at least 44px high. Desktop keeps its density. */
@media (max-width: 860px) {
  .btn, select, textarea, input:not([type="checkbox"], [type="radio"], [type="hidden"]) { min-height: 44px; }
  /* The sticky header (about 61px) must not hide a field or button that a focus or a scroll puts at the top. */
  html { scroll-padding-top: 72px; }
  .check, label:has(> input[type="checkbox"], > input[type="radio"]) { min-height: 44px; display: inline-flex; align-items: center; }
  /* Issue 822: report tabs, small segmented buttons, the order line remove and extras, and the sort buttons in a table head. */
  .seg a, .seg.sm button, .lg-x, .lg-mods .lg-mod, .ledger th button, a.tel { min-height: 44px; }
  .seg a, a.tel { display: inline-flex; align-items: center; }
  .lg-x, .ledger th button { min-width: 44px; }
}

/* Issue 818: stop billing tick on the Parties screen: a 44 px tap target and one inline question */
.sb-stop { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; cursor: pointer; }
.sb-stop input { width: 24px; height: 24px; }
.sb-ask, form[data-stream] .ask { margin-top: 4px; }
.sb-ask .btn, form[data-stream] .ask .btn { min-height: 44px; }
form[data-stream] > .hint { font-size: var(--text-xs); color: var(--ink-3); margin: 8px 0 0; }
.sb-stop-line { margin: 4px 0 0; font-size: var(--text-sm); color: var(--ink-2); }
.sb-stop-line[hidden] { display: none; }
