/* ============================================================
   AssurParts — design system.
   One stylesheet, no build step. Light and dark themes are driven by
   data-theme on <html>; every colour below comes from a token so the two
   themes never drift apart.
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }

:root {
  /* Brand.
     A deliberately desaturated navy-blue, not a stock framework indigo. The
     palette this replaced was Tailwind's defaults — indigo-600, emerald-600,
     red-600 — which is instantly recognisable and reads as a template rather
     than as anyone's company. */
  --brand: #16457e;
  --brand-strong: #0f3460;
  --brand-soft: #eff3f8;
  --brand-ring: rgba(22, 69, 126, .28);

  /* Status colours are muted on purpose. This screen is read all day by people
     reconciling money; saturated greens and reds shout, and everything that
     shouts equally says nothing. */
  --ok: #1a6b3c;
  --ok-soft: #e9f3ec;
  --warn: #8a5514;
  --warn-soft: #fbf2e6;
  --hot: #9a4416;
  --hot-soft: #fbeee6;
  --bad: #99231f;
  --bad-soft: #f9ebea;
  --info: #1f4a7a;
  --info-soft: #edf1f7;

  /* Surfaces: white panels on a neutral paper ground, separated by hairlines
     rather than by shadow. */
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --raised: #ffffff;
  --line: #dfe3e9;
  --line-strong: #c4cad4;
  --text: #14181f;
  --text-2: #46505f;
  --text-3: #6b7686;

  /* The sidebar keeps its own scheme so the shell reads the same way in either
     theme. Flat, not a gradient: application chrome that fades down the page
     is a marketing device, and it dates fast. */
  --side-bg: #16233c;
  --side-text: rgba(255, 255, 255, .74);
  --side-text-strong: #ffffff;
  --side-muted: rgba(255, 255, 255, .44);
  --side-line: rgba(255, 255, 255, .10);
  --side-hover: rgba(255, 255, 255, .06);
  --side-active: rgba(255, 255, 255, .11);
  --side-accent: #8fb2e8;
  --side-bg-end: #16233c;

  /* Hairline elevation. The 56px-blur drop shadow this replaced belongs on a
     landing page, not on a table of invoices. */
  --shadow-sm: 0 1px 1px rgba(20, 24, 31, .04);
  --shadow: 0 1px 3px rgba(20, 24, 31, .07);
  --shadow-lg: 0 8px 24px rgba(20, 24, 31, .14);

  /* Enterprise radii. 12–18px reads as a consumer app; ledgers have corners. */
  --r-sm: 3px;
  --r: 4px;
  --r-lg: 6px;

  --sidebar-w: 236px;
  --sidebar-w-rail: 64px;

  /* System stack. The fonts were fetched from Google's CDN on every page load,
     which many corporate networks block outright — leaving the app in a
     fallback nobody designed — and which sends the user's address to a third
     party on a screen showing client financial data. */
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, 'Cascadia Mono', Consolas, 'Liberation Mono', monospace;
}

html[data-theme='dark'] {
  /* Lifted enough to carry on a dark ground, still short of neon. */
  --brand: #5b8fd4;
  --brand-strong: #7aa5df;
  --brand-soft: #16233a;
  --brand-ring: rgba(91, 143, 212, .35);

  --ok: #5fb583;
  --ok-soft: #11251a;
  --warn: #d3a05a;
  --warn-soft: #261c0f;
  --hot: #d08a5f;
  --hot-soft: #26170f;
  --bad: #d4736d;
  --bad-soft: #271414;
  --info: #6fa3d4;
  --info-soft: #131f2e;

  --bg: #0f1219;
  --surface: #171b24;
  --surface-2: #1c212b;
  --raised: #1c212b;
  --line: #2a303c;
  --line-strong: #3a4250;
  --text: #e8eaee;
  --text-2: #a3abb8;
  --text-3: #757e8c;

  /* Darker than the surfaces so the sidebar still separates from the page
     rather than merging into it. Flat here too. */
  --side-bg: #0c1119;
  --side-text: rgba(255, 255, 255, .70);
  --side-text-strong: #ffffff;
  --side-muted: rgba(255, 255, 255, .40);
  --side-line: rgba(255, 255, 255, .08);
  --side-hover: rgba(255, 255, 255, .05);
  --side-active: rgba(255, 255, 255, .10);
  --side-accent: #7aa5df;
  --side-bg-end: #0c1119;

  --shadow-sm: 0 1px 1px rgba(0, 0, 0, .35);
  --shadow: 0 1px 3px rgba(0, 0, 0, .45);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, .55);
  color-scheme: dark;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
/* Document numbers are identifiers, not prose: a narrow column was breaking
   INV-1001 across two lines. Every .mono use is an atomic token — a document
   number, a part number, a capability, an amount — so none of them should
   ever break. */
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-2); }
.dim { color: var(--text-3); }
.small { font-size: 12px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.strong { font-weight: 650; }
.spacer { flex: 1; }
a { color: var(--brand); }

.i { width: 18px; height: 18px; flex: none; display: block; }

/* ============================================================
   Sign in.
   Split down the middle on a wide screen: the product on the left, the form
   on the right. The left half is the only ornament in the application and it
   is deliberately quiet — line work in the brand navy, not a purple wash,
   film grain or a glint at every corner. It also carries no control, so it
   simply goes away below 1024px rather than stacking above the form and
   pushing it under the fold.
   ============================================================ */

.login-screen {
  position: fixed; inset: 0; overflow-y: auto;
  background: var(--bg);
  display: grid; grid-template-columns: 1fr;
}
.login-main {
  display: grid; place-items: center;
  padding: 32px 24px; min-height: 100%;
}

/* ---- The brand half ---- */
.login-aside { display: none; }

@media (min-width: 1024px) {
  .login-screen { grid-template-columns: 1fr 1fr; }
  .login-aside {
    position: relative; display: flex; flex-direction: column;
    padding: 40px; overflow: hidden;
    background: var(--side-bg); color: var(--side-text-strong);
    border-right: 1px solid var(--line);
  }
}
/* ---- The mark ---------------------------------------------------------------
   The supplied logo, at 1.342:1. Height is what is set and width follows, so
   the sizes below stay comparable with the type beside them; giving both would
   squash it. It carries its own colour, so none of the --logo-ink inversion the
   drawn mark needed applies — the white ground is knocked out of the PNG
   instead, which is what lets it sit on the navy chrome. */
.logo-mark { display: block; flex: none; width: auto; }
.logo-mark-lg     { height: 27px; }
.logo-mark-side   { height: 25px; }
.logo-mark-card   { height: 32px; }
/* 22px tall is ~30px wide, which is the footprint the square mark had. Any
   larger and the name beside it truncates — the chip is the one place the mark
   competes with text for a fixed width. */
.logo-mark-avatar { height: 22px; }

/* The lockup sits on the optical centre of the wordmark, not on its box: the
   mark is a solid shape and the text has ascenders, so aligning the two boxes
   leaves the mark looking low. */
.login-aside-head {
  position: relative; z-index: 2;
  display: flex; align-items: center; gap: 9px;
}
.login-wordmark { font-size: 19px; font-weight: 650; letter-spacing: -.2px; line-height: 1; }
.login-aside-foot { position: relative; z-index: 2; margin-top: auto; max-width: 27em; }
.login-pitch { font-size: 19px; line-height: 1.5; color: rgba(255, 255, 255, .92); }
.login-pitch-sub {
  margin-top: 12px; font-family: var(--mono); font-size: 12.5px;
  color: var(--side-muted); letter-spacing: .02em;
}
/* A wash from the panel colour upward, so the line work fades out behind the
   text instead of running through it. */
.login-aside::after {
  content: ''; position: absolute; inset: 0; z-index: 1; pointer-events: none;
  background:
    linear-gradient(to top, var(--side-bg) 4%, transparent 62%),
    linear-gradient(to bottom, var(--side-bg) 2%, transparent 26%);
}

/* Held well back: this is the texture behind a sign-in form, not the subject
   of the screen. At full strength the dense corner competed with the wordmark
   sitting on top of it. */
.login-paths {
  position: absolute; inset: 0; z-index: 0; pointer-events: none;
  color: #fff; opacity: .55;
}
.login-paths svg { width: 100%; height: 100%; display: block; }
/* The travel is one dash sliding along each curve. stroke-dashoffset is
   compositor-friendly, so 72 curves cost nothing and need no frame loop. */
.login-paths path {
  /* One long segment and a long gap, so each curve reads as a strand with a
     travelling highlight. Shorter dashes tile into a dotted texture that draws
     more attention than the panel behind a sign-in form should. */
  stroke-dasharray: 520 1100;
  animation-name: lg-flow;
  animation-timing-function: linear;
  animation-iteration-count: infinite;
}
.login-paths svg.is-still path { animation: none; stroke-dasharray: none; }
@keyframes lg-flow { to { stroke-dashoffset: -1620; } }
@media (prefers-reduced-motion: reduce) {
  .login-paths path { animation: none; stroke-dasharray: none; }
}

/* ---- The form half ---- */
.login-card {
  width: 100%; max-width: 384px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 28px 28px 24px;
  box-shadow: var(--shadow);
}
/* On a wide screen the panel beside it already says whose product this is, so
   the card needs no border of its own competing with it. */
@media (min-width: 1024px) {
  .login-card { border-color: transparent; background: transparent; box-shadow: none; padding: 0; }
  .login-card .logo-mark-card { display: none; }
}

.login-head { margin-bottom: 26px; }
.login-head .logo-mark-card { margin-bottom: 16px; }
.login-head h1 { font-size: 23px; font-weight: 680; letter-spacing: -.4px; color: var(--text); }
.login-head p { margin-top: 5px; font-size: 13.5px; color: var(--text-2); }

/* ---- Fields ------------------------------------------------------------------
   The one screen every user meets before they trust anything else here, so the
   fields get height, a mark of what they hold, and a focus state that moves.
   Everything is still on the system's own terms: the same navy, the same 6px
   corner, no gradient and no glow. --lg-field-h keeps the input, its icon, the
   reveal button and the submit all on one measurement. */
.lg-field { --lg-field-h: 46px; margin-bottom: 15px; }
/* The box the overlays measure themselves against. It holds the input and
   nothing else that changes height, so a hint appearing underneath cannot drag
   the icon and the reveal button down with it. */
.lg-control { position: relative; display: block; }
.lg-field label {
  display: block; font-size: 12px; font-weight: 650;
  letter-spacing: .01em; color: var(--text-2); margin-bottom: 6px;
}

/* The icon marks what the field holds, and follows the field's state: grey at
   rest, brand once you are typing in it. */
.lg-lead {
  position: absolute; left: 0; top: 0; bottom: 0;
  width: 42px;
  display: grid; place-items: center; pointer-events: none;
  color: var(--text-3); transition: color .15s ease;
}
.lg-lead .i { width: 17px; height: 17px; }
.lg-field:focus-within .lg-lead { color: var(--brand); }

.lg-field input {
  width: 100%; height: var(--lg-field-h);
  padding: 0 14px 0 42px; font: inherit; font-size: 14.5px;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--line-strong); border-radius: var(--r-lg);
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
#loginPassword { padding-right: 46px; }
.lg-field input::placeholder { color: var(--text-3); }
.lg-field input:hover:not(:focus) { border-color: var(--text-3); }

/* A ring rather than the 2px outline that was here: the outline sat hard on the
   border and jumped the eye. This grows out of the field instead, and it is a
   visible focus indicator in its own right, so nothing is lost by taking the
   outline off. */
.lg-field input:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-ring);
}

/* Chrome paints its own flat yellow over autofilled inputs, which undoes the
   whole field. The inset shadow is the only way to repaint the background, and
   the long transition keeps Chrome from flashing its colour back in. */
.lg-field input:-webkit-autofill,
.lg-field input:-webkit-autofill:hover,
.lg-field input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--text);
  -webkit-box-shadow: 0 0 0 40px var(--surface) inset;
  transition: background-color 9999s ease-in-out 0s;
}

/* A rejected sign-in marks the fields as well as printing the message. One
   sentence under a form is easy to miss; a red edge on the thing you have to
   change is not. Cleared on the next keystroke rather than on the next attempt,
   so the warning goes away as soon as you act on it. */
.lg-field input[aria-invalid='true'] {
  border-color: var(--bad);
}
.lg-field input[aria-invalid='true']:focus {
  border-color: var(--bad);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--bad) 22%, transparent);
}
/* The icon sits before the input in the DOM, so a sibling combinator cannot
   reach it — the field itself carries the state instead. */
.lg-field:has(input[aria-invalid='true']) .lg-lead { color: var(--bad); }
.lg-caps + * { margin-top: 0; }

.lg-caps {
  display: flex; align-items: center; gap: 6px;
  margin-top: 7px; font-size: 12px; font-weight: 600; color: var(--warn);
}
/* `display: flex` on the class outranks the browser's own [hidden] rule, so
   without this the warning is on the screen permanently — which is worse than
   not having it, because it is then telling everyone their Caps Lock is on. */
.lg-caps[hidden] { display: none; }
.lg-caps .i { width: 14px; height: 14px; }

/* Centred on the input by its own box, so neither the label above nor a hint
   below can move it. */
.lg-peek {
  position: absolute; right: 5px; top: 50%; transform: translateY(-50%);
  height: calc(var(--lg-field-h) - 10px); width: 36px;
  display: grid; place-items: center; background: none; border: 0;
  color: var(--text-3); cursor: pointer; border-radius: var(--r);
  transition: color .15s ease, background .15s ease;
}
.lg-peek:hover { color: var(--text); background: var(--surface-2); }
.lg-peek:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }

.lg-submit {
  width: 100%; height: 46px; margin-top: 8px; padding: 0 16px;
  display: inline-flex; align-items: center; justify-content: center;
  font: inherit; font-size: 14.5px; font-weight: 650; letter-spacing: .01em;
  color: #fff; background: var(--brand); border: 0;
  border-radius: var(--r-lg); cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: background .15s ease, box-shadow .15s ease, transform .08s ease;
}
.lg-submit:active:not(:disabled) { transform: translateY(1px); }
.lg-submit:hover:not(:disabled) { background: var(--brand-strong); }
.lg-submit:disabled { opacity: .55; cursor: not-allowed; }
.lg-submit:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* Two things land here: a failed sign-in, and a plain statement of fact like
   "You have signed out." The second was wearing the first's red border and
   pink fill, which told the user something had gone wrong when nothing had. */
.login-error {
  margin-top: 14px; padding: 9px 11px; font-size: 13px;
  color: var(--bad); background: var(--bad-soft);
  border: 1px solid var(--bad); border-radius: var(--r-sm);
}
.login-error:empty { display: none; }
.login-error.is-note {
  color: var(--text-2); background: var(--surface-2); border-color: var(--line);
}

.lg-foot { margin-top: 16px; text-align: center; font-size: 12px; color: var(--text-3); }


/* ============ Shell ============ */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w); flex: none;
  background: var(--side-bg);
  color: var(--side-text);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
  transition: width .18s ease;
}

.brand { display: flex; align-items: center; gap: 11px; padding: clamp(13px, 2vh, 18px) 14px clamp(11px, 1.7vh, 15px); border-bottom: 1px solid var(--side-line); }
/* Nothing in the sidebar may wrap: while the rail animates the box is briefly
   narrow, and wrapping text would reflow into a mess for those 180ms. */
.sidebar, .brand { overflow-x: hidden; }
/* Initials stood here because the icon before them was a gear, which said
   "settings" on a screen that is about money. The mark that replaced them is
   the product's own, so it says AssurParts and nothing else. */

.brand-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.brand-text strong, .brand-text span { white-space: nowrap; }
.brand-text strong { font-size: 14px; font-weight: 650; letter-spacing: -.1px; color: var(--side-text-strong); }
.brand-text span { font-size: 11px; color: var(--side-muted); }

/* Collapse control. Sits with the brand, and stays reachable in rail mode. */
.rail-btn {
  margin-left: auto; width: 28px; height: 28px; flex: none;
  display: grid; place-items: center; cursor: pointer;
  background: transparent; border: 1px solid transparent; border-radius: var(--r);
  color: var(--side-muted); transition: color .15s, background .15s, border-color .15s;
}
.rail-btn:hover { color: var(--side-text-strong); background: var(--side-hover); border-color: var(--side-line); }
.rail-btn .i { width: 16px; height: 16px; transition: transform .2s ease; }

.nav {
  flex: 1; overflow-y: auto; overflow-x: hidden; padding: clamp(6px, 1vh, 10px) 10px 10px;
  /* No visible scrollbar: a grey track down the navy edge looks like a seam,
     and this list is only a screenful. Scrolling itself is kept, so every item
     is still reachable on a short window — hiding the bar must not strand the
     last menu item. */
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.nav::-webkit-scrollbar { width: 0; height: 0; }
.nav-group {
  font-size: 9.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .1em;
  color: var(--side-muted); padding: clamp(6px, 1.5vh, 14px) 10px clamp(1px, .5vh, 5px); white-space: nowrap;
}
.nav-item {
  position: relative;
  width: 100%; display: flex; align-items: center; gap: 11px;
  padding: clamp(5px, .95vh, 9px) 11px; border: 0; border-radius: var(--r); cursor: pointer;
  font: inherit; font-size: 13.5px; font-weight: 550; text-align: left; white-space: nowrap;
  color: var(--side-text); background: transparent; transition: background .14s, color .14s;
}
.nav-item:hover { background: var(--side-hover); color: var(--side-text-strong); }
.nav-item.active { background: var(--side-active); color: var(--side-text-strong); font-weight: 650; }
/* A bar on the active row, so the current page is obvious at a glance and
   still readable when the labels are hidden. */
.nav-item.active::before {
  content: ''; position: absolute; left: -10px; top: 5px; bottom: 5px;
  width: 3px; border-radius: 0 3px 3px 0; background: var(--side-accent);
}
.nav-item .i { width: 17px; height: 17px; flex: none; }
.nav-count {
  margin-left: auto; font-size: 11px; font-weight: 700; padding: 1px 7px;
  border-radius: var(--r-lg); background: rgba(255, 255, 255, .13); color: var(--side-text-strong);
}
.nav-count.hot { background: var(--bad); color: #fff; }

.sidebar-foot { border-top: 1px solid var(--side-line); padding: 8px 10px; display: flex; align-items: center; gap: 6px; }
.who {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px;
  background: transparent; border: 0; border-radius: var(--r-lg); padding: 6px; cursor: pointer; font: inherit; text-align: left;
  color: inherit;
}
.who:hover { background: var(--side-hover); }
.who-text { display: flex; flex-direction: column; min-width: 0; }
.who-text strong { font-size: 12.5px; font-weight: 650; color: var(--side-text-strong); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who-text span { font-size: 11px; color: var(--side-muted); text-transform: capitalize; }
/* Squared initials, flat. The violet gradient here was the last decorative
   flourish in the shell, and it did not match anything else on the screen. */
.sidebar-actions { display: flex; gap: 4px; }

.icon-btn {
  width: 32px; height: 32px; border-radius: var(--r); border: 1px solid transparent;
  background: transparent; color: var(--text-2); cursor: pointer;
  display: grid; place-items: center;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--line); }
/* Inside the coloured sidebar these have to invert. */
.sidebar .icon-btn { color: var(--side-muted); }
.sidebar .icon-btn:hover { background: var(--side-hover); color: var(--side-text-strong); border-color: var(--side-line); }

/* ---- Rail mode: icons only ----------------------------------------------
   Labels are hidden rather than removed, so the title attribute still names
   each item on hover and screen readers keep the accessible name. */
.shell.rail .sidebar { width: var(--sidebar-w-rail); }
.shell.rail .brand { justify-content: center; padding: 16px 8px 14px; gap: 0; }
.shell.rail .brand-text { display: none; }
.shell.rail .rail-btn { position: absolute; top: 62px; right: -13px; z-index: 5;
  background: var(--surface); border-color: var(--line); color: var(--text-2); box-shadow: var(--shadow-sm); }
.shell.rail .rail-btn:hover { color: var(--brand); border-color: var(--brand); background: var(--surface); }
.shell.rail .rail-btn .i { transform: rotate(180deg); }
.shell.rail .nav { padding: 8px 8px 16px; }
.shell.rail .nav-item { justify-content: center; padding: 10px; gap: 0; }
.shell.rail .nav-item > span:not(.nav-count) { display: none; }
.shell.rail .nav-item.active::before { left: -8px; }
.shell.rail .nav-count {
  position: absolute; top: 3px; right: 4px; margin: 0;
  min-width: 16px; padding: 0 4px; font-size: 9.5px; line-height: 16px; text-align: center;
}
/* The group label becomes a rule — the grouping survives, the words do not. */
.shell.rail .nav-group { font-size: 0; padding: 10px 12px 6px; }
.shell.rail .nav-group::after { content: ''; display: block; height: 1px; background: var(--side-line); }
.shell.rail .sidebar-foot { flex-direction: column; padding: 10px 8px; gap: 8px; }
.shell.rail .who { justify-content: center; padding: 4px; flex: none; }
.shell.rail .who-text { display: none; }


.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 14px;
  padding: 15px 26px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.topbar-title { min-width: 0; }
.topbar-title h1 { font-size: 19px; font-weight: 720; letter-spacing: -.3px; }
.topbar-title p { font-size: 12.5px; color: var(--text-2); }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.menu-btn { display: none; }

.view { padding: 22px 26px 56px; }

/* ============ Buttons ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 8px 14px; border-radius: var(--r-lg); border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--text);
  font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  transition: background .14s, border-color .14s, transform .1s, box-shadow .14s;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--surface-2); border-color: var(--text-3); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn .i { width: 16px; height: 16px; }

.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--brand-strong); border-color: var(--brand-strong); }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-ok:hover:not(:disabled) { filter: brightness(.94); background: var(--ok); }
.btn-bad { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn-bad:hover:not(:disabled) { filter: brightness(.94); background: var(--bad); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); border-color: var(--line); }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: var(--r); }
.btn-block { width: 100%; padding: 11px; font-size: 14px; margin-top: 6px; }

/* ============ Cards, panels, grids ============ */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; margin-bottom: 20px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  padding: 15px 17px; box-shadow: var(--shadow-sm);
}
.card-label { display: flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 600; color: var(--text-2); }
.card-label .i { width: 15px; height: 15px; }
.card-value { font-size: 25px; font-weight: 730; letter-spacing: -.6px; margin: 7px 0 2px; }
.card-value.sm { font-size: 20px; }
.card-foot { font-size: 11.5px; color: var(--text-3); }
.card-foot.up { color: var(--ok); }
.card-foot.down { color: var(--bad); }
.card.accent-brand { border-left: 3px solid var(--brand); }
.card.accent-ok { border-left: 3px solid var(--ok); }
.card.accent-bad { border-left: 3px solid var(--bad); }
.card.accent-warn { border-left: 3px solid var(--warn); }

.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  box-shadow: var(--shadow-sm); margin-bottom: 18px; overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 13px 17px; border-bottom: 1px solid var(--line);
}
.panel-head h2, .panel-head h3 { font-size: 14px; font-weight: 680; letter-spacing: -.1px; }
.panel-head p { font-size: 12px; color: var(--text-2); }
.panel-head .head-actions { margin-left: auto; display: flex; gap: 7px; flex-wrap: wrap; }
.panel-body { padding: 17px; }
.panel-body.tight { padding: 0; }

.grid-2 { display: grid; grid-template-columns: 1.35fr 1fr; gap: 18px; align-items: start; }
/* A column of panels inside a grid cell. Stacking each side independently
   avoids the hole a short panel leaves next to a tall one. */
.stack { display: flex; flex-direction: column; gap: 18px; }
.stack > .panel { margin-bottom: 0; }
.grid-halves { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }

/* ============ Toolbar ============ */
.toolbar { display: flex; gap: 9px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.toolbar input[type='text'], .toolbar input[type='date'], .toolbar select {
  padding: 8px 11px; border: 1px solid var(--line-strong); border-radius: var(--r);
  background: var(--surface); color: var(--text); font: inherit; font-size: 13px;
}
.toolbar input:focus, .toolbar select:focus { outline: 2px solid var(--brand-ring); outline-offset: -1px; border-color: var(--brand); }
.search { position: relative; }
.search .i { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-3); width: 16px; height: 16px; }
.search input { padding-left: 32px !important; min-width: 240px; }

.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r); padding: 2px; }
.seg button {
  border: 0; background: transparent; color: var(--text-2); font: inherit; font-size: 12.5px; font-weight: 600;
  padding: 5px 11px; border-radius: var(--r); cursor: pointer;
}
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* ============ Tables ============ */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left; font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-3); padding: 10px 14px; background: var(--surface-2);
  border-bottom: 1px solid var(--line); white-space: nowrap; position: sticky; top: 0;
}
tbody td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface-2); }
td.actions { text-align: right; white-space: nowrap; }
td.actions > * + * { margin-left: 5px; }
th.center, td.center { text-align: center; }

/* Yes/no marks in a matrix column. The icon is display:block, so on its own it
   ignores text-align and drifts left of the dash in the next row — inline-flex
   puts a tick and a dash in exactly the same place. */
.mark { display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; vertical-align: middle; }
.mark .i { width: 17px; height: 17px; }
.mark.yes { color: var(--ok); }
.mark.no { color: var(--text-3); }

.empty { padding: 44px 20px; text-align: center; color: var(--text-3); }
.empty .i { width: 26px; height: 26px; margin: 0 auto 10px; color: var(--line-strong); }
.row-sub { font-size: 11.5px; color: var(--text-3); }
.total-row td { background: var(--surface-2); font-weight: 700; border-top: 2px solid var(--line-strong); }

/* A row that needs attention — a delivery past its needed-by date, say. Marked
   on the edge rather than by tinting the whole row, which fights the badges. */
tr.row-flag > td:first-child { box-shadow: inset 2px 0 0 var(--bad); }

/* ============ Badges ============ */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2.5px 9px; border-radius: var(--r-lg); font-size: 11.5px; font-weight: 650; white-space: nowrap;
  border: 1px solid transparent;
}
.badge-neutral { background: var(--surface-2); color: var(--text-2); border-color: var(--line); }
.badge-brand { background: var(--brand-soft); color: var(--brand); border-color: color-mix(in srgb, var(--brand) 26%, transparent); }
.badge-ok { background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 26%, transparent); }
.badge-warn { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.badge-hot { background: var(--hot-soft); color: var(--hot); border-color: color-mix(in srgb, var(--hot) 30%, transparent); }
.badge-bad { background: var(--bad-soft); color: var(--bad); border-color: color-mix(in srgb, var(--bad) 26%, transparent); }
.badge-info { background: var(--info-soft); color: var(--info); border-color: color-mix(in srgb, var(--info) 26%, transparent); }
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px;
  border-radius: var(--r-lg); border: 1px dashed var(--line-strong); background: var(--surface-2);
  font-size: 12px; color: var(--text-2);
}

/* ============ Lifecycle stepper ============ */
.steps { display: flex; align-items: flex-start; gap: 0; overflow-x: auto; padding: 4px 0 2px; }
.step { flex: 1; min-width: 92px; position: relative; text-align: center; }
.step::before {
  content: ''; position: absolute; top: 12px; left: 0; right: 50%; height: 2px; background: var(--line);
}
.step::after {
  content: ''; position: absolute; top: 12px; left: 50%; right: 0; height: 2px; background: var(--line);
}
.step:first-child::before, .step:last-child::after { display: none; }
.step .bullet {
  position: relative; z-index: 1; width: 26px; height: 26px; margin: 0 auto 7px;
  border-radius: 50%; background: var(--surface); border: 2px solid var(--line);
  display: grid; place-items: center; color: var(--text-3); font-size: 11px; font-weight: 700;
}
.step .bullet .i { width: 14px; height: 14px; }
.step .step-name { font-size: 11.5px; font-weight: 600; color: var(--text-3); }
.step .step-when { font-size: 10.5px; color: var(--text-3); }
.step.done .bullet { background: var(--ok); border-color: var(--ok); color: #fff; }
.step.done::before, .step.done::after { background: var(--ok); }
.step.now .bullet { background: var(--brand); border-color: var(--brand); color: #fff; box-shadow: 0 0 0 4px var(--brand-ring); }
.step.now::before { background: var(--ok); }
.step.now .step-name { color: var(--text); font-weight: 700; }
.step.done .step-name { color: var(--text-2); }
.step.void .bullet { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
.step.void .step-name { color: var(--bad); }

/* ============ Key-date chain (purchase → bill → payment) ============ */
.chain { display: flex; align-items: stretch; gap: 8px; flex-wrap: wrap; }
.chain-item {
  flex: 1; min-width: 148px; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--r-sm); padding: 10px 12px;
}
.chain-item .k { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); }
.chain-item .v { font-size: 14px; font-weight: 650; margin-top: 3px; }
.chain-item .n { font-size: 11px; color: var(--text-3); }
.chain-item.pending { border-style: dashed; }
.chain-item.pending .v { color: var(--text-3); font-weight: 550; }
.chain-gap { display: grid; place-items: center; font-size: 11px; color: var(--text-3); padding: 0 2px; }

/* ============ Aging bar ============ */
.aging-bar { display: flex; height: 13px; border-radius: var(--r-lg); overflow: hidden; background: var(--surface-2); border: 1px solid var(--line); }
.aging-bar span { display: block; height: 100%; transition: width .3s; }
.aging-seg-current { background: #94a3b8; }
.aging-seg-d0_30 { background: var(--ok); }
.aging-seg-d31_60 { background: #eab308; }
.aging-seg-d61_90 { background: var(--hot); }
.aging-seg-d90_plus { background: var(--bad); }
.aging-legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 12px; }
.aging-legend-item { display: flex; align-items: center; gap: 7px; font-size: 12px; }
.aging-legend-item .sw { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.aging-legend-item b { font-variant-numeric: tabular-nums; }

.bucket-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(146px, 1fr)); gap: 12px; }
.bucket-card { border: 1px solid var(--line); border-radius: var(--r); padding: 13px 15px; background: var(--surface); border-top: 3px solid var(--line); }
.bucket-card .b-label { font-size: 11.5px; font-weight: 650; color: var(--text-2); }
.bucket-card .b-value { font-size: 19px; font-weight: 720; margin: 5px 0 1px; letter-spacing: -.3px; }
.bucket-card .b-foot { font-size: 11px; color: var(--text-3); }
.bucket-card[data-b='current'] { border-top-color: #94a3b8; }
.bucket-card[data-b='d0_30'] { border-top-color: var(--ok); }
.bucket-card[data-b='d31_60'] { border-top-color: #eab308; }
.bucket-card[data-b='d61_90'] { border-top-color: var(--hot); }
.bucket-card[data-b='d90_plus'] { border-top-color: var(--bad); }
.bucket-card[data-b='d90_plus'] .b-value { color: var(--bad); }

/* ============ Detail layout ============ */
.detail-head { display: flex; align-items: flex-start; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.detail-head .title-block h2 { font-size: 21px; font-weight: 730; letter-spacing: -.4px; display: flex; align-items: center; gap: 10px; }
.detail-head .title-block p { font-size: 13px; color: var(--text-2); margin-top: 2px; }
.detail-head .head-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px 22px; }
.kv .k { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); }
.kv .v { font-size: 13.5px; font-weight: 550; margin-top: 2px; word-break: break-word; }

.feed { list-style: none; }
.feed li { display: flex; gap: 11px; padding: 9px 0; border-bottom: 1px dashed var(--line); font-size: 13px; }
.feed li:last-child { border-bottom: 0; }
.feed .fdot { width: 7px; height: 7px; border-radius: 50%; background: var(--brand); margin-top: 6px; flex: none; }
.feed .fwhen { font-size: 11px; color: var(--text-3); }

/* ============ Forms ============ */
.field { display: block; margin-bottom: 13px; }
.field > span, .field-label { display: block; font-size: 12px; font-weight: 650; color: var(--text-2); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 9px 12px; border: 1px solid var(--line-strong); border-radius: var(--r);
  background: var(--surface-2); color: var(--text); font: inherit; font-size: 13.5px;
}
.field textarea { resize: vertical; min-height: 66px; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid var(--brand-ring); outline-offset: -1px; border-color: var(--brand); background: var(--surface);
}
.field input[readonly] { background: var(--brand-soft); color: var(--brand); font-weight: 650; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.field-hint { font-size: 11.5px; color: var(--text-3); margin-top: 4px; }
.form-section { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-3); margin: 20px 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.form-error {
  display: none; margin: 4px 0 12px; font-size: 12.5px; padding: 8px 11px; border-radius: var(--r-sm);
  background: var(--bad-soft); color: var(--bad); border: 1px solid color-mix(in srgb, var(--bad) 26%, transparent);
}
.form-error.show { display: block; }
.checkline { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 550; cursor: pointer; }
.checkline input { width: auto; }

/* Editable part-line rows */
.lines { border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.line-row {
  display: grid; grid-template-columns: 1.5fr 1fr .55fr .55fr .7fr 30px;
  gap: 8px; padding: 9px 10px; align-items: center; border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.line-row:last-child { border-bottom: 0; }
.line-row.head {
  background: var(--surface-2); font-size: 10.5px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: var(--text-3);
}
.line-row input, .line-row select {
  width: 100%; padding: 7px 9px; border: 1px solid var(--line-strong); border-radius: var(--r);
  background: var(--surface-2); color: var(--text); font: inherit; font-size: 12.5px;
}
.line-row input:focus { outline: 2px solid var(--brand-ring); outline-offset: -1px; }
.line-row .line-total { font-family: var(--mono); font-size: 12.5px; text-align: right; font-weight: 600; }
.line-del { border: 0; background: transparent; color: var(--text-3); cursor: pointer; border-radius: 6px; padding: 4px; }
.line-del:hover { background: var(--bad-soft); color: var(--bad); }
.lines-foot { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.lines-total { margin-left: auto; font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ============ Modal ============ */
.overlay {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px;
  background: rgba(9, 11, 22, .55); backdrop-filter: blur(3px);
}
.modal {
  width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg); animation: pop .16s ease-out;
}
.modal.wide { max-width: 800px; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.99); } }
.modal-head { display: flex; align-items: flex-start; gap: 12px; padding: 18px 20px 12px; }
.modal-head h3 { font-size: 16px; font-weight: 700; letter-spacing: -.2px; }
.modal-head p { font-size: 12.5px; color: var(--text-2); margin-top: 3px; }
.modal-body { padding: 4px 20px 8px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px 18px; }
.modal-foot .left { margin-right: auto; }

.note {
  display: flex; gap: 9px; padding: 11px 13px; border-radius: var(--r-sm); font-size: 12.5px;
  background: var(--info-soft); color: var(--info); border: 1px solid color-mix(in srgb, var(--info) 22%, transparent);
  margin-bottom: 14px;
}
.note .i { width: 16px; height: 16px; margin-top: 1px; }
.note.warn { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 26%, transparent); }
.note.bad { background: var(--bad-soft); color: var(--bad); border-color: color-mix(in srgb, var(--bad) 22%, transparent); }
.note.ok { background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 22%, transparent); }

/* ============ Toasts ============ */
.toasts { position: fixed; top: 16px; right: 16px; z-index: 200; display: flex; flex-direction: column; gap: 9px; }
.toast {
  display: flex; align-items: center; gap: 9px; min-width: 230px; max-width: 380px;
  padding: 11px 14px; border-radius: var(--r); font-size: 13px; font-weight: 550;
  background: var(--raised); color: var(--text); border: 1px solid var(--line);
  box-shadow: var(--shadow-lg); animation: slide .18s ease-out;
}
@keyframes slide { from { opacity: 0; transform: translateX(16px); } }
.toast.ok { border-left: 3px solid var(--ok); }
.toast.bad { border-left: 3px solid var(--bad); }
.toast.info { border-left: 3px solid var(--brand); }
.toast .i { flex: none; }
.toast.ok .i { color: var(--ok); }
.toast.bad .i { color: var(--bad); }
.toast.info .i { color: var(--brand); }

/* ============ Loading ============ */
.loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 56px; color: var(--text-3); font-size: 13px; }
.spin {
  width: 17px; height: 17px; border-radius: 50%; flex: none;
  border: 2px solid var(--line-strong); border-top-color: var(--brand); animation: rot .7s linear infinite;
}
.btn .spin { width: 14px; height: 14px; border-top-color: currentColor; border-color: rgba(255,255,255,.35); }
@keyframes rot { to { transform: rotate(360deg); } }

/* ---- Centre-screen activity ----------------------------------------------
   Shown for the actions that replace the whole screen — signing in, signing
   out — where the button that started it is about to disappear and an inline
   spinner would vanish with it.

   pointer-events stay off: this reports progress, it does not trap the pointer.
   The timing lives in showBusy(); the two rules that matter are that it waits
   before appearing, so a fast action never flashes, and once shown it stays
   long enough to be read rather than strobing. */
.busy {
  position: fixed; inset: 0; z-index: 90;
  display: grid; place-items: center;
  pointer-events: none; opacity: 0;
  /* Just enough to push the page back a step. At 55% the whole screen went
     grey, which reads as a fault rather than as a pause. */
  background: color-mix(in srgb, var(--bg) 30%, transparent);
  transition: opacity .16s ease;
}
.busy.show { opacity: 1; }
.busy-card {
  display: flex; align-items: center; gap: 11px;
  padding: 13px 18px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  font-size: 13px; font-weight: 600;
  animation: busy-in .18s ease both;
}
@keyframes busy-in { from { opacity: 0; transform: translateY(6px) scale(.98); } }
@media (prefers-reduced-motion: reduce) {
  .busy { transition: none; }
  .busy-card { animation: none; }
}

/* The login button's spinner. It was emitting a `lg-spin` element that no rule
   ever matched, so every sign-in showed the text changing and nothing turning. */
.lg-submit .spin {
  width: 14px; height: 14px;
  border-color: rgba(255, 255, 255, .35); border-top-color: #fff;
}

.progress { height: 6px; border-radius: var(--r-lg); background: var(--line); overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--ok); border-radius: var(--r-lg); }

/* ============ Responsive ============ */
/* Width is given up in a deliberate order: two-column panels fold first, then
   the sidebar collapses to a drawer, then the topbar stops trying to fit a
   title and its buttons on one line. Table columns are last, because a column
   that goes away takes information with it — everything above it is only
   layout. */

/* ---- Laptop: panels side by side stop earning their keep ----------------- */
@media (max-width: 1080px) {
  .grid-2, .grid-halves { grid-template-columns: 1fr; }
}

/* ---- Narrow laptop / tablet: the search box was hogging the toolbar ------ */
@media (max-width: 1000px) {
  .field-row-3 { grid-template-columns: 1fr 1fr; }
  .search input { min-width: 180px !important; }
}

/* ---- Tablet: four figures read better as a square than as 3 + 1 ----------
   auto-fit does the arithmetic and lands on three across with the fourth
   stranded on its own row beside two empty cells. Two-up keeps the block
   rectangular, which is what makes a row of figures scannable. */
@media (max-width: 900px) {
  .cards { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 560px) {
  .cards { grid-template-columns: 1fr; }
}

/* ---- Phone and small tablet ---------------------------------------------- */
@media (max-width: 860px) {
  .sidebar {
    position: fixed; z-index: 60; left: 0; top: 0; transform: translateX(-100%);
    transition: transform .2s; box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: none; }
  .menu-btn { display: grid; }
  .view { padding: 16px 14px 48px; }
  .field-row, .field-row-3 { grid-template-columns: 1fr; }
  .line-row { grid-template-columns: 1fr 1fr; }
  .line-row.head { display: none; }

  /* The title and its actions were competing for one line: at 375px the
     subtitle came out five words wide beside two export buttons. Let the bar
     wrap, and give the buttons their own row where they can be full size. */
  .topbar { padding: 12px 14px; flex-wrap: wrap; row-gap: 10px; }
  .topbar-title { flex: 1 1 auto; }
  .topbar-actions { flex: 1 1 100%; margin-left: 0; }
  .topbar-actions > .btn { flex: 1 1 auto; }

  /* The toolbar's search should own its row rather than squeeze beside a
     filter and a date. */
  .toolbar .search { flex: 1 1 100%; }
  .toolbar .search input { min-width: 0 !important; width: 100%; }

  /* A table scrolled sideways must keep saying which row you are reading. The
     first column holds the identity — a customer, an invoice number, a part —
     so it stays put while the figures move under it. Only wrapped tables get
     this: `.table-wrap` is what scrolls, and the printed invoice must not. */
  .table-wrap thead th { z-index: 2; }
  .table-wrap thead th:first-child,
  .table-wrap tbody td:first-child {
    position: sticky; left: 0;
  }
  .table-wrap thead th:first-child { z-index: 3; background: var(--surface-2); }
  .table-wrap tbody td:first-child { z-index: 1; background: var(--surface); }
  .table-wrap tbody tr.clickable:hover td:first-child { background: var(--surface-2); }
  .table-wrap .total-row td:first-child { background: var(--surface-2); }
  /* The hairline is the only hint that there is more to the right. */
  .table-wrap thead th:first-child::after,
  .table-wrap tbody td:first-child::after {
    content: ''; position: absolute; top: 0; right: 0; bottom: 0; width: 1px;
    background: var(--line);
  }
  /* Left to itself the table obeys width:100%, squeezes to the viewport and
     breaks "Desert Rock Quarry" over three lines — a row three times taller
     carrying the same information. Letting the identity column set its own
     width pushes the table wider than the frame instead, which is what the
     horizontal scroll is there for. */
  .table-wrap thead th:first-child,
  .table-wrap tbody td:first-child { white-space: nowrap; }
}

/* ---- Touch, at any width -------------------------------------------------
   A 28px button is a comfortable target for a mouse and a coin toss for a
   thumb. This keys off the pointer rather than the viewport, so a tablet gets
   the same treatment as a phone and a small desktop window does not. */
@media (pointer: coarse) {
  .btn, .seg button, .toolbar input, .toolbar select { min-height: 44px; }
  .icon-btn, .menu-btn, .rail-btn { min-width: 44px; min-height: 44px; }
  .nav-item { min-height: 44px; }
  .nav-group { font-size: 10.5px; }

  /* Inside a row, 44px each would make three actions taller than the row they
     sit in. 38px still clears the average fingertip. */
  td.actions .icon-btn, td.actions .btn-sm { min-height: 38px; min-width: 38px; }

  /* Safari zooms the whole page when a focused input is under 16px. The layout
     then sits half off-screen and has to be pinched back — which reads as the
     app being broken rather than as a browser default. */
  .field input, .field select, .field textarea,
  .toolbar input, .toolbar select,
  .login-card input { font-size: 16px; }
}

/* ============================================================
   Printable documents (the invoice you send a customer).
   Hidden on screen; on paper it is the only thing that prints.
   ============================================================ */
#printRoot { display: none; }

.doc { color: #111; background: #fff; font-size: 12px; line-height: 1.55; }
.doc-head { display: flex; justify-content: space-between; gap: 24px; align-items: flex-start;
  padding-bottom: 16px; border-bottom: 2px solid #111; }
.doc-head h1 { font-size: 19px; font-weight: 700; letter-spacing: -.2px; }
.doc-meta { font-size: 11px; color: #444; margin-top: 4px; }
.doc-meta span { color: #888; }
.doc-title { text-align: right; }
.doc-title h2 { font-size: 22px; letter-spacing: 3px; font-weight: 700; }
.doc-no { font-family: var(--mono); font-size: 13px; margin-top: 2px; }
.doc-stamp { display: inline-block; margin-top: 8px; padding: 3px 12px; border: 2px solid; border-radius: 4px;
  font-weight: 700; letter-spacing: 2px; font-size: 12px; }
.doc-stamp.paid { color: #067647; border-color: #067647; }
.doc-stamp.due { color: #b42318; border-color: #b42318; }

.doc-parties { display: flex; justify-content: space-between; gap: 32px; margin: 20px 0 18px; }
.doc-label { font-size: 10px; text-transform: uppercase; letter-spacing: .08em; color: #888; margin-bottom: 4px; }
.doc-strong { font-size: 14px; font-weight: 650; }
.doc-facts { min-width: 240px; }
.doc-facts div { display: flex; justify-content: space-between; gap: 20px; padding: 2px 0; }
.doc-facts span { color: #666; }

.doc-table { width: 100%; border-collapse: collapse; margin-bottom: 16px; }
.doc-table th { text-align: left; font-size: 10px; text-transform: uppercase; letter-spacing: .06em;
  color: #555; border-bottom: 1px solid #bbb; padding: 7px 8px; background: #f4f4f6; }
.doc-table td { padding: 8px; border-bottom: 1px solid #e5e5e8; vertical-align: top; }
.doc-table .r { text-align: right; font-variant-numeric: tabular-nums; }
.doc-table.small td, .doc-table.small th { padding: 5px 8px; font-size: 11px; }
.doc-sub { font-size: 10.5px; color: #777; }

.doc-totals { margin-left: auto; width: 280px; }
.doc-totals div { display: flex; justify-content: space-between; padding: 4px 8px; }
.doc-totals b { font-variant-numeric: tabular-nums; }
.doc-due { border-top: 2px solid #111; margin-top: 4px; padding-top: 8px !important; font-size: 14px; }

.doc-payments { margin-top: 22px; }
.doc-note { margin-top: 18px; font-size: 11px; color: #444; }
.doc-foot { margin-top: 28px; padding-top: 12px; border-top: 1px solid #ddd; font-size: 11px; color: #555; }

@media print {
  /* Only the document goes on paper. */
  body.printing > *:not(#printRoot) { display: none !important; }
  body.printing #printRoot { display: block !important; }
  body { background: #fff; }
  @page { size: A4; margin: 16mm; }
  .doc-table thead { display: table-header-group; }
  .doc-table tr { break-inside: avoid; }
}

/* Letterhead preview on the Settings screen. */
.letterhead { border: 1px solid var(--line); border-radius: var(--r-sm); padding: 18px 20px; background: var(--surface-2); }
.lh-name { font-size: 17px; font-weight: 700; letter-spacing: -.2px; }
.lh-meta { font-size: 12px; color: var(--text-2); margin-top: 4px; white-space: pre-line; }
.lh-rule { height: 2px; background: var(--text); margin: 14px 0 10px; opacity: .8; }
.lh-foot { font-size: 12px; color: var(--text-2); min-height: 18px; }


/* A short window used to drop the group headings entirely to save height. With
   seven groups and seventeen items that removed the only thing telling sales
   from purchasing from finance, on exactly the windows where a long flat list
   is hardest to read. Tightened instead: the headings keep their meaning and
   still give back most of the space. The menu scrolls if it has to. */
@media (max-height: 700px) {
  .nav-group { padding: 6px 10px 1px; font-size: 9px; letter-spacing: .08em; }
  .nav { padding-top: 6px; }
}
