/**
 * Discovery Page Styles
 * 
 * A clean, modern design for the stock discovery/screener page.
 * Uses CSS custom properties for theming.
 */

/* =============================================================================
   CSS VARIABLES
   ============================================================================= */

:root {
  /* Colors - Clean light theme */
  --bg-primary: #ffffff;
  --bg-secondary: #f8f9fa;
  --bg-tertiary: #f1f3f5;
  --bg-hover: #e9ecef;
  
  --text-primary: #212529;
  --text-secondary: #495057;
  --text-muted: #868e96;
  
  --accent-primary: #228be6;
  --accent-secondary: #1971c2;
  --accent-hover: #1c7ed6;
  
  --success: #2f9e44;
  --success-bg: rgba(47, 158, 68, 0.1);
  --danger: #e03131;
  --danger-bg: rgba(224, 49, 49, 0.1);
  --warning: #f59f00;
  
  --border: #dee2e6;
  --border-light: #e9ecef;
  
  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
  
  /* Sizing */
  --sidebar-width: 280px;
  --header-height: 60px;
  
  /* Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "SF Mono", "Fira Code", "Consolas", monospace;
  
  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.5);
  
  /* Borders */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
}

/* =============================================================================
   BASE STYLES
   ============================================================================= */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
}

body {
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-primary);
}

a {
  color: var(--accent-primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* =============================================================================
   LAYOUT
   ============================================================================= */

.discover-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.discover-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-md) var(--space-lg);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  height: var(--header-height);
}

.header-left {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
}

.header-left h1 {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
}

.back-link {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.back-link:hover {
  color: var(--accent-primary);
}

.header-right {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.last-updated {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Auth container */
.auth-container {
  display: flex;
  align-items: center;
}

.auth-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 1rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.8125rem;
  border: 1px solid var(--border);
  background: var(--bg-primary);
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.2s;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  line-height: 1;
}

.auth-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  background: var(--accent-primary);
  color: white;
  border-color: var(--accent-primary);
}

.discover-main {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* =============================================================================
   FILTERS PANEL
   ============================================================================= */

.filters-panel {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  padding: var(--space-lg);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  transition: width 0.2s ease, min-width 0.2s ease, padding 0.2s ease, opacity 0.2s ease;
}

.filters-panel.collapsed {
  width: 0;
  min-width: 0;
  padding: 0;
  overflow: hidden;
  border-right: none;
  opacity: 0;
  pointer-events: none;
}

.filters-panel h2 {
  font-size: 0.875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  margin-bottom: var(--space-lg);
}

.filter-group {
  margin-bottom: var(--space-md);
}

.filter-group label {
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: var(--space-xs);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.filter-select,
.filter-input {
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.875rem;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.filter-select:focus,
.filter-input:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 2px rgba(34, 139, 230, 0.2);
}

.filter-select option {
  background: var(--bg-primary);
}

.filter-divider {
  border: none;
  border-top: 1px solid var(--border-light);
  margin: var(--space-lg) 0;
}

.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-xs);
}

.checkbox-grid label,
.checkbox-stack label {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  font-size: 0.8rem;
  color: var(--text-primary);
  cursor: pointer;
}

.checkbox-stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.checkbox-grid input[type="checkbox"],
.checkbox-stack input[type="checkbox"] {
  accent-color: var(--accent-primary);
}

/* Toggle buttons for asset type selection */
.toggle-buttons {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.toggle-btn {
  padding: 6px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.15s;
  color: var(--text-secondary);
}

.toggle-btn:hover {
  background: var(--bg-hover);
  border-color: var(--accent-primary);
}

.toggle-btn.active {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: white;
}

.filter-hint {
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.apply-btn {
  width: 100%;
  padding: var(--space-md);
  margin-top: var(--space-lg);
  background: var(--accent-primary);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.apply-btn:hover {
  background: var(--accent-hover);
}

.apply-btn:active {
  transform: scale(0.98);
}

.hidden {
  display: none !important;
}

/* =============================================================================
   TOM SELECT OVERRIDES
   ============================================================================= */

.ts-wrapper {
  font-size: 0.85rem;
}

.ts-wrapper.multi .ts-control {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
}

.ts-wrapper.multi .ts-control > .item {
  background: var(--accent-primary);
  color: white;
  border-radius: 3px;
  padding: 2px 6px;
  margin: 2px;
  font-size: 0.75rem;
}

.ts-wrapper.single .ts-control {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
}

.ts-dropdown {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
}

.ts-dropdown .option {
  padding: 8px 12px;
  font-size: 0.85rem;
}

.ts-dropdown .option.active {
  background: var(--bg-hover);
}

.ts-dropdown .option:hover {
  background: var(--bg-hover);
}

.ts-wrapper.focus .ts-control {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 2px rgba(34, 139, 230, 0.2);
}

/* =============================================================================
   RESULTS AREA
   ============================================================================= */

.results-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: var(--space-lg);
  overflow: hidden;
  position: relative;
}

.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-md);
  flex-shrink: 0;
}

.results-meta {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.results-separator {
  margin: 0 var(--space-sm);
  color: var(--text-muted);
}

.results-actions {
  display: flex;
  gap: var(--space-sm);
}

.action-btn {
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.15s;
}

.action-btn:hover:not(:disabled) {
  background: var(--bg-hover);
}

.action-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* =============================================================================
   TABLE
   ============================================================================= */

.table-wrapper {
  flex: 1;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
}

.discover-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.discover-table thead {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg-tertiary);
}

.discover-table th {
  padding: var(--space-sm) var(--space-md);
  text-align: left;
  font-weight: 600;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
  user-select: none;
}

.discover-table th.sortable {
  cursor: pointer;
}

.discover-table th.sortable:hover {
  color: var(--accent-primary);
}

.discover-table th .sort-icon {
  font-size: 0.6rem;
  color: var(--accent-primary);
}

.discover-table th.sorted-asc,
.discover-table th.sorted-desc {
  color: var(--accent-primary);
  background: rgba(29, 155, 240, 0.1);
}

/* Highlight the primary sort column (first in returns list) */
.discover-table th.sorted-column {
  color: var(--accent-primary);
  background: rgba(29, 155, 240, 0.08);
  font-weight: 600;
}

.discover-table th.sorted-column .sort-icon {
  opacity: 1;
}

.discover-table tbody tr {
  border-bottom: 1px solid var(--border-light);
  transition: background 0.1s;
}

.discover-table tbody tr:hover {
  background: var(--bg-hover);
}

.discover-table td {
  padding: var(--space-sm) var(--space-md);
  white-space: nowrap;
}

/* Ticker cell */
.discover-table .ticker-cell {
  font-weight: 600;
  font-family: var(--font-mono);
  color: var(--accent-primary);
}

.discover-table .ticker-cell:hover {
  color: var(--accent-secondary);
  cursor: pointer;
}

/* Company info cell (Name + Sector/Industry) */
.discover-table .company-info-cell {
  min-width: 280px;
  max-width: 350px;
  padding: 6px 12px;
}

.discover-table .company-name {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.discover-table .company-meta {
  font-size: 0.7rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
  margin-top: 2px;
}

/* Links cell (Yahoo/Google Finance) */
.discover-table .links-cell {
  padding: 6px 8px;
  white-space: nowrap;
}

.discover-table .links-cell a {
  display: inline-block;
  font-size: 0.7rem;
  color: var(--text-muted);
  text-decoration: none;
  padding: 2px 6px;
  border-radius: 3px;
  background: var(--bg-secondary);
  margin-right: 4px;
  transition: all 0.15s ease;
}

.discover-table .links-cell a:hover {
  color: var(--primary);
  background: var(--bg-tertiary);
}

/* Price cells */
.discover-table .price-cell {
  text-align: right;
  font-family: 'SF Mono', 'Menlo', monospace;
  font-size: 0.85rem;
  white-space: nowrap;
  padding: 8px 12px;
}

/* Sparkline cells */
.discover-table .sparkline-cell {
  padding: 6px 10px;
  width: 150px;
  min-width: 150px;
  max-width: 150px;
  position: relative;
}

.discover-table .sparkline-header {
  text-align: center;
  width: 150px;
}

.sparkline-svg {
  display: block;
  width: 100%;
  height: 40px;
}

.sparkline-empty {
  color: var(--text-muted);
  font-size: 0.75rem;
}

/* Sparkline tooltip */
.sparkline-tooltip {
  display: none;
  position: fixed;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.25rem;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
  z-index: 99999;
  min-width: 320px;
  font-size: 0.85rem;
  pointer-events: none;
}

.sparkline-tooltip .tooltip-title {
  font-weight: 700;
  font-size: 0.9rem;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-light);
}

.sparkline-tooltip .tooltip-chart {
  margin: 8px 0 12px;
}

.sparkline-tooltip .tooltip-chart svg {
  width: 240px;
  height: 80px;
  display: block;
}

.sparkline-tooltip .sparkline-legend {
  margin-top: 6px;
  display: flex;
  gap: 12px;
  align-items: center;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.sparkline-tooltip .legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.sparkline-tooltip .legend-line {
  display: inline-block;
  width: 18px;
  border-top: 2px solid currentColor;
}

.sparkline-tooltip .legend-line.benchmark {
  border-top-style: dashed;
  border-top-color: #6b7280;
}

.sparkline-tooltip .tooltip-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 0;
  gap: 16px;
}

.sparkline-tooltip .tooltip-label {
  color: var(--text-secondary);
  flex-shrink: 0;
}

.sparkline-tooltip .tooltip-value {
  font-weight: 600;
  font-family: var(--font-mono);
  text-align: right;
}

.sparkline-tooltip .tooltip-value.positive {
  color: var(--success);
}

.sparkline-tooltip .tooltip-value.negative {
  color: var(--danger);
}

/* Range bar visual */
.sparkline-tooltip .range-bar-container {
  margin: 10px 0;
  padding: 8px 0;
  border-top: 1px solid var(--border-light);
  border-bottom: 1px solid var(--border-light);
}

.sparkline-tooltip .range-bar-label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-bottom: 6px;
  display: flex;
  justify-content: space-between;
}

.sparkline-tooltip .range-bar {
  position: relative;
  height: 8px;
  background: linear-gradient(to right, var(--danger), #fbbf24, var(--success));
  border-radius: 4px;
  margin: 4px 0;
}

.sparkline-tooltip .range-bar-marker {
  position: absolute;
  top: -4px;
  width: 16px;
  height: 16px;
  background: var(--text-primary);
  border: 2px solid white;
  border-radius: 50%;
  transform: translateX(-50%);
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.sparkline-tooltip .drawdown-info {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  margin-top: 6px;
}

.sparkline-tooltip .drawdown-info .drawdown-value {
  font-weight: 600;
  color: var(--danger);
}

/* Performance colors */
.discover-table .performance-positive {
  color: var(--success);
}

.discover-table .performance-negative {
  color: var(--danger);
}

/* Preset columns */
.discover-table .preset-return-cell {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  text-align: right;
  white-space: nowrap;
}

/* Ensure consistent width for return values */
.discover-table .return-value {
  display: inline-block;
  min-width: 58px;
  text-align: right;
}

.discover-table .rank-capsule {
  display: inline-block;
  min-width: 32px;
  text-align: center;
  margin-left: 4px;
}

/* Numeric columns alignment (market cap onwards - column 4+) */
.discover-table td:nth-child(n+4) {
  text-align: right;
  font-family: var(--font-mono);
}

.discover-table th:nth-child(n+4) {
  text-align: right;
}

/* Sparkline column should be centered */
.discover-table .sparkline-cell {
  text-align: center;
}

/* Company column should be left-aligned */
.discover-table td:nth-child(3) {
  text-align: left;
}

.discover-table .preset-return-header {
  min-width: 70px;
  text-align: right;
}

/* Rank capsule */
.metric-rank-capsule {
  display: inline-block;
  padding: 1px 5px;
  margin-left: 4px;
  font-size: 0.65rem;
  font-weight: 600;
  border-radius: 3px;
  border: 1px solid;
}

/* Multi-period summary */
.preset-summary-cell {
  position: relative;
  min-width: 160px;
}

.preset-summary-chart {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 40px;
  padding: 6px 12px;
}

.preset-summary-bar {
  flex: 1;
  min-width: 6px;
  max-width: 14px;
  border-radius: 2px 2px 0 0;
  transition: opacity 0.15s;
}

.preset-summary-cell:hover .preset-summary-bar {
  opacity: 0.8;
}

.preset-summary-monotonic {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 0 12px 6px;
}

.preset-summary-monotonic .mono-block {
  flex: 1;
  min-width: 6px;
  max-width: 14px;
  height: 6px;
  border-radius: 2px;
  opacity: 0.9;
}

.mono-up {
  background: var(--success);
}

.mono-down {
  background: var(--danger);
}

/* Multi-period tooltip (uses core positioning) */
.preset-summary-tooltip {
  display: none;
  position: fixed;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.25rem;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
  z-index: 99999;
  min-width: 280px;
  max-width: 400px;
  pointer-events: none;
  font-size: 0.85rem;
}

.preset-summary-tooltip .tooltip-header {
  font-weight: 700;
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border-light);
}

.preset-summary-tooltip .tooltip-avg-rank {
  font-weight: 600 !important;
  margin-bottom: 0.75rem !important;
  padding-bottom: 0.75rem !important;
}

.preset-summary-tooltip .tooltip-note {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.preset-summary-tooltip .tooltip-table {
  display: grid;
  grid-template-columns: 22px 40px minmax(80px, auto) minmax(60px, auto) 16px;
  gap: 8px 12px;
  align-items: center;
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

.preset-summary-tooltip .tooltip-dot {
  text-align: center;
  font-size: 0.9rem;
  line-height: 1;
  width: 22px;
}

.preset-summary-tooltip .tooltip-period {
  font-weight: 600;
  text-align: left;
  color: var(--text-secondary);
}

.preset-summary-tooltip .tooltip-return {
  text-align: right;
  font-weight: 500;
  white-space: nowrap;
}

.preset-summary-tooltip .tooltip-rank {
  text-align: right;
  color: var(--text-muted);
  font-size: 0.75rem;
  white-space: nowrap;
}

.preset-summary-tooltip .tooltip-monotonic {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  justify-self: center;
}

.preset-summary-tooltip .tooltip-row-positive .tooltip-return {
  color: var(--success);
}

.preset-summary-tooltip .tooltip-row-negative .tooltip-return {
  color: var(--danger);
}

/* Generic cell tooltip (core) */
.cell-tooltip {
  display: none;
  position: fixed;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 99999;
  white-space: nowrap;
  min-width: 200px;
  pointer-events: none;
}

/* Average columns */
.avg-col {
  background: rgba(34, 139, 230, 0.08);
}

/* Benchmark comparison column */
.benchmark-col {
  background: rgba(139, 69, 180, 0.08);
}

/* Benchmark column header */
.discover-table .benchmark-header {
  white-space: nowrap;
  text-align: center;
}

.benchmark-cell {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  white-space: nowrap;
  text-align: center;
}

.benchmark-cell .beats-count {
  font-weight: 600;
}

.benchmark-cell .avg-outperf {
  margin-left: 4px;
  font-size: 0.7rem;
}

.benchmark-cell.outperformer {
  color: var(--success);
}

.benchmark-cell.underperformer {
  color: var(--danger);
}

.benchmark-cell.neutral {
  color: var(--text-secondary);
}

/* Benchmark tooltip */
.benchmark-tooltip {
  display: none;
  position: fixed;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.25rem;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
  z-index: 99999;
  min-width: 360px;
  pointer-events: none;
}

.benchmark-tooltip .tooltip-header {
  font-weight: 600;
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-light);
}

/* Benchmark tooltip header section */
.benchmark-tooltip .tooltip-header-section {
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-light);
}

.benchmark-tooltip .tooltip-title {
  font-weight: 700;
  font-size: 0.9rem;
  margin-bottom: 4px;
}

.benchmark-tooltip .tooltip-avg-line {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.benchmark-tooltip .avg-outperf-value {
  font-weight: 600;
  font-family: var(--font-mono);
}

.benchmark-tooltip .avg-outperf-value.positive {
  color: var(--success);
}

.benchmark-tooltip .avg-outperf-value.negative {
  color: var(--danger);
}

/* Benchmark tooltip table */
.benchmark-tooltip .tooltip-table {
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

.benchmark-tooltip .tooltip-table-header,
.benchmark-tooltip .tooltip-table-row {
  display: grid;
  grid-template-columns: 50px 80px 80px 80px 24px;
  gap: 8px;
  align-items: center;
  padding: 5px 0;
}

.benchmark-tooltip .tooltip-table-header {
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border-light);
  margin-bottom: 4px;
}

.benchmark-tooltip .tooltip-table-row.beat {
  color: var(--success);
}

.benchmark-tooltip .tooltip-table-row.lost {
  color: var(--danger);
}

.benchmark-tooltip .tooltip-table-row.neutral {
  color: var(--text-muted);
}

.benchmark-tooltip .col-period {
  text-align: left;
}

.benchmark-tooltip .col-ticker,
.benchmark-tooltip .col-bench,
.benchmark-tooltip .col-diff {
  text-align: right;
}

.benchmark-tooltip .col-result {
  text-align: center;
  font-size: 0.9rem;
}

/* Sticky columns - Favorites (left: 0) and Ticker (left: 36px) */
.fav-cell,
th.fav-header {
  position: sticky;
  left: 0;
  z-index: 6;
  background: var(--bg-tertiary);
}

.discover-table tbody .fav-cell {
  background: var(--bg-secondary);
}

.discover-table tbody tr:hover .fav-cell {
  background: var(--bg-hover);
}

.sticky-col {
  position: sticky;
  left: 36px; /* Offset by fav column width */
  background: var(--bg-tertiary);
  z-index: 5;
}

.discover-table tbody .sticky-col {
  background: var(--bg-secondary);
}

.discover-table tbody tr:hover .sticky-col {
  background: var(--bg-hover);
}

/* =============================================================================
   PAGINATION
   ============================================================================= */

.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: var(--space-lg);
  padding: var(--space-md);
  flex-shrink: 0;
}

.page-btn {
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.15s;
}

.page-btn:hover:not(:disabled) {
  background: var(--bg-hover);
}

.page-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.page-info {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* =============================================================================
   LOADING & ERRORS
   ============================================================================= */

.loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: var(--space-md);
  background: rgba(255, 255, 255, 0.9);
  z-index: 100;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-overlay span {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.error-message {
  padding: var(--space-md);
  margin: var(--space-md) 0;
  background: var(--danger-bg);
  border: 1px solid var(--danger);
  border-radius: var(--radius-md);
  color: var(--danger);
  text-align: center;
}

/* =============================================================================
   FOOTER
   ============================================================================= */

.discover-footer {
  padding: var(--space-md) var(--space-lg);
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  text-align: center;
}

.discover-footer p {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* =============================================================================
   RESPONSIVE
   ============================================================================= */

@media (max-width: 1024px) {
  .discover-main {
    flex-direction: column;
  }
  
  .filters-panel {
    width: 100%;
    min-width: 100%;
    max-height: 50vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  
  .checkbox-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (max-width: 640px) {
  .discover-header {
    flex-direction: column;
    gap: var(--space-sm);
    height: auto;
    padding: var(--space-sm) var(--space-md);
  }
  
  .header-left h1 {
    font-size: 1rem;
  }
  
  .filters-panel {
    padding: var(--space-md);
  }
  
  .results-area {
    padding: var(--space-md);
  }
  
  .results-header {
    flex-direction: column;
    gap: var(--space-sm);
  }
  
  .checkbox-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* =============================================================================
   HELP TOOLTIPS
   (Shared styles from main app - needed for table header help icons)
   ============================================================================= */

/* Backdrop overlay when tooltip is open */
.help-tooltip-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.25);
  z-index: 99999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  cursor: pointer;
}

.help-tooltip-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

/* Custom animated cursor for help tooltips */
.help-cursor {
  position: fixed;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  pointer-events: none;
  z-index: 999999;
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.5);
  transition: opacity 0.15s ease, transform 0.15s ease;
  background: linear-gradient(135deg, #a8b4f0 0%, #c4a8f7 25%, #ffc4e8 50%, #f0a8d0 75%, #a8b4f0 100%);
  background-size: 200% 200%;
  animation: helpCursorGradient 3s ease infinite;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  font-size: 12px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  box-shadow: 0 0 10px rgba(168, 180, 240, 0.5),
              0 0 20px rgba(184, 164, 217, 0.3);
}

.help-cursor.active {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

@keyframes helpCursorGradient {
  0% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

/* Help label styles */
.has-help-tooltip {
  cursor: none;
}

.has-help-tooltip input,
.has-help-tooltip select,
.has-help-tooltip button {
  cursor: pointer;
}

.has-help-tooltip:hover {
  color: var(--accent-primary);
}

.has-help-tooltip:hover .help-icon {
  background: rgba(34, 139, 230, 0.25);
  border-color: rgba(34, 139, 230, 0.7);
  color: var(--accent-primary);
  transform: scale(1.1);
}

/* Table headers with help */
th[data-help] {
  position: relative;
  white-space: nowrap;
}

th[data-help] .help-icon {
  margin-left: 0.25rem;
  position: relative;
  top: -1px;
}

/* Help icon - matching main app style */
.help-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  margin-left: 0.35rem;
  border-radius: 50%;
  background: rgba(34, 139, 230, 0.12);
  border: 1.5px solid rgba(34, 139, 230, 0.4);
  color: rgba(34, 139, 230, 0.85);
  font-size: 9px;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
  position: relative;
  transition: all 0.15s ease;
  vertical-align: middle;
  line-height: 1;
}

.help-icon:hover {
  background: rgba(34, 139, 230, 0.25);
  border-color: rgba(34, 139, 230, 0.7);
  color: var(--accent-primary);
  transform: scale(1.1);
}

.help-icon.active {
  background: rgba(34, 139, 230, 0.3);
  border-color: var(--accent-primary);
  color: var(--accent-primary);
  transform: scale(1.1);
}

/* Help tooltip popup */
.help-tooltip {
  position: fixed;
  top: auto;
  left: auto;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.25rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  z-index: 100000;
  width: 420px;
  max-width: calc(100vw - 40px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--text-primary);
  text-align: left;
  white-space: normal;
  box-sizing: border-box;
}

.help-tooltip.visible {
  opacity: 1;
  pointer-events: auto;
}

/* Markdown content in tooltips */
.help-tooltip h1,
.help-tooltip h2,
.help-tooltip h3 {
  margin: 0 0 0.5rem 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.help-tooltip p {
  margin: 0 0 0.75rem 0;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.help-tooltip p:last-child {
  margin-bottom: 0;
}

.help-tooltip strong {
  font-weight: 600;
  color: var(--text-primary);
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.help-tooltip ul {
  margin: 0.5rem 0;
  padding-left: 1.25rem;
}

.help-tooltip li {
  margin: 0.35rem 0;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.help-tooltip code {
  background: var(--bg-secondary);
  padding: 0.125rem 0.35rem;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.85em;
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: pre-wrap;
}

.help-tooltip em {
  font-style: italic;
  color: var(--text-muted);
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/* =============================================================================
   FAVORITES (Heart column)
   ============================================================================= */

/* Heart cell */
.fav-cell {
  width: 36px;
  min-width: 36px;
  max-width: 36px;
  padding: 4px !important;
  text-align: center;
  border-right: 1px solid var(--border-light);
  vertical-align: middle;
}

/* Heart button */
.fav-heart-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 50%;
  transition: all 0.15s ease;
}

.fav-heart-btn:hover {
  background: var(--bg-hover);
  transform: scale(1.1);
}

.fav-heart-btn:active {
  transform: scale(0.95);
}

/* Heart icon */
.fav-heart-icon {
  fill: none;
  transition: all 0.2s ease;
}

.fav-heart-icon .heart-outline {
  fill: none;
  stroke: var(--text-muted);
  stroke-width: 1.5;
  transition: all 0.2s ease;
}

.fav-heart-icon .heart-fill {
  fill: transparent;
  stroke: none;
  transition: all 0.2s ease;
}

.fav-heart-btn:hover .heart-outline {
  stroke: var(--danger);
}

/* Favorited state */
.fav-heart-btn.is-favorited .heart-outline {
  stroke: var(--danger);
  fill: var(--danger);
}

.fav-heart-btn.is-favorited .heart-fill {
  fill: var(--danger);
}

.fav-heart-btn.is-favorited:hover {
  background: var(--danger-bg);
}

/* Badge for multiple lists */
.fav-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  min-width: 14px;
  height: 14px;
  padding: 0 3px;
  font-size: 9px;
  font-weight: 700;
  line-height: 14px;
  text-align: center;
  color: white;
  background: var(--accent-primary);
  border-radius: 7px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

/* Make button position relative for badge positioning */
.fav-heart-btn {
  position: relative;
}

/* Favorites dropdown */
.fav-dropdown {
  position: fixed;
  z-index: 9999;
  min-width: 200px;
  max-width: 280px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  overflow: hidden;
}

.fav-dropdown-header {
  padding: 10px 12px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}

.fav-dropdown-title {
  font-weight: 600;
  font-size: 0.8125rem;
  color: var(--text-primary);
}

.fav-dropdown-lists {
  max-height: 240px;
  overflow-y: auto;
  padding: 4px 0;
}

.fav-dropdown-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  transition: background 0.1s ease;
}

.fav-dropdown-item:hover {
  background: var(--bg-hover);
}

.fav-dropdown-label {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0; /* Allow text truncation */
  cursor: pointer;
}

.fav-dropdown-item input[type="checkbox"] {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  margin: 0;
  cursor: pointer;
  accent-color: var(--accent-primary);
}

/* List action buttons (rename, delete) */
.fav-list-actions {
  display: flex;
  gap: 2px;
  width: 50px; /* Fixed width to ensure alignment */
  justify-content: flex-end;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.fav-dropdown-item:hover .fav-list-actions {
  opacity: 1;
}

.fav-action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: none;
  border-radius: 4px;
  background: transparent;
  cursor: pointer;
  transition: all 0.1s ease;
}

.fav-action-btn svg {
  fill: var(--text-muted);
}

.fav-action-btn:hover {
  background: var(--bg-tertiary);
}

.fav-action-btn:hover svg {
  fill: var(--text-primary);
}

.fav-delete-btn:hover {
  background: var(--danger-bg);
}

.fav-delete-btn:hover svg {
  fill: var(--danger);
}

.fav-list-name {
  flex: 1;
  font-size: 0.875rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0; /* Allow truncation */
}

.fav-list-count {
  font-size: 0.75rem;
  color: var(--text-muted);
  flex-shrink: 0;
  min-width: 32px; /* Fixed width for alignment */
  text-align: right;
}

.fav-dropdown-footer {
  padding: 8px 12px;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
}

.fav-new-list-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 6px 8px;
  border: 1px dashed var(--border);
  border-radius: 4px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.8125rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.fav-new-list-btn:hover {
  background: var(--bg-primary);
  border-color: var(--accent-primary);
  color: var(--accent-primary);
}

.fav-new-list-btn svg {
  fill: currentColor;
}

/* Favorites header */
th.fav-header {
  width: 36px !important;
  min-width: 36px !important;
  max-width: 36px !important;
  padding: 4px !important;
  text-align: center;
  vertical-align: middle;
  border-right: 1px solid var(--border-light);
}

.fav-header-icon {
  fill: none;
  stroke: var(--text-muted);
  stroke-width: 1.5;
  vertical-align: middle;
}

/* Favorite list selector in sidebar */
#favorite-list-group .label-icon {
  color: var(--danger);
}

#favorite-list-hint {
  display: none;
  color: var(--warning);
  font-style: italic;
}

/* When viewing a favorites list */
.viewing-favorites #favorite-list-hint {
  display: block;
}

.viewing-favorites .filterable-group {
  opacity: 0.5;
  pointer-events: none;
}

.viewing-favorites .filterable-group select,
.viewing-favorites .filterable-group input,
.viewing-favorites .filterable-group button {
  pointer-events: none;
}

/* Sign-in Modal (fallback when Clerk unavailable) */
.fav-signin-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  backdrop-filter: blur(2px);
}

.fav-signin-modal {
  background: var(--bg-primary);
  border-radius: 12px;
  padding: 2rem;
  max-width: 400px;
  width: 90%;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  animation: modalSlideIn 0.2s ease-out;
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: translateY(-20px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.fav-signin-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
}

.fav-signin-modal h3 {
  margin: 0 0 0.5rem 0;
  font-size: 1.25rem;
  color: var(--text-primary);
}

.fav-signin-modal p {
  margin: 0 0 1.5rem 0;
  color: var(--text-secondary);
  font-size: 0.9rem;
  line-height: 1.5;
}

.fav-signin-actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.fav-signin-btn {
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  border: none;
}

.fav-signin-primary {
  background: var(--accent-primary);
  color: white;
}

.fav-signin-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.fav-signin-secondary {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.fav-signin-secondary:hover {
  background: var(--bg-hover);
}

.fav-signin-debug-hint {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.75rem;
}

.fav-signin-debug-hint code {
  background: var(--bg-secondary);
  padding: 0.125rem 0.35rem;
  border-radius: 4px;
  font-family: var(--font-mono);
}
