/* trade_canvas/static/assets/css/holding-preview.css
 *
 * The holding preview (C89; design guide "Holding preview (C89)"): the
 * shell in portfolio.html (#holdingPreviewModal, the Share modal's dark
 * shell), the fragment from /securities/<TICKER>/preview (.hp-*), and the
 * rows' press tint where a tap opens it. Loaded only on a portfolio's
 * dashboard, after the page's own styles and positions.css / today.css.
 *
 * The look is the stock page's (security-page.css), compacted to the lab's
 * R4 (founder 2026-10-20): the app's tokens, tabular figures, green/red only
 * on the day's change, the strip's Total gain and the decline line's tone,
 * flat surfaces. Below 576px it is a bottom sheet that fits a 375px and a
 * 390px phone without a scroll of its own (name 18px, chart 120px, no
 * industry); from 576px Bootstrap's centred modal, 640px wide.
 */

/* ---------- Shell ---------- */

.modal.holding-preview {
  --bs-modal-width: 640px;
  --hp-pad-x: 22px;
  overscroll-behavior: contain;
}

.holding-preview__content {
  position: relative;
  border-radius: 12px;
}

/* The phone sheet's handle; it says "this slides", the swipe is optional. */
.holding-preview__grab { display: none; }

.holding-preview__close {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-primary, #e6edf3);
  font-size: 26px;
  line-height: 1;
  transition: background-color 0.15s ease;
}

.holding-preview__close:hover { background: rgba(255, 255, 255, 0.08); }

.holding-preview__close:focus-visible {
  outline: 2px solid var(--ss-focus-ring, #c4b5fd);
  outline-offset: -2px;
}

.holding-preview .holding-preview__body {
  padding: 20px var(--hp-pad-x) 16px;
  overscroll-behavior: contain;
}

.holding-preview__foot {
  display: flex;
  flex: none;
  justify-content: flex-end;
  padding: 10px var(--hp-pad-x);
  border-top: 1px solid var(--border-subtle, rgba(255, 255, 255, 0.06));
}

.holding-preview__foot:empty { display: none; }

/* ---------- The fragment ---------- */

.hp {
  display: flex;
  flex-direction: column;
  gap: 12px;
  color: var(--text-primary, #e6edf3);
  font-variant-numeric: tabular-nums;
}

.hp-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  /* Clear of the × in the corner. */
  padding-right: 40px;
}

/* The stock page's flat disc: the issuer's logo inset, or the ticker's letters. */
.hp-logo {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  overflow: hidden;
  border-radius: 50%;
  background: var(--bg-main, #0b1626);
}

.hp-logo img {
  width: 100%;
  height: 100%;
  padding: 5px;
  box-sizing: border-box;
  object-fit: contain;
}

.hp-logo-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary, #c8d4e1);
  font-size: 14px;
  font-weight: 700;
}

.hp-id {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.hp-name {
  margin: 0;
  color: var(--text-primary, #e6edf3);
  font-size: 20px;
  font-weight: 700;
  line-height: 1.2;
  overflow-wrap: break-word;
  text-wrap: balance;
}

.hp-meta {
  margin: 0;
  color: var(--text-secondary, #c8d4e1);
  font-size: var(--fs-small, 12px);
}

/* Neutral, not green: green is for gains and losses (Messaging §9b). */
.hp-symbol { font-weight: 600; }

.hp-price {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 10px;
  margin: 0;
}

.hp-price-value {
  font-size: 18px;
  font-weight: 700;
}

.hp-change {
  font-size: var(--fs-body, 14px);
  font-weight: 600;
  white-space: nowrap;
}

.hp-session {
  color: var(--text-muted, #a3b6c8);
  font-size: var(--fs-body, 14px);
}

.hp-when {
  flex-basis: 100%;
  color: var(--text-muted, #a3b6c8);
  font-size: var(--fs-small, 12px);
}

.hp-price-none {
  color: var(--text-muted, #a3b6c8);
  font-size: var(--fs-body, 14px);
}

.hp-pos { color: var(--accent-green, #34d399); }
.hp-neg { color: var(--accent-red, #fb8a8a); }

/* "In this portfolio": the row's own figures, a step back from the header
   (a tint, no border). */
.hp-strip-slot:empty { display: none; }

.hp-strip {
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
}

.hp-strip__title {
  margin: 0 0 2px;
  color: var(--text-muted, #a3b6c8);
  font-size: var(--fs-small, 12px);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.hp-strip__stats {
  display: grid;
  grid-template-columns: auto auto minmax(0, 1fr);
  gap: 2px 18px;
  margin: 0;
}

.hp-stat {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.hp-stat__label {
  color: var(--text-muted, #a3b6c8);
  font-size: var(--fs-small, 12px);
  font-weight: 400;
}

.hp-stat__value {
  margin: 0;
  color: var(--text-primary, #e6edf3);
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
}

.hp-stat__value.hp-pos { color: var(--accent-green, #34d399); }
.hp-stat__value.hp-neg { color: var(--accent-red, #fb8a8a); }

/* The amount and its percent each stay whole; on a narrow strip the
   percent takes the next line rather than running past the edge. */
.hp-stat__amount,
.hp-stat__pct { white-space: nowrap; }

.hp-stat__pct { font-size: var(--fs-small, 12px); }

.hp-compare {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.hp-q {
  margin: 0;
  color: var(--text-primary, #e6edf3);
  font-size: 17px;
  font-weight: 700;
  line-height: 1.25;
  text-wrap: balance;
}

/* The answer belongs to its question. */
.hp-answer {
  margin: -8px 0 0;
  color: var(--text-secondary, #c8d4e1);
  font-size: var(--fs-body, 14px);
}

.hp-chart[hidden] { display: none; }

/* The compact Performance chart: no card, no padding, a fixed box so the
   sheet doesn't grow when Chart.js arrives. */
.holding-preview .hp-chart .performance-chart-embed { margin: 0; }

.holding-preview .hp-chart .pop2-chart-wrap {
  position: relative;
  height: 200px;
  padding: 0;
}

.holding-preview .hp-chart .pop2-chart-canvas {
  min-height: 0;
  height: 100%;
}

.hp-decline {
  margin: 0;
  color: var(--text-secondary, #c8d4e1);
  font-size: var(--fs-body, 14px);
}

.hp-decline b {
  color: var(--text-primary, #e6edf3);
  font-weight: 600;
}

.hp-decline b.hp-pos { color: var(--accent-green, #34d399); }
.hp-decline b.hp-neg { color: var(--accent-red, #fb8a8a); }

.hp-sep { color: var(--text-muted, #a3b6c8); }

.hp-fine {
  margin: 0;
  color: var(--text-muted, #a3b6c8);
  font-size: var(--fs-small, 12px);
}

.hp-note {
  margin: 0;
  color: var(--text-secondary, #c8d4e1);
  font-size: var(--fs-body, 14px);
}

/* While the fragment loads: room for the answer and the chart, so the
   sheet doesn't jump when they arrive. Still, no shimmer (Motion: no loops). */
.hp-skeleton {
  height: 340px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
}

/* "Full stock page ›": the accent button (.ss-btn-accent's colours), a
   44px target. */
.hp-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 22px;
  border: 1px solid var(--ss-cta-border, rgba(169, 143, 248, 0.8));
  border-radius: 10px;
  background: var(--ss-cta-fill, rgba(111, 66, 193, 0.28));
  color: var(--ss-cta-text, #f3efff);
  font-size: 15px;
  font-weight: 700;
  text-decoration: none;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.hp-link:hover,
.hp-link:focus-visible {
  background: rgba(111, 66, 193, 0.38);
  border-color: var(--ss-active-line, #a98ff8);
  color: #ffffff;
  text-decoration: none;
}

.hp-link:focus-visible {
  outline: 2px solid var(--ss-focus-ring, #c4b5fd);
  outline-offset: 2px;
}

/* ---------- Phone: a bottom sheet ---------- */

@media (max-width: 575.98px) {
  /* No margin: Bootstrap's centred, scrollable dialog then fills the screen,
     and the content docks to its foot. With a unit: Bootstrap subtracts it
     from 100% in calc(), where a bare 0 is invalid. */
  .modal.holding-preview {
    --bs-modal-margin: 0px;
    --hp-pad-x: 16px;
  }

  .holding-preview .holding-preview__dialog {
    align-items: flex-end;
    max-width: none;
  }

  .modal.holding-preview.fade .holding-preview__dialog {
    transform: translateY(100%);
    transition: transform 0.22s ease-out;
  }

  .modal.holding-preview.show .holding-preview__dialog { transform: none; }

  .holding-preview .holding-preview__content {
    width: 100%;
    max-height: calc(100vh - 24px);
    max-height: calc(100dvh - 24px);
    border-width: 1px 0 0;
    border-radius: 16px 16px 0 0;
  }

  .holding-preview__grab {
    display: block;
    flex: none;
    width: 36px;
    height: 4px;
    margin: 8px auto 0;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.28);
  }

  .holding-preview__close {
    top: 4px;
    right: 6px;
  }

  .holding-preview .holding-preview__body { padding: 6px var(--hp-pad-x) 10px; }

  .holding-preview__foot {
    padding: 0 var(--hp-pad-x) calc(16px + env(safe-area-inset-bottom, 0px));
    border-top: 0;
  }

  .holding-preview__foot .hp-link { width: 100%; }

  .hp { gap: 10px; }

  .hp-name { font-size: 18px; }

  /* "ticker · type · sector" only: the industry is the desktop's. */
  .hp-industry { display: none; }

  .hp-strip__stats { gap: 2px 14px; }

  .holding-preview .hp-chart .pop2-chart-wrap { height: 120px; }

  .hp-skeleton { height: 290px; }
}

@media (prefers-reduced-motion: reduce) {
  .modal.holding-preview.fade .holding-preview__dialog { transition: none; }
}

/* ---------- Rows that open it ---------- */

/* Every row that opens the preview says so under the pointer; a press
   answers at once (feedback, ≤ 150 ms). Cash rows open nothing and keep
   their plain cursor. */
#positions-pane tr.positions-account-row,
#positions-pane tr.positions-part-row,
#positions-pane .pm-part {
  cursor: pointer;
}

#positions-pane tr[data-row-id],
#positions-pane tr.positions-account-row,
#positions-pane tr.positions-part-row,
#positions-pane li.pm-row:not(.pm-cash-row),
#today-pane a.today-mover {
  -webkit-tap-highlight-color: transparent;
}

#positions-pane .positions-table tbody tr.positions-account-row td,
#positions-pane .positions-table tbody tr.positions-part-row td {
  transition: background-color 0.12s ease;
}

#positions-pane .positions-table tbody tr.positions-account-row:hover td {
  background: rgba(255, 255, 255, 0.055);
}

#positions-pane .positions-table tbody tr[data-row-id]:active td,
#positions-pane .positions-table tbody tr.positions-account-row:active td,
#positions-pane .positions-table tbody tr.positions-part-row:active td,
#positions-pane li.pm-row:not(.pm-cash-row):active,
#today-pane a.today-mover:active {
  background: rgba(255, 255, 255, 0.09);
}

/* A part's own press inside its holding's item. */
#positions-pane .pm-part {
  border-radius: 4px;
  transition: background-color 0.12s ease;
}

#positions-pane .pm-part:active { background: rgba(255, 255, 255, 0.09); }

/* Keyboard focus on a row: the app's focus ring, drawn inside the row. */
#positions-pane tr[tabindex]:focus-visible,
#positions-pane li.pm-row[tabindex]:focus-visible,
#positions-pane .pm-part[tabindex]:focus-visible {
  outline: 2px solid var(--ss-focus-ring, #c4b5fd);
  outline-offset: -2px;
}

#positions-pane tr[tabindex]:focus-visible td { background: rgba(255, 255, 255, 0.055); }

/* ---------- Openers on the other tabs (C128) ---------- */

/* Allocation's "Preview <TICKER> ›": a quiet text link under the Portfolio Insight (founder
   2026-10-24: not the sheet's content in the panel, not a second accent button beside the
   page's Get Started Free). The link colour, a 44px target. */
.snapshot-explorer__panel-preview {
  display: inline-flex;
  align-items: center;
  /* The space before "›": a flex item's leading space collapses, so the gap draws it. */
  gap: 0.3em;
  min-height: 44px;
  margin-top: 4px;
  font-size: var(--fs-body, 14px);
  color: var(--ss-link, #a98ff8);
  font-weight: 600;
  text-decoration: none;
  transition: color 0.15s ease;
}

.snapshot-explorer__panel-preview[hidden] {
  display: none;
}

.snapshot-explorer__panel-preview:hover,
.snapshot-explorer__panel-preview:focus-visible {
  color: var(--ss-link-hover, #c4b5fd);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.snapshot-explorer__panel-preview:focus-visible {
  outline: 2px solid var(--ss-focus-ring, #c4b5fd);
  outline-offset: 2px;
  border-radius: 4px;
}
