/* =============================================================
   WORKOVA STOCKS — screener.css
   Stock Screener page layout and components
   ============================================================= */


/* ── PAGE LAYOUT ─────────────────────────────────────────────── */
.screener-page {
  padding-top:    var(--sp-8);
  padding-bottom: var(--sp-20);
  min-height:     80vh;
}

.screener-layout {
  display:               grid;
  grid-template-columns: 300px 1fr;
  gap:                   var(--sp-6);
  align-items:           start;
}

/* ── FILTER SIDEBAR ──────────────────────────────────────────── */
.filter-sidebar {
  position:      sticky;
  top:           calc(var(--navbar-h) + var(--ticker-h) + var(--sp-4));
  max-height:    calc(100vh - var(--navbar-h) - var(--ticker-h) - var(--sp-8));
  overflow-y:    auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-default) transparent;
}

.filter-sidebar::-webkit-scrollbar { width: 4px; }
.filter-sidebar::-webkit-scrollbar-track { background: transparent; }
.filter-sidebar::-webkit-scrollbar-thumb { background: var(--border-default); border-radius: 4px; }

.filter-panel {
  background:    var(--surface-card);
  border:        1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow:    var(--shadow-xs);
  overflow:      hidden;
}

.filter-panel__header {
  display:         flex;
  align-items:     center;
  justify-content: space-between;
  padding:         var(--sp-4) var(--sp-5);
  border-bottom:   1px solid var(--border-subtle);
  background:      var(--surface-subtle);
  position:        sticky;
  top:             0;
  z-index:         2;
}

.filter-panel__title {
  font-size:      var(--type-sm);
  font-weight:    700;
  color:          var(--text-primary);
  letter-spacing: -0.01em;
}

.filter-panel__clear {
  font-size:       var(--type-xs);
  font-weight:     600;
  color:           var(--clr-primary);
  background:      none;
  border:          none;
  cursor:          pointer;
  padding:         3px 8px;
  border-radius:   var(--radius-sm);
  transition:      background-color var(--dur-fast) var(--ease-out);
}

.filter-panel__clear:hover { background-color: var(--clr-primary-muted); }

/* Filter group (collapsible) */
.filter-group {
  border-bottom: 1px solid var(--border-subtle);
}

.filter-group:last-child { border-bottom: none; }

.filter-group__trigger {
  display:          flex;
  align-items:      center;
  justify-content:  space-between;
  width:            100%;
  padding:          var(--sp-3) var(--sp-5);
  background:       none;
  border:           none;
  cursor:           pointer;
  text-align:       left;
  transition:       background-color var(--dur-fast) var(--ease-out);
}

.filter-group__trigger:hover { background-color: var(--surface-subtle); }

.filter-group__label {
  font-size:   var(--type-xs);
  font-weight: 700;
  color:       var(--text-secondary);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.filter-group__chevron {
  width:      16px;
  height:     16px;
  color:      var(--text-muted);
  transition: transform var(--dur-base) var(--ease-out);
  flex-shrink: 0;
}

.filter-group.open .filter-group__chevron {
  transform: rotate(180deg);
}

.filter-group__body {
  display: none;
  padding: var(--sp-3) var(--sp-5) var(--sp-4);
}

.filter-group.open .filter-group__body { display: block; }

/* Range slider */
.range-filter {
  display:        flex;
  flex-direction: column;
  gap:            var(--sp-3);
}

.range-filter__inputs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap:     var(--sp-2);
}

.range-filter__input {
  width:            100%;
  font-family:      var(--font-data);
  font-size:        var(--type-sm);
  font-weight:      500;
  color:            var(--text-primary);
  background:       var(--surface-subtle);
  border:           1px solid var(--border-default);
  border-radius:    var(--radius-sm);
  padding:          7px 10px;
  transition:       border-color var(--dur-fast) var(--ease-out),
                    box-shadow   var(--dur-fast) var(--ease-out);
}

.range-filter__input:focus {
  outline:      none;
  border-color: var(--border-focus);
  box-shadow:   var(--shadow-focus);
  background:   var(--surface-card);
}

.range-filter__input::placeholder { color: var(--text-muted); }

.range-filter__label {
  font-size:   var(--type-xs);
  color:       var(--text-muted);
  font-weight: 500;
  text-align:  center;
}

/* Checkbox filter */
.checkbox-filter {
  display:        flex;
  flex-direction: column;
  gap:            var(--sp-2);
}

.checkbox-item {
  display:     flex;
  align-items: center;
  gap:         var(--sp-3);
  cursor:      pointer;
  padding:     var(--sp-1) 0;
}

.checkbox-item__input {
  width:         16px;
  height:        16px;
  border-radius: 4px;
  border:        2px solid var(--border-default);
  background:    var(--surface-card);
  cursor:        pointer;
  flex-shrink:   0;
  accent-color:  var(--clr-primary);
  transition:    border-color var(--dur-fast) var(--ease-out);
}

.checkbox-item__input:focus-visible {
  outline:      2px solid var(--border-focus);
  outline-offset: 2px;
}

.checkbox-item__label {
  font-size:   var(--type-sm);
  color:       var(--text-secondary);
  font-weight: 500;
  cursor:      pointer;
  flex:        1;
}

.checkbox-item__count {
  font-size:        var(--type-xs);
  color:            var(--text-muted);
  background:       var(--surface-subtle);
  padding:          1px 6px;
  border-radius:    var(--radius-pill);
  font-weight:      500;
}

/* Quick preset pills */
.preset-filters {
  display:   flex;
  flex-wrap: wrap;
  gap:       var(--sp-2);
  padding:   var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border-subtle);
}

.preset-btn {
  font-size:        var(--type-xs);
  font-weight:      600;
  padding:          5px 12px;
  border-radius:    var(--radius-pill);
  border:           1px solid var(--border-default);
  background:       var(--surface-card);
  color:            var(--text-secondary);
  cursor:           pointer;
  transition:       background-color var(--dur-fast) var(--ease-out),
                    color            var(--dur-fast) var(--ease-out),
                    border-color     var(--dur-fast) var(--ease-out);
  white-space:      nowrap;
}

.preset-btn:hover,
.preset-btn.active {
  background-color: var(--clr-primary-muted);
  color:            var(--clr-primary);
  border-color:     rgba(37, 99, 235, 0.2);
}

/* Active filter count badge */
.filter-badge {
  display:         inline-flex;
  align-items:     center;
  justify-content: center;
  min-width:       18px;
  height:          18px;
  padding:         0 5px;
  border-radius:   var(--radius-pill);
  background:      var(--clr-primary);
  color:           #fff;
  font-size:       10px;
  font-weight:     700;
  margin-left:     var(--sp-2);
}


/* ── RESULTS PANEL ───────────────────────────────────────────── */
.results-panel {
  min-width: 0;
}

.results-header {
  display:         flex;
  align-items:     center;
  justify-content: space-between;
  gap:             var(--sp-4);
  margin-bottom:   var(--sp-4);
  flex-wrap:       wrap;
}

.results-count {
  font-size:   var(--type-base);
  font-weight: 600;
  color:       var(--text-primary);
}

.results-count span {
  font-family:    var(--font-data);
  color:          var(--clr-primary);
  font-size:      var(--type-lg);
  font-weight:    700;
}

.results-controls {
  display:     flex;
  align-items: center;
  gap:         var(--sp-3);
  flex-wrap:   wrap;
}

/* Sort dropdown */
.sort-select {
  font-family:      var(--font-ui);
  font-size:        var(--type-sm);
  font-weight:      500;
  color:            var(--text-primary);
  background:       var(--surface-card);
  border:           1px solid var(--border-default);
  border-radius:    var(--radius-sm);
  padding:          7px 32px 7px 12px;
  cursor:           pointer;
  appearance:       none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394A3B8' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat:   no-repeat;
  background-position: right 10px center;
  transition:       border-color var(--dur-fast) var(--ease-out);
}

.sort-select:focus {
  outline:      none;
  border-color: var(--border-focus);
  box-shadow:   var(--shadow-focus);
}

/* View toggle */
.view-toggle {
  display:     flex;
  align-items: center;
  gap:         2px;
  background:  var(--surface-subtle);
  border-radius: var(--radius-sm);
  padding:     3px;
}

.view-btn {
  width:           32px;
  height:          28px;
  display:         flex;
  align-items:     center;
  justify-content: center;
  border-radius:   5px;
  border:          none;
  background:      none;
  color:           var(--text-muted);
  cursor:          pointer;
  transition:      background-color var(--dur-fast) var(--ease-out),
                   color            var(--dur-fast) var(--ease-out);
}

.view-btn.active {
  background: var(--surface-card);
  color:      var(--text-primary);
  box-shadow: var(--shadow-xs);
}

.view-btn svg { width: 14px; height: 14px; }


/* ── ACTIVE FILTERS BAR ──────────────────────────────────────── */
.active-filters {
  display:       flex;
  align-items:   center;
  gap:           var(--sp-2);
  flex-wrap:     wrap;
  margin-bottom: var(--sp-4);
  padding:       var(--sp-3) var(--sp-4);
  background:    var(--surface-card);
  border:        1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

.active-filters__label {
  font-size:   var(--type-xs);
  font-weight: 600;
  color:       var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  flex-shrink: 0;
}

.active-filter-tag {
  display:         inline-flex;
  align-items:     center;
  gap:             6px;
  font-size:       var(--type-xs);
  font-weight:     600;
  color:           var(--clr-primary);
  background:      var(--clr-primary-muted);
  border:          1px solid rgba(37, 99, 235, 0.15);
  border-radius:   var(--radius-pill);
  padding:         3px 4px 3px 10px;
}

.active-filter-tag__remove {
  width:            16px;
  height:           16px;
  border-radius:    50%;
  background:       rgba(37, 99, 235, 0.15);
  border:           none;
  cursor:           pointer;
  display:          flex;
  align-items:      center;
  justify-content:  center;
  color:            var(--clr-primary);
  transition:       background-color var(--dur-fast) var(--ease-out);
  flex-shrink:      0;
}

.active-filter-tag__remove:hover { background-color: rgba(37, 99, 235, 0.25); }
.active-filter-tag__remove svg   { width: 9px; height: 9px; }


/* ── SCREENER TABLE ──────────────────────────────────────────── */
.screener-table-wrap {
  background:    var(--surface-card);
  border:        1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow:    var(--shadow-xs);
  overflow:      hidden;
}

.screener-table {
  width:           100%;
  border-collapse: collapse;
}

.screener-table thead {
  background:    var(--surface-subtle);
  position:      sticky;
  top:           0;
  z-index:       1;
}

.screener-table th {
  padding:        var(--sp-3) var(--sp-4);
  font-size:      var(--type-xs);
  font-weight:    700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color:          var(--text-muted);
  white-space:    nowrap;
  border-bottom:  1px solid var(--border-subtle);
  user-select:    none;
}

.screener-table th.sortable {
  cursor: pointer;
  transition: color var(--dur-fast) var(--ease-out);
}

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

.screener-table th.right,
.screener-table td.right { text-align: right; }

.screener-table th.active-sort { color: var(--clr-primary); }

.sort-icon {
  display:      inline-flex;
  align-items:  center;
  margin-left:  4px;
  vertical-align: middle;
  color:        var(--text-muted);
  transition:   color var(--dur-fast) var(--ease-out);
}

.sort-icon svg { width: 11px; height: 11px; }

th.active-sort .sort-icon { color: var(--clr-primary); }

.screener-table td {
  padding:       var(--sp-3) var(--sp-4);
  font-size:     var(--type-sm);
  color:         var(--text-primary);
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
  white-space:   nowrap;
}

.screener-table tbody tr:last-child td { border-bottom: none; }

.screener-table tbody tr {
  transition: background-color var(--dur-fast) var(--ease-out);
  cursor:     pointer;
}

.screener-table tbody tr:hover { background-color: var(--surface-subtle); }

/* Stock identity cell */
.st-identity {
  display:   flex;
  align-items: center;
  gap:       var(--sp-3);
  min-width: 180px;
}

.st-logo {
  width:            34px;
  height:           34px;
  border-radius:    var(--radius-sm);
  background:       var(--clr-primary-muted);
  display:          flex;
  align-items:      center;
  justify-content:  center;
  font-size:        9px;
  font-weight:      800;
  color:            var(--clr-primary);
  flex-shrink:      0;
  border:           1px solid var(--border-subtle);
}

.st-ticker {
  font-size:      var(--type-sm);
  font-weight:    700;
  color:          var(--text-primary);
  letter-spacing: 0.02em;
  display:        block;
}

.st-name {
  font-size:     var(--type-xs);
  color:         var(--text-muted);
  display:       block;
  max-width:     160px;
  overflow:      hidden;
  text-overflow: ellipsis;
}

.st-num {
  font-family:    var(--font-data);
  font-size:      var(--type-sm);
  font-weight:    500;
  color:          var(--text-primary);
  letter-spacing: 0;
}

.st-num--gain { color: var(--clr-gain); }
.st-num--loss { color: var(--clr-loss); }

/* Sparkline mini chart in table */
.st-spark {
  width:  80px;
  height: 32px;
  display: block;
}


/* ── CARD VIEW ───────────────────────────────────────────────── */
.screener-cards {
  display:               grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap:                   var(--sp-4);
}

/* Reuses .stock-card from components.css */


/* ── PAGINATION ROW ──────────────────────────────────────────── */
.screener-footer {
  display:         flex;
  align-items:     center;
  justify-content: space-between;
  padding:         var(--sp-4) var(--sp-5);
  border-top:      1px solid var(--border-subtle);
  background:      var(--surface-card);
  border-radius:   0 0 var(--radius-lg) var(--radius-lg);
  flex-wrap:       wrap;
  gap:             var(--sp-3);
}

.screener-footer__info {
  font-size:   var(--type-xs);
  color:       var(--text-muted);
  font-weight: 500;
}


/* ── COLUMN CUSTOMISER MODAL ─────────────────────────────────── */
.col-customiser {
  display:               grid;
  grid-template-columns: 1fr 1fr;
  gap:                   var(--sp-3);
}

.col-toggle {
  display:      flex;
  align-items:  center;
  gap:          var(--sp-3);
  padding:      var(--sp-3);
  border:       1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  cursor:       pointer;
  transition:   background-color var(--dur-fast) var(--ease-out),
                border-color     var(--dur-fast) var(--ease-out);
}

.col-toggle:hover       { background: var(--surface-subtle); }
.col-toggle.active      { background: var(--clr-primary-muted); border-color: rgba(37,99,235,0.2); }
.col-toggle.active .col-toggle__label { color: var(--clr-primary); }

.col-toggle__check {
  width:            18px;
  height:           18px;
  border-radius:    4px;
  border:           2px solid var(--border-default);
  display:          flex;
  align-items:      center;
  justify-content:  center;
  flex-shrink:      0;
  color:            transparent;
  transition:       background-color var(--dur-fast),
                    border-color     var(--dur-fast),
                    color            var(--dur-fast);
}

.col-toggle.active .col-toggle__check {
  background:   var(--clr-primary);
  border-color: var(--clr-primary);
  color:        #fff;
}

.col-toggle__check svg { width: 10px; height: 10px; }

.col-toggle__label {
  font-size:   var(--type-xs);
  font-weight: 600;
  color:       var(--text-secondary);
}


/* ── MOBILE FILTER DRAWER ────────────────────────────────────── */
.filter-drawer-backdrop {
  display:          none;
  position:         fixed;
  inset:            0;
  background:       var(--surface-overlay);
  z-index:          200;
  backdrop-filter:  blur(4px);
}

.filter-drawer-backdrop.open { display: block; }

.filter-drawer {
  position:   fixed;
  top:        0;
  left:       0;
  bottom:     0;
  width:      min(340px, 90vw);
  background: var(--surface-card);
  box-shadow: var(--shadow-lg);
  overflow-y: auto;
  transform:  translateX(-100%);
  transition: transform var(--dur-slow) var(--ease-out);
  z-index:    201;
}

.filter-drawer.open { transform: translateX(0); }

.filter-drawer__header {
  display:         flex;
  align-items:     center;
  justify-content: space-between;
  padding:         var(--sp-4) var(--sp-5);
  border-bottom:   1px solid var(--border-subtle);
  position:        sticky;
  top:             0;
  background:      var(--surface-card);
  z-index:         2;
}

.filter-drawer__title {
  font-size:   var(--type-md);
  font-weight: 700;
  color:       var(--text-primary);
}

.filter-drawer__footer {
  position:    sticky;
  bottom:      0;
  padding:     var(--sp-4) var(--sp-5);
  background:  var(--surface-card);
  border-top:  1px solid var(--border-subtle);
  display:     flex;
  gap:         var(--sp-3);
}


/* ── RESPONSIVE ──────────────────────────────────────────────── */
@media (max-width: 1023px) {
  .screener-layout {
    grid-template-columns: 1fr;
  }

  .filter-sidebar {
    display:  none;   /* replaced by drawer on mobile */
    position: static;
    max-height: none;
  }
}

@media (max-width: 767px) {
  .screener-table th:nth-child(n+5),
  .screener-table td:nth-child(n+5) {
    display: none;
  }

  .screener-table th:nth-child(n+7),
  .screener-table td:nth-child(n+7) {
    display: none;
  }

  .st-spark { display: none; }
}
