/* FIG. 3 ledger widget (js/widgets/ledger.js). Every rule is scoped under .w-ledger and uses core tokens.
   Narrow (under 440px of widget width): the phone artboard, balance and session status side by side
   above the buckets and the ledger. Wider: the desktop artboard, a 170px balance column beside the ledger. */

.w-ledger {
  container: w-ledger / inline-size;
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.4;
}
.w-ledger p,
.w-ledger dl,
.w-ledger dd { margin: 0; }

.w-ledger .wl-vh {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
}

/* readouts */
.w-ledger .wl-grid {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-areas:
    "head session"
    "buckets buckets"
    "ledger ledger";
  column-gap: 12px;
  align-items: end;
}
.w-ledger .wl-head { grid-area: head; min-width: 0; }
.w-ledger .wl-lbl { letter-spacing: .12em; color: var(--ink-2); }
.w-ledger .wl-total {
  font-family: var(--font-narrow); font-weight: 700; font-size: 34px; line-height: 1.05;
  font-variant-numeric: tabular-nums;
}
.w-ledger .wl-session {
  grid-area: session; justify-self: end; min-width: 0; padding-bottom: 4px;
  letter-spacing: .04em; text-align: right; color: var(--ink-2);
}

.w-ledger .wl-buckets { grid-area: buckets; display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.w-ledger .wl-bucket { display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 8px; align-items: center; }
.w-ledger .wl-bucket dt { letter-spacing: .04em; }
.w-ledger .wl-bucket dd { display: grid; grid-template-columns: minmax(0, 1fr) minmax(36px, auto); gap: 8px; align-items: center; }
.w-ledger .wl-bar { position: relative; display: block; height: 8px; background: var(--hover); }
.w-ledger .wl-fill {
  position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: var(--ink);
  transition: width .3s ease;
}
.w-ledger .wl-v { text-align: right; font-variant-numeric: tabular-nums; }

/* the ledger itself */
.w-ledger .wl-ledger { grid-area: ledger; min-width: 0; margin-top: 14px; }
.w-ledger .wl-table { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: 12px; line-height: 1.3; }
.w-ledger .wl-table caption {
  padding-bottom: 6px; border-bottom: 1px solid var(--line);
  letter-spacing: .1em; text-align: left; color: var(--ink-2);
}
.w-ledger .wl-col-no { width: 48px; }
.w-ledger .wl-col-amt { width: 50px; }
.w-ledger .wl-col-b { width: 66px; }
.w-ledger .wl-table td {
  padding: 5px 6px 5px 0; border-bottom: 1px dotted var(--line);
  vertical-align: top; overflow-wrap: anywhere;
}
.w-ledger .wl-table td:last-child { padding-right: 0; }
.w-ledger .wl-no,
.w-ledger .wl-note-c { color: var(--ink-2); }
.w-ledger .wl-amt { padding-right: 10px; font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
/* rows the last press appended: a static mark, no motion */
.w-ledger .wl-table tr.is-new td { background: var(--hover); }

/* controls */
.w-ledger .wl-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin-top: 14px; }
.w-ledger .wl-btn {
  min-width: 0; min-height: 44px; margin: 0; padding: 4px 2px;
  border: 1px solid var(--ink); border-radius: 0; background: transparent; color: var(--ink);
  font-family: var(--font-mono); font-size: 12px; font-weight: 600; letter-spacing: .04em; line-height: 1.2;
  touch-action: manipulation;
  transition: background-color .16s ease, color .16s ease;
}
.w-ledger .wl-btn:hover { background: var(--hover); }
.w-ledger .wl-btn:active { background: var(--ink); color: var(--sheet); }
.w-ledger .wl-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* unavailable right now: drawn dashed, like pending work on the plan, and still readable */
.w-ledger .wl-btn[aria-disabled="true"],
.w-ledger .wl-btn[aria-disabled="true"]:hover,
.w-ledger .wl-btn[aria-disabled="true"]:active {
  border-style: dashed; border-color: var(--ink-2); background: transparent; color: var(--ink-2); cursor: not-allowed;
}

.w-ledger .wl-note { margin-top: 12px; line-height: 1.5; letter-spacing: .04em; color: var(--ink-2); }

/* desktop artboard */
@container w-ledger (min-width: 440px) {
  .w-ledger .wl-grid {
    grid-template-columns: 170px minmax(0, 1fr);
    grid-template-rows: auto auto auto 1fr;
    grid-template-areas:
      "head ledger"
      "buckets ledger"
      "session ledger"
      ". ledger";
    column-gap: 18px;
    row-gap: 10px;
    align-items: start;
  }
  .w-ledger .wl-session { justify-self: start; padding-bottom: 0; text-align: left; }
  .w-ledger .wl-bucket dd { grid-template-columns: minmax(0, 1fr) minmax(32px, auto); }
  .w-ledger .wl-buckets,
  .w-ledger .wl-ledger { margin-top: 0; }
  .w-ledger .wl-col-no { width: 46px; }
  .w-ledger .wl-col-amt { width: 46px; }
}

/* motion: the bars ease to a new length unless reduced motion is asked for */
.w-ledger.is-still .wl-fill,
.w-ledger.is-still .wl-btn { transition: none; }
@media (prefers-reduced-motion: reduce) {
  .w-ledger .wl-fill,
  .w-ledger .wl-btn { transition: none; }
}

@media (forced-colors: active) {
  .w-ledger .wl-bar { outline: 1px solid CanvasText; }
  .w-ledger .wl-fill { forced-color-adjust: none; background: CanvasText; }
  .w-ledger .wl-btn[aria-disabled="true"] { border-color: GrayText; color: GrayText; }
  .w-ledger .wl-table tr.is-new td { background: Highlight; color: HighlightText; forced-color-adjust: none; }
}
