/* dashboard/tape-rail.css — the Tape's rail (tape-rail.js), shared by the
   Desk and the Live Feed. Brand tokens only (theme.css). A page sizes the
   rail's column itself (the layout element gets has-tape / is-tape-closed)
   and may override position for its own phone layout.

   .tape-rail             the rail: sticky beside the page content
   .tape-rail.is-closed   collapsed to a slim tab (the choice is remembered)
   .tape-rail.is-pinned   the Tape page (opts.pinned): the page's main content,
                          always open, one row per event, flows with the page
   .tape-rail.is-sheet    phones, on pages that opt in: a modal bottom sheet
                          (.is-sheet-open), opened by .tape-sheet-btn (sticky
                          at the foot of the screen) over a .tape-backdrop;
                          html.tape-sheet-lock stops the page scrolling
                          behind it.
   Colour is meaning: gold = money, green = shortening / result, slate
   (--drift) = drifting, red = the off. */

.tape-rail {
  position: sticky; top: 70px;
  display: flex; flex-direction: column;
  max-height: calc(100vh - 86px);
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}
.tape-rail:empty { display: none; }
.tape-head {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px; flex-shrink: 0;
  padding: 12px 12px 11px 14px; border-bottom: 1px solid var(--border-subtle);
}
.tape-title { font: 700 0.66rem/1 var(--font-mono); letter-spacing: 0.2em; text-transform: uppercase; color: var(--accent); }
.tape-count {
  padding: 3px 6px; border-radius: 4px; background: var(--surface-hover);
  font: 700 0.6rem/1 var(--font-mono); color: var(--text-dim);
}
.tape-toggle, .tape-tab {
  border: 1px solid var(--border-subtle); border-radius: var(--radius-sm);
  background: transparent; color: var(--text-dim); cursor: pointer;
  font: 700 0.6rem/1 var(--font-mono); letter-spacing: 0.1em; text-transform: uppercase;
  transition: color 0.12s, border-color 0.12s, background 0.12s;
}
.tape-toggle { margin-left: auto; padding: 6px 9px; }
.tape-toggle:hover, .tape-tab:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-dim); }
.tape-tab { display: none; }
.tape-unseen {
  padding: 2px 5px; border-radius: 9px; background: var(--accent-fill); color: var(--on-accent);
  font: 700 0.58rem/1 var(--font-mono); letter-spacing: 0;
}
.tape-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.tape-empty { margin: 0; padding: 16px 14px; font-size: 0.76rem; line-height: 1.5; color: var(--text-muted); }
.tape-list { list-style: none; margin: 0; padding: 0; }
.tape-foot {
  margin: 0; padding: 10px 14px 12px; border-top: 1px solid var(--border);
  font-size: 0.66rem; line-height: 1.45; color: var(--text-muted);
}

.tp { position: relative; padding: 9px 12px 9px 24px; border-bottom: 1px solid var(--border); }
.tp::before {
  content: ""; position: absolute; left: 11px; top: 13px;
  width: 6px; height: 6px; border-radius: 50%; background: var(--text-muted);
}
.tp--money::before { background: var(--gold); }
.tp--move.is-in::before { background: var(--green); }
.tp--move.is-out::before { background: var(--drift); }
/* A move on thin money (under £100 matched between the two prices) or at 100+. */
.tp.is-thin { opacity: 0.55; }
.tp.is-thin::before { background: var(--text-muted); }
.tp--nr::before { background: var(--gold); box-shadow: 0 0 0 2px var(--gold-dim); }
.tp--fav::before { background: var(--accent); }
.tp--off::before { background: var(--red); }
.tp--result::before { background: var(--green); box-shadow: 0 0 0 2px var(--green-dim); }
.tp-meta { display: flex; align-items: baseline; gap: 8px; font: 600 0.62rem/1.2 var(--font-mono); color: var(--text-muted); }
.tp-meta time { font-variant-numeric: tabular-nums; }
.tp-meta a { color: var(--accent); font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; text-decoration: none; }
.tp-meta a:hover { text-decoration: underline; }
.tp-text { margin: 3px 0 0; font-size: 0.8rem; line-height: 1.35; color: var(--text); overflow-wrap: anywhere; }
.tp--money .tp-text, .tp--result .tp-text { color: var(--text-strong); font-weight: 600; }
.tp.is-new { animation: tpIn 1.2s ease-out; }
@keyframes tpIn { from { background: color-mix(in srgb, var(--accent) 14%, transparent); } to { background: transparent; } }

/* collapsed: a slim tab on the right */
.tape-rail.is-closed .tape-head,
.tape-rail.is-closed .tape-body { display: none; }
.tape-rail.is-closed { border-radius: var(--radius-md); }
.tape-rail.is-closed .tape-tab {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  width: 100%; padding: 12px 0; border: 0; border-radius: 0;
}
.tape-rail.is-closed .tape-tab > span:first-child { writing-mode: vertical-rl; letter-spacing: 0.22em; }

/* ---- phones, on pages that opt in (TapeRail.mount opts.sheet) ---- */
/* The button is sticky, not fixed: put it in <body> just before the footer.
   It floats at the foot of the screen while the page scrolls and comes to
   rest above the footer at the end, so it never covers the footer's text.
   The negative top margin tucks it into the content's bottom padding. */
.tape-sheet-btn {
  position: sticky; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 90;
  display: flex; align-items: center; gap: 9px;
  width: max-content; margin: -24px 16px 0 auto;
  min-height: 44px; padding: 0 8px 0 16px;
  border: 1px solid var(--accent); border-radius: 999px;
  background: var(--surface-raised); color: var(--accent);
  box-shadow: var(--shadow-pop); cursor: pointer;
  font: 700 0.68rem/1 var(--font-mono); letter-spacing: 0.18em; text-transform: uppercase;
}
.tape-sheet-btn[hidden] { display: none; }
.tape-sheet-btn:hover { background: var(--accent-dim); }
.tape-sheet-btn__count {
  min-width: 26px; padding: 6px 7px; border-radius: 999px; text-align: center;
  background: var(--surface-hover); color: var(--text-dim);
  letter-spacing: 0; font-variant-numeric: tabular-nums;
}
.tape-sheet-btn.has-new .tape-sheet-btn__count { background: var(--accent-fill); color: var(--on-accent); }
.tape-backdrop {
  position: fixed; inset: 0; z-index: 130;
  background: color-mix(in srgb, var(--brand-navy) 55%, transparent);
}
.tape-backdrop[hidden] { display: none; }
.tape-rail.is-sheet {
  position: fixed; left: 0; right: 0; bottom: 0; top: auto; z-index: 131;
  max-height: 80vh; max-height: 80dvh;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0; border-bottom: 0;
  box-shadow: var(--shadow-pop);
  padding-bottom: env(safe-area-inset-bottom);
  transform: translateY(100%); visibility: hidden;
  transition: transform 0.22s ease, visibility 0s linear 0.22s;
}
.tape-rail.is-sheet.is-sheet-open { transform: none; visibility: visible; transition: transform 0.22s ease; }
.tape-rail.is-sheet .tape-tab { display: none; }
.tape-rail.is-sheet .tape-head { padding: 10px 10px 10px 16px; }
.tape-rail.is-sheet .tape-toggle { min-height: 40px; padding: 0 14px; }
html.tape-sheet-lock, html.tape-sheet-lock body { overflow: hidden; }

/* "Open the Tape page", in the rail header on the Desk and the Live Feed */
.tape-page-link {
  order: 9; flex: 1 0 100%; margin-top: 2px; color: var(--accent); text-decoration: none;
  font: 700 0.6rem/1.2 var(--font-mono); letter-spacing: 0.08em; text-transform: uppercase;
}
.tape-page-link:hover { text-decoration: underline; }

/* ---- the Tape page (opts.pinned): full width, one row per event ---- */
.tape-rail.is-pinned { position: static; max-height: none; overflow: visible; }
.tape-rail.is-pinned .tape-body { overflow: visible; }
.tape-rail.is-pinned.is-filtered-empty .tape-empty { display: none; }
.tape-rail.is-pinned .tp {
  display: grid; grid-template-columns: minmax(190px, 280px) minmax(0, 1fr) auto;
  align-items: center; gap: 4px 18px; padding: 11px 16px 11px 30px;
}
.tape-rail.is-pinned .tp::before { left: 14px; top: 50%; margin-top: -3px; }
.tape-rail.is-pinned .tp-meta { gap: 12px; font-size: 0.7rem; }
.tape-rail.is-pinned .tp-text { margin: 0; font-size: 0.88rem; }
.tape-rail.is-pinned .tp .rp-open { justify-self: end; }
@media (max-width: 700px) {
  .tape-rail.is-pinned .tp { grid-template-columns: minmax(0, 1fr); padding: 11px 14px 11px 28px; }
  .tape-rail.is-pinned .tp::before { top: 17px; margin-top: 0; }
  .tape-rail.is-pinned .tp .rp-open { justify-self: start; min-height: 40px; margin-top: 4px; }
}

@media (prefers-reduced-motion: reduce) {
  .tp.is-new { animation: none; }
  .tape-rail.is-sheet, .tape-rail.is-sheet.is-sheet-open { transition: none; }
}
