@layer components {
  .tw { overflow-x: auto; }
  .tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
  .tbl th { height: 38px; padding: 0 14px; text-align: left; font-family: var(--f-m); font-weight: 700; font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--wash); }
  .tbl th svg { width: 11px; height: 11px; vertical-align: -1px; margin-left: 4px; }
  .tbl td { height: 48px; padding: 0 14px; border-bottom: 1px solid var(--line); color: var(--dim); white-space: nowrap; }
  .tbl tr:last-child td { border-bottom: 0; }
  .tbl th:first-child, .tbl td:first-child { padding-left: 18px; }
  .tbl th:last-child, .tbl td:last-child { padding-right: 18px; }
  .tbl td.t { color: var(--strong); font-weight: 600; }
  .tbl td small { margin-left: 8px; font-weight: 400; color: var(--muted); font-size: 12px; }
  .tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
  .tbl td.num { color: var(--ink); }
  .tbl tbody tr:hover td { background: var(--hover); }
  .tbl tr.tot td { height: 44px; color: var(--strong); font-weight: 600; border-top: 1px solid var(--line-2); background: var(--wash-2); }
  .tbl td.go { width: 36px; padding-right: 14px; color: var(--muted); }
  .tbl td.go svg { width: 15px; height: 15px; }
  .tbl td a { color: inherit; }
  .tbl tbody tr[data-href] { cursor: pointer; }
  .tbl tr.bad td { background: var(--bad-wash); }
  .tbl tr.low td { background: var(--warn-wash); }
  .tbl tr.sel td { background: var(--accent-soft); }
  .tbl tr.sel td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
  .tbl td.ck { width: 44px; }
  .tbl.perm td { height: 38px; }
  .tbl.perm tr.grp td { cursor: default; }
  .tbl.perm th:last-child, .tbl.perm td.tg { text-align: right; }
  .tbl.perm td.tg .row { justify-content: flex-end; gap: 4px; flex-wrap: wrap; }
  .tbl.perm tr.nil td.t { color: var(--muted); font-weight: 400; }

  /* toolbar */
  .tbar { display: flex; align-items: center; gap: 8px; padding: 12px 18px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
  .tbar .end { margin-left: auto; display: flex; gap: 8px; align-items: center; }
  .trun { position: relative; height: 2px; margin-top: -2px; overflow: hidden; opacity: 0; pointer-events: none; }
  .trun span { display: block; width: 40%; height: 100%; background: var(--accent); }
  .busy .trun { opacity: 1; }
  .busy .trun span { animation: pg-run 1.3s ease-in-out infinite; }
  .busy .tw, .busy [data-showing] { opacity: .45; pointer-events: none; }
  @media (prefers-reduced-motion: reduce) { .busy .trun span { animation: none; margin-left: 30%; } }
  .gs { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); white-space: nowrap; }
  .gs .sel .input { height: 32px; width: auto; min-width: 118px; padding-left: 10px; font-size: 13px; }
  .search { display: flex; align-items: center; gap: 8px; height: 34px; padding: 0 10px; border: 1px solid var(--line-2); border-radius: var(--r-sm); background: var(--well); color: var(--muted); min-width: 260px; }
  .field > .search { flex: none; }
  .search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
  .search svg { width: 15px; height: 15px; }
  .search input { all: unset; flex: 1; min-width: 0; color: var(--ink); font-size: 13.5px; }
  .search.lg { flex: none; height: 44px; padding: 0 14px; }
  .search.lg input { font-size: 16px; }
  .search input::placeholder { color: var(--placeholder); }
  .search kbd { font-family: var(--f-m); font-size: 10px; border: 1px solid var(--line-2); border-radius: var(--r-xs); padding: 1px 5px; color: var(--muted); }
  @media (pointer: coarse) {
    .search kbd { display: none; }
  }
  .fchip { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 4px 0 10px; border-radius: var(--r-sm); background: var(--accent-soft); color: var(--accent); font-size: 12.5px; font-weight: 600; white-space: nowrap; }
  .fchip > svg { width: 13px; height: 13px; }
  .fchip button { width: 22px; height: 22px; padding: 0; border: 0; border-radius: var(--r-xs); background: none; color: inherit; display: grid; place-items: center; }
  .fchip button:hover { background: var(--accent-soft); }
  .fchip button svg { width: 13px; height: 13px; }

  /* sortable headings and their menus */
  .th-s { display: inline-flex; align-items: center; gap: 6px; padding: 0; border: 0; background: none; color: inherit; font: inherit; letter-spacing: inherit; text-transform: inherit; cursor: pointer; }
  .tbl th .th-s svg { width: 12px; height: 12px; margin: 0; color: var(--muted); }
  .th-s .si-d, .th-s .si-u { display: none; }
  .th-s:hover .si-u, .th-s:focus-visible .si-u { display: inline; opacity: 0.8; }
  .tbl th.asc, .tbl th.desc { color: var(--ink); }
  .tbl th.asc .si-u, .tbl th.desc .si-u { display: none; }
  .tbl th.asc .si-d, .tbl th.desc .si-d { display: inline; color: var(--accent); }
  .tbl th.asc .si-d { transform: rotate(180deg); }
  .th-m { display: inline-grid; place-items: center; width: 20px; height: 20px; margin-left: 4px; padding: 0; border: 0; border-radius: var(--r-xs); background: none; color: var(--muted); opacity: 0; vertical-align: middle; }
  .tbl th .th-m svg { width: 13px; height: 13px; margin: 0; }
  .tbl th:hover .th-m, .th-m:focus-visible, .tbl th.open .th-m { opacity: 1; }
  .tbl th.open { background: var(--hover); color: var(--ink); }
  .tbl th.open .th-m { background: var(--fill-2); color: var(--ink); }

  /* groups */
  .tbl tr.grp td { height: 36px; background: var(--wash-2); color: var(--dim); font-weight: 600; font-size: 12.5px; cursor: pointer; }
  .gc { display: inline-grid; place-items: center; width: 20px; height: 20px; color: var(--muted); }
  .gc svg { width: 14px; height: 14px; transition: transform 0.15s; }
  .tbl tr.grp.shut .gc svg { transform: rotate(-90deg); }
  .grp-n { font-family: var(--f-m); font-size: 11px; font-weight: 700; color: var(--muted); }
  .grp-t { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--ink); }
  .tbl tr.grp.gl2 td { background: var(--wash); }
  .tbl tr.grp.gl2 .row { padding-left: 24px; }
  .tbl .ha { display: none; }

  .chips { display: contents; }
  .tb-sort { display: none; }
  .fset { display: flex; flex-direction: column; gap: 10px; }
  .bsheet-b .mlab { padding: 0 0 8px; }
  .pager { display: flex; align-items: center; gap: 8px; }
  .pager .sel .input { height: 30px; width: 72px; font-size: 13px; }
  .pager .at { font-family: var(--f-m); font-size: 12px; }

  @media (width < 1100px) {
    .tbl .ht { display: none; }
    .search { min-width: 200px; }
  }

  /* A table fills the screen down to the bottom edge and scrolls its rows; table.js sets --fill. */
  @media (width >= 700px) {
    .pnl[data-table] { display: flex; flex-direction: column; height: var(--fill, auto); margin-bottom: 40px; }
    .pnl[data-table] .tw { flex: 1; min-height: 0; overflow: auto; }
    .pnl[data-table]:not(.embed) .tw { scrollbar-gutter: stable; }
    .pnl[data-table].pinned .tbl { table-layout: fixed; }
    .pnl[data-table].embed { height: auto; margin-bottom: 0; }
    .pnl[data-table] thead th { position: sticky; top: 0; z-index: 1; background: linear-gradient(var(--wash), var(--wash)), var(--panel); }
  }
  @media (700px <= width < 1100px) {
    .pnl[data-table] { margin-bottom: 28px; }
  }

  /* On a phone each row becomes a card: td.t is the title, td.sub the line under it, td.tg
     the status at the top right, td.hm is dropped, and every other cell shows its data-l. */
  .tbl.lines tr:has([data-won]:checked) td { background: var(--accent-soft); }

  @media (width < 700px) {
    .tbl thead { display: none; }
    .tbl, .tbl tbody, .tbl tfoot { display: block; }
    .tbl tr { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
    .tbl tr:last-child { border-bottom: 0; }
    .tbl td, .tbl td:first-child, .tbl td:last-child { display: block; height: auto; padding: 0; border: 0; white-space: normal; min-width: 0; }
    .tbl td.t { grid-column: 1 / span 2; grid-row: 1; font-size: 15px; }
    .tbl td.tg { grid-column: 3; grid-row: 1; justify-self: end; align-self: start; }
    .tbl td.sub { grid-column: 1 / -1; grid-row: 2; margin-top: -6px; color: var(--muted); font-size: 12.5px; }
    .tbl td.full { grid-column: 1 / -1; }
    .tbl td[data-l]::before { content: attr(data-l); display: block; font-family: var(--f-m); font-weight: 700; font-size: 9.5px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }
    .tbl .num { text-align: left; }
    .tbl td.hm, .tbl td.go { display: none; }
    .tbl tbody tr:hover td { background: none; }
    .tbl tr.tot { grid-template-columns: minmax(0, 1fr) auto; }
    .tbl tr.tot td { height: auto; border: 0; background: none; }
    .tbl tr.grp { display: block; padding: 8px 16px; background: var(--wash-2); }
    .tbl tr.grp td { height: auto; background: none; }
    .tbl tr.bad { box-shadow: inset 3px 0 0 var(--bad); }
    .tbl tr.low { box-shadow: inset 3px 0 0 var(--warn); }
    .tbl tr.bad td, .tbl tr.low td, .tbl tr.sel td { background: none; box-shadow: none; }
    .tbl.perm tr { grid-template-columns: minmax(0, 1fr) auto; }
    .tbl.perm td.t { grid-column: 1; }
    .tbl.perm td.tg { grid-column: 2; }
    .tbl .ht { display: none; }
    .tbl.lines tbody tr:not(.grp), .tbl.lines tr.tot { display: flex; flex-wrap: wrap; align-items: baseline; gap: 5px 0; padding: 12px 16px; }
    .tbl.lines tbody tr:not(.grp)::before { content: ""; order: 3; flex-basis: 100%; height: 0; }
    .tbl.lines tr:has([data-won]:checked) { background: var(--accent-soft); }
    .tbl.lines tr:has([data-won]:checked) td { background: none; }
    .tbl.lines td[data-l]::before { content: none; }
    .tbl.lines td.tg { order: 0; width: 30px; align-self: center; }
    .tbl.lines td.t { order: 1; flex: 1; }
    .tbl.lines td[data-k="net"] { order: 2; font-weight: 600; color: var(--strong); }
    .tbl.lines td.sub, .tbl.lines td[data-k="entry"], .tbl.lines tbody td[data-k="signup"] { margin: 0; font-size: 13px; color: var(--muted); }
    .tbl.lines td.sub { order: 4; }
    .tbl.lines td[data-k="entry"] { order: 5; }
    .tbl.lines tbody td[data-k="signup"] { display: block; order: 6; }
    .tbl.lines tbody td[data-k="bought"] { display: block; order: 8; flex: 1 1 100%; margin-top: 3px; font-size: 13px; color: var(--ink); }
    .tbl.lines td[data-k="paid"] { order: 9; font-size: 13px; color: var(--muted); }
    .tbl.lines td[data-k="fee"] { order: 10; font-size: 13px; }
    .tbl.lines td[data-k="fee"]:empty { display: none; }
    .tbl.lines td[data-k="entry"]::before, .tbl.lines tbody td[data-k="signup"]::before, .tbl.lines tbody td[data-k="fee"]::before { content: "\00b7"; display: inline; margin: 0 6px; font: inherit; letter-spacing: 0; text-transform: none; color: var(--dim); }
    .tbl.lines tr.tot td:first-child { flex: 1; }
    .tbl.lines tr.tot .num { margin-left: 14px; }
    .tbl.lines tr.tot td[data-sum="fee"] { color: var(--muted); }
    .tbar { padding: 12px 16px; }
    .search { min-width: 0; flex: 1 1 100%; height: 44px; }
    .search input { font-size: 16px; }
    .tbar .end { margin-left: 0; width: 100%; }
    .tbar .end .btn { flex: 1; }
    .tbar .gs { display: none; }
    .tb-sort { display: inline-flex; }
    .pager .lbl-rows { display: none; }
  }
}
