/* ==========================================================================
   Shared theme for every page — loaded once via page_header() (_common.php).
   Design system: dark "chrome" (sidebar/topbar) over a light content canvas,
   IBM Plex Sans for UI text, IBM Plex Mono for anything tabular/monetary.
   See DECISIONS.md "Interface redesign" for the reasoning.
   ========================================================================== */

:root {
  --paper: #EEF2EF;
  --surface: #FFFFFF;
  --surface-sunk: #E7ECE8;
  --ink: #14211F;
  --ink-soft: #29393B;
  --muted: #46564F;
  --faint: #64766D;
  --border: #C9D4CB;
  --border-strong: #A6B6AA;
  --accent: #1F425A;
  --accent-ink: #F3F7F9;
  --accent-soft: #DCE9EE;
  --success: #235A40;
  --success-soft: #D8ECDF;
  --critical: #8F2E2E;
  --critical-soft: #F1D9D8;
  --warning: #79540C;
  --warning-soft: #F0E1BE;
  --shadow: 0 1px 3px rgba(20,33,31,0.10), 0 8px 20px -8px rgba(20,33,31,0.20);
  --chrome: #14232A;
  --chrome-ink: #ECF1EF;
  --chrome-muted: #90A4A6;
  --chrome-faint: #5B6E71;
  --chrome-border: #263A40;
  --chrome-active: #24404C;
  /* Chrome (sidebar/topbar) is dark in both light and dark theme, so its
     own accent stays constant — the light-theme --accent is too dark to
     read against a dark chrome background. */
  --chrome-accent: #8FC3DB;
  /* User-assignable pin colors (page_header()'s pin picker; also now
     company_edit.php's chrome_color) — constant across both app themes,
     same reasoning as --chrome-accent: the chrome bar they render
     against is always dark. -dot is the vivid picker-swatch color (shown
     on the light pin-panel surface); -bg/-border are the tinted versions
     used on the pinned pill/company-switch badge/sidebar stripe.
     -bg/-border were originally desaturated to blend into the dark
     chrome, but that made them hard to tell apart at a glance (user
     feedback 2026-09-05/09) — teal especially, since its hue sits close
     to --chrome-active's own. Re-tuned to real Tailwind 800/600 shades
     (same families as -dot's own 400/500 shades) for meaningfully higher
     saturation while staying dark enough to read as a tinted chip, not a
     bright pastel. No true red — that stays reserved for void/overdue/
     critical (see --critical above), so a user's color choice here can
     never read as a warning. */
  --pin-blue-dot: #3B82F6; --pin-blue-bg: #1E40AF; --pin-blue-border: #2563EB;
  --pin-teal-dot: #14B8A6; --pin-teal-bg: #115E59; --pin-teal-border: #0D9488;
  --pin-green-dot: #22C55E; --pin-green-bg: #166534; --pin-green-border: #16A34A;
  --pin-amber-dot: #F59E0B; --pin-amber-bg: #92400E; --pin-amber-border: #D97706;
  --pin-purple-dot: #A78BFA; --pin-purple-bg: #5B21B6; --pin-purple-border: #7C3AED;
  --pin-rose-dot: #FB7185; --pin-rose-bg: #9F1239; --pin-rose-border: #E11D48;
  --radius-sm: 4px;
  --radius-md: 6px;
  --font-ui: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0D1315;
    --surface: #182124;
    --surface-sunk: #0A0F11;
    --ink: #F1F5F3;
    --ink-soft: #D3DEDA;
    --muted: #A6B8B1;
    --faint: #7E9089;
    --border: #384542;
    --border-strong: #4B5A56;
    --accent: #9EC4D6;
    --accent-ink: #0A1D26;
    --accent-soft: #22343C;
    --success: #7FC49E;
    --success-soft: #1C3729;
    --critical: #E9948F;
    --critical-soft: #3E2523;
    --warning: #E6BC6C;
    --warning-soft: #3E3018;
    --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 6px 20px -8px rgba(0,0,0,0.5);
    --chrome: #060A0B;
    --chrome-ink: #ECF1EF;
    --chrome-muted: #8098A0;
    --chrome-border: #1C2729;
    --chrome-active: #1E343C;
  }
}
:root[data-theme="dark"] {
  --paper: #0D1315;
  --surface: #182124;
  --surface-sunk: #0A0F11;
  --ink: #F1F5F3;
  --ink-soft: #D3DEDA;
  --muted: #A6B8B1;
  --faint: #7E9089;
  --border: #384542;
  --border-strong: #4B5A56;
  --accent: #9EC4D6;
  --accent-ink: #0A1D26;
  --accent-soft: #22343C;
  --success: #7FC49E;
  --success-soft: #1C3729;
  --critical: #E9948F;
  --critical-soft: #3E2523;
  --warning: #E6BC6C;
  --warning-soft: #3E3018;
  --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 6px 20px -8px rgba(0,0,0,0.5);
  --chrome: #060A0B;
  --chrome-ink: #ECF1EF;
  --chrome-muted: #8098A0;
  --chrome-border: #1C2729;
  --chrome-active: #1E343C;
}

* { box-sizing: border-box; }
/* Belt-and-braces: nothing on the page should ever be able to force a
   page-wide horizontal scrollbar/zoom-out. The real fix for any given
   overflowing element is still to make that element shrink properly
   (see .topbar/.main's own min-width: 0 below) — this is just a backstop
   so a future one can't silently reintroduce the same whole-page-zoomed-
   out-on-mobile bug (see mobile UX pass notes, DECISIONS.md). */
html, body { height: 100%; overflow-x: hidden; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { text-wrap: balance; font-weight: 600; margin: 0 0 6px; color: var(--ink); }
h1 { font-size: 21px; }
h2 { font-size: 17px; }
h3 { font-size: 14px; }
a { color: var(--accent); }
::selection { background: var(--accent-soft); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
small { color: var(--muted); }

/* ============ App shell ============ */
.shell {
  height: 100vh;
  display: grid;
  grid-template-columns: 240px 1fr;
  grid-template-rows: 56px 1fr;
  grid-template-areas: "topbar topbar" "sidebar main";
  overflow: hidden;
}
.shell.no-sidebar {
  grid-template-columns: 1fr;
  grid-template-areas: "topbar" "main";
}
.topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 18px;
  background: var(--chrome);
  border-bottom: 1px solid var(--chrome-border);
  z-index: 20;
  position: relative;
  /* A grid item's default min-width is content-based ("auto"), not the
     grid track's own width — without this, a topbar full of nowrap
     labels (brand, company name, account links) can force the whole
     "main" grid track, and with it the page, wider than the viewport on
     a phone, instead of the topbar's own children truncating/hiding as
     their own rules intend. */
  min-width: 0;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 600; letter-spacing: 0.01em; color: var(--chrome-ink); white-space: nowrap; }
.brand-mark {
  width: 22px; height: 22px; border-radius: var(--radius-sm);
  background: var(--chrome-accent); color: var(--chrome);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono); font-weight: 600; font-size: 12px;
}
.menu-btn {
  display: none; background: none; border: 1px solid transparent !important; border-radius: var(--radius-sm);
  width: 34px; height: 34px; padding: 0 !important; align-items: center; justify-content: center; cursor: pointer; color: var(--chrome-ink) !important;
}
.menu-btn:hover { background: var(--chrome-active) !important; }
.company-switch {
  display: flex; align-items: center; gap: 8px; padding: 6px 10px;
  border: 1px solid var(--chrome-border); border-radius: var(--radius-sm); background: var(--chrome-active);
  cursor: pointer; color: var(--chrome-ink); font-size: 13px; text-decoration: none;
}
.company-switch:hover { border-color: var(--chrome-muted); }
/* Now holds a company's legal/DBA name (page_header()), not just a short
   slug — cap it so a long name can't push the pinned links off the
   topbar; the mobile media query below tightens this further. */
.company-switch span:not(.brand-mark) { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.company-switch-logo { height: 18px; width: 18px; object-fit: contain; border-radius: 3px; background: var(--chrome-ink); }
/* Per-company chrome_color (migration 034) — a colored tint on the
   company-switch badge plus a persistent stripe down the sidebar, so
   which company is currently open reads at a glance across every page,
   not just from the (also-present) plain-text slug. Same --pin-*
   variables the top bar's own pinned-link colors use, set via the
   .pin-* rules above — see company_url()'s callers in _common.php for
   which element gets which class. */
.company-switch[class*="pin-"] { background: var(--pin-bg); border-color: var(--pin-border); }
.company-switch[class*="pin-"]:hover { border-color: var(--pin-dot); }
.sidebar[class*="pin-"] { border-left: 6px solid var(--pin-dot); }
.topbar-spacer { flex: 1; }
.user-menu { display: flex; align-items: center; gap: 12px; font-size: 12.5px; color: var(--chrome-muted); white-space: nowrap; }
.user-menu a { color: var(--chrome-muted); }
.user-menu a:hover { color: var(--chrome-ink); }
.user-menu-name { color: var(--chrome-ink); font-weight: 500; }
/* Mobile-only stand-in for .user-menu above (toggled by the media query
   below) — the same account links (Companies/Manage users/Access log/
   Log out), collapsed behind one icon button instead of shown inline,
   since their text doesn't fit a phone-width topbar. Reuses the same
   native <details>/.page-menu disclosure company_edit.php's "More"
   menu already uses, and the same icon-button shape as .pin-config-btn
   right next to it in the topbar, rather than inventing a new pattern. */
.account-menu { display: none; }
.account-menu-btn {
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  width: 34px; height: 34px; padding: 0 !important; border: 1px solid transparent !important; border-radius: var(--radius-sm);
  background: none; color: var(--chrome-ink) !important; cursor: pointer;
}
.account-menu-btn:hover, .account-menu[open] .account-menu-btn { background: var(--chrome-active) !important; }

/* ============ Pinned top-bar links ============ */
.pinned-links {
  display: flex; align-items: center; gap: 4px;
  overflow-x: auto; scrollbar-width: none;
}
.pinned-links::-webkit-scrollbar { display: none; }
.pinned-link {
  padding: 7px 13px; border-radius: var(--radius-sm);
  border: 1px solid var(--chrome-border); background: var(--chrome-active);
  color: var(--chrome-ink); text-decoration: none; font-size: 14px; font-weight: 500; white-space: nowrap;
}
.pinned-link:hover { border-color: var(--chrome-muted); color: var(--chrome-accent); }
/* Sets of --pin-bg/--pin-border/--pin-dot, keyed by color name — not
   scoped to .pinned-link, so the same six colors also drive the
   per-company chrome-color indicator below (.company-switch/.sidebar)
   without duplicating the palette. */
.pin-blue   { --pin-bg: var(--pin-blue-bg);   --pin-border: var(--pin-blue-border);   --pin-dot: var(--pin-blue-dot); }
.pin-teal   { --pin-bg: var(--pin-teal-bg);   --pin-border: var(--pin-teal-border);   --pin-dot: var(--pin-teal-dot); }
.pin-green  { --pin-bg: var(--pin-green-bg);  --pin-border: var(--pin-green-border);  --pin-dot: var(--pin-green-dot); }
.pin-amber  { --pin-bg: var(--pin-amber-bg);  --pin-border: var(--pin-amber-border);  --pin-dot: var(--pin-amber-dot); }
.pin-purple { --pin-bg: var(--pin-purple-bg); --pin-border: var(--pin-purple-border); --pin-dot: var(--pin-purple-dot); }
.pin-rose   { --pin-bg: var(--pin-rose-bg);   --pin-border: var(--pin-rose-border);   --pin-dot: var(--pin-rose-dot); }
.pinned-link[class*="pin-"] { background: var(--pin-bg); border-color: var(--pin-border); }
.pinned-link[class*="pin-"]:hover { border-color: var(--pin-dot); color: var(--pin-dot); }
.pin-config-btn {
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  width: 34px; height: 34px; padding: 0 !important; border: 1px solid transparent !important; border-radius: var(--radius-sm);
  background: none; color: var(--chrome-ink) !important; cursor: pointer;
}
.pin-config-btn:hover, .pin-config-btn[aria-expanded="true"] { background: var(--chrome-active) !important; color: var(--chrome-ink) !important; }

.pin-panel {
  position: absolute; top: 46px; right: 18px; z-index: 30;
  width: 300px; max-height: min(70vh, 560px); overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  box-shadow: var(--shadow); padding: 14px;
}
.pin-panel-title { margin: 0 0 10px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--faint); }
.pin-panel-group { margin-bottom: 12px; }
.pin-panel-label {
  font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--faint);
  padding-bottom: 5px; margin-bottom: 4px; border-bottom: 1px solid var(--border);
}
.pin-panel-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 5px 2px; font-size: 13.5px; color: var(--ink); font-weight: 400;
}
.pin-panel-checkbox { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.pin-panel-checkbox input { margin: 0; }
.pin-swatches { display: inline-flex; align-items: center; gap: 4px; flex-shrink: 0; }
.swatch {
  display: inline-block; width: 14px; height: 14px; border-radius: 50%;
  cursor: pointer; border: 1px solid var(--border-strong); position: relative;
}
.swatch input { position: absolute; opacity: 0; width: 0; height: 0; }
.swatch:has(input:checked) { outline: 2px solid var(--ink-soft); outline-offset: 1px; }
.swatch-none { background: var(--surface-sunk); }
.swatch-blue { background: var(--pin-blue-dot); border-color: var(--pin-blue-dot); }
.swatch-teal { background: var(--pin-teal-dot); border-color: var(--pin-teal-dot); }
.swatch-green { background: var(--pin-green-dot); border-color: var(--pin-green-dot); }
.swatch-amber { background: var(--pin-amber-dot); border-color: var(--pin-amber-dot); }
.swatch-purple { background: var(--pin-purple-dot); border-color: var(--pin-purple-dot); }
.swatch-rose { background: var(--pin-rose-dot); border-color: var(--pin-rose-dot); }
.pin-panel-actions { display: flex; gap: 8px; margin-top: 4px; padding-top: 10px; border-top: 1px solid var(--border); }

.scrim { display: none; position: fixed; inset: 0; background: rgba(4,7,8,0.55); z-index: 15; }

/* ============ Confirmation dialog (confirm.js) ============
   Replaces native confirm() for destructive/one-way form submissions —
   a native <dialog> for free focus-trapping/Escape-to-close, styled to
   match everything else instead of the browser's unstyled default. */
.confirm-dialog {
  border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow);
  padding: 20px; max-width: 380px; width: calc(100% - 40px);
}
.confirm-dialog::backdrop { background: rgba(4,7,8,0.55); }
.confirm-dialog-message { margin: 0 0 16px; font-size: 14px; line-height: 1.5; }
.confirm-dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ============ Flash banner (set_flash()/page_header(), _common.php) ============
   One-shot post-redirect success acknowledgment — "Invoice INV-142
   posted" — instead of a bare redirect with no confirmation feedback. */
.flash-success {
  background: var(--success-soft); color: var(--success); border: 1px solid var(--success);
  border-radius: var(--radius-sm); padding: 10px 14px; margin: 0 0 16px; font-size: 13.5px;
}

/* ============ Live totals (live-totals.js) ============ */
.live-total-output {
  padding: 10px 18px; font-family: var(--font-mono); font-variant-numeric: tabular-nums;
  font-size: 13px; color: var(--muted); border-top: 1px solid var(--border);
}
.live-total-output.live-total-balanced { color: var(--success); font-weight: 600; }

/* ============ Sidebar ============ */
.sidebar {
  grid-area: sidebar;
  background: var(--chrome);
  border-right: 1px solid var(--chrome-border);
  overflow-y: auto;
  padding: 14px 10px 24px;
}
.nav-group { margin-top: 18px; }
.nav-label {
  display: flex; align-items: center; justify-content: space-between; gap: 6px; width: 100%;
  font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.1em; color: var(--chrome-faint);
  padding: 0 10px 8px; margin: 0 0 6px;
  border: none; border-bottom: 1px solid var(--chrome-border); background: none;
  font-family: inherit; cursor: pointer;
}
.nav-label:hover { color: var(--chrome-muted); }
.nav-chevron { flex-shrink: 0; transition: transform 0.15s ease; }
@media (prefers-reduced-motion: reduce) { .nav-chevron { transition: none; } }
.nav-group.collapsed .nav-chevron { transform: rotate(-90deg); }
.nav-group.collapsed .nav-group-items { display: none; }
a.nav-item, button.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--chrome-ink); text-decoration: none; font-size: 13.5px;
  cursor: pointer; border: none !important; background: none; width: 100%; text-align: left;
  font-family: inherit; font-weight: 400;
}
a.nav-item:hover, button.nav-item:hover { background: var(--chrome-active) !important; }
a.nav-item.active, button.nav-item.active { background: var(--chrome-active) !important; color: var(--chrome-accent) !important; font-weight: 500; }

/* ============ Main content ============ */
.main { grid-area: main; overflow-y: auto; overflow-x: auto; padding: 26px 30px 60px; min-width: 0; }
.page-wrap { max-width: 1180px; }
.page-title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.page-title-row h1 { margin: 0 0 6px; }

/* ============ Page-level "More" menu (dialog.js) ============
   A native <details>/<summary> disclosure instead of a hand-rolled
   dropdown — free keyboard/click-outside handling. Opens content
   <dialog>s (below) for actions that don't need to always be visible on
   the page, e.g. company_edit.php's Data export / Archive company. */
.page-menu { position: relative; margin-bottom: 6px; }
.page-menu > summary { list-style: none; cursor: pointer; }
.page-menu > summary::-webkit-details-marker { display: none; }
.page-menu-list {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 20;
  min-width: 200px; padding: 6px; display: flex; flex-direction: column; gap: 2px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow);
}
.page-menu-item {
  display: block; width: 100%; text-align: left; font: inherit; color: var(--ink);
  background: none; border: none; padding: 8px 10px; border-radius: var(--radius-sm); cursor: pointer;
}
.page-menu-item:hover, .page-menu-item:focus-visible { background: var(--surface-sunk); }

/* ============ Content dialog (dialog.js) ============
   Same native <dialog> shape as .confirm-dialog, wider and left-aligned
   for real paragraph content plus its own form(s) instead of a single
   confirm/cancel choice. */
.content-dialog {
  border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow);
  padding: 20px; max-width: 480px; width: calc(100% - 40px);
}
.content-dialog::backdrop { background: rgba(4,7,8,0.55); }
.content-dialog h2 { margin-top: 0; }
.content-dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* ============ Buttons ============
   A four-tier UX-importance ladder, assigned per page based on what that
   page's own actions actually are (see CLAUDE.md's action-bar
   hierarchy) — not every page uses all four tiers, and a page can
   legitimately show more than one Primary1 action at once (e.g.
   bill.php's Edit and Post Bill are both Primary1 — each is, on its
   own, "the reason someone is on this page" for a different bill
   status).
     Primary1   .btn-primary          solid accent fill — top tier.
     Primary2   .btn-primary-outline  accent outline, transparent fill —
                                       same accent family as Primary1,
                                       one rung down.
     Secondary1 .btn-secondary        neutral border, solid surface fill
                                       — the plain default look below.
     Secondary2 .btn-secondary-outline neutral outline, transparent fill
                                       — one rung down from Secondary1.
   .btn-danger is a separate axis (destructive, not a rank) — see the
   ledger-red rule above.
   Every tier's hover fills in toward its own color rather than a single
   shared hover treatment, so the feedback language reads as one system:
   a solid tier darkens itself, an outline tier fills in with a soft
   tint of the same hue it's already bordered in.
*/
button, .btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong);
  font-family: inherit; font-size: 13.5px; font-weight: 500; cursor: pointer; white-space: nowrap;
  background: var(--surface); color: var(--ink); text-decoration: none;
  transition: background-color .12s ease, border-color .12s ease, color .12s ease;
}
@media (prefers-reduced-motion: reduce) { button, .btn, a.nav-item, button.nav-item, .sidebar, .scrim { transition: none !important; } }
button:hover, .btn:hover { background: var(--surface-sunk); }

.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, black); }

.btn-primary-outline { background: transparent; border-color: var(--accent); color: var(--accent); }
.btn-primary-outline:hover { background: var(--accent-soft); }

.btn-secondary { background: var(--surface); border-color: var(--border-strong); color: var(--ink); }

.btn-secondary-outline { background: transparent; border-color: var(--border); color: var(--muted); }
.btn-secondary-outline:hover { background: var(--surface-sunk); color: var(--ink); }

.btn-danger, button.btn-danger { background: none; border-color: var(--critical); color: var(--critical); }
.btn-danger:hover, button.btn-danger:hover { background: var(--critical-soft); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }

/* A <button> (needed for a real form POST — Archive, etc.) styled to
   read as a plain inline link instead of a button, for an action that's
   real but minor enough not to compete visually with the row it's on. */
.btn-link, button.btn-link {
  display: inline; background: none; border: none; padding: 0; border-radius: 0;
  color: var(--accent); font-size: inherit; font-weight: 400; text-decoration: underline;
}
.btn-link:hover, button.btn-link:hover { background: none; color: var(--accent); opacity: 0.8; }
/* Same reasoning as .field-row-group[hidden] elsewhere in this file — an
   author class's own `display` otherwise beats the UA default for
   [hidden], so toggling the hidden attribute (customers/vendors/items.php's
   live "Clear" link) would silently do nothing without this. */
.btn-link[hidden] { display: none; }

/* ============ Forms ============
   A fieldset is a real panel (surface background, generous gap) laid out
   as a wrapping flex row — every field-carrying <label> becomes one flex
   item, its own two lines (caption, then the control) via flex-direction:
   column, so plain pre-existing markup like `<label>City: <input></label>`
   gets a proper stacked field with no markup changes anywhere. A
   checkbox/radio label is the one deliberate exception (:has() below) —
   those stay a single inline row, box beside its own words, since
   stacking a checkbox above its label reads as broken. A label wrapping a
   <textarea> goes full-width instead of sharing a row, since a notes box
   cramped to input-width defeats the point of it being a textarea. */
/* Capped on the fieldset itself, not the form — several forms (invoice/
   bill/credit-memo line items) have a wide <table> as a sibling of the
   fieldset within the same <form>, which needs the full content width. */
fieldset {
  border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--surface); margin-bottom: 18px; padding: 18px 20px 16px;
  display: flex; flex-wrap: wrap; gap: 16px 22px; align-items: flex-start;
  max-width: 820px;
}
legend { font-size: 12.5px; font-weight: 600; color: var(--ink-soft); padding: 0 6px; }
label {
  display: flex; flex-direction: column; gap: 5px;
  margin: 0; font-size: 12.5px; color: var(--muted); line-height: 1.3;
}
label:has(> input[type="checkbox"]), label:has(> input[type="radio"]) {
  flex-direction: row; align-items: center; gap: 7px; color: var(--ink-soft);
  align-self: center;
}
label:has(> textarea) { flex-basis: 100%; max-width: 640px; }
label:has(> input[type="checkbox"]) input, label:has(> input[type="radio"]) input { margin: 0; }
input, select, textarea {
  font-family: inherit; font-size: 13.5px; color: var(--ink); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 7px 10px; outline: none;
}
select { min-width: 11em; }
textarea { width: 100%; min-height: 4.5em; font-family: inherit; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type="checkbox"], input[type="radio"] { padding: 0; }
form > button, form > .btn, form > .btn-link { margin-top: 4px; }
/* A one-off explanatory line inside a fieldset (e.g. "only needed if
   shipping differs from billing") — always its own full-width row
   rather than competing for space as just another field. */
.field-hint { margin: 6px 0 0; font-size: 12px; color: var(--faint); }
.field-hint a { color: var(--faint); text-decoration: underline; }
fieldset .field-hint { flex-basis: 100%; margin: 2px 0 0; }
/* A <div> that only exists to be JS-shown/hidden as one unit (e.g. an
   item's inventory-only fields) shouldn't create its own nested block
   layout — display:contents promotes its label children to be direct
   flex items of the fieldset itself, so they wrap into the same field
   grid as everything else. The [hidden] rule re-asserts over that (an
   author stylesheet class otherwise beats the UA default for the
   hidden attribute) so toggling .hidden in JS still actually hides it. */
.field-row-group { display: contents; }
.field-row-group[hidden] { display: none; }
/* A lone stray <br> from old manual line-break markup is now a harmless,
   zero-effect flex item rather than something that needs stripping out
   of every page — flex containers don't honor forced line breaks. */
fieldset > br { display: none; }

/* ============ Tables ============ */
table { border-collapse: collapse; margin: 1rem 0; width: 100%; background: var(--surface); }
th, td { border-bottom: 1px solid var(--border); padding: 9px 12px; text-align: left; font-size: 13.5px; }
th {
  background: var(--surface-sunk); font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--faint); font-weight: 600;
}
tr:hover td { background: var(--surface-sunk); }
.num { text-align: right; }
.void { color: var(--faint); text-decoration: line-through; }

/* ============ Alerts ============ */
.error, .ok {
  border-radius: var(--radius-md); padding: 10px 16px; margin: 0 0 1rem; font-size: 13.5px;
}
.error { color: var(--critical); border: 1px solid var(--critical); background: var(--critical-soft); }
.ok { color: var(--success); border: 1px solid var(--success); background: var(--success-soft); }
/* A negative dollar figure (money(), _common.php) — plain text in the
   traditional accounting red, not a badge/pill. */
.money-negative { color: var(--critical); }

/* ============ Status pills (Phase 2: adopt per-page) ============ */
.pill {
  display: inline-flex; align-items: center; gap: 5px; white-space: nowrap;
  padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 500; letter-spacing: 0.01em;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill-posted, .pill-success { background: var(--success-soft); color: var(--success); }
.pill-draft { background: var(--surface-sunk); color: var(--muted); }
.pill-overdue, .pill-critical { background: var(--critical-soft); color: var(--critical); }
.pill-void { background: var(--surface-sunk); color: var(--faint); text-decoration: line-through; }
.pill-partial, .pill-warning { background: var(--warning-soft); color: var(--warning); }

/* ============ Panels / KPI tiles / dashboard (Phase 2: adopt per-page) ============ */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); margin-bottom: 22px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.panel-head h2 { margin: 0; }
.panel-body { padding: 6px 0; }
.panel-body.pad { padding: 16px 18px; }
.panel table { margin: 0; }
.panel th:first-child, .panel td:first-child { padding-left: 18px; }
.panel th:last-child, .panel td:last-child { padding-right: 18px; }

.kpi-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 26px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 16px 18px; }
.kpi-label { font-size: 12.5px; color: var(--muted); margin-bottom: 8px; }
.kpi-value { font-family: var(--font-mono); font-size: 24px; font-weight: 600; letter-spacing: -0.01em; }
.kpi-sub { font-size: 12px; color: var(--faint); margin-top: 6px; }
.kpi-sub.up { color: var(--success); }
.kpi-sub.down { color: var(--critical); }
.quick-row { display: flex; gap: 10px; margin-bottom: 26px; flex-wrap: wrap; }

.activity-row { display: flex; align-items: center; gap: 12px; padding: 11px 18px; border-bottom: 1px solid var(--border); }
.activity-row:last-child { border-bottom: none; }
.activity-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.activity-body { flex: 1; min-width: 0; }
.activity-title { font-size: 13.5px; }
.activity-meta { font-size: 12px; color: var(--faint); }
.activity-amt { font-family: var(--font-mono); font-size: 13.5px; }

.filters { display: flex; gap: 8px; padding: 14px 18px; border-bottom: 1px solid var(--border); flex-wrap: wrap; align-items: center; }
.chip {
  padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface);
  font-size: 12.5px; color: var(--muted); cursor: pointer;
}
.chip.active { background: var(--accent-soft); border-color: var(--accent-soft); color: var(--accent); font-weight: 500; }

.meta-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 22px; }
.meta-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 16px 18px; }
.meta-card h3 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--faint); margin-bottom: 10px; }
.meta-line { display: flex; justify-content: space-between; padding: 5px 0; font-size: 13.5px; }
.meta-line .k { color: var(--muted); }
.meta-line .v { text-align: right; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label { margin: 0; font-size: 12.5px; font-weight: 500; }

/* ============ typeahead.js widget ============ */
.typeahead { position: relative; display: inline-block; }
.typeahead-input { width: 240px; }
/* A number input renders far wider than its content needs by default —
   every quantity[] field across the invoice/bill/credit-memo/recurring
   line-items tables (see typeahead_field() call sites) shares this one
   name, so this one rule fixes all of them at once. */
input[name="quantity[]"] { width: 80px; }
.typeahead-suggestions {
  position: absolute; top: 100%; left: 0; z-index: 10; margin-top: 2px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  max-height: 220px; overflow-y: auto; min-width: 260px; max-width: 380px; box-shadow: var(--shadow);
}
.typeahead-suggestions .suggestion { padding: 0.4rem 0.7rem; cursor: pointer; font-size: 13.5px; }
.typeahead-suggestions .suggestion:hover,
.typeahead-suggestions .suggestion.active { background: var(--accent-soft); }
.typeahead-suggestions .suggestion-empty { padding: 0.4rem 0.7rem; color: var(--faint); font-style: italic; }
#list-search { width: 300px; margin-bottom: 0.5rem; }

/* ============ Responsive ============ */
@media (max-width: 860px) {
  .shell:not(.no-sidebar) { grid-template-columns: 1fr; grid-template-areas: "topbar" "main"; }
  .menu-btn { display: flex; width: 44px; height: 44px; }
  .sidebar {
    position: fixed; top: 56px; bottom: 0; left: 0; width: 250px; z-index: 20;
    transform: translateX(-100%); transition: transform .18s ease;
    box-shadow: var(--shadow);
  }
  .shell.nav-open .sidebar { transform: translateX(0); }
  .shell.nav-open .scrim { display: block; top: 56px; }
  .company-switch span:not(.brand-mark) { max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  /* Wordmark text drops (keeping just the "$" mark) to leave room for
     the company name/switcher, which is the thing actually worth the
     space on a phone-width topbar. */
  .brand span:not(.brand-mark) { display: none; }
  .user-menu { display: none; }
  .account-menu { display: block; }
  .pinned-links { display: none; }
  .pin-panel { right: 10px; left: 10px; width: auto; top: 50px; }
  .kpi-row { grid-template-columns: 1fr 1fr; }
  .meta-grid { grid-template-columns: 1fr; }
  .main { padding: 18px 14px 50px; }

  /* Bigger, easier-to-tap nav rows — the desktop sizing (13.5px text,
     8px padding) assumes a mouse pointer; this is now the only way to
     navigate on a phone, so it gets real touch-target sizing. */
  a.nav-item, button.nav-item { padding: 12px 10px; font-size: 15px; }
  .nav-label { padding: 0 10px 12px; font-size: 11.5px; }

  /* Fallback only — a table wider than the screen at least scrolls
     instead of getting silently clipped, for the rare case JS didn't
     run (responsive-tables.js normally replaces this with the stacked-
     card layout just below, which every table across the whole app
     gets automatically — see that file's own comment for why a global
     JS pass on <table>/<th>/<td> covers ~40 pages' worth of tables
     without touching any of their markup). Still the ONLY treatment
     for a table responsive-tables.js explicitly skips (no <th> row to
     label from at all). */
  table { display: block; width: auto; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  th, td { white-space: nowrap; font-size: 15px; }
  th { font-size: 12.5px; }

  /* The real mobile table treatment: one stacked "card" per row instead
     of a cramped, horizontally-scrolling grid — the classic responsive-
     table pattern, applied by responsive-tables.js (which adds this
     class and a data-label on every <td> from that column's own <th>
     text) rather than per-page markup changes. */
  table.responsive-cards {
    display: block; width: 100%; max-width: 100%; overflow-x: visible; white-space: normal;
  }
  table.responsive-cards thead { display: none; }
  table.responsive-cards tbody { display: block; }
  table.responsive-cards tr {
    display: block; margin-bottom: 10px; padding: 10px 12px;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  }
  /* An empty-state/colspan row (e.g. "No invoices match.") — responsive-
     tables.js leaves these without a data-label; render as plain
     unlabeled text, not a card that looks broken. */
  table.responsive-cards tr:has(td[colspan]) { background: none; border: none; padding: 4px 0; }
  table.responsive-cards td {
    display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 4px 12px;
    padding: 5px 0; border: none; white-space: normal; font-size: 15px; text-align: right;
  }
  table.responsive-cards td:not([data-label]) { justify-content: flex-start; text-align: left; }
  table.responsive-cards td[data-label]::before {
    content: attr(data-label); flex-shrink: 0; text-align: left;
    font-size: 12.5px; font-weight: 500; color: var(--muted);
  }
  /* A real form control (an editable line-items table — e.g. invoice
     entry — still gets this same card treatment) reads better on its
     own full-width line below the label than squeezed beside it. */
  table.responsive-cards td:has(> input),
  table.responsive-cards td:has(> select),
  table.responsive-cards td:has(> .typeahead) { flex-direction: column; align-items: stretch; }
  table.responsive-cards td:has(> input) > input,
  table.responsive-cards td:has(> select) > select { width: 100%; }
  /* A cell with nothing in it (a blank "Due" column on a draft, say)
     would otherwise still show its label with nothing after it. */
  table.responsive-cards td[data-label]:empty { display: none; }

  /* General type bump — the desktop sizes above (12-13.5px for most UI
     text) read as genuinely small once nothing else on the screen is
     competing for space the way a desktop window's other chrome does.
     Headings (h1/h2/h3) already have their own larger explicit sizes
     and are left alone; this covers the smaller supporting text that
     makes up most of what's actually read on any given page. */
  body { font-size: 16px; }
  label { font-size: 14.5px; }
  .field-hint { font-size: 13.5px; }
  .pill { font-size: 12.5px; }

  /* 16px is the threshold below which iOS Safari zooms the whole page
     in when a field is focused — jarring, and almost certainly most of
     what reads as "fields are too small." Selects/inputs/textareas are
     what get typed/tapped into; buttons don't trigger that zoom, so
     they keep their own sizing below instead of matching this. */
  input, select, textarea { font-size: 16px; }
  /* An input/textarea's HTML size="N"/cols="N" attribute (e.g.
     size="60" on a handful of Company Settings fields) sets an
     intrinsic width in characters that's completely independent of any
     CSS width — at 16px/char that alone can exceed a phone's viewport,
     overflowing sideways regardless of the table/flex-wrap fixes
     elsewhere on this page. One global cap fixes every such field at
     once, the same "don't touch ~40 pages of markup" reasoning as the
     table treatment above. */
  input, textarea { max-width: 100%; box-sizing: border-box; }

  /* ~44px is the touch-target size both Apple's HIG and Material Design
     call a minimum — well above this app's desktop-mouse-sized default
     (8px vertical padding + 13.5px text). Checkboxes/radios are excluded
     (a 44px-tall checkbox would look broken) and sized up separately. */
  button, .btn,
  input:not([type="checkbox"]):not([type="radio"]), select {
    min-height: 44px;
  }
  button, .btn { font-size: 15px; }
  input[type="checkbox"], input[type="radio"] { width: 20px; height: 20px; }

  /* Fixed pixel widths that fit fine on a desktop viewport can force a
     phone-width layout to overflow sideways on their own, independent
     of the table fix above. */
  .typeahead-input, #list-search { width: 100%; }
}
@media (max-width: 520px) {
  .kpi-row { grid-template-columns: 1fr; }
  .user-menu { gap: 8px; }
  fieldset { padding: 16px; gap: 14px; }
  fieldset label:not(:has(> input[type="checkbox"])):not(:has(> input[type="radio"])) { flex: 1 1 100%; }
  fieldset input, fieldset select { width: 100%; }
}

/* ==========================================================================
   New-company setup wizard (wizard_header()/wizard_footer(), _common.php) —
   deliberately its own minimal shell, not the app's normal sidebar/topbar
   shell: no nav to get lost in during first-run setup, one focused step
   at a time. Reuses the same chrome/surface tokens as the real topbar so
   it doesn't look like a different, unrelated product mid-setup.
   ========================================================================== */
.wizard-shell { min-height: 100vh; display: flex; flex-direction: column; background: var(--paper); }
.wizard-topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; height: 56px; background: var(--chrome); border-bottom: 1px solid var(--chrome-border);
}
.wizard-cancel { color: var(--chrome-muted); font-size: 13px; text-decoration: none; }
.wizard-cancel:hover { color: var(--chrome-ink); }
.wizard-main { flex: 1; display: flex; flex-direction: column; align-items: center; padding: 48px 20px; }
.wizard-main > * { width: 100%; max-width: 640px; }
.wizard-step-label {
  margin: 0 0 6px; font-size: 12px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--faint);
}
.wizard-main h1 { margin: 0 0 24px; }
.wizard-choice-row { display: flex; flex-direction: column; gap: 12px; }
.wizard-choice {
  display: block; padding: 20px 22px; border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--surface); text-decoration: none; color: var(--ink); box-shadow: var(--shadow);
}
.wizard-choice:hover { border-color: var(--accent); }
.wizard-choice strong { display: block; font-size: 16px; margin-bottom: 4px; }
.wizard-choice span { color: var(--muted); font-size: 14px; }
.wizard-actions { display: flex; gap: 12px; align-items: center; margin-top: 20px; }
.wizard-skip { color: var(--muted); font-size: 14px; text-decoration: none; }
.wizard-skip:hover { color: var(--ink); }
@media (max-width: 520px) {
  .wizard-main { padding: 28px 16px; }
}
