/* ===================================================================
   Stock Finder Drawer
   Follows the .od-drawer pattern from opportunity-detail.css
   =================================================================== */

/* ── Overlay ────────────────────────────────────────────────────── */
.sf-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(2px);
    z-index: calc(var(--z-panel-overlay) - 1);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-slow, 0.3s ease);
}
.sf-overlay.sf-open {
    opacity: 1;
    pointer-events: auto;
}

/* ── Drawer panel ───────────────────────────────────────────────── */
.sf-drawer {
    position: fixed;
    top: 0;
    right: 0;
    width: 820px;
    max-width: 100vw;
    height: 100vh;
    background: var(--bg-primary, #0a0a12);
    border-left: 1px solid var(--border-color, #2a2a3c);
    z-index: var(--z-panel, 210);
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform var(--transition-slow, 0.3s ease);
    overflow: hidden;
}
.sf-drawer.sf-open {
    transform: translateX(0);
}

/* ── Header ─────────────────────────────────────────────────────── */
.sf-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}
.sf-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}
.sf-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 22px;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    line-height: 1;
    transition: color 0.15s, background 0.15s;
}
.sf-close:hover {
    color: var(--text-primary);
    background: rgba(255,255,255,0.06);
}

/* ── Search ─────────────────────────────────────────────────────── */
.sf-search {
    padding: 10px 20px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}
.sf-search-input {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-secondary, #12121c);
    border: 1px solid var(--border-color, #2a2a3c);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    transition: border-color 0.15s;
}
.sf-search-input:focus {
    border-color: var(--accent-blue, #4a6cf7);
}
.sf-search-input::placeholder {
    color: var(--text-muted);
}

/* ── Filters ────────────────────────────────────────────────────── */
.sf-filters {
    padding: 10px 20px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}
.sf-filter-row {
    display: flex;
    gap: 10px;
    margin-bottom: 8px;
}
.sf-filter-row:last-child {
    margin-bottom: 0;
}
.sf-filter {
    flex: 1;
    min-width: 0;
}
.sf-filter label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 3px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
/* Wrapper around the label that hosts the rich .context-tooltip card.
   We deliberately avoid the native `title` attribute — it renders as the
   OS tooltip (ugly on Windows) and can't be styled or carry structured
   content. The wrapper triggers the styled card from context-tooltips.css. */
.sf-label-wrap {
    display: inline-block;
    max-width: 100%;
}
.sf-info {
    color: var(--text-muted);
    font-size: 11px;
    opacity: 0.7;
    transition: opacity 0.15s, color 0.15s;
}
.sf-label-wrap:hover .sf-info {
    color: var(--accent-blue, #4a6cf7);
    opacity: 1;
}

/* Position override for tooltip cards that live inside the filter grid.
   Left-align the card under the label and widen the usable area slightly
   — 280px (shared default) is tight when the filter column is ~240px and
   the card should not horizontally clip off the drawer. */
.sf-filter .sf-tooltip {
    left: 0;
    transform: none;
    width: 300px;
    max-width: calc(100vw - 40px);
    text-align: left;
}
.sf-filter .sf-tooltip::before {
    left: 18px;
    transform: none;
}
/* Last filter in each row: anchor tooltip to the right so it doesn't
   overflow the drawer. 3-column grid → the :nth-child(3) is always the
   rightmost. */
.sf-filter-row .sf-filter:nth-child(3) .sf-tooltip {
    left: auto;
    right: 0;
}
.sf-filter-row .sf-filter:nth-child(3) .sf-tooltip::before {
    left: auto;
    right: 18px;
}
.sf-filter select,
.sf-filter input[type="number"] {
    width: 100%;
    padding: 5px 8px;
    background: var(--bg-secondary, #12121c);
    border: 1px solid var(--border-color, #2a2a3c);
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 13px;
    outline: none;
}
.sf-filter select:focus,
.sf-filter input[type="number"]:focus {
    border-color: var(--accent-blue, #4a6cf7);
}
.sf-price-range {
    display: flex;
    align-items: center;
    gap: 6px;
}
.sf-price-range input {
    flex: 1;
    min-width: 0;
}
.sf-range-sep {
    color: var(--text-muted);
    font-size: 12px;
    flex-shrink: 0;
}

/* ── Results header ─────────────────────────────────────────────── */
.sf-results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 20px;
    font-size: 13px;
    color: var(--text-muted);
    flex-shrink: 0;
}
.sf-results-count {
    font-size: 12px;
}
.sf-reset-btn {
    background: transparent;
    border: 1px solid var(--border-color, #2a2a3c);
    border-radius: 4px;
    color: var(--text-muted);
    padding: 3px 10px;
    font-size: 12px;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.sf-reset-btn:hover {
    color: var(--text-primary);
    border-color: var(--accent-blue, #4a6cf7);
    background: rgba(74, 108, 247, 0.08);
}

/* ── Results table ──────────────────────────────────────────────── */
.sf-results-table {
    flex: 1;
    overflow: hidden;         /* Tabulator manages its own scrolling inside */
    min-height: 0;
}
/* Kill horizontal scroll — fitColumns already makes columns span the
   available width, so any overflow here is a bug (usually a 1-2px rounding
   gap from totalling column widths). Hide the x-axis scrollbar outright. */
.sf-results-table.ps-grid.tabulator .tabulator-tableholder {
    overflow-x: hidden !important;
}

/* The table container carries the `ps-grid` class (added by stock-finder.js
   in _renderResults) so ps-grid.css owns the dark-header / light-rows /
   dark-hover skin. The overrides below are only for Stock-Finder-specific
   deltas: we keep native Tabulator sort arrows (ps-grid.css hides them for
   programmatic sort) and layer a persistent selection indicator on top of
   the shared hover behaviour.
   --------------------------------------------------------------------- */

/* Persistent selection — sits on top of ps-grid.css's dark-hover pattern.
   We pin the selected row to the hover colour (dark) so it stays dark even
   when the mouse leaves, and add a vivid left accent bar so the user can
   tell at a glance which row is armed for "Execute Buy". */
.sf-results-table.ps-grid.tabulator .tabulator-row.tabulator-selected,
.sf-results-table.ps-grid.tabulator .tabulator-row.tabulator-selectable.tabulator-selected,
.sf-results-table.ps-grid.tabulator .tabulator-row.tabulator-selected:hover {
    background: #1a1a28 !important;
    box-shadow: inset 3px 0 0 #4a6cf7 !important;
}
.sf-results-table.ps-grid.tabulator .tabulator-row.tabulator-selected .tabulator-cell,
.sf-results-table.ps-grid.tabulator .tabulator-row.tabulator-selected .tabulator-cell .ps-mono,
.sf-results-table.ps-grid.tabulator .tabulator-row.tabulator-selected .tabulator-cell .cell-name {
    color: #f1f5f9 !important;
}

/* Tabulator pagination footer — blend with the drawer chrome */
.sf-results-table .tabulator-footer {
    background: var(--bg-primary);
    border-top: 1px solid var(--border-color);
    color: var(--text-muted);
    font-size: 12px;
}
.sf-results-table .tabulator-paginator {
    color: var(--text-muted);
}
.sf-results-table .tabulator-page {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    padding: 2px 8px;
    margin: 0 2px;
    border-radius: 4px;
}
.sf-results-table .tabulator-page.active {
    color: var(--text-primary);
    border-color: var(--accent-blue, #4a6cf7);
    background: rgba(74, 108, 247, 0.12);
}
.sf-results-table .tabulator-page:hover:not(.active) {
    color: var(--text-primary);
    background: rgba(255,255,255,0.04);
}

/* ── Action footer (Execute Buy) ────────────────────────────────── */
.sf-action-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 20px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-primary);
    flex-shrink: 0;
}
.sf-selected-label {
    font-size: 13px;
    color: var(--text-muted);
    font-family: var(--font-mono, ui-monospace, Menlo, monospace);
    letter-spacing: 0.02em;
}
.sf-selected-label--active {
    color: var(--text-primary);
    font-weight: 600;
}
.sf-execute-btn {
    background: var(--accent-blue, #4a6cf7);
    color: #ffffff;
    border: none;
    border-radius: 6px;
    padding: 8px 18px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s;
    min-width: 140px;
    text-align: center;
}
.sf-execute-btn:hover:not(:disabled) {
    background: #5a7cff;
}
.sf-execute-btn:disabled {
    background: var(--bg-secondary, #12121c);
    color: var(--text-muted);
    cursor: not-allowed;
    opacity: 0.7;
    border: 1px solid var(--border-color, #2a2a3c);
}

/* ── Responsive ─────────────────────────────────────────────────── */
@media (max-width: 600px) {
    .sf-drawer { width: 100vw; }
    .sf-filter-row { flex-direction: column; gap: 6px; }
}
