/*
 * Books charts.
 *
 * Palette "metals and patina", checked with the dataviz validator against the panel surface
 * (#fffefd light, #211e1b dark): seven categorical slots in a fixed order, adjacent CVD ΔE ≥ 10.3,
 * normal-vision ΔE ≥ 20.1 in both themes; the first three slots also pass all-pairs.
 *   1 verdigris  money in        2 bronze  money out        3 lapis   4 old gold   5 plum   6 moss   7 violet
 * Old gold sits at 2.99:1 on the light panel, so every chart ships direct labels or a figures table.
 * Lateness is an ordinal brick ramp (light end 2.21:1 light, 2.61:1 dark), "not due" is the
 * de-emphasis gray, and gold stays the one accent for the period you're in.
 */

:root {
  --viz-in: #018e7d;
  --viz-out: #c16e21;
  --viz-3: #335aa6;
  --viz-4: #b59026;
  --viz-5: #ab4a7d;
  --viz-6: #6d8c40;
  --viz-7: #6f4fa1;
  --viz-loss: #bc4a3f;
  --viz-late-1: #e49c8d;
  --viz-late-2: #d67161;
  --viz-late-3: #bc4a3f;
  --viz-late-4: #932b29;
  --viz-context: var(--chart);
  --viz-accent: var(--chart-last);
  --viz-total: var(--secondary);
  --viz-surface: var(--panel);
  --viz-grid: var(--line-soft);
  --viz-axis: var(--line-strong);
  --viz-on-dark: #fff;
  --viz-on-light: #1f1a16;
  --viz-good: var(--green);
  --viz-bad: var(--red)
}

:root[data-theme="dark"] {
  --viz-in: #33a795;
  --viz-out: #c47735;
  --viz-3: #5279c1;
  --viz-4: #b0922e;
  --viz-5: #bf6291;
  --viz-6: #7f9f53;
  --viz-7: #8d6cc2;
  --viz-loss: #d06358;
  --viz-late-1: #9c443b;
  --viz-late-2: #c65a4f;
  --viz-late-3: #e47d6d;
  --viz-late-4: #f7a695;
  --viz-context: oklch(.45 .012 75)
}

/* Tones: each mark reads its color from --c, each label inside a fill from --on */
.t-in { --c: var(--viz-in); --on: var(--viz-on-dark) }
.t-out { --c: var(--viz-out); --on: var(--viz-on-dark) }
.t-s3 { --c: var(--viz-3); --on: var(--viz-on-dark) }
.t-s4 { --c: var(--viz-4); --on: var(--viz-on-dark) }
.t-s5 { --c: var(--viz-5); --on: var(--viz-on-dark) }
.t-s6 { --c: var(--viz-6); --on: var(--viz-on-dark) }
.t-s7 { --c: var(--viz-7); --on: var(--viz-on-dark) }
.t-up { --c: var(--viz-in); --on: var(--viz-on-dark) }
.t-down { --c: var(--viz-out); --on: var(--viz-on-dark) }
.t-loss { --c: var(--viz-loss); --on: var(--viz-on-dark) }
.t-total { --c: var(--viz-total); --on: var(--viz-on-dark) }
.t-accent { --c: var(--viz-accent); --on: var(--viz-on-light) }
.t-context { --c: var(--viz-context); --on: var(--viz-on-light) }
.t-late1 { --c: var(--viz-late-1); --on: var(--viz-on-light) }
.t-late2 { --c: var(--viz-late-2); --on: var(--viz-on-dark) }
.t-late3 { --c: var(--viz-late-3); --on: var(--viz-on-dark) }
.t-late4 { --c: var(--viz-late-4); --on: var(--viz-on-dark) }
.t-current { --c: var(--viz-context); --on: var(--viz-on-light) }

:root[data-theme="dark"] .t-context,
:root[data-theme="dark"] .t-current,
:root[data-theme="dark"] .t-late1 {
  --on: var(--viz-on-dark)
}

:root[data-theme="dark"] .t-late4 {
  --on: var(--viz-on-light)
}

/* Figure frame */
.viz {
  margin: 0;
  display: grid;
  gap: 14px;
  min-width: 0;
  container-type: inline-size;
  --plot-h: 196px
}

.viz.compact {
  --plot-h: 132px;
  gap: 10px
}

.viz-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: .76rem;
  color: var(--secondary)
}

.viz-legend li {
  display: inline-flex;
  align-items: center;
  gap: 7px
}

.viz-key {
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: var(--c)
}

.viz-key.line {
  width: 14px;
  height: 2px;
  border-radius: 2px
}

.viz-frame {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-rows: var(--plot-h) auto;
  column-gap: 10px
}

.viz-y {
  position: relative;
  min-width: 2.6em;
  font-size: .7rem;
  line-height: 1;
  font-weight: 500;
  color: var(--sub);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  text-align: right
}

.viz-y span {
  position: absolute;
  right: 0;
  bottom: var(--b);
  transform: translateY(50%);
  white-space: nowrap
}

.viz-plot {
  position: relative;
  min-width: 0
}

.viz-grid i {
  position: absolute;
  left: 0;
  right: 0;
  bottom: var(--b);
  height: 1px;
  background: var(--viz-grid)
}

.viz-grid i.zero {
  background: var(--viz-axis)
}

.viz-x {
  grid-column: 2;
  display: grid;
  grid-template-columns: repeat(var(--n), minmax(0, 1fr));
  margin: 8px 0 0;
  padding: 0;
  list-style: none;
  font-size: .7rem;
  line-height: 1.2;
  color: var(--sub);
  text-align: center;
  font-variant-numeric: tabular-nums
}

.viz-x li {
  min-width: 0;
  overflow: hidden;
  text-overflow: clip;
  white-space: nowrap
}

.viz-x li.is-current {
  color: var(--ink);
  font-weight: 620
}

/*
  A narrow chart names every other column, and the names that stay are given the room of the ones
  that went: each is centred on its column and may run over its neighbours' empty places, where it
  used to be cut to its own column's width ("Dec 16" read "Dec").
*/
@container (max-width: 520px) {
  .viz-x.dense li {
    display: flex;
    justify-content: center;
    overflow: visible
  }

  .viz-x.dense li:nth-child(even) {
    visibility: hidden
  }
}

@container (max-width: 300px) {
  .viz-x.dense li:not(:nth-child(4n + 1)) {
    visibility: hidden
  }
}

/* Columns */
.viz-cols {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(var(--n), minmax(0, 1fr));
  margin: 0;
  padding: 0;
  list-style: none
}

.viz-col {
  position: relative;
  min-width: 0
}

.viz-hit {
  position: absolute;
  inset: 0 1px;
  display: flex;
  justify-content: center;
  gap: 2px;
  padding: 0 14%;
  border-radius: var(--r-sm);
  color: inherit;
  text-decoration: none;
  outline-offset: 1px;
  cursor: default
}

a.viz-hit {
  cursor: pointer
}

.viz-hit:hover,
.viz-hit:focus-visible,
.viz-hit.is-active {
  background: color-mix(in oklch, var(--ink) 4.5%, transparent)
}

.viz-lane {
  position: relative;
  flex: 0 1 24px;
  min-width: 2px;
  height: 100%
}

.viz-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: var(--b);
  height: var(--h);
  background: var(--c);
  box-sizing: border-box
}

.viz-bar.end {
  border-radius: 4px 4px 0 0
}

.viz-bar.neg.end {
  border-radius: 0 0 4px 4px
}

.viz-bar.on {
  border-bottom: 2px solid var(--viz-surface)
}

.viz-bar.neg.on {
  border-bottom: 0;
  border-top: 2px solid var(--viz-surface)
}

.viz-col.is-context .viz-bar {
  opacity: .36
}

.viz-hit:hover .viz-bar,
.viz-hit:focus-visible .viz-bar,
.viz-hit.is-active .viz-bar {
  opacity: 1;
  filter: saturate(1.06) brightness(1.04)
}

.viz-cap {
  position: absolute;
  left: 50%;
  bottom: calc(var(--b) + var(--h) + 5px);
  transform: translateX(-50%);
  font-size: .7rem;
  font-weight: 620;
  color: var(--ink);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  pointer-events: none
}

.viz-cap.neg {
  bottom: auto;
  top: calc(100% - var(--b) + 5px)
}

/* The strip under a column chart: one signed figure per column on its own small scale */
.viz-strip {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  column-gap: 10px;
  align-items: center;
  margin-top: -2px
}

.viz-strip>span {
  min-width: 2.6em;
  font-size: .7rem;
  font-weight: 560;
  color: var(--secondary);
  text-align: right;
  line-height: 1.15
}

.viz-strip ol {
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--n), minmax(0, 1fr));
  height: 46px;
  margin: 0;
  padding: 0;
  list-style: none
}

.viz-strip ol::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 1px;
  background: var(--viz-axis)
}

.viz-strip li {
  position: relative;
  display: flex;
  justify-content: center
}

.viz-strip li i {
  position: absolute;
  bottom: 50%;
  width: min(24px, 52%);
  height: var(--h);
  border-radius: 4px 4px 0 0;
  background: var(--c)
}

.viz-strip li.neg i {
  bottom: auto;
  top: 50%;
  border-radius: 0 0 4px 4px
}

.viz-strip li.is-context i {
  opacity: .36
}

.viz-strip .strip-values {
  grid-column: 2;
  height: auto;
  margin-top: 4px;
  font-size: .68rem;
  font-weight: 640;
  color: var(--ink);
  font-variant-numeric: tabular-nums
}

.viz-strip .strip-values::before {
  display: none
}

.viz-strip .strip-values li {
  justify-content: center;
  white-space: nowrap
}

.viz-strip .strip-values li.end {
  justify-content: flex-end
}

.viz-strip .strip-values li.start {
  justify-content: flex-start
}

@container (max-width: 560px) {
  .viz-strip .strip-values li:not(.end) {
    visibility: hidden
  }
}

.viz-strip>span {
  grid-row: span 2;
  align-self: start;
  padding-top: 16px
}

/* Lines */
.viz-line .viz-plot {
  outline-offset: 4px;
  border-radius: 4px
}

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

.viz-line path.line {
  fill: none;
  stroke: var(--c);
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-linecap: round
}

.viz-line path.ahead {
  stroke-dasharray: 2 5;
  opacity: .9
}

.viz-line path.area {
  fill: var(--c);
  opacity: .1;
  stroke: none
}

.viz-end,
.viz-dot {
  position: absolute;
  width: 8px;
  height: 8px;
  margin: -4px 0 0 -4px;
  border-radius: 50%;
  background: var(--c);
  box-shadow: 0 0 0 2px var(--viz-surface);
  pointer-events: none
}

.viz-cross {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--x);
  width: 1px;
  background: var(--viz-axis);
  pointer-events: none
}

.viz-cross[hidden] {
  display: none
}

.viz-ahead-mark {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--x);
  border-left: 1px solid var(--viz-axis);
  pointer-events: none
}

.viz-ahead-mark span {
  position: absolute;
  top: -2px;
  left: 6px;
  font-size: .68rem;
  color: var(--sub);
  white-space: nowrap
}

.viz-xl {
  position: relative;
  grid-column: 2;
  height: 1.2em;
  margin-top: 8px;
  font-size: .7rem;
  color: var(--sub)
}

.viz-xl span {
  position: absolute;
  left: var(--x);
  transform: translateX(-50%);
  white-space: nowrap
}

.viz-xl span:first-child {
  transform: none
}

.viz-xl span:last-child {
  transform: translateX(-100%)
}

/* Sparklines */
.viz-spark {
  position: relative;
  display: block;
  height: 34px;
  min-width: 64px
}

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

.viz-spark path.line {
  fill: none;
  stroke: var(--viz-context);
  stroke-width: 1.75;
  stroke-linejoin: round;
  stroke-linecap: round
}

.viz-spark path.area {
  fill: var(--c, var(--viz-context));
  opacity: .08
}

.viz-spark .viz-end {
  width: 7px;
  height: 7px;
  margin: -3.5px 0 0 -3.5px;
  background: var(--c, var(--viz-accent))
}

/* Ranked bars: largest first, one baseline, square at the baseline and rounded at the data end */
.viz-rank {
  display: grid;
  margin: 0;
  padding: 0;
  list-style: none
}

.viz-rank li+li {
  border-top: 1px solid var(--line-soft)
}

.viz-rank a,
.viz-rank .row {
  display: grid;
  grid-template-columns: minmax(0, 11fr) minmax(0, 9fr) minmax(6.2em, auto);
  grid-template-areas: "name bar amount";
  align-items: center;
  gap: 3px 14px;
  padding: 9px 2px;
  color: inherit;
  border-radius: var(--r-xs)
}

.viz-rank a:hover .rank-name,
.viz-rank a:focus-visible .rank-name {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: .2em
}

.rank-name {
  grid-area: name;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: .85rem;
  font-weight: 540
}

.rank-name small {
  margin-left: 6px;
  color: var(--sub);
  font-weight: 500
}

.rank-bar {
  grid-area: bar;
  display: block;
  height: 10px;
  min-width: 0
}

.rank-bar i {
  display: block;
  width: var(--w);
  min-width: 3px;
  height: 100%;
  border-radius: 0 4px 4px 0;
  background: var(--c)
}

.rank-figs {
  grid-area: amount;
  display: grid;
  justify-items: end;
  gap: 1px;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1
}

.rank-figs b {
  font-size: .85rem;
  font-weight: 620
}

.rank-figs small {
  font-size: .7rem;
  color: var(--sub);
  white-space: nowrap
}

.rank-figs .up,
.rank-figs .down {
  color: var(--secondary)
}

@container (max-width: 430px) {
  .viz-rank a,
  .viz-rank .row {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "name amount" "bar bar"
  }
}

/* Segmented bars: one whole split into parts */
.viz-seg {
  display: flex;
  gap: 2px;
  min-width: 0
}

.viz-seg.tall {
  height: 28px
}

.viz-seg.thin {
  height: 8px
}

.viz-seg>* {
  position: relative;
  display: flex;
  align-items: center;
  min-width: 2px;
  background: var(--c);
  color: var(--on);
  text-decoration: none;
  overflow: visible
}

.viz-seg.tall>* {
  border-radius: 4px
}

.viz-seg.thin>*:first-child {
  border-radius: 999px 0 0 999px
}

.viz-seg.thin>*:last-child {
  border-radius: 0 999px 999px 0
}

.viz-seg.thin>*:only-child {
  border-radius: 999px
}

.viz-seg.tall b {
  padding: 0 8px;
  font-size: .72rem;
  font-weight: 640;
  white-space: nowrap;
  font-variant-numeric: tabular-nums
}

.viz-seg.tall b.no-fit {
  visibility: hidden
}

.viz-seg a:hover,
.viz-seg a:focus-visible,
.viz-seg .is-active {
  filter: brightness(1.07) saturate(1.05)
}

.viz-seg-key {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
  font-size: .76rem;
  color: var(--secondary)
}

.viz-seg-key li {
  display: inline-flex;
  align-items: center;
  gap: 7px
}

.viz-seg-key b {
  color: var(--ink);
  font-weight: 600;
  font-variant-numeric: tabular-nums
}

/* Waterfall */
.viz-wf .viz-col::after {
  content: "";
  position: absolute;
  left: calc(50% + 12px);
  right: calc(-50% + 12px);
  bottom: var(--l);
  height: 1px;
  background: var(--viz-axis);
  pointer-events: none
}

.viz-wf .viz-col.last::after {
  display: none
}

.viz-wf .viz-bar {
  border-radius: 4px
}

.viz-wf .viz-lane {
  flex-basis: 34px
}

/* a long word under a narrow column breaks, at a syllable where the language is known, and does not run over its neighbour */
.viz-x.wrap li {
  white-space: normal;
  overflow: visible;
  overflow-wrap: anywhere;
  hyphens: auto;
  padding: 0 2px;
  text-wrap: balance
}

@container (max-width: 430px) {
  .viz-x.wrap li {
    padding: 0;
    font-size: .68rem
  }
}

/* Meters: the fill carries the state, the track is a lighter step of the same hue */
.viz-meter {
  display: block;
  height: 8px;
  border-radius: 999px;
  background: color-mix(in oklch, var(--c) 18%, var(--viz-surface));
  overflow: hidden
}

.viz-meter i {
  display: block;
  width: var(--w);
  height: 100%;
  border-radius: inherit;
  background: var(--c)
}

/* Figures table: the accessible twin of every chart */
.viz-figures {
  font-size: .8rem
}

.viz-figures summary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--secondary);
  font-weight: 560;
  cursor: pointer;
  list-style: none;
  border-radius: var(--r-xs)
}

.viz-figures summary::-webkit-details-marker {
  display: none
}

.viz-figures summary:hover {
  color: var(--ink)
}

.viz-figures summary .icon {
  transition: transform .2s var(--ease-out)
}

.viz-figures[open] summary .icon {
  transform: rotate(180deg)
}

.viz-figures table {
  width: 100%;
  margin-top: 10px;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1
}

.viz-figures th,
.viz-figures td {
  padding: 6px 10px 6px 0;
  border-bottom: 1px solid var(--line-soft);
  text-align: right;
  white-space: nowrap
}

.viz-figures th:first-child,
.viz-figures td:first-child {
  text-align: left
}

.viz-figures thead th {
  font-weight: 600;
  color: var(--secondary)
}

/* Tooltip: one for the page, values lead and names follow */
.viz-tip {
  position: fixed;
  z-index: 80;
  left: 0;
  top: 0;
  min-width: 176px;
  max-width: 300px;
  padding: 10px 12px 11px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow-lg);
  font-size: .78rem;
  line-height: 1.35;
  pointer-events: none;
  opacity: 0;
  transform: translateY(3px);
  transition: opacity .12s var(--ease-out), transform .12s var(--ease-out)
}

.viz-tip.show {
  opacity: 1;
  transform: none
}

.viz-tip header {
  margin-bottom: 7px;
  font-weight: 600;
  color: var(--secondary)
}

.viz-tip dl {
  display: grid;
  gap: 4px;
  margin: 0
}

.viz-tip dl div {
  display: grid;
  grid-template-columns: 14px auto minmax(0, 1fr);
  align-items: center;
  gap: 8px
}

.viz-tip dt {
  font-weight: 640;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  text-align: right
}

.viz-tip dd {
  margin: 0;
  color: var(--secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap
}

.viz-tip .viz-key {
  width: 14px;
  height: 2px;
  border-radius: 2px
}

.viz-tip .viz-key.blank {
  background: transparent
}

.viz-tip p {
  margin: 8px 0 0;
  padding-top: 7px;
  border-top: 1px solid var(--line-soft);
  color: var(--sub);
  font-size: .72rem
}

/* Performance page */
.books-views {
  display: flex;
  gap: 2px;
  margin: -12px 0 22px;
  overflow-x: auto;
  scrollbar-width: none
}

.books-views a {
  padding: 7px 12px;
  border-radius: var(--r-sm);
  font-size: .86rem;
  font-weight: 560;
  color: var(--secondary);
  white-space: nowrap
}

.books-views a:hover {
  color: var(--ink);
  background: var(--hover)
}

.books-views a[aria-current] {
  color: var(--ink);
  background: var(--hover)
}

.pf-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  margin-bottom: 18px
}

.pf-filters .presets {
  flex-basis: auto
}

.pf-filters form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
  margin-left: auto
}

.pf-filters label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: .8rem;
  font-weight: 560;
  color: var(--secondary)
}

.pf-filters select,
.pf-filters input[type="date"] {
  width: auto;
  min-height: 34px;
  padding: 5px 10px;
  font-size: .8rem
}

.pf-range {
  margin: -4px 0 18px;
  font-size: .84rem;
  color: var(--secondary)
}

.pf-range b {
  color: var(--ink);
  font-weight: 600
}

[data-viz-scope] {
  transition: opacity .2s var(--ease-out)
}

[data-viz-scope].is-refreshing {
  opacity: .55;
  pointer-events: none
}

.kpi-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin: 0 0 20px;
  overflow: hidden
}

.kpi {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 4px;
  min-width: 0;
  padding: 18px 20px 16px;
  border-left: 1px solid var(--line-soft)
}

.kpi:first-child {
  border-left: 0
}

.kpi dt {
  font-size: .8rem;
  font-weight: 560;
  color: var(--secondary)
}

.kpi dd {
  margin: 0
}

.kpi-figure {
  display: block;
  font-size: clamp(1.45rem, 2.1vw, 1.85rem);
  font-weight: 590;
  font-stretch: 108%;
  letter-spacing: -.04em;
  line-height: 1.12;
  white-space: nowrap
}

.kpi-figure.negative {
  color: var(--ink)
}

.kpi-delta {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 2px 6px;
  font-size: .76rem;
  color: var(--sub)
}

.kpi-delta b {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-weight: 640;
  color: var(--secondary)
}

.kpi-delta b.good {
  color: var(--viz-good)
}

.kpi-delta b.bad {
  color: var(--viz-bad)
}

.kpi-delta b .icon {
  width: 13px;
  height: 13px
}

.kpi-note {
  font-size: .76rem;
  color: var(--sub)
}

.kpi .viz-spark {
  margin-top: 6px
}

.pf-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 20px
}

.pf-card {
  grid-column: span 6;
  display: grid;
  align-content: start;
  gap: 16px;
  padding: 20px 22px 18px;
  min-width: 0;
  container-type: inline-size
}

.pf-card.wide {
  grid-column: span 8
}

.pf-card.side {
  grid-column: span 4
}

.pf-card.full {
  grid-column: 1 / -1
}

/* a card that stands alone above the grid keeps the grid's own distance from it */
.pf-card + .pf-grid {
  margin-top: 20px
}

.pf-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 4px 16px
}

.pf-head h2 {
  font-size: 1rem
}

.pf-head p {
  margin-top: 2px;
  font-size: .8rem;
  color: var(--secondary)
}

.pf-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding-top: 2px
}

.pf-total {
  font-size: .8rem;
  color: var(--secondary)
}

.pf-total b {
  color: var(--ink);
  font-weight: 620;
  font-variant-numeric: tabular-nums
}

.pf-empty {
  display: grid;
  place-items: center;
  gap: 6px;
  min-height: 150px;
  padding: 20px;
  border: 1px dashed var(--line);
  border-radius: var(--r-md);
  text-align: center;
  font-size: .84rem;
  color: var(--secondary)
}

/* What changed */
.changes {
  display: grid;
  margin: 0;
  padding: 0;
  list-style: none
}

.changes li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px 12px;
  padding: 12px 0;
  border-top: 1px solid var(--line-soft)
}

.changes li:first-child {
  border-top: 0;
  padding-top: 2px
}

.changes p {
  font-size: .85rem;
  line-height: 1.45
}

.changes a.text-link {
  font-size: .78rem
}

.change-bar {
  grid-column: 1 / -1;
  display: block;
  height: 6px;
  border-radius: 999px;
  background: color-mix(in oklch, var(--c) 16%, var(--viz-surface))
}

.change-bar i {
  display: block;
  width: var(--w);
  min-width: 4px;
  height: 100%;
  border-radius: inherit;
  background: var(--c)
}

.change-actions {
  display: flex;
  gap: 12px;
  align-items: center
}

.change-actions button {
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  font-size: .78rem;
  font-weight: 560;
  color: var(--secondary);
  cursor: pointer;
  display: inline-flex;
  gap: 5px;
  align-items: center
}

.change-actions button:hover {
  color: var(--ink)
}

.change-actions .icon {
  width: 14px;
  height: 14px
}

/* Inline figures on other pages */
.acct-spark {
  width: 84px;
  height: 26px;
  min-width: 0
}

/*
  An account's row: its name, what waits for review, its balance over the last weeks, the balance.
  Each has its own column, so a row with nothing to review still ends where the others do.
*/
.account-list {
  container-type: inline-size
}

.account-list a {
  grid-template-columns: minmax(0, 1fr) auto auto auto
}

.account-list .acct-name {
  grid-column: 1
}

.account-list .review-chip {
  grid-column: 2
}

.account-list .acct-spark {
  grid-column: 3
}

.account-list .acct-balance {
  grid-column: 4
}

/* in a narrow card: the name and the balance, and what waits for review under the name */
@container (max-width: 440px) {
  .account-list a {
    grid-template-columns: minmax(0, 1fr) auto
  }

  .account-list .acct-balance {
    grid-area: 1 / 2;
    align-self: start
  }

  .account-list .review-chip {
    grid-area: 2 / 1;
    justify-self: start
  }

  .account-list .acct-spark {
    display: none
  }
}

.cash-events a.cash-more {
  display: inline-flex;
  margin-top: 10px;
  padding: 0;
  border: 0;
  font-size: .8rem
}

.tile-aging {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line-soft)
}

.tile-aging h3 {
  margin-bottom: 8px;
  font-size: .78rem;
  font-weight: 600;
  color: var(--secondary)
}

.pl-tile .viz,
.spend-tile .viz-rank {
  margin-top: 10px
}

.spend-tile .viz-rank a {
  padding: 7px 2px
}

@media (max-width: 560px) {
  .acct-spark {
    display: none
  }
}

.report-chart {
  margin: 0 0 20px;
  padding: 20px 22px 18px;
  container-type: inline-size
}

.report-chart .pf-head {
  margin-bottom: 14px
}

.statement-sheet .viz-seg {
  margin-top: 2px
}

/* Balance sheet: the two sides of the equation as two bars of one length */
.bs-bars {
  display: grid;
  gap: 18px
}

.bs-row {
  display: grid;
  grid-template-columns: 11em minmax(0, 1fr);
  align-items: start;
  gap: 16px
}

.bs-name {
  padding-top: 6px;
  font-size: .82rem;
  font-weight: 600;
  color: var(--secondary)
}

.bs-row .viz-seg-key {
  margin-top: 8px
}

/* Diverging bars: profit to the right of zero, loss to the left */
.viz-div {
  display: grid;
  margin: 0;
  padding: 0;
  list-style: none
}

.viz-div li {
  display: grid;
  grid-template-columns: minmax(0, 12em) minmax(0, 1fr) minmax(6.5em, auto);
  align-items: center;
  gap: 14px;
  padding: 8px 0;
  border-top: 1px solid var(--line-soft)
}

.viz-div li:first-child {
  border-top: 0
}

.div-name {
  display: grid;
  min-width: 0;
  font-size: .85rem;
  font-weight: 560
}

.div-name small {
  font-size: .72rem;
  font-weight: 500;
  color: var(--sub);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis
}

.div-track {
  position: relative;
  display: block;
  height: 12px
}

.div-track::before {
  content: "";
  position: absolute;
  left: 50%;
  top: -6px;
  bottom: -6px;
  width: 1px;
  background: var(--viz-axis)
}

.div-track i {
  position: absolute;
  left: 50%;
  top: 0;
  width: var(--w);
  min-width: 3px;
  height: 100%;
  border-radius: 0 4px 4px 0;
  background: var(--c)
}

.div-track i.neg {
  left: auto;
  right: 50%;
  border-radius: 4px 0 0 4px
}

.viz-div b {
  text-align: right;
  font-size: .85rem;
  font-weight: 620;
  font-variant-numeric: tabular-nums
}

/* Budget meters with a tick for how far through the year today is */
.viz-meters {
  display: grid;
  gap: 14px;
  margin: 0;
  padding: 0;
  list-style: none
}

.viz-meters li {
  display: grid;
  grid-template-columns: 7em minmax(0, 1fr) minmax(0, 15em);
  align-items: center;
  gap: 14px
}

.meter-name {
  font-size: .85rem;
  font-weight: 600
}

.viz-meter.pace {
  position: relative;
  height: 12px;
  overflow: visible
}

.viz-meter.pace::after {
  content: "";
  position: absolute;
  left: var(--pace);
  top: -5px;
  bottom: -5px;
  width: 2px;
  margin-left: -1px;
  border-radius: 2px;
  background: var(--ink)
}

.meter-figs {
  display: grid;
  font-size: .8rem;
  font-variant-numeric: tabular-nums
}

.meter-figs small {
  font-size: .74rem;
  font-weight: 600
}

.meter-figs small.good {
  color: var(--viz-good)
}

.meter-figs small.bad {
  color: var(--viz-bad)
}

@container (max-width: 560px) {
  .bs-row,
  .viz-meters li {
    grid-template-columns: minmax(0, 1fr)
  }

  .bs-row {
    gap: 6px
  }

  .bs-name {
    padding-top: 0
  }

  .viz-div li {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "name value" "bar bar"
  }

  .div-name {
    grid-area: name
  }

  .div-track {
    grid-area: bar
  }

  .viz-div b {
    grid-area: value
  }
}

.share-bar {
  display: inline-block;
  width: 64px;
  height: 6px;
  margin-right: 10px;
  vertical-align: middle;
  border-radius: 0 3px 3px 0;
  background: linear-gradient(90deg, var(--c) var(--w), transparent var(--w))
}

/* Custom dates sit behind the last chip */
.pf-custom {
  position: relative
}

.pf-custom summary {
  list-style: none;
  cursor: pointer
}

.pf-custom summary::-webkit-details-marker {
  display: none
}

.pf-custom-form {
  position: absolute;
  z-index: 20;
  top: calc(100% + 8px);
  left: 0;
  display: grid;
  gap: 10px;
  width: min(280px, 86vw);
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--panel);
  box-shadow: var(--shadow-lg)
}

.pf-custom-form label {
  display: grid;
  gap: 4px
}

.pf-custom-form input {
  width: 100%
}

/* Cash flow */
.viz-key.dotted {
  background: repeating-linear-gradient(90deg, var(--c) 0 2px, transparent 2px 5px)
}

.viz-key.spark-key {
  width: 11px;
  height: 11px;
  border-radius: 0;
  background: var(--viz-accent);
  clip-path: path("M5.5 0C5.8 3.6 6.5 4.4 11 5.5C6.5 6.1 5.8 7 5.5 11C5.1 7 4.4 6.1 0 5.5C4.4 4.4 5.1 3.6 5.5 0Z")
}

.viz-payday {
  position: absolute;
  width: 15px;
  height: 15px;
  margin: -7.5px 0 0 -7.5px;
  color: var(--viz-accent);
  filter: drop-shadow(0 0 2px var(--viz-surface)) drop-shadow(0 0 1px var(--viz-surface));
  pointer-events: none
}

.viz-payday svg {
  display: block;
  width: 100%;
  height: 100%
}

.viz-low {
  position: absolute;
  pointer-events: none
}

.viz-low i {
  position: absolute;
  width: 9px;
  height: 9px;
  margin: -4.5px 0 0 -4.5px;
  border: 2px solid var(--viz-surface);
  border-radius: 50%;
  background: var(--ink);
  box-sizing: content-box;
  transform: translate(-2px, -2px)
}

.viz-low b {
  position: absolute;
  top: 10px;
  left: 0;
  transform: translateX(-50%);
  padding: 2px 6px;
  border-radius: 999px;
  background: var(--panel);
  box-shadow: 0 0 0 1px var(--line);
  font-size: .7rem;
  font-weight: 640;
  white-space: nowrap;
  font-variant-numeric: tabular-nums
}

/* The label keeps clear of the dates under the plot and of the plot's two ends */
.viz-low.is-above b {
  top: auto;
  bottom: 10px
}

.viz-low.is-end b {
  left: auto;
  right: -10px;
  transform: none
}

.viz-low.is-start b {
  left: -10px;
  transform: none
}

.viz-rank.sources .row {
  grid-template-columns: minmax(0, 8fr) minmax(0, 7fr) minmax(6.6em, auto)
}

.cash-items {
  width: 100%;
  border-collapse: collapse;
  font-size: .84rem
}

.cash-items th,
.cash-items td {
  padding: 9px 12px 9px 0;
  border-bottom: 1px solid var(--line-soft);
  text-align: left;
  vertical-align: top
}

.cash-items thead th {
  font-size: .76rem;
  font-weight: 600;
  color: var(--secondary)
}

.cash-items .num {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1
}

.cash-items td.in {
  color: var(--green)
}

.cash-items td:first-child {
  white-space: nowrap;
  color: var(--secondary)
}

.cash-items .sub {
  display: block;
  margin-top: 2px;
  font-size: .74rem;
  color: var(--sub)
}

.cash-items .sub.late {
  color: var(--red)
}

.source-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--hover);
  font-size: .72rem;
  font-weight: 600;
  color: var(--secondary);
  white-space: nowrap
}

.source-tag.src-planned {
  background: var(--gold-soft);
  color: var(--gold-ink);
  box-shadow: inset 0 0 0 1px var(--gold-line)
}

.source-tag.src-expected {
  background: var(--blue-bg);
  color: var(--blue)
}

.plan-list {
  display: grid;
  margin: 0;
  padding: 0;
  list-style: none
}

.plan-list li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 14px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line-soft)
}

.plan-name {
  display: grid;
  min-width: 0
}

.plan-name b {
  font-size: .88rem;
  font-weight: 600
}

.plan-name small {
  font-size: .76rem;
  color: var(--sub)
}

.plan-amount {
  font-weight: 620;
  font-variant-numeric: tabular-nums
}

.plan-amount.in {
  color: var(--green)
}

.plan-form .form-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr))
}

.plan-form:has(select[name="repeat"] option[value="once"]:checked) .field:has([name="until"]) {
  visibility: hidden
}

.source-group+.source-group {
  margin-top: 6px
}

.source-group h3 {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 2px 2px 6px;
  font-size: .8rem;
  font-weight: 600;
  color: var(--secondary)
}

.source-group h3 b {
  color: var(--ink);
  font-weight: 620;
  font-variant-numeric: tabular-nums
}

@media (max-width: 760px) {
  .plan-form .form-grid {
    grid-template-columns: minmax(0, 1fr)
  }

  .cash-items th:nth-child(3),
  .cash-items td:nth-child(3) {
    display: none
  }
}

/* Entrance: the main chart rises once, nothing else moves on its own */
@media (prefers-reduced-motion: no-preference) {
  .viz-rise .viz-bar {
    transform-origin: 50% 100%;
    animation: viz-rise .55s var(--ease-out) both;
    animation-delay: calc(var(--i, 0) * 28ms)
  }

  .viz-rise .viz-bar.neg {
    transform-origin: 50% 0
  }

  @keyframes viz-rise {
    from {
      transform: scaleY(0)
    }
  }
}

@media (max-width: 1100px) {
  .pf-card.wide,
  .pf-card.side {
    grid-column: 1 / -1
  }
}

@media (max-width: 900px) {
  .kpi-row {
    grid-template-columns: repeat(2, minmax(0, 1fr))
  }

  .kpi:nth-child(3) {
    border-left: 0
  }

  .kpi:nth-child(n + 3) {
    border-top: 1px solid var(--line-soft)
  }

  .pf-card {
    grid-column: 1 / -1
  }

  .pf-filters form {
    margin-left: 0
  }
}

@media (max-width: 560px) {
  .viz {
    --plot-h: 164px
  }

  .pf-card {
    padding: 16px 16px 14px
  }

  .kpi {
    padding: 15px 16px 13px
  }
}

@media (max-width: 420px) {
  .kpi-row {
    grid-template-columns: minmax(0, 1fr)
  }

  .kpi {
    border-left: 0;
    border-top: 1px solid var(--line-soft)
  }

  .kpi:first-child {
    border-top: 0
  }
}

@media print {
  .viz-tip,
  .books-views,
  .pf-filters,
  .change-actions {
    display: none !important
  }

  .viz-bar,
  .viz-seg>*,
  .rank-bar i,
  .viz-strip li i,
  .viz-meter i {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact
  }
}

@media (forced-colors: active) {
  .viz-bar,
  .viz-seg>*,
  .rank-bar i,
  .viz-strip li i,
  .viz-meter i,
  .viz-key,
  .change-bar i {
    forced-color-adjust: none;
    background: CanvasText
  }

  .t-out .viz-bar,
  .viz-bar.t-out,
  .viz-key.t-out,
  .viz-seg>.t-late2,
  .viz-seg>.t-s4 {
    background: repeating-linear-gradient(45deg, CanvasText 0 2px, Canvas 2px 5px)
  }

  .viz-seg>.t-late3,
  .viz-seg>.t-s5,
  .viz-bar.t-s5 {
    background: repeating-linear-gradient(135deg, CanvasText 0 2px, Canvas 2px 5px)
  }

  .viz-line path.line {
    stroke: CanvasText
  }
}

/* ---------- Cash scenarios (books/cash_flow.html, books/cash_scenario.html) ---------- */

.scenario-reading {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin: 0 0 16px
}

.scenario-reading .icon {
  width: 16px;
  height: 16px
}

.scenario-table th[scope="row"] {
  font-weight: 560;
  color: var(--secondary);
  white-space: nowrap
}

.scenario-table thead th .viz-key {
  margin-inline-end: 6px;
  vertical-align: middle
}

.scenario-table td.negative {
  color: var(--red)
}

.scenario-table td.in {
  color: var(--green)
}

.scenario-table td small.sub {
  white-space: normal;
  max-width: 24ch;
  margin-inline-start: auto
}

.scenario-links {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin-top: 6px
}

.scenario-pick {
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 10px 16px
}

.scenario-pick fieldset {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  margin: 0;
  padding: 0;
  border: 0
}

.scenario-pick legend {
  width: 100%;
  margin-bottom: 6px;
  font-size: .78rem;
  color: var(--secondary)
}

.scenario-pick label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: .84rem
}

.scenario-new > summary {
  list-style: none;
  width: max-content
}

.scenario-new > summary::-webkit-details-marker {
  display: none
}

.scenario-new[open] > summary {
  margin-bottom: 14px
}

.scenario-form .form-grid {
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr))
}

.scenario-remove {
  padding-top: 4px
}

.scenario-items:has(select[name$="repeat"] option[value="once"]:checked) .field:has([name$="until"]) {
  visibility: hidden
}
