/* ── Tokens → SA (design.md §2) ───────────────────────────
   This component is original, so it asks SA's tokens for what it needs
   instead of mapping someone else's. On its OWN root, so nothing leaks:

     --rng-ink    ← --text        the amount in the middle
     --rng-on     ← --bg          type and icon sitting ON a coloured arc
     --rng-off    ← --text-faint  an icon on an arc that has lost its colour
     --rng-dim    ← --panel-2     the colour an arc loses its colour TO

   The seven category colours are NOT tokens: they come in with the data
   (`--seg`, set per arc by the component). SA has no categorical palette; see
   the notes in spending-ring.js. */
.rng {
  --rng-ink: var(--text, #f4f6fa);
  --rng-on: var(--bg, #0b1320);
  --rng-off: var(--text-faint, #6d7d99);
  --rng-dim: var(--panel-2, #1b273d);
  position: relative;
  color: var(--rng-ink);
  font-family: inherit;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;}

.rng-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;}

/* ── one arc, and everything about it is read off two numbers ──
   --k is 1 while the arc is coloured and 0 once it has lost its colour; --e is 0 for a
   normal arc and 1 for the chosen one. The colour is a mix of the category's own and the
   dark one, so the same number drives the colour, the icon and the label; --e adds a touch
   of brightness to the thickness the component already gives it. The arc keeps its shape. */
.rng-arc {
  fill: color-mix(in srgb, var(--seg) calc(var(--k) * 100%), var(--rng-dim));
  stroke: none;
  filter: brightness(calc(1 + var(--e, 0) * 0.1));}

.rng-seg { outline: none; cursor: pointer; }

.rng-seg:focus-visible .rng-arc {
  filter: drop-shadow(0 0 3px var(--accent, #06b6d4));}

.rng-ico {
  pointer-events: none;
  color: color-mix(in srgb, var(--rng-on) calc(var(--k) * 100%), var(--rng-off));}

/* the amount at the start of the arc: small, tabular, dark on the colour */
.rng-lab {
  fill: var(--rng-on);
  font-size: 8.5px;
  font-weight: 600;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;}

/* ── the middle ─────────────────────────────────────────────
   Positioned by the component, on the middle of a ring and under an open arc or a bar.
   The caption is a one-cell grid whose cell holds the old word and the new one at the same
   time while they swap. */
.rng-mid {
  position: absolute;
  display: grid;
  justify-items: center;
  gap: calc(var(--u, 1px) * 1);
  text-align: center;
  transform: translate(-50%, -50%);
  pointer-events: none;}

.rng-cap { display: inline-grid; }

.rng-t { grid-area: 1 / 1; white-space: nowrap; }

.rng-cap {
  font-size: calc(var(--u, 1px) * 10);
  line-height: 1.2;
  color: var(--text-faint, #6d7d99);
  letter-spacing: 0.01em;}

.rng-sub {
  font-size: calc(var(--u, 1px) * 10);
  line-height: 1.2;
  color: var(--text-dim, #a4b1c7);
  letter-spacing: 0.01em;}

/* ══ The amount: the rolling counter's number ══════════════
   Same structure and numbers as .rct-num in rolling-counter.css: every digit is a strip of
   0–9 behind a window (--rng-cell tall, set by the component from `size`), columns open and
   close with the length of the number, and the rolling digits fade at the window's top and
   bottom edge. The prefix and suffix are plain text beside it. */
.rng-num {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  height: var(--rng-cell, 33px);
  font-size: calc(var(--u, 1px) * 28);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  line-height: var(--rng-cell, 33px);
  color: var(--rng-ink);
  /* rolling digits fade at the window's top and bottom edge */
  mask-image: linear-gradient(transparent, #000 20%, #000 80%, transparent);}

.rng-aff { height: var(--rng-cell, 33px); }

.rng-pair { display: flex; }

.rng-col {
  width: 0;
  opacity: 0;
  overflow: hidden;
  height: var(--rng-cell, 33px);
  transition: width 320ms cubic-bezier(0.3, 1.2, 0.4, 1), opacity 220ms ease;}

.rng-col[data-on] { width: 0.64em; opacity: 1; }

.rng-strip {
  display: flex;
  flex-direction: column;
  align-items: center;
  will-change: transform;}

.rng-strip > span { height: var(--rng-cell, 33px); }

.rng-sep {
  width: 0;
  opacity: 0;
  overflow: hidden;
  transition: width 320ms cubic-bezier(0.3, 1.2, 0.4, 1), opacity 220ms ease;}

.rng-sep[data-on] { width: 0.26em; opacity: 1; }

/* ── Tokens → SA (design.md §2) ───────────────────────────
   Bencho reads --fill-on (ink) and --fill-slab (ground) and four more
   it does not define: --pane-edge, --signal, --font-ui and the
   per-element --c / --i / --stb-r / --stb-rr.
   The first four are mapped here, on the component's OWN root, as
   aliases of SA's tokens, so the rest of this stylesheet stays exactly
   as upstream (easier to re-sync) and nothing leaks out:

     --fill-on    → --text      ink: the bars, the figure, the hairlines
     --fill-slab  → --panel-2   ground: the card, the tab thumb, the tip
     --pane-edge  → --border    the card's hairline
     --signal     → --accent    the keyboard focus ring

   --font-ui is not mapped to a token: SA has none, and the card should
   take the page's font, so it is `inherit` below.
   --c, --i, --stb-r and --stb-rr are NOT tokens: stacked-bars.js writes
   them on each bar, column and on the root. Do not map them.
   The fallbacks are SA's own values (design.md §2). */
.stb {
  --fill-on: var(--text, #f4f6fa);
  --fill-slab: var(--panel-2, #1b273d);
  --pane-edge: var(--border, #2a3a56);
  --signal: var(--accent, #06b6d4);}

/* ══ Stacked bars (lab/StackedBars.tsx) ═══ */
.stb {
  --stb-c1: color-mix(in srgb, var(--fill-on, #17181a) 100%, var(--fill-slab, #ffffff));
  --stb-c2: color-mix(in srgb, var(--fill-on, #17181a) 78%, var(--fill-slab, #ffffff));
  --stb-c3: color-mix(in srgb, var(--fill-on, #17181a) 60%, var(--fill-slab, #ffffff));
  --stb-c4: color-mix(in srgb, var(--fill-on, #17181a) 44%, var(--fill-slab, #ffffff));
  --stb-c5: color-mix(in srgb, var(--fill-on, #17181a) 32%, var(--fill-slab, #ffffff));
  --stb-c6: color-mix(in srgb, var(--fill-on, #17181a) 22%, var(--fill-slab, #ffffff));
  --stb-alert: color-mix(in srgb, var(--fill-on, #17181a) 100%, var(--fill-slab, #ffffff));
  --stb-soft: color-mix(in srgb, var(--fill-on, #17181a) 72%, var(--fill-slab, #ffffff));
  --stb-mute: color-mix(in srgb, var(--fill-on, #17181a) 52%, var(--fill-slab, #ffffff));
  --stb-faint: color-mix(in srgb, var(--fill-on, #17181a) 32%, var(--fill-slab, #ffffff));
  --stb-w6: color-mix(in srgb, var(--fill-on, #17181a) 6%, transparent);
  --stb-w12: color-mix(in srgb, var(--fill-on, #17181a) 12%, transparent);
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px;
  box-sizing: border-box;
  border-radius: 20px;
  background: var(--fill-slab, #ffffff);
  color: var(--fill-on, #17181a);
  font-family: inherit;
  font-size: 13px;
  user-select: none;
  -webkit-user-select: none;}

/* the Arc ring's and Audio trim's palette (2026-11-19), cool at the
   foot of each stack warming to the top; the bounced bars keep the
   status red, the one colour here that means something */
.stb[data-colour="on"] {
  --stb-c1: #3d7bff; --stb-c2: #d77bf2; --stb-c3: #ff7a1a;
  --stb-c4: #ffbe1a; --stb-c5: #34c759; --stb-c6: #ffe23d;
  --stb-alert: #e5484d;}

/* (port) the original drew this from a `data-stroke` attribute on the
   page; here the card carries it itself (option `stroke`) */
.stb[data-stroke="on"] { box-shadow: 0 0 0 1px var(--pane-edge); }

/* header: icon tile, title, Day / Week */
.stb-head { display: flex; align-items: center; gap: 12px; }

.stb-titles { flex: 1; min-width: 0; }

/* 16 / 13, the recent blocks' title and meta (Audio trim, Arc ring, 2026-11-19) */
.stb-title { font-size: 16px; font-weight: 500; letter-spacing: -0.01em; line-height: 22px; }

.stb-sub { font-size: 13px; color: var(--stb-mute); line-height: 18px; font-variant-numeric: tabular-nums; }

.stb-seg-ctl {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 2px;
  /* a pill, track and thumb, as the recent blocks' controls */
  border-radius: 999px;
  background: var(--stb-w6);}

.stb-thumb {
  position: absolute;
  top: 2px;
  bottom: 2px;
  left: 2px;
  width: calc(50% - 2px);
  border-radius: 999px;
  background: var(--fill-slab, #ffffff);
  transition: transform 220ms cubic-bezier(0.22, 1, 0.36, 1);}

.stb-seg-ctl[data-mode="Week"] .stb-thumb { transform: translateX(100%); }

.stb-tab {
  position: relative;
  appearance: none;
  border: 0;
  background: none;
  padding: 0 12px;
  height: 30px;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--stb-mute);
  cursor: pointer;
  border-radius: 999px;
  transition: color 160ms ease, scale 160ms cubic-bezier(0.22, 1, 0.36, 1);}

.stb-tab[data-on] { color: var(--fill-on, #17181a); }

.stb-tab:hover:not([data-on]) { color: var(--stb-soft); }

.stb-tab:active { scale: 0.96; }

.stb-tab:focus-visible { outline: 2px solid var(--signal, #2231dd); outline-offset: 0; }

/* the one figure */
.stb-figure { display: flex; align-items: baseline; gap: 8px; margin-bottom: -4px; }

.stb-num {
  font-size: 30px;
  font-weight: 500;
  /* proportional figures, a touch tighter (2026-11-19): tabular ones gave
     the 1 an 8's width and the figure read gappy. It only changes on the
     Day / Week switch, where it pops in fresh, so nothing jitters.
     0: at -0.04 the narrow 1 crowded the 8, and -0.02 still read tight */
  letter-spacing: 0em;
  line-height: 32px;
  font-variant-numeric: proportional-nums;}

.stb-unit { font-size: 13px; color: var(--stb-mute); }

/* Price flow's pop in: each character rises a touch from below, out
   of a slight blur and from nothing, a hair past its mark — left to
   right, 70ms apart */
.stb-digit { display: inline-block; }

.stb-digit[data-pop] {
  animation: stb-pop 500ms cubic-bezier(0.34, 1.45, 0.64, 1) both;
  animation-delay: calc(var(--i, 0) * 70ms);}

@media (prefers-reduced-motion: reduce) {
  .stb-digit[data-pop] { animation: none; }
}

/* the plot: absolutely placed columns, each segment its own rounded box */
.stb-plot { position: relative; width: 100%; touch-action: none; cursor: crosshair; }

.stb-base {
  position: absolute;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--stb-w12);}

.stb-col { position: absolute; top: 0; bottom: 0; }

.stb-bar,
.stb-esc {
  position: absolute;
  left: 0;
  right: 0;
  border-radius: var(--stb-r);
  transition:
    height 600ms cubic-bezier(0.22, 1, 0.36, 1) calc(var(--i) * 14ms),
    bottom 600ms cubic-bezier(0.22, 1, 0.36, 1) calc(var(--i) * 14ms),
    background-color 160ms ease;}

.stb-bar { background-color: var(--c); }

.stb-esc { background-color: var(--stb-alert); }

/* Mono: escalated is full ink, hatched, so it never reads as Identity */
.stb[data-colour="off"] .stb-esc {
  background-image: repeating-linear-gradient(-45deg, transparent 0 1.5px, var(--fill-slab, #ffffff) 1.5px 3px);}

/* scrubbing: the others step back by mixing toward the slab */
.stb[data-scrub] .stb-col:not([data-on]) .stb-bar {
  background-color: color-mix(in srgb, var(--c) 38%, var(--fill-slab, #ffffff));}

.stb[data-scrub] .stb-col:not([data-on]) .stb-esc {
  background-color: color-mix(in srgb, var(--stb-alert) 38%, var(--fill-slab, #ffffff));}

.stb-ring {
  position: absolute;
  top: 0;
  left: 0;
  box-sizing: border-box;
  border: 1.5px solid var(--stb-mute);
  border-radius: var(--stb-rr);
  pointer-events: none;
  opacity: 0;
  transition: opacity 160ms ease;}

.stb[data-scrub] .stb-ring { opacity: 1; }

/* the tooltip: beside the column, gliding on a spring */
.stb-tip {
  position: absolute;
  top: 0;
  left: 0;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--fill-slab, #ffffff);
  /* filled like the card, parted from the bars by a soft grey hairline */
  border: 1px solid color-mix(in srgb, var(--fill-on, #17181a) 10%, var(--fill-slab, #ffffff));
  font-size: 12px;
  line-height: 16px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 160ms ease;}

.stb[data-scrub] .stb-tip { opacity: 1; }

.stb-tip-head,
.stb-tip-row { display: flex; align-items: center; gap: 6px; white-space: nowrap; }

.stb-tip-head { justify-content: space-between; color: var(--stb-mute); margin-bottom: 2px; }

.stb-tip b { font-weight: 500; font-variant-numeric: tabular-nums; color: var(--fill-on, #17181a); }

.stb-tip-row span { flex: 1; color: var(--stb-soft); }

.stb-tip-row b { font-weight: 400; }

.stb-tip-row i {
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background-color: var(--c);}

.stb-tip-row[data-esc] i { background-color: var(--stb-alert); }

.stb[data-colour="off"] .stb-tip-row[data-esc] i {
  background-image: repeating-linear-gradient(-45deg, transparent 0 1.5px, var(--fill-slab, #ffffff) 1.5px 3px);}

/* one tiny footer: first and last date */
.stb-axis {
  display: flex;
  justify-content: space-between;
  margin-top: -8px;
  font-size: 11px;
  line-height: 14px;
  color: var(--stb-faint);
  font-variant-numeric: tabular-nums;}

@keyframes stb-pop {
  from { transform: translateY(0.18em); opacity: 0; filter: blur(2px); }
  to { transform: none; opacity: 1; filter: blur(0); }}


/* Firebase 360 panel: local observations only, responsive and independent. */
.fd-dialog{--bg:#0b1320;--panel:#131d2e;--panel-2:#1b273d;--text:#f4f6fa;--text-dim:#a4b1c7;--text-faint:#9aacc4;--border:#2a3a56;--accent:#22b8cf;color-scheme:dark;width:min(800px,calc(100vw - 16px));max-width:calc(100vw - 16px);max-height:calc(100dvh - 16px);padding:0;border:1px solid var(--border);border-radius:18px;background:var(--bg);color:var(--text);box-sizing:border-box;overflow:auto;font:14px/1.45 system-ui,sans-serif}
.fd-dialog::backdrop{background:rgba(2,6,23,.75)}
.fd-dialog *{box-sizing:border-box}
.fd-header{position:sticky;top:0;z-index:5;display:flex;justify-content:space-between;align-items:center;gap:10px;background:var(--panel);border-bottom:1px solid var(--border);padding:12px 14px}
.fd-header h2,.fd-header p{margin:0}
.fd-header h2{font-size:18px;color:var(--text)}
.fd-muted{color:var(--text-dim);font-size:12px;overflow-wrap:anywhere}
.fd-dialog>p.fd-muted{padding:0 14px;margin:8px 0 12px}
.fd-btn,.fd-seg,.fd-day,.fd-close,.fd-legend-row{border:1px solid var(--border);background:var(--panel-2);border-radius:10px;color:var(--text);min-height:44px;min-width:44px;font:inherit;cursor:pointer;padding:7px 10px}
.fd-close{font-size:24px;line-height:1;padding:0}
.fd-dialog button:focus-visible,.fd-dialog summary:focus-visible,.fd-dialog .rng-seg:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.fd-dialog button[aria-pressed=true]{background:#243b52;border-color:var(--accent);color:#fff}
.fd-dialog button:disabled{opacity:.5;cursor:default}
.fd-tools{padding:12px 14px 0;display:grid;gap:8px}
.fd-segment,.fd-actions{display:flex;gap:4px;flex-wrap:wrap}
.fd-segment{padding:3px;background:var(--panel);border:1px solid var(--border);border-radius:12px}
.fd-seg{flex:1;background:transparent;border-color:transparent}
.fd-actions .fd-btn{flex:1}
.fd-body{display:grid;gap:10px;padding:0 14px 14px;min-width:0}
.fd-kpis{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px}
.fd-kpi,.fd-card{min-width:0;overflow:hidden;background:var(--panel);border:1px solid var(--border);border-radius:14px;padding:10px;display:grid;gap:8px}
.fd-kpi .fd-number{--rng-ink:var(--text);--rng-cell:30px;--u:1px;height:30px;justify-content:flex-start;font-size:clamp(15px,4.8vw,24px);mask-image:none;font-variant-numeric:tabular-nums;overflow:hidden}
.fd-kpi .rng-col{height:30px}.fd-kpi .rng-strip>span{height:30px}
.fd-number .rng-aff{display:none}
.fd-section-title{margin:0;font-size:15px;color:var(--text)}
.fd-chart-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(100%,310px),1fr));gap:10px;align-items:start;min-width:0}
.fd-ring-host,.fd-bars-host{display:flex;justify-content:center;min-width:0;overflow:hidden}
.fd-ring-host .rng{flex:none;max-width:100%}
.fd-ring-host .rng-cap{max-width:114px;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}
.fd-ring-host .rng-exact{font-size:14px;max-width:120px;overflow-wrap:anywhere}
.fd-ring-host .rng-lab{display:none}
.fd-legend{display:grid;gap:4px}
.fd-legend-row,.fd-line{display:flex;align-items:center;gap:8px;text-align:left;min-width:0}
.fd-legend-row{width:100%;padding:6px 8px;font-size:12px}
.fd-dot{display:inline-block;flex:none;width:10px;height:10px;border-radius:3px}
.fd-label{flex:1;min-width:0;overflow-wrap:anywhere}
.fd-value,.fd-pct{flex:none;font-variant-numeric:tabular-nums}
.fd-pct{min-width:36px;text-align:right;color:var(--text-dim);font-size:11px}
.fd-line{padding:5px 0;justify-content:space-between;font-size:13px;border-bottom:1px solid var(--border)}
.fd-line strong{font-variant-numeric:tabular-nums}
.fd-bars-host .stb{border:0;background:transparent;max-width:100%;padding-top:4px;padding-bottom:4px}
.fd-bars-host .stb-seg-ctl{display:none!important}
.fd-bars-host .stb-tip{z-index:2}
.fd-bars-host .stb-esc{display:none}
.fd-bars-host .stb-axis{color:var(--text-dim)}
.fd-days{display:flex;flex-wrap:wrap;gap:4px}
.fd-day{flex:1;font-size:11px;padding:3px}
.fd-day.fd-missing{border-style:dashed;color:var(--text-dim)}
.fd-day-detail{min-height:40px;color:var(--text-dim);font-size:12px}
.fd-meter{display:flex;height:16px;border-radius:8px;overflow:hidden;background:var(--panel-2)}
.fd-meter>span{flex-basis:0;min-width:0}
.fd-details{border-top:1px solid var(--border);font-size:13px}
.fd-details>summary{cursor:pointer;min-height:44px;display:flex;align-items:center;font-weight:600}
.fd-events{list-style:none;padding:0;margin:0;display:grid;gap:5px;max-height:360px;overflow:auto}
.fd-event{display:grid;gap:2px;padding:8px;border-radius:8px;background:var(--panel-2);font-size:12px}
.fd-empty{font-size:13px;color:var(--text-dim);text-align:center;padding:16px 6px;margin:0}
@media(max-width:360px){.fd-body{padding-inline:9px}.fd-tools{padding-inline:9px}.fd-card{padding:8px}.fd-kpi{padding:8px}.fd-kpi .fd-number{font-size:18px}.fd-legend-row{gap:5px}}
@media(prefers-reduced-motion:reduce){.fd-dialog *,.fd-dialog *::before,.fd-dialog *::after{animation-duration:.01ms!important;transition-duration:.01ms!important}}
.fd-kpi .fd-number.fd-long{font-size:14px;display:block;overflow-wrap:anywhere;height:auto;min-height:30px;line-height:1.35}
