/* --- Reset & Base Variables --- */
:root {
    --bg-base: #0a0f1d;
    --bg-surface: rgba(18, 26, 47, 0.6);
    --bg-surface-solid: #121a2f;
    --border-color: rgba(255, 255, 255, 0.08);
    --border-glow: rgba(0, 242, 254, 0.15);
    
    --color-primary: #00f2fe; /* Neon Cyan */
    --color-secondary: #4facfe; /* Electric Blue */
    --color-success: #00e676; /* Neon Green */
    --color-danger: #ff1744; /* Neon Red */
    --color-warning: #ffb300; /* Warm Amber */
    
    --text-primary: #ffffff;
    --text-secondary: #8f9cae;
    --text-muted: #576574;
    
    --sidebar-width: 260px;
    --transition-speed: 0.3s;
    --glass-blur: 16px;
    --border-radius: 16px;
    --shadow-premium: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-base);
    color: var(--text-primary);
    overflow-x: hidden;
    height: 100vh;
}

h1, h2, h3, h4, .logo-text {
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
}

/* --- Loading screen ---
   Shown first; the sign-in screen (z-index 3000) covers it when needed. The app stays hidden
   (but laid out, so charts size correctly) until auth.js removes .app-booting. */
.app-booting .app-container,
.app-booting .app-disclaimer {
    visibility: hidden;
}

.boot-loader {
    position: fixed;
    inset: 0;
    z-index: 2500;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 18px;
    background: var(--bg-base);
    transition: opacity 0.3s ease;
}

.boot-loader.boot-done {
    opacity: 0;
    pointer-events: none;
}

.boot-logo .logo-text {
    font-size: 1.8rem;
    color: var(--text-primary);
}

.boot-spinner {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 3px solid var(--border-color);
    border-top-color: var(--color-primary);
    animation: boot-spin 0.9s linear infinite;
}

@keyframes boot-spin {
    to { transform: rotate(360deg); }
}

.boot-status {
    margin: 0;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* --- Layout --- */
.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* --- Sidebar --- */
.sidebar {
    width: var(--sidebar-width);
    background-color: #060913;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    padding: 18px 0 24px;
    z-index: 100;
}

.sidebar-header {
    padding: 0 24px;
    margin-bottom: 18px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 9px;
}

.logo-icon {
    font-size: 18px;
    color: var(--color-primary);
    text-shadow: 0 0 10px rgba(0, 242, 254, 0.4);
}

.logo-text {
    font-size: 17px;
    letter-spacing: 0.5px;
}

.logo-text .highlight {
    color: var(--color-primary);
}

/* Scrolls on short screens so the footer (account, theme, status) stays visible */
.sidebar-nav {
    flex-grow: 1;
    min-height: 0;
    overflow-y: auto;
}

.sidebar-nav ul {
    list-style: none;
}

.sidebar-nav li.nav-divider {
    padding: 0;
    margin: 10px 24px;
    height: 1px;
    background: var(--border-color);
    border: none;
    cursor: default;
    pointer-events: none;
}

.sidebar-nav li {
    padding: 11px 24px;
    display: flex;
    align-items: center;
    gap: 16px;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 15px;
    font-weight: 500;
    border-left: 3px solid transparent;
    transition: all var(--transition-speed) ease;
}

.sidebar-nav li i {
    font-size: 18px;
    width: 20px;
    text-align: center;
    transition: color var(--transition-speed);
}

.sidebar-nav li:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.02);
}

.sidebar-nav li.active {
    color: var(--color-primary);
    background: rgba(0, 242, 254, 0.05);
    border-left-color: var(--color-primary);
}

.sidebar-nav li.active i {
    color: var(--color-primary);
    text-shadow: 0 0 8px rgba(0, 242, 254, 0.5);
}

.sidebar-footer {
    flex-shrink: 0;
    padding: 12px 24px 0;
}

/* --- Theme Toggle Component --- */
.theme-toggle-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    margin-bottom: 12px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    transition: all var(--transition-speed);
}

.theme-toggle-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.theme-toggle-label i {
    font-size: 0.88rem;
    color: var(--color-primary);
}

.theme-switch {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 20px;
}

.theme-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.theme-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #2c3a4e;
    transition: 0.3s;
    border-radius: 20px;
}

.theme-slider:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 3px;
    bottom: 3px;
    background-color: #ffffff;
    transition: 0.3s;
    border-radius: 50%;
}

input:checked + .theme-slider {
    background-color: var(--color-primary);
}

input:checked + .theme-slider:before {
    transform: translateX(16px);
}

.connection-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-secondary);
}

.connection-status.connected i {
    color: var(--color-success);
    text-shadow: 0 0 6px var(--color-success);
    animation: pulse 2s infinite;
}

/* --- Main Content --- */
.main-content {
    flex-grow: 1;
    overflow-y: auto;
    padding: 32px 40px;
    background: radial-gradient(circle at 50% 0%, #151e36 0%, #0a0f1d 70%);
}

.content-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 32px;
}

.content-header h1 {
    font-size: 32px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.content-header .subtitle {
    color: var(--text-secondary);
    font-size: 14px;
    margin-top: 4px;
}

/* --- Premium Glass Cards --- */
.glass-card {
    background: var(--bg-surface);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-premium);
    transition: transform 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
}

.glass-card:hover {
    border-color: rgba(0, 242, 254, 0.25);
    box-shadow: 0 8px 32px 0 var(--border-glow);
}

.card-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-header h3 {
    font-size: 18px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
}

.card-header h3 i {
    color: var(--color-primary);
}

.card-body {
    padding: 24px;
}

/* --- Dashboard Stats Grid --- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 24px;
    margin-bottom: 32px;
}

.stat-card {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 24px;
}

.stat-icon {
    width: 52px;
    height: 52px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.val-icon {
    background: rgba(0, 242, 254, 0.1);
    color: var(--color-primary);
    border: 1px solid rgba(0, 242, 254, 0.2);
}

.yield-icon {
    background: rgba(79, 172, 254, 0.1);
    color: var(--color-secondary);
    border: 1px solid rgba(79, 172, 254, 0.2);
}

.risk-icon {
    background: rgba(0, 230, 118, 0.1);
    color: var(--color-success);
    border: 1px solid rgba(0, 230, 118, 0.2);
}

.beta-icon {
    background: rgba(255, 179, 0, 0.1);
    color: var(--color-warning);
    border: 1px solid rgba(255, 179, 0, 0.2);
}

.stat-info {
    display: flex;
    flex-direction: column;
}

.stat-label {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
    margin-bottom: 4px;
}

.stat-value {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.5px;
    margin-bottom: 4px;
}

.stat-sub {
    font-size: 12px;
    font-weight: 600;
}

.stat-sub.positive {
    color: var(--color-success);
}

.stat-sub.negative {
    color: var(--color-danger);
}

/* --- Visuals Grid (Charts) --- */
.visuals-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 24px;
    margin-bottom: 32px;
}

@media (max-width: 1024px) {
    .visuals-grid {
        grid-template-columns: 1fr;
    }
    .visuals-grid .span-2 {
        grid-column: span 1;
    }
}

.chart-container {
    min-height: 380px;
}

.chart-placeholder {
    height: 280px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    gap: 16px;
    font-size: 14px;
}

.chart-placeholder i {
    font-size: 48px;
    color: var(--text-muted);
    opacity: 0.3;
}

/* --- Tables --- */
.table-responsive {
    width: 100%;
    overflow-x: auto;
}

.dashboard-table,
.data-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.dashboard-table th,
.data-table th {
    padding: 14px 18px;
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.dashboard-table td,
.data-table td {
    padding: 14px 18px;
    font-size: 13px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
    white-space: nowrap;
}

.dashboard-table tbody tr,
.data-table tbody tr {
    transition: background-color var(--transition-speed);
}

.dashboard-table tbody tr:hover,
.data-table tbody tr:hover {
    background-color: rgba(255, 255, 255, 0.03);
}

.dashboard-table td .ticker-badge {
    background: rgba(0, 242, 254, 0.1);
    color: var(--color-primary);
    padding: 4px 8px;
    border-radius: 6px;
    font-weight: 600;
    font-size: 12px;
    border: 1px solid rgba(0, 242, 254, 0.2);
}

.data-table td .badge {
    margin-left: 8px;
    display: inline-block;
    vertical-align: middle;
}

/* Stock Screener Table Specific Layout & Spacing */
#screener-stocks-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    table-layout: auto;
}

#screener-stocks-table th {
    padding: 16px 20px !important;
    font-size: 13px !important;
    font-weight: 700 !important;
    color: var(--text-secondary) !important;
    text-transform: uppercase !important;
    letter-spacing: 0.6px !important;
    border-bottom: 2px solid var(--border-color) !important;
    white-space: nowrap !important;
    background: rgba(255, 255, 255, 0.02);
}

#screener-stocks-table td {
    padding: 14px 20px !important;
    font-size: 14px !important;
    border-bottom: 1px solid var(--border-color) !important;
    white-space: nowrap !important;
}

#screener-stocks-table tbody tr:hover {
    background-color: rgba(0, 242, 254, 0.04) !important;
}

/* Explicit minimum column widths to prevent header text collision */
#screener-stocks-table th:nth-child(1) { min-width: 50px; }
#screener-stocks-table th:nth-child(2) { min-width: 110px; } /* Ticker */
#screener-stocks-table th:nth-child(3) { min-width: 180px; } /* Company Name */
#screener-stocks-table th:nth-child(4) { min-width: 120px; } /* Price ($) */
#screener-stocks-table th:nth-child(5) { min-width: 150px; } /* Period Perf (%) */
#screener-stocks-table th:nth-child(6) { min-width: 160px; } /* Ann. Return (μ) */
#screener-stocks-table th:nth-child(7) { min-width: 190px; } /* Ann. Variance (σ²) */
#screener-stocks-table th:nth-child(8) { min-width: 160px; } /* Ann. Volatility (σ) */
#screener-stocks-table th:nth-child(9) { min-width: 140px; } /* Sharpe Ratio */
#screener-stocks-table th:nth-child(10) { min-width: 150px; } /* Min-Var Weight */
#screener-stocks-table th:nth-child(11) { min-width: 90px; } /* Action */

.empty-state-text {
    text-align: center;
    color: var(--text-secondary);
    padding: 40px !important;
}

/* --- Tabs Management --- */
.tab-content {
    display: none;
    animation: fadeIn 0.4s ease-out;
}

.tab-content.active-tab {
    display: block;
}

/* --- Holdings Layout --- */
.holdings-layout {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.add-holding-horizontal-grid {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 1.2fr;
    gap: 16px;
    align-items: end;
}

@media (max-width: 900px) {
    .add-holding-horizontal-grid {
        grid-template-columns: 1fr;
    }
}

.empty-icon {
    font-size: 40px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

/* --- Forms & Styled Inputs --- */
.form-group {
    margin-bottom: 20px;
}

.form-row {
    display: flex;
    gap: 16px;
}

.col-6 {
    width: 50%;
}

label {
    display: block;
    margin-bottom: 8px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
}

.search-input-wrapper {
    position: relative;
    width: 100%;
}

.search-icon {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
}

.search-input-wrapper input {
    padding-left: 44px !important;
}

input[type="text"], input[type="number"], .styled-select {
    width: 100%;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    transition: border-color var(--transition-speed), box-shadow var(--transition-speed);
}

input:focus, .styled-select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(0, 242, 254, 0.2);
}

select, .styled-select, .styled-input select {
    color: #ffffff !important;
    background-color: #121a2f;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px 12px;
}

select option, .styled-select option, option {
    background-color: #121a2f !important;
    color: #ffffff !important;
    padding: 10px;
}

select option:hover, select option:focus, select option:checked {
    background-color: #1a2646 !important;
    color: #00f2fe !important;
}

.styled-select {
    appearance: none;
    background-image: url("data:image/svg+xml;utf8,<svg fill='white' height='24' viewBox='0 0 24 24' width='24' xmlns='http://www.w3.org/2000/svg'><path d='M7 10l5 5 5-5z'/><path d='M0 0h24v24H0z' fill='none'/></svg>");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
    cursor: pointer;
}

.benchmark-selector {
    display: flex;
    align-items: center;
    gap: 12px;
}

.benchmark-selector label {
    margin-bottom: 0;
    white-space: nowrap;
}

/* Autocomplete Dropdown & Stacking Context Fix */
.add-holding-section {
    position: relative;
    z-index: 50;
    overflow: visible !important;
}

.search-ticker-group {
    position: relative;
    z-index: 100;
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    font-size: 14px;
    font-weight: 600;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    transition: all var(--transition-speed) ease;
}

.btn-primary {
    background: linear-gradient(135deg, #00f2fe 0%, #0070f3 100%);
    color: #000000 !important;
    font-weight: 700;
}

.btn-primary i,
.btn-primary span {
    color: #000000 !important;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0, 112, 243, 0.4);
}

.btn-success {
    background: #00e676 !important;
    color: #000000 !important;
    font-weight: 700 !important;
}

.btn-success i,
.btn-success span {
    color: #000000 !important;
}

.btn-success:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0, 230, 118, 0.4);
}

.btn-success:disabled,
#btn-run-rebalance:disabled {
    background: rgba(0, 230, 118, 0.25) !important;
    color: #a0aec0 !important;
    border: 1px solid rgba(0, 230, 118, 0.3) !important;
    opacity: 0.7;
    cursor: not-allowed;
}

.btn-success:disabled i,
.btn-success:disabled span {
    color: #a0aec0 !important;
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.12);
}

.btn-danger {
    background: rgba(255, 23, 68, 0.1);
    color: var(--color-danger);
    border: 1px solid rgba(255, 23, 68, 0.2);
}

.btn-danger:hover {
    background: var(--color-danger);
    color: white;
}

.btn-block {
    width: 100%;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
    border-radius: 6px;
}

/* --- Badges --- */
.badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
}

.badge-low {
    background: rgba(0, 230, 118, 0.15);
    color: var(--color-success);
}

.badge-moderate {
    background: rgba(255, 179, 0, 0.15);
    color: var(--color-warning);
}

.badge-high {
    background: rgba(255, 23, 68, 0.15);
    color: var(--color-danger);
}

.badge-success {
    background: rgba(0, 230, 118, 0.12);
    color: var(--color-success);
    border: 1px solid rgba(0, 230, 118, 0.4);
}

.badge-info {
    background: rgba(0, 242, 254, 0.12);
    color: var(--color-primary);
    border: 1px solid rgba(0, 242, 254, 0.4);
}

.badge-warning {
    background: rgba(255, 179, 0, 0.12);
    color: var(--color-warning);
    border: 1px solid rgba(255, 179, 0, 0.4);
}

.badge-danger {
    background: rgba(255, 23, 68, 0.12);
    color: var(--color-danger);
    border: 1px solid rgba(255, 23, 68, 0.4);
}

/* --- Rebalance Layout --- */
.rebalance-layout {
    display: grid;
    grid-template-columns: 1fr 1.5fr;
    gap: 24px;
    align-items: start;
}

@media (max-width: 900px) {
    .rebalance-layout {
        grid-template-columns: 1fr;
    }
}

.rebalance-inputs-container {
    max-height: 320px;
    overflow-y: auto;
    margin-bottom: 24px;
    padding-right: 8px;
}

.rebalance-input-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-color);
}

.rebalance-input-item .ticker {
    font-weight: 700;
    color: var(--color-primary);
    width: 60px;
}

.rebalance-input-item .current-w {
    font-size: 13px;
    color: var(--text-secondary);
}

.rebalance-input-item .input-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 120px;
}

.rebalance-input-item input {
    text-align: right;
    padding: 8px 12px;
}

.rebalance-summary {
    margin-bottom: 24px;
}

.allocation-total-bar {
    display: flex;
    justify-content: space-between;
    font-weight: 600;
    margin-bottom: 8px;
    font-size: 14px;
}

.allocation-total-bar .total-val.valid {
    color: var(--color-success);
}

.allocation-total-bar .total-val.invalid {
    color: var(--color-danger);
}

.progress-bar-container {
    height: 6px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 3px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: var(--color-primary);
    border-radius: 3px;
    transition: width var(--transition-speed) ease, background-color var(--transition-speed) ease;
}

.progress-bar.valid {
    background: var(--color-success);
}

.progress-bar.invalid {
    background: var(--color-danger);
}

.rebalance-charts-container {
    margin-top: 24px;
}

.trade-action {
    font-weight: 700;
}

.trade-action.buy {
    color: var(--color-success);
}

.trade-action.sell {
    color: var(--color-danger);
}

.trade-action.hold {
    color: var(--text-secondary);
}

/* --- Matrix Analyzer styling --- */
.matrix-controls {
    display: flex;
    align-items: center;
    gap: 24px;
}

.matrix-input-section {
    margin-bottom: 24px;
}

.matrix-input-wrapper {
    display: flex;
    gap: 16px;
}

.styled-input {
    flex-grow: 1;
}

.matrix-placeholder {
    height: 350px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    gap: 16px;
}

.matrix-large-icon {
    font-size: 52px;
    opacity: 0.3;
}

.matrix-interpretation {
    background: rgba(255, 255, 255, 0.02);
    border-left: 4px solid var(--color-primary);
    padding: 16px;
    border-radius: 0 8px 8px 0;
    margin-top: 24px;
}

.matrix-interpretation h4 {
    font-size: 15px;
    margin-bottom: 8px;
    color: var(--color-primary);
}

.matrix-interpretation p {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.6;
}

/* Toggle Switch */
.toggle-container {
    display: flex;
    align-items: center;
    gap: 10px;
}

.toggle-label {
    font-size: 13px;
    color: var(--text-secondary);
}

.toggle-label.font-bold {
    color: var(--text-primary);
    font-weight: 600;
}

.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.1);
    transition: .4s;
    border: 1px solid var(--border-color);
}

.slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
}

input:checked + .slider {
    background-color: var(--color-primary);
}

input:focus + .slider {
    box-shadow: 0 0 1px var(--color-primary);
}

input:checked + .slider:before {
    transform: translateX(20px);
}

.slider.round {
    border-radius: 34px;
}

.slider.round:before {
    border-radius: 50%;
}

/* --- Utilities --- */
.helper-text {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.hidden {
    display: none !important;
}

/* --- Animations --- */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
    0% { opacity: 0.4; }
    50% { opacity: 1; }
    100% { opacity: 0.4; }
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* --- Methodology Guide --- */
.methodology-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 24px;
}

.methodology-card {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.04);
    border-radius: 12px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.methodology-card h4 {
    font-size: 16px;
    color: var(--color-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.methodology-card .desc {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.5;
}

.methodology-card .formula {
    background: rgba(0, 0, 0, 0.2);
    padding: 12px;
    border-radius: 8px;
    text-align: center;
    font-family: 'Courier New', Courier, monospace;
    font-size: 14px;
    color: #ffffff;
    overflow-x: auto;
    margin: 8px 0;
    border: 1px solid rgba(255, 255, 255, 0.02);
}

.methodology-card .details {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.5;
}

/* --- Optimizer & Backtest Styling --- */
.opt-controls {
    display: flex;
    align-items: center;
    gap: 16px;
}

.opt-breakdown-panel {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.opt-cards-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 24px;
    width: 100%;
    box-sizing: border-box;
}

@media (max-width: 1200px) {
    .opt-cards-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 640px) {
    .opt-cards-grid {
        grid-template-columns: minmax(0, 1fr);
    }
}

.opt-portfolio-card {
    padding: 12px;
    min-width: 0;
    overflow: hidden;
    box-sizing: border-box;
}

.opt-portfolio-card .card-header {
    margin-bottom: 10px;
    gap: 6px;
}

.opt-portfolio-card .card-header h4 {
    font-size: 0.85rem;
    line-height: 1.25;
    word-break: break-word;
}

.opt-metrics-row {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: flex-start;
    gap: 6px 4px;
    font-size: 12px;
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
}

.opt-metrics-row > div {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 1px;
    min-width: 0;
}

.opt-metrics-row .lbl {
    color: var(--text-secondary);
    font-size: 10px;
    font-weight: 500;
    opacity: 0.85;
    white-space: nowrap;
}

.opt-metrics-row strong {
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

.weights-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.weight-bar-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 13px;
}

.weight-bar-item .ticker {
    font-weight: 600;
    width: 60px;
    color: var(--color-primary);
}

.weight-bar-item .pct {
    font-weight: 700;
}

.hypothesis-banner {
    white-space: pre-line;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.5;
}

.hypothesis-banner.success {
    background: rgba(0, 230, 118, 0.1);
    border: 1px solid rgba(0, 230, 118, 0.3);
    color: var(--color-success);
}

.hypothesis-banner.warning {
    background: rgba(255, 179, 0, 0.1);
    border: 1px solid rgba(255, 179, 0, 0.3);
    color: var(--color-warning);
}

.hypothesis-banner.neutral {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

.hypothesis-banner i {
    font-size: 24px;
    flex-shrink: 0;
}

/* --- Step Progress Card Styling --- */
.opt-progress-card {
    background: rgba(18, 26, 47, 0.7);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 24px;
    margin: 20px 0;
}

.progress-header {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 16px;
    font-weight: 600;
    color: var(--color-primary);
    margin-bottom: 16px;
}

.progress-spinner {
    font-size: 20px;
}

.progress-bar-container {
    height: 8px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 20px;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #00f2fe 0%, #4facfe 100%);
    transition: width 0.4s ease;
}

.progress-steps-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.step-item {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
    color: var(--text-secondary);
    transition: all 0.3s ease;
}

.step-item.active {
    color: #ffffff;
    font-weight: 600;
}

.step-item.active .step-icon {
    color: var(--color-primary);
}

.step-item.completed {
    color: var(--color-success);
}

.step-item.completed .step-icon {
    color: var(--color-success);
}

.progress-percent-badge {
    margin-left: auto;
    background: rgba(0, 242, 254, 0.15);
    border: 1px solid rgba(0, 242, 254, 0.4);
    color: var(--color-primary);
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 700;
}

.step-percentage-badge {
    margin-left: auto;
    font-size: 12px;
    font-weight: 700;
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.05);
    padding: 2px 8px;
    border-radius: 6px;
    transition: all 0.3s ease;
}

.step-item.active .step-percentage-badge {
    color: var(--color-primary);
    background: rgba(0, 242, 254, 0.2);
}

.step-item.completed .step-percentage-badge {
    color: var(--color-success);
    background: rgba(0, 230, 118, 0.2);
}

/* --- Live Price Badge & Modal --- */
.label-with-badge {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.label-with-badge label {
    margin-bottom: 0 !important;
}

.live-price-badge {
    background: linear-gradient(135deg, rgba(0, 242, 254, 0.15) 0%, rgba(0, 230, 118, 0.15) 100%);
    border: 1px solid rgba(0, 242, 254, 0.4);
    color: var(--color-primary);
    font-size: 11px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 12px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 0 10px rgba(0, 242, 254, 0.1);
}

.live-price-badge:hover {
    background: linear-gradient(135deg, rgba(0, 242, 254, 0.3) 0%, rgba(0, 230, 118, 0.3) 100%);
    border-color: var(--color-primary);
    color: #ffffff;
    transform: translateY(-1px) scale(1.03);
    box-shadow: 0 0 14px rgba(0, 242, 254, 0.35);
}

.live-price-badge:active {
    transform: scale(0.96);
}

.live-price-badge i {
    font-size: 10px;
    color: var(--color-success);
    animation: flashPulse 1.8s infinite;
}

@keyframes flashPulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.6; transform: scale(1.15); }
}

.input-pulse-highlight {
    animation: inputGlow 0.8s ease-out;
}

@keyframes inputGlow {
    0% {
        border-color: var(--color-success);
        box-shadow: 0 0 15px rgba(0, 230, 118, 0.6);
        background-color: rgba(0, 230, 118, 0.1);
    }
    100% {
        border-color: rgba(255, 255, 255, 0.1);
        box-shadow: none;
        background-color: transparent;
    }
}

/* Modal Overlay */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(6, 9, 19, 0.8);
    backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 1;
    transition: opacity 0.3s ease;
}

.modal-overlay.hidden {
    display: none !important;
    opacity: 0;
    pointer-events: none;
}

.modal-card {
    width: 90%;
    max-width: 440px;
    background: var(--bg-surface-solid);
    border: 1px solid var(--border-glow);
    border-radius: var(--border-radius);
    padding: 24px;
    box-shadow: var(--shadow-premium);
    animation: modalSlideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalSlideUp {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    font-size: 18px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.close-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 24px;
    cursor: pointer;
    transition: color 0.2s;
}

.close-btn:hover {
    color: var(--color-danger);
}

/* Utility hidden class */
.hidden {
    display: none !important;
}

/* --- Live Price Badge Below Input Box --- */
.live-price-below-container {
    margin-top: 8px;
    width: 100%;
}

.live-price-badge-below {
    width: 100%;
    background: linear-gradient(135deg, rgba(0, 242, 254, 0.12) 0%, rgba(0, 230, 118, 0.12) 100%);
    border: 1px solid rgba(0, 242, 254, 0.35);
    color: var(--color-primary);
    font-size: 12px;
    font-weight: 600;
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.live-price-badge-below:hover {
    background: linear-gradient(135deg, rgba(0, 242, 254, 0.25) 0%, rgba(0, 230, 118, 0.25) 100%);
    border-color: var(--color-primary);
    color: #ffffff;
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(0, 242, 254, 0.3);
}

.live-price-badge-below:active {
    transform: scale(0.98);
}

.live-price-badge-below i {
    color: var(--color-success);
    margin-right: 6px;
    font-size: 11px;
    animation: flashPulse 1.8s infinite;
}

.click-apply-tag {
    font-size: 11px;
    color: var(--text-secondary);
    font-weight: 500;
    margin-left: auto;
    background: rgba(255, 255, 255, 0.06);
    padding: 2px 8px;
    border-radius: 4px;
    transition: color 0.2s;
}

.live-price-badge-below:hover .click-apply-tag {
    color: #ffffff;
    background: rgba(0, 242, 254, 0.3);
}

/* Stock Screener Styling */
.screener-header-card {
    padding: 24px;
}

.screener-presets-area {
    margin-bottom: 20px;
}

.screener-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.preset-chips-container {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.preset-chip {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.25s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.preset-chip:hover {
    background: rgba(0, 242, 254, 0.12);
    border-color: var(--color-primary);
    color: var(--color-primary);
    transform: translateY(-2px);
}

.preset-chip.active,
.preset-chip.active i {
    background: #00f2fe !important;
    color: #000000 !important;
    border-color: #00f2fe !important;
    font-weight: 700 !important;
}

.screener-controls-grid {
    display: grid;
    grid-template-columns: 2fr 1fr 1.2fr;
    gap: 16px;
    align-items: end;
    margin-bottom: 20px;
}

@media (max-width: 992px) {
    .screener-controls-grid {
        grid-template-columns: 1fr;
    }
}

.screener-search-input-wrapper {
    position: relative;
}

.selected-tickers-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-top: 16px;
    border-top: 1px dashed var(--border-color);
}

.selected-tickers-bar .bar-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
}

.ticker-tags-container {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.ticker-tag {
    background: rgba(0, 242, 254, 0.1);
    border: 1px solid rgba(0, 242, 254, 0.3);
    color: #ffffff;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.ticker-tag .remove-tag-btn {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.6);
    cursor: pointer;
    font-size: 12px;
    padding: 0;
    margin: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s;
}

.ticker-tag .remove-tag-btn:hover {
    color: #ff5252;
}

.screener-table-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
    padding: 20px 24px;
}

.table-search-input {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    color: #ffffff;
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 13px;
    outline: none;
    width: 180px;
}

.table-search-input:focus {
    border-color: var(--color-primary);
}

.screener-matrix-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
    padding: 20px 24px;
}

.matrix-toggle-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.matrix-toggle-btn.active {
    background: rgba(0, 242, 254, 0.15);
    border-color: var(--color-primary);
    color: var(--color-primary);
}

.matrix-heatmap-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 4px;
    font-size: 12px;
}

.matrix-heatmap-table th,
.matrix-heatmap-table td {
    padding: 10px 12px;
    text-align: center;
    border-radius: 6px;
}

.matrix-heatmap-table th {
    font-weight: 700;
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.05);
}

.screener-action-banner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 20px;
    padding: 24px 30px;
    background: linear-gradient(135deg, rgba(0, 242, 254, 0.08) 0%, rgba(79, 172, 254, 0.04) 100%);
    border: 1px solid rgba(0, 242, 254, 0.25);
    border-radius: 16px;
}

.screener-action-banner h4 {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 6px;
    color: #ffffff;
}

.screener-action-banner p {
    font-size: 13px;
    color: var(--text-secondary);
    max-width: 650px;
    margin: 0;
}

/* --- Outline Button Variants --- */
.btn-outline-primary {
    background: rgba(0, 242, 254, 0.08);
    border: 1px solid rgba(0, 242, 254, 0.3);
    color: var(--color-primary);
}
.btn-outline-primary:hover {
    background: rgba(0, 242, 254, 0.2);
    color: #ffffff;
}

.btn-outline-success {
    background: rgba(0, 230, 118, 0.08);
    border: 1px solid rgba(0, 230, 118, 0.3);
    color: var(--color-success);
}
.btn-outline-success:hover {
    background: rgba(0, 230, 118, 0.2);
    color: #ffffff;
}

.btn-outline-info {
    background: rgba(79, 172, 254, 0.08);
    border: 1px solid rgba(79, 172, 254, 0.3);
    color: #4facfe;
}
.btn-outline-info:hover {
    background: rgba(79, 172, 254, 0.2);
    color: #ffffff;
}

.btn-outline-danger {
    background: rgba(255, 71, 87, 0.08);
    border: 1px solid rgba(255, 71, 87, 0.3);
    color: #ff4757;
}
.btn-outline-danger:hover {
    background: rgba(255, 71, 87, 0.2);
    color: #ffffff;
}

/* --- Comparison Cards Grid Layout --- */
.comparison-cards-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}

@media (max-width: 1024px) {
    .comparison-cards-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 640px) {
    .comparison-cards-grid {
        grid-template-columns: 1fr;
    }
}

/* --- Macroeconomics Interactive Hover Tooltips --- */
.macro-tooltip-container {
    position: relative;
    display: inline-block;
}

.macro-info-icon {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-left: 6px;
    cursor: help;
    transition: color 0.2s ease, transform 0.2s ease;
}

.macro-tooltip-container:hover .macro-info-icon {
    color: #00f2fe;
    transform: scale(1.15);
}

.macro-tooltip-card {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    z-index: 1000;
    width: 320px;
    padding: 14px 16px;
    margin-top: 8px;
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(0, 242, 254, 0.35);
    border-radius: 10px;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.6);
    font-size: 0.8rem;
    line-height: 1.45;
    color: #e2e8f0;
    pointer-events: none;
}

.macro-tooltip-container:hover .macro-tooltip-card {
    display: block;
    animation: fadeInTooltip 0.2s ease-in-out forwards;
}

@keyframes fadeInTooltip {
    from {
        opacity: 0;
        transform: translateY(4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.tooltip-sec {
    margin-bottom: 8px;
}

.tooltip-sec:last-child {
    margin-bottom: 0;
}

.tooltip-sec strong {
    color: #00f2fe;
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 3px;
    font-size: 0.82rem;
}

/* --- Macroeconomics Click-to-Open Info Button & Modal Tables --- */
.macro-info-btn {
    background: rgba(0, 242, 254, 0.12);
    border: 1px solid rgba(0, 242, 254, 0.3);
    color: #00f2fe;
    width: 26px !important;
    height: 26px !important;
    min-width: 26px !important;
    min-height: 26px !important;
    max-width: 26px !important;
    max-height: 26px !important;
    aspect-ratio: 1 / 1 !important;
    flex-shrink: 0 !important;
    border-radius: 50% !important;
    box-sizing: border-box !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s ease;
    margin-left: 6px;
}

.macro-info-btn:hover {
    background: #00f2fe;
    color: #0b132b;
    transform: scale(1.15);
    box-shadow: 0 0 10px rgba(0, 242, 254, 0.5);
}

.macro-regime-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 12px;
    font-size: 0.85rem;
}

.macro-regime-table th, .macro-regime-table td {
    padding: 10px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    text-align: left;
}

.macro-regime-table th {
    background: rgba(255, 255, 255, 0.05);
    color: #00f2fe;
    font-weight: 600;
}

.macro-regime-table tr:hover {
    background: rgba(255, 255, 255, 0.03);
}

/* Autocomplete Search Dropdown Styling */
.search-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: 9999;
    background: #141b2d;
    border: 1px solid rgba(0, 242, 254, 0.3);
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.7);
    max-height: 250px;
    overflow-y: auto;
    padding: 6px 0;
}

.search-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.search-item:last-child {
    border-bottom: none;
}

.search-item:hover, .search-item.active-item {
    background: rgba(0, 242, 254, 0.2);
    border-left: 3px solid #00f2fe;
    padding-left: 11px;
}

.search-item .ticker-sym {
    font-weight: 700;
    color: #00f2fe;
    min-width: 60px;
}

.search-item .ticker-name {
    color: #e2e8f0;
    flex: 1;
    margin: 0 10px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.search-item .ticker-exch {
    font-size: 11px;
    color: #8f9cae;
    background: rgba(255, 255, 255, 0.06);
    padding: 2px 6px;
    border-radius: 4px;
}

.search-item.empty {
    color: #8f9cae;
    font-style: italic;
    cursor: default;
    justify-content: center;
}

/* --- Light Mode Custom Variables & Style Overrides --- */
[data-theme="light"] {
    --bg-base: #ffffff;
    --bg-surface: #ffffff;
    --bg-surface-solid: #ffffff;
    --border-color: rgba(0, 0, 0, 0.12);
    --border-glow: rgba(0, 112, 243, 0.2);

    --color-primary: #0070f3;
    --color-secondary: #00a8ff;
    --color-success: #10b981;
    --color-danger: #ef4444;
    --color-warning: #f59e0b;

    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;

    --shadow-premium: 0 8px 32px 0 rgba(0, 0, 0, 0.08);
}

[data-theme="light"] body {
    background-color: #ffffff !important;
    color: #0f172a !important;
}

[data-theme="light"] .main-content {
    background: #ffffff !important;
    background-image: none !important;
    background-color: #ffffff !important;
}

[data-theme="light"] .sidebar {
    background-color: #f8fafc !important;
    border-right-color: rgba(0, 0, 0, 0.08) !important;
}

[data-theme="light"] .sidebar-nav li {
    color: #475569 !important;
}

[data-theme="light"] .sidebar-nav li:hover {
    background: rgba(0, 112, 243, 0.06) !important;
    color: #0070f3 !important;
}

[data-theme="light"] .sidebar-nav li.active {
    background: linear-gradient(90deg, rgba(0, 112, 243, 0.12) 0%, rgba(0, 112, 243, 0.02) 100%) !important;
    color: #0070f3 !important;
    border-left-color: #0070f3 !important;
}

[data-theme="light"] .sidebar-nav li.active i {
    color: #0070f3 !important;
    text-shadow: none !important;
}

[data-theme="light"] .glass-card,
[data-theme="light"] .macro-card-wrapper,
[data-theme="light"] .chart-container,
[data-theme="light"] .stat-card {
    background: #ffffff !important;
    border-color: rgba(0, 0, 0, 0.1) !important;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05) !important;
    color: #0f172a !important;
}

[data-theme="light"] .header {
    background: #ffffff !important;
    border-bottom-color: rgba(0, 0, 0, 0.08) !important;
}

[data-theme="light"] .theme-toggle-container {
    background: rgba(0, 0, 0, 0.03) !important;
    border-color: rgba(0, 0, 0, 0.08) !important;
}

/* --- Dropdowns, Selects, Inputs, & Options in Light Mode --- */
[data-theme="light"] select,
[data-theme="light"] option,
[data-theme="light"] optgroup,
[data-theme="light"] input,
[data-theme="light"] textarea,
[data-theme="light"] .styled-input,
[data-theme="light"] .btn-sm {
    background-color: #ffffff !important;
    color: #0f172a !important;
    border-color: rgba(0, 0, 0, 0.18) !important;
}

[data-theme="light"] select option {
    background-color: #ffffff !important;
    color: #0f172a !important;
}

[data-theme="light"] .styled-input::placeholder,
[data-theme="light"] input::placeholder {
    color: #94a3b8 !important;
}

/* --- Tables, Modals, & Typography --- */
[data-theme="light"] .styled-table th,
[data-theme="light"] .macro-regime-table th {
    background: rgba(0, 112, 243, 0.05) !important;
    color: #334155 !important;
    border-bottom-color: rgba(0, 0, 0, 0.08) !important;
}

[data-theme="light"] .styled-table td,
[data-theme="light"] .macro-regime-table td:not([style*="color"]) {
    border-bottom-color: rgba(0, 0, 0, 0.06) !important;
    color: #0f172a;
}

[data-theme="light"] .apexcharts-legend-text {
    color: #0f172a !important;
    fill: #0f172a !important;
}

[data-theme="light"] .modal-content {
    background: #ffffff !important;
    color: #0f172a !important;
    border-color: rgba(0, 0, 0, 0.12) !important;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.12) !important;
}

[data-theme="light"] label,
[data-theme="light"] .form-group label,
[data-theme="light"] .helper-text,
[data-theme="light"] .card-subtitle,
[data-theme="light"] p {
    color: #334155 !important;
}

[data-theme="light"] h1, 
[data-theme="light"] h2, 
[data-theme="light"] h3, 
[data-theme="light"] h4, 
[data-theme="light"] h5, 
[data-theme="light"] h6 {
    color: #0f172a !important;
}

/* --- ApexCharts Tooltips & Text in Light Mode --- */
[data-theme="light"] .apexcharts-tooltip {
    background: #ffffff !important;
    color: #0f172a !important;
    border: 1px solid rgba(0, 0, 0, 0.15) !important;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1) !important;
}

[data-theme="light"] .apexcharts-tooltip-title {
    background: #f1f5f9 !important;
    color: #0f172a !important;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1) !important;
}

/* --- Search Dropdown in Light Mode --- */
[data-theme="light"] .search-dropdown {
    background: #ffffff !important;
    border-color: rgba(0, 0, 0, 0.15) !important;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15) !important;
}

[data-theme="light"] .search-item {
    color: #0f172a !important;
}

[data-theme="light"] .search-item:hover {
    background: rgba(0, 112, 243, 0.08) !important;
    color: #0070f3 !important;
}

[data-theme="light"] .search-item .ticker-symbol {
    color: #0070f3 !important;
}

[data-theme="light"] .search-item .ticker-name {
    color: #334155 !important;
}

/* --- Active Universe Tickers in Light Mode --- */
[data-theme="light"] .ticker-tag {
    background: #e2e8f0 !important;
    border: 1px solid #cbd5e1 !important;
    color: #0f172a !important;
    font-weight: 700 !important;
}

[data-theme="light"] .ticker-tag .remove-tag-btn {
    color: #475569 !important;
}

[data-theme="light"] .ticker-tag .remove-tag-btn:hover {
    color: #ef4444 !important;
}

/* --- Correlation Matrix Cells in Light Mode --- */
[data-theme="light"] .matrix-heatmap-table td {
    font-weight: 700 !important;
    color: #0f172a !important;
}

[data-theme="light"] .apexcharts-datalabel,
[data-theme="light"] .apexcharts-datalabels text {
    fill: #0f172a !important;
    color: #0f172a !important;
}

/* --- Primary Blue Buttons in Light Mode --- */
[data-theme="light"] .btn-primary,
[data-theme="light"] #btn-run-screener,
[data-theme="light"] #btn-run-opt,
[data-theme="light"] #btn-run-rebalance {
    background: #0070f3 !important;
    color: #ffffff !important;
    font-weight: 700 !important;
}

[data-theme="light"] .btn-primary i,
[data-theme="light"] .btn-primary span,
[data-theme="light"] #btn-run-screener i,
[data-theme="light"] #btn-run-screener span,
[data-theme="light"] #btn-run-opt i,
[data-theme="light"] #btn-run-opt span,
[data-theme="light"] #btn-run-rebalance i,
[data-theme="light"] #btn-run-rebalance span {
    color: #ffffff !important;
}

[data-theme="light"] .preset-chip.active,
[data-theme="light"] .preset-chip.active i {
    background: #0070f3 !important;
    color: #ffffff !important;
    border-color: #0070f3 !important;
}

/* --- Information Icons & Buttons in Light Mode --- */
[data-theme="light"] .macro-info-btn,
[data-theme="light"] .macro-info-btn i,
[data-theme="light"] .fa-circle-info,
[data-theme="light"] .fa-info-circle,
[data-theme="light"] i.fa-circle-info,
[data-theme="light"] i.fa-info-circle {
    color: #0070f3 !important;
    border-color: rgba(0, 112, 243, 0.4) !important;
    background: rgba(0, 112, 243, 0.08) !important;
}

/* --- Information Modal KaTeX & Section Light Mode Styles --- */
[data-theme="light"] .katex-formula-block,
[data-theme="light"] .katex,
[data-theme="light"] .katex * {
    color: #0f172a !important;
}

[data-theme="light"] #macro-modal-body p,
[data-theme="light"] #macro-modal-body span,
[data-theme="light"] #macro-modal-body li,
[data-theme="light"] #macro-modal-body th,
[data-theme="light"] #macro-modal-body td:not([style*="color"]) {
    color: #0f172a !important;
}

[data-theme="light"] #macro-modal-body .katex-formula-block {
    background: #ffffff !important;
    border-color: rgba(0, 0, 0, 0.15) !important;
}

/* --- Execution & Direct Portfolio Buying Cards in Light Mode --- */
[data-theme="light"] .comparison-cards-grid .opt-portfolio-card,
[data-theme="light"] .weights-list,
[data-theme="light"] .weight-bar-item,
[data-theme="light"] .saved-sets-toolbar {
    background: #ffffff !important;
    border-color: rgba(0, 0, 0, 0.12) !important;
    color: #0f172a !important;
}

[data-theme="light"] .weight-bar-item .pct {
    color: #0f172a !important;
}

/* --- Optimizer Progress Card & Steps in Light Mode --- */
[data-theme="light"] .opt-progress-card {
    background: #ffffff !important;
    border-color: rgba(0, 0, 0, 0.12) !important;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05) !important;
    color: #0f172a !important;
}

[data-theme="light"] .progress-header {
    color: #0070f3 !important;
}

[data-theme="light"] .progress-bar-container {
    background: rgba(0, 0, 0, 0.08) !important;
}

[data-theme="light"] .step-item {
    color: #475569 !important;
}

[data-theme="light"] .step-item.active {
    color: #0f172a !important;
    font-weight: 700 !important;
}

/* --- Macro Crisis & Stress-Test Scenarios Default (Night Mode) --- */
.stresstest-card {
    background: rgba(18, 26, 47, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.08);
    transition: all 0.2s ease;
}

.stresstest-card.active-scenario {
    background: rgba(0, 242, 254, 0.08) !important;
    border: 1px solid #00f2fe !important;
    box-shadow: 0 0 16px rgba(0, 242, 254, 0.15) !important;
}

.stresstest-metrics-box {
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.stresstest-summary-pill {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

/* --- Macro Crisis & Stress-Test Scenarios in Light Mode --- */
[data-theme="light"] .stresstest-controls,
[data-theme="light"] #stresstest-cards-grid,
[data-theme="light"] .scenario-card,
[data-theme="light"] .stress-card,
[data-theme="light"] .hedging-controls,
[data-theme="light"] #stresstest-summary-banner,
[data-theme="light"] #stresstest-details-container {
    background: #ffffff !important;
    border-color: rgba(0, 0, 0, 0.12) !important;
    color: #0f172a !important;
}

[data-theme="light"] .stresstest-card {
    background: #ffffff !important;
    border: 1px solid rgba(0, 0, 0, 0.12) !important;
    color: #0f172a !important;
}

[data-theme="light"] .stresstest-card.active-scenario {
    background: #ffffff !important;
    border: 2px solid #0070f3 !important;
    box-shadow: 0 4px 16px rgba(0, 112, 243, 0.15) !important;
}

[data-theme="light"] .stresstest-metrics-box {
    background: #ffffff !important;
    border: 1px solid rgba(0, 0, 0, 0.1) !important;
}

[data-theme="light"] .stresstest-summary-pill {
    background: #ffffff !important;
    border: 1px solid rgba(0, 0, 0, 0.12) !important;
}

/* --- Ticker Exclusion Alert Text Color --- */
#stresstest-exclusion-alert,
.exclusion-notice {
    color: #d97706 !important;
}

/* --- Strategy Performance & Risk Matrix Table in Light Mode --- */
[data-theme="light"] .dashboard-table td strong {
    color: #0f172a !important;
}

[data-theme="light"] .dashboard-table td,
[data-theme="light"] .dashboard-table th {
    color: #0f172a !important;
}

/* ...but don't let the blanket override above stomp on gain/loss coloring in table cells
   (e.g. the Dashboard's Holdings Summary "Returns" column) — positive/negative must stay
   green/red in light mode too, not just dark mode. */
[data-theme="light"] .dashboard-table td.positive,
[data-theme="light"] .dashboard-table .stat-sub.positive {
    color: var(--color-success) !important;
}

[data-theme="light"] .dashboard-table td.negative,
[data-theme="light"] .dashboard-table .stat-sub.negative {
    color: var(--color-danger) !important;
}

/* --- Toast Notifications in Light Mode --- */
[data-theme="light"] .toast-message,
[data-theme="light"] #toast-container .toast-message {
    background: #ffffff !important;
    color: #0f172a !important;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15) !important;
}

[data-theme="light"] .toast-message span {
    color: #0f172a !important;
}

/* --- Holdings List Manager & Filter Styles --- */
.dashboard-filter-bar,
.holdings-list-manager-bar {
    transition: all 0.3s ease;
}

[data-theme="light"] .dashboard-filter-bar,
[data-theme="light"] .holdings-list-manager-bar {
    background: #ffffff !important;
    border: 1px solid rgba(0, 0, 0, 0.1) !important;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05) !important;
}

[data-theme="light"] .dashboard-filter-bar span,
[data-theme="light"] .holdings-list-manager-bar h3 {
    color: #0f172a !important;
}






/* --- Crisis Regime Detector (Macroeconomics tab) --- */
.crisis-card {
    padding: 20px 24px;
    margin-bottom: 24px;
    border-left: 4px solid #ff9100;
}
.crisis-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}
.crisis-headline {
    font-family: 'Outfit', sans-serif;
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 4px 0 6px 0;
    display: flex;
    align-items: center;
    gap: 10px;
}
.crisis-summary {
    font-size: 0.86rem;
    color: var(--text-secondary);
    line-height: 1.5;
    margin: 0 0 16px 0;
}
.crisis-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 16px;
    margin-bottom: 16px;
}
.crisis-panel {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    padding: 12px 14px;
    min-width: 0;
}
.crisis-panel-hold { border-color: rgba(0, 230, 118, 0.25); background: rgba(0, 230, 118, 0.04); }
.crisis-panel-avoid { border-color: rgba(255, 71, 87, 0.25); background: rgba(255, 71, 87, 0.04); }
.crisis-panel-title {
    display: block;
    font-size: 0.8rem;
    color: var(--text-primary);
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.crisis-playbook-title {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 4px 0 10px 0;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.crisis-score-row { margin-bottom: 10px; }
.crisis-score-row.is-top .crisis-score-label { font-weight: 700; color: var(--text-primary); }
.crisis-score-label {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}
.crisis-score-num { font-weight: 700; color: var(--text-primary); white-space: nowrap; }
.crisis-score-num small { font-weight: 500; color: var(--text-muted); margin-left: 4px; }
.crisis-bar-track {
    position: relative;
    height: 8px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.07);
    overflow: hidden;
}
.crisis-bar-fill { height: 100%; border-radius: 4px; transition: width 0.6s ease; }
.crisis-bar-marker {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 1px;
    background: rgba(255, 255, 255, 0.35);
}
.crisis-evidence-list {
    list-style: none;
    margin: 0;
    padding: 0;
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.45;
}
.crisis-evidence-group { margin-bottom: 10px; }
.crisis-evidence-group ul { margin: 4px 0 0 0; padding-left: 18px; }
.crisis-evidence-group ul li { margin-bottom: 3px; }
.crisis-asset-table { margin-top: 0; font-size: 0.82rem; }
.crisis-asset-table td { padding: 7px 8px; vertical-align: top; color: var(--text-primary); }
.crisis-cheatsheet-details {
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    padding: 10px 14px;
    margin-bottom: 10px;
}
.crisis-cheatsheet-details summary {
    cursor: pointer;
    font-weight: 600;
    font-size: 0.88rem;
    color: var(--color-primary);
}
.crisis-cheatsheet-table th, .crisis-cheatsheet-table td { text-align: center; white-space: nowrap; }
.crisis-cheatsheet-table th:first-child, .crisis-cheatsheet-table td:first-child { text-align: left; }
.crisis-cheat-cell { font-size: 0.9rem; }
.crisis-col-active { background: rgba(255, 145, 0, 0.12) !important; }
.crisis-legend { font-size: 0.75rem; color: var(--text-muted); margin-top: 8px; }
.crisis-footnote { font-size: 0.75rem; color: var(--text-muted); margin: 6px 0 0 0; line-height: 1.4; }
.macro-section-title {
    margin: 32px 0 16px 0;
    font-size: 1.1rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

[data-theme="light"] .crisis-panel { background: #f8fafc; border-color: rgba(0, 0, 0, 0.08); }
[data-theme="light"] .crisis-panel-hold { background: rgba(16, 185, 129, 0.06); border-color: rgba(16, 185, 129, 0.3); }
[data-theme="light"] .crisis-panel-avoid { background: rgba(239, 68, 68, 0.05); border-color: rgba(239, 68, 68, 0.3); }
[data-theme="light"] .crisis-bar-track { background: rgba(0, 0, 0, 0.08); }
[data-theme="light"] .crisis-bar-marker { background: rgba(0, 0, 0, 0.3); }
[data-theme="light"] .crisis-cheatsheet-details { border-color: rgba(0, 0, 0, 0.1); }
[data-theme="light"] .crisis-col-active { background: rgba(245, 158, 11, 0.15) !important; }

@media (max-width: 600px) {
    .crisis-grid { grid-template-columns: 1fr; }
    .crisis-headline { font-size: 1.1rem; }
}

/* AI second opinion panel inside the Crisis Regime Detector */
.crisis-ai-panel {
    background: rgba(0, 242, 254, 0.05);
    border: 1px solid rgba(0, 242, 254, 0.22);
    border-radius: 10px;
    padding: 12px 14px;
    margin-bottom: 16px;
}
.crisis-ai-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}
.crisis-ai-badges { display: flex; gap: 6px; flex-wrap: wrap; }
.crisis-ai-badges .badge { text-transform: capitalize; }
.crisis-ai-body { font-size: 0.84rem; color: var(--text-secondary); line-height: 1.5; }
.crisis-ai-verdict { font-weight: 700; color: var(--text-primary); font-size: 0.92rem; margin-bottom: 6px; }
.crisis-ai-reasoning { margin: 0 0 8px 0; font-size: 0.84rem; color: var(--text-secondary); line-height: 1.55; }
.crisis-ai-secondary { font-size: 0.8rem; margin-bottom: 8px; color: var(--text-secondary); }
.crisis-ai-lists { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; }
.crisis-ai-lists ul { margin: 4px 0 0 0; padding-left: 18px; font-size: 0.8rem; }
.crisis-ai-lists li { margin-bottom: 3px; }
.crisis-ai-list-title { font-size: 0.78rem; font-weight: 700; color: var(--text-primary); }
.crisis-ai-footnote { font-size: 0.72rem; color: var(--text-muted); margin-top: 8px; }
[data-theme="light"] .crisis-ai-panel { background: rgba(0, 112, 243, 0.04); border-color: rgba(0, 112, 243, 0.2); }

/* --- Sign-in (auth.js) --- */
.auth-overlay {
    z-index: 3000;
    background: var(--bg-base);
}

.auth-card {
    max-width: 400px;
    text-align: center;
    padding: 32px 28px;
}

.auth-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 20px;
}

.auth-logo i {
    color: var(--color-primary);
}

.auth-card h2 {
    font-size: 1.25rem;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.auth-sub {
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.5;
    margin-bottom: 24px;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
    text-align: left;
}

.auth-form label {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.auth-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    min-height: 44px;
}

.auth-error {
    color: var(--color-danger);
    font-size: 0.85rem;
    margin-top: 12px;
    min-height: 1em;
}

.auth-user-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    min-height: 40px;
    padding: 8px 12px;
    margin-bottom: 12px;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    color: var(--text-secondary);
    font: inherit;
    font-size: 0.85rem;
    text-align: left;
    cursor: pointer;
}

.auth-user-chip:hover,
.auth-user-chip:focus-visible {
    border-color: var(--border-glow);
    color: var(--text-primary);
}

.auth-chip-gear {
    font-size: 0.8rem;
}

.auth-user-chip > i {
    color: var(--color-primary);
}

.auth-user-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.auth-divider {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-muted);
    font-size: 0.8rem;
    margin: 6px 0;
}

.auth-divider::before,
.auth-divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--border-color);
}

.auth-links {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.auth-link {
    background: none;
    border: none;
    padding: 6px 0;
    color: var(--color-secondary);
    font: inherit;
    font-size: 0.85rem;
    cursor: pointer;
}

.auth-link:hover,
.auth-link:focus-visible {
    text-decoration: underline;
}

.auth-info {
    color: var(--color-success);
    font-size: 0.85rem;
    min-height: 1em;
}

.auth-legal {
    margin-top: 16px;
    color: var(--text-muted);
    font-size: 0.78rem;
}

.auth-legal a {
    color: var(--text-secondary);
}

.account-card {
    max-width: 420px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.account-who {
    color: var(--text-secondary);
    font-size: 0.9rem;
    overflow-wrap: anywhere;
}

.account-danger {
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 10px 14px;
}

.account-danger summary {
    cursor: pointer;
    color: var(--color-danger);
    font-weight: 600;
    min-height: 32px;
    display: flex;
    align-items: center;
}

.account-danger[open] {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.account-danger p {
    color: var(--text-secondary);
    font-size: 0.85rem;
    line-height: 1.5;
}

/* Disclaimer pinned to the bottom of the screen, centred */
.app-disclaimer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 150;
    padding: 6px 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.72rem;
    line-height: 1.4;
    background: rgba(10, 15, 29, 0.92);
    border-top: 1px solid var(--border-color);
}

.app-disclaimer a {
    color: var(--text-secondary);
}

[data-theme="light"] .app-disclaimer {
    background: rgba(255, 255, 255, 0.94);
    border-top-color: rgba(0, 0, 0, 0.08);
}

/* Keep the last content clear of the disclaimer bar */
.main-content {
    padding-bottom: 56px;
}

.sidebar {
    padding-bottom: 40px;
}

/* Sign-in and account fields: email/password inputs aren't covered by the text-input rule */
.auth-card input,
.account-card input {
    width: 100%;
    min-height: 44px;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
}

.account-danger .auth-error {
    color: var(--color-danger);
}

/* --- Fair value estimate card (Fundamentals tab) --- */
.valuation-card {
    padding: 20px 24px;
    margin-bottom: 24px;
    border-left: 4px solid var(--color-primary);
    transition: opacity 0.2s;
}
.valuation-card.valuation-busy { opacity: 0.55; pointer-events: none; }
.valuation-loading { padding: 12px 0; color: var(--text-secondary); font-size: 0.9rem; }
.valuation-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.valuation-head h3 { margin: 0; font-size: 1.1rem; color: var(--text-primary); }
.valuation-head h3 i { color: var(--color-primary); }
.valuation-verdict { font-size: 0.85rem; padding: 5px 14px; }
.valuation-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.valuation-stat {
    display: flex; flex-direction: column; gap: 3px; min-width: 0;
    padding: 12px 14px; border: 1px solid var(--border-color); border-radius: 10px;
}
.valuation-stat.highlight { border-color: var(--border-glow); background: rgba(0, 242, 254, 0.05); }
.valuation-stat-label { font-size: 0.72rem; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.05em; }
.valuation-stat-value { font-family: 'Outfit', sans-serif; font-size: 1.45rem; font-weight: 600; color: var(--text-primary); }
.valuation-stat-value.muted, .valuation-table tr.muted td { color: var(--text-muted); }
.valuation-stat-sub { font-size: 0.75rem; color: var(--text-secondary); }
.val-up { color: var(--color-success) !important; }
.val-down { color: var(--color-danger) !important; }

/* Range bar: shaded fair-value range with markers for price, fair value and analyst target */
.valuation-bar { position: relative; height: 10px; margin: 46px 8px 40px; border-radius: 5px; background: var(--border-color); }
.valuation-bar-range { position: absolute; top: 0; bottom: 0; border-radius: 5px; background: rgba(0, 242, 254, 0.35); }
.valuation-bar-mark { position: absolute; top: -6px; width: 3px; height: 22px; margin-left: -1.5px; border-radius: 2px; }
.valuation-bar-mark span {
    position: absolute; left: 50%; transform: translateX(-50%); white-space: nowrap;
    font-size: 0.72rem; font-weight: 600;
}
.valuation-bar-mark.price { background: var(--text-primary); }
.valuation-bar-mark.price span { top: -20px; color: var(--text-primary); }
.valuation-bar-mark.fair { background: var(--color-primary); }
.valuation-bar-mark.fair span { top: 26px; color: var(--color-primary); }
.valuation-bar-mark.analyst { background: var(--color-warning); }
.valuation-bar-mark.analyst span { top: 26px; color: var(--color-warning); transform: translateX(-50%) translateY(14px); }

.valuation-subhead { margin: 18px 0 8px; font-size: 0.9rem; color: var(--text-primary); }
.valuation-subhead small { font-weight: 400; color: var(--text-secondary); font-size: 0.75rem; }
.valuation-table { width: 100%; overflow-x: auto; }
.valuation-table .data-table th, .valuation-table .data-table td { padding: 9px 12px; }
.valuation-table td.valuation-explain { white-space: normal; min-width: 260px; color: var(--text-secondary); font-size: 12px; }
.valuation-table.sensitivity td, .valuation-table.sensitivity th { text-align: center; }
.valuation-table.sensitivity td.center { outline: 2px solid var(--color-primary); outline-offset: -2px; font-weight: 700; }

.valuation-details { margin-top: 16px; border-top: 1px solid var(--border-color); padding-top: 12px; }
.valuation-details summary { cursor: pointer; font-size: 0.9rem; font-weight: 600; color: var(--text-primary); }
.valuation-details summary i { color: var(--color-primary); margin-right: 4px; }
.valuation-assumptions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-top: 14px; }
.valuation-assumptions label { display: flex; flex-direction: column; gap: 6px; font-size: 0.8rem; color: var(--text-secondary); }
.valuation-assumptions small { font-size: 0.72rem; color: var(--text-muted); }
.valuation-actions { display: flex; gap: 10px; margin-top: 12px; }
.valuation-bt-text { font-size: 0.82rem; color: var(--text-secondary); line-height: 1.5; margin: 10px 0; }
.valuation-note { margin-top: 14px; font-size: 0.75rem; color: var(--text-muted); line-height: 1.45; }
.valuation-section { padding: 16px 0; border-top: 1px solid var(--border-color); }
.valuation-section:first-of-type { border-top: none; padding-top: 0; }
.valuation-section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.valuation-section-title { margin: 0 0 10px; font-size: 0.95rem; color: var(--text-primary); }
.valuation-section-head .valuation-section-title { margin: 0; }

/* Quality: headline percentile plus one bar per measure */
.quality-headline { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.quality-pct { font-family: 'Outfit', sans-serif; font-size: 2.4rem; font-weight: 700; color: var(--color-primary); line-height: 1; }
.quality-pct-sub { font-size: 0.85rem; color: var(--text-secondary); line-height: 1.35; }
.quality-pct-sub small { color: var(--text-muted); font-size: 0.75rem; }
.quality-metrics { display: flex; flex-direction: column; gap: 8px; }
.quality-metric { display: grid; grid-template-columns: minmax(0, 180px) 64px minmax(0, 1fr) 44px; align-items: center; gap: 12px; font-size: 0.82rem; }
.quality-metric.muted { opacity: 0.55; }
.quality-metric-name { color: var(--text-secondary); }
.quality-metric-value { color: var(--text-primary); font-weight: 600; text-align: right; }
.quality-metric-bar { height: 8px; border-radius: 4px; background: var(--border-color); overflow: hidden; }
.quality-metric-bar div { height: 100%; border-radius: 4px; background: var(--color-primary); }
.quality-metric-pct { color: var(--text-secondary); font-size: 0.75rem; text-align: right; }

/* Quality Ranking tab */
.quality-ranking-card { padding: 24px; border-top: 3px solid var(--color-primary); }
.quality-ranking-head h2 { margin: 0; font-size: 1.4rem; color: var(--text-primary); }
.quality-ranking-head h2 i { color: var(--color-primary); }
.quality-ranking-head p { margin: 4px 0 0; font-size: 0.85rem; color: var(--text-secondary); }
.quality-ranking-controls { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1fr); gap: 10px; margin: 18px 0 10px; }
.quality-ranking-summary { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 16px; font-size: 0.78rem; color: var(--text-secondary); margin-bottom: 8px; }
.quality-ranking-table { max-height: 70vh; overflow: auto; border: 1px solid var(--border-color); border-radius: 10px; }
.quality-ranking-table thead th { position: sticky; top: 0; background: var(--bg-surface-solid); z-index: 1; }
.quality-ranking-table th.sortable { cursor: pointer; user-select: none; }
.quality-ranking-table th.sortable:hover { color: var(--text-primary); }
.quality-ranking-table tbody tr { cursor: pointer; }
.quality-ranking-table td.qr-company { display: flex; flex-direction: column; gap: 2px; white-space: normal; min-width: 180px; }
.quality-ranking-table td.qr-company span { font-size: 11.5px; color: var(--text-secondary); }
.quality-ranking-table td.qr-score { min-width: 120px; }
.quality-ranking-table td.qr-score > span { display: block; font-weight: 600; margin-bottom: 4px; }
.quality-ranking-table td.qr-info { color: var(--text-secondary); }

@media (max-width: 900px) {
    .quality-ranking-controls { grid-template-columns: minmax(0, 1fr); }
    .valuation-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .valuation-assumptions { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 768px) {
    .valuation-card { padding: 16px; }
    .quality-metric { grid-template-columns: minmax(0, 1fr) 56px 40px; }
    .quality-metric-bar { grid-column: 1 / -1; grid-row: 2; }
    .valuation-stat-value { font-size: 1.2rem; }
    .valuation-bar-mark span { font-size: 0.66rem; }
}

/* --- Phone and small tablet layout --- */
.mobile-topbar,
.sidebar-backdrop {
    display: none;
}

@media (max-width: 768px) {
    /* Sidebar becomes a slide-out menu (mobile-nav.js) */
    .sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        width: min(280px, 82vw);
        z-index: 200;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        box-shadow: none;
    }

    body.sidebar-open .sidebar {
        transform: none;
        box-shadow: 8px 0 32px rgba(0, 0, 0, 0.45);
    }

    .sidebar-backdrop {
        position: fixed;
        inset: 0;
        z-index: 190;
        background: rgba(0, 0, 0, 0.5);
    }

    body.sidebar-open .sidebar-backdrop {
        display: block;
    }

    .mobile-topbar {
        display: flex;
        align-items: center;
        gap: 12px;
        position: sticky;
        top: 0;
        z-index: 120;
        margin: 0 -16px 16px;
        padding: 10px 16px;
        background: rgba(10, 15, 29, 0.94);
        border-bottom: 1px solid var(--border-color);
        backdrop-filter: blur(10px);
        -webkit-backdrop-filter: blur(10px);
    }

    .mobile-topbar .logo-text {
        font-size: 18px;
    }

    .mobile-menu-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 40px;
        border-radius: 10px;
        border: 1px solid var(--border-color);
        background: rgba(255, 255, 255, 0.04);
        color: var(--text-primary);
        font-size: 18px;
        cursor: pointer;
    }

    [data-theme="light"] .mobile-topbar {
        background: rgba(255, 255, 255, 0.94);
        border-bottom-color: rgba(0, 0, 0, 0.08);
    }

    [data-theme="light"] .mobile-menu-btn {
        background: #f1f5f9;
        border-color: rgba(0, 0, 0, 0.08);
        color: #0f172a;
    }

    /* Content uses the full width */
    .app-container {
        width: 100%;
    }

    .main-content {
        padding: 0 16px 56px;
        min-width: 0;
    }

    .content-header {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
        margin-bottom: 20px;
    }

    .content-header h1 {
        font-size: 24px;
    }

    .header-actions,
    .benchmark-selector {
        flex-wrap: wrap;
    }

    .card-header {
        padding: 14px 16px;
        flex-wrap: wrap;
        gap: 10px;
    }

    .card-header h3 {
        font-size: 16px;
    }

    .card-body {
        padding: 16px;
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 12px;
        margin-bottom: 20px;
    }

    .stat-card {
        padding: 14px;
        gap: 12px;
    }

    .stat-icon {
        width: 38px;
        height: 38px;
        font-size: 16px;
        flex-shrink: 0;
    }

    /* Wide tables scroll sideways inside their card instead of stretching the page */
    table {
        display: block;
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .tab-content {
        min-width: 0;
    }

    /* Stat cards: icon above the numbers so two fit side by side */
    .stat-card {
        flex-direction: column;
        align-items: flex-start;
        min-width: 0;
    }

    .stat-card > * {
        min-width: 0;
        max-width: 100%;
    }

    /* Grids laid out with inline styles (in the page and in rendered results) go to one column */
    .tab-content [style*="grid-template-columns"] {
        grid-template-columns: minmax(0, 1fr) !important;
    }

    /* Inline flex rows (label + dropdown, button groups) wrap instead of squeezing */
    .tab-content [style*="display: flex"],
    .tab-content [style*="display:flex"] {
        flex-wrap: wrap;
    }

    .tab-content select {
        flex: 1 1 160px !important;
        min-width: 0 !important;
        max-width: 100%;
    }

    th,
    td {
        padding: 10px 10px;
        font-size: 13px;
    }

    th {
        white-space: nowrap;
    }

    /* Screener: presets scroll sideways in one row; long ticker lists scroll inside the card */
    .preset-chips-container {
        flex-wrap: nowrap;
        overflow-x: auto;
        padding-bottom: 6px;
        -webkit-overflow-scrolling: touch;
    }

    .preset-chip {
        flex-shrink: 0;
        white-space: nowrap;
        padding: 7px 12px;
        font-size: 12px;
    }

    .selected-tickers-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .ticker-tags-container {
        max-height: 200px;
        overflow-y: auto;
    }

    /* Optimizer: settings in two columns, ticker input above the run button */
    .opt-controls {
        flex-wrap: wrap;
        width: 100%;
        gap: 10px;
    }

    .opt-controls .control-group {
        flex: 1 1 calc(50% - 10px);
        min-width: 0;
    }

    .opt-controls select {
        width: 100%;
    }

    .matrix-input-wrapper {
        flex-direction: column;
    }

    /* Bigger tap target for the popups' close button */
    .close-modal-btn {
        padding: 8px;
        margin: -8px;
    }

    .opt-saved-select-group {
        flex-wrap: wrap;
        max-width: 100%;
    }

    .opt-saved-select-group select {
        max-width: 100%;
    }
}
