:root {
    --primary-color: #0d6efd;
    --primary-hover: #0b5ed7;
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --border-color: #e5e7eb;
    --border-dark: #cbd5e1;
    --bg-page: #f8fafc;
    --bg-card: #ffffff;
    --highlight-yellow: #fef08a;
    --highlight-yellow-subtle: #fef9c3;
    --green-profit: #16a34a;
    --red-loss: #dc2626;
    --badge-blue: #e0f2fe;
    --badge-blue-text: #0369a1;
}

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

.hidden {
    display: none !important;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-page);
    color: var(--text-main);
    line-height: 1.5;
    font-size: 13px;
    -webkit-font-smoothing: antialiased;
}

.app-container {
    max-width: 100%;
    width: 100%;
    margin: 0;
    padding: 12px 20px 40px;
}

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px 20px;
    margin-bottom: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.logo-box {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon {
    font-size: 20px;
}

.logo-text {
    font-size: 16px;
    font-weight: 700;
    color: #111827;
}

.badge-live {
    background: #dcfce7;
    color: #15803d;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 4px;
    letter-spacing: 0.5px;
}

.badge-liq {
    background: #fef3c7;
    color: #b45309;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 4px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 14px;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #10b981;
    display: inline-block;
}

.status-dot.scanning {
    background: #f59e0b;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.3); opacity: 0.7; }
    100% { transform: scale(1); opacity: 1; }
}

.cached-count {
    font-size: 11px;
    color: #64748b;
    background: #f1f5f9;
    padding: 3px 8px;
    border-radius: 4px;
}

/* Nav tabs */
.main-nav {
    display: flex;
    align-items: center;
    border-bottom: 2px solid var(--border-color);
    margin-bottom: 16px;
    background: transparent;
}

.nav-tab {
    background: none;
    border: none;
    padding: 10px 18px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.15s ease;
}

.nav-tab:hover {
    color: var(--text-main);
}

.nav-tab.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

.tab-badge {
    background: var(--badge-blue);
    color: var(--badge-blue-text);
    font-size: 11px;
    font-weight: 700;
    padding: 1px 7px;
    border-radius: 10px;
}

.nav-spacer {
    flex-grow: 1;
}

.scan-mode-selector {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 600;
}

.form-select-sm {
    border: 1px solid var(--border-dark);
    border-radius: 5px;
    padding: 5px 10px;
    font-size: 12px;
    background: #fff;
    cursor: pointer;
}

/* Content Area */
.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Filter View Table (Screenshot 1) */
.filter-table-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 16px 24px 24px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.03);
}

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

.filter-table thead th {
    text-align: left;
    padding: 10px 8px;
    border-bottom: 2px solid var(--border-color);
    font-size: 13px;
    font-weight: 600;
    color: #4b5563;
}

.filter-row {
    border-bottom: 1px solid #f1f5f9;
}

.filter-row:hover {
    background-color: #fafbfc;
}

.filter-row td {
    padding: 14px 8px;
    vertical-align: middle;
}

.col-check {
    width: 40px;
    text-align: center;
}

/* ---- ON/OFF rule switch -------------------------------------------- */
.switch {
    position: relative;
    display: inline-block;
    width: 42px;
    height: 24px;
    vertical-align: middle;
    cursor: pointer;
}

/* The real checkbox stays on top so it stays keyboard/AT accessible. */
.switch input[type="checkbox"] {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    opacity: 0;
    cursor: pointer;
    z-index: 1;
}

.switch-track {
    position: absolute;
    inset: 0;
    border-radius: 999px;
    background: var(--border-dark);
    box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.08);
    transition: background-color 0.15s ease, box-shadow 0.15s ease;
}

.switch-thumb {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    transition: transform 0.15s ease;
}

.switch input:checked + .switch-track {
    background: var(--green-profit);
    box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.08);
}

.switch input:checked + .switch-track .switch-thumb {
    transform: translateX(18px);
}

.switch input:focus-visible + .switch-track {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Rule switched off: grey out the title and its criteria controls. */
.filter-row.is-off .filter-title {
    color: var(--text-muted);
}

.filter-row.is-off .col-inputs {
    opacity: 0.45;
}

.switch-state {
    display: inline-block;
    margin-left: 6px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: var(--green-profit);
    vertical-align: middle;
}

.switch-state.off {
    color: var(--text-muted);
}

/* ON/OFF badge next to each rule title. */
.rule-state {
    display: inline-block;
    margin-left: 6px;
    padding: 1px 6px;
    border-radius: 3px;
    background: #dcfce7;
    color: #15803d;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.05em;
    vertical-align: 2px;
}

.rule-state.off {
    background: #f1f5f9;
    color: var(--text-muted);
}

.filter-title {
    font-size: 13px;
    font-weight: 700;
    color: #111827;
    margin-bottom: 3px;
}

.filter-desc {
    font-size: 11px;
    color: var(--text-muted);
    max-width: 440px;
    line-height: 1.4;
}

.col-inputs {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.input-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ---- Limit controls ------------------------------------------------- */
.lbl-unit,
.lbl-to {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
}

/* Secondary ("to ...") limit, hidden unless the rule is a range. */
.limit-range-end {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.limit-range-end.is-hidden {
    display: none;
}

.limit-note {
    font-size: 10px;
    color: var(--text-muted);
    margin-top: -2px;
}

.limit-warning {
    color: #b91c1c;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}

.form-input.is-invalid {
    border-color: #dc2626;
    background: #fef2f2;
}

.input-group.has-error .form-select {
    border-color: #dc2626;
}

.lbl-range {
    font-size: 12px;
    color: var(--text-muted);
}

.form-select {
    border: 1px solid var(--border-dark);
    border-radius: 4px;
    padding: 5px 8px;
    font-size: 12px;
    background: #fff;
    color: var(--text-main);
    cursor: pointer;
}

.form-input {
    border: 1px solid var(--border-dark);
    border-radius: 4px;
    padding: 5px 8px;
    font-size: 12px;
    color: var(--text-main);
}

.w-70 {
    width: 70px;
    text-align: center;
}

.presets-row {
    display: flex;
    gap: 4px;
}

.btn-preset, .btn-preset-delta, .btn-preset-dte, .btn-preset-keml, .btn-preset-profit-pct, .btn-preset-profit {
    background: #ffffff;
    border: 1px solid var(--border-dark);
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    line-height: 1.2;
    text-align: center;
    color: #374151;
    transition: all 0.1s ease;
}

.btn-preset:hover, .btn-preset-delta:hover, .btn-preset-dte:hover, .btn-preset-keml, .btn-preset-profit-pct, .btn-preset-profit:hover {
    background: #f1f5f9;
}

.btn-preset.active, .btn-preset-delta.active, .btn-preset-dte.active, .btn-preset-keml, .btn-preset-profit-pct, .btn-preset-profit.active {
    background: #e2e8f0;
    border-color: #94a3b8;
    color: #0f172a;
}

.radio-row {
    display: flex;
    align-items: center;
    gap: 16px;
    font-size: 12px;
}

.radio-label, .check-label {
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    font-weight: 500;
}

.check-options-row {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-top: 4px;
}

.col-order {
    text-align: right;
    color: #9ca3af;
    font-size: 18px;
    cursor: grab;
    user-select: none;
    padding-right: 12px !important;
}

.action-footer {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px 0 10px;
    gap: 8px;
}

.btn-primary-lg {
    background: #1877f2;
    color: #ffffff;
    border: none;
    border-radius: 5px;
    padding: 10px 32px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(24, 119, 242, 0.25);
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.15s ease;
}

.btn-primary-lg:hover {
    background: #166fe5;
}

.btn-primary-lg:disabled {
    background: #93c5fd;
    cursor: not-allowed;
}

.btn-spinner {
    display: none;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255,255,255,0.4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.btn-spinner.active {
    display: inline-block;
}

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

.filter-hint {
    font-size: 11px;
    font-style: italic;
    color: var(--text-muted);
}

/* Results View */
.results-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    background: #fff;
    padding: 8px 16px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
}

.view-toggle {
    display: flex;
    border: 1px solid var(--border-dark);
    border-radius: 5px;
    overflow: hidden;
}

.btn-toggle {
    background: #ffffff;
    border: none;
    padding: 6px 14px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    color: var(--text-muted);
}

.btn-toggle.active {
    background: #1e293b;
    color: #ffffff;
}

.toolbar-info {
    font-size: 12px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
}

.execution-badge {
    background: #dbeafe;
    color: #1e40af;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 700;
}

.toolbar-actions {
    display: flex;
    gap: 8px;
}

.btn-secondary-sm, .btn-primary-sm, .btn-secondary {
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 600;
    border-radius: 5px;
    cursor: pointer;
}

.btn-secondary, .btn-secondary-sm {
    background: #fff;
    border: 1px solid var(--border-dark);
    color: #374151;
}

.btn-secondary:hover, .btn-secondary-sm:hover {
    background: #f8fafc;
}

.btn-primary-sm {
    background: var(--primary-color);
    border: 1px solid var(--primary-color);
    color: #fff;
}

.btn-primary-sm:hover {
    background: var(--primary-hover);
}

/* Results Tables (Screenshots 2 & 3) */
.table-container {
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow-x: auto;
    box-shadow: 0 1px 3px rgba(0,0,0,0.03);
}

.table-container.hidden {
    display: none;
}

/* ===== Filter view: sidebar + table (SAMURAI-style) ===== */
.filter-view-layout {
    display: grid;
    grid-template-columns: 240px minmax(0, 1fr);
    gap: 12px;
    align-items: start;
}

.filter-view-layout.hidden {
    display: none;
}

.filter-summary-panel {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-left: 3px solid var(--green-profit);
    border-radius: 8px;
    padding: 12px 0 0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
    position: sticky;
    top: 12px;
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 24px);
    overflow: auto;
}

.fsp-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 14px 10px;
    border-bottom: 1px solid #eef2f7;
    margin-bottom: 6px;
}

.fsp-title {
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #475569;
}

.fsp-badge {
    background: #dcfce7;
    color: #15803d;
    font-size: 11px;
    font-weight: 800;
    padding: 2px 8px;
    border-radius: 999px;
}

.fsp-sections {
    padding: 0 8px 8px;
}

.fsp-section {
    margin-bottom: 10px;
}

.fsp-section-title {
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--green-profit);
    padding: 6px 6px 4px;
    border-left: 2px solid var(--green-profit);
    margin-left: 4px;
    margin-bottom: 2px;
}

.fsp-row {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    padding: 5px 6px;
    border-radius: 4px;
    font-size: 11px;
}

.fsp-row:hover {
    background: #f8fafc;
}

.fsp-row.is-off {
    opacity: 0.45;
}

.fsp-label {
    color: var(--text-muted);
    font-weight: 600;
    white-space: nowrap;
}

.fsp-value {
    color: #0f172a;
    font-weight: 700;
    text-align: right;
}

.fsp-value em {
    font-style: normal;
    color: #94a3b8;
    font-weight: 600;
    font-size: 10px;
}

.fsp-footer-btn {
    margin-top: auto;
    width: 100%;
    border: none;
    border-top: 1px solid #eef2f7;
    background: #f0fdf4;
    color: #15803d;
    font-size: 11px;
    font-weight: 700;
    padding: 10px 8px;
    cursor: pointer;
    border-radius: 0 0 7px 7px;
}

.fsp-footer-btn:hover {
    background: #dcfce7;
}

/* Ticker cell with subtitle */
.cell-ticker .symbol-link {
    display: inline-block;
}

.symbol-sub {
    font-size: 10px;
    color: #94a3b8;
    font-weight: 500;
    margin-top: 1px;
    line-height: 1.2;
}

/* Pills */
.pill {
    display: inline-block;
    min-width: 42px;
    text-align: center;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.02em;
    line-height: 1.4;
}

.pill-yes {
    background: #dcfce7;
    color: #15803d;
}

.pill-no {
    background: #ffedd5;
    color: #c2410c;
}

.pill-muted {
    background: #f1f5f9;
    color: #64748b;
}

.pill-delta {
    background: #e0f2fe;
    color: #0369a1;
    font-variant-numeric: tabular-nums;
}

/* Grouped ticker rows */
.btn-expand.btn-more {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    color: #1d4ed8;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 800;
    min-width: 30px;
    padding: 1px 4px;
    line-height: 1.4;
}

.btn-expand.btn-more:hover,
.btn-expand.btn-more.expanded {
    background: #dbeafe;
    border-color: #93c5fd;
}

.row-primary.has-more > td {
    background: #fafcff;
}

.row-child {
    background: #fcfcfd;
}

.row-child > td:nth-child(2) {
    padding-left: 22px;
}

.row-child > td:nth-child(2)::before {
    content: "└";
    position: absolute;
    left: 8px;
    color: #cbd5e1;
    font-size: 11px;
}

.row-child.hidden {
    display: none;
}

#tableFilterView thead th:nth-child(3),
#tableFilterView tbody td:nth-child(3) {
    text-align: right;
}

#tableFilterView thead th:nth-child(2),
#tableFilterView tbody td:nth-child(2) {
    text-align: left;
}

@media (max-width: 960px) {
    .filter-view-layout {
        grid-template-columns: 1fr;
    }

    .filter-summary-panel {
        position: static;
        max-height: none;
    }
}

.results-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 12px;
    white-space: nowrap;
}

.results-table thead th {
    background: #f8fafc;
    border-bottom: 2px solid var(--border-color);
    padding: 8px 10px;
    font-size: 11px;
    font-weight: 700;
    color: #475569;
    text-align: right;
    cursor: pointer;
    user-select: none;
}

.results-table thead th:nth-child(1),
.results-table thead th:nth-child(2),
.results-table thead th:nth-child(3) {
    text-align: left;
}

.results-table thead th:hover {
    background: #f1f5f9;
}

.results-table tbody tr {
    border-bottom: 1px solid #f1f5f9;
}

.results-table tbody tr:hover {
    background-color: #f8fafc;
}

.results-table tbody td {
    padding: 9px 10px;
    text-align: right;
    border-bottom: 1px solid #f1f5f9;
}

.results-table tbody td:nth-child(1),
.results-table tbody td:nth-child(2),
.results-table tbody td:nth-child(3) {
    text-align: left;
}

.btn-expand {
    background: none;
    border: none;
    font-size: 14px;
    font-weight: 700;
    color: #3b82f6;
    cursor: pointer;
    padding: 0 4px;
}

.symbol-link {
    color: #0284c7;
    font-weight: 700;
    text-decoration: none;
}

.symbol-link:hover {
    text-decoration: underline;
}

.chart-icon {
    font-size: 12px;
    cursor: pointer;
    opacity: 0.7;
}

.chart-icon:hover {
    opacity: 1;
}

/* Yellow highlighted strike columns (Screenshots 2 & 3) */
.cell-strike-highlight {
    background-color: var(--highlight-yellow-subtle) !important;
    font-weight: 600;
    color: #1e293b;
}

.text-profit-green {
    color: var(--green-profit);
    font-weight: 700;
}

.text-loss-red {
    color: var(--red-loss);
    font-weight: 700;
}

.btn-menu {
    background: none;
    border: none;
    font-size: 16px;
    color: #94a3b8;
    cursor: pointer;
    padding: 0 4px;
}

.btn-menu:hover {
    color: #1e293b;
}

/* Expanded Row Details */
.row-expanded-details {
    background: #fdfefe !important;
}

.expanded-card {
    padding: 12px 20px;
    display: flex;
    gap: 32px;
    background: #f8fafc;
    border-left: 3px solid var(--primary-color);
    margin: 4px 0;
    border-radius: 4px;
}

.detail-col {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 12px;
}

.detail-label {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
}

.detail-val {
    font-weight: 600;
}

.detail-links {
    margin-left: auto;
    display: flex;
    gap: 12px;
    align-items: center;
}

.btn-ext-link {
    background: #fff;
    border: 1px solid var(--border-dark);
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    text-decoration: none;
    color: #0369a1;
}

.btn-ext-link:hover {
    background: #f0f9ff;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

.empty-state.hidden {
    display: none;
}

.empty-icon {
    font-size: 40px;
    margin-bottom: 12px;
}

.empty-title {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 6px;
}

.empty-desc {
    font-size: 13px;
    color: var(--text-muted);
    max-width: 440px;
    margin: 0 auto 16px;
}

/* Filter analysis tab */
.filter-analysis-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 20px 24px 18px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.03);
}

.filter-analysis-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 14px;
}

.filter-analysis-header h2 {
    font-size: 17px;
    margin-bottom: 4px;
}

.filter-analysis-header p,
.filter-analysis-note {
    color: var(--text-muted);
    font-size: 12px;
}

.filter-analysis-meta {
    color: #334155;
    font-size: 12px;
    font-weight: 600;
    background: #f1f5f9;
    border-radius: 5px;
    padding: 8px 10px;
    margin-bottom: 10px;
}

.filter-analysis-message {
    min-height: 20px;
    color: var(--text-muted);
    font-size: 12px;
    margin: 0 0 10px;
}

.filter-analysis-message.error {
    color: var(--red-loss);
}

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

.analysis-table th,
.analysis-table td {
    padding: 12px 10px;
    border-bottom: 1px solid #eef2f7;
    text-align: left;
}

.analysis-table th {
    color: #4b5563;
    font-size: 12px;
    font-weight: 700;
}

.analysis-table td {
    font-size: 13px;
}

.analysis-table tr:last-child td {
    border-bottom: 0;
}

.analysis-count-heading,
.analysis-count-cell {
    text-align: right !important;
    white-space: nowrap;
}

.analysis-count-value {
    color: #111827;
    font-size: 15px;
    font-weight: 700;
}

.analysis-count-context {
    color: var(--text-muted);
    font-size: 11px;
    margin-left: 4px;
}

.analysis-status {
    display: inline-block;
    min-width: 52px;
    text-align: center;
    padding: 2px 7px;
    border-radius: 12px;
    font-size: 10px;
    font-weight: 700;
}

.analysis-status.on {
    background: #dcfce7;
    color: #15803d;
}

.analysis-status.off {
    background: #f1f5f9;
    color: #64748b;
}

/* Rule listed as switched off: dim the row so ON/OFF reads at a glance. */
.analysis-table tr.is-off td {
    color: var(--text-muted);
}

.analysis-table tr.is-off .analysis-count-cell {
    opacity: 0.6;
}

.analysis-count-cell.pending {
    color: var(--text-muted);
}

.analysis-empty {
    color: var(--text-muted);
    text-align: center !important;
    padding: 24px !important;
}

.filter-analysis-note {
    margin-top: 12px;
}

@media (max-width: 700px) {
    .filter-analysis-card {
        padding: 14px 12px;
    }

    .filter-analysis-header {
        flex-direction: column;
    }

    .analysis-table th,
    .analysis-table td {
        padding: 9px 6px;
        font-size: 11px;
    }
}

/* Sticky Table Columns */
.col-sticky-expand {
    position: sticky !important;
    left: 0 !important;
    width: 38px !important;
    min-width: 38px !important;
    max-width: 38px !important;
    z-index: 4;
    background: #ffffff;
    box-sizing: border-box;
    text-align: center !important;
    padding: 8px 4px !important;
}

.col-sticky-symbol {
    position: sticky !important;
    left: 38px !important;
    width: 82px !important;
    min-width: 82px !important;
    max-width: 82px !important;
    z-index: 4;
    background: #ffffff;
    box-sizing: border-box;
    text-align: left !important;
    padding: 8px 10px !important;
}

.col-sticky-chart {
    position: sticky !important;
    left: 120px !important;
    width: 32px !important;
    min-width: 32px !important;
    max-width: 32px !important;
    z-index: 4;
    background: #ffffff;
    box-sizing: border-box;
    text-align: center !important;
    padding: 8px 4px !important;
    border-right: 2px solid #cbd5e1 !important;
    box-shadow: 3px 0 6px rgba(0, 0, 0, 0.06);
}

.col-sticky-filter-ticker {
    position: sticky !important;
    left: 38px !important;
    width: 125px !important;
    min-width: 125px !important;
    max-width: 125px !important;
    z-index: 4;
    background: #ffffff;
    box-sizing: border-box;
    text-align: left !important;
    padding: 8px 10px !important;
    border-right: 2px solid #cbd5e1 !important;
    box-shadow: 3px 0 6px rgba(0, 0, 0, 0.06);
}

/* Sticky Header Background */
thead th.col-sticky-expand,
thead th.col-sticky-symbol,
thead th.col-sticky-chart,
thead th.col-sticky-filter-ticker {
    background: #f8fafc !important;
    z-index: 7 !important;
}

/* Grouped primary row sticky background */
tr.row-primary.has-more > td.col-sticky-expand,
tr.row-primary.has-more > td.col-sticky-symbol,
tr.row-primary.has-more > td.col-sticky-chart,
tr.row-primary.has-more > td.col-sticky-filter-ticker {
    background: #fafcff !important;
}

/* Grouped child row sticky background */
tr.row-child > td.col-sticky-expand,
tr.row-child > td.col-sticky-symbol,
tr.row-child > td.col-sticky-chart,
tr.row-child > td.col-sticky-filter-ticker {
    background: #fcfcfd !important;
}

/* Row hover sticky background */
tbody tr:hover > td.col-sticky-expand,
tbody tr:hover > td.col-sticky-symbol,
tbody tr:hover > td.col-sticky-chart,
tbody tr:hover > td.col-sticky-filter-ticker {
    background: #f1f5f9 !important;
}

/* Sticky expanded details card */
.expanded-card {
    position: sticky;
    left: 8px;
    width: fit-content;
    max-width: calc(100vw - 80px);
}


/* Chart Modal */
.chart-modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(15, 23, 42, 0.7);
    backdrop-filter: blur(4px);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.chart-modal-backdrop.hidden {
    display: none !important;
}

.chart-modal-dialog {
    background: #ffffff;
    border-radius: 12px;
    width: 100%;
    max-width: 1300px;
    height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    border: 1px solid var(--border-color);
    overflow: hidden;
}

.chart-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border-color);
    background: #f8fafc;
}

.cm-left {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
}

.cm-ticker {
    font-size: 20px;
    font-weight: 800;
    color: #0f172a;
}

.cm-price {
    font-size: 15px;
    font-weight: 700;
    color: #334155;
    background: #f1f5f9;
    padding: 3px 10px;
    border-radius: 6px;
}

.cm-strikes-wrap {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: 8px;
}

.cm-strikes-label {
    font-size: 11px;
    font-weight: 700;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.cm-strikes-pills {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.cm-strike-pill {
    background: #fef3c7;
    color: #b45309;
    border: 1px solid #fde68a;
    font-size: 12px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 4px;
}

.cm-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.btn-tv-link {
    background: #2563eb;
    color: #ffffff;
    border: none;
    padding: 7px 14px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
}

.btn-tv-link:hover {
    background: #1d4ed8;
}

.btn-copy-pine {
    background: #ffffff;
    color: #334155;
    border: 1px solid #cbd5e1;
    padding: 7px 14px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-copy-pine:hover {
    background: #f1f5f9;
    border-color: #94a3b8;
}

.btn-modal-close {
    background: none;
    border: none;
    font-size: 18px;
    color: #64748b;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
}

.btn-modal-close:hover {
    background: #fee2e2;
    color: #dc2626;
}

.chart-modal-body {
    flex: 1;
    position: relative;
    background: #ffffff;
    width: 100%;
    height: 100%;
}

.chart-canvas-container {
    width: 100%;
    height: 100%;
    position: relative;
}

.chart-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 14px;
    color: #64748b;
    font-weight: 600;
}

.cm-toolbar { display: flex; align-items: center; gap: 10px; padding: 10px 20px; border-bottom: 1px solid var(--border-color); background: #f8fafc; flex-wrap: wrap; }
.cm-zoom-group { display: flex; gap: 6px; }
.cm-zoom-btn { width: 30px; height: 30px; border-radius: 6px; border: 1px solid #cbd5e1; background: #ffffff; color: #334155; font-size: 16px; font-weight: 700; cursor: pointer; line-height: 1; }
.cm-zoom-btn:hover { background: #f1f5f9; }
.cm-tf-group { display: flex; gap: 6px; }
.cm-tf-btn { height: 30px; min-width: 36px; padding: 0 10px; border-radius: 6px; border: 1px solid #cbd5e1; background: #ffffff; color: #334155; font-size: 12px; font-weight: 700; cursor: pointer; }
.cm-tf-btn.active { background: #2563eb; border-color: #2563eb; color: #ffffff; }
.cm-expiry-select { height: 30px; border-radius: 6px; border: 1px solid #cbd5e1; background: #ffffff; color: #0f172a; font-size: 12px; font-weight: 600; padding: 0 8px; min-width: 170px; }

.cm-em-legend {
    position: absolute;
    top: 10px;
    left: 12px;
    z-index: 15;
    font-size: 12px;
    font-weight: 600;
    color: #1e293b;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(4px);
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    padding: 6px 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    max-width: calc(100% - 24px);
    pointer-events: none;
}

.em-badge-main {
    background: #fef3c7;
    color: #b45309;
    border: 1px solid #fde68a;
    padding: 2px 7px;
    border-radius: 4px;
    font-weight: 700;
    font-size: 11px;
}

.em-badge-high {
    background: #ecfdf5;
    color: #047857;
    border: 1px solid #a7f3d0;
    padding: 2px 7px;
    border-radius: 4px;
    font-weight: 700;
    font-size: 11px;
}

.em-badge-low {
    background: #fef2f2;
    color: #b91c1c;
    border: 1px solid #fecaca;
    padding: 2px 7px;
    border-radius: 4px;
    font-weight: 700;
    font-size: 11px;
}

.em-sub-meta {
    color: #64748b;
    font-size: 11px;
    font-weight: 500;
}

.cm-exp-line {
    position: absolute;
    top: 0;
    bottom: 26px;
    width: 0;
    border-left: 2px dashed #6366f1;
    z-index: 10;
    pointer-events: none;
    display: none;
}

.cm-exp-line-label {
    position: absolute;
    top: 8px;
    left: 6px;
    background: #4f46e5;
    color: #ffffff;
    font-size: 11px;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 4px;
    white-space: nowrap;
    pointer-events: none;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
    letter-spacing: 0.3px;
    display: inline-block;
}

/* ===== Ranks View ===== */
.ranks-note {
    font-size: 11.5px;
    line-height: 1.5;
    color: #64748b;
    margin: 2px 2px 10px;
    max-width: 1100px;
}

.ranks-note.hidden {
    display: none;
}

.ranks-table tbody td {
    padding-top: 6px;
    padding-bottom: 6px;
}

.ranks-table thead th.col-sep,
.ranks-table tbody td.col-sep {
    border-left: 1px solid var(--border-color);
}

.rank-pctl {
    white-space: nowrap;
}

.rank-bar {
    display: inline-block;
    vertical-align: middle;
    width: 42px;
    height: 6px;
    background: #eef2f7;
    border-radius: 3px;
    overflow: hidden;
    margin-right: 6px;
}

.rank-fill {
    display: block;
    height: 100%;
    border-radius: 3px;
    background: #bfdbfe;
}

.rank-fill.mid {
    background: #60a5fa;
}

.rank-fill.hi {
    background: #2563eb;
}

.rank-val {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    color: #1e293b;
}

.rank-na {
    color: #94a3b8;
}


/* ---------------- BPS Rank tab ---------------- */
.bps-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.bps-cap { font-size: 13px; color: var(--text-muted); display: flex; align-items: center; gap: 6px; }
.bps-table-wrap { overflow-x: auto; }
.bps-rank-table th { cursor: pointer; white-space: nowrap; user-select: none; }
.bps-rank-table th.sorted::after { content: " " attr(data-dir); font-size: 10px; }
.bps-rank-table td { white-space: nowrap; font-variant-numeric: tabular-nums; }
.bps-rank-table td.pos { color: var(--green-profit); font-weight: 600; }
.bps-rank-table td.neg { color: var(--red-loss); }
.bps-rank-table td.bps-sym { color: var(--primary-color); font-weight: 700; }
.bps-rank-table td.bps-strike { background: var(--highlight-yellow-subtle); font-weight: 600; }
.bps-rank-table td.bps-warn { color: #c2410c; font-weight: 600; }
.bps-rank-table tr.bps-both td:first-child { box-shadow: inset 4px 0 0 var(--green-profit); }
.bps-rank-table tr.bps-both { background: #f0fdf4; }
.bps-score { display: flex; align-items: center; gap: 8px; min-width: 110px; }
.bps-bar { flex: 1; height: 6px; background: var(--border-color); border-radius: 3px; overflow: hidden; }
.bps-bar span { display: block; height: 100%; background: var(--primary-color); }

.bps-score-cell { text-align: center; }
.bps-pill { display: inline-block; min-width: 34px; padding: 2px 8px; border-radius: 999px; font-weight: 700; font-variant-numeric: tabular-nums; }
.bps-pill.bps-hi { background: #dcfce7; color: #166534; }
.bps-pill.bps-mid { background: #fef9c3; color: #854d0e; }
.bps-pill.bps-lo { background: #fee2e2; color: #991b1b; }

.bps-score-cell { white-space: nowrap; }
.bps-dec { display: inline-block; margin-left: 6px; padding: 1px 6px; border-radius: 4px; font-size: 11px; font-weight: 700; letter-spacing: .3px; }
.bps-dec-open { background: var(--green-profit); color: #fff; }
.bps-dec-no { background: #e5e7eb; color: #6b7280; }
