/* Components and layout. All values come from tokens.css. */
*, *::before, *::after { box-sizing: border-box; }
html { font-size: 16px; }
body { margin: 0; font: var(--fs-14)/var(--lh) var(--font-ui); color: var(--ink); background: var(--paper);
  -webkit-text-size-adjust: 100%; }
h1, h2, h3, p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
.num, input[type=number] { font-variant-numeric: tabular-nums lining-nums; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: var(--r-sm); }
.skip { position: absolute; left: var(--s4); top: -60px; background: var(--brand); color: var(--brand-ink);
  padding: var(--s2) var(--s4); border-radius: var(--r-sm); z-index: 100; transition: top var(--t-fast); }
.skip:focus { top: var(--s2); }
svg.ic { width: 1em; height: 1em; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round; vertical-align: -0.14em; }

/* ---------------------------------------------------------------- shell */
.app { display: grid; grid-template-columns: 252px minmax(0, 1fr); min-height: 100vh; }
.rail { background: var(--rail); color: var(--rail-ink); position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; padding: var(--s5) 0 var(--s4); }
.brand { padding: 0 var(--s5) var(--s4); }
.brand-name { font: 600 var(--fs-16)/1.25 var(--font-title); letter-spacing: .1px; }
.brand-co { color: var(--rail-ink-2); font-size: var(--fs-13); margin-top: 2px; overflow-wrap: anywhere; }
.nav { display: flex; flex-direction: column; padding: var(--s2) var(--s3); gap: 2px; overflow-y: auto; flex: 1; }
.nav-label { color: var(--rail-ink-2); font-size: var(--fs-12); padding: var(--s4) var(--s2) var(--s1); }
.nav-item { display: flex; align-items: center; gap: var(--s3); padding: 9px var(--s2); border: 0; background: none;
  color: var(--rail-ink-2); text-align: left; border-radius: var(--r-sm); cursor: pointer; min-height: 40px;
  transition: background var(--t-fast), color var(--t-fast); }
.nav-item:hover { color: var(--rail-ink); background: rgba(255, 255, 255, .07); }
.nav-item[aria-current=page] { color: #fff; background: rgba(255, 255, 255, .13); font-weight: 600; }
.nav-item .step { width: 22px; height: 22px; border-radius: 50%; border: 1.5px solid currentColor; display: grid;
  place-items: center; font-size: var(--fs-12); flex: none; font-variant-numeric: tabular-nums; }
.nav-item .ic { font-size: 18px; width: 22px; }
.nav-item .flag { margin-left: auto; font-size: var(--fs-12); padding: 1px 7px; border-radius: var(--r-pill);
  background: rgba(255, 255, 255, .16); color: #fff; font-weight: 400; }
.nav-item .flag.bad { background: #c9413c; }
.rail-foot { padding: var(--s3) var(--s3) 0; display: flex; flex-direction: column; gap: 2px;
  border-top: 1px solid rgba(255, 255, 255, .12); }
.rail-note { color: var(--rail-ink-2); font-size: var(--fs-12); padding: var(--s3) var(--s5) 0; }
.main { padding: var(--s8) var(--s8) var(--s10); min-width: 0; }
.page { max-width: 1120px; margin: 0 auto; display: flex; flex-direction: column; gap: var(--s4); }
.page-head { display: flex; align-items: flex-end; gap: var(--s4); flex-wrap: wrap; margin-bottom: var(--s2); }
.page-head > div:first-child { flex: 1; min-width: 240px; }
.title { font: 600 var(--fs-26)/1.2 var(--font-title); letter-spacing: -.1px; }
.lede { color: var(--ink-2); margin-top: var(--s1); max-width: 68ch; }

/* ---------------------------------------------------------------- card */
.card { background: var(--sheet); border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: var(--shadow-1);
  padding: var(--s5); min-width: 0; }
.card-head { display: flex; align-items: baseline; gap: var(--s3); flex-wrap: wrap; margin-bottom: var(--s4); }
.card-title { font-size: var(--fs-16); font-weight: 600; }
.card-sub { color: var(--ink-2); font-size: var(--fs-13); }
.card-head .spacer { flex: 1; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(196px, 1fr)); gap: var(--s4) var(--s5); }
.row { display: flex; gap: var(--s3); align-items: center; flex-wrap: wrap; }
.row.end { align-items: flex-end; }
.stack { display: flex; flex-direction: column; gap: var(--s3); }
.muted { color: var(--ink-2); }
.hint { color: var(--ink-2); font-size: var(--fs-13); }

/* ---------------------------------------------------------------- button */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--s2); min-height: 36px;
  padding: 0 var(--s4); border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--sheet);
  color: var(--ink); cursor: pointer; font-weight: 600; white-space: nowrap; text-decoration: none;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast), transform var(--t-fast); }
.btn:hover { background: var(--sheet-2); border-color: var(--rule); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.12); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { background: var(--bad-soft); border-color: var(--bad); }
.btn.sm { min-height: 30px; padding: 0 var(--s3); font-weight: 400; font-size: var(--fs-13); }
.btn.lg { min-height: 46px; padding: 0 var(--s6); font-size: var(--fs-16); }
.btn.icon { padding: 0; width: 36px; }
.btn.sm.icon { width: 30px; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.rail .btn-rail { display: flex; align-items: center; gap: var(--s3); padding: 9px var(--s2); min-height: 40px; border: 0;
  background: none; color: var(--rail-ink-2); border-radius: var(--r-sm); cursor: pointer; text-align: left; }
.rail .btn-rail:hover { color: var(--rail-ink); background: rgba(255, 255, 255, .07); }
.rail .btn-rail .ic { font-size: 18px; width: 22px; }

/* ---------------------------------------------------------------- form */
.input, select.input { min-height: 36px; padding: 0 var(--s3); border: 1px solid var(--rule); border-radius: var(--r-sm);
  background: var(--sheet); min-width: 0; max-width: 100%; transition: border-color var(--t-fast), box-shadow var(--t-fast); }
.input:hover { border-color: var(--ink-2); }
.input:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 25%, transparent); }
input[type=number].input { width: 120px; text-align: right; }
.input.wide { width: 280px; }
.field { display: flex; flex-direction: column; gap: var(--s1); font-size: var(--fs-13); color: var(--ink-2); min-width: 0; }
.field > span { font-weight: 600; color: var(--ink); }
.check { display: inline-flex; align-items: center; gap: var(--s2); cursor: pointer; min-height: 32px; }
.check input { width: 16px; height: 16px; accent-color: var(--brand); }
.search { position: relative; }
.search .ic { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--ink-2); }
.search .input { padding-left: 32px; width: 240px; }

/* ---------------------------------------------------------------- badge, chip */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: var(--r-pill);
  font-size: var(--fs-12); font-weight: 600; background: var(--sheet-2); color: var(--ink-2); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.info { background: var(--info-soft); color: var(--info); }
.chips { display: flex; flex-direction: column; gap: var(--s2); }
.chip { display: flex; align-items: flex-start; gap: var(--s2); padding: var(--s2) var(--s3); border-radius: var(--r-sm);
  background: var(--ok-soft); color: var(--ok); font-variant-numeric: tabular-nums; }
.chip.bad { background: var(--bad-soft); color: var(--bad); font-weight: 600; }
.chip.plain { background: var(--sheet-2); color: var(--ink-2); }
.chip .ic { margin-top: 3px; }

/* ---------------------------------------------------------------- notice */
.notice { display: flex; gap: var(--s3); padding: var(--s3) var(--s4); border-radius: var(--r-md); border: 1px solid;
  align-items: flex-start; }
.notice .ic { font-size: 18px; margin-top: 1px; }
.notice b { display: block; }
.notice.ok { background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 35%, transparent); color: var(--ok); }
.notice.bad { background: var(--bad-soft); border-color: color-mix(in srgb, var(--bad) 35%, transparent); color: var(--bad); }
.notice.warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 35%, transparent); color: var(--warn); }

/* ---------------------------------------------------------------- ledger table */
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--r-sm); max-width: 100%; }
.table-wrap.tall { max-height: 440px; }
table.ledger { border-collapse: separate; border-spacing: 0; width: 100%; background: var(--sheet); }
.ledger th { position: sticky; top: 0; z-index: 1; background: var(--sheet-2); color: var(--ink-2); font-weight: 600;
  font-size: var(--fs-13); text-align: left; padding: 9px var(--s3); white-space: nowrap; border-bottom: 1px solid var(--rule); }
.ledger td { padding: 7px var(--s3); border-bottom: 1px solid var(--line); vertical-align: middle; }
.ledger tr:last-child td { border-bottom: 0; }
.ledger .num { text-align: right; white-space: nowrap; }
.ledger .rule { border-left: 3px double var(--rule); }           /* the accountant's double rule before amounts */
.ledger tr.total td { border-top: 1px solid var(--ink-2); border-bottom: 3px double var(--ink-2); font-weight: 700; }
.ledger tbody tr.pick { cursor: pointer; }
.ledger tbody tr:hover td { background: color-mix(in srgb, var(--brand-soft) 45%, transparent); }
.neg { color: var(--bad); font-weight: 700; }
.table-plain td { padding: 6px var(--s2); border: 0; }

/* ---------------------------------------------------------------- tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab { border: 0; background: none; padding: var(--s2) var(--s4); min-height: 38px; cursor: pointer; color: var(--ink-2);
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab:hover { color: var(--ink); }
.tab[aria-selected=true] { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }

/* ---------------------------------------------------------------- modal, toast */
.scrim { position: fixed; inset: 0; background: rgba(10, 13, 26, .55); display: grid; place-items: center; z-index: 50;
  padding: var(--s4); animation: fade var(--t-med) var(--ease); }
.modal { background: var(--sheet); border-radius: var(--r-md); box-shadow: var(--shadow-2); width: min(460px, 100%);
  padding: var(--s6); border: 1px solid var(--line); animation: rise var(--t-med) var(--ease); }
.modal h2 { font: 600 var(--fs-20)/1.25 var(--font-title); margin-bottom: var(--s2); }
.modal .modal-body { color: var(--ink-2); margin-bottom: var(--s5); display: flex; flex-direction: column; gap: var(--s3); }
.modal .modal-actions { display: flex; justify-content: flex-end; gap: var(--s2); flex-wrap: wrap; }
.toasts { position: fixed; right: var(--s5); bottom: var(--s5); display: flex; flex-direction: column; gap: var(--s2);
  z-index: 60; max-width: min(420px, calc(100vw - 32px)); }
.toast { display: flex; gap: var(--s3); align-items: flex-start; padding: var(--s3) var(--s4); border-radius: var(--r-md);
  background: var(--ink); color: var(--sheet); box-shadow: var(--shadow-2); animation: rise var(--t-med) var(--ease); }
.toast.bad { background: var(--bad); color: #fff; }
:root[data-theme="dark"] .toast.bad { color: #1a0a09; }
.toast .ic { font-size: 18px; margin-top: 1px; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

/* ---------------------------------------------------------------- empty, skeleton, progress, meter */
.empty { text-align: center; padding: var(--s8) var(--s4); color: var(--ink-2); }
.empty .ic { font-size: 32px; color: var(--rule); margin-bottom: var(--s2); }
.empty b { display: block; color: var(--ink); font-size: var(--fs-16); margin-bottom: var(--s1); }
.skeleton { border-radius: var(--r-sm); background: linear-gradient(90deg, var(--line) 25%, var(--sheet-2) 50%, var(--line) 75%);
  background-size: 200% 100%; animation: shimmer 1.2s linear infinite; height: 16px; }
.skeleton.block { height: 120px; border-radius: var(--r-md); }
@keyframes shimmer { to { background-position: -200% 0; } }
.progress { height: 6px; border-radius: var(--r-pill); background: var(--line); overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--brand); border-radius: inherit; transition: width var(--t-med) var(--ease); }
.progress.busy > i { width: 35%; animation: slide 1.1s var(--ease) infinite alternate; }
@keyframes slide { from { margin-left: 0; } to { margin-left: 65%; } }
.meter { display: flex; align-items: center; gap: var(--s3); color: var(--ink-2); font-size: var(--fs-13); }
.meter .progress { width: 140px; }

/* ---------------------------------------------------------------- dropzone */
.drop { border: 2px dashed var(--rule); border-radius: var(--r-md); padding: var(--s6); text-align: center; color: var(--ink-2);
  background: var(--sheet-2); transition: background var(--t-fast), border-color var(--t-fast); display: flex;
  flex-direction: column; align-items: center; gap: var(--s3); }
.drop.over { background: var(--brand-soft); border-color: var(--brand); color: var(--ink); }
.drop > .ic { font-size: 28px; color: var(--brand); }

/* ---------------------------------------------------------------- company cards */
.co-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: var(--s4); }
.co-card { display: flex; flex-direction: column; gap: var(--s3); text-align: left; background: var(--sheet); border: 1px solid var(--line);
  border-left: 4px solid var(--brand); border-radius: var(--r-md); padding: var(--s5); cursor: pointer; box-shadow: var(--shadow-1);
  min-height: 132px; transition: border-color var(--t-fast), box-shadow var(--t-med), transform var(--t-med) var(--ease); }
.co-card:hover { border-color: var(--brand); box-shadow: var(--shadow-2); transform: translateY(-2px); }
.co-card .co-name { font: 600 var(--fs-20)/1.25 var(--font-title); overflow-wrap: anywhere; }
.co-card .co-meta { color: var(--ink-2); font-size: var(--fs-13); margin-top: auto; display: flex; gap: var(--s2); align-items: center; flex-wrap: wrap; }
.co-card.new { border: 2px dashed var(--rule); background: transparent; box-shadow: none; align-items: center; justify-content: center;
  color: var(--ink-2); text-align: center; }
.co-card.new:hover { color: var(--brand); border-color: var(--brand); transform: none; box-shadow: none; }
.co-card.new .ic { font-size: 26px; }

/* ---------------------------------------------------------------- item cards (registers) */
.item-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(236px, 1fr)); gap: var(--s3); }
.item-card { text-align: left; background: var(--sheet); border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--s4);
  cursor: pointer; display: flex; flex-direction: column; gap: var(--s2); transition: border-color var(--t-fast), box-shadow var(--t-fast); }
.item-card:hover { border-color: var(--rule); }
.item-card[aria-pressed=true] { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand); }
.item-card .name { font-weight: 600; font-size: var(--fs-16); display: flex; justify-content: space-between; gap: var(--s2); }
.item-card dl { display: grid; grid-template-columns: auto 1fr; gap: 2px var(--s3); margin: 0; font-size: var(--fs-13); }
.item-card dt { color: var(--ink-2); }
.item-card dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.item-card dd.bal { font-weight: 700; }
.spark { width: 100%; height: 34px; display: block; }

/* ---------------------------------------------------------------- mix bar */
.mixbar { display: flex; height: 30px; border-radius: var(--r-sm); overflow: hidden; border: 1px solid var(--line); }
.mixbar > span { min-width: 2px; transition: flex-grow var(--t-med) var(--ease); }
.legend { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s5); font-size: var(--fs-13); margin-top: var(--s3); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; }
.legend b { font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: var(--s3); }
.stat { background: var(--sheet); border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--s4); }
.stat b { display: block; font: 600 var(--fs-26)/1.15 var(--font-ui); font-variant-numeric: tabular-nums; }
.stat span { color: var(--ink-2); font-size: var(--fs-13); }

/* ---------------------------------------------------------------- checklist */
.checklist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--s2); }
.checklist li { display: flex; gap: var(--s3); align-items: flex-start; }
.checklist .ic { font-size: 18px; margin-top: 1px; color: var(--ok); }
.checklist li.bad .ic { color: var(--bad); }
.checklist li.bad { color: var(--bad); font-weight: 600; }
.checklist small { display: block; color: var(--ink-2); font-weight: 400; }

/* ---------------------------------------------------------------- chart */
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart text { font: var(--fs-12) var(--font-ui); fill: var(--ink-2); font-variant-numeric: tabular-nums; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .axis { stroke: var(--rule); stroke-width: 1; }
.chart .cap { stroke: var(--bad); stroke-width: 1.5; stroke-dasharray: 6 4; }
.chart .cap-label { fill: var(--bad); font-weight: 600; }
.chart .series { fill: none; stroke-width: 2; stroke-linejoin: round; }
.chart .cursor { stroke: var(--ink-2); stroke-width: 1; stroke-dasharray: 2 3; }
.chart-tip { font-size: var(--fs-13); color: var(--ink-2); min-height: 20px; font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- calendar */
.cal { display: grid; grid-template-columns: repeat(auto-fill, minmax(196px, 1fr)); gap: var(--s4) var(--s5); }
.cal-month h3 { font-size: var(--fs-13); font-weight: 600; margin-bottom: var(--s1); }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-grid span.dow { font-size: 11px; color: var(--ink-2); text-align: center; }
.cal-day { border: 0; background: none; aspect-ratio: 1; border-radius: var(--r-sm); font-size: var(--fs-12); cursor: pointer;
  position: relative; font-variant-numeric: tabular-nums; padding: 0; transition: background var(--t-fast); }
.cal-day:hover { background: var(--brand-soft); }
.cal-day.off { background: var(--sheet-2); color: var(--ink-2); }
.cal-day.hol { background: var(--warn-soft); color: var(--warn); font-weight: 700; box-shadow: inset 0 0 0 1px var(--warn); }
.cal-day.sale::after { content: ""; position: absolute; left: 50%; bottom: 2px; width: 5px; height: 5px; margin-left: -2.5px;
  border-radius: 50%; background: var(--brand); }
.cal-day.out { visibility: hidden; }
.cal-key { display: flex; gap: var(--s5); flex-wrap: wrap; font-size: var(--fs-13); color: var(--ink-2); margin-bottom: var(--s4); }
.cal-key i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

/* ---------------------------------------------------------------- timeline */
.timeline { list-style: none; margin: 0; padding: 0 0 0 var(--s5); border-left: 2px solid var(--line); display: flex;
  flex-direction: column; gap: var(--s4); }
.timeline li { position: relative; background: var(--sheet); border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--s4);
  display: grid; grid-template-columns: auto 1fr auto; gap: var(--s2) var(--s4); align-items: center; }
.timeline li::before { content: ""; position: absolute; left: calc(-1 * var(--s5) - 7px); top: 22px; width: 12px; height: 12px;
  border-radius: 50%; background: var(--brand); border: 2px solid var(--paper); }
.timeline .when { font-weight: 600; }
.timeline .facts { color: var(--ink-2); font-size: var(--fs-13); grid-column: 2; }

/* ---------------------------------------------------------------- action bar */
.actionbar { display: flex; gap: var(--s3); align-items: center; flex-wrap: wrap; padding: var(--s3) var(--s4);
  background: var(--sheet); border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: var(--shadow-1); }
/* On a roomy screen the bar docks to the bottom edge as an opaque strip of the page itself,
   so it never floats on top of a card. On narrow or short screens it stays in the flow. */
@media (min-width: 900px) and (min-height: 640px) {
  .actionbar { position: sticky; bottom: 0; z-index: 5; background: var(--paper); border: 0; border-top: 1px solid var(--rule);
    border-radius: 0; box-shadow: none; padding: var(--s3) 0; margin-bottom: calc(-1 * var(--s10)); padding-bottom: var(--s4); }
}
details.more summary { cursor: pointer; color: var(--ink-2); padding: var(--s2) 0; }
details.more[open] summary { margin-bottom: var(--s2); }

/* ---------------------------------------------------------------- narrow */
@media (max-width: 899px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .rail { position: static; height: auto; padding: var(--s3) 0 0; }
  .brand { padding: 0 var(--s4) var(--s2); display: flex; align-items: baseline; gap: var(--s3); flex-wrap: wrap; }
  .nav { flex-direction: row; overflow-x: auto; padding: 0 var(--s3) var(--s2); flex: none; }
  .nav-label, .rail-note { display: none; }
  .nav-item { white-space: nowrap; flex: none; }
  .rail-foot { flex-direction: row; border-top: 1px solid rgba(255, 255, 255, .12); padding: var(--s1) var(--s3); }
  .main { padding: var(--s5) var(--s4) var(--s8); }
  .input.wide, .search .input { width: 100%; }
  .title { font-size: var(--fs-20); }
  .timeline li { grid-template-columns: 1fr; }
  .timeline .facts { grid-column: 1; }
}

/* ================================================================ phone and tablet (Phase C)
   Bottom bar for the four steps, 44 px touch targets, tables scroll inside their own box
   with the first column held in place, and the page itself never scrolls sideways. */
.sk-title { width: 220px; height: 28px; }
.topact { display: none; }
.tabbar { display: none; }
@media (max-width: 899px) {
  .rail { position: sticky; top: 0; z-index: 20; flex-direction: row; align-items: center; height: auto;
    padding: var(--s2) var(--s4); padding-top: calc(var(--s2) + env(safe-area-inset-top)); }
  .brand { padding: 0; flex: 1; min-width: 0; display: block; }
  .brand-co { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .nav, .rail-foot, .rail-note { display: none; }
  .topact { display: block; }
  .topact .btn-rail { min-width: 44px; min-height: 44px; justify-content: center; }
  .main { padding: var(--s4) var(--s4) var(--s8); }
  body.has-co .main { padding-bottom: calc(64px + env(safe-area-inset-bottom) + var(--s6)); }
  body.has-co .tabbar { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    background: var(--rail); border-top: 1px solid rgba(255, 255, 255, .14); padding-bottom: env(safe-area-inset-bottom); }
  .tabbar button { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    min-height: 60px; border: 0; background: none; color: var(--rail-ink-2); font-size: 11px; cursor: pointer; padding: 6px 2px; }
  .tabbar button .ic { font-size: 22px; }
  .tabbar button[aria-current=page] { color: #fff; font-weight: 600; box-shadow: inset 0 3px 0 #fff; }
  .tabbar .dot { position: absolute; top: 9px; left: 50%; margin-left: 9px; width: 8px; height: 8px; border-radius: 50%; background: #f0c060; }
  .tabbar .dot.bad { background: #ff6b63; }
  body.has-co .toasts { bottom: calc(72px + env(safe-area-inset-bottom)); left: var(--s4); right: var(--s4); }

  /* touch targets */
  .btn, .btn.sm, .input, select.input, .tab, .check { min-height: 44px; }
  .btn.icon, .btn.sm.icon { width: 44px; }
  .check input { width: 20px; height: 20px; }
  .input, select.input, input[type=number].input { font-size: 16px; }      /* stops iOS zooming into a field */
  input[type=number].input { width: 104px; }
  .ledger td select.input { width: 100%; min-width: 132px; }
  .ledger td .input.wide { min-width: 168px; }                  /* text boxes in a table keep a usable width; the table scrolls */
  .ledger td input[type=date].input { min-width: 150px; }
  .card { padding: var(--s4); }
  .title { font-size: var(--fs-20); }
  .input.wide, .search, .search .input { width: 100%; }
  .co-grid, .item-grid { grid-template-columns: minmax(0, 1fr); }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat b { font-size: var(--fs-20); overflow-wrap: anywhere; }
  .timeline { padding-left: var(--s4); }
  .timeline li { grid-template-columns: auto minmax(0, 1fr); }
  .timeline li > .row, .timeline .facts { grid-column: 1 / -1; }
  .modal-actions .btn { flex: 1 1 100%; }

  /* tables: scroll inside the box, first column stays */
  .table-wrap { -webkit-overflow-scrolling: touch; }
  .ledger th:first-child, .ledger td:first-child { position: sticky; left: 0; z-index: 2; background: var(--sheet);
    box-shadow: 1px 0 0 var(--line); }
  .ledger th:first-child { z-index: 3; background: var(--sheet-2); }
  .ledger th, .ledger td { padding-left: var(--s2); padding-right: var(--s2); }

  /* primary action: docked just above the bottom bar, opaque, part of the page */
  .actionbar { position: sticky; bottom: calc(60px + env(safe-area-inset-bottom)); z-index: 5; background: var(--paper);
    border: 0; border-top: 1px solid var(--rule); border-radius: 0; box-shadow: none; margin: 0 calc(-1 * var(--s4));
    padding: var(--s3) var(--s4); }
  .actionbar .hint { flex: 1 1 100%; order: 3; }
  body:not(.has-co) .actionbar { bottom: 0; }
  .chart-tip { min-height: 40px; }
}
@media (max-width: 899px) and (max-height: 520px) { .actionbar { position: static; } }
