/* Option Agric — office UI.
 *
 * Plain on purpose: legible on a cheap monitor, quick on a slow PC, no build
 * step and no framework. But consistent — one spacing scale, one type scale,
 * one set of controls, so every page looks like the same program.
 */

:root {
  /* Ink. Four steps, no more — anything else is decoration pretending to be
     hierarchy. */
  --ink: #1a1d21;          /* body text                                   */
  --ink-2: #4a5259;        /* secondary text that still has to be read    */
  --muted: #646e7c;        /* labels and hints                            */
  --line: #dfe3e8;         /* hairlines                                   */
  --line-strong: #bcc3cb;  /* input borders, so fields look like fields   */

  /* Ground */
  --bg: #f2f4f6;
  --card: #ffffff;
  --sunken: #f7f8fa;

  /* Brand. One navy, borrowed from the letterhead. No second accent — a
     second colour would compete with the semantic ones below. */
  --brand: #10357e;
  --brand-ink: #0b2557;
  --brand-wash: #eaeefa;

  /* Semantic. Used only to mean something, never for decoration. */
  --ok-bg: #e8f4ec;   --ok-ink: #1a6338;   --ok-line: #c2ddcd;
  --bad-bg: #fdeded;  --bad-ink: #9b2220;  --bad-line: #e8c4c4;
  --warn-bg: #fdf5e6; --warn-ink: #855812; --warn-line: #e8d6b0;

  /* Type scale. Six steps. Every size in the sheet is one of these — the
     previous sheet had drifted to fourteen, which reads as carelessness even
     when no single choice is wrong. */
  --fs-xs: 12px;     /* table headings, chips                             */
  --fs-sm: 13px;     /* hints, secondary lines                           */
  --fs-base: 15px;   /* everything else                                  */
  --fs-lg: 17px;     /* section headings                                 */
  --fs-xl: 20px;     /* page title, and the figure in a summary band      */

  /* Two weights. Bold on nineteen different things is not emphasis. */
  --fw-normal: 400;
  --fw-bold: 600;

  /* Spacing */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;

  /* Corners. Business software, not a consumer app: square enough to look
     like a tool, rounded just enough not to look unfinished. */
  --radius: 4px;
  --radius-sm: 3px;

  --chip: #eef1f5;         /* neutral chip / tag ground                   */
  --nav-link: #c9d5ee;     /* navigation text at rest, on the navy bar    */

  --mono: ui-monospace, "Cascadia Mono", Consolas, "Courier New", monospace;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font: 15px/1.55 -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

.wrap { max-width: 1120px; margin: 0 auto; padding: 0 var(--s5); }
@media (max-width: 640px) { .wrap { padding: 0 var(--s3); } }

/* ============================ navigation ============================ */
/*
 * One set of links, two shapes.
 *
 * Wide: a row across the bar, group headings hidden.
 * Phone: a labelled sheet behind a hamburger. The row used to scroll
 * horizontally with nothing to say so — Settings simply sat off-screen and a
 * new user had no way to know it existed.
 */

.nav {
  background: var(--brand);
  color: #fff;
  position: relative;
  z-index: 30;
}

.nav-inner {
  display: flex;
  align-items: center;
  gap: var(--s4);
  min-height: 56px;
  flex-wrap: nowrap;
}

.brand {
  font-weight: var(--fw-bold);
  color: #fff;
  text-decoration: none;
  white-space: nowrap;
  flex: 0 0 auto;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* the hamburger — hidden until there is not room for the row */
.nav-toggle { display: none; }

.nav-panel {
  display: flex;
  align-items: center;
  gap: var(--s1);
  flex: 1 1 auto;
  min-width: 0;
}

.nav-panel a {
  color: var(--nav-link);
  text-decoration: none;
  font-size: var(--fs-base);
  white-space: nowrap;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
}
.nav-panel a:hover { color: #fff; background: rgba(255, 255, 255, 0.1); }
.nav-panel a.on { color: #fff; background: rgba(255, 255, 255, 0.18); font-weight: var(--fw-bold); }

/* group headings and the in-panel account block belong to the phone sheet */
.nav-group-label, .nav-account { display: none; }

.nav-out { display: flex; align-items: center; gap: var(--s2); flex: 0 0 auto; white-space: nowrap; }
.who { font-size: var(--fs-sm); color: var(--nav-link); }
.who-un { opacity: 0.8; font-family: var(--mono); font-size: var(--fs-xs); }

.link {
  background: none; border: 0; color: #fff; cursor: pointer;
  font: inherit; font-size: var(--fs-sm); text-decoration: underline; padding: 0;
}

.nav-backdrop { display: none; }

@media (max-width: 1040px) {
  .who { display: none; }
}

/* ---------------------------------------------------------------- phone -- */

@media (max-width: 860px) {

  .nav-out { display: none; }

  .nav-toggle {
    display: flex;
    align-items: center;
    gap: var(--s2);
    margin-left: auto;
    flex: 0 0 auto;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.25);
    color: #fff;
    font: inherit;
    font-size: var(--fs-base);
    font-weight: var(--fw-bold);
    padding: 9px 14px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    min-height: 44px;   /* full touch target */
  }
  .nav-toggle:hover { background: rgba(255, 255, 255, 0.2); }

  .burger { display: block; width: 16px; height: 12px; position: relative; }
  .burger span {
    position: absolute; left: 0; right: 0; height: 2px;
    background: #fff; border-radius: var(--radius-sm);
    transition: transform 0.18s ease, opacity 0.18s ease;
  }
  .burger span:nth-child(1) { top: 0; }
  .burger span:nth-child(2) { top: 5px; }
  .burger span:nth-child(3) { top: 10px; }

  /* the bars become a cross while the sheet is open */
  .nav.open .burger span:nth-child(1) { transform: translateY(5px) rotate(45deg); }
  .nav.open .burger span:nth-child(2) { opacity: 0; }
  .nav.open .burger span:nth-child(3) { transform: translateY(-5px) rotate(-45deg); }

  .nav-panel {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #fff;
    color: var(--ink);
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: var(--s2) 0 var(--s3);
    border-bottom: 1px solid var(--line);
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.18);
    max-height: calc(100vh - 56px);
    overflow-y: auto;
  }
  .nav.open .nav-panel { display: flex; }

  .nav-group-label {
    display: block;
    margin: var(--s3) 0 var(--s1);
    padding: 0 var(--s4);
    font-size: var(--fs-xs);
    font-weight: var(--fw-bold);
    color: var(--muted);
  }
  .nav-group-label:first-child { margin-top: var(--s1); }

  .nav-panel a {
    color: var(--ink);
    /* menu rows are a touch target first and text second */
    font-size: 16px;
    font-weight: var(--fw-normal);
    padding: 13px var(--s4);
    border-radius: 0;
    border-left: 3px solid transparent;
    white-space: normal;
  }
  .nav-panel a:hover { background: var(--sunken); color: var(--ink); }
  .nav-panel a.on {
    background: var(--brand-wash);
    border-left-color: var(--brand);
    color: var(--brand);
    font-weight: var(--fw-bold);
  }

  .nav-account {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s3);
    margin: var(--s3) var(--s4) 0;
    padding-top: var(--s3);
    border-top: 1px solid var(--line);
  }
  .nav-account form { margin: 0; }
  .nav-who { font-size: var(--fs-sm); color: var(--ink-2); font-weight: var(--fw-bold); }
  .nav-who .who-un { display: block; color: var(--muted); font-weight: var(--fw-normal); }
  .nav-role {
    display: inline-block; margin-top: 2px;
    font-size: var(--fs-xs);
    font-weight: var(--fw-bold); color: var(--muted);
    background: var(--chip); padding: 1px 7px; border-radius: var(--radius-sm);
  }

  .nav-backdrop {
    display: block;
    position: fixed;
    inset: 56px 0 0;
    background: rgba(10, 16, 30, 0.45);
    z-index: 20;
  }
  .nav-backdrop[hidden] { display: none; }

  /* the page must not scroll behind the open sheet */
  body.nav-locked { overflow: hidden; }
}

@media (max-width: 420px) {
  .brand { max-width: 118px; font-size: var(--fs-sm); }
}

/* Only on a genuinely tiny screen does the label go; the icon alone is what
   made the previous navigation undiscoverable, so it is the last thing cut. */
@media (max-width: 330px) {
  .nav-toggle-text { display: none; }
  .nav-toggle { padding: 10px 12px; }
}

/* ============================== cards =============================== */

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--s5);
  margin: var(--s5) 0;
}
.card.narrow { max-width: 560px; margin-inline: auto; }
.login { margin-top: 8vh; }
@media (max-width: 640px) { .card { padding: var(--s4); } }

/* ============================ typography ============================ */

h1 { margin: 0 0 var(--s1); font-size: var(--fs-xl); font-weight: var(--fw-bold); line-height: 1.25; letter-spacing: -0.2px; }
h2 { margin: 0 0 var(--s2); font-size: var(--fs-lg); font-weight: var(--fw-bold); line-height: 1.3; }
p  { margin: 0 0 var(--s3); }
p:last-child { margin-bottom: 0; }

.muted { color: var(--muted); }
.small { font-size: var(--fs-sm); }
.mono  { font-family: var(--mono); font-size: var(--fs-sm); }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }

a { color: var(--brand); }
a:hover { color: var(--brand-ink); }

section { margin-top: var(--s5); padding-top: var(--s5); border-top: 1px solid var(--line); }

code {
  font-family: var(--mono);
  font-size: var(--fs-sm);
  background: var(--sunken);
  border: 1px solid var(--line);
  padding: 1px 5px;
  border-radius: var(--radius-sm);
}

/* ========================== page headings =========================== */

.editor-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s4);
  flex-wrap: wrap;
}
.editor-actions { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }
.editor-actions form { margin: 0; }

/* ============================== forms =============================== */

fieldset {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--s4) var(--s4) var(--s2);
  margin: 0 0 var(--s4);
  min-width: 0;
}
legend { font-weight: var(--fw-bold); padding: 0 var(--s2); color: var(--brand); font-size: var(--fs-base); }

label { display: block; margin-bottom: var(--s3); font-size: var(--fs-sm); font-weight: var(--fw-bold); }
.hint { font-weight: var(--fw-normal); color: var(--muted); }

input[type=text], input[type=password], input[type=number], input[type=date],
input:not([type]), textarea, select {
  display: block;
  width: 100%;
  margin-top: var(--s1);
  padding: 8px 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  font: inherit;
  font-weight: var(--fw-normal);
  color: var(--ink);
  background: #fff;
}
input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--brand);
  outline-offset: -1px;
  border-color: var(--brand);
}
input:disabled, textarea:disabled, select:disabled { background: var(--sunken); color: var(--muted); }
textarea { resize: vertical; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 var(--s4); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 var(--s4); }
@media (max-width: 760px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

.check { display: flex; align-items: center; gap: var(--s2); margin-top: var(--s1); font-weight: var(--fw-normal); }
.check input[type=checkbox] { width: auto; margin: 0; }
.inline-num { width: 60px !important; display: inline-block !important; margin: 0 2px !important; padding: 4px 6px !important; }

.filters {
  display: flex;
  align-items: flex-end;
  gap: var(--s3) var(--s4);
  flex-wrap: wrap;
  padding: var(--s3) 0 var(--s4);
  border-bottom: 1px solid var(--line);
  margin-bottom: var(--s3);
}
.filters .inline { margin: 0; }
.filters .inline input, .filters .inline select { min-width: 120px; }

/* ============================= buttons ============================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s1);
  padding: 8px 16px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  font: inherit;
  font-weight: var(--fw-bold);
  font-size: var(--fs-base);
  line-height: 1.4;
  cursor: pointer;
  text-decoration: none;
  color: var(--ink);
  white-space: nowrap;
}
.btn:hover { background: var(--sunken); border-color: var(--muted); color: var(--ink); }
.btn:active { transform: translateY(1px); }

.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-ink); border-color: var(--brand-ink); color: #fff; }

.btn.danger { border-color: var(--bad-line); color: var(--bad-ink); background: #fff; }
.btn.danger:hover { background: var(--bad-bg); border-color: var(--bad-ink); color: var(--bad-ink); }

.btn.big { padding: 11px 24px; font-size: var(--fs-base); }
.btn.small { padding: 4px 10px; font-size: var(--fs-sm); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.inline-form { display: inline; margin: 0; }

/* ============================= messages ============================= */

.flash {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: var(--fs-base);
  margin: var(--s4) 0;
  border: 1px solid transparent;
}
.flash-ok  { background: var(--ok-bg);  color: var(--ok-ink);  border-color: var(--ok-line); }
.flash-bad { background: var(--bad-bg); color: var(--bad-ink); border-color: var(--bad-line); }
.flash ul { margin: var(--s1) 0 0; padding-left: 20px; }
.flash a { color: inherit; }

.note {
  background: var(--sunken);
  border: 1px solid var(--line);
  border-left: 3px solid var(--brand);
  padding: 10px 14px;
  font-size: var(--fs-sm);
  color: var(--ink-2);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin: var(--s2) 0 0;
}
.note.warn { border-left-color: var(--warn-ink); background: var(--warn-bg); color: var(--warn-ink); border-color: var(--warn-line); }

.msg { font-size: var(--fs-sm); min-height: 20px; margin: var(--s2) 0 0; color: var(--muted); }
.msg.ok  { color: var(--ok-ink); }
.msg.bad { color: var(--bad-ink); }

/* ============================== tables ============================== */

.table-scroll { overflow-x: auto; }

table.grid { width: 100%; border-collapse: collapse; margin-top: var(--s3); }
table.grid th, table.grid td {
  border-bottom: 1px solid var(--line);
  padding: 9px 10px;
  text-align: left;
  vertical-align: middle;
}
table.grid th {
  font-size: var(--fs-sm);
  color: var(--ink-2);
  font-weight: var(--fw-bold);
  border-bottom: 1px solid var(--line-strong);
  white-space: nowrap;
}
table.grid th .hint { display: block; text-transform: none; letter-spacing: 0; font-size: var(--fs-xs); font-weight: var(--fw-normal); }
table.grid tbody tr:hover { background: var(--sunken); }
table.grid tbody tr:last-child td { border-bottom: 0; }
table.grid input, table.grid select { margin-top: 0; padding: 5px 8px; font-size: var(--fs-base); }
table.grid input.mono { font-family: var(--mono); }
.narrow-input { width: 140px !important; display: inline-block !important; }

.row-actions { display: flex; gap: var(--s1); align-items: center; }
.row-actions form { margin: 0; }

/* ============================= register ============================= */

.filters.wrapped { flex-wrap: wrap; }
.totals-strip { margin: var(--s2) 0 0; }

.status-form { display: inline; }
.status-select {
  text-transform: capitalize;
  width: auto !important;
  display: inline-block !important;
  margin: 0 !important;
  padding: 3px 22px 3px 9px !important;
  font-size: var(--fs-xs);
  font-weight: var(--fw-bold);
  border-radius: var(--radius-sm);
  background: var(--chip);
  color: var(--ink-2);
  border-color: transparent;
}
.status-select.sent { background: var(--brand-wash); color: var(--brand); }
.status-select.accepted, .status-select.paid { background: var(--ok-bg); color: var(--ok-ink); }
.status-select.cancelled, .status-select.expired { background: var(--bad-bg); color: var(--bad-ink); }

.pill {
  display: inline-block;
  vertical-align: middle;
  font-size: var(--fs-xs);
  font-weight: var(--fw-bold);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  background: var(--chip);
  color: var(--muted);
}
.pill.locked { background: var(--bad-bg); color: var(--bad-ink); }

.status {
  display: inline-block;
  text-transform: capitalize;
  font-size: var(--fs-xs); font-weight: var(--fw-bold);
  padding: 2px 9px; border-radius: var(--radius-sm); background: var(--chip); color: var(--ink-2);
}
.status.sent { background: var(--brand-wash); color: var(--brand); }
.status.accepted, .status.paid { background: var(--ok-bg); color: var(--ok-ink); }
.status.cancelled, .status.expired { background: var(--bad-bg); color: var(--bad-ink); }

/* ============================ dashboard ============================= */

/* A summary band, not dashboard widgets.
 *
 * These were boxed cards with a fill and 28px figures in brand navy. Navy is
 * the colour of links and the primary button — using it for a number that is
 * neither implies something is clickable. And a figure does not need to be the
 * largest thing on the page to be found; it only needs to be the only large
 * thing in its row. Hairline dividers and a single bold step do that, and read
 * like a statement rather than an analytics panel.
 */
.tiles {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin: var(--s5) 0;
  background: var(--card);
  overflow: hidden;
}
.tile {
  padding: var(--s3) var(--s4);
  border-left: 1px solid var(--line);
}
.tile:first-child { border-left: 0; }

.tile-label {
  display: block;
  font-size: var(--fs-sm);
  color: var(--muted);
  font-weight: var(--fw-normal);
}
.tile-value {
  display: block;
  font-size: var(--fs-xl);
  font-weight: var(--fw-bold);
  color: var(--ink);
  margin-top: 2px;
  line-height: 1.2;
  /* digits line up between rows, which is the whole reason to set a figure
     apart in the first place */
  font-variant-numeric: tabular-nums;
}
/* not a figure — a state. It should not be typeset as one. */
.tile-value.small {
  font-size: var(--fs-base);
  font-weight: var(--fw-normal);
  color: var(--ink-2);
  padding: 3px 0;
}

@media (max-width: 760px) {
  .tiles { grid-template-columns: 1fr; }
  .tile { border-left: 0; border-top: 1px solid var(--line); }
  .tile:first-child { border-top: 0; }
}

/* money reads as a column of figures wherever it appears */
.mono, td.right { font-variant-numeric: tabular-nums; }

.next-up { margin-top: var(--s5); padding-top: var(--s4); border-top: 1px solid var(--line); }

/* ============================ signature ============================= */

.sig-preview {
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  min-height: 92px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s2);
  margin-bottom: var(--s3);
}
.sig-preview img { max-height: 72px; mix-blend-mode: multiply; }

/* ========================= document editor ========================== */

.docnum { color: var(--brand); }
.save-state { font-size: var(--fs-sm); color: var(--muted); }
.save-state.bad { color: var(--bad-ink); }

table.lines { width: 100%; border-collapse: collapse; margin-bottom: var(--s3); }
table.lines th {
  font-size: var(--fs-xs); color: var(--muted);
  text-align: left; padding: 0 6px var(--s1); font-weight: var(--fw-bold);
}
table.lines td { padding: 2px 4px; vertical-align: middle; }
table.lines input { margin-top: 0; padding: 6px 8px; }
table.lines .w-qty { width: 72px; }
table.lines .w-part { width: 150px; }
table.lines .w-price { width: 130px; }
table.lines .w-amt { width: 130px; text-align: right; }
table.lines .w-x { width: 36px; }
table.lines .l-amount {
  text-align: right; font-weight: var(--fw-bold); font-family: var(--mono); font-size: var(--fs-sm);
}

.linkline a { color: inherit; font-weight: var(--fw-bold); }

/* a control that is working — PDF rendering takes about two seconds */
.btn.is-busy, a.is-busy {
  opacity: 0.65;
  pointer-events: none;
  cursor: progress;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

/* ============================ danger zone =========================== */

.danger-zone {
  border: 1px solid var(--bad-line);
  background: var(--bad-bg);
  border-radius: var(--radius);
  padding: var(--s4);
  margin-top: var(--s5);
}
.danger-zone h2 { color: var(--bad-ink); margin-bottom: var(--s1); }
.danger-zone p { font-size: var(--fs-sm); color: var(--ink-2); }
.danger-zone form { margin-top: var(--s3); }

/* ========================== the printed guide ======================= */

.guide-steps { counter-reset: step; list-style: none; padding: 0; margin: var(--s5) 0 0; }
.guide-steps > li {
  counter-increment: step;
  position: relative;
  padding: 0 0 var(--s5) 46px;
  margin-bottom: var(--s5);
  border-bottom: 1px solid var(--line);
}
.guide-steps > li:last-child { border-bottom: 0; margin-bottom: 0; }
.guide-steps > li::before {
  content: counter(step);
  position: absolute; left: 0; top: 0;
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--brand); color: #fff;
  font-weight: var(--fw-bold); font-size: var(--fs-base);
  display: flex; align-items: center; justify-content: center;
}
.guide-steps h2 { margin: var(--s1) 0 var(--s2); font-size: var(--fs-lg); }
.guide-steps ul { margin: 0 0 var(--s3); padding-left: 20px; }
.guide-steps li li { margin-bottom: var(--s1); }

.guide-table td { padding: 7px 10px; font-size: var(--fs-base); }
.guide-table td.k { width: 42%; font-weight: var(--fw-bold); }
.guide-foot { margin-top: var(--s5); padding-top: var(--s3); border-top: 1px solid var(--line); }

@media print {
  .nav, .no-print, .flash { display: none !important; }
  body { background: #fff; font-size: 11pt; }
  .wrap { max-width: none; padding: 0; }
  .card { border: 0; margin: 0; padding: 0; border-radius: 0; }
  .guide-steps > li { page-break-inside: avoid; }
  .note { background: var(--brand-wash) !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  a { text-decoration: none; color: inherit; }
}

/* ====================================================================
   MOBILE
   --------------------------------------------------------------------
   The office PC is one way in; a phone on the office wifi is the other,
   and probably the commoner one. Below 760px the layout stops being a
   narrowed desktop and becomes its own thing: tables turn into stacked
   cards, controls grow to a thumb-sized target, and the save bar sticks
   to the bottom of the screen.
   ==================================================================== */

@media (max-width: 760px) {

  /* iOS zooms the page in when it focuses an input smaller than 16px.
     Nothing else on the page is 16px, so this is purely to stop that. */
  input[type=text], input[type=password], input[type=number], input[type=date],
  input:not([type]), textarea, select {
    /* Deliberately off the type scale. Below 16px, iOS zooms the page in when a
       field is focused and the user has to pinch back out after every one. */
    font-size: 16px;
    padding: 10px 12px;
  }

  body { font-size: var(--fs-base); }
  .card { padding: var(--s4); margin: var(--s3) 0; border-radius: 0;
          border-left: 0; border-right: 0; }
  .wrap { padding: 0; }
  .wrap > .flash { margin-inline: var(--s3); }

  h1 { font-size: var(--fs-xl); }

  /* thumb-sized controls */
  .btn { padding: 11px 16px; font-size: var(--fs-base); }
  .btn.small { padding: 8px 12px; font-size: var(--fs-sm); }
  .editor-actions { width: 100%; }
  .editor-actions .btn, .editor-actions form { flex: 1 1 auto; }
  .editor-actions .btn { justify-content: center; }

  .editor-head { flex-direction: column; align-items: stretch; gap: var(--s3); }

  /* filters become a single stacked block */
  .filters { flex-direction: column; align-items: stretch; gap: var(--s3); }
  .filters .inline, .filters .inline input, .filters .inline select { width: 100%; min-width: 0; }
  .filters .btn { width: 100%; }

  /* ---- tables become cards -------------------------------------- */
  .table-scroll { overflow: visible; }

  table.grid, table.grid tbody, table.grid tr, table.grid td { display: block; width: 100%; }
  table.grid thead { display: none; }

  table.grid tr {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    margin-bottom: var(--s3);
    padding: var(--s3);
    background: #fff;
  }
  table.grid tbody tr:hover { background: #fff; }

  table.grid td {
    border: 0;
    padding: var(--s1) 0;
    text-align: left !important;
  }
  table.grid td:empty { display: none; }

  /* the header each cell lost, put back in front of its value */
  table.grid td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: var(--fs-xs);
    font-weight: var(--fw-bold);
    color: var(--muted);
    margin-bottom: 2px;
  }

  table.grid td.cell-actions {
    padding-top: var(--s3);
    margin-top: var(--s2);
    border-top: 1px solid var(--line);
  }

  /* Two fields per line where they read naturally as a pair, so a document is
     about half as tall without losing a single label. */
  table.grid tr {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--s2) var(--s3);
  }
  table.grid td[data-label="Customer"],
  table.grid td[data-label="What was deleted"],
  table.grid td.cell-actions,
  table.grid td:not([data-label]) { grid-column: 1 / -1; }

  table.grid td[data-label]::before { color: var(--muted); }

  /* the number and the money are what people scan for */
  table.grid td[data-label="Number"],
  table.grid td[data-label="Total"] { font-size: var(--fs-lg); }
  .row-actions { flex-wrap: wrap; }
  .row-actions .btn { flex: 1 1 auto; }
  .narrow-input { width: 100% !important; }

  /* ---- the document editor -------------------------------------- */

  table.lines, table.lines tbody, table.lines tr, table.lines td { display: block; width: 100%; }
  table.lines thead { display: none; }
  table.lines tr {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: var(--s3);
    margin-bottom: var(--s3);
    position: relative;
    background: var(--sunken);
  }
  table.lines td { padding: var(--s1) 0; }
  table.lines td::before {
    content: attr(data-label);
    display: block;
    font-size: var(--fs-xs);
    font-weight: var(--fw-bold); color: var(--muted); margin-bottom: 2px;
  }
  table.lines .w-qty, table.lines .w-part, table.lines .w-price, table.lines .w-amt { width: auto; }
  table.lines .l-amount { text-align: left; font-size: var(--fs-lg); }
  table.lines .w-x { position: absolute; top: var(--s2); right: var(--s2); width: auto; }
  table.lines .w-x::before { content: none; }

  /* Save follows you down a long form */
  .sticky-save {
    position: sticky;
    bottom: 0;
    z-index: 20;
    background: rgba(255, 255, 255, 0.97);
    border-top: 1px solid var(--line);
    padding: var(--s3) var(--s4);
    margin: var(--s4) 0 calc(-1 * var(--s4));
    display: flex;
    gap: var(--s2);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.06);
  }
  .sticky-save .btn { flex: 1; justify-content: center; }


  .grid-2, .grid-3 { gap: 0; }

  /* the guide reads as a column, not an indented list */
  .guide-steps > li { padding-left: 38px; }
  .guide-steps > li::before { width: 26px; height: 26px; font-size: var(--fs-sm); }
  .guide-table td { display: block; }
  .guide-table td.k { width: auto; padding-bottom: 0; }
}

/* very small phones */
@media (max-width: 400px) {
  .brand { max-width: 110px; }
  .nav-links a { font-size: var(--fs-sm); padding: var(--s1) 6px; }
}

/* ---- collapsible filter panel -------------------------------------
   On a phone six filter controls fill the screen before a single
   document is visible, so they fold away behind a summary. On a desktop
   there is room for them, so the panel is always open and the summary
   is not shown at all. */

.filter-panel > summary { display: none; }
.filter-panel[open] > .filters { display: flex; }

@media (max-width: 760px) {
  .filter-panel > summary {
    display: flex;
    align-items: center;
    gap: var(--s2);
    cursor: pointer;
    list-style: none;
    padding: 11px var(--s3);
    margin-bottom: var(--s3);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    font-weight: var(--fw-bold);
    font-size: var(--fs-base);
    background: #fff;
  }
  .filter-panel > summary::-webkit-details-marker { display: none; }
  .filter-panel > summary::after {
    content: "▾";
    margin-left: auto;
    color: var(--muted);
  }
  .filter-panel[open] > summary::after { content: "▴"; }
  .filter-panel > .filters { border-bottom: 0; padding-top: 0; }
}

/* ====================================================================
   Editor totals, and the other rules the stylesheet rewrite dropped.
   Found by auditing every class used in a view against the rules that
   actually exist — the totals block had been rendering unstyled, which
   is why "Subtotal" and its figure ran together on the phone.
   ==================================================================== */

.editor { display: block; }

.totals-panel {
  display: flex;
  justify-content: flex-end;
  margin: var(--s4) 0 var(--s5);
}
.totals-lines {
  width: 320px;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--sunken);
}

.trow {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--s4);
  padding: 9px var(--s4);
  border-bottom: 1px solid var(--line);
  font-size: var(--fs-base);
}
.trow:last-child { border-bottom: 0; }

.trow .num {
  font-family: var(--mono);
  font-weight: var(--fw-bold);
  text-align: right;
  white-space: nowrap;
}

.trow.grand {
  background: #fff;
  border-top: 2px solid var(--brand);
  font-size: var(--fs-lg);
  font-weight: var(--fw-bold);
  padding: 12px var(--s4);
}
.trow.grand .num { font-size: var(--fs-xl); color: var(--brand); }

/* the Kwacha equivalent is internal — it must never look like part of the
   customer-facing total. PLAN.md §5.10 */
.trow.equiv {
  background: var(--warn-bg);
  color: var(--warn-ink);
  font-size: var(--fs-sm);
  border-top: 1px dashed var(--warn-line);
}
.trow.equiv .num { font-size: var(--fs-sm); }

.roe-field { max-width: 260px; }

.rowx {
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--muted);
  border-radius: var(--radius-sm);
  width: 30px;
  height: 30px;
  line-height: 1;
  font-size: var(--fs-lg);
  cursor: pointer;
  padding: 0;
}
.rowx:hover { background: var(--bad-bg); border-color: var(--bad-ink); color: var(--bad-ink); }

.doc-admin { margin-top: var(--s5); }

table.grid.register td { vertical-align: middle; }

@media (max-width: 760px) {
  .totals-panel { margin: var(--s3) 0 var(--s4); }
  .totals-lines { width: 100%; }
  .roe-field { max-width: none; }
  .rowx { width: 34px; height: 34px; }
}

/* ====================================================================
   ACCESSIBILITY PASS — 1 September 2026
   Findings from a full audit; each block says what it fixes.
   ==================================================================== */

/* --- Keyboard focus ------------------------------------------------
   Audit: no interactive element had an author-defined focus style, so a
   keyboard user was relying on whatever the browser happened to draw —
   which on a coloured button against a coloured bar is close to nothing.
   One ring, everywhere, high contrast against both grounds.
   WCAG 2.4.7 Focus Visible. */

:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 3px solid var(--brand);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* on the blue bar the brand-blue ring would disappear, so invert it */
.nav :where(a, button, summary):focus-visible {
  outline-color: #fff;
  outline-offset: 2px;
}

/* the ring must sit above neighbouring rows rather than under them */
:focus-visible { position: relative; z-index: 1; }

/* --- Contrast ------------------------------------------------------
   Audit: .pill was 4.07:1 against its own background, under the 4.5:1
   AA minimum for text this size. --ink-2 gives 7.3:1.
   WCAG 1.4.3 Contrast (Minimum). */

.pill { color: var(--ink-2); }

/* --- Motion --------------------------------------------------------
   Audit: the hamburger animated with no regard for the reduced-motion
   preference. WCAG 2.3.3 Animation from Interactions. */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* --- Touch targets -------------------------------------------------
   Audit: on a 375px screen the row actions were 37px tall and the status
   dropdown 28px — the single most-used control on the register. WCAG
   2.5.8 asks 24px minimum; 44px is the comfortable thumb target and
   there is room for it once the table is a stack of cards. */

@media (max-width: 760px) {
  .btn.small { min-height: 44px; padding: 10px 14px; font-size: var(--fs-base); }
  .status-select { min-height: 44px; padding: 10px 30px 10px 12px !important; font-size: var(--fs-sm); }
  .row-actions { gap: var(--s2); }
  table.grid td.cell-actions .btn { flex: 1 1 auto; }
  .filters .btn { min-height: 44px; }
  input[type=checkbox] { width: 22px !important; height: 22px; }
}

/* Work held on the device and not yet sent. Deliberately amber rather than
   green: it must not read as "done". Somebody who thinks a queued document is
   issued will quote a number that does not exist. */
.flash-warn { background: var(--warn-bg); color: var(--warn-ink); border-color: var(--warn-line); }
.save-state.warn { color: var(--warn-ink); font-weight: var(--fw-bold); }
.save-state.ok { color: var(--ok-ink); }
