/* Investment portfolio card and purchase form (see portfolio.js). Colors only come from the
   theme variables of index.html; the one exception is the neutral backdrop scrim below. */

.pf-card, .pf-card *, .pf-overlay, .pf-overlay * { box-sizing: border-box; }
.pf-card [hidden], .pf-overlay [hidden] { display: none !important; }
.pf-card :is(button):focus-visible,
.pf-overlay :is(select, input, button):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.pf-card { background: var(--card); color: var(--text); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px; margin-bottom: 14px; }
.pf-title { margin-bottom: 12px; }

/* Summary */
.pf-summary { margin-bottom: 14px; }
.pf-summary-label { margin: 0; color: var(--muted); font-size: 0.78rem; }
.pf-summary-value { margin: 2px 0 0; font-size: 1.9rem; font-weight: 800; letter-spacing: -0.02em; line-height: 1.15;
  font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.pf-summary-note { margin: 6px 0 0; color: var(--muted); font-size: 0.75rem; }
.pf-summary-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px 12px;
  margin: 12px 0 0; padding-top: 12px; border-top: 1px solid var(--border); }
.pf-stat { min-width: 0; }
.pf-stat-pnl { grid-column: 1 / -1; }
.pf-stat-label { color: var(--muted); font-size: 0.72rem; }
.pf-stat-value { margin: 2px 0 0; font-size: 0.95rem; font-weight: 700; font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere; }
.pf-stat-pnl .pf-stat-value { font-size: 1.05rem; }

.pf-pnl[data-tone="positive"] { color: var(--positive); }
.pf-pnl[data-tone="negative"] { color: var(--loss); }
.pf-pnl[data-tone="neutral"] { color: var(--muted); }
.pf-pnl-percent:empty { display: none; }

/* Positions */
.pf-positions { list-style: none; margin: 0; padding: 0; }
.pf-position { border-top: 1px solid var(--border); }
/* The 8px side padding is cancelled by the negative margin: text stays aligned with the card,
   while the focus ring gets room. */
.pf-position-head { display: flex; flex-direction: column; align-items: stretch; gap: 8px; width: calc(100% + 16px);
  min-height: 56px; margin: 0 -8px; padding: 10px 8px; border-radius: 8px; background: none; color: inherit; font: inherit; text-align: left; }
/* One line that never wraps: the title gives way first, then the figures wrap onto extra lines. */
.pf-position-main { display: flex; align-items: center; gap: 10px; min-width: 0; }
.pf-badge { display: flex; align-items: center; justify-content: center; flex: none; width: 36px; height: 36px;
  border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-size: 0.68rem; font-weight: 700; }
.pf-position-title { display: flex; flex-direction: column; flex: 1 1 56px; min-width: 0; }
.pf-position-name { font-size: 0.92rem; font-weight: 600; overflow-wrap: anywhere; }
.pf-position-symbol { color: var(--muted); font-size: 0.72rem; }
.pf-position-figures { display: block; flex: 0 1 auto; min-width: 0; text-align: right; }
.pf-position-value { display: block; font-size: 0.95rem; font-weight: 700; font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere; }
.pf-position-pnl { display: block; font-size: 0.75rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.pf-chevron { flex: none; width: 8px; height: 8px; margin: 0 4px 3px 2px; color: var(--muted);
  border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg);
  transition: transform 0.15s ease; }
.pf-position-head[aria-expanded="true"] .pf-chevron { margin-bottom: 0; margin-top: 4px; transform: rotate(-135deg); }
.pf-position-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(92px, 1fr)); gap: 6px 10px; }
.pf-mini { display: flex; flex-direction: column; min-width: 0; }
.pf-mini-label { color: var(--muted); font-size: 0.68rem; }
.pf-mini-value { font-size: 0.8rem; font-weight: 600; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

/* Lots of an expanded position */
.pf-lots { padding: 0 0 12px; }
.pf-lot-list { list-style: none; margin: 0; padding: 0; }
.pf-lot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 6px;
  padding: 8px 8px 8px 12px; border-radius: 8px; background: var(--bg); }
.pf-lot-info { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.pf-lot-date { font-size: 0.85rem; font-weight: 700; }
.pf-lot-line { color: var(--muted); font-size: 0.75rem; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.pf-lot-part { display: inline-block; }
.pf-lot-actions { display: flex; flex: none; gap: 4px; }
.pf-icon-btn { display: flex; align-items: center; justify-content: center; width: 36px; height: 36px; padding: 0;
  background: var(--card); color: var(--muted); border: 1px solid var(--border); }
.pf-lot-delete { color: var(--loss); }
.pf-icon { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round;
  stroke-linejoin: round; pointer-events: none; }

.pf-empty { margin: 0; padding: 16px 0; color: var(--muted); font-size: 0.88rem; text-align: center; }
.pf-add-btn { display: block; width: 100%; min-height: 44px; margin: 12px 0 0; background: var(--accent-soft);
  color: var(--accent); font-size: 0.9rem; font-weight: 600; }

/* Purchase form */
.pf-overlay { --pf-scrim: rgba(0, 0, 0, 0.5); position: fixed; inset: 0; z-index: 75; display: flex;
  overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  padding: max(20px, env(safe-area-inset-top, 0px)) max(20px, env(safe-area-inset-right, 0px))
    max(20px, env(safe-area-inset-bottom, 0px)) max(20px, env(safe-area-inset-left, 0px));
  background: var(--pf-scrim); color: var(--text); color-scheme: light; animation: pf-fade 0.18s ease-out both; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .pf-overlay { color-scheme: dark; }
}
/* margin: auto centers the dialog when it fits and still lets a tall one scroll from its top. */
.pf-dialog { width: 100%; max-width: 380px; margin: auto; padding: 20px; background: var(--card);
  border: 1px solid var(--border); border-radius: 14px; }
.pf-dialog-title { margin: 0 0 14px; font-size: 1.05rem; }
.pf-field { min-width: 0; margin: 0 0 12px; }
.pf-field-label { display: block; margin-bottom: 4px; color: var(--muted); font-size: 0.8rem; }
.pf-input { display: block; width: 100%; min-width: 0; max-width: 100%; min-height: 42px; padding: 8px 10px;
  font: inherit; font-size: 16px; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px; }
/* Without this iOS Safari sizes the date field from its native widget and overflows narrow dialogs. */
.pf-input[type="date"] { -webkit-appearance: none; appearance: none; text-align: left; }
.pf-input[aria-invalid="true"] { border-color: var(--loss); }
.pf-field-hint { margin: 4px 0 0; color: var(--muted); font-size: 0.72rem; }
.pf-field-error { margin: 4px 0 0; color: var(--loss); font-size: 0.78rem; }
.pf-field-error:empty { display: none; }
.pf-field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 0 12px; }
.pf-total-line { margin: 0 0 14px; color: var(--muted); font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.pf-form-error { margin: -6px 0 14px; color: var(--loss); font-size: 0.82rem; }
.pf-form-error:empty { display: none; }
.pf-lot-staking { color: var(--positive); }
.pf-form-actions { display: flex; gap: 8px; }
.pf-btn { flex: 1; min-height: 44px; font-size: 0.95rem; font-weight: 600; }
.pf-btn-secondary { background: var(--done-bg); color: var(--muted); }
.pf-btn-primary { background: var(--accent); color: var(--bg); }

@keyframes pf-fade { from { opacity: 0; } to { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  .pf-overlay { animation: none; }
  .pf-chevron { transition: none; }
}
