/* Market Screener – layout & components */

body.screener-dark-page,
body.rsi-dark-page.screener-page {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    margin: 0;
    padding: 70px 0 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.screener-page .container-fluid {
    flex: 1;
    max-width: 100%;
    margin: 0 auto;
    width: 100%;
    padding: 16px 20px 32px;
}

.screener-page .hero {
    margin: 0 0 14px;
    padding: 18px 20px;
    border-radius: 14px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
}

.screener-page .hero h1 {
    font-size: 1.35rem;
    margin: 0;
    font-weight: 800;
    letter-spacing: 0.3px;
}

.screener-page .hero p {
    margin: 8px 0 0;
    opacity: 0.92;
    font-size: 0.92rem;
    line-height: 1.5;
}

.screener-top-bar {
    margin-bottom: 12px;
}

.screener-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    border-radius: 14px;
    background: #fff;
    border: 1px solid #e5e7eb;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.06);
}

.screener-toolbar .timeframe-container {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    padding: 0;
    margin: 0;
    max-width: none;
    flex: 1 1 auto;
}

.screener-header {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    margin: 10px 0 0;
    padding: 0 4px;
}

.update-status {
    font-size: 0.78rem;
    color: #6c757d;
    padding: 0.35rem 0.75rem;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.05);
    display: inline-block;
}

.update-status.updating {
    color: #fff;
    background: #2563eb;
    animation: screener-pulse 1.5s infinite;
}

.update-status.error {
    color: #fff;
    background: #dc3545;
}

@keyframes screener-pulse {
    0% { opacity: 1; }
    50% { opacity: 0.6; }
    100% { opacity: 1; }
}

.loading-message {
    text-align: center;
    margin: 0.75rem auto;
    font-weight: 700;
    color: #2563eb;
    display: none;
}

/* Timeframe pills */
.screener-page .timeframe-btn {
    min-width: 84px;
    padding: 8px 14px;
    border-radius: 999px;
    border: 1px solid rgba(15, 23, 42, 0.15);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    background: #e5e7eb;
    color: #111827;
    opacity: 0.9;
    transition: background-color 0.16s, color 0.16s, opacity 0.16s, box-shadow 0.16s, transform 0.16s;
    cursor: pointer;
}

.screener-page .timeframe-btn:hover {
    opacity: 1;
}

.screener-page .timeframe-btn.active[data-timeframe="15m"] { background: #22c55e; color: #fff; border-color: #22c55e; }
.screener-page .timeframe-btn.active[data-timeframe="1h"] { background: #3b82f6; color: #fff; border-color: #3b82f6; }
.screener-page .timeframe-btn.active[data-timeframe="4h"] { background: #f97316; color: #fff; border-color: #f97316; }
.screener-page .timeframe-btn.active[data-timeframe="1d"] { background: #ef4444; color: #fff; border-color: #ef4444; }

/* Search */
#dark-search-container {
    display: flex;
    justify-content: flex-end;
    flex: 0 1 280px;
    min-width: 200px;
}

.dark-search-box {
    position: relative;
    width: 100%;
    max-width: 280px;
}

#darkSymbolSearch {
    width: 100%;
    padding: 9px 36px 9px 36px;
    border: 1px solid #ced4da;
    border-radius: 10px;
    font-size: 13px;
    color: #212529;
    background: #fff;
}

#darkSymbolSearch:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.dark-search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: #6c757d;
    font-size: 14px;
    pointer-events: none;
}

#darkClearSearch {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: #e9ecef;
    color: #495057;
    border: none;
    border-radius: 6px;
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 11px;
}

#darkClearSearch:hover {
    background: #dc3545;
    color: #fff;
}

.search-status {
    position: absolute;
    left: 0;
    top: 100%;
    width: 100%;
    background: #fff;
    border: 1px solid #ced4da;
    color: #495057;
    font-size: 11px;
    padding: 4px 8px;
    border-radius: 0 0 8px 8px;
    text-align: center;
    display: none;
    z-index: 5;
}

/* Filter panel */
.filter-container {
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 14px;
    padding: 14px 16px;
    margin: 0 0 14px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.06);
}

.filter-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding-bottom: 10px;
    border-bottom: 1px solid #dee2e6;
    flex-wrap: wrap;
    gap: 8px;
}

.filter-title {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #212529;
    font-size: 14px;
    font-weight: 700;
}

.filter-title svg { color: #2563eb; }

.filter-reset-btn {
    background: #dc3545;
    color: #fff;
    border: none;
    padding: 7px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.filter-reset-btn:hover { background: #c82333; }

.filter-sections {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.filter-section {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 10px;
    padding: 10px 12px;
}

.filter-section-title {
    color: #495057;
    font-size: 11px;
    font-weight: 700;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.filter-section-content {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 12px;
    align-items: center;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 0 1 auto;
}

.filter-label {
    color: #6c757d;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}

.filter-btn-group {
    display: inline-flex;
    flex-wrap: nowrap;
    border: 1px solid #ced4da;
    border-radius: 8px;
    overflow: hidden;
    background: #fff;
}

.filter-btn {
    padding: 6px 8px;
    font-size: 10px;
    font-weight: 600;
    border: none;
    background: transparent;
    color: #495057;
    cursor: pointer;
    border-right: 1px solid #ced4da;
    white-space: nowrap;
    min-height: 32px;
    transition: background 0.15s, color 0.15s;
}

.filter-btn:last-child { border-right: none; }
.filter-btn:hover { background: #e9ecef; }

.filter-btn.active-neutral { background: #fbbf24; color: #1f2937; }
.filter-btn.active-long { background: #22c55e; color: #fff; }
.filter-btn.active-short { background: #ef4444; color: #fff; }

.filter-btn.tone-long { color: #16a34a; }
.filter-btn.tone-short { color: #dc2626; }
.filter-btn.tone-neutral { color: #92400e; }

.filter-composite-section {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
}

.composite-group {
    display: flex;
    align-items: center;
    gap: 6px;
}

.composite-label { color: #6c757d; font-size: 11px; font-weight: 600; }
.composite-label.label-long { color: #16a34a; }
.composite-label.label-short { color: #dc2626; }

.filter-select {
    padding: 6px 10px;
    font-size: 12px;
    border: 1px solid #ced4da;
    border-radius: 8px;
    background: #fff;
    color: #495057;
    min-height: 34px;
}

.sort-group {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
    padding-left: 12px;
    border-left: 1px solid #dee2e6;
    flex-wrap: wrap;
}

.sort-label { color: #6c757d; font-size: 11px; font-weight: 600; }

.filter-stats {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid #dee2e6;
    flex-wrap: wrap;
}

.stat-item { display: flex; align-items: center; gap: 4px; }
.stat-value { font-size: 14px; font-weight: 700; }
.stat-visible .stat-value { color: #16a34a; }
.stat-filtered .stat-value { color: #dc2626; }
.stat-label { color: #6c757d; font-size: 10px; }
.stat-divider { color: #dee2e6; }

/* Table – scroll container (vertical + horizontal) with sticky header row */
.screener-table-wrap {
    max-height: min(62vh, calc(100vh - 300px));
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    margin-bottom: 14px;
    background: #fff;
    position: relative;
}

.screener-table-wrap::after {
    content: "← scroll for all columns →";
    display: block;
    text-align: center;
    font-size: 10px;
    color: #64748b;
    padding: 6px 0 4px;
    letter-spacing: 0.02em;
    background: inherit;
    position: sticky;
    left: 0;
    bottom: 0;
}

#indicatorTable {
    width: max-content;
    min-width: 100%;
    margin: 0;
    border-collapse: separate;
    border-spacing: 0;
    table-layout: auto;
    font-size: 12px;
}

#indicatorTable th,
#indicatorTable td {
    display: table-cell !important;
    white-space: nowrap;
    min-width: 68px;
}

#indicatorTable th:first-child,
#indicatorTable td:first-child {
    min-width: 100px;
    max-width: 120px;
}

#indicatorTable th:nth-child(17),
#indicatorTable td:nth-child(17) {
    min-width: 56px;
}

#indicatorTable th:nth-child(18),
#indicatorTable td:nth-child(18) {
    min-width: 128px;
}

#indicatorTable td.badge-cell {
    white-space: normal;
    overflow: visible;
    min-width: 130px;
    line-height: 1.45;
}

#indicatorTable .signal-pill {
    display: inline-block;
    margin: 2px 3px 2px 0;
    vertical-align: middle;
    white-space: nowrap;
}

#indicatorTable td.cell-tone-bull {
    background: rgba(34, 197, 94, 0.14) !important;
    color: #15803d;
}

#indicatorTable td.cell-tone-bear {
    background: rgba(239, 68, 68, 0.14) !important;
    color: #b91c1c;
}

.screener-page #indicatorTable td.cell-tone-bull,
body.rsi-dark-page.screener-page #indicatorTable td.cell-tone-bull {
    color: #6ee7b7 !important;
    background: rgba(34, 197, 94, 0.16) !important;
}

.screener-page #indicatorTable td.cell-tone-bear,
body.rsi-dark-page.screener-page #indicatorTable td.cell-tone-bear {
    color: #fca5a5 !important;
    background: rgba(239, 68, 68, 0.16) !important;
}

#indicatorTable th {
    background: #1f2937;
    color: #f9fafb;
    padding: 10px 8px;
    font-size: 11px;
    font-weight: 700;
    text-align: center;
    border-bottom: 1px solid #374151;
    position: sticky;
    top: 0;
    z-index: 4;
    white-space: nowrap;
    box-shadow: 0 1px 0 #374151;
}

/* Sticky symbol column (horizontal scroll) – all viewports */
#indicatorTable th:first-child,
#indicatorTable td:first-child,
#resultsTable th:first-child,
#resultsTable td:first-child {
    position: sticky;
    left: 0;
    z-index: 3;
    box-shadow: 4px 0 10px rgba(0, 0, 0, 0.12);
    border-right: 1px solid #334155;
    isolation: isolate;
}

#indicatorTable thead th:first-child,
#resultsTable thead th:first-child {
    z-index: 8;
    top: 0;
    left: 0;
}

#indicatorTable th:first-child,
#resultsTable th:first-child { text-align: left; padding-left: 12px; }

#indicatorTable thead th:first-child,
#resultsTable thead th:first-child {
    background-color: #1f2937;
}

#indicatorTable td,
#resultsTable td {
    padding: 8px 6px;
    text-align: center;
    border-bottom: 1px solid #e5e7eb;
    color: #212529;
    vertical-align: middle;
}

#indicatorTable td:first-child,
#resultsTable td:first-child {
    position: sticky;
    left: 0;
    background-color: #ffffff;
    text-align: left;
    padding-left: 12px;
    font-weight: 600;
}

#indicatorTable tbody tr:nth-child(even) td:first-child,
#resultsTable tbody tr:nth-child(even) td:first-child {
    background-color: #f9fafb;
}

#indicatorTable tbody tr:hover td:first-child,
#resultsTable tbody tr:hover td:first-child {
    background-color: #eef4ff;
}

#indicatorTable td:first-child::before,
#resultsTable td:first-child::before {
    content: "";
    position: absolute;
    inset: 0;
    background-color: inherit;
    z-index: -1;
    pointer-events: none;
}

#indicatorTable td:first-child a,
#resultsTable td:first-child a {
    color: #2563eb;
    text-decoration: none;
}

#indicatorTable td:first-child a:hover,
#resultsTable td:first-child a:hover { text-decoration: underline; }

#indicatorTable tbody tr:nth-child(even) { background: #f9fafb; }

#indicatorTable tbody tr:hover td {
    background: rgba(37, 99, 235, 0.06);
}

#indicatorTable tfoot th {
    background: #111827;
    color: #fff;
    padding: 10px 8px;
    border-top: 1px solid #374151;
}

.bg-green,
.bg-red,
.bg-yellow,
.bg-gray,
.signal-pill {
    padding: 3px 7px;
    border-radius: 6px;
    font-size: 10px;
    font-weight: 700;
    display: inline-block;
    white-space: nowrap;
}

.bg-green {
    background: rgba(34, 197, 94, 0.15);
    color: #15803d;
}

.bg-red {
    background: rgba(239, 68, 68, 0.15);
    color: #b91c1c;
}

.bg-yellow {
    background: rgba(245, 158, 11, 0.2);
    color: #92400e;
}

.bg-gray {
    background: rgba(107, 114, 128, 0.2);
    color: #374151;
}

#indicatorTable td.bg-green,
#indicatorTable td.bg-red,
#indicatorTable td.bg-yellow,
#indicatorTable td.bg-gray {
    display: table-cell !important;
}

/* Pagination */
#paginationControls {
    margin: 0 0 18px;
    padding: 0;
}

.pagination-container {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: center;
    align-items: center;
    padding: 12px;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 12px;
}

.pagination-btn {
    border: 1px solid #ced4da;
    min-width: 36px;
    height: 36px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 12px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 10px;
    color: #495057;
    background: #fff;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.pagination-btn:hover:not(:disabled) {
    background: #2563eb;
    color: #fff;
    border-color: #2563eb;
}

.pagination-btn-active,
.pagination-btn:disabled {
    color: #fff;
    background: #2563eb;
    border-color: #2563eb;
    cursor: default;
    opacity: 1;
}

/* Preloader */
.preloader {
    position: fixed;
    inset: 0;
    background: #0b0f14;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    transition: opacity 0.5s ease, visibility 0.5s ease;
}

.preloader.loaded {
    opacity: 0;
    visibility: hidden;
}

.preloader .spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #1e293b;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: screener-spin 1s linear infinite;
}

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

.screener-page .footer-simple {
    margin-top: auto;
}

/* Desktop: compact table so all 21 columns fit without horizontal scroll */
@media (min-width: 1024px) {
    .screener-table-wrap::after {
        display: none;
    }

    #indicatorTable {
        width: 100%;
        min-width: 0;
        max-width: 100%;
        table-layout: fixed;
        font-size: 10px;
    }

    #indicatorTable th,
    #indicatorTable td {
        min-width: 0;
        max-width: none;
        padding: 4px 2px;
        font-size: 10px;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    #indicatorTable th {
        padding: 5px 2px;
        font-size: 9px;
        letter-spacing: -0.02em;
        line-height: 1.2;
    }

    #indicatorTable th:first-child,
    #indicatorTable td:first-child {
        width: 6.5%;
        min-width: 0;
        max-width: none;
        padding-left: 8px;
    }

    #indicatorTable th:nth-child(2),
    #indicatorTable td:nth-child(2) {
        width: 4.8%;
    }

    #indicatorTable th:nth-child(n+3):nth-child(-n+16),
    #indicatorTable td:nth-child(n+3):nth-child(-n+16) {
        width: 3.7%;
    }

    #indicatorTable th:nth-child(17),
    #indicatorTable td:nth-child(17) {
        width: 3.2%;
    }

    #indicatorTable th:nth-child(18),
    #indicatorTable td:nth-child(18) {
        width: 8%;
        overflow: visible;
        white-space: normal;
    }

    #indicatorTable th:nth-child(19),
    #indicatorTable td:nth-child(19),
    #indicatorTable th:nth-child(20),
    #indicatorTable td:nth-child(20) {
        width: 3.5%;
    }

    #indicatorTable th:nth-child(21),
    #indicatorTable td:nth-child(21) {
        width: 4.2%;
    }

    #indicatorTable td.badge-cell {
        min-width: 0;
        font-size: 8px;
        line-height: 1.25;
        padding: 2px 1px;
        overflow: visible;
        white-space: normal;
    }

    #indicatorTable .signal-pill,
    #indicatorTable .bg-green,
    #indicatorTable .bg-red,
    #indicatorTable .bg-yellow,
    #indicatorTable .bg-gray {
        padding: 1px 4px;
        font-size: 8px;
        margin: 1px 1px 1px 0;
        border-radius: 4px;
    }

    #indicatorTable td:first-child a,
    #indicatorTable td.symbol-link-cell {
        font-size: 10px;
    }
}

/* Mobile */
@media (max-width: 768px) {
    .screener-page .container-fluid { padding: 12px 10px 24px; }
    .screener-page .hero { padding: 14px 16px; }
    .screener-page .hero h1 { font-size: 1.1rem; }

    .screener-toolbar {
        flex-direction: column;
        align-items: stretch;
        padding: 12px;
    }

    .screener-toolbar .timeframe-container {
        justify-content: center;
    }

    .screener-page .timeframe-btn {
        flex: 1 1 calc(50% - 4px);
        min-width: 0;
        text-align: center;
    }

    #dark-search-container {
        flex: 1 1 100%;
        min-width: 0;
        max-width: none;
    }

    .dark-search-box { max-width: none; }

    .filter-container { padding: 10px 12px; }

    .filter-section-content {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-group {
        flex-direction: column;
        align-items: stretch;
        width: 100%;
    }

    .filter-btn-group {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .filter-btn {
        flex: 1 1 auto;
        min-height: 38px;
        padding: 8px 10px;
        font-size: 11px;
    }

    .sort-group {
        margin-left: 0;
        padding-left: 0;
        border-left: none;
        width: 100%;
        justify-content: flex-start;
    }

    .filter-select { flex: 1; min-width: 0; }

    .screener-table-wrap {
        max-height: min(70vh, calc(100dvh - 260px));
        border-radius: 10px;
        overflow: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }

    .screener-table-wrap::after {
        content: "← scroll indicators →";
    }

    #indicatorTable th:first-child,
    #indicatorTable td:first-child {
        min-width: 108px;
        width: 108px;
        max-width: 108px;
        box-shadow: 4px 0 14px rgba(0, 0, 0, 0.22);
    }

    #indicatorTable td:first-child .symbol-link,
    #indicatorTable td:first-child a {
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .pagination-container { padding: 10px 8px; }

    .pagination-btn {
        min-width: 34px;
        height: 34px;
    }
}

@media (max-width: 480px) {
    .screener-page .timeframe-btn {
        flex: 1 1 100%;
    }
}

/* RTL locales (ar, fa): keep indicator table LTR for horizontal scroll + sticky symbol column */
html[dir="rtl"] body.screener-page .screener-table-wrap,
html[dir="rtl"] body.screener-page #indicatorTable {
    direction: ltr;
    unicode-bidi: isolate;
}

html[dir="rtl"] body.screener-page .screener-top-bar,
html[dir="rtl"] body.screener-page .hero,
html[dir="rtl"] body.screener-page .filter-container,
html[dir="rtl"] body.screener-page .pagination-container {
    direction: rtl;
    text-align: right;
}

html[dir="rtl"] body.screener-page #indicatorTable th:first-child,
html[dir="rtl"] body.screener-page #indicatorTable td:first-child {
    text-align: left;
}
