/* Purchase desk: the look of every page. Phone first (360 px), then the office monitor (1366 px).
   Light, high contrast, system fonts, every tap target at least 44 px. Nothing is loaded from outside. */
:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --ink: #15191e;
  --muted: #55606d;
  --line: #d6dae0;
  --brand: #0b5c8a;
  --brand-ink: #ffffff;
  --ok: #18794e;
  --ok-bg: #e3f5ec;
  --warn: #9a3412;
  --warn-bg: #ffedd5;
  --amber: #7a4a00;
  --amber-bg: #fff3d6;
  --bad: #b42318;
  --bad-bg: #fde8e6;
  --blue: #0b5c8a;
  --blue-bg: #dcebf5;
  --focus: #1a73e8;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
  --nav-h: 60px;
  --side-w: 184px;
  font-size: 16px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { scroll-padding-top: 64px; }
body {
  background: var(--bg); color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Arial, sans-serif;
  line-height: 1.35; -webkit-text-size-adjust: 100%;
}
body.has-nav { padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px)); }
h1 { font-size: 1.3rem; margin: 0 0 8px; line-height: 1.2; }
h2 { font-size: 1.1rem; margin: 0 0 8px; line-height: 1.2; }
h3 { font-size: 1rem; margin: 16px 0 6px; }
p { margin: 0 0 10px; }
a { color: var(--brand); }
[hidden] { display: none !important; }
.vh { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--muted); }
.money, .num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.num { text-align: right; }
.spacer { flex: 1; }
.icon { width: 22px; height: 22px; flex: none; vertical-align: middle; }
.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

/* Top bar: scrolls away on a phone (it is three lines tall there), stays in place on wider screens */
.topbar {
  position: static; z-index: 30;
  display: flex; align-items: center; gap: 4px 10px; flex-wrap: wrap;
  padding: 6px 12px; min-height: 52px; background: var(--brand); color: var(--brand-ink);
}
.brand { color: var(--brand-ink); font-weight: 700; font-size: 1.1rem; text-decoration: none; white-space: nowrap; }
.brand-site { font-weight: 500; }
.top-facts { display: flex; gap: 2px 12px; flex-wrap: wrap; font-size: 0.85rem; order: 5; width: 100%; opacity: 0.95; }
.top-user { font-weight: 600; max-width: 34vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-form { display: inline; margin: 0; }
.top-btn {
  min-height: 40px; padding: 4px 10px; border-radius: 8px; font: inherit; font-weight: 600; font-size: 0.9rem;
  background: rgba(255, 255, 255, 0.14); border: 1px solid rgba(255, 255, 255, 0.6); color: #fff; cursor: pointer;
}
.top-btn:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }

/* Banners under the top bar */
.strip { padding: 8px 12px; font-size: 0.95rem; font-weight: 600; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.strip-amber { background: #ffcf5c; color: #3d2600; border-bottom: 2px solid #b07a00; }
.strip-blue { background: var(--blue-bg); color: var(--blue); }
.strip-acting { background: #3d2600; color: #fff; }

/* Navigation: a bar at the bottom on a phone, a column at the side on a wide screen */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; display: flex;
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.nav-item {
  flex: 1; min-width: 0; min-height: var(--nav-h); display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 2px; padding: 4px 1px; color: var(--muted); text-decoration: none;
  font-size: 0.7rem; font-weight: 600; text-align: center; border-top: 3px solid transparent;
}
.nav-item span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item.is-on { color: var(--brand); border-top-color: var(--brand); background: #eef5fa; }
.nav-item:focus-visible { outline: 3px solid var(--focus); outline-offset: -3px; }

main { max-width: 1240px; margin: 0 auto; padding: 12px 12px 32px; }

/* Buttons and inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 8px 16px; border-radius: var(--radius);
  border: 1px solid #aab2bd; background: var(--card); color: var(--ink);
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:hover { border-color: #7d8792; }
.btn:focus-visible, input:focus-visible, select:focus-visible, .tile:focus-visible, .sup-card:focus-visible,
.fchip:focus-visible, .line:focus-visible, .key:focus-visible, .tab:focus-visible {
  outline: 3px solid var(--focus); outline-offset: 2px;
}
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-warn { background: var(--warn-bg); border-color: var(--warn); color: var(--warn); }
.btn-danger { color: var(--bad); border-color: var(--bad); }
.btn-big { min-height: 56px; font-size: 1.1rem; padding: 12px 24px; }
.btn-small { min-height: 44px; padding: 6px 12px; font-size: 0.95rem; }
.btn[disabled] { opacity: 0.5; cursor: default; }
label { display: block; font-weight: 600; margin: 12px 0 4px; }
input[type="text"], input[type="search"], input[type="number"], input[type="date"], input[type="password"], select {
  width: 100%; min-height: 48px; padding: 8px 12px; font: inherit; font-size: 1.05rem;
  border: 1px solid #8a96a3; border-radius: 8px; background: #fff; color: var(--ink);
}
.form { max-width: 420px; }
.row-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 8px 0; }
.row-form label { margin: 0; }
.row-form input, .row-form select { width: auto; flex: 1 1 150px; min-width: 0; }
.field-error { color: var(--bad); font-weight: 600; margin: 4px 0 0; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.pad { padding: 14px; margin-bottom: 12px; }
.empty, .soon, .message { padding: 24px 16px; text-align: center; }
.message { max-width: 520px; margin: 24px auto; }
.notice { padding: 10px 12px; border-radius: 8px; font-weight: 600; }
.notice-ok { background: var(--ok-bg); color: var(--ok); }
.notice-bad { background: var(--bad-bg); color: var(--bad); }

.tag {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 0.8rem; font-weight: 700;
  background: #e9edf1; color: #3c4652; white-space: nowrap; vertical-align: middle;
}
.tag-ok { background: var(--ok-bg); color: var(--ok); }
.tag-warn { background: var(--warn-bg); color: var(--warn); }
.tag-amber { background: var(--amber-bg); color: var(--amber); }
.tag-bad { background: var(--bad-bg); color: var(--bad); }
.tag-blue { background: var(--blue-bg); color: var(--blue); }
.tag-grey { background: #dfe3e8; color: #3c4652; }

.spinner {
  display: inline-block; width: 16px; height: 16px; border-radius: 50%; vertical-align: -2px;
  border: 3px solid currentColor; border-right-color: transparent; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }

/* Sign in */
.signin { max-width: 560px; margin: 8px auto; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-top: 12px; }
.tile {
  display: flex; flex-direction: column; justify-content: center; gap: 4px; min-height: 96px; padding: 12px;
  background: var(--card); border: 2px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  color: var(--ink); text-decoration: none; text-align: center;
}
.tile:active { background: #e8f1f8; }
.tile-name { font-size: 1.15rem; font-weight: 700; overflow-wrap: anywhere; }
.tile-sub { font-size: 0.85rem; color: var(--muted); }
.tile.is-off { opacity: 0.55; border-style: dashed; }
.pin-form { max-width: 320px; margin: 0 auto; }
.pin-input { text-align: center; font-size: 1.8rem !important; letter-spacing: 0.4em; min-height: 60px !important; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 12px; }
.key {
  min-height: 68px; font: inherit; font-size: 1.6rem; font-weight: 700; border-radius: var(--radius);
  border: 1px solid #aab2bd; background: var(--card); color: var(--ink); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.key:active { background: #e8f1f8; }
.key-soft { background: #eef1f4; }
.key-ok { background: var(--brand); border-color: var(--brand); color: #fff; font-size: 1.2rem; }

/* Page head, filters, totals */
.page-head { display: flex; align-items: baseline; gap: 6px 14px; flex-wrap: wrap; margin-bottom: 8px; }
.page-head h1 { margin: 0; }
.h-day { font-size: 0.95rem; font-weight: 500; white-space: nowrap; }
.day-pick { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.day-pick label { margin: 0; }
.day-pick input { width: auto; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 8px 0; }
.fchip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 6px 14px; border-radius: 999px;
  border: 1px solid #aab2bd; background: var(--card); color: var(--ink); text-decoration: none; font-weight: 600;
}
.fchip.is-on { background: var(--brand); border-color: var(--brand); color: #fff; }
.fsep { width: 1px; height: 28px; background: var(--line); }
.totals { display: flex; gap: 6px 16px; flex-wrap: wrap; align-items: center; margin: 8px 0 12px; }
.rule-line { font-size: 0.9rem; }

/* Supplier cards */
.cards { display: grid; grid-template-columns: 1fr; gap: 10px; }
.sup-card {
  display: flex; flex-direction: column; gap: 6px; padding: 12px 14px; min-height: 96px;
  color: var(--ink); text-decoration: none; border-left: 6px solid var(--line);
}
.sup-card.has-urgent { border-left-color: var(--warn); }
.sup-card:active { background: #e8f1f8; }
.sup-name { font-weight: 700; font-size: 1.05rem; overflow-wrap: anywhere; }
.sup-value { font-size: 1.25rem; font-weight: 700; }
.sup-value .muted { font-size: 0.9rem; font-weight: 500; }
.sup-counts { display: flex; gap: 6px; flex-wrap: wrap; }
.sup-foot { display: flex; gap: 4px 14px; flex-wrap: wrap; font-size: 0.9rem; }

/* Draft lines: stacked cards on a phone, a table on a wide screen. One table; a heading row per division. */
table { border-collapse: collapse; width: 100%; }
th, td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: 0.82rem; color: var(--muted); font-weight: 700; }
th.num, td.num { text-align: right; }
.lines thead { display: none; }
.lines, .lines tbody { display: block; }
.lines tr.division-head { display: block; margin: 16px 0 8px; }
.lines tr.division-head th {
  display: flex; gap: 4px 10px; flex-wrap: wrap; align-items: baseline; padding: 0; border: 0;
  font-size: 1.1rem; color: var(--ink);
}
.lines tr.division-head .muted { font-size: 0.85rem; font-weight: 500; }
.lines tr.line {
  display: grid; grid-template-columns: 1fr 1fr; gap: 2px 12px; padding: 10px 12px; margin-bottom: 8px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  cursor: pointer;
}
.lines tr.line.is-held { background: #f0f2f4; }
.lines td { display: flex; justify-content: space-between; gap: 8px; border: 0; padding: 3px 0; text-align: right; }
.lines td::before { content: attr(data-label); color: var(--muted); font-size: 0.82rem; font-weight: 600; text-align: left; }
.lines td.c-item { grid-column: 1 / -1; display: block; text-align: left; padding-bottom: 6px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.lines td.c-item::before { content: none; }
.lines td.col-key { font-size: 1.1rem; }
.lines td.c-value { order: 1; }                         /* on a phone: value beside HQ stock, */
.lines td.c-wide { order: 2; grid-column: 1 / -1; }     /* then last PO and last receipt on lines of their own */
.item-name { font-weight: 700; display: block; overflow-wrap: anywhere; }
.item-pack { font-size: 0.85rem; margin-right: 6px; }
.item-flags { display: inline-flex; gap: 4px; flex-wrap: wrap; }
.col-key b { color: var(--brand); }
.mini th, .mini td { padding: 5px 6px; font-size: 0.92rem; }
.kv th { width: 44%; color: var(--ink); font-size: 0.92rem; }

/* The detail drawer: full screen on a phone, a side panel on a wide screen */
.drawer {
  position: fixed; inset: 0; z-index: 60; background: var(--bg); overflow-y: auto; overscroll-behavior: contain;
  padding-bottom: 24px;
}
.drawer-bar { position: sticky; top: 0; z-index: 1; display: flex; justify-content: flex-end; padding: 8px 12px; background: var(--bg); border-bottom: 1px solid var(--line); }
.drawer-body { padding: 12px; outline: none; }
.drawer-shade { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, 0.35); }
body.drawer-open { overflow: hidden; }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; margin: 10px 0; }
.facts > div { display: flex; justify-content: space-between; gap: 8px; border-bottom: 1px solid var(--line); padding: 4px 0; }
.facts dt { color: var(--muted); font-size: 0.88rem; font-weight: 600; }
.facts dd { margin: 0; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.facts.facts-wide { grid-template-columns: 1fr; }
.facts-wide dd { font-weight: 500; white-space: normal; }
.fact-key dd { color: var(--brand); font-size: 1.1rem; }
.spark-box { margin: 6px 0 10px; }
.spark { display: block; width: 100%; height: 64px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; color: var(--brand); }
.spark-line { fill: none; stroke: currentColor; stroke-width: 2; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.spark-axis { stroke: var(--line); stroke-width: 1; vector-effect: non-scaling-stroke; }
.spark-zero { fill: var(--bad); }
.held-box { margin-top: 16px; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
.held-box.is-held { border-color: var(--warn); background: #fff8f1; }
.held-box h3 { margin-top: 0; }

/* Settings */
.tabs { display: flex; gap: 6px; overflow-x: auto; margin: 0 -12px 12px; padding: 0 12px 6px; }
.tab {
  flex: none; min-height: 44px; display: inline-flex; align-items: center; padding: 6px 14px; border-radius: 999px;
  border: 1px solid #aab2bd; background: var(--card); color: var(--ink); text-decoration: none; font-weight: 600; white-space: nowrap;
}
.tab.is-on { background: var(--brand); border-color: var(--brand); color: #fff; }
.links { margin: 0; padding: 0; list-style: none; }
.links li { padding: 10px 0; border-bottom: 1px solid var(--line); }
.links a { font-weight: 700; margin-right: 8px; }
.rule { padding: 10px 0; border-bottom: 1px solid var(--line); }
.rule label { margin-top: 0; }
.rule.has-error input { border-color: var(--bad); }
.stepper { display: flex; gap: 8px; max-width: 320px; }
.stepper input { text-align: center; font-weight: 700; font-size: 1.2rem; min-width: 0; }
.step { min-width: 56px; font-size: 1.4rem; }
.rule-help { margin: 6px 0 0; font-size: 0.9rem; }
.rule-default { white-space: nowrap; }
.save-bar {
  position: sticky; bottom: var(--nav-h); z-index: 5; margin: 0 -12px 12px; padding: 8px 12px;
  background: var(--bg); border-top: 1px solid var(--line);
}
.rows { display: grid; gap: 6px; }
.row {
  display: flex; gap: 8px 12px; flex-wrap: wrap; align-items: center; justify-content: space-between;
  padding: 8px 10px; background: var(--card); border: 1px solid var(--line); border-radius: 8px;
}
.row-main { flex: 1 1 240px; min-width: 0; overflow-wrap: anywhere; }
.row-act { display: flex; gap: 8px; align-items: center; flex: 0 1 auto; }
.row-act select { width: auto; min-width: 150px; }
.search-row { position: sticky; top: 0; z-index: 4; background: var(--bg); padding: 6px 0; }
.person h2 { display: flex; gap: 6px 10px; flex-wrap: wrap; align-items: center; }
.person h2 .muted { font-size: 0.85rem; font-weight: 500; }
.person.is-off { opacity: 0.7; }
.person-actions { display: flex; gap: 8px 16px; flex-wrap: wrap; align-items: center; }
.person-actions .row-form { margin: 0; flex: 1 1 260px; }
.audit-detail span { display: inline-block; margin-right: 8px; overflow-wrap: anywhere; }
.audit td { overflow-wrap: anywhere; }

/* Wide screens: side navigation, cards in columns, lines as a real table */
@media (min-width: 640px) {
  .cards { grid-template-columns: repeat(2, 1fr); }
  .top-facts { order: 0; width: auto; margin-left: 8px; font-size: 0.9rem; }
  .top-user { max-width: none; }
  .facts { grid-template-columns: repeat(3, 1fr); }
  .topbar { position: sticky; top: 0; }
  .search-row { top: 52px; }
}
@media (min-width: 960px) {
  body.has-nav { padding-bottom: 0; padding-left: var(--side-w); }
  .nav {
    top: 0; right: auto; bottom: 0; width: var(--side-w); flex-direction: column; justify-content: flex-start;
    border-top: 0; border-right: 1px solid var(--line); padding: 60px 8px 8px; gap: 4px; z-index: 20;
  }
  .nav-item {
    flex: none; flex-direction: row; justify-content: flex-start; gap: 10px; min-height: 48px; padding: 8px 12px;
    font-size: 0.98rem; border-top: 0; border-left: 4px solid transparent; border-radius: 0 8px 8px 0; text-align: left;
  }
  .nav-item.is-on { border-left-color: var(--brand); }
  .topbar { z-index: 30; margin-left: calc(-1 * var(--side-w)); padding-left: 16px; }
  .cards { grid-template-columns: repeat(3, 1fr); }
  main { padding: 16px 20px 40px; }
  .save-bar { bottom: 0; }

  .lines { display: table; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
  .lines thead { display: table-header-group; }
  .lines tbody { display: table-row-group; }
  .lines tr.division-head { display: table-row; }
  .lines tr.division-head th { display: table-cell; padding: 10px 8px 6px; background: #e6ebf0; font-size: 1rem; border-bottom: 1px solid var(--line); }
  .lines tr.division-head .muted { margin-left: 8px; }
  .lines tr.line { display: table-row; box-shadow: none; border: 0; cursor: pointer; }
  .lines tr.line:hover { background: #eef5fa; }
  .lines tr.line.is-held { background: #f0f2f4; }
  .lines td { display: table-cell; border-bottom: 1px solid var(--line); padding: 7px 8px; text-align: left; white-space: nowrap; }
  .lines td.num { text-align: right; }
  .lines td::before { content: none; }
  .lines td.c-item { display: table-cell; padding-bottom: 7px; margin: 0; white-space: normal; min-width: 200px; }
  .lines thead th { position: sticky; top: 52px; background: #eef1f4; z-index: 2; vertical-align: bottom; }
  .lines td.col-key, .lines thead th.col-key { background: #f3f8fc; }

  .drawer { inset: 0 0 0 auto; width: min(520px, 42vw); border-left: 1px solid var(--line); box-shadow: -8px 0 24px rgba(0, 0, 0, 0.15); }
  .facts { grid-template-columns: 1fr 1fr; }
}
@media (min-width: 1300px) {
  .cards { grid-template-columns: repeat(4, 1fr); }
}
@media print {
  .nav, .topbar .top-form, .drawer, .drawer-shade { display: none !important; }
  body.has-nav { padding: 0; }
}
