/* ============================================================
   BSB design system — component layer (redesign stage A, 2026-09-28)

   The spec is the Claude Design canvas: STYLE.md + the component
   sheets P3-1-Components-Light/Dark. Every value here comes from a
   token in /css/tokens.css, so light and dark need no per-component
   overrides. Usage snippets: docs/DESIGN-SYSTEM.md. The Blade
   components in resources/views/components/ emit this markup.

   Namespace: every class is .ui-*. The older component classes
   (.btn, .pill, .tbl, .mcards, .alert, .chip, .segmented …) keep
   working for the pages that have not been rebuilt yet; nothing
   here changes them.

   Loaded by tenant.layouts._component-foundation, i.e. on every
   console and member-app page, after styles.css / admin.css /
   tokens.css and before each page's @stack('styles').

   Phone breakpoint: 760px (tables become card lists, buttons grow
   to 48px, the page head stacks).
   ============================================================ */

/* ---------- Primitives ---------- */
.ui-num, .ui-tabular { font-variant-numeric: tabular-nums; }
.ui-serif { font-family: var(--serif); }
.ui-eyebrow {
  font-size: var(--fs-micro); font-weight: 700; letter-spacing: 1.6px;
  text-transform: uppercase; color: var(--gold-text); line-height: 1.3;
}
.ui-meta { font-size: var(--fs-meta); color: var(--ink-2); }
.ui-sr {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.ui-icon { display: block; flex: 0 0 auto; }
@media (max-width: 760px) { .ui-only-desktop { display: none !important; } }
@media (min-width: 761px) { .ui-only-phone { display: none !important; } }

/* Keyboard focus, one look everywhere. */
.ui-btn:focus-visible, .ui-iconbtn:focus-visible, .ui-chip:focus-visible,
.ui-seg-item:focus-visible, .ui-row:focus-visible, .ui-menu-item:focus-visible,
.ui-kicker a:focus-visible, .ui-how > summary:focus-visible, .ui-sheet-row:focus-visible,
.ui-stepper-btn:focus-visible, a.ui-kpi:focus-visible {
  outline: 2px solid var(--burgundy-text); outline-offset: 2px;
}

/* ---------- Panel ---------- */
.ui-panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm); box-sizing: border-box; overflow: hidden;
}
.ui-panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 18px 22px; border-bottom: 1px solid var(--line);
}
.ui-panel-title {
  font-family: var(--serif); font-size: var(--fs-panel); font-weight: 500; line-height: 1.25;
  color: var(--ink); margin: 0;
}
.ui-panel-link {
  display: inline-flex; align-items: center; gap: 4px; font-size: 13.5px; font-weight: 600;
  color: var(--burgundy-text); text-decoration: none; white-space: nowrap;
}
.ui-panel-body { padding: 22px; }
.ui-well { background: var(--surface-2); border-radius: var(--r-md); padding: 14px 16px; }
@media (max-width: 760px) {
  .ui-panel-head { padding: 16px; }
  .ui-panel-body { padding: 16px; }
}

/* ---------- Buttons (STYLE §9) ----------
   .ui-btn is desktop M (40px) and grows to phone L (48px) below 760px.
   --l is L everywhere, --s is the dense-row size (44px floor on phone).
   One primary per view. */
.ui-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: var(--r-btn);
  font-family: inherit; font-size: 14px; font-weight: 600; line-height: 1;
  white-space: nowrap; box-sizing: border-box; cursor: pointer; margin: 0;
  text-decoration: none; border: 1px solid transparent;
  background: var(--btn-secondary-bg); color: var(--ink);
  transition: background .15s, border-color .15s, box-shadow .15s;
}
.ui-btn .ui-icon { width: 16px; height: 16px; }
.ui-btn--l { height: 48px; padding: 0 20px; border-radius: 14px; font-size: 15px; gap: 9px; }
.ui-btn--l .ui-icon { width: 18px; height: 18px; }
.ui-btn--s { height: 34px; padding: 0 12px; border-radius: 10px; font-size: 13px; gap: 6px; }
.ui-btn--s .ui-icon { width: 15px; height: 15px; }
.ui-btn--block { width: 100%; }
@media (max-width: 760px) {
  .ui-btn:not(.ui-btn--s) { height: 48px; padding: 0 20px; border-radius: 14px; font-size: 15px; gap: 9px; }
  .ui-btn:not(.ui-btn--s) .ui-icon { width: 18px; height: 18px; }
  .ui-btn--s { height: 44px; }
}
.ui-btn--primary {
  background: var(--burgundy); color: var(--on-fill); border-color: var(--burgundy);
  box-shadow: 0 1px 2px rgba(60,34,28,0.12), inset 0 0 0 1px rgba(168,129,78,0.30);
}
.ui-btn--primary:hover { background: var(--burgundy-deep); border-color: var(--burgundy-deep); color: var(--on-fill); }
.ui-btn--secondary {
  background: var(--btn-secondary-bg); color: var(--ink); border-color: var(--line-input);
  box-shadow: var(--shadow-sm);
}
.ui-btn--secondary:hover { background: var(--surface-2); color: var(--ink); }
.ui-btn--soft { background: var(--btn-soft-bg); color: var(--ink); border-color: transparent; }
.ui-btn--soft:hover { border-color: var(--line); color: var(--ink); }
.ui-btn--ghost { background: transparent; color: var(--burgundy-text); border-color: transparent; }
.ui-btn--ghost:hover, .ui-btn--ghost[aria-expanded="true"] { background: var(--surface-2); color: var(--burgundy-text); }
.ui-btn--danger { background: var(--surface); color: var(--burgundy-text); border-color: var(--burgundy-text); }
.ui-btn--danger:hover { background: var(--burgundy-wash); color: var(--burgundy-text); }
/* Inside a confirm dialog only — the action that actually destroys. */
.ui-btn--confirm { background: var(--burgundy-deep); color: var(--on-fill); border-color: var(--burgundy-deep); }
.ui-btn--confirm:hover { filter: brightness(1.08); color: var(--on-fill); }
.ui-btn:disabled, .ui-btn[aria-disabled="true"], .ui-btn.is-disabled {
  opacity: .45; cursor: not-allowed; pointer-events: none;
}

/* Icon button, 44px (STYLE §9 "Icon 44"). --40 is the desktop top-bar size. */
.ui-iconbtn {
  width: 44px; height: 44px; border-radius: var(--r-sm); border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm);
  display: inline-grid; place-items: center; box-sizing: border-box; padding: 0; margin: 0;
  cursor: pointer; flex: 0 0 auto; font-family: inherit; text-decoration: none;
}
.ui-iconbtn .ui-icon { width: 20px; height: 20px; }
.ui-iconbtn:hover { background: var(--surface-2); color: var(--ink); }
.ui-iconbtn--40 { width: 40px; height: 40px; border-radius: var(--r-btn); }
.ui-iconbtn--40 .ui-icon { width: 18px; height: 18px; }
.ui-iconbtn--menu { background: var(--burgundy-wash); border-color: var(--dashed); color: var(--burgundy-text); }
.ui-iconbtn--48 { width: 48px; height: 48px; border-radius: 14px; }

/* ---------- Form fields (STYLE §10) ---------- */
.ui-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.ui-label { font-size: 13.5px; font-weight: 600; color: var(--ink); }
.ui-req { color: var(--burgundy-text); }
.ui-input {
  height: 44px; padding: 0 14px; border-radius: var(--r-sm); border: 1px solid var(--line-input);
  background: var(--input-bg); font-family: inherit; font-size: 14.5px; color: var(--ink);
  box-sizing: border-box; width: 100%; margin: 0;
}
textarea.ui-input { height: auto; min-height: 96px; padding: 12px 14px; line-height: 1.5; resize: vertical; }
.ui-input::placeholder { color: var(--ink-2); opacity: 1; }
.ui-input:focus { outline: none; border-color: var(--burgundy-text); box-shadow: 0 0 0 3px var(--focus-ring); }
.ui-input[aria-invalid="true"], .ui-input.is-invalid { border-color: var(--burgundy-text); box-shadow: 0 0 0 3px var(--error-ring); }
@media (max-width: 760px) {
  .ui-input { height: 48px; font-size: 16px; }   /* 16px stops iOS zooming */
  textarea.ui-input { height: auto; }
}
.ui-hint { font-size: 13px; color: var(--ink-2); line-height: 1.4; }
.ui-error {
  display: flex; gap: 6px; align-items: center; font-size: 13px; font-weight: 600;
  color: var(--burgundy-text); line-height: 1.4;
}
.ui-error .ui-icon { width: 14px; height: 14px; }
.ui-select { position: relative; min-width: 0; }
.ui-select select.ui-input {
  appearance: none; -webkit-appearance: none; -moz-appearance: none;
  padding-right: 40px; cursor: pointer; background-image: none;
}
.ui-select-chev {
  position: absolute; right: 14px; top: 50%; margin-top: -9px; width: 18px; height: 18px;
  pointer-events: none; color: var(--burgundy-text);
}

/* Switch — a real checkbox (form-native), drawn as STYLE's 46×28 toggle. */
.ui-toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 44px; }
.ui-toggle-text { min-width: 0; cursor: pointer; }
.ui-toggle-title { display: block; font-size: var(--fs-body); font-weight: 600; color: var(--ink); line-height: 1.35; }
.ui-toggle-sub { display: block; font-size: 13px; color: var(--ink-2); line-height: 1.4; }
.ui-switch { position: relative; display: inline-block; width: 46px; height: 28px; flex: 0 0 auto; cursor: pointer; }
.ui-switch input {
  position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; z-index: 1;
}
.ui-switch-track {
  position: absolute; inset: 0; border-radius: var(--r-pill); background: var(--toggle-off);
  transition: background .18s;
}
.ui-switch-track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: var(--toggle-knob); box-shadow: 0 1px 2px rgba(0,0,0,0.25); transition: transform .18s;
}
.ui-switch input:checked + .ui-switch-track { background: var(--burgundy); }
.ui-switch input:checked + .ui-switch-track::after { transform: translateX(18px); }
.ui-switch input:focus-visible + .ui-switch-track { outline: 2px solid var(--burgundy-text); outline-offset: 2px; }
.ui-switch input:disabled + .ui-switch-track { opacity: .45; }
@media (prefers-reduced-motion: reduce) {
  .ui-switch-track, .ui-switch-track::after { transition: none; }
}

.ui-check {
  display: flex; align-items: center; gap: 12px; min-height: 44px; font-size: var(--fs-body);
  color: var(--ink); cursor: pointer;
}
.ui-check input[type="checkbox"], .ui-check input[type="radio"] {
  width: 20px; height: 20px; margin: 0; flex: 0 0 auto; accent-color: var(--burgundy);
}

.ui-dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 24px;
  border: 1.5px dashed var(--dashed); border-radius: var(--r-md); background: var(--surface-2);
  text-align: center; box-sizing: border-box; position: relative;
}
.ui-dropzone.is-dragover { border-color: var(--burgundy-text); background: var(--burgundy-wash); }
.ui-dropzone .ui-icontile { width: 44px; height: 44px; border-radius: var(--r-sm); }
.ui-dropzone .ui-icontile .ui-icon { width: 22px; height: 22px; }
.ui-dropzone-title { font-size: 15px; font-weight: 600; color: var(--ink); }
.ui-dropzone-hint { font-size: 13px; color: var(--ink-2); margin-top: -6px; }
.ui-dropzone-file { font-size: 13px; font-weight: 600; color: var(--ink); overflow-wrap: anywhere; }
.ui-dropzone input[type="file"] { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
/* The invisible input is the tab stop; its visible "Choose file" label shows the focus. */
.ui-dropzone input[type="file"]:focus-visible + label { outline: 2px solid var(--burgundy-text); outline-offset: 2px; }

.ui-stepper {
  display: inline-flex; align-items: stretch; border: 1px solid var(--line-input); border-radius: var(--r-sm);
  overflow: hidden; background: var(--input-bg); flex: 0 0 auto;
}
.ui-stepper-btn {
  width: 44px; height: 46px; border: 0; background: transparent; color: var(--burgundy-text);
  display: grid; place-items: center; margin: 0; padding: 0; cursor: pointer; font-family: inherit;
}
.ui-stepper-btn .ui-icon { width: 20px; height: 20px; }
.ui-stepper-btn:disabled { opacity: .45; cursor: not-allowed; }
.ui-stepper-val {
  width: 48px; min-width: 48px; border: 0; border-left: 1px solid var(--line); border-right: 1px solid var(--line);
  background: transparent; text-align: center; font-family: inherit; font-size: 16px; font-weight: 700;
  color: var(--ink); font-variant-numeric: tabular-nums; margin: 0; padding: 0; -moz-appearance: textfield; appearance: textfield;
}
.ui-stepper-val::-webkit-outer-spin-button, .ui-stepper-val::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.ui-stepper-val:focus { outline: none; background: var(--surface-2); }

/* ---------- Sticky save bar (STYLE §19) ----------
   Hidden until the form it watches changes (public/js/ui.js). Desktop:
   a floating bar at the bottom of the content column. Phone: full-bleed
   at the bottom edge. */
.ui-savebar {
  position: sticky; bottom: 16px; z-index: 45; max-width: 1184px; margin: 16px auto 0;
  display: flex; align-items: center; gap: 12px; box-sizing: border-box;
  padding: 12px 16px 12px 20px; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-md); box-shadow: var(--shadow-lg);
}
.ui-savebar[hidden] { display: none; }
.ui-savebar-text { flex: 1; min-width: 0; font-size: 13.5px; color: var(--ink-2); }
@media (max-width: 760px) {
  .ui-savebar {
    position: fixed; left: 0; right: 0; bottom: 0; max-width: none; margin: 0;
    border-radius: 0; border: 0; border-top: 1px solid var(--line); box-shadow: var(--shadow-save);
    padding: 12px 16px calc(16px + env(safe-area-inset-bottom));
  }
  .ui-savebar .ui-savebar-discard { display: none; }
}

/* ---------- Segmented control (STYLE §11) ---------- */
.ui-seg {
  display: inline-flex; padding: 3px; gap: 2px; border-radius: var(--r-pill);
  background: var(--seg-bg); border: 1px solid var(--line); box-sizing: border-box; max-width: 100%;
}
.ui-seg--block { display: flex; width: 100%; }
.ui-seg-item {
  display: inline-flex; align-items: center; justify-content: center;
  height: 38px; padding: 0 16px; border-radius: var(--r-pill); border: 0; background: transparent;
  font-family: inherit; font-size: 13.5px; font-weight: 600; color: var(--burgundy-text);
  white-space: nowrap; cursor: pointer; margin: 0; box-sizing: border-box; text-decoration: none;
}
.ui-seg--block .ui-seg-item { flex: 1 1 0; min-width: 0; }
.ui-seg-item[aria-pressed="true"], .ui-seg-item[aria-current="page"], .ui-seg-item[aria-checked="true"], .ui-seg-item.is-on,
.ui-seg-item:has(input:checked) {
  background: var(--burgundy); color: var(--on-fill); box-shadow: var(--shadow-sm);
}
/* Radio-backed items (a form choice): the input is visually hidden, the
   label carries the focus ring. */
label.ui-seg-item { position: relative; }
.ui-seg-item:has(input:focus-visible) { outline: 2px solid var(--burgundy-text); outline-offset: 2px; }
@media (max-width: 760px) { .ui-seg-item { height: 44px; } }

/* ---------- Filter chips with counts (STYLE §12) ---------- */
.ui-chips { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
@media (max-width: 760px) {
  /* One row that scrolls sideways; the last chip is cut at the edge. */
  .ui-chips {
    flex-wrap: nowrap; overflow-x: auto; margin: 0 -16px; padding: 0 16px 2px;
    scrollbar-width: none; -webkit-overflow-scrolling: touch;
  }
  .ui-chips::-webkit-scrollbar { display: none; }
}
.ui-chip {
  display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 14px;
  border-radius: var(--r-pill); border: 1px solid var(--line-input); background: var(--surface);
  font-family: inherit; font-size: 13.5px; font-weight: 600; color: var(--ink);
  white-space: nowrap; box-sizing: border-box; margin: 0; cursor: pointer; flex: 0 0 auto; text-decoration: none;
}
.ui-chip:has(.ui-cnt) { padding: 0 12px 0 14px; }
.ui-chip:hover { border-color: var(--burgundy-text); color: var(--ink); }
.ui-chip[aria-pressed="true"], .ui-chip[aria-current="page"], .ui-chip.is-on {
  background: var(--burgundy); border-color: var(--burgundy); color: var(--on-fill);
}
@media (max-width: 760px) { .ui-chip { height: 44px; } }
.ui-cnt {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px;
  box-sizing: border-box; border-radius: var(--r-pill); background: var(--surface-3); color: var(--ink-2);
  font-size: 11.5px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums;
}
.ui-cnt--active { background: var(--burgundy-tint-strong); color: var(--burgundy-text); }
.ui-chip[aria-pressed="true"] .ui-cnt, .ui-chip[aria-current="page"] .ui-cnt, .ui-chip.is-on .ui-cnt {
  background: rgba(255,255,255,0.22); color: var(--on-fill);
}

/* ---------- Status pills (STYLE §13) — heritage palette only ---------- */
.ui-pill {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px;
  border-radius: var(--r-pill); font-size: 12px; font-weight: 700; white-space: nowrap;
  box-sizing: border-box; line-height: 1; flex: 0 0 auto; font-variant-numeric: tabular-nums;
  background: var(--surface-3); color: var(--ink-2);
}
.ui-pill .ui-icon { width: 12px; height: 12px; }
.ui-pill-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: 0 0 auto; }
.ui-pill-hollow { width: 7px; height: 7px; border-radius: 50%; border: 1.5px solid currentColor; box-sizing: border-box; flex: 0 0 auto; }
.ui-pill--paid, .ui-pill--credit, .ui-pill--in { background: var(--sage-bg); color: var(--sage-text); }
.ui-pill--owes, .ui-pill--out { background: var(--burgundy-tint-strong); color: var(--burgundy-text); }
.ui-pill--notdue, .ui-pill--neutral { background: var(--surface-3); color: var(--ink-2); }
.ui-pill--waived { background: transparent; border: 1px solid var(--line-strong); color: var(--ink-2); }
.ui-pill--pending { background: var(--gold-tint); color: var(--gold-text); }
.ui-pill--offline { background: transparent; border: 1px solid var(--ink-2); color: var(--ink); }
/* Event stage tags: same shape, 8px corners, flag icon, no dot. */
.ui-pill--stage { border-radius: var(--r-xs); background: var(--gold-tint); color: var(--gold-text); }
.ui-pill--stage-open { border-radius: var(--r-xs); background: var(--sage-bg); color: var(--sage-text); }
.ui-pill--stage-plan { border-radius: var(--r-xs); background: var(--surface-3); color: var(--ink-2); }

/* ---------- Money (STYLE §0) ----------
   Tabular sans, never monospace. Ledgers colour every row by
   direction; statements colour only results and negatives. */
.ui-money { font-variant-numeric: tabular-nums; white-space: nowrap; }
.ui-money--in { color: var(--sage-text); }
.ui-money--out { color: var(--burgundy-text); }
.ui-money--zero { color: var(--ink-2); }

/* ---------- Table → cards (STYLE §14) ----------
   Column roles: title / meta / amount / status / action. Render the
   same rows twice — .ui-tbl-panel (desktop) and .ui-mcards (phone) —
   and the breakpoint picks one. Nothing scrolls sideways at 390. */
.ui-tbl { width: 100%; border-collapse: collapse; }
.ui-tbl th {
  text-align: left; font-size: var(--fs-micro); font-weight: 700; letter-spacing: 1px;
  text-transform: uppercase; color: var(--ink-2); padding: 12px 16px;
  border-bottom: 1px solid var(--line); white-space: nowrap; background: transparent;
}
.ui-tbl td {
  padding: 14px 16px; font-size: var(--fs-body); color: var(--ink); border-bottom: 1px solid var(--line-2);
  vertical-align: middle;
}
.ui-tbl th:first-child, .ui-tbl td:first-child { padding-left: 22px; }
.ui-tbl th:last-child, .ui-tbl td:last-child { padding-right: 22px; }
.ui-tbl tbody tr:last-child td { border-bottom: 0; }
.ui-tbl tbody tr:hover { background: var(--surface-2); }
.ui-tbl tr[data-href] { cursor: pointer; }
.ui-tbl .ui-col-title { font-weight: 600; }
.ui-tbl .ui-col-title a { color: inherit; text-decoration: none; }
.ui-tbl .ui-col-title a:hover { text-decoration: underline; }
.ui-sub { display: block; font-size: 13px; font-weight: 400; color: var(--ink-2); margin-top: 2px; }
.ui-tbl .ui-col-meta { font-size: 13.5px; color: var(--ink-2); }
.ui-tbl .ui-col-amount, .ui-tbl th.ui-col-amount {
  text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap;
}
.ui-tbl th.ui-col-amount { font-weight: 700; }
.ui-tbl .ui-col-action { text-align: right; width: 1%; white-space: nowrap; }
@media (max-width: 760px) { .ui-tbl-panel { display: none; } }
@media (min-width: 761px) { .ui-mcards { display: none; } }

/* Phone card list — also usable on desktop as .ui-rows. */
.ui-rows {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
  box-shadow: var(--shadow-sm); overflow: hidden;
}
.ui-row {
  display: flex; align-items: center; gap: 12px; min-height: 68px; padding: 12px 16px;
  border-bottom: 1px solid var(--line-2); text-decoration: none; color: var(--ink);
  box-sizing: border-box; background: transparent;
}
.ui-row:last-child { border-bottom: 0; }
a.ui-row:hover { background: var(--surface-2); color: var(--ink); }
.ui-row-lead { flex: 0 0 auto; display: flex; }
.ui-row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ui-row-title, .ui-row-meta { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ui-row-title { font-size: 15px; font-weight: 600; line-height: 1.35; }
.ui-row-meta { font-size: 13px; color: var(--ink-2); line-height: 1.4; }
@media (max-width: 760px) {
  /* On a phone the second line wraps rather than being cut mid-word
     ("… paid 17 Au…"); the title keeps its one line. */
  .ui-row-meta { white-space: normal; overflow: visible; text-overflow: clip; overflow-wrap: anywhere; }
}
.ui-row-value { flex: 0 0 auto; display: flex; align-items: center; font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.ui-row-chev { width: 16px; height: 16px; color: var(--ink-2); flex: 0 0 auto; }
.ui-avatar {
  width: 40px; height: 40px; border-radius: 50%; background: var(--surface-3); color: var(--ink);
  display: grid; place-items: center; font-size: 12.5px; font-weight: 700; line-height: 1; flex: 0 0 auto;
}
.ui-month-head {
  display: flex; justify-content: space-between; align-items: baseline; padding: 16px 16px 8px;
}
.ui-month-head .ui-meta { font-variant-numeric: tabular-nums; }

/* ---------- Financial rows (STYLE §15) ----------
   Band · line · subtotal · grand total. The label wraps, the amount is
   always visible, the prior year is a second right-hand column on
   desktop and a muted second line on phone. No sideways scroll. */
.ui-fin { background: var(--surface); }
.ui-fin-cols, .ui-fin-line {
  display: grid; grid-template-columns: minmax(0, 1fr) 130px; align-items: baseline;
  column-gap: 16px; padding: 11px 22px;
}
.ui-fin.has-prior .ui-fin-cols, .ui-fin.has-prior .ui-fin-line { grid-template-columns: minmax(0, 1fr) 130px 150px; }
.ui-fin-cols {
  padding-top: 10px; padding-bottom: 10px; border-bottom: 1px solid var(--line);
  font-size: var(--fs-micro); font-weight: 700; letter-spacing: 1px; text-transform: uppercase; color: var(--ink-2);
}
.ui-fin-cols > span:not(:first-child) { text-align: right; }
.ui-fin-band {
  background: var(--surface-2); padding: 8px 22px; font-size: 11.5px; font-weight: 700;
  letter-spacing: 1.2px; text-transform: uppercase; color: var(--gold-text);
}
.ui-fin-line { border-bottom: 1px solid var(--line-2); }
.ui-fin-label { min-width: 0; font-size: var(--fs-body); color: var(--ink); line-height: 1.35; overflow-wrap: anywhere; }
.ui-fin-amt {
  text-align: right; font-size: var(--fs-body); font-weight: 500; font-variant-numeric: tabular-nums;
  white-space: nowrap; color: var(--ink);
}
.ui-fin-prior {
  text-align: right; font-size: 13.5px; color: var(--ink-2); font-variant-numeric: tabular-nums; white-space: nowrap;
}
.ui-fin-prior-label { display: none; }
.ui-fin-line--sub { border-top: 1px solid var(--line-strong); border-bottom: 0; padding-top: 12px; padding-bottom: 12px; }
.ui-fin-line--sub .ui-fin-label { font-weight: 700; }
.ui-fin-line--sub .ui-fin-amt { font-size: 15px; font-weight: 700; }
.ui-fin-line--grand { border-top: 2px solid var(--burgundy-text); border-bottom: 0; padding-top: 14px; padding-bottom: 16px; }
.ui-fin-line--grand .ui-fin-label { font-family: var(--serif); font-size: 18px; font-weight: 600; line-height: 1.3; }
.ui-fin-line--grand .ui-fin-amt { font-size: 18px; font-weight: 700; }
/* Sign colour: only result lines and negative figures. */
.ui-fin-amt.is-neg { color: var(--burgundy-text); }
.ui-fin-line--sub .ui-fin-amt.is-pos, .ui-fin-line--grand .ui-fin-amt.is-pos { color: var(--sage-text); }
@media (max-width: 760px) {
  .ui-fin-cols { display: none; }
  .ui-fin-band { padding: 8px 16px; }
  .ui-fin-line, .ui-fin.has-prior .ui-fin-line { grid-template-columns: minmax(0, 1fr) auto; padding-left: 16px; padding-right: 16px; }
  .ui-fin-prior {
    grid-column: 1 / -1; display: flex; justify-content: space-between; gap: 12px;
    font-size: 13px; margin-top: 3px; text-align: left;
  }
  .ui-fin-prior-label { display: inline; }
}

/* ---------- KPI tile and strip (STYLE §16) ---------- */
.ui-kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.ui-kpis--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.ui-kpis--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 1080px) { .ui-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 760px) { .ui-kpis { gap: 12px; } }
.ui-kpi {
  display: block; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm); padding: 20px; min-width: 0; box-sizing: border-box;
  color: var(--ink); text-decoration: none;
}
a.ui-kpi:hover { border-color: var(--line-strong); color: var(--ink); }
.ui-icontile {
  width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; flex: 0 0 auto;
  background: var(--surface-3); color: var(--ink-2);
}
.ui-icontile .ui-icon { width: 20px; height: 20px; }
.ui-icontile--burg { background: var(--burgundy-tint-strong); color: var(--burgundy-text); }
.ui-icontile--gold { background: var(--gold-tint); color: var(--gold-text); }
.ui-icontile--sage { background: var(--sage-bg); color: var(--sage-text); }
.ui-icontile--neutral { background: var(--surface-3); color: var(--ink-2); }
.ui-kpi-value {
  font-family: var(--serif); font-size: var(--fs-hero); font-weight: 600; line-height: 1; margin-top: 14px;
  color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap;
}
.ui-kpi-label { font-size: 13px; font-weight: 500; color: var(--ink-2); margin-top: 8px; line-height: 1.35; }
.ui-kpi-foot { font-size: 12.5px; font-weight: 600; margin-top: 10px; color: var(--ink-2); }
.ui-tone-burg { color: var(--burgundy-text); }
.ui-tone-gold { color: var(--gold-text); }
.ui-tone-sage { color: var(--sage-text); }
.ui-tone-neutral { color: var(--ink-2); }
@media (max-width: 760px) { .ui-kpi { padding: 16px; } }
/* Compact tile: label first, no icon. */
.ui-kpi--compact { padding: 14px 16px; border-radius: var(--r-md); }
.ui-kpi--compact .ui-kpi-label { font-size: 12.5px; font-weight: 600; margin-top: 0; }
.ui-kpi--compact .ui-kpi-value { font-size: 22px; line-height: 1.1; margin-top: 4px; }
/* Phone strip: one panel, N cells. */
.ui-kpi-strip {
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: var(--shadow-sm);
}
.ui-kpi-strip-cell { padding: 12px 14px; min-width: 0; color: var(--ink); text-decoration: none; }
.ui-kpi-strip-cell + .ui-kpi-strip-cell { border-left: 1px solid var(--line); }
.ui-kpi-strip-label { font-size: 12px; font-weight: 600; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ui-kpi-strip-value {
  font-family: var(--serif); font-size: 20px; font-weight: 600; line-height: 1.15; margin-top: 2px;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
/* All-zero collapse: one line, never a row of $0 tiles. */
.ui-allclear {
  display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 0 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: var(--shadow-sm);
  font-size: 14px; font-weight: 600; color: var(--ink); box-sizing: border-box;
}
.ui-allclear .ui-icon { width: 20px; height: 20px; color: var(--sage-text); }

/* ---------- Empty state (STYLE §17) ---------- */
.ui-empty {
  display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center;
  padding: 40px 24px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm); box-sizing: border-box;
}
.ui-empty-icon {
  width: 52px; height: 52px; border-radius: var(--r-md); background: var(--surface-2); color: var(--ink-2);
  display: grid; place-items: center;
}
.ui-empty-icon .ui-icon { width: 24px; height: 24px; }
.ui-empty-title { font-family: var(--serif); font-size: 19px; font-weight: 500; line-height: 1.3; color: var(--ink); margin: 6px 0 0; }
.ui-empty-line { font-size: 14px; color: var(--ink-2); max-width: 380px; line-height: 1.5; margin: 0; }
.ui-empty-action { margin-top: 8px; }
@media (max-width: 760px) { .ui-empty { padding: 32px 20px; } }
/* Honest variant: says what is missing, inline, not a hero. */
.ui-honest {
  display: flex; gap: 14px; align-items: flex-start; padding: 16px 18px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: var(--shadow-sm);
}
.ui-honest .ui-icontile { width: 40px; height: 40px; border-radius: var(--r-sm); }
.ui-honest-body { flex: 1; min-width: 0; }
.ui-honest-title { font-size: var(--fs-body); font-weight: 600; color: var(--ink); line-height: 1.35; }
.ui-honest-line { font-size: 13px; color: var(--ink-2); margin-top: 8px; line-height: 1.45; }
.ui-honest-action { flex: 0 0 auto; }
.ui-progress { height: 6px; border-radius: var(--r-pill); background: var(--surface-3); overflow: hidden; margin-top: 8px; }
.ui-progress-fill { height: 100%; background: var(--burgundy); border-radius: inherit; }
@media (max-width: 760px) {
  .ui-honest { flex-wrap: wrap; padding: 16px; }
  .ui-honest-action { flex: 1 1 100%; }
  .ui-honest-action .ui-btn { width: 100%; }
}

/* ---------- Alerts + "How this works" (STYLE §18) ---------- */
.ui-alert {
  display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-radius: var(--r-md);
  border: 1px solid var(--line); background: var(--surface-2); font-size: 14px; line-height: 1.45;
  color: var(--ink); box-sizing: border-box;
}
.ui-alert-icon { width: 20px; height: 20px; flex: 0 0 auto; margin-top: 1px; color: var(--gold-text); }
.ui-alert-main { min-width: 0; }
.ui-alert-title { display: block; font-weight: 700; }
.ui-alert a { color: var(--ink); font-weight: 700; text-decoration: underline; }
.ui-alert--info { background: var(--surface-2); border-color: var(--line); }
.ui-alert--warning { background: var(--gold-tint); border-color: var(--gold-border); }
.ui-alert--warning .ui-alert-icon { color: var(--gold-text); }
.ui-alert--error { background: var(--burgundy-wash); border-color: var(--error-border); }
.ui-alert--error .ui-alert-icon, .ui-alert--error .ui-alert-title { color: var(--burgundy-text); }
.ui-alert--success { background: var(--sage-bg); border-color: var(--sage-border); }
.ui-alert--success .ui-alert-icon { color: var(--sage-text); }
.ui-how { border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); }
.ui-how > summary {
  display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 0 16px;
  font-size: 14px; font-weight: 600; color: var(--burgundy-text); cursor: pointer; list-style: none;
}
.ui-how > summary::-webkit-details-marker { display: none; }
.ui-how > summary .ui-icon { width: 16px; height: 16px; }
.ui-how-chev { margin-left: auto; transition: transform .15s; }
.ui-how[open] .ui-how-chev { transform: rotate(180deg); }
.ui-how-body { padding: 0 16px 14px 42px; font-size: 13.5px; color: var(--ink-2); line-height: 1.55; }
.ui-how-body > :first-child { margin-top: 0; }
.ui-how-body > :last-child { margin-bottom: 0; }

/* ---------- Page head (STYLE §8) ---------- */
.ui-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 26px; }
.ui-head-main { display: flex; flex-direction: column; min-width: 0; }
.ui-kicker {
  display: flex; align-items: center; gap: 6px; min-height: 28px; font-size: 13px; font-weight: 600;
  color: var(--ink-2); flex-wrap: wrap;
}
.ui-kicker a {
  display: inline-flex; align-items: center; gap: 4px; min-height: 28px; color: var(--ink-2); text-decoration: none;
}
.ui-kicker a:hover { color: var(--burgundy-text); }
.ui-kicker .ui-icon { width: 14px; height: 14px; }
.ui-kicker-sep { font-weight: 500; }
.ui-title {
  font-family: var(--serif); font-size: var(--fs-page); font-weight: 500; line-height: 1.15;
  letter-spacing: -0.01em; color: var(--ink); margin: 0; overflow-wrap: anywhere;
}
.ui-subtitle { font-size: 14px; color: var(--ink-2); margin: 6px 0 0; line-height: 1.45; }
.ui-head-actions { display: flex; gap: 10px; align-items: center; flex: 0 0 auto; }
div.ui-head-primary, div.ui-head-secondary { display: flex; gap: 10px; }
.ui-fy { width: 150px; flex: 0 0 auto; }
.ui-fy select.ui-input { height: 40px; font-size: 14px; font-weight: 600; }
@media (max-width: 760px) {
  .ui-head { flex-direction: column; align-items: stretch; gap: 14px; margin-bottom: 20px; }
  .ui-kicker, .ui-kicker a { min-height: 44px; }
  .ui-subtitle { font-size: 13.5px; }
  .ui-head-actions { flex-wrap: wrap; }
  .ui-head-actions .ui-fy { flex: 1 1 100%; width: auto; }
  .ui-head-actions .ui-fy select.ui-input { height: 48px; font-size: 16px; }
  .ui-head-actions .ui-head-primary { flex: 1 1 0; min-width: 0; }
  .ui-head-actions div.ui-head-primary > * { flex: 1 1 auto; width: 100%; }
  .ui-head-actions .ui-head-secondary { display: none; }   /* it moves into ⋯ More */
  .ui-head-actions .ui-more-label { display: none; }       /* ⋯ becomes a 48px icon button */
  .ui-head-actions .ui-more > .ui-btn { width: 48px; padding: 0; }
  /* …boxed like every other 48px icon button (.ui-iconbtn--48), as the canvas draws it. */
  .ui-head-actions .ui-more > .ui-btn--ghost {
    border-radius: 14px; border-color: var(--line); background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm);
  }
  /* …and it still answers a press and shows its menu is open (the rule above outranks .ui-btn--ghost's own). */
  .ui-head-actions .ui-more > .ui-btn--ghost:hover,
  .ui-head-actions .ui-more > .ui-btn--ghost[aria-expanded="true"] { background: var(--surface-2); }
}

/* ---------- "⋯ More" menu ---------- */
.ui-more { position: relative; flex: 0 0 auto; display: inline-flex; }
.ui-menu {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 60; width: 264px; max-width: calc(100vw - 32px);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
  box-shadow: var(--shadow-lg); padding: 6px; box-sizing: border-box;
}
.ui-menu[hidden] { display: none; }
.ui-menu--left { right: auto; left: 0; }
/* No room below its button on the screen: above it, or scrolling inside
   itself when neither side has room (public/js/ui.js placeMenu). */
.ui-menu--up { top: auto; bottom: calc(100% + 8px); }
.ui-menu--scroll { overflow-y: auto; overscroll-behavior: contain; }
.ui-menu-item {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 44px; padding: 0 12px;
  border-radius: var(--r-sm); border: 0; background: transparent; font-family: inherit;
  font-size: 14px; font-weight: 600; color: var(--ink); text-decoration: none; text-align: left;
  box-sizing: border-box; cursor: pointer; margin: 0;
}
.ui-menu-item .ui-icon { width: 18px; height: 18px; color: var(--ink-2); }
.ui-menu-item:hover { background: var(--surface-2); color: var(--ink); }
.ui-menu-item--danger, .ui-menu-item--danger .ui-icon { color: var(--burgundy-text); }
.ui-menu-item--danger:hover { color: var(--burgundy-text); }
.ui-menu-sep { height: 1px; background: var(--line-2); margin: 6px 4px; }
.ui-menu form { margin: 0; }

/* ---------- Sheet: bottom sheet on phone, side sheet on desktop (STYLE §20) ---------- */
.ui-sheet {
  border: 0; padding: 0; margin: 0; max-width: none; max-height: none; color: var(--ink);
  background: var(--surface); box-sizing: border-box; overflow: auto;
  position: fixed; top: 0; right: 0; bottom: 0; left: auto; width: min(440px, 100vw); height: 100%;
  border-left: 1px solid var(--line); box-shadow: var(--shadow-lg);
}
.ui-sheet:not([open]) { display: none; }
.ui-sheet::backdrop { background: var(--scrim); }
.ui-sheet-inner { display: flex; flex-direction: column; min-height: 100%; padding: 16px 22px 24px; box-sizing: border-box; }
.ui-sheet-grabber { display: none; width: 36px; height: 4px; border-radius: 2px; background: var(--grabber); margin: 0 auto 10px; }
.ui-sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.ui-sheet-title { font-family: var(--serif); font-size: 19px; font-weight: 500; line-height: 1.3; color: var(--ink); margin: 0; }
.ui-sheet-body { display: flex; flex-direction: column; gap: 14px; margin-top: 10px; flex: 1 1 auto; }
.ui-sheet-foot { display: flex; gap: 10px; margin-top: 20px; }
.ui-sheet-foot .ui-btn--primary { flex: 1 1 auto; }
.ui-sheet-group { padding: 14px 4px 6px; }
.ui-sheet-row {
  display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 0 12px; border-radius: var(--r-sm);
  font-size: 15px; font-weight: 600; color: var(--ink); text-decoration: none;
}
.ui-sheet-row:hover { background: var(--surface-2); color: var(--ink); }
.ui-sheet-row[aria-current="page"] { background: var(--burgundy-tint); color: var(--burgundy-text); }
.ui-sheet-row .ui-cnt { margin-left: auto; }
@media (max-width: 760px) {
  .ui-sheet {
    top: auto; left: 0; right: 0; bottom: 0; width: 100%; height: auto; max-height: 92vh;
    border-left: 0; border-radius: var(--r-xl) var(--r-xl) 0 0; box-shadow: var(--shadow-sheet);
  }
  .ui-sheet-inner { min-height: 0; padding: 8px 16px calc(24px + env(safe-area-inset-bottom)); }
  .ui-sheet-grabber { display: block; }
}
body.ui-sheet-open { overflow: hidden; }

/* ---------- Toast (STYLE §21) ---------- */
.ui-toasts {
  position: fixed; left: 16px; right: 16px; bottom: 16px; z-index: 90;
  display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none;
}
.ui-toast {
  display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 0 8px 0 16px; width: 100%; max-width: 420px;
  border-radius: 14px; background: var(--toast-bg); color: var(--toast-ink); box-shadow: var(--shadow-lg);
  font-size: 14px; font-weight: 600; box-sizing: border-box; pointer-events: auto;
}
.ui-toast .ui-icon { width: 20px; height: 20px; color: var(--toast-icon); }
.ui-toast-text { flex: 1; min-width: 0; line-height: 1.35; padding: 8px 0; }
.ui-toast-action {
  height: 44px; padding: 0 12px; border: 0; background: transparent; color: var(--toast-action);
  font-family: inherit; font-size: 14px; font-weight: 700; margin: 0; cursor: pointer; border-radius: 10px;
  text-decoration: none; display: inline-flex; align-items: center;
}
.ui-toast-action:hover { color: var(--toast-action); background: rgba(255,255,255,0.06); }
@media (max-width: 760px) { .ui-toasts { bottom: 96px; } }   /* above the tab bar / save bar */

/* ---------- Cellar sync strip (component sheet §9) ---------- */
.ui-sync {
  height: 36px; display: flex; align-items: center; gap: 8px; padding: 0 16px; background: var(--surface-2);
  color: var(--ink); font-size: 13.5px; font-weight: 600; box-sizing: border-box; white-space: nowrap;
}
.ui-sync--offline { background: var(--surface-3); }
.ui-sync-dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; background: var(--sage); }
.ui-sync--offline .ui-sync-dot { background: transparent; border: 2px solid var(--ink-2); box-sizing: border-box; }
.ui-sync--syncing .ui-sync-dot { background: var(--gold); }
.ui-sync-sub { font-size: 13px; font-weight: 500; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; }

/* ---------- Print: controls and overlays never print ---------- */
@media print {
  .ui-savebar, .ui-toasts, .ui-sheet, .ui-menu, .ui-more, .ui-head-actions { display: none !important; }
  .ui-tbl-panel { display: block !important; }
  .ui-mcards { display: none !important; }
}
