/* EXIM Purchase & Dispatch -- design tokens and layout.
   Dark by default (matching the sheet app it replaces), light theme available
   via [data-theme="light"] on <html>. */

:root {
  --bg: #0e1116;
  --bg-raised: #161b22;
  --bg-input: #0b0f14;
  --panel: #131920;
  --border: #242c38;
  --border-strong: #323d4d;

  --text: #e6edf3;
  --text-dim: #9aa7b4;
  --text-faint: #6b7987;

  --accent: #4c9aff;
  --accent-dim: #1f4d80;
  --ok: #3fb950;
  --warn: #d9a441;
  --crit: #f2545b;
  --info: #a98bdc;
  --money: #f0b429;

  --radius: 10px;
  --radius-sm: 6px;
  --gap: 16px;
  --sidebar-w: 216px;
  --header-h: 56px;

  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  /* Chart palette -- validated with the dataviz palette validator against this
     app's own dark surface (#131920): lightness band, chroma, CVD separation,
     normal-vision floor and contrast all PASS. Do not hand-tweak these. */
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #9085e9;
  --grid: #2c2c2a;
  --axis: #383835;
  --ink-muted: #898781;
  /* Status colours are fixed and never themed; they always ship with a label. */
  --st-good: #0ca30c;
  --st-warn: #fab219;
  --st-crit: #d03b3b;
  --st-none: #6b7987;

  --mono: ui-monospace, "Cascadia Mono", "SF Mono", Menlo, Consolas, monospace;
}

[data-theme="light"] {
  --bg: #f4f6f9;
  --bg-raised: #ffffff;
  --bg-input: #ffffff;
  --panel: #ffffff;
  --border: #dde3ea;
  --border-strong: #c3ccd7;
  --text: #16202b;
  --text-dim: #566373;
  --text-faint: #8593a3;
  --accent: #1667d6;
  --accent-dim: #cfe0fa;
  --ok: #1a7f37;
  --warn: #9a6700;
  --crit: #cf222e;
  --info: #6639ba;
  --money: #9a6700;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #4a3aa7;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --ink-muted: #898781;
  --st-good: #0ca30c;
  --st-warn: #fab219;
  --st-crit: #d03b3b;
  --st-none: #8593a3;
  --shadow: 0 8px 24px rgba(16, 32, 48, 0.12);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }

/* ------------------------------------------------------------------ shell */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; height: 100vh;
  height: 100dvh; grid-template-rows: minmax(0, 1fr); overflow: hidden; }

.sidebar {
  background: var(--bg-raised);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0;
}
.brand {
  height: var(--header-h); display: flex; align-items: center; gap: 10px;
  padding: 0 16px; border-bottom: 1px solid var(--border); flex: none;
}
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px; flex: none;
  background: linear-gradient(135deg, var(--accent), var(--info));
  display: grid; place-items: center; font-weight: 700; font-size: 13px; color: #fff;
}
.brand-text { font-weight: 650; letter-spacing: .2px; }
.brand-text small { display: block; font-weight: 400; font-size: 11px; color: var(--text-faint); }

/* The menu scrolls inside the sidebar when the window is short (or zoomed in),
   so the page itself never grows taller than the window. */
#sidebar-nav { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
.nav { padding: 10px 8px; }
.nav-group { margin: 14px 8px 6px; font-size: 10.5px; letter-spacing: .09em;
  text-transform: uppercase; color: var(--text-faint); }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; margin-bottom: 2px;
  border-radius: var(--radius-sm); color: var(--text-dim); font-size: 13.5px;
}
.nav a:hover { background: var(--panel); color: var(--text); }
.nav a.active { background: var(--accent-dim); color: var(--text); font-weight: 550; }
.nav a .ic { width: 16px; text-align: center; opacity: .9; flex: none; }
.nav a .badge {
  margin-left: auto; background: var(--crit); color: #fff; font-size: 10.5px;
  border-radius: 9px; padding: 1px 6px; font-weight: 650;
}
.sidebar-foot { padding: 10px; border-top: 1px solid var(--border); flex: none; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar {
  height: var(--header-h); flex: none; display: flex; align-items: center; gap: 12px;
  padding: 0 18px; border-bottom: 1px solid var(--border); background: var(--bg-raised);
}
.topbar h1 { font-size: 16px; margin: 0; font-weight: 600; }
.topbar .spacer { flex: 1; }
.content { flex: 1; overflow: auto; padding: 18px; min-height: 0; }

/* ----------------------------------------------------------------- pieces */
.btn {
  display: inline-flex; align-items: center; gap: 7px; padding: 7px 12px;
  background: var(--panel); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); cursor: pointer; white-space: nowrap; font-size: 13px;
}
.btn:hover { border-color: var(--accent); color: var(--text); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 550; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.danger { border-color: var(--crit); color: var(--crit); }
.btn.danger:hover { background: var(--crit); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
.btn.ghost:hover { background: var(--panel); }
.btn.sm { padding: 4px 8px; font-size: 12px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

input, select, textarea {
  background: var(--bg-input); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); padding: 7px 9px; width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-dim);
}
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 11.5px; color: var(--text-dim); margin-bottom: 5px; }

.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
}
.card h3 { margin: 0 0 2px; font-size: 13.5px; font-weight: 600; }
.card .sub { font-size: 11.5px; color: var(--text-faint); margin-bottom: 12px; }

.grid-2 { display: grid; gap: var(--gap); grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { display: grid; gap: var(--gap); grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { display: grid; gap: var(--gap); grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1280px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 1100px) { .grid-3, .grid-2 { grid-template-columns: 1fr; } }

.muted { color: var(--text-dim); }
.faint { color: var(--text-faint); }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.pos { color: var(--ok); }
.neg { color: var(--crit); }
.row { display: flex; align-items: center; gap: 10px; }
.wrap { flex-wrap: wrap; }

/* ------------------------------------------------------------------- KPIs */
.kpi { position: relative; overflow: hidden; cursor: pointer; }
.kpi:hover { border-color: var(--accent); }
.kpi .k-label { font-size: 11.5px; color: var(--text-dim); text-transform: uppercase;
  letter-spacing: .05em; }
.kpi .k-value { font-size: 25px; font-weight: 650; margin: 7px 0 3px; letter-spacing: -.5px; }
.kpi .k-sub { font-size: 11.5px; color: var(--text-faint); }
.kpi .k-bar { position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--accent); }
.kpi.crit .k-bar { background: var(--crit); }
.kpi.warn .k-bar { background: var(--warn); }
.kpi.ok   .k-bar { background: var(--ok); }
.kpi.money .k-value { color: var(--money); }

/* ----------------------------------------------------------------- alerts */
.alert-list { display: flex; flex-direction: column; gap: 6px; }
.alert-row {
  display: flex; align-items: center; gap: 11px; padding: 9px 11px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg-raised); cursor: pointer;
}
.alert-row:hover { border-color: var(--accent); }
.alert-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.sev-critical .alert-dot { background: var(--crit); box-shadow: 0 0 0 3px rgba(242,84,91,.16); }
.sev-warning  .alert-dot { background: var(--warn); box-shadow: 0 0 0 3px rgba(217,164,65,.16); }
.sev-info     .alert-dot { background: var(--info); box-shadow: 0 0 0 3px rgba(169,139,220,.16); }
.alert-body { min-width: 0; flex: 1; }
.alert-title { font-size: 13px; font-weight: 550; }
.alert-detail { font-size: 11.5px; color: var(--text-faint);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.alert-count { font-weight: 650; font-variant-numeric: tabular-nums; }
.alert-value { font-size: 11.5px; color: var(--text-faint); min-width: 74px; text-align: right; }

/* ------------------------------------------------------------------ table */
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--panel); }
table.data { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13px; }
table.data th {
  position: sticky; top: 0; z-index: 2; background: var(--bg-raised);
  border-bottom: 1px solid var(--border-strong); padding: 9px 10px; text-align: left;
  font-size: 11.5px; font-weight: 600; color: var(--text-dim); white-space: nowrap;
  text-transform: uppercase; letter-spacing: .04em; cursor: pointer; user-select: none;
}
table.data th.static { cursor: default; }
table.data th .arrow { color: var(--accent); margin-left: 3px; }
table.data td { border-bottom: 1px solid var(--border); padding: 6px 10px; vertical-align: middle;
  max-width: 340px; }
table.data tr:hover td { background: rgba(127, 160, 200, .06); }
table.data tr.selected td { background: var(--accent-dim); }
table.data td.editable { cursor: text; }
table.data td.editable:hover { box-shadow: inset 0 0 0 1px var(--border-strong); }
table.data td.clip { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.data tfoot td { position: sticky; bottom: 0; background: var(--bg-raised);
  border-top: 1px solid var(--border-strong); font-weight: 600; }
.cell-input { padding: 3px 5px; border-radius: 4px; }

.pill {
  display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11.5px;
  font-weight: 550; white-space: nowrap; border: 1px solid transparent;
}
.pill-Despatched, .pill-Dispatched, .pill-Received, .pill-Paid { background: rgba(63,185,80,.14); color: var(--ok);
  border-color: rgba(63,185,80,.3); }
.pill-Pending, .pill-Unpaid, .pill-To-Order, .pill-On-Hold { background: rgba(155,168,184,.13); color: var(--text-dim);
  border-color: var(--border-strong); }
.pill-Ready, .pill-Ready-to-Dispatch, .pill-Stock, .pill-From-Stock, .pill-In-Stock,
.pill-Advance-Received { background: rgba(76,154,255,.14);
  color: var(--accent); border-color: rgba(76,154,255,.3); }
.pill-In-Process, .pill-In-Production, .pill-Partial, .pill-Partially-Paid, .pill-Order,
.pill-PO-Issued, .pill-Stock-Transfer {
  background: rgba(217,164,65,.14); color: var(--warn); border-color: rgba(217,164,65,.3); }
.pill-Customer { background: rgba(63,185,80,.14); color: var(--ok); border-color: rgba(63,185,80,.3); }
.pill-Supplier { background: rgba(76,154,255,.14); color: var(--accent);
  border-color: rgba(76,154,255,.3); }

/* Contacts: a card each, wide enough to read and to tap on a phone. */
.contact-grid { display: grid; gap: var(--gap);
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.contact-card a.btn { min-height: 34px; display: inline-flex; align-items: center; gap: 6px; }
@media (max-width: 860px) { .contact-grid { grid-template-columns: 1fr; } }

.pill-Cancelled, .pill-Written-Off { background: rgba(242,84,91,.13); color: var(--crit);
  border-color: rgba(242,84,91,.3); }
.pill-Partially-Despatched, .pill-Partially-Dispatched { background: rgba(169,139,220,.14); color: var(--info);
  border-color: rgba(169,139,220,.3); }

.flag { color: var(--crit); font-weight: 700; margin-left: 5px; cursor: help; }
.empty-cell { color: var(--text-faint); font-style: italic; }

/* ----------------------------------------------------------------- filters */
.filterbar { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.filter-line { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.search-box { position: relative; flex: 1; min-width: 220px; max-width: 420px; }
.search-box input { padding-left: 32px; }
.search-box .ic { position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  color: var(--text-faint); pointer-events: none; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 7px 3px 10px;
  background: var(--accent-dim); border: 1px solid var(--accent); border-radius: 20px;
  font-size: 12px;
}
.chip b { font-weight: 600; }
.chip button { background: none; border: none; cursor: pointer; color: inherit;
  font-size: 15px; line-height: 1; padding: 0 2px; opacity: .75; }
.chip button:hover { opacity: 1; }
.filter-panel {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 12px; padding: 14px; background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius);
}
.filter-panel label.field { margin: 0; }

/* ------------------------------------------------------------------ charts */
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 10px 16px; margin-top: 10px; font-size: 12px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; color: var(--text-dim); }
.swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.bar-row { display: grid; grid-template-columns: 130px 1fr 92px; gap: 10px;
  align-items: center; margin-bottom: 7px; font-size: 12.5px; }
.bar-track { background: var(--bg-input); border-radius: 4px; height: 17px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 4px; background: var(--accent); }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-dim); }

/* ------------------------------------------------------------------ drawer */
.drawer-backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .55); z-index: 40;
  display: flex; justify-content: flex-end;
}
.drawer {
  width: min(720px, 100%); background: var(--bg-raised); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; box-shadow: var(--shadow);
}
.drawer-head { padding: 14px 18px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px; flex: none; }
.drawer-head h2 { margin: 0; font-size: 15px; }
.drawer-body { padding: 18px; overflow: auto; flex: 1; }
.drawer-foot { padding: 12px 18px; border-top: 1px solid var(--border);
  display: flex; gap: 10px; justify-content: flex-end; flex: none; }
.section-title { font-size: 11px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-faint); margin: 20px 0 10px; border-bottom: 1px solid var(--border);
  padding-bottom: 6px; }
.section-title:first-child { margin-top: 0; }

.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 50;
  display: grid; place-items: center; }
.modal { width: min(560px, 92vw); background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); }
.modal .drawer-body { max-height: 65vh; }

/* ------------------------------------------------------------------ misc */
.bulkbar {
  display: flex; align-items: center; gap: 10px; padding: 9px 14px; margin-bottom: 12px;
  background: var(--accent-dim); border: 1px solid var(--accent); border-radius: var(--radius);
}
.toast-host { position: fixed; right: 18px; bottom: 18px; z-index: 90;
  display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 10px 14px; border-radius: var(--radius-sm); background: var(--bg-raised);
  border: 1px solid var(--border-strong); box-shadow: var(--shadow); font-size: 13px;
  max-width: 400px; animation: rise .16s ease-out;
}
.toast.err { border-color: var(--crit); color: var(--crit); }
.toast.ok { border-color: var(--ok); }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } }

.pager { display: flex; align-items: center; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.empty-state { text-align: center; padding: 56px 20px; color: var(--text-faint); }
.empty-state h3 { color: var(--text-dim); margin: 0 0 6px; }
.spinner { width: 15px; height: 15px; border: 2px solid var(--border-strong);
  border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.dropzone { border: 2px dashed var(--border-strong); border-radius: var(--radius);
  padding: 30px; text-align: center; color: var(--text-dim); cursor: pointer; }
.dropzone.over { border-color: var(--accent); background: var(--accent-dim); }

/* ------------------------------------------------------------------ audit */
.audit-entry {
  display: grid; grid-template-columns: 150px 1fr; gap: 14px;
  padding: 11px 0; border-bottom: 1px solid var(--border);
}
.audit-entry:last-child { border-bottom: none; }
.audit-when { font-size: 12px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.change-row {
  display: grid; grid-template-columns: 170px minmax(0, 1fr) 16px minmax(0, 1fr);
  gap: 8px; align-items: baseline; font-size: 12.5px; padding: 2px 0;
}
.change-field { color: var(--text-dim); }
.change-before { color: var(--text-faint); text-decoration: line-through;
  overflow: hidden; text-overflow: ellipsis; }
.change-arrow { color: var(--text-faint); text-align: center; }
.change-after { color: var(--text); overflow: hidden; text-overflow: ellipsis; }
.pill-audit-ok { background: rgba(12,163,12,.15); color: var(--st-good);
  border: 1px solid rgba(12,163,12,.35); }
.pill-audit-crit { background: rgba(208,59,59,.15); color: var(--st-crit);
  border: 1px solid rgba(208,59,59,.35); }
.pill-audit-warn { background: rgba(250,178,25,.15); color: var(--st-warn);
  border: 1px solid rgba(250,178,25,.35); }
.pill-audit-muted, .pill-audit- { background: rgba(127,160,200,.12); color: var(--text-dim);
  border: 1px solid var(--border-strong); }

/* ==========================================================================
   Tablet and phone.

   The sidebar becomes an off-canvas drawer behind a hamburger, the dense grids
   collapse to one column, and every control grows to a 44px touch target. The
   order-line table keeps its horizontal scroll -- 26 columns genuinely do not
   fit a phone, and shrinking them to fit would make them unreadable; the
   Columns picker is the honest answer there.
   ========================================================================== */

/* The hamburger only exists on small screens. */
.menu-btn { display: none; }
.scrim { display: none; }

@media (max-width: 1024px) {
  .grid-4, .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .audit-entry { grid-template-columns: 120px 1fr; gap: 10px; }
  .change-row { grid-template-columns: 130px minmax(0, 1fr) 14px minmax(0, 1fr); }
}

@media (max-width: 860px) {
  :root { --header-h: 52px; }

  .app { grid-template-columns: 1fr; }

  /* Sidebar slides in over the content rather than squeezing it. */
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: 264px; z-index: 60;
    transform: translateX(-100%); transition: transform .18s ease-out;
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .scrim {
    display: block; position: fixed; inset: 0; z-index: 55;
    background: rgba(0, 0, 0, .5); opacity: 0; pointer-events: none;
    transition: opacity .18s ease-out;
  }
  .scrim.open { opacity: 1; pointer-events: auto; }

  .menu-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 38px; height: 38px; padding: 0; font-size: 18px; flex: none;
  }
  .topbar { padding: 0 12px; gap: 8px; }
  .topbar h1 { font-size: 15px; }
  .content { padding: 12px; }

  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }

  /* Touch targets. 16px inputs also stop iOS zooming the page on focus. */
  .btn { padding: 10px 14px; min-height: 42px; }
  .btn.sm { padding: 7px 10px; min-height: 34px; }
  input, select, textarea { padding: 10px; font-size: 16px; min-height: 42px; }
  .nav a { padding: 12px 12px; font-size: 15px; }

  .kpi .k-value { font-size: 22px; }

  /* Filter and toolbar rows stack instead of overflowing. */
  .filter-line { gap: 8px; }
  .search-box { min-width: 100%; max-width: 100%; }
  /* One filter per row, and the panel scrolls inside itself instead of
     pushing the whole list a screen and a half down. */
  .filter-panel { grid-template-columns: 1fr; max-height: 62vh; overflow-y: auto;
    -webkit-overflow-scrolling: touch; }
  .filter-panel-foot { position: sticky; bottom: -14px; display: flex; gap: 8px;
    padding: 10px 0 2px; background: var(--panel); }
  .filter-panel-foot .btn { flex: 1; }
  .filter-line > label.field { min-width: 100% !important; flex: 1 1 100% !important; }

  /* Drawers and modals use the whole screen on a phone. */
  .drawer { width: 100%; }
  .drawer-backdrop { align-items: stretch; }
  .modal { width: 100%; max-width: 100%; border-radius: 0; height: 100%; }
  .modal-backdrop { place-items: stretch; }
  .modal .drawer-body { max-height: none; flex: 1; }
  .modal > .modal, .modal-backdrop > .modal { display: flex; flex-direction: column; }

  .table-wrap { max-height: none !important; }

  /* Wide tables become stacked cards: no sideways swiping to read a line. */
  .line-cards, .order-cards { display: grid; gap: 10px; }
  /* Four small totals read fine two-up; one per row wastes the screen. */
  .order-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  .order-kpis .k-value { font-size: 18px; }
  .line-card { cursor: pointer; }
  .line-card .pill { font-size: 11px; }
  table.data td { max-width: 240px; }

  /* Report preset tabs scroll sideways rather than wrapping into a wall. */
  .filter-line.tabs { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; }

  .bar-row { grid-template-columns: 100px 1fr 74px; font-size: 12px; }
  .audit-entry { grid-template-columns: 1fr; gap: 4px; }
  .audit-when { display: flex; gap: 10px; }
  .change-row { grid-template-columns: 1fr; gap: 0; padding: 4px 0 6px; }
  .change-row .change-arrow { display: none; }
  .change-before::after { content: ' 92'; text-decoration: none; }

  .toast-host { left: 12px; right: 12px; bottom: 12px; }
  .toast { max-width: 100%; }
  .pager { gap: 8px; }
}

@media (max-width: 460px) {
  .topbar h1 { font-size: 14px; }
  .kpi .k-value { font-size: 20px; }
  .card { padding: 13px; }
  .bar-row { grid-template-columns: 84px 1fr 66px; }
}

/* A finger is not a mouse: no hover-only affordances on touch devices. */
@media (hover: none) {
  table.data td.editable:hover { box-shadow: none; }
  table.data td.editable { -webkit-tap-highlight-color: rgba(76,154,255,.2); }
}

/* Line imported with problems: shown until someone marks it reviewed. */
.flag { color: var(--warn); font-weight: 700; margin-left: 6px; cursor: help; }

/* Dates are typed DD/MM/YYYY; a calendar opens on click. */
.date-field { position: relative; display: flex; align-items: center; }
.date-field input[data-date] { flex: 1; min-width: 0; padding-right: 30px; }
.date-field .date-icon {
  position: absolute; right: 8px; cursor: pointer; font-size: 14px; opacity: .75;
}
input.invalid { border-color: var(--crit) !important; }

/* Floating panels: calendar and searchable name lists. */
.popover {
  position: fixed; z-index: 1000; background: var(--panel); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm, 6px);
  box-shadow: 0 8px 28px rgba(0, 0, 0, .22);
}
.cal { padding: 10px; width: 264px; }
.cal-head { display: flex; align-items: center; gap: 2px; margin-bottom: 8px; }
.cal-head b { flex: 1; text-align: center; font-size: 13.5px; }
.cal-nav {
  border: 0; background: transparent; color: var(--text); cursor: pointer;
  font-size: 17px; width: 28px; height: 28px; border-radius: 6px;
}
.cal-nav:hover, .cal-day:hover { background: var(--bg-raised); }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-wd { text-align: center; font-size: 11px; color: var(--text-faint); padding: 2px 0 4px; }
.cal-day {
  border: 0; background: transparent; color: var(--text); cursor: pointer;
  height: 32px; border-radius: 6px; font-size: 13px;
}
.cal-day.today { outline: 1px solid var(--accent); }
.cal-day.on { background: var(--accent); color: #fff; font-weight: 600; }
.cal-foot { display: flex; justify-content: space-between; margin-top: 8px; }
.combo-list { max-height: 300px; overflow-y: auto; padding: 4px; }
.combo-item { padding: 7px 10px; border-radius: 5px; cursor: pointer; font-size: 13px; }
.combo-item.on, .combo-item:hover { background: var(--bg-raised); }
.combo-item.add {
  border-top: 1px solid var(--border); margin-top: 4px; color: var(--accent); font-weight: 600;
}
.combo-more { padding: 6px 10px; font-size: 12px; color: var(--text-faint); }

/* The typed DELETE confirmation sits above drawers and other dialogs. */
.modal-backdrop.confirm-delete { z-index: 1100; }

/* Order funnel: centred bars, stage label left, value right. */
.funnel-row { display: grid; grid-template-columns: 190px 1fr 130px; gap: 12px;
  align-items: center; padding: 3px 0; }
.funnel-label { font-size: 13px; line-height: 1.3; }
.funnel-label .faint, .funnel-value .faint { font-size: 11.5px; }
.funnel-track { display: flex; justify-content: center; }
.funnel-bar { height: 26px; border-radius: 4px; transition: opacity .15s; }
.funnel-row:hover .funnel-bar { opacity: .85; }
.funnel-value { text-align: right; font-size: 13px; }
.funnel-drop { font-size: 11.5px; text-align: center; padding: 1px 0 1px 202px; }
@media (max-width: 640px) {
  .funnel-row { grid-template-columns: 1fr; gap: 4px; }
  .funnel-value { text-align: left; }
  .funnel-drop { padding-left: 0; text-align: left; }
}

/* Order lines: the grid uses the full height of the page. */
.lines-view { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.lines-view > * { flex: none; }
.lines-view > .lines-grid { flex: 1 1 auto; min-height: 280px; max-height: none; }
.lines-view > .pager { margin-top: 10px; }

/* Order lines: the tick box and Description stay put while the grid scrolls
   sideways. Pinned cells need solid backgrounds, or scrolled cells show through;
   row hover and selection are layered on top of that solid colour. */
.lines-grid .pin-0, .lines-grid .pin-1 { position: sticky; z-index: 1; background: var(--panel); }
.lines-grid .pin-0 { left: 0; width: 40px; min-width: 40px; max-width: 40px;
  box-sizing: border-box; padding-left: 12px; padding-right: 4px; }
.lines-grid .pin-1 { left: 40px; box-shadow: inset -1px 0 0 var(--border-strong); }
.lines-grid thead .pin-0, .lines-grid thead .pin-1,
.lines-grid tfoot .pin-0, .lines-grid tfoot .pin-1 { z-index: 3; background: var(--bg-raised); }
.lines-grid tr:hover td.pin-0, .lines-grid tr:hover td.pin-1 {
  background: linear-gradient(rgba(127, 160, 200, .06), rgba(127, 160, 200, .06)), var(--panel); }
.lines-grid tr.selected td.pin-0, .lines-grid tr.selected td.pin-1 { background: var(--accent-dim); }
@media (max-width: 640px) {
  /* On a phone a pinned description would fill the screen: pin only the tick box. */
  .lines-grid .pin-1 { position: static; box-shadow: none; }
}

/* The line just added: highlighted for a few seconds at the top of the list. */
@keyframes just-added { from { background: var(--accent-dim); } to { background: transparent; } }
.lines-grid tr.just-added td { animation: just-added 3.5s ease-out; }
@keyframes just-added-pin { from { background: var(--accent-dim); } to { background: var(--panel); } }
.lines-grid tr.just-added td.pin-0, .lines-grid tr.just-added td.pin-1 {
  animation: just-added-pin 3.5s ease-out; }

/* A field set aside because the line needs no purchase. */
.muted-field { opacity: .45; }

/* Supplier payment pills share the customer ones; Advance Paid reads like
   Advance Received. */
.pill-Advance-Paid { background: rgba(76,154,255,.14); color: var(--accent);
  border-color: rgba(76,154,255,.3); }
