/* Investment portfolio page. Values come from tokens.css; shared-ui.css loads after this file. */

.pf-shell {
  width: 100%;
  max-width: min(1760px, calc(100vw - 32px));
  margin: 0 auto;
  padding: var(--space-3) 0 var(--space-6);
}

.pf-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-3);
}

.pf-eyebrow-row {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.pf-eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: var(--text-sm);
}

.pf-eye {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.pf-eye:hover { background: var(--surface-2); color: var(--text); }
.pf-eye:focus-visible { outline: none; box-shadow: var(--focus-ring); }

.pf-total {
  margin: 0;
  font-variant-numeric: tabular-nums;
  font-size: 2.3rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.15;
  color: var(--text);
}

.pf-total-sub {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1) var(--space-2);
  margin: var(--space-2) 0 0;
  font-size: var(--text-sm);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.pf-change {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  font-weight: 700;
}

.pf-change.pf-pos { background: var(--success-soft); }
.pf-change.pf-neg { background: var(--danger-soft); }
.pf-change-label { color: var(--muted); }
.pf-day { width: 100%; font-size: var(--text-xs); }

/* text for screen readers only */
.pf-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.pf-head-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.pf-head-actions .btn[hidden],
.pf-field[hidden],
.pf-alerts[hidden] {
  display: none;
}

.pf-icon-btn {
  min-width: var(--control-height);
  padding-inline: 0;
  font-size: var(--text-lg);
}

.pf-pos { color: var(--success); }
.pf-neg { color: var(--danger); }
.pf-stale { color: var(--warning); }

.pf-alerts {
  display: grid;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

.pf-alert {
  margin: 0;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: var(--text-sm);
  background: var(--surface);
}

.pf-alert-danger { border-color: var(--danger); background: var(--danger-soft); color: var(--text); }
.pf-alert-warning { border-color: var(--warning); background: var(--warning-soft); color: var(--text); }

.pf-tabs {
  display: flex;
  gap: var(--space-1);
  margin-bottom: var(--space-3);
  padding: var(--space-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  overflow-x: auto;
  scrollbar-width: none;
}

.pf-tab {
  flex: 1 0 auto;
  min-height: 38px;
  padding: 0 var(--space-3);
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
}

.pf-tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-card);
}

.pf-panel {
  display: grid;
  gap: var(--space-3);
}

.pf-card {
  display: grid;
  gap: var(--space-3);
  align-content: start;
}

.pf-card h2,
.pf-card h3 {
  margin: 0;
  font-size: var(--text-lg);
}

.pf-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

.pf-card-head h3 {
  margin: var(--space-3) 0 var(--space-1);
  font-size: var(--text-md);
}

.pf-small-btn {
  min-height: 34px;
  padding: 0 var(--space-3);
  font-size: var(--text-xs);
}

/* summary on the analysis tab: label on the left, number on the right */
.pf-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: var(--space-6);
  margin: 0;
}

.pf-kpi {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: baseline;
  gap: 2px var(--space-3);
  padding: var(--space-2) 0;
  border-top: 1px solid var(--border);
}

.pf-kpi > small {
  grid-column: 1 / -1;
  color: var(--faint);
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
}

.pf-summary .pf-kpi:nth-child(-n + 2) { border-top: 0; }

.pf-kpi dt {
  color: var(--muted);
  font-size: var(--text-sm);
}

.pf-kpi dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  text-align: right;
  white-space: nowrap;
}

/* the portfolio tab: kind chips, account picker, one list of holdings */
.pf-chips {
  display: flex;
  gap: var(--space-2);
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.pf-chips::-webkit-scrollbar { display: none; }

.pf-chip {
  flex: 0 0 auto;
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.pf-chip small {
  color: var(--muted);
  font-size: var(--text-xs);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.pf-chip.active {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-contrast);
}

.pf-chip.active small { color: inherit; opacity: 0.8; }
.pf-chip:focus-visible { outline: none; box-shadow: var(--focus-ring); }

/* account picker in the list heading: looks like text with an arrow */
.pf-account-pick {
  max-width: 100%;
  min-height: 32px;
  padding: 0 var(--space-1);
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.pf-account-pick:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.pf-list-head { align-items: center; }

.pf-list-card { gap: 0; padding-top: var(--space-2); padding-bottom: var(--space-2); }

.pf-list-head {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-2) 0;
  color: var(--muted);
  font-size: var(--text-xs);
  font-weight: 600;
}

.pf-list-head > span:last-child { font-variant-numeric: tabular-nums; text-align: right; }
.pf-list-head small { font-size: inherit; }
.pf-month { margin-top: var(--space-2); border-top: 1px solid var(--border); padding-top: var(--space-3); }
.pf-list-card > .pf-month:first-child { margin-top: 0; border-top: 0; padding-top: var(--space-2); }

.pf-avatar {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--muted);
  font-size: var(--text-xs);
  font-weight: 800;
  letter-spacing: 0.02em;
}

.pf-avatar-th-stock { background: color-mix(in srgb, var(--work) 16%, transparent); color: var(--work); }
.pf-avatar-us-stock { background: color-mix(in srgb, var(--study) 16%, transparent); color: var(--study); }
.pf-avatar-etf { background: color-mix(in srgb, var(--travel) 16%, transparent); color: var(--travel); }
.pf-avatar-fund { background: color-mix(in srgb, var(--rest) 16%, transparent); color: var(--rest); }
.pf-avatar-gold { background: var(--special-soft); color: var(--special); }
.pf-avatar-crypto { background: color-mix(in srgb, var(--exercise) 16%, transparent); color: var(--exercise); }

.pf-file-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-2);
  color: var(--muted);
  font-size: var(--text-xs);
}

.pf-more {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.pf-more > summary {
  min-height: 48px;
  display: flex;
  align-items: center;
  padding: 0 var(--space-4);
  font-weight: 700;
  cursor: pointer;
}

.pf-more > summary:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: var(--radius); }
.pf-more-body { display: grid; gap: var(--space-3); padding: 0 var(--space-3) var(--space-3); }

.pf-two {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
}

.pf-empty,
.pf-note {
  margin: 0;
  color: var(--muted);
  font-size: var(--text-sm);
}

.pf-pre { white-space: pre-wrap; }

.pf-bars,
.pf-holds,
.pf-txs,
.pf-movers,
.pf-mini-list {
  display: grid;
  gap: 0;
  margin: 0;
  padding: 0;
  list-style: none;
}

.pf-bars { gap: var(--space-3); }

.pf-bar-label {
  display: flex;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: 4px;
  font-size: var(--text-sm);
}

.pf-bar-label span:last-child {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  white-space: nowrap;
}

.pf-bar {
  height: 8px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  overflow: hidden;
}

.pf-bar i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.pf-bar.over i { background: var(--danger); }

.pf-hold,
.pf-tx,
.pf-link-row {
  width: 100%;
  display: grid;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) 0;
  border: 0;
  border-top: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.pf-holds li:first-child .pf-hold,
.pf-txs li:first-child .pf-tx,
.pf-movers li:first-child .pf-link-row,
.pf-links li:first-child .pf-link-row {
  border-top: 0;
}

.pf-hold:hover,
.pf-tx:hover,
.pf-link-row:hover {
  background: var(--surface-2);
}

.pf-hold:focus-visible,
.pf-tx:focus-visible,
.pf-link-row:focus-visible,
.pf-tab:focus-visible,
.pf-seg:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.pf-hold {
  grid-template-columns: 40px minmax(0, 1fr) auto;
  padding-inline: var(--space-1);
}

.pf-hold-name strong { font-size: var(--text-md); }

/* long symbols such as SCBRMS&P500 are cut, never pushed under the numbers */
.pf-hold-name strong,
.pf-tx-main strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pf-card-head .pf-bench.modal-input { width: auto; max-width: 55%; flex: 0 1 auto; }
.pf-hold small em { font-style: normal; }

.pf-hold > span,
.pf-tx > span,
.pf-link-row > span {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.pf-hold small,
.pf-tx small,
.pf-link-row small {
  color: var(--muted);
  font-size: var(--text-xs);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pf-hold-qty,
.pf-hold-price,
.pf-hold-value,
.pf-tx-amount {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.pf-hold-price em {
  font-style: normal;
  font-size: var(--text-xs);
}

.pf-hold-value strong { font-weight: 700; }

.pf-link-row {
  grid-template-columns: minmax(0, 1fr) auto;
  padding-inline: var(--space-1);
}

/* rows highlight with rounded corners, not a hard box */
.pf-hold,
.pf-tx,
.pf-link-row {
  border-radius: var(--radius-sm);
  padding-inline: var(--space-2);
  transition: background-color 0.16s ease, transform 0.12s ease;
}

.pf-hold:active,
.pf-tx:active,
.pf-link-row:active { transform: scale(0.992); }

.pf-list-head > span:first-child { white-space: nowrap; }

.pf-link-row > span:last-child {
  font-variant-numeric: tabular-nums;
}

.pf-group-total {
  font-variant-numeric: tabular-nums;
  font-size: var(--text-sm);
  white-space: nowrap;
}

.pf-tx {
  grid-template-columns: 64px minmax(0, 1fr) auto;
}

.pf-tx-type {
  justify-self: stretch;
  text-align: center;
  white-space: nowrap;
  padding: 3px 6px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--muted);
  font-size: var(--text-xs);
  font-weight: 700;
}

.pf-tx-buy { background: var(--accent-soft); color: var(--text); }
.pf-tx-sell { background: var(--warning-soft); color: var(--warning); }
.pf-tx-dividend { background: var(--success-soft); color: var(--success); }
.pf-tx-bad { background: var(--danger-soft); }

.pf-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
}

.pf-filters {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-2);
}

.pf-filters .modal-input {
  width: 100%;
  min-width: 0;
  font-size: var(--text-sm);
}

.pf-segs {
  display: inline-flex;
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: none;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.pf-seg {
  flex: 0 0 auto;
  white-space: nowrap;
  min-height: 34px;
  padding: 0 var(--space-3);
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: var(--text-sm);
  cursor: pointer;
}

.pf-seg.active {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: var(--shadow-card);
}

.pf-start ol {
  display: grid;
  gap: var(--space-3);
  margin: 0;
  padding: 0;
  list-style: none;
}

.pf-start li {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-3);
}

.pf-start li p { margin: 2px 0 0; color: var(--muted); font-size: var(--text-sm); }
.pf-start li.done { opacity: 0.7; }

.pf-step {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--surface-2);
  font-weight: 700;
}

.pf-start li.done .pf-step { background: var(--success-soft); color: var(--success); }

.pf-disclaimer {
  margin: var(--space-4) 0 0;
  color: var(--faint);
  font-size: var(--text-xs);
  text-align: center;
}

/* dialogs */
.pf-dialog .edit-box {
  max-height: min(86vh, 760px);
  overflow: auto;
  display: grid;
  gap: var(--space-3);
}

.edit-dialog.pf-dialog-wide {
  width: min(720px, calc(100vw - 24px));
}

.pf-dialog h2 { margin: 0; font-size: var(--text-lg); }
.pf-dialog h3 { margin: var(--space-2) 0 0; font-size: var(--text-md); }

.pf-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
}

.pf-field {
  display: grid;
  gap: 6px;
  min-width: 0;
  font-size: var(--text-sm);
}

.pf-field > span { color: var(--muted); font-size: var(--text-xs); font-weight: 600; }
.pf-span-2 { grid-column: 1 / -1; }

.pf-check {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 44px;
}

.pf-check input { width: 20px; height: 20px; }
.pf-check > span { color: var(--text); font-size: var(--text-sm); font-weight: 500; }

.pf-form-summary {
  margin: 0;
  min-height: 1.4em;
  font-variant-numeric: tabular-nums;
  font-size: var(--text-sm);
  color: var(--muted);
}

.pf-form-error {
  margin: 0;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: var(--text-sm);
}

.pf-form-error[hidden] { display: none; }

.pf-detail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
}

.pf-detail-head p { margin: 2px 0 0; color: var(--muted); font-size: var(--text-sm); }

.pf-price-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
}

.pf-price-line strong { font-variant-numeric: tabular-nums; font-size: var(--text-xl); font-weight: 500; }
.pf-price-line small { color: var(--muted); font-size: var(--text-xs); }

.pf-inline-price {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--space-2);
  margin-left: auto;
}

.pf-inline-price .modal-input { width: 150px; }
.pf-inline-price .pf-field { flex: 1 1 200px; }
.pf-inline-price .pf-field .modal-input { width: 100%; }

.pf-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-2);
  margin: 0;
}

.pf-metrics div {
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.pf-metrics dt { color: var(--muted); font-size: var(--text-xs); }
.pf-metrics dd { margin: 2px 0 0; font-variant-numeric: tabular-nums; font-size: var(--text-sm); overflow-wrap: anywhere; }

.pf-mini-list li {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-2) 0;
  border-top: 1px solid var(--border);
  font-size: var(--text-sm);
}

.pf-mini-list li:first-child { border-top: 0; }
.pf-mini-list.pf-links li { display: block; padding: 0; }
.pf-mini-list li > span:last-child { font-variant-numeric: tabular-nums; text-align: right; }

.pf-detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.pf-fab {
  display: none;
}

@media (max-width: 960px) {
  .pf-two { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 640px) {
  .pf-shell { padding-top: var(--space-2); }
  .pf-head { align-items: flex-start; gap: var(--space-3); }
  .pf-head-actions { width: 100%; justify-content: space-between; }
  .pf-head-actions .btn-primary { display: none; }
  .pf-total { font-size: 2rem; }
  .pf-eye { width: 44px; height: 44px; }
  .pf-chip { min-height: 44px; }
  .pf-account-pick { min-height: 44px; }
  .pf-summary { grid-template-columns: minmax(0, 1fr); }
  .pf-summary .pf-kpi:nth-child(2) { border-top: 1px solid var(--border); }
  .pf-hold { gap: var(--space-2); padding-block: 10px; }
  .pf-hold-value strong { font-size: var(--text-sm); }
  .pf-filters .modal-input { padding-inline: 8px; font-size: var(--text-xs); }

  .pf-tx { grid-template-columns: 52px minmax(0, 1fr) auto; gap: var(--space-2); }
  .pf-tx-amount span { font-size: var(--text-sm); }

  .pf-form-grid { grid-template-columns: minmax(0, 1fr); }
  .pf-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pf-inline-price { margin-left: 0; width: 100%; }
  .pf-inline-price .modal-input { flex: 1 1 120px; width: auto; }
  .pf-start li { grid-template-columns: 34px minmax(0, 1fr); }
  .pf-start li .btn { grid-column: 2; justify-self: start; }

  .pf-fab {
    position: fixed;
    right: 16px;
    bottom: calc(var(--bottom-nav-height) + 18px + env(safe-area-inset-bottom));
    z-index: 900;
    width: 56px;
    height: 56px;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 50%;
    background: var(--accent);
    color: var(--accent-contrast);
    font-size: 28px;
    box-shadow: var(--shadow-float);
    cursor: pointer;
  }
}

/* asset search (phase P2) */
.pf-search { position: relative; }
.pf-search[hidden] { display: none; }
.pf-search label > span { color: var(--muted); font-size: var(--text-xs); font-weight: 600; }
.pf-search-results {
  margin: 0;
  padding: var(--space-1) var(--space-2);
  list-style: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-float);
  max-height: 260px;
  overflow: auto;
}
.pf-search-results[hidden] { display: none; }
.pf-search-results li:first-child .pf-link-row { border-top: 0; }
.pf-search-results /* rows highlight with rounded corners, not a hard box */
.pf-hold,
.pf-tx,
.pf-link-row {
  border-radius: var(--radius-sm);
  padding-inline: var(--space-2);
  transition: background-color 0.16s ease, transform 0.12s ease;
}

.pf-hold:active,
.pf-tx:active,
.pf-link-row:active { transform: scale(0.992); }

.pf-list-head > span:first-child { white-space: nowrap; }

.pf-link-row > span:last-child { font-family: var(--font-body); font-size: var(--text-xs); color: var(--muted); }
.pf-hint { color: var(--muted); font-size: var(--text-xs); min-height: 1em; }

/* allocation, limits, watchlist, alerts (phases P3-P5) */
.pf-donut-wrap {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-4);
}
.pf-donut { width: 150px; height: 150px; flex: 0 0 auto; }
.pf-donut circle { transition: stroke-dasharray 0.2s ease; }
.pf-legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: var(--text-sm);
}
.pf-legend li { display: flex; align-items: center; gap: 6px; }
.pf-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: 0 0 auto; }

.pf-table-wrap { overflow-x: auto; }
.pf-table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.pf-table th, .pf-table td { padding: var(--space-2); border-top: 1px solid var(--border); text-align: left; }
.pf-table thead th { border-top: 0; color: var(--muted); font-size: var(--text-xs); font-weight: 600; }
.pf-table td { font-variant-numeric: tabular-nums; }
.pf-table tbody th { font-weight: 500; }
.pf-table tr.pf-over th, .pf-table tr.pf-over td:nth-child(2) { color: var(--danger); }
.pf-pct-input { width: 84px; min-height: 38px; }

.pf-advice { margin: 0; padding-left: 1.2em; display: grid; gap: 4px; font-size: var(--text-sm); }

.pf-tag {
  display: inline-block;
  padding: 1px 8px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--muted);
  font-size: var(--text-xs);
  font-style: normal;
  font-weight: 600;
}

.pf-range {
  position: relative;
  display: block;
  height: 6px;
  margin: 8px 0 4px auto;
  width: 100%;
  max-width: 160px;
  border-radius: var(--radius-pill);
  background: var(--surface-3);
}
.pf-range i {
  position: absolute;
  top: -3px;
  width: 4px;
  height: 12px;
  margin-left: -2px;
  border-radius: 2px;
  background: var(--accent);
}

.pf-alert-actions { display: inline-flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); font-family: var(--font-body); font-size: var(--text-xs); color: var(--muted); }
.pf-alert-form {
  display: grid;
  grid-template-columns: 120px 140px minmax(0, 1fr) auto;
  gap: var(--space-2);
}

@media (max-width: 640px) {
  .pf-watch-row { grid-template-areas: "name price" "qty value"; }
  .pf-alert-form { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .pf-alert-form #pfAlertNote { grid-column: 1 / -1; }
  .pf-alert-form .btn { grid-column: 1 / -1; }
  .pf-donut { width: 120px; height: 120px; }
  .pf-mini-list li { flex-wrap: wrap; }
}

/* charts, levels, history, plans (phases P6-P10) */
.pf-chart { width: 100%; height: auto; display: block; margin-top: var(--space-2); }
.pf-chart polyline { fill: none; stroke-width: 1.6; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.pf-chart polyline.pf-line-price { stroke: var(--accent); stroke-width: 2; }
.pf-line-sma50 { stroke: var(--travel); }
.pf-line-sma200 { stroke: var(--study); }
.pf-chart line { stroke-width: 1; stroke-dasharray: 4 4; vector-effect: non-scaling-stroke; }
.pf-chart .pf-line-cost { stroke: var(--muted); stroke-dasharray: 2 3; }
polyline.pf-line-cost { stroke: var(--muted); stroke-dasharray: 5 4; }
.pf-line-support { stroke: var(--success); }
.pf-line-resistance { stroke: var(--danger); }
.pf-chart-label { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.pf-mark-buy { fill: var(--success); stroke: var(--surface); stroke-width: 1.5; }
.pf-mark-sell { fill: var(--danger); stroke: var(--surface); stroke-width: 1.5; }
.pf-chart-key { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-3); margin: var(--space-1) 0 0; font-size: var(--text-xs); color: var(--muted); }
.pf-chart-key span::before { content: ""; display: inline-block; width: 14px; height: 3px; margin-right: 6px; vertical-align: middle; border-radius: 2px; background: currentColor; }
.pf-chart-key .k-price::before { background: var(--accent); }
.pf-chart-key .k-sma50::before { background: var(--travel); }
.pf-chart-key .k-sma200::before { background: var(--study); }
.pf-chart-key .k-cost::before { background: var(--muted); }
.pf-chart-key .k-support::before { background: var(--success); }
.pf-chart-key .k-resistance::before { background: var(--danger); }
.pf-mini-list.pf-levels li > span:first-child { display: grid; gap: 2px; text-align: left; font-family: var(--font-body); }
.pf-levels strong { font-variant-numeric: tabular-nums; font-weight: 500; }
.pf-levels em { font-style: normal; font-variant-numeric: tabular-nums; font-size: var(--text-xs); }
.pf-levels small { color: var(--muted); font-size: var(--text-xs); }
.pf-levels-wrap { gap: var(--space-4); }
.pf-metrics-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.pf-bench { width: auto; min-height: 36px; font-size: var(--text-sm); }
.pf-tag-due { background: var(--warning-soft); color: var(--warning); }
.pf-plan-form { grid-template-columns: minmax(0, 1fr) 90px minmax(0, 1fr) auto; }
@media (max-width: 640px) {
  .pf-plan-form { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .pf-plan-form .btn, .pf-plan-form select { grid-column: 1 / -1; }
  .pf-metrics-2 { grid-template-columns: minmax(0, 1fr); }
}

.pf-mini-list.pf-levels li { flex-wrap: nowrap; align-items: center; }
.pf-mini-list.pf-levels li > .btn { flex: 0 0 auto; white-space: nowrap; }

/* AI analysis (portfolio-ai.js) */
.pf-ai-cta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3);
  border: 1px solid var(--accent-border);
  border-radius: var(--radius);
  background: var(--accent-soft);
}

.pf-ai-cta > div { display: grid; gap: 2px; min-width: 0; }
.pf-ai-cta small { color: var(--muted); font-size: var(--text-xs); }
.pf-ai-steps ul { margin: 0; padding: 0 var(--space-4) var(--space-3) calc(var(--space-4) + 1em); color: var(--muted); font-size: var(--text-sm); }
.pf-ai-steps > summary { font-size: var(--text-sm); }
.pf-ai-wait { padding: var(--space-4) 0; text-align: center; }
.pf-ai-warn { padding: var(--space-2) var(--space-3); border-radius: var(--radius); background: var(--warning-soft); color: var(--text); }
.pf-alert small { color: var(--muted); overflow-wrap: anywhere; }

.pf-ai-sources {
  display: grid;
  gap: var(--space-2);
  margin: 0;
  padding-left: 1.4em;
  font-size: var(--text-sm);
}

.pf-ai-sources li { overflow-wrap: anywhere; }
.pf-ai-sources small { display: block; color: var(--muted); font-size: var(--text-xs); }

/* text written in Markdown, rendered by core/markdown.js */
.md {
  min-width: 0;
  color: var(--text);
  font-size: var(--text-md);
  line-height: 1.7;
  overflow-wrap: anywhere;
}

.md > :first-child { margin-top: 0; }
.md h3, .md h4, .md h5 { margin: var(--space-5) 0 var(--space-2); line-height: 1.35; }
.md h3 { font-size: var(--text-lg); padding-top: var(--space-3); border-top: 1px solid var(--border); }
.md > h3:first-child { border-top: 0; padding-top: 0; }
.md h4 { font-size: var(--text-md); }
.md h5 { font-size: var(--text-sm); color: var(--muted); }
.md p, .md ul, .md ol, .md blockquote, .md pre { margin: 0 0 var(--space-3); }
.md ul, .md ol { padding-left: 1.4em; }
.md li + li { margin-top: 4px; }
.md a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.md code { padding: 1px 5px; border-radius: var(--radius-sm); background: var(--surface-2); font-size: 0.92em; }
.md pre { padding: var(--space-3); border-radius: var(--radius); background: var(--surface-2); overflow-x: auto; }
.md pre code { padding: 0; background: none; }
.md blockquote { padding: var(--space-2) var(--space-3); border-left: 3px solid var(--accent-border); background: var(--surface-2); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.md hr { border: 0; border-top: 1px solid var(--border); margin: var(--space-4) 0; }
.md-table { margin: 0 0 var(--space-3); overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.md table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); font-variant-numeric: tabular-nums; }
.md th, .md td { padding: var(--space-2) var(--space-3); border-top: 1px solid var(--border); text-align: left; vertical-align: top; }
.md thead th { border-top: 0; background: var(--surface-2); color: var(--muted); font-size: var(--text-xs); font-weight: 700; white-space: nowrap; }
.md td { min-width: 72px; }

@media (max-width: 640px) {
  .md { font-size: var(--text-sm); }
  .pf-ai-cta .btn { min-height: 44px; }
}

.pf-detail-head > .btn { flex: 0 0 auto; white-space: nowrap; }
/* numbers in tables stay whole; the table scrolls sideways instead */
.md .md-table { overflow-wrap: normal; }
.md td, .md th { overflow-wrap: normal; word-break: normal; }

/* Holdings: compact rows, two or three across on wide screens so a long list stays short. */
.pf-holds-grid { column-gap: var(--space-6); }
.pf-holds-grid .pf-hold { padding-block: var(--space-2); gap: var(--space-2) var(--space-3); grid-template-columns: 34px minmax(0, 1fr) auto; }
.pf-holds-grid .pf-avatar { width: 34px; height: 34px; font-size: 0.72rem; }
.pf-holds-grid .pf-hold-name strong { font-size: var(--text-sm); }
.pf-holds-grid .pf-hold-value strong { font-size: var(--text-sm); }
.pf-list-total { margin: 0 0 var(--space-1); color: var(--muted); font-size: var(--text-xs); font-variant-numeric: tabular-nums; }
.pf-sort-pick { color: var(--muted); font-weight: 600; text-align: right; }

@media (min-width: 1000px) {
  .pf-holds-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  /* every row keeps its top line, also the first of the second column */
  .pf-holds-grid li:nth-child(2) .pf-hold { border-top: 0; }
}

@media (min-width: 1500px) {
  .pf-holds-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .pf-holds-grid li:nth-child(3) .pf-hold { border-top: 0; }
}

/* phones: the gain shows as a percentage only, so names and units keep their room */
@media (max-width: 640px) {
  .pf-holds-grid .pf-gain-amt { display: none; }
}

/* Interactive chart (core/chart.js) */
.ch { position: relative; width: 100%; margin-top: var(--space-2); }
.ch-plot { position: relative; outline: none; cursor: crosshair; touch-action: pan-y; user-select: none; -webkit-user-select: none; border-radius: var(--radius-sm); }
.ch-plot:focus-visible { box-shadow: var(--focus-ring); }
.ch-svg { display: block; width: 100%; height: auto; overflow: visible; }
.ch-svg.ch-up { color: var(--success); }
.ch-svg.ch-down { color: var(--danger); }
.ch-grid { stroke: var(--border); stroke-width: 1; }
.ch-axis { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.ch-price { fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.ch-stop-top { stop-color: currentColor; stop-opacity: 0.22; }
.ch-stop-bottom { stop-color: currentColor; stop-opacity: 0; }
.ch-area { stroke: none; }
.ch-line { fill: none; stroke-width: 1.5; stroke-linejoin: round; }
.ch-line.pf-line-sma50 { stroke: var(--travel); }
.ch-line.pf-line-sma200 { stroke: var(--study); }
.ch-line.pf-line-ema20 { stroke: var(--rest); }
.ch-line.pf-line-cost { stroke: var(--muted); stroke-dasharray: 5 4; }
.ch-band { fill: var(--accent-soft); stroke: var(--accent-border); stroke-width: 0.6; }
.ch-level { stroke-width: 1.2; stroke-dasharray: 6 5; }
.ch-level.pf-line-support { stroke: var(--success); }
.ch-level.pf-line-resistance { stroke: var(--danger); }
.ch-level.pf-line-cost { stroke: var(--muted); stroke-dasharray: 2 4; }
.ch-wick { stroke-width: 1; }
.ch-candle-up { fill: var(--success); stroke: var(--success); }
.ch-candle-down { fill: var(--danger); stroke: var(--danger); }
.ch-mark { stroke: var(--surface); stroke-width: 1.5; }
.ch-mark-buy { fill: var(--success); }
.ch-mark-sell { fill: var(--danger); }
.ch-last { fill: currentColor; }
.ch-last-text { fill: var(--surface); font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums; }
.ch-cross { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.ch-dot { fill: currentColor; stroke: var(--surface); stroke-width: 2; }
.ch-zoombox { fill: var(--accent-soft); stroke: var(--accent-border); }
.ch-empty { margin: 0; padding: var(--space-5) 0; color: var(--muted); text-align: center; font-size: var(--text-sm); }
.ch-tip {
  position: absolute;
  top: 0;
  z-index: 3;
  display: grid;
  gap: 3px;
  min-width: 168px;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-float);
  font-size: var(--text-xs);
  pointer-events: none;
}
.ch-tip[hidden] { display: none; }
.ch-tip strong { font-size: var(--text-sm); }
.ch-tip span { display: flex; justify-content: space-between; gap: var(--space-3); }
.ch-tip em { color: var(--muted); font-style: normal; }
.ch-tip b { font-variant-numeric: tabular-nums; }
.ch-tip .ch-up { color: var(--success); }
.ch-tip .ch-down { color: var(--danger); }
.ch-reset { position: absolute; top: 4px; left: 8px; z-index: 2; min-height: 32px; padding: 0 var(--space-3); border: 1px solid var(--border); border-radius: var(--radius-pill); background: var(--surface); color: var(--text); font: inherit; font-size: var(--text-xs); font-weight: 700; cursor: pointer; }
.ch-reset[hidden] { display: none; }
.pf-chart-title { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-2) var(--space-3); }
.pf-chart-title h3 { margin: var(--space-2) 0 0; }
.pf-chart-tools { display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--space-2); margin-top: var(--space-2); }
.pf-chart-toggles { margin-top: var(--space-2); flex-wrap: wrap; overflow: visible; }
.pf-chip-sm { min-height: 32px; padding: 0 var(--space-3); font-size: var(--text-xs); }
.pf-chip-sm.active.pf-toggle-sma50 { background: var(--travel); border-color: var(--travel); }
.pf-chip-sm.active.pf-toggle-sma200 { background: var(--study); border-color: var(--study); }
.pf-chip-sm.active.pf-toggle-ema20 { background: var(--rest); border-color: var(--rest); }
.pf-chart-help { font-size: var(--text-xs); }
@media (max-width: 640px) {
  .pf-chip-sm { min-height: 40px; }
  .pf-chart-tools .pf-segs { width: 100%; }
  .pf-chart-tools .pf-seg { flex: 1 0 auto; min-height: 40px; }
}

/* Motion: the chart line draws itself, the panel content rises in on a tab change */
@keyframes pf-draw { from { stroke-dasharray: 1; stroke-dashoffset: 1; } to { stroke-dasharray: 1; stroke-dashoffset: 0; } }
@keyframes pf-rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.ch-price { animation: pf-draw 0.7s ease-out both; }
.pf-panel.pf-anim > * { animation: pf-rise 0.32s cubic-bezier(0.2, 0.8, 0.2, 1) both; }
.pf-panel.pf-anim > :nth-child(2) { animation-delay: 0.04s; }
.pf-panel.pf-anim > :nth-child(3) { animation-delay: 0.08s; }
.pf-panel.pf-anim > :nth-child(n + 4) { animation-delay: 0.12s; }
.pf-panel.pf-anim .pf-holds li { animation: pf-rise 0.3s ease both; }
.pf-panel.pf-anim .pf-holds li:nth-child(2) { animation-delay: 0.03s; }
.pf-panel.pf-anim .pf-holds li:nth-child(3) { animation-delay: 0.06s; }
.pf-panel.pf-anim .pf-holds li:nth-child(4) { animation-delay: 0.09s; }
.pf-panel.pf-anim .pf-holds li:nth-child(n + 5) { animation-delay: 0.12s; }
.pf-chip, .pf-seg, .pf-tab { transition: background-color 0.16s ease, color 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease, transform 0.12s ease; }
.pf-chip:active, .pf-seg:active, .pf-tab:active, .pf-eye:active { transform: scale(0.95); }
.pf-tab.active { transition-duration: 0.22s; }
.pf-total-in { animation: pf-rise 0.45s cubic-bezier(0.2, 0.8, 0.2, 1) both; }
