/* Portfolio workspace (v2): hero, performance, allocation, risk, holdings, activity.
   Rendered by js/portfolio-view.js. House rules: no cards — sections are spacing and a
   rule above; figures sit in hairline-divided rows; only floating things (tooltips) and
   small data marks have a fill; every chart has hover, touch and keyboard. */

#portfolio-page .portfolio-backdrop {
  display: grid;
  gap: clamp(1.75rem, 3vw, 2.75rem);
  min-width: 0;
}
#portfolio-page :is(.pf-hero, .pf-section) {
  min-width: 0;
  font-variant-numeric: tabular-nums;
}

/* Section tabs with the one page action on the same row, right-aligned. -------------- */
/* One column the width of the page: a row that can scroll (the tabs on phones) must
   never widen the whole workspace. */
#portfolio-page .portfolio-shell { grid-template-columns: minmax(0, 1fr); }
#portfolio-page .portfolio-section-bar {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin: 0;
}
#portfolio-page .portfolio-section-bar .portfolio-section-tabs {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  width: min(36rem, 100%);
  margin: 0;
}
#portfolio-page .portfolio-section-bar .portfolio-topbar { flex: 0 0 auto; width: auto; align-self: center; }
/* Actions are text in the accent colour, not filled buttons: the tab row's and the
   first-run card's alike. */
#portfolio-page :is(.portfolio-section-bar .portfolio-add-button, .portfolio-onboarding-cta) {
  width: auto;
  min-height: 42px;
  padding: 0 .15rem;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  color: var(--accent);
  font-weight: 750;
  transform: none;
}
#portfolio-page :is(.portfolio-section-bar .portfolio-add-button, .portfolio-onboarding-cta):hover {
  border: 0;
  background: transparent;
  color: var(--accent-strong);
  transform: none;
}
#portfolio-page :is(.portfolio-section-bar .portfolio-add-button, .portfolio-onboarding-cta):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#portfolio-page .portfolio-activity-view { border-top: 0; padding-top: 0; }
#portfolio-page .portfolio-section-tabs .pf-tab-short { display: none; }

/* Shared pieces -------------------------------------------------------------------- */
.pf-term {
  cursor: help;
  text-decoration: underline dotted color-mix(in srgb, var(--muted) 55%, transparent);
  text-underline-offset: 3px;
}
.pf-term:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px; }
.pf-muted { color: var(--muted); }
#portfolio-page .positive { color: var(--positive); }
#portfolio-page .negative { color: var(--negative); }
.pf-empty {
  margin: 0;
  padding: 1.25rem 0;
  color: var(--muted);
  font-size: .86rem;
}
.pf-empty.is-error { color: var(--negative); }
.pf-bar {
  position: relative;
  display: block;
  height: 4px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--hairline);
}
.pf-bar > i {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: inherit;
  background: var(--swatch, var(--accent));
}

.pf-section {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
  padding-top: clamp(1rem, 1.6vw, 1.35rem);
  border-top: 1px solid var(--border);
}
.pf-section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: .75rem 1.25rem;
}
.pf-section-title {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: .35rem .85rem;
  min-width: 0;
}
.pf-section-title h3 {
  margin: 0;
  color: var(--text);
  font-family: var(--font-display);
  font-size: clamp(1.05rem, 1.3vw, 1.25rem);
  font-weight: 750;
  letter-spacing: -.01em;
}
.pf-count { color: var(--muted); font-size: .8rem; }

/* Text toggles: the pressed option is underlined, like the range tabs. */
.pf-switch {
  display: inline-flex;
  gap: 2px;
  border: 0;
  background: transparent;
}
.pf-switch button {
  min-height: 36px;
  padding: 0 .7rem;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted-2);
  font: inherit;
  font-size: .78rem;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  transition: color var(--transition-fast), box-shadow var(--transition-fast);
}
.pf-switch button:hover { color: var(--text); }
.pf-switch button:is([aria-pressed="true"], [aria-selected="true"]) {
  color: var(--text);
  box-shadow: inset 0 -2px 0 var(--accent);
}
.pf-switch button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.pf-switch button span { margin-left: .2rem; color: var(--muted); font-weight: 600; }

/* Hero ----------------------------------------------------------------------------- */
.pf-hero {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
  align-items: end;
  gap: 1.5rem clamp(1.5rem, 4vw, 4rem);
  padding-block: 0 clamp(.25rem, 1vw, .75rem);
}
.pf-hero-main { display: grid; gap: .55rem; min-width: 0; }
.pf-label { justify-self: start; color: var(--muted); font-size: .8rem; font-weight: 650; }
.pf-hero-value {
  color: var(--text);
  font-family: var(--font-display);
  font-size: clamp(2.3rem, 5vw, 3.6rem);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -.03em;
  overflow-wrap: anywhere;
}
.pf-hero-moves {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem 1.75rem;
  margin: .35rem 0 0;
}
.pf-hero-moves > div { display: flex; align-items: baseline; gap: .55rem; }
.pf-hero-moves dt { color: var(--muted); font-size: .8rem; font-weight: 650; }
.pf-hero-moves dd { margin: 0; color: var(--text); font-size: 1rem; font-weight: 750; }
.pf-hero-moves dd small { margin-left: .2rem; font-size: .86rem; font-weight: 650; }

.pf-hero-facts {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin: 0;
}
.pf-hero-facts > div {
  display: grid;
  gap: .3rem;
  min-width: 0;
  padding: .2rem 0 .2rem 1rem;
  border-left: 1px solid var(--hairline);
}
.pf-hero-facts dt { justify-self: start; color: var(--muted); font-size: .76rem; font-weight: 650; white-space: nowrap; }
.pf-hero-facts dd {
  margin: 0;
  color: var(--text);
  font-size: clamp(.98rem, 1.3vw, 1.15rem);
  font-weight: 750;
  overflow-wrap: anywhere;
}

/* Performance ---------------------------------------------------------------------- */
.pf-range-change { display: flex; flex-wrap: wrap; align-items: baseline; gap: .2rem .6rem; margin: 0; font-size: .92rem; }
.pf-range-change strong { font-weight: 750; }
.pf-range-change span { font-weight: 650; }
.pf-range-change .pf-range-label { color: var(--muted); font-size: .8rem; font-weight: 600; }
.pf-chart-controls { display: flex; flex: 0 0 auto; flex-wrap: nowrap; align-items: center; gap: .5rem 1.25rem; }
#portfolio-page .portfolio-range-tabs { width: 31rem; min-width: 0; }

.pf-chart {
  --pf-line: var(--accent);
  margin: 0;
  display: grid;
  gap: .5rem;
  min-width: 0;
  min-height: 300px;
}
.pf-chart.is-return.is-up { --pf-line: var(--positive); }
.pf-chart.is-return.is-down { --pf-line: var(--negative); }
.pf-chart-empty { align-self: center; justify-self: center; margin: 0; color: var(--muted); font-size: .86rem; }
.pf-chart-legend { display: flex; flex-wrap: wrap; gap: .3rem 1.1rem; color: var(--text-2); font-size: .74rem; }
.pf-chart-legend span { display: inline-flex; align-items: center; gap: .4rem; }
.pf-chart-legend .is-value i { width: 14px; height: 3px; border-radius: 2px; background: var(--pf-line); }
.pf-chart-legend .is-invested i { width: 14px; border-top: 2px dashed var(--muted); }
.pf-chart-legend .is-trade i { width: 7px; height: 7px; border-radius: 50%; background: var(--positive); }
.pf-chart-plot { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .65rem; }
.pf-chart-area {
  position: relative;
  min-width: 0;
  height: clamp(220px, 28vw, 320px);
  color: var(--pf-line);
  touch-action: pan-y;
  cursor: crosshair;
}
.pf-chart-area:focus { outline: none; }
.pf-chart-area:focus-visible { outline: 2px dashed var(--accent); outline-offset: 4px; }
.pf-chart-area svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; overflow: visible; }
.pf-grid { stroke: var(--hairline); stroke-width: 1; vector-effect: non-scaling-stroke; }
.pf-zero { stroke: var(--border-strong); stroke-width: 1; stroke-dasharray: 3 4; vector-effect: non-scaling-stroke; }
.pf-line { fill: none; stroke: var(--pf-line); stroke-width: 2; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.pf-area { stroke: none; }
.pf-invested { fill: none; stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 5 5; vector-effect: non-scaling-stroke; opacity: .85; }
.pf-marks, .pf-dots { position: absolute; inset: 0; pointer-events: none; }
.pf-mark, .pf-end, .pf-dots i {
  position: absolute;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}
.pf-mark { width: 7px; height: 7px; background: var(--positive); box-shadow: 0 0 0 2px var(--bg); }
.pf-mark.is-sell { background: var(--negative); }
.pf-mark.is-mixed { background: var(--accent-2); }
.pf-end { width: 9px; height: 9px; background: var(--pf-line); box-shadow: 0 0 0 4px color-mix(in srgb, var(--pf-line) 22%, transparent); }
.pf-dots i { width: 10px; height: 10px; background: var(--surface); border: 2px solid var(--pf-line); }
.pf-dots i.is-invested { width: 8px; height: 8px; border-color: var(--muted); }
.pf-cross { position: absolute; top: 0; bottom: 0; width: 0; border-left: 1px dashed var(--muted); pointer-events: none; }
.pf-tip {
  position: absolute;
  top: 6px;
  z-index: 5;
  width: max-content;
  min-width: 190px;
  max-width: 280px;
  display: grid;
  gap: 5px;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  transform: translateX(14px);
  pointer-events: none;
  font-size: .78rem;
}
.pf-tip.is-left { transform: translateX(calc(-100% - 14px)); }
.pf-tip[hidden], .pf-cross[hidden] { display: none; }
.pf-tip time { color: var(--muted); font-size: .7rem; }
.pf-tip-row { display: grid; grid-template-columns: 8px minmax(0, 1fr) auto; align-items: center; gap: 8px; color: var(--text-2); }
.pf-tip-row i { width: 8px; height: 8px; border-radius: 50%; background: transparent; }
.pf-tip-row.is-value i { background: var(--pf-line); }
.pf-tip-row.is-invested i { border-top: 2px dashed var(--muted); border-radius: 0; height: 0; }
.pf-tip-row b { color: var(--text); font-weight: 700; }
.pf-tip-row.positive b { color: var(--positive); }
.pf-tip-row.negative b { color: var(--negative); }
.pf-tip p { margin: 3px 0 0; padding-top: 6px; border-top: 1px solid var(--hairline); color: var(--text); font-size: .74rem; line-height: 1.4; }
.pf-chart-y { position: relative; min-width: 58px; color: var(--muted); font-size: .68rem; text-align: right; }
.pf-chart-y span { position: absolute; right: 0; transform: translateY(-50%); white-space: nowrap; }
.pf-chart-x { position: relative; height: 1rem; margin-right: calc(58px + .65rem); color: var(--muted); font-size: .68rem; }
.pf-chart-x span { position: absolute; transform: translateX(-50%); white-space: nowrap; }
.pf-chart-x span.is-first { transform: none; }
.pf-chart-x span.is-last { transform: translateX(-100%); }
#portfolio-page .portfolio-shell.is-loading-analytics .pf-chart-area { opacity: .45; }

/* Allocation + risk ------------------------------------------------------------------ */
.pf-split {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(17rem, 1fr);
  gap: clamp(1.75rem, 3vw, 3rem);
  align-items: start;
}
.pf-allocation {
  display: grid;
  grid-template-columns: minmax(170px, 230px) minmax(0, 1fr);
  align-items: center;
  gap: clamp(1.25rem, 3vw, 2.5rem);
}
.pf-allocation > .pf-empty { grid-column: 1 / -1; }
.pf-donut { position: relative; width: 100%; max-width: 230px; aspect-ratio: 1; justify-self: center; }
.pf-donut svg { width: 100%; height: 100%; display: block; transform: rotate(0deg); }
.pf-slice {
  fill: none;
  stroke-width: 5.2;
  cursor: pointer;
  transition: stroke-width var(--transition-fast), opacity var(--transition-fast);
}
.pf-allocation.has-active .pf-slice { opacity: .35; }
.pf-allocation.has-active .pf-slice.is-active { opacity: 1; stroke-width: 6.4; }
.pf-donut-center {
  position: absolute;
  inset: 22%;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-content: center;
  justify-items: center;
  gap: .15rem;
  text-align: center;
  pointer-events: none;
}
.pf-donut-center small { max-width: 100%; overflow: hidden; color: var(--muted); font-size: .72rem; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.pf-donut-center strong { color: var(--text); font-family: var(--font-display); font-size: clamp(1.05rem, 1.6vw, 1.3rem); font-weight: 800; }
.pf-donut-center span { color: var(--muted); font-size: .72rem; }
.pf-legend { display: grid; margin: 0; padding: 0; list-style: none; }
.pf-legend-row {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(5.5rem, 1fr) minmax(5.5rem, auto);
  align-items: center;
  gap: .9rem;
  min-height: 46px;
  padding: .3rem .25rem;
  border-bottom: 1px solid var(--hairline);
  transition: opacity var(--transition-fast);
}
.pf-legend-row:last-child { border-bottom: 0; }
.pf-legend-row:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.pf-allocation.has-active .pf-legend-row:not(.is-active) { opacity: .45; }
.pf-legend-name { display: flex; align-items: center; gap: .6rem; min-width: 0; }
.pf-legend-name > span:last-child { display: grid; min-width: 0; }
.pf-legend-name strong { overflow: hidden; color: var(--text); font-size: .84rem; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.pf-legend-name small { color: var(--muted); font-size: .72rem; }
.pf-swatch { flex: 0 0 10px; width: 10px; height: 10px; border-radius: 50%; background: var(--swatch); }
.pf-legend-weight { display: grid; gap: .3rem; }
.pf-legend-weight b { color: var(--text); font-size: .82rem; font-weight: 700; }
.pf-legend-value { color: var(--text-2); font-size: .82rem; text-align: right; }
#portfolio-page .pf-logo { width: 28px; height: 28px; flex: 0 0 28px; border-radius: 8px; }
#portfolio-page .pf-logo .asset-logo-fallback { font-size: .66rem; }

.pf-risk-level { color: var(--muted); font-size: .8rem; font-weight: 700; }
.pf-risk-level[data-risk-band="0"] { color: var(--positive); }
.pf-risk-level[data-risk-band="1"] { color: var(--accent-2); }
.pf-risk-level[data-risk-band="2"], .pf-risk-level[data-risk-band="3"] { color: var(--negative); }
.pf-risk { display: grid; gap: .9rem; }
.pf-risk-score { display: flex; align-items: baseline; gap: .4rem; }
.pf-risk-score strong { color: var(--text); font-family: var(--font-display); font-size: 2.4rem; font-weight: 800; line-height: 1; }
.pf-risk-score span { color: var(--muted); font-size: .86rem; }
.pf-risk-scale {
  position: relative;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 3px;
  padding-top: 10px;
  color: var(--muted);
  font-size: .66rem;
}
.pf-risk-scale::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--positive), var(--accent-2) 45%, var(--negative));
  opacity: .7;
}
.pf-risk-scale i {
  position: absolute;
  top: -4px;
  width: 4px;
  height: 12px;
  border-radius: 2px;
  background: var(--text);
  box-shadow: 0 0 0 2px var(--bg);
  transform: translateX(-50%);
}
.pf-risk-scale span:last-child { text-align: right; }
.pf-risk-scale span:nth-child(3), .pf-risk-scale span:nth-child(4) { text-align: center; }
.pf-risk-factors { display: grid; }
.pf-risk-factor {
  display: grid;
  grid-template-columns: minmax(7rem, 1fr) minmax(4rem, 1.2fr) 2rem;
  align-items: center;
  gap: .75rem;
  min-height: 38px;
  border-bottom: 1px solid var(--hairline);
  font-size: .8rem;
}
.pf-risk-factor > span { justify-self: start; color: var(--text-2); font-weight: 650; }
.pf-risk-factor b { color: var(--text); text-align: right; }
.pf-risk-summary { margin: 0; color: var(--text); font-size: .84rem; line-height: 1.45; }
.pf-risk-coverage { justify-self: start; color: var(--muted); font-size: .72rem; }

/* Holdings ---------------------------------------------------------------------------- */
.pf-table-wrap { min-width: 0; overflow-x: auto; overscroll-behavior-inline: contain; }
.pf-holdings { width: 100%; border-collapse: collapse; font-size: .84rem; }
#portfolio-page .pf-holdings :is(th, td) {
  padding: .6rem .75rem;
  border: 0;
  border-bottom: 1px solid var(--hairline);
  background: transparent;
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}
#portfolio-page .pf-holdings th {
  position: static;
  padding-block: .3rem;
  border-bottom-color: var(--border);
  color: var(--muted);
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .01em;
  text-transform: none;
}
#portfolio-page .pf-holdings :is(th, td):first-child { padding-left: 0; }
#portfolio-page .pf-holdings :is(th, td):last-child { padding-right: 0; }
#portfolio-page .pf-holdings .pf-num { text-align: right; }
.pf-holdings th button {
  min-height: 32px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
}
.pf-holdings th button:hover { color: var(--text); }
.pf-holdings th button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.pf-holdings th:is([aria-sort="ascending"], [aria-sort="descending"]) button { color: var(--text); }
.pf-holdings th[aria-sort="descending"] button::after { content: " ↓"; }
.pf-holdings th[aria-sort="ascending"] button::after { content: " ↑"; }
.pf-holdings tbody tr { transition: background var(--transition-fast); }
.pf-holdings tbody tr:hover { background: color-mix(in srgb, var(--text) 3%, transparent); }
.pf-holdings td small { display: block; margin-top: 2px; color: var(--muted); font-size: .74rem; }
.pf-holdings td strong { color: var(--text); font-weight: 700; }
.pf-holdings td :is(strong, small).positive { color: var(--positive); }
.pf-holdings td :is(strong, small).negative { color: var(--negative); }
.pf-holdings .pf-col-weight { width: 7.5rem; }
/* What a holding has made is the column people look for: the % leads, large. */
.pf-holdings .pf-col-return strong { font-size: .95rem; }
.pf-holdings .pf-col-return small { font-weight: 600; }
.pf-holdings .pf-col-weight span { display: block; }
.pf-holdings .pf-col-weight .pf-bar { margin: 5px 0 0 auto; width: 4.5rem; }
.pf-holdings tfoot td { border-bottom: 0; color: var(--text-2); font-weight: 700; }
#portfolio-page .pf-holdings tfoot td { border-bottom: 0; padding-top: .8rem; }
.pf-fresh { display: inline-block; width: 6px; height: 6px; margin-left: 6px; border-radius: 50%; vertical-align: middle; background: var(--accent-2); }
.pf-fresh.is-stale { background: var(--negative); }

.pf-asset {
  display: inline-flex;
  align-items: center;
  gap: .7rem;
  min-width: 0;
  max-width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.pf-asset > span:last-child { display: grid; min-width: 0; }
.pf-asset strong { overflow: hidden; color: var(--text); font-size: .86rem; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.pf-asset small { overflow: hidden; color: var(--muted); font-size: .74rem; text-overflow: ellipsis; white-space: nowrap; }
.pf-asset:hover strong { color: var(--accent-strong); }
.pf-asset:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }
.pf-holdings .pf-inline-units { display: none; }

/* Activity ----------------------------------------------------------------------------- */
.pf-activity-toolbar { display: flex; flex: 0 1 auto; min-width: 0; flex-wrap: nowrap; align-items: center; gap: .5rem 1.25rem; }
.pf-search {
  display: flex;
  align-items: center;
  gap: .45rem;
  flex: 0 1 20rem;
  min-width: 0;
  min-height: 36px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
}
.pf-search:focus-within { border-bottom-color: var(--accent); }
.pf-search svg { width: 15px; height: 15px; flex: 0 0 15px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.pf-search input {
  width: 100%;
  min-width: 0;
  min-height: 34px;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
  box-shadow: none;
  color: var(--text);
  font: inherit;
  font-size: .82rem;
}
.pf-activity { position: relative; min-width: 0; }
.pf-activity[aria-busy="true"] .pf-activity-list { opacity: .5; }
.pf-activity-list, .pf-activity-list ol { margin: 0; padding: 0; list-style: none; }
.pf-month h4 {
  margin: 0;
  padding: .9rem 0 .35rem;
  color: var(--muted);
  font-size: .72rem;
  font-weight: 750;
  letter-spacing: .06em;
  text-transform: uppercase;
}
.pf-month:first-child h4 { padding-top: .1rem; }
.pf-tx {
  display: grid;
  grid-template-columns: 2.6rem 3.2rem minmax(10rem, 1.6fr) minmax(9rem, 1.2fr) minmax(6.5rem, .8fr) minmax(7.5rem, .9fr) 4.5rem;
  align-items: center;
  gap: .9rem;
  min-height: 58px;
  padding: .45rem 0;
  border-bottom: 1px solid var(--hairline);
  font-size: .84rem;
}
.pf-tx:hover { background: color-mix(in srgb, var(--text) 3%, transparent); }
.pf-tx-date { display: grid; justify-items: center; line-height: 1.1; }
.pf-tx-date b { color: var(--text); font-size: 1rem; font-weight: 750; }
.pf-tx-date small { color: var(--muted); font-size: .66rem; font-weight: 700; text-transform: uppercase; }
.pf-tx-date .pf-tx-time { margin-top: 2px; color: var(--muted-2); font-weight: 600; font-variant-numeric: tabular-nums; text-transform: none; }
.pf-tx-type { justify-self: start; font-size: .74rem; font-weight: 750; }
.pf-tx-type::before { content: ""; display: inline-block; width: 6px; height: 6px; margin-right: 6px; border-radius: 50%; vertical-align: 1px; background: currentColor; }
.pf-tx-type.is-buy { color: var(--positive); }
.pf-tx-type.is-sell { color: var(--negative); }
.pf-tx-detail, .pf-tx-amount, .pf-tx-result { display: grid; min-width: 0; color: var(--text-2); }
.pf-tx-detail small, .pf-tx-amount small, .pf-tx-result small { overflow: hidden; color: var(--muted); font-size: .72rem; text-overflow: ellipsis; white-space: nowrap; }
.pf-tx-amount, .pf-tx-result { text-align: right; }
.pf-tx-amount strong { color: var(--text); font-weight: 700; }
.pf-tx-result strong { font-weight: 700; }
.pf-tx-result .pf-term { text-decoration-thickness: 1px; }
.pf-tx-actions { display: flex; justify-content: flex-end; gap: .15rem; opacity: 0; transition: opacity var(--transition-fast); }
.pf-tx:is(:hover, :focus-within) .pf-tx-actions { opacity: 1; }
@media (hover: none) { .pf-tx-actions { opacity: 1; } }
.pf-icon {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.pf-icon:hover { color: var(--text); background: color-mix(in srgb, var(--text) 7%, transparent); }
.pf-icon.is-danger:hover { color: var(--negative); background: var(--negative-soft); }
.pf-icon:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.pf-icon svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
/* Activity is one list: older rows load as its end comes into view. */
.pf-activity-more {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-top: .5rem;
  color: var(--muted);
  font-size: .78rem;
  font-variant-numeric: tabular-nums;
}
.pf-activity-more[hidden] { display: none; }
.pf-activity-more button {
  min-height: 40px;
  padding: 0 .25rem;
  border: 0;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.pf-activity-more button:hover:not(:disabled) { color: var(--accent-strong); }
.pf-activity-more button:disabled { color: var(--muted-2); cursor: default; }
.pf-activity-more button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.pf-activity-more button[hidden] { display: none; }

/* Calendar refinements: heat follows the size of the day's move. ------------------------ */
#portfolio-page .portfolio-calendar-day.positive { background: color-mix(in srgb, var(--positive) calc(var(--heat, .35) * 26%), transparent); }
#portfolio-page .portfolio-calendar-day.negative { background: color-mix(in srgb, var(--negative) calc(var(--heat, .35) * 26%), transparent); }

/* Intermediate widths -------------------------------------------------------------------- */
@media (max-width: 1180px) {
  .pf-hero { grid-template-columns: minmax(0, 1fr); align-items: start; }
  .pf-hero-facts > div:first-child { padding-left: 0; border-left: 0; }
  .pf-split { grid-template-columns: minmax(0, 1fr); }
  .pf-tx { grid-template-columns: 2.6rem 3.2rem minmax(9rem, 1.5fr) minmax(8rem, 1fr) minmax(6rem, .8fr) minmax(7rem, .9fr) 4.5rem; gap: .6rem; }
  .pf-holdings .pf-col-units, .pf-holdings .pf-col-cost { display: none; }
  .pf-holdings .pf-inline-units { display: inline; }
}

/* Phones ---------------------------------------------------------------------------- */
@media (max-width: 760px) {
  #portfolio-page .portfolio-backdrop { gap: 1.6rem; }
  .pf-hero { gap: 1.1rem; padding-top: .25rem; }
  .pf-hero-value { font-size: clamp(2.1rem, 11vw, 2.8rem); }
  .pf-hero-moves { gap: .35rem 1.25rem; }
  .pf-hero-facts { grid-template-columns: repeat(2, minmax(0, 1fr)); row-gap: .75rem; }
  .pf-hero-facts > div { padding: .55rem 0 0; border-left: 0; border-top: 1px solid var(--hairline); }
  .pf-hero-facts > div:nth-child(odd) { padding-right: .75rem; }
  .pf-section-head { align-items: flex-start; }
  .pf-chart-controls { width: 100%; min-width: 0; flex-wrap: wrap; }
  /* Four tabs scroll if they must; the action keeps its icon, its name stays readable. */
  #portfolio-page .portfolio-section-bar { gap: .5rem; }
  #portfolio-page .portfolio-section-bar .portfolio-section-tabs {
    flex: 1 1 auto;
    width: auto;
    min-width: 0;
    margin: 0;
    grid-template-columns: none;
    grid-auto-flow: column;
    grid-auto-columns: max-content;
    gap: .65rem;
    overflow-x: auto;
    scrollbar-width: none;
  }
  #portfolio-page .portfolio-section-bar .portfolio-section-tabs::-webkit-scrollbar { display: none; }
  #portfolio-page .portfolio-section-bar .portfolio-section-tabs button { padding-inline: .1rem; font-size: .8rem; }
  #portfolio-page .portfolio-section-tabs .pf-tab-long { display: none; }
  #portfolio-page .portfolio-section-tabs .pf-tab-short { display: inline; }
  #portfolio-page .portfolio-section-bar .portfolio-add-button span { display: none; }
  #portfolio-page .portfolio-section-bar .portfolio-add-button { min-width: 36px; justify-content: center; }
  #portfolio-page .portfolio-section-bar .portfolio-mobile-refresh { width: 36px; min-width: 36px; }
  #portfolio-page .portfolio-section-bar .portfolio-topbar { width: auto; flex: 0 0 auto; gap: .15rem; }
  #portfolio-page .portfolio-section-bar .portfolio-mobile-refresh { margin-left: 0; }
  #portfolio-page .portfolio-range-tabs { width: 100%; min-width: 0; }
  .pf-chart { min-height: 240px; }
  .pf-chart-area { height: 210px; }
  .pf-chart-y { min-width: 44px; }
  .pf-chart-x { margin-right: calc(44px + .65rem); }
  .pf-tip, .pf-tip.is-left { top: auto; bottom: calc(100% + 6px); left: 0 !important; right: 0; width: auto; min-width: 0; max-width: none; transform: none; }

  /* Phones read what they own before how risky it is. */
  .pf-split { display: contents; }
  .pf-hero { order: 0; }
  .pf-performance { order: 1; }
  .pf-holdings-section { order: 2; }
  .pf-allocation-section { order: 3; }
  .pf-risk-section { order: 4; }
  .pf-allocation { grid-template-columns: minmax(0, 1fr); }
  .pf-donut { max-width: 200px; }
  .pf-legend-row { grid-template-columns: minmax(0, 1fr) 4.5rem auto; gap: .6rem; }
  .pf-legend-weight .pf-bar { display: none; }

  /* Holdings become a two-line list: who and how much / what it is worth and made. */
  .pf-holdings thead { display: none; }
  .pf-holdings, .pf-holdings tbody, .pf-holdings tfoot { display: block; }
  .pf-holdings tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "asset value" "asset return";
    align-items: center;
    column-gap: .75rem;
    padding: .55rem 0;
    border-bottom: 1px solid var(--hairline);
  }
  #portfolio-page .pf-holdings :is(th, td) { padding: 0; border: 0; }
  .pf-holdings :is(.pf-col-units, .pf-col-cost, .pf-col-price, .pf-col-day, .pf-col-weight) { display: none; }
  .pf-holdings .pf-col-asset { grid-area: asset; min-width: 0; }
  .pf-holdings .pf-col-value { grid-area: value; }
  .pf-holdings .pf-col-return { grid-area: return; display: flex; justify-content: flex-end; gap: .45rem; }
  .pf-holdings .pf-col-return small { margin: 0; }
  .pf-holdings tfoot tr { border-bottom: 0; }
  .pf-holdings tfoot .pf-col-asset { color: var(--muted); }

  .pf-activity-toolbar { width: 100%; flex-wrap: wrap; }
  .pf-search { flex: 1 1 100%; }
  /* A trade is three lines: date and asset / what was traded / paid and result. */
  .pf-tx {
    grid-template-columns: 2.4rem minmax(0, 1fr) auto;
    grid-template-areas:
      "date asset amount"
      "date detail result"
      "date type actions";
    gap: .2rem .7rem;
    padding: .7rem 0;
  }
  .pf-tx-date { grid-area: date; align-self: start; }
  .pf-tx .pf-asset { grid-area: asset; }
  .pf-tx-detail { grid-area: detail; }
  .pf-tx-type { grid-area: type; align-self: center; }
  .pf-tx-amount { grid-area: amount; }
  .pf-tx-result { grid-area: result; }
  .pf-tx-actions { grid-area: actions; opacity: 1; }
  .pf-tx-detail small { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .pf-slice, .pf-legend-row, .pf-tx-actions, .pf-switch button { transition: none; }
}
