/* ==========================================================================
   DESK LAYER: ticker search, trade tape, key figures, direction switch,
   mobile card rows. Tokens from app.css only; both themes inherit.
   ========================================================================== */

/* --- Ticker search (sits on the masthead) ------------------------------- */
.ticker-search {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 30px;
  padding: 0 8px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--masthead-dim);
}
.ticker-search:focus-within { background: #fff; border-color: #fff; color: #444; }
.ticker-search input {
  width: 150px;
  background: transparent;
  border: 0;
  outline: 0;
  color: var(--masthead-fg);
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
}
.ticker-search:focus-within input { color: #1c1c1b; }
.ticker-search input::placeholder { color: var(--masthead-dim); text-transform: none; font-weight: 400; }
.ticker-search:focus-within input::placeholder { color: var(--fg-dim); }
.ticker-search kbd {
  font-family: inherit;
  font-size: 12.5px;
  color: var(--masthead-dim);
  border: 1px solid var(--masthead-dim);
  border-radius: var(--radius-sm);
  padding: 1px 8px;
}
.ticker-search:focus-within kbd { display: none; }

/* --- Directional nav ----------------------------------------------------- */
.nav-buy.on  { color: var(--buy); }
.nav-sell.on { color: var(--sell); }

/* --- Trade tape ---------------------------------------------------------- */
.tape {
  display: flex;
  align-items: stretch;
  height: 32px;
  background: var(--bg-card-subtle);
  border-bottom: 1px solid var(--line);
  overflow: hidden;
}
.tape[hidden] { display: none; }
.tape-label {
  flex: none;
  display: flex;
  align-items: center;
  padding: 0 14px 0 28px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--fg-muted);
  background: var(--bg-card-subtle);
  border-right: 1px solid var(--line);
  position: relative;
  z-index: 1;
  white-space: nowrap;
}
.tape-track { flex: 1; display: flex; overflow-x: auto; scrollbar-width: none; min-width: 0; }
.tape-track::-webkit-scrollbar { display: none; }
.tape-inner { flex: none; display: flex; align-items: center; }
.tape-track.is-moving { overflow: hidden; }
.tape-track.is-moving .tape-inner { animation: tape-scroll var(--tape-secs, 60s) linear infinite; }
.tape-track.is-moving:hover .tape-inner,
.tape-track.is-moving:focus-within .tape-inner { animation-play-state: paused; }
@keyframes tape-scroll { to { transform: translateX(-100%); } }
.tape-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 16px;
  height: 100%;
  white-space: nowrap;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--fg-muted);
  border-right: 1px solid var(--line-subtle);
}
.tape-item:hover { background: var(--bg-card-hover); text-decoration: none; }
.tape-item b { color: var(--fg); font-weight: 700; }
.tape-buy .tape-arrow, .tape-buy .tape-val { color: var(--buy); }
.tape-sell .tape-arrow, .tape-sell .tape-val { color: var(--sell); }
.tape-arrow { font-size: 12.5px; }
.tape-who { color: var(--fg-dim); font-size: 12px; }

/* --- Key figures strip: a ruled row, figures not boxes ------------------- */
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 0;
  margin: 0 0 16px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}
.kpi {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 10px 16px 10px 0;
  min-width: 0;
}
.kpi + .kpi { padding-left: 16px; border-left: 1px solid var(--line-subtle); }
.kpi-label { font-size: 12.5px; color: var(--fg-muted); }
.kpi-val {
  font-size: 20px;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.01em;
  color: var(--fg);
}
.kpi-val.kpi-date { font-size: 14px; padding-top: 3px; }
.kpi-buy { color: var(--buy); }
.kpi-sell { color: var(--sell); }
.kpi-warn { color: var(--mid); }
.kpi-sub {
  font-size: 12.5px;
  color: var(--fg-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Cluster detail: lead insider name, verdict drivers ---------------------- */
.kpi-val.kpi-name {
  font-size: 16px;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: 0;
  padding-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.verdict .header-left { flex: 1 1 360px; min-width: 0; }
.verdict-reason {
  margin: 14px 0 0;
  max-width: 62ch;
  font-size: 15.5px;
  font-weight: 600;
  line-height: 1.5;
  color: var(--fg);
}
.verdict-score { display: flex; flex-direction: column; gap: 8px; align-items: stretch; }
.score-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0;
}
.score-split div {
  display: flex; flex-direction: column; gap: 2px; padding: 8px 12px;
  background: var(--bg-panel);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
}
.score-split dt { font-size: 12.5px; color: var(--fg-muted); }
.score-split dd { margin: 0; font-size: 20px; font-weight: 700; line-height: 1.2; color: var(--fg); }
.verdict-note { margin: 0; font-size: 12.5px; color: var(--fg-muted); }

/* Data notes: one calm line per fact */
.data-notes { display: grid; gap: 8px; margin: 0 0 20px; }
.data-notes .warning-callout { margin: 0; }
.data-notes .note-neutral { background: var(--bg-card-subtle); border-color: var(--line); }
.formula { margin: 0 0 14px; max-width: 58ch; }

/* Chart: status, annotation */
.chart-wrap { position: relative; }
.chart-status {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 0 24px;
  text-align: center;
  font-size: 13px;
  color: var(--fg-muted);
  pointer-events: none;
}
.chart-status[hidden] { display: none; }
.chart-note { margin: 0 0 10px; font-size: 13px; color: var(--fg-muted); }

/* Transactions: grouped by insider */
.group-row td { background: var(--bg-card-subtle); border-bottom-color: var(--line); }
.group-child td { font-size: 13px; color: var(--fg-muted); }
.group-child .date-cell { padding-left: 28px; }
.group-child[hidden] { display: none; }
.group-toggle {
  margin-left: 8px;
  padding: 0;
  font: inherit;
  font-size: 12.5px;
  color: var(--accent-text);
  background: none;
  border: 0;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}
.group-toggle:hover { color: var(--accent-hover); }
.grid tfoot td { padding: 9px 12px; border-top: 1px solid var(--line-strong); background: var(--table-header-bg); font-size: 13.5px; }
.foot-label { font-size: 12.5px; font-weight: 600; color: var(--fg-muted); }

/* Tape pause control (WCAG 2.2.2) */
.tape-pause {
  flex: none;
  padding: 0 14px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--fg-muted);
  background: var(--bg-card-subtle);
  border: 0;
  border-right: 1px solid var(--line);
  cursor: pointer;
}
.tape-pause:hover { color: var(--fg); }
.tape-pause:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.tape-pause[hidden] { display: none; }
.tape-track.is-paused .tape-inner { animation-play-state: paused; }
.analysis-grid { align-items: start; }

/* --- Direction switch (Buys / Sells / Both) ----------------------------- */
.seg {
  display: inline-flex;
  align-self: flex-end;
  margin: 0;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-panel);
  min-width: 0;
  overflow: hidden;
}
.seg-opt { position: relative; cursor: pointer; }
.seg-opt + .seg-opt { border-left: 1px solid var(--line); }
.seg-opt input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.seg-opt span { display: block; padding: 5px 14px; font-size: 13px; font-weight: 500; color: var(--fg-muted); }
.seg-opt:hover span { color: var(--fg); background: var(--bg-card-hover); }
.seg-opt input:checked + span { background: var(--fg); color: var(--bg-panel); font-weight: 600; }
.seg-opt input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }

/* Value coloured by side */
.total-val.total-P { color: var(--buy); }
.total-val.total-S { color: var(--sell); }

/* --- Responsive --------------------------------------------------------- */
@media (max-width: 1100px) {
  .ticker-search input { width: 110px; }
}
@media (max-width: 860px) {
  .topbar { flex-wrap: wrap; height: auto; padding-top: 8px; padding-bottom: 0; row-gap: 4px; }
  .topbar-nav { order: 3; flex: 1 0 100%; }
  .tape-label { padding-left: 16px; }
  .ticker-search input { width: 120px; }
}
@media (max-width: 720px) {
  .kpi-strip { grid-template-columns: 1fr 1fr; }
  .kpi, .kpi + .kpi { padding: 10px 12px 10px 0; border-left: 0; }
  .kpi:nth-child(even) { padding-left: 12px; border-left: 1px solid var(--line-subtle); }
  .kpi:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .seg { align-self: stretch; }
  .seg-opt { flex: 1; text-align: center; }
  /* Rows become stacked records: each cell shows its column label. */
  #results .table-wrap { border: 0; background: transparent; overflow: visible; }
  #results .grid, #results .grid tbody, #results .grid tr, #results .grid td { display: block; width: 100%; }
  #results .grid thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  #results .grid tbody tr {
    margin-bottom: 8px;
    padding: 4px 12px;
    background: var(--bg-panel);
    border: 1px solid var(--line);
  }
  #results .grid td[data-label] {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 7px 0;
    border: 0;
    text-align: right !important;
  }
  #results .grid td[data-label] + td[data-label] { border-top: 1px solid var(--line-subtle); }
  #results .grid td[data-label]::before {
    content: attr(data-label);
    flex: none;
    font-size: 12.5px;
    color: var(--fg-muted);
  }
  #results .grid td .company-cell, #results .grid td .insider-cell { justify-content: flex-end; flex-wrap: wrap; }
  #results .grid td.empty { text-align: center !important; }
}
@media (prefers-reduced-motion: reduce) {
  .tape-track.is-moving .tape-inner { animation: none; }
}
