@import url("../../assets/fonts/fonts.css");

/* Shared stock view. The handle occupies the first stock's position. */
#quote-panel {
  --quote-detail: 1;
  --quote-top: max(6rem, 29vh);
  --quote-bottom: 7.5rem;
  position: fixed;
  z-index: 38;
  top: var(--quote-top);
  right: 1.5rem;
  bottom: var(--quote-bottom);
  display: flex;
  flex-direction: column;
  width: 14rem;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-family: "IBM Plex Mono", monospace;
  opacity: 0;
  transform: translateX(8px);
  pointer-events: none;
  transition: opacity 180ms ease, transform 200ms cubic-bezier(0.2, 0, 0, 1);
}
#quote-panel[hidden], .quote-handle[hidden] { display: none !important; }
#quote-panel.is-open { opacity: 1; transform: translateX(0); pointer-events: auto; }
#quote-panel.is-hover-preview {
  --quote-detail: var(--quote-preview-detail, 0);
  bottom: auto;
  max-height: calc(100vh - var(--quote-top) - var(--quote-bottom));
  background: var(--paper);
  opacity: var(--quote-reveal, 0);
  transform: translateX(calc((1 - var(--quote-reveal, 0)) * 12px));
  pointer-events: none;
}
#quote-panel.is-hover-preview.is-preview-interactive { pointer-events: auto; }
#quote-panel.is-preview-interactive .quote-stack-head { overflow: visible; }
#quote-panel .quote-stack-head {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  flex: 0 0 auto;
  gap: 0.5rem;
  height: calc(40px * var(--quote-detail));
  overflow: clip;
  margin-bottom: calc(0.25rem * var(--quote-detail));
  opacity: var(--quote-detail);
  color: var(--muted);
  font: 0.75rem "IBM Plex Sans", sans-serif;
}
#quote-panel button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  min-height: 32px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: 1rem "IBM Plex Mono", monospace;
  cursor: pointer;
}
.quote-handle svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.5; }
#quote-panel .quote-stack-pin { width: 40px; min-height: 40px; }
.quote-stack-pin svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; transform: rotate(-35deg); transition: transform 180ms cubic-bezier(0.2, 0, 0, 1); }
#quote-panel .quote-stack-pin[aria-pressed="true"] { color: var(--accent); }
.quote-stack-pin[aria-pressed="true"] svg { fill: currentColor; transform: rotate(0); }
#quote-panel button:hover, #quote-panel a:hover { color: var(--accent); }
#quote-panel :focus-visible, .quote-handle:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
#quote-panel .quote-viewport {
  position: relative;
  display: flex;
  min-height: 0;
  --quote-fade-top: 0px;
  --quote-fade-bottom: 0px;
}
#quote-panel .quote-viewport.has-before { --quote-fade-top: 20px; }
#quote-panel .quote-viewport.has-after { --quote-fade-bottom: 20px; }
#quote-panel .quote-stack {
  min-height: 0;
  width: 100%;
  overflow-y: auto;
  scroll-padding-block: 24px;

  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--muted) transparent;
  padding-inline: 2px 8px;
}
#quote-panel .quote-entry { padding: 0 0 calc(0.25rem + 1.75rem * var(--quote-detail)); margin: 0; overflow: clip; }
#quote-panel .quote-details {
  height: var(--quote-detail-height, auto);
  overflow: clip;
  opacity: var(--quote-detail);
  transition: height 200ms cubic-bezier(0.2, 0, 0, 1), opacity 140ms ease;
}
#quote-panel.is-hover-preview .quote-details { height: calc(var(--quote-detail-height, 0px) * var(--quote-detail)); }
#quote-panel .quote-details-inner { display: flow-root; }
#quote-panel.is-hover-preview header button { opacity: var(--quote-detail); }
#quote-panel .quote-entry:focus { outline: none; }
#quote-panel .quote-entry:focus-visible { outline: 1px dotted var(--muted); outline-offset: -1px; }
#quote-panel header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto 32px;
  align-items: center;
  gap: 0.35rem;
  margin: 0 0 0.2rem;
  padding: 0;
  border: 0;
}
#quote-panel h2 { margin: 0; color: var(--ink); font: 500 0.8125rem "IBM Plex Mono", monospace; letter-spacing: normal; line-height: 1.5; }
#quote-panel h2::after { display: none; }
#quote-panel .quote-price, #quote-panel .quote-change { display: inline-flex; white-space: pre; font-size: 0.875rem; font-variant-numeric: tabular-nums; }
#quote-panel .quote-price { justify-self: end; color: var(--ink); }
#quote-panel .is-up { color: var(--positive); }
#quote-panel .is-down { color: var(--negative); }
#quote-panel .is-flat { color: var(--muted); }
#quote-panel .quote-identity { margin: 0 0 0.45rem; color: var(--ink-soft); font-size: 0.6875rem; line-height: 1.4; overflow-wrap: anywhere; }
#quote-panel .quote-digit.is-padding { width: 0; flex-basis: 0; }
#quote-panel dl { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.5rem; margin: 0; padding: 0; font-size: 0.6875rem; }
#quote-panel .quote-extra { margin-top: 0.65rem; }
#quote-panel [data-year-range] { grid-column: 1 / -1; }
#quote-panel dt { color: var(--muted); }
#quote-panel dd { margin: 0.25rem 0 0; }
#quote-panel [data-relative-volume] { display: block; margin-top: 0.2rem; color: var(--ink-soft); font-size: 0.625rem; white-space: nowrap; }
#quote-panel .quote-events { display: grid; gap: 0.2rem; margin-top: 0.65rem; }
#quote-panel .quote-events a { display: block; min-width: 0; width: 100%; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-soft); font-size: 0.6875rem; line-height: 1.5; }
#quote-panel a, #quote-panel .quote-status { display: block; width: fit-content; margin-top: 0.45rem; color: var(--ink-soft); font-size: 0.6875rem; line-height: 1.4; }
#quote-panel [data-quote-model] { margin: 0.2rem 0 0.85rem; }
#quote-panel .quote-entry:last-child { padding-bottom: 0.25rem; }
#quote-panel .quote-empty { margin: 0; max-width: 22ch; color: var(--muted); font: 0.75rem/1.6 "IBM Plex Mono", monospace; }
#quote-panel [hidden] { display: none; }

.quote-handle {
  position: fixed;
  z-index: 37;
  top: max(6rem, 29vh);
  right: 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 44px;
  min-height: 44px;
  padding: 12px 0;
  border: 0;
  border-radius: 3px;
  background: transparent;
  color: var(--muted);
  font: 0.6875rem "IBM Plex Mono", monospace;
  cursor: pointer;
  animation: quote-handle-in 180ms ease;
  opacity: var(--quote-handle-opacity, 1);
  transition: opacity 140ms ease, color 140ms ease, background-color 140ms ease;
}
.quote-handle:hover, .quote-handle:focus-visible { color: var(--ink); background: var(--paper-raised); }
.quote-dots { display: flex; flex-direction: column; gap: 8px; }
.quote-dots i { display: block; width: 2px; height: 2px; border-radius: 50%; background: currentColor; }
@keyframes quote-handle-in { from { opacity: 0; } to { opacity: 1; } }

/* Articles keep their text geometry. At widths without a spare margin the
   stock view is a temporary opaque panel instead of changing the document. */
@media (min-width: 761px) and (max-width: 1719px) {
  body:not(.index-page) #quote-panel {
    --quote-top: 6rem;
    --quote-bottom: 2rem;
    right: 1rem;
    width: 15.5rem;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 3px;
    background: var(--paper);
    box-shadow: none;
  }
  body:not(.index-page) .quote-handle { top: 6rem; }
}
@media (min-width: 761px) and (max-width: 1359px) {
  #quote-panel { right: 1rem; width: 15rem; padding: 8px; border: 1px solid var(--line); border-radius: 3px; background: var(--paper); }
}
/* The inline homepage watchlist is the mobile stock interface. */
@media (max-width: 760px) {
  #quote-panel, .quote-handle { display: none !important; }
}
@media (prefers-reduced-motion: reduce) {
  #quote-panel, .quote-handle, #quote-panel .quote-details, .quote-stack-pin svg { animation: none; transition: none; }
  #quote-panel.is-hover-preview { transform: none; }
}

/* Index overlays obscure underlying content without enclosing it in a card. */
.index-page #quote-panel,
.index-page #quote-panel.is-hover-preview {
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  isolation: isolate;
}
.index-page #quote-panel::before {
  content: "";
  position: absolute;
  inset: -12px;
  z-index: -1;
  pointer-events: none;
  background: color-mix(in srgb, var(--bg) 65%, transparent);
  -webkit-backdrop-filter: blur(24px);
  backdrop-filter: blur(24px);
  -webkit-mask-image: linear-gradient(to right, transparent, black 12px, black calc(100% - 12px), transparent);
  mask-image: linear-gradient(to right, transparent, black 12px, black calc(100% - 12px), transparent);
}
.index-page .quote-handle:hover,
.index-page .quote-handle:focus-visible { background: transparent; }
