/* Your book: the sheet is the screen ("Your book as a sheet", BS59). A top bar, one slim band (this month and
   Worth a look), a cell bar, the sheet filling the rest of the height (it scrolls inside; the page does not), and a
   bottom bar with the sheet tabs and the status. Tiles, the priority list and the empty state are the shared shapes
   in `pages.css`; this file only rearranges them. Tokens only, so both themes follow. */

/* Card 15: Remove on an entry the owner added; 44 px of hit area, ink not plum (plum is never a control). */
#bookPage .tbl td.act, #bookPage .tbl th.act { text-align: right; width: 1%; white-space: nowrap; }
#bookPage .tbl .rm { color: var(--ink); font-size: 13px; min-height: 44px; min-width: 44px; padding: 0 4px; cursor: pointer; }

/* Card 17 (live check of Card 15): at 390 the Remove column made the table 450 px wide in a 358 px page.
   On the phone the cells wrap and the gaps close up, so every column, Remove included, fits without a
   sideways scroll; the figure never wraps. */
@media (max-width: 1023px) {
  #bookPage .tbl th, #bookPage .tbl td { white-space: normal; padding-right: 6px; overflow-wrap: anywhere; }
  #bookPage .tbl td.num, #bookPage .tbl th.num { white-space: nowrap; overflow-wrap: normal; }
  #bookPage .tbl td.act, #bookPage .tbl th.act { padding-right: 0; }
  #bookPage .tbl .rm { padding: 0 2px; }
}

/* ── the screen: the page is exactly the window tall and never scrolls itself ─────────────────────────────────── */
#bookPage.bk { max-width: none; margin: 0; padding: 0; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; box-sizing: border-box; }
@media (max-width: 1023px) { #bookPage.bk { height: calc(100dvh - 52px); } }
/* the Evelyst button's reserved 76 px belongs to the pages that scroll; here it sits over the bottom bar's right end, in the 96 px the status leaves free */
body.has-ask-fab #pageHost:has(#page-book:not([hidden]) #bookPage.bk) { padding-bottom: 0; }
body.has-ask-fab:has(#page-book:not([hidden]) #bookPage.bk) .ask-fab { bottom: 0; right: 24px; width: 44px; height: 44px; }

/* top bar: title, period, search, then (right) This month, Add and Download */
.bk-top { flex: none; display: flex; align-items: center; flex-wrap: wrap; gap: 10px 12px; padding: 12px 24px; border-bottom: 1px solid var(--rule); }
.bk-top .page-title { font-size: 26px; margin: 0 8px 0 0; }
.bk-sp { flex: 1 1 0; }
.bk-top .search-wrap { flex: 0 1 260px; min-width: 150px; }
.bk-top .search-wrap .inp { min-height: 36px; font-size: 13px; }
.bk-top .range-pop { z-index: 40; }
#bookBandShow[hidden], .bk-filt[hidden], .bk-cellbar[hidden] { display: none; }
#bookDlMsg { margin: 8px 24px 0; }

/* the band: tiles left, Worth a look right, one hide button */
.bk-band { flex: none; margin: 12px 24px; border: 1px solid var(--rule); background: var(--paper-2); }
@media (min-width: 641px) { .bk-band[data-hidden] { display: none; } }
.bk-band-line { display: none; }
.bk-band-row { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr) minmax(0, 1fr) minmax(0, .8fr) minmax(0, 2.3fr) 44px; }
.bk-band .tiles { display: contents; }
.bk-band .tile { background: none; padding: 12px 14px; gap: 2px; border-right: 1px solid var(--rule); }
.bk-band .tile-top { display: flex; flex-wrap: wrap; gap: 0 8px; align-items: baseline; }
.bk-band .tile-lab { font-size: 12px; font-weight: 400; color: var(--ink-mid); }
.bk-band .tile-span { font-size: 12px; margin: 0; }
.bk-band .tile-val { font-size: 26px; line-height: 1.1; margin-top: 2px; }
.bk-band .tile-val.empty { font-size: 13px; line-height: 1.3; }
.bk-band .tile-sub { font-size: 12px; margin-top: 2px; }
.bk-band .tile-ask { padding-top: 6px; font-size: 12px; color: var(--plum); min-height: 24px; }
.bk-worth { padding: 12px 14px; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.bk-worth-h { margin: 0; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-mid); }
.bk-worth .prio { max-width: none; }
.bk-worth .prio li { padding: 0 0 8px; border: 0; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 10px; }
.bk-worth .prio li:last-child { padding-bottom: 0; }
.bk-worth .prio .lead { font-family: var(--sans); font-size: 14px; line-height: 1.35; }
.bk-worth .prio .lead .fig { font-family: var(--serif); font-size: 17px; font-weight: 500; }
.bk-worth .prio .why { display: none; }
.bk-worth .prio .go { grid-row: 1; color: var(--plum); font-size: 12px; min-height: 24px; }
.bk-worth .asof { font-size: 13px; }
.bk-hide { align-self: start; width: 44px; height: 44px; display: grid; place-items: center; border: 0; background: none; color: var(--ink-mid); cursor: pointer; }
.bk-hide:hover { color: var(--ink); }
.bk-hide:focus-visible, .bk-band-line:focus-visible { outline: 2px solid var(--plum); outline-offset: -2px; }
.bk-till { border-top: 1px solid var(--rule); padding: 6px 14px; }
.bk-till .till-row { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; }
.bk-till .pnote { background: none; border: 0; padding: 0; max-width: none; font-size: 12.5px; }
.bk-till .till-row .asof { margin: 0 !important; }

/* cell bar: the selected cell's reference and value, read only */
.bk-cellbar { flex: none; display: flex; align-items: stretch; height: 34px; border-top: 1px solid var(--rule); background: var(--paper); }
.bk-ref { width: 112px; display: flex; align-items: center; padding: 0 10px; border-right: 1px solid var(--rule); font-family: var(--mono); font-size: 12.5px; }
.bk-eq { width: 34px; display: flex; align-items: center; justify-content: center; border-right: 1px solid var(--rule); color: var(--ink-mid); font-family: var(--serif); font-style: italic; font-size: 12px; }
.bk-val { flex: 1; min-width: 0; display: flex; align-items: center; padding: 0 12px; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* the sheet's area: fills what is left, whatever the window */
.bk-grid { flex: 1 1 0; min-height: 0; display: flex; flex-direction: column; position: relative; border-top: 1px solid var(--rule); background: var(--paper); }
.bk-grid > .sheet-eq { flex: none; margin: 0; padding: 6px 12px; background: var(--paper-2); }
.bk-grid > .sheet-host { flex: 1 1 0; min-height: 0; }
.bk-grid .products-host { flex: 1 1 0; min-height: 0; overflow: auto; padding: 12px 24px 24px; }

/* bottom bar: the sheet tabs, then the status */
.bk-foot { flex: none; display: flex; align-items: stretch; min-height: 44px; border-top: 1px solid var(--rule); background: var(--paper-2); }
.bk-tabs { display: flex; padding-left: 24px; flex: none; }
.bk-tabs button { min-height: 44px; padding: 0 16px; border: 0; border-right: 1px solid var(--rule); background: var(--paper-2); color: var(--ink-mid); font: inherit; font-size: 13px; cursor: pointer; }
.bk-tabs button:first-child { border-left: 1px solid var(--rule); }
.bk-tabs button:hover { color: var(--ink); }
.bk-tabs button[aria-pressed="true"] { background: var(--paper); color: var(--ink); font-weight: 600; box-shadow: inset 0 -2px 0 var(--plum); }
.bk-tabs button:focus-visible { outline: 2px solid var(--plum); outline-offset: -2px; }
.bk-status { flex: 1; min-width: 0; display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 0 22px; padding: 0 96px 0 16px; font-size: 12.5px; color: var(--ink-mid); }
.bk-status [hidden] { display: none; }
.bk-held { color: var(--red); }

/* ── the sheet (grid) inside it ───────────────────────────────────────────────────────────────────────────────── */
#bookPage .book-sheet { position: relative; display: flex; flex-direction: column; min-height: 0; }
#bookPage .sheet-body { flex: 1 1 0; min-height: 0; display: flex; }
#bookPage .sheet-grid { flex: 1; min-width: 0; min-height: 0; }
/* a message (Try again, Undone, a refusal) sits over the bottom bar's status area, just below the sheet, so it never moves the grid or covers the blank add row */
#bookPage .sheet-note { position: absolute; top: 100%; right: 96px; max-width: 55%; height: 44px; box-sizing: border-box; z-index: 6; margin: 0; padding: 0 12px; display: flex; align-items: center; font-size: 12.5px; background: var(--paper-2); }
#bookPage .sheet-note:empty { display: none; }
@media (max-width: 640px) { #bookPage .sheet-note { position: static; max-width: none; height: auto; padding: 6px 12px; } }
#bookPage .sheet-eq { margin: 0 0 6px; }
/* the row numbers (the header is row 1) and the column letters */
.sheet-gutter { width: 44px; flex: none; display: flex; flex-direction: column; background: var(--paper-2); border-right: 1px solid var(--rule); overflow: hidden; font-size: 12px; color: var(--ink-mid); }
.sheet-gutter-corner { flex: none; display: flex; align-items: flex-end; justify-content: center; padding-bottom: 12px; box-sizing: border-box; border-bottom: 1px solid var(--rule); background: var(--paper-3); min-height: 58px; }
.sheet-gutter-vp { flex: 1; min-height: 0; overflow: hidden; position: relative; }
.sheet-gutter-in > div { height: 40px; display: flex; align-items: center; justify-content: center; box-sizing: border-box; border-bottom: 1px solid var(--rule-soft); }
#bookPage .book-sheet .slick-header-column { position: relative; padding-top: 20px; box-sizing: border-box; }
#bookPage .book-sheet .col-let { position: absolute; top: 0; left: 0; right: 0; height: 20px; line-height: 20px; text-align: center; font-size: 12px; font-weight: 400; color: var(--ink-mid); background: var(--paper-3); border-bottom: 1px solid var(--rule-soft); pointer-events: none; }
/* below the last entry the sheet carries on as empty gridlines, like any spreadsheet */
#bookPage .book-sheet .slick-viewport { background-image: repeating-linear-gradient(to bottom, transparent 0, transparent 39px, var(--rule-soft) 39px, var(--rule-soft) 40px); background-attachment: local; }
#bookPage .book-sheet .slick-cell.num, #bookPage .book-sheet .slick-header-column.num { text-align: right; }
#bookPage .book-sheet .sheet-lock { display: inline-flex; vertical-align: -2px; margin-right: 6px; color: var(--ink-mid); }
#bookPage .book-sheet .sheet-lock .ico { width: 14px; height: 14px; }
#bookPage .book-sheet .slick-row.loading .slick-cell { color: var(--ink-mid); }
#bookPage .book-sheet .slick-row.row-locked .slick-cell { color: var(--ink-mid); }
#bookPage .book-sheet .slick-row.row-locked .slick-cell.selected, #bookPage .book-sheet .slick-row.row-locked .slick-cell.active { color: var(--ink); }
#bookPage .book-sheet { --alpine-header-column-height: 58px; --alpine-header-column-line-height: 36px; --alpine-header-align-items: center; --alpine-odd-row-color: var(--paper); }
#bookPage .book-sheet .slick-header-column.num { justify-content: flex-end; }
#bookPage .book-sheet { --alpine-cell-padding: 0 6px; }
#bookPage .book-sheet .slick-cell { line-height: 38px; }

/* ── a phone (640 px and below): the same look, for reading and adding (D5, BS60) ────────────────────────────── */
.pr-list { flex: 1 1 0; min-height: 0; overflow-y: auto; padding-bottom: 56px; } /* the last row scrolls clear of the Evelyst button */
.pr { display: grid; grid-template-columns: 34px 64px minmax(0, 1fr) 92px 40px; min-height: 44px; width: 100%; box-sizing: border-box; padding: 0; margin: 0; border: 0; border-bottom: 1px solid var(--rule-soft); background: none; color: var(--ink); font: inherit; text-align: left; cursor: pointer; }
.pr.hdr { min-height: 32px; background: var(--paper-2); border-bottom-color: var(--rule); font-weight: 600; font-size: 12.5px; cursor: default; position: sticky; top: 0; z-index: 2; }
.pn { display: flex; align-items: center; justify-content: center; font-size: 12px; color: var(--ink-mid); background: var(--paper-2); border-right: 1px solid var(--rule); }
.pc { display: flex; align-items: center; gap: 5px; padding: 0 8px; border-right: 1px solid var(--rule-soft); font-size: 14px; white-space: nowrap; overflow: hidden; min-width: 0; }
.pc .pc-t { overflow: hidden; text-overflow: ellipsis; }
.pc.num { justify-content: flex-end; font-variant-numeric: tabular-nums; }
.pc.mid { color: var(--ink-mid); }
.pc.last { border-right: 0; }
.pc.bad { background: color-mix(in srgb, var(--red) 6%, var(--paper)); color: var(--ink); box-shadow: inset 0 0 0 1px var(--red); }
.pr.till .pc { color: var(--ink-mid); }
.pr[data-pr]:focus-visible, .pr-add:focus-visible { outline: 2px solid var(--plum); outline-offset: -2px; }
.pr[aria-expanded="true"] { background: var(--paper-2); }
.pr-d { padding: 4px 12px 4px 46px; border-bottom: 1px solid var(--rule-soft); background: var(--paper-2); }
.pr-d[hidden] { display: none; }
.pr-add .add-t { grid-column: 2 / -1; border-right: 0; color: var(--ink-mid); }
.pr-add .ico { width: 14px; height: 14px; color: var(--plum); }
.pr-empty { padding: 12px 16px; }
#bookPage .pcard-held { margin: 4px 0 0; font-size: 13px; color: var(--red); }
#bookPage .pcard-foot { display: flex; justify-content: space-between; align-items: center; min-height: 44px; font-size: 13px; color: var(--ink-mid); }
#bookPage .pr-d .rm { color: var(--ink); font-size: 13px; min-height: 44px; min-width: 44px; padding: 0 4px; cursor: pointer; }

@media (max-width: 640px) {
  .bk-top { padding: 8px 12px; gap: 8px; }
  .bk-top .page-title { font-size: 22px; margin: 0; flex: 1 1 auto; }
  .bk-sp { display: none; }
  .bk-top .search-wrap { order: 9; flex: 1 1 140px; }
  #bookDl { order: 8; }
  #bookBandShow { display: none; }
  .bk-band { margin: 0; border-width: 0 0 1px; }
  .bk-band-line { display: flex; align-items: center; gap: 8px; width: 100%; min-height: 48px; padding: 0 16px; border: 0; background: none; color: var(--ink); font: inherit; font-size: 14px; text-align: left; cursor: pointer; }
  .bk-band-txt { flex: 1; }
  .bk-band-line .ico { width: 14px; height: 14px; transition: transform 160ms; }
  .bk-band[data-open] .bk-band-line .ico { transform: rotate(180deg); }
  .bk-band-body { display: none; padding: 0 16px 14px; }
  .bk-band[data-open] .bk-band-body { display: block; }
  .bk-band-row { display: flex; flex-direction: column; gap: 12px; }
  .bk-band .tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .bk-band .tile { border: 0; padding: 0; }
  .bk-band .tile-span, .bk-band .tile-sub { display: none; }
  .bk-band .tile-val { font-size: 20px; }
  .bk-worth { padding: 0; }
  .bk-hide, .bk-cellbar { display: none; }
  .bk-till { padding: 8px 0 0; border: 0; }
  .bk-foot { flex-direction: column-reverse; min-height: 0; }
  .bk-tabs { padding: 0; }
  .bk-tabs button { flex: 1; min-height: 48px; font-size: 14px; border-right: 1px solid var(--rule); }
  .bk-tabs button:first-child { border-left: 0; }
  .bk-tabs button:last-child { border-right: 0; }
  .bk-tabs button[aria-pressed="true"] { box-shadow: inset 0 2px 0 var(--plum); }
  .bk-status { justify-content: flex-start; padding: 0 12px; min-height: 0; gap: 0 14px; border-bottom: 1px solid var(--rule); }
  .bk-status:has(> :not([hidden])) { min-height: 34px; }
  body.has-ask-fab:has(#page-book:not([hidden]) #bookPage.bk) .ask-fab { bottom: 98px; right: 8px; } /* over the status line and the row chevron column, clear of Amount */
  .bk-grid .products-host { padding: 8px 12px 16px; }
  /* the product table keeps its columns and scrolls sideways inside its own area, not the page */
  #bookPage .products-host .tbl { min-width: 620px; }
  #bookPage .products-host .tbl th, #bookPage .products-host .tbl td { white-space: nowrap; overflow-wrap: normal; }
}

/* The sheet's right-click menu and the Ask chip (Task 7). Tokens only, so both themes follow. */
.sheet-menu { position: fixed; z-index: 50; min-width: 220px; max-width: min(360px, calc(100vw - 16px)); background: var(--paper); border: 1px solid var(--rule); border-radius: var(--radius); padding: 6px 0; box-shadow: 0 4px 18px rgba(30, 26, 21, .18); }
.sheet-menu-item { display: block; width: 100%; min-height: 44px; padding: 0 16px; text-align: left; font: inherit; font-size: 14px; color: var(--ink); background: none; border: 0; cursor: pointer; }
.sheet-menu-item.evelyst { color: var(--plum); }
.sheet-menu-item:hover, .sheet-menu-item:focus-visible { background: var(--paper-2, var(--rule)); outline: none; }
.sheet-menu-item:focus-visible { box-shadow: inset 2px 0 0 var(--plum); }
.sheet-menu-sep { height: 1px; margin: 6px 0; background: var(--rule); }
#bookPage .sheet-ask-chip { position: absolute; z-index: 5; min-height: 44px; padding: 0 14px; font: inherit; font-size: 13px; font-weight: 500; color: var(--plum); background: var(--paper); border: 1px solid var(--plum); border-radius: 22px; cursor: pointer; box-shadow: 0 1px 6px rgba(30, 26, 21, .18); white-space: nowrap; }
#bookPage .sheet-ask-chip[hidden] { display: none; }
#bookPage .sheet-ask-chip:focus-visible { outline: 2px solid var(--plum); outline-offset: 2px; }
.corr-form .inp { width: 100%; min-height: 44px; }
.corr-form .err { color: var(--red); margin: 8px 0 0; }
.products-loading { margin: 0; font-size: 12.5px; color: var(--ink-mid); }
/* the blank row at the end of the sheet is where an owner types the next entry; say so */
#bookPage .book-sheet .slick-row.new-row .slick-cell.l1:empty::before { content: 'Type to add an entry'; color: var(--ink-mid); font-style: italic; }

/* ── "Your layout" (view B): the owner's old arrangement, a real table (Task 20) ───────────────────────────────── */
.bk-view { display: inline-flex; border: 1px solid var(--rule); border-radius: 6px; overflow: hidden; }
.bk-view[hidden] { display: none; }
.bk-view button { min-height: 36px; padding: 0 12px; border: 0; background: var(--paper-2); color: var(--ink-mid); font: inherit; font-size: 13px; cursor: pointer; }
.bk-view button + button { border-left: 1px solid var(--rule); }
.bk-view button[aria-pressed="true"] { background: var(--paper); color: var(--ink); font-weight: 600; box-shadow: inset 0 -2px 0 var(--plum); }
.bk-view button:focus-visible { outline: 2px solid var(--plum); outline-offset: -2px; }
@media (max-width: 640px) { .bk-view { display: none; } }

.viewb-host { flex: 1 1 0; min-height: 0; display: flex; flex-direction: column; }
.vb { flex: 1 1 0; min-height: 0; display: flex; flex-direction: column; }
.vb-bar { flex: none; display: flex; align-items: center; gap: 10px; padding: 8px 24px; }
.vb-period { font-weight: 600; min-width: 9ch; text-align: center; }
.vb-pick { display: inline-flex; align-items: center; gap: 8px; margin-left: auto; font-size: 13px; color: var(--ink-mid); }
.vb-pick .inp { min-height: 36px; font-size: 13px; }
.vb-disc { flex: none; margin: 0; padding: 0 24px 8px; font-size: 13px; color: var(--ink-mid); }
.vb-note { flex: none; margin: 0; padding: 0 24px; font-size: 12.5px; color: var(--ink); min-height: 0; }
.vb-note:empty { display: none; }
.vb-scroll { flex: 1 1 0; min-height: 0; overflow: auto; padding: 0 24px 24px; }
.vb-tbl { border-collapse: collapse; font-size: 14px; color: var(--ink); background: var(--paper); }
.vb-tbl th, .vb-tbl td { border: 1px solid var(--rule); padding: 0 8px; min-height: 40px; height: 40px; box-sizing: border-box; text-align: left; font-weight: 400; white-space: nowrap; }
.vb-tbl .vb-c.num { text-align: right; font-variant-numeric: tabular-nums; }
.vb-tbl .banner { text-align: left; font-size: 16px; background: var(--paper-2); }
.vb-tbl .header { background: var(--paper-2); font-weight: 600; text-align: center; }
.vb-tbl thead td { background: var(--paper-2); }
.vb-tbl th[scope="row"] { background: var(--paper-2); font-weight: 600; text-align: left; }
.vb-tbl .vb-lock { color: var(--ink-mid); }
/* after .vb-lock, so a locked TOTAL keeps the full ink (a copied fill is checked against --ink) */
.vb-tbl .total { background: var(--paper-3); font-weight: 600; color: var(--ink); }
.vb-tbl .vb-held { background: color-mix(in srgb, var(--red) 6%, var(--paper)); color: var(--ink); box-shadow: inset 0 0 0 1px var(--red); }
.vb-tbl [data-r]:focus-visible { outline: 2px solid var(--plum); outline-offset: -2px; }
.vb-in { width: 100%; min-width: 7ch; height: 100%; box-sizing: border-box; border: 0; padding: 0; background: var(--paper); color: var(--ink); font: inherit; text-align: inherit; outline: 2px solid var(--plum); outline-offset: -2px; }
.vb-empty { padding: 12px 24px; }

/* ── "Things you asked for": a right-hand panel; the sheet narrows beside it (Task 21, D41) ───────────────────── */
.bk-main { flex: 1 1 0; min-height: 0; display: flex; }
.bk-main > .bk-grid { min-width: 0; }
.bk-asked { flex: none; width: 340px; box-sizing: border-box; overflow-y: auto; padding: 12px 16px 24px; border-top: 1px solid var(--rule); border-left: 1px solid var(--rule); background: var(--paper); }
.bk-asked[hidden] { display: none; }
.asked-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.asked-h { margin: 0; font-family: var(--serif); font-size: 20px; font-weight: 500; }
.asked-x { width: 44px; height: 44px; margin: -8px -12px -8px 0; border: 0; background: none; color: var(--ink-mid); font-size: 22px; cursor: pointer; }
.asked-x:hover { color: var(--ink); }
.asked-x:focus-visible { outline: 2px solid var(--plum); outline-offset: -2px; }
.asked-form { display: flex; flex-direction: column; gap: 8px; margin: 8px 0 4px; align-items: flex-start; }
.asked-form .fld { width: 100%; }
.asked-item { padding: 12px 0; border-top: 1px solid var(--rule-soft); }
.asked-item:first-child { border-top: 0; }
.asked-t { margin: 0 0 6px; font-size: 14px; font-weight: 600; }
.asked-item .tbl { font-size: 13px; }
.asked-item .asof { margin: 6px 0 0; }
.bk-asked .err, .bk-asked .asof[data-note] { margin: 6px 0 0; }
.ask-col { color: var(--ink-mid); }
/* a phone: the panel opens over the page as a full-width sheet; the list under it stays as it was */
@media (max-width: 640px) {
  .bk-asked { position: fixed; inset: 0; z-index: 60; width: auto; border: 0; padding-bottom: 72px; }
}
