/**
 * TickerPulse Enterprise Advanced Stock Screener Stylesheet 6.0
 * Responsive, Mobile-First, Accessible, Dark & Light Mode
 */

:root {
  --tp-scr-bg-surface: var(--tp-bg-surface, #131722);
  --tp-scr-bg-card: var(--tp-bg-surface-subtle, #1e222d);
  --tp-scr-bg-hover: rgba(255, 255, 255, 0.04);
  --tp-scr-border: var(--tp-border-color, rgba(255, 255, 255, 0.08));
  --tp-scr-text: var(--tp-text-primary, #f8fafc);
  --tp-scr-text-muted: var(--tp-text-muted, #94a3b8);
  --tp-scr-text-secondary: var(--tp-text-secondary, #cbd5e1);
  --tp-scr-primary: var(--tp-color-primary, #3b82f6);
  --tp-scr-primary-subtle: rgba(59, 130, 246, 0.12);
  --tp-scr-success: var(--tp-color-success, #10b981);
  --tp-scr-success-subtle: rgba(16, 185, 129, 0.12);
  --tp-scr-danger: var(--tp-color-danger, #ef4444);
  --tp-scr-danger-subtle: rgba(239, 68, 68, 0.12);
  --tp-scr-warning: var(--tp-color-warning, #f59e0b);
  --tp-scr-warning-subtle: rgba(245, 158, 11, 0.12);
  --tp-scr-radius-sm: 6px;
  --tp-scr-radius-md: 10px;
  --tp-scr-radius-lg: 14px;
}

[data-theme="light"] {
  --tp-scr-bg-surface: #ffffff;
  --tp-scr-bg-card: #f8fafc;
  --tp-scr-bg-hover: #f1f5f9;
  --tp-scr-border: #e2e8f0;
  --tp-scr-text: #0f172a;
  --tp-scr-text-muted: #64748b;
  --tp-scr-text-secondary: #334155;
  --tp-scr-primary-subtle: rgba(37, 99, 235, 0.08);
  --tp-scr-success-subtle: rgba(16, 185, 129, 0.08);
  --tp-scr-danger-subtle: rgba(239, 68, 68, 0.08);
  --tp-scr-warning-subtle: rgba(245, 158, 11, 0.08);
}

/* Global Container & Anti-Overflow */
.tp-screener-wrapper {
  max-width: 1360px;
  margin: 0 auto;
  padding: 0 1rem 3rem 1rem;
  overflow-x: hidden;
  box-sizing: border-box;
}

/* 1. Header Section */
.tp-screener-header {
  margin-bottom: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.tp-screener-title-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 1rem;
}

.tp-screener-title {
  font-family: var(--tp-font-heading, 'Outfit', sans-serif);
  font-size: clamp(1.6rem, 2.5vw, 2.2rem);
  font-weight: 900;
  line-height: 1.2;
  margin: 0;
  color: var(--tp-scr-text);
  letter-spacing: -0.02em;
}

.tp-screener-subtitle {
  color: var(--tp-scr-text-muted);
  font-size: 0.95rem;
  margin: 0.35rem 0 0 0;
  max-width: 760px;
  line-height: 1.45;
}

.tp-screener-meta-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  background: var(--tp-scr-bg-card);
  border: 1px solid var(--tp-scr-border);
  color: var(--tp-scr-text-secondary);
}

.tp-screener-meta-badge.live {
  border-color: rgba(16, 185, 129, 0.3);
  color: var(--tp-scr-success);
}

/* 2. Top Universe & Search Control Bar */
.tp-screener-ctrl-bar {
  background: var(--tp-scr-bg-card);
  border: 1px solid var(--tp-scr-border);
  border-radius: var(--tp-scr-radius-lg);
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.tp-screener-search-wrap {
  position: relative;
  flex: 1;
  min-width: 240px;
}

.tp-screener-search-wrap svg {
  position: absolute;
  left: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--tp-scr-text-muted);
  pointer-events: none;
}

.tp-screener-search-input {
  width: 100%;
  padding: 0.55rem 0.75rem 0.55rem 2.4rem;
  border-radius: var(--tp-scr-radius-md);
  border: 1px solid var(--tp-scr-border);
  background: var(--tp-scr-bg-surface);
  color: var(--tp-scr-text);
  font-size: 0.85rem;
  font-family: inherit;
  transition: all 0.2s ease;
  box-sizing: border-box;
}

.tp-screener-search-input:focus {
  outline: none;
  border-color: var(--tp-scr-primary);
  box-shadow: 0 0 0 3px var(--tp-scr-primary-subtle);
}

.tp-screener-universe-select,
.tp-screener-sector-select {
  padding: 0.55rem 0.85rem;
  border-radius: var(--tp-scr-radius-md);
  border: 1px solid var(--tp-scr-border);
  background: var(--tp-scr-bg-surface);
  color: var(--tp-scr-text);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  box-sizing: border-box;
}

.tp-screener-action-btns {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* 3. 8 Category Horizontal Scroll Tabs */
.tp-category-tabs-container {
  position: relative;
  margin-bottom: 1rem;
}

.tp-category-tabs {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding-bottom: 0.35rem;
  scrollbar-width: none;
  -ms-overflow-style: none;
  -webkit-overflow-scrolling: touch;
}

.tp-category-tabs::-webkit-scrollbar {
  display: none;
}

.tp-cat-tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.5rem 0.95rem;
  border-radius: 999px;
  background: var(--tp-scr-bg-card);
  border: 1px solid var(--tp-scr-border);
  color: var(--tp-scr-text-secondary);
  font-size: 0.825rem;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.tp-cat-tab-btn:hover {
  background: var(--tp-scr-bg-hover);
  border-color: var(--tp-scr-primary);
  color: var(--tp-scr-text);
}

.tp-cat-tab-btn.active {
  background: var(--tp-scr-primary);
  border-color: var(--tp-scr-primary);
  color: #ffffff;
  box-shadow: 0 4px 12px var(--tp-scr-primary-subtle);
}

/* 4. Quick Screen Presets Grid (Horizontal on mobile, flex grid on desktop) */
.tp-presets-scroll-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(270px, 1fr));
  gap: 0.85rem;
  margin-bottom: 1.25rem;
}

@media (max-width: 640px) {
  .tp-presets-scroll-grid {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    gap: 0.75rem;
    padding-bottom: 0.5rem;
    scrollbar-width: none;
  }
  .tp-presets-scroll-grid::-webkit-scrollbar { display: none; }
  .tp-preset-card {
    min-width: 250px;
    max-width: 260px;
    scroll-snap-align: start;
    flex-shrink: 0;
  }
}

.tp-preset-card {
  background: var(--tp-scr-bg-card);
  border: 1px solid var(--tp-scr-border);
  border-radius: var(--tp-scr-radius-md);
  padding: 0.9rem 1rem;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
}

.tp-preset-card:hover {
  transform: translateY(-2px);
  border-color: var(--tp-scr-primary);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
}

.tp-preset-card.active {
  border-color: var(--tp-scr-primary);
  background: var(--tp-scr-primary-subtle);
}

.tp-preset-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.35rem;
}

.tp-preset-title {
  font-size: 0.9rem;
  font-weight: 800;
  color: var(--tp-scr-text);
  margin: 0;
}

.tp-preset-badge {
  font-size: 0.7rem;
  font-weight: 800;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: var(--tp-scr-bg-surface);
  color: var(--tp-scr-primary);
  border: 1px solid var(--tp-scr-border);
  font-family: var(--tp-font-mono, monospace);
}

.tp-preset-subtitle {
  font-size: 0.75rem;
  color: var(--tp-scr-text-muted);
  font-family: var(--tp-font-mono, monospace);
  margin-bottom: 0.45rem;
  line-height: 1.35;
}

.tp-preset-desc {
  font-size: 0.75rem;
  color: var(--tp-scr-text-secondary);
  line-height: 1.35;
  margin-bottom: 0.65rem;
}

.tp-preset-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--tp-scr-primary);
  border: none;
  background: transparent;
  padding: 0;
  cursor: pointer;
}

/* 5. Custom Query Builder & Advanced Filter Drawer */
.tp-builder-card {
  background: var(--tp-scr-bg-card);
  border: 1px solid var(--tp-scr-border);
  border-radius: var(--tp-scr-radius-lg);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.tp-builder-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--tp-scr-border);
}

.tp-builder-title {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--tp-scr-text);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.tp-builder-rules-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-bottom: 1rem;
}

.tp-builder-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  background: var(--tp-scr-bg-surface);
  padding: 0.6rem 0.75rem;
  border-radius: var(--tp-scr-radius-md);
  border: 1px solid var(--tp-scr-border);
}

.tp-builder-select,
.tp-builder-input {
  padding: 0.45rem 0.65rem;
  border-radius: var(--tp-scr-radius-sm);
  border: 1px solid var(--tp-scr-border);
  background: var(--tp-scr-bg-card);
  color: var(--tp-scr-text);
  font-size: 0.825rem;
  font-family: inherit;
}

.tp-builder-select:focus,
.tp-builder-input:focus {
  outline: none;
  border-color: var(--tp-scr-primary);
}

.tp-builder-op-badge {
  font-weight: 800;
  font-size: 0.725rem;
  padding: 0.25rem 0.5rem;
  border-radius: var(--tp-scr-radius-sm);
  background: var(--tp-scr-primary-subtle);
  color: var(--tp-scr-primary);
  border: 1px solid rgba(59, 130, 246, 0.2);
}

.tp-builder-delete-btn {
  background: transparent;
  border: none;
  color: var(--tp-scr-danger);
  cursor: pointer;
  padding: 0.35rem;
  border-radius: var(--tp-scr-radius-sm);
  display: inline-flex;
  align-items: center;
}

.tp-builder-delete-btn:hover {
  background: var(--tp-scr-danger-subtle);
}

.tp-builder-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
}

/* 6. Active Filter Chips */
.tp-chips-container {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.tp-filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  background: var(--tp-scr-bg-card);
  border: 1px solid var(--tp-scr-border);
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--tp-scr-text);
}

.tp-chip-remove {
  background: transparent;
  border: none;
  color: var(--tp-scr-text-muted);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0;
  line-height: 1;
}

.tp-chip-remove:hover {
  color: var(--tp-scr-danger);
}

/* 7. Summary KPI Cards */
.tp-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.tp-summary-card {
  background: var(--tp-scr-bg-card);
  border: 1px solid var(--tp-scr-border);
  border-radius: var(--tp-scr-radius-md);
  padding: 0.85rem 1rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.tp-summary-label {
  font-size: 0.7rem;
  font-weight: 800;
  color: var(--tp-scr-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 0.25rem;
}

.tp-summary-val {
  font-family: var(--tp-font-mono, monospace);
  font-size: 1.35rem;
  font-weight: 900;
  color: var(--tp-scr-text);
  line-height: 1.1;
}

.tp-summary-sub {
  font-size: 0.7rem;
  color: var(--tp-scr-text-muted);
  margin-top: 0.25rem;
}

/* 8. Desktop Results Table & Customizer */
.tp-results-table-card {
  background: var(--tp-scr-bg-card);
  border: 1px solid var(--tp-scr-border);
  border-radius: var(--tp-scr-radius-lg);
  padding: 1.25rem;
  margin-bottom: 2.5rem;
}

.tp-results-table-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.tp-screener-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.825rem;
  text-align: left;
}

.tp-screener-table th {
  padding: 0.75rem 0.6rem;
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--tp-scr-text-muted);
  text-transform: uppercase;
  border-bottom: 1px solid var(--tp-scr-border);
  white-space: nowrap;
  background: var(--tp-scr-bg-card);
  position: sticky;
  top: 0;
  z-index: 10;
}

.tp-screener-table th.sortable {
  cursor: pointer;
  user-select: none;
}

.tp-screener-table th.sortable:hover {
  color: var(--tp-scr-primary);
}

.tp-screener-table td {
  padding: 0.75rem 0.6rem;
  border-bottom: 1px solid var(--tp-scr-border);
  color: var(--tp-scr-text);
  vertical-align: middle;
}

.tp-screener-table tr:hover td {
  background: var(--tp-scr-bg-hover);
}

.tp-screener-table .num-cell {
  text-align: right;
  font-family: var(--tp-font-mono, monospace);
  font-weight: 700;
  white-space: nowrap;
}

/* 52W Visual Bar */
.tp-52w-wrap {
  width: 100px;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.tp-52w-track {
  height: 4px;
  background: rgba(148, 163, 184, 0.2);
  border-radius: 999px;
  position: relative;
  overflow: hidden;
}

.tp-52w-progress {
  height: 100%;
  background: var(--tp-scr-primary);
  border-radius: 999px;
}

.tp-52w-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.65rem;
  color: var(--tp-scr-text-muted);
  font-family: var(--tp-font-mono, monospace);
}

/* Watchlist Star Button */
.tp-star-btn {
  background: transparent;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0.2rem;
  line-height: 1;
  color: var(--tp-scr-text-muted);
  transition: all 0.15s ease;
}

.tp-star-btn:hover {
  transform: scale(1.2);
  color: var(--tp-scr-warning);
}

.tp-star-btn.active {
  color: var(--tp-scr-warning);
}

/* 9. Mobile Stock Cards (Strictly active on screen < 768px) */
.tp-mobile-cards-container {
  display: none;
}

@media (max-width: 767px) {
  .tp-desktop-table-wrap {
    display: none !important;
  }
  .tp-mobile-cards-container {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
  }
}

.tp-mobile-card {
  background: var(--tp-scr-bg-surface);
  border: 1px solid var(--tp-scr-border);
  border-radius: var(--tp-scr-radius-md);
  padding: 0.95rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  transition: all 0.15s ease;
}

.tp-mobile-card:hover {
  border-color: var(--tp-scr-primary);
}

.tp-mobile-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.tp-mobile-card-symbol {
  font-size: 1rem;
  font-weight: 800;
  color: var(--tp-scr-text);
  margin: 0;
}

.tp-mobile-card-name {
  font-size: 0.75rem;
  color: var(--tp-scr-text-muted);
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
  max-width: 170px;
}

.tp-mobile-card-price {
  text-align: right;
  font-family: var(--tp-font-mono, monospace);
  font-size: 1.05rem;
  font-weight: 900;
  color: var(--tp-scr-text);
}

.tp-mobile-card-chg {
  font-size: 0.75rem;
  font-weight: 800;
  font-family: var(--tp-font-mono, monospace);
}

.tp-mobile-card-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.4rem;
  background: var(--tp-scr-bg-card);
  padding: 0.6rem;
  border-radius: var(--tp-scr-radius-sm);
  border: 1px solid var(--tp-scr-border);
  font-size: 0.725rem;
}

.tp-mobile-stat-item {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.tp-mobile-stat-lbl {
  font-size: 0.65rem;
  color: var(--tp-scr-text-muted);
  text-transform: uppercase;
}

.tp-mobile-stat-val {
  font-weight: 800;
  font-family: var(--tp-font-mono, monospace);
  color: var(--tp-scr-text);
}

.tp-mobile-card-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

/* 10. Modals & Drawers */
.tp-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  z-index: 9999;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.tp-modal-overlay.active {
  display: flex;
}

.tp-modal-card {
  background: var(--tp-scr-bg-surface);
  border: 1px solid var(--tp-scr-border);
  border-radius: var(--tp-scr-radius-lg);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.5rem;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.35);
  box-sizing: border-box;
}

.tp-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--tp-scr-border);
}

.tp-modal-title {
  font-size: 1.1rem;
  font-weight: 800;
  margin: 0;
  color: var(--tp-scr-text);
}

.tp-modal-close {
  background: transparent;
  border: none;
  font-size: 1.25rem;
  color: var(--tp-scr-text-muted);
  cursor: pointer;
  padding: 0;
}

.tp-modal-close:hover {
  color: var(--tp-scr-text);
}

/* Buttons */
.tp-scr-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.5rem 0.95rem;
  border-radius: var(--tp-scr-radius-md);
  font-size: 0.825rem;
  font-weight: 700;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s ease;
  font-family: inherit;
  text-decoration: none;
}

.tp-scr-btn-primary {
  background: var(--tp-scr-primary);
  color: #ffffff;
}

.tp-scr-btn-primary:hover {
  opacity: 0.92;
  box-shadow: 0 4px 12px var(--tp-scr-primary-subtle);
}

.tp-scr-btn-secondary {
  background: var(--tp-scr-bg-surface);
  border-color: var(--tp-scr-border);
  color: var(--tp-scr-text);
}

.tp-scr-btn-secondary:hover {
  background: var(--tp-scr-bg-hover);
  border-color: var(--tp-scr-primary);
}

.tp-scr-btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.75rem;
}
