/* ============================================================
   Stocks Explorer — layout, watchlist tray/table, daily summary,
   alerts editor, and responsive rules
   ============================================================ */

/* Generic safety: Plotly graphs must never overflow their parent. */
.js-plotly-plot,
.plot-container,
.dash-graph,
.svg-container {
  max-width: 100%;
}

/* ── Watchlist tray ───────────────────────────────────────── */
.watchlist-chip {
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  /* Allow shrinkage so chips wrap on a narrow viewport. */
  min-width: 0;
}

.watchlist-chip:hover {
  border-color: #98a2b3;
}

.watchlist-chip--primary:hover {
  background: #1d2939;
  border-color: #1d2939;
}

.watchlist-chip button {
  color: inherit;
  background: transparent;
}

.watchlist-chip button:hover {
  opacity: 0.85;
  text-decoration: underline;
}

/* When the watchlist has many tickers, allow the chip rail to scroll
   horizontally on cramped screens rather than pushing other UI down. */
.watchlist-chips {
  overflow-x: auto;
  scrollbar-width: thin;
}

.watchlist-quick-add-input:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.watchlist-quick-add-btn:hover {
  background: #1d2939;
}

/* ── Watchlist table ──────────────────────────────────────── */
.watchlist-table-card {
  /* DataTable provides its own scroll wrapper; ensure we don't double-scroll. */
  overflow: hidden;
}

.watchlist-table-card .dash-table-container {
  font-family: inherit;
}

.watchlist-table-card .dash-spreadsheet-container {
  font-size: 12px;
}

.watchlist-table-card .dash-spreadsheet-container .dash-cell-value {
  white-space: normal !important;
  overflow: hidden;
  text-overflow: ellipsis;
}

.watchlist-table-card .dash-spreadsheet-container .Select-control {
  font-size: 12px;
  min-height: 28px;
  height: 28px;
}

.watchlist-table-card .dash-spreadsheet-container input {
  font-size: 12px !important;
}

.watchlist-table-card .dash-spreadsheet-container .dash-filter input {
  height: 24px;
}

.watchlist-table-toolbar {
  align-items: flex-end;
}

/* ── Daily summary tiles ──────────────────────────────────── */
.watchlist-summary-grid > div:hover {
  border-color: #b6c2d1;
}

/* ── Alerts panel ─────────────────────────────────────────── */
.alerts-form .Select-control {
  height: 32px;
  min-height: 32px;
  font-size: 13px;
}

/* ── Discovery tabs ───────────────────────────────────────── */
.discovery-card .tab {
  font-weight: 600;
}

.discovery-card .tab--selected {
  border-top: 2px solid #101828 !important;
  color: #101828 !important;
}

/* ── Section headers ──────────────────────────────────────── */
.section-header h2 {
  margin: 0;
}

/* Active pipeline manifest, rendered once on page load (not polled). */
.data-freshness-indicator {
  color: var(--text-muted-color);
  font-size: 12px;
  line-height: 1.35;
  margin: -2px 0 10px;
}

.chart-data-details {
  margin: 8px 12px 12px;
  color: var(--text-soft-color);
}

.chart-data-details summary {
  cursor: pointer;
  font-weight: 700;
}

.chart-data-table {
  border-collapse: collapse;
  margin-top: 8px;
  width: 100%;
}

.chart-data-table th,
.chart-data-table td {
  border-bottom: 1px solid var(--border-color);
  padding: 6px 8px;
  text-align: right;
}

.chart-data-table th:first-child,
.chart-data-table td:first-child {
  text-align: left;
}

.skip-link {
  position: fixed;
  left: 12px;
  top: 12px;
  z-index: 2000;
  transform: translateY(-160%);
  background: var(--surface-bg);
  border: 2px solid var(--accent-color);
  border-radius: 6px;
  color: var(--text-color);
  font-weight: 700;
  padding: 8px 12px;
}

.skip-link:focus {
  transform: translateY(0);
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid var(--accent-color) !important;
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}

/* ── Mobile (≤ 720px) ─────────────────────────────────────── */
@media (max-width: 720px) {
  .page-container {
    padding: 10px !important;
    gap: 10px !important;
  }

  /* Stack control row vertically. */
  .control-row {
    flex-direction: column !important;
    align-items: stretch !important;
  }

  .control-row > div {
    flex: 1 1 100% !important;
    min-width: 0 !important;
  }

  .controls-stack {
    gap: 10px !important;
  }

  /* Tighter price summary cards on mobile. */
  .price-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 6px !important;
  }

  /* Tighter chip wrapping; force horizontal scroll if rail still overflows. */
  .watchlist-chips {
    gap: 6px !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    padding-bottom: 4px;
  }

  .watchlist-chip {
    font-size: 12px !important;
    flex: 0 0 auto;
  }

  .watchlist-quick-add-row {
    flex-wrap: wrap !important;
  }

  /* Cards: tighter padding. */
  .card,
  .price-chart-card,
  .stock-chart-card,
  .overview-card,
  .discovery-card,
  .watchlist-tray,
  .watchlist-table-card,
  .watchlist-summary,
  .alerts-panel {
    padding: 10px !important;
    border-radius: 10px !important;
  }

  .price-chart-card .js-plotly-plot,
  .price-chart-card .plotly-graph-div,
  .stock-chart-card .js-plotly-plot,
  .stock-chart-card .plotly-graph-div {
    min-height: 280px;
  }

  /* Native controls must not trigger iOS zoom, and primary touch targets stay
     comfortably usable without making desktop controls oversized. */
  .Select-input > input,
  .dash-dropdown input,
  input,
  textarea,
  select {
    font-size: 16px !important;
  }

  .stock-sidebar button,
  .stock-left-column button,
  .theme-control label {
    min-height: 44px;
  }

  /* Flatten the columns on phones so the watch list follows search before the
     chart/company/financial cards rather than far below the fold. */
  .stock-main-grid {
    display: flex !important;
    flex-direction: column;
  }

  .stock-left-column,
  .stock-sidebar {
    display: contents !important;
  }

  .watchlist-card { order: 1; }
  .stock-chart-card { order: 2; }
  .company-snapshot-card { order: 3; }
  .financials-card { order: 4; }
  .stock-sidebar > *:not(.watchlist-card) { order: 5; }

  .overview-card .js-plotly-plot,
  .overview-card .plotly-graph-div {
    min-height: 240px;
  }

  /* Daily summary collapses to single column on phones. */
  .watchlist-summary-grid {
    grid-template-columns: 1fr !important;
  }

  /* Watchlist toolbar stacks. */
  .watchlist-table-toolbar {
    flex-direction: column !important;
    align-items: stretch !important;
  }

  .watchlist-table-toolbar > div {
    width: 100%;
  }

  /* DataTable: rely on horizontal scroll. */
  .watchlist-table-card .dash-spreadsheet-container {
    overflow-x: auto;
  }

  /* Section header titles a touch smaller. */
  .section-header h2 {
    font-size: 13px !important;
  }

  /* Alerts form collapses to single column on phones. */
  .alerts-form {
    grid-template-columns: 1fr !important;
  }
}

/* ── Tablet (721px – 960px) ───────────────────────────────── */
@media (min-width: 721px) and (max-width: 960px) {
  .price-summary {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  }
}

/* ── Wide screens (≥ 961px): two-column overview ──────────── */
@media (min-width: 961px) {
  .overview-grid {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) !important;
  }
}

/* Only the selected session's source time is displayed on each card. */
.grow-watch-quote-stamp { padding: 0 42px 12px 16px; overflow-wrap: anywhere; }
.grow-watch-quote-time { font-size: 11px; color: var(--text-muted-color); margin-top: 2px; }
