:root {
    --bg-dark: #f4f7fb;
    --bg-card: rgba(255, 255, 255, 0.92);
    --bg-sidebar: #ffffff;
    --surface: #ffffff;
    --card-bg: #ffffff;
    --text-main: #172033;
    --text-muted: #64748b;
    --accent: #d7263d;
    --primary: #d7263d;
    --accent-glow: rgba(215, 38, 61, 0.16);
    --blue: #2563eb;
    --green: #059669;
    --border: rgba(30, 41, 59, 0.12);
}

* { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Inter', sans-serif; }

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
    background-image: linear-gradient(135deg, #f8fafc 0%, #eef4ff 48%, #fff5f6 100%);
}

.app-container { display: flex; height: 100vh; }

/* Sidebar */
.sidebar {
    width: 240px;
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 30px 0;
}

.logo {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 0 25px 40px;
    font-size: 18px;
    font-weight: 800;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.nav-menu { padding: 0 15px; }
.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    text-decoration: none;
    color: var(--text-muted);
    border-radius: 12px;
    margin-bottom: 5px;
    font-size: 14px;
    font-weight: 500;
    transition: 0.3s;
}
.nav-item:hover, .nav-item.active {
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-main);
}
.nav-item.active {
    color: var(--accent);
    background: rgba(255, 71, 87, 0.05);
}

/* Main */
.main-content { flex: 1; overflow-y: auto; display: flex; flex-direction: column; }

.topbar {
    padding: 25px 40px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(10px);
    position: sticky; top: 0; z-index: 100;
}

.welcome-text h1 { font-size: 24px; font-weight: 700; }
.welcome-text p { color: var(--text-muted); font-size: 14px; margin-top: 5px; }

.header-actions { display: flex; gap: 15px; }

/* Dashboard Content */
.dashboard { padding: 40px; }

.result-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: auto auto;
    gap: 30px;
    transition: opacity 0.18s ease, filter 0.18s ease;
}

.result-grid.is-refreshing {
    opacity: 0.72;
    filter: saturate(0.85);
    pointer-events: none;
}

.result-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 30px;
    backdrop-filter: blur(15px);
}

.card-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 25px;
}
.card-header i { font-size: 20px; color: var(--accent); }
.card-header h3 { font-size: 16px; font-weight: 700; letter-spacing: 0.5px; }

.numbers-display {
    display: flex;
    gap: 20px;
    margin-bottom: 25px;
    flex-wrap: wrap;
}
.numbers-display .num {
    font-size: 68px;
    font-weight: 800;
    color: var(--accent);
    line-height: 1;
    min-width: 96px;
    min-height: 92px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 14px;
    background: #fff1f3;
    border: 1px solid rgba(215, 38, 61, 0.18);
    box-shadow: 0 12px 26px rgba(215, 38, 61, 0.12);
    text-shadow: none;
}

.reason-text {
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.6;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

/* De Section */
.de-card { grid-column: 1 / 3; }
.de-stats { display: flex; gap: 40px; margin-bottom: 30px; }
.stat-item span { font-size: 12px; color: var(--text-muted); margin-right: 10px; }
.stat-item strong { font-size: 18px; color: var(--green); }

.de-lists { display: grid; grid-template-columns: 1fr 1.5fr; gap: 40px; margin-bottom: 25px; }
.list-group h4 { font-size: 12px; color: var(--text-muted); margin-bottom: 15px; text-transform: uppercase; }

.numbers-wrap { display: flex; flex-wrap: wrap; gap: 10px; }
.numbers-wrap span {
    background: rgba(255, 255, 255, 0.05);
    padding: 8px 12px;
    border-radius: 8px;
    font-weight: 700;
    font-size: 15px;
    color: var(--text-main);
    border: 1px solid var(--border);
}
.de-dan10 span { color: #ff9f43; border-color: rgba(255, 159, 67, 0.3); }
.full-width { grid-column: 1 / 3; margin-top: 20px; }
#de-dan36 span { color: var(--green); border-color: rgba(46, 213, 115, 0.3); }

/* Ba Cang */
.numbers-wrap.compact span { font-size: 13px; padding: 6px 10px; }

/* Global components */
.btn {
    padding: 12px 24px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: 0.3s;
    border: none;
}
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 8px 20px var(--accent-glow); }
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 12px 25px var(--accent-glow); }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text-muted); }
.btn-outline:hover { background: rgba(255,255,255,0.05); color: var(--text-main); }

.spinner {
    width: 50px; height: 50px;
    border: 3px solid rgba(255,255,255,0.05);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s infinite linear;
    margin-bottom: 20px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 100px 0; opacity: 0.6;
}
.empty-state i { font-size: 60px; margin-bottom: 25px; color: var(--text-muted); }

.hidden { display: none !important; }

/* Tab Views */
.view-section {
    display: none;
    animation: fadeIn 0.3s ease-in-out;
}

.view-section.active {
    display: block;
}

.settings-tab-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    padding: 10px 0;
    position: relative;
    transition: 0.3s;
    display: flex;
    align-items: center;
    gap: 8px;
}

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

.settings-tab-btn.active {
    color: var(--accent);
}

.settings-tab-btn.active::after {
    content: '';
    position: absolute;
    bottom: -16px;
    left: 0;
    width: 100%;
    height: 2px;
    background: var(--accent);
    box-shadow: 0 0 10px var(--accent-glow);
}

.sub-view {
    display: none;
}

.sub-view.active {
    display: block;
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background: rgba(20, 20, 20, 0.95);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 20px;
    color: white;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 250px;
    animation: slideIn 0.3s ease-out forwards;
    backdrop-filter: blur(10px);
}

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

.toast.success { border-left: 4px solid #10b981; }
.toast.error { border-left: 4px solid #ef4444; }
.toast.info { border-left: 4px solid var(--accent); }

.toast i { font-size: 18px; }
.toast.success i { color: #10b981; }
.toast.error i { color: #ef4444; }
.toast.info i { color: var(--accent); }

/* Status Badges */
.status-active {
    color: #10b981;
    background: rgba(16, 185, 129, 0.1);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
}

.status-error {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
}

/* Custom Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
    backdrop-filter: blur(8px);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: 0.3s;
}

.modal-overlay.hidden {
    display: none;
    opacity: 0;
}

.modal-content {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    width: 400px;
    padding: 30px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.5);
    text-align: center;
    animation: modalSlideUp 0.3s ease-out;
}

@keyframes modalSlideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-header i {
    font-size: 40px;
    color: #f59e0b;
    margin-bottom: 15px;
}

.modal-header h3 {
    font-size: 20px;
    margin-bottom: 10px;
}

.modal-body p {
    color: var(--text-muted);
    margin-bottom: 25px;
    line-height: 1.6;
}

.modal-footer {
    display: flex;
    gap: 12px;
}

.modal-footer .btn {
    flex: 1;
    padding: 12px;
}

.btn-danger {
    background: linear-gradient(135deg, #ef4444 0%, #b91c1c 100%);
    box-shadow: 0 4px 15px rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(239, 68, 68, 0.4);
}

/* History Table */
.history-container {
    background: var(--surface);
    border-radius: 16px;
    padding: 1.5rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    overflow-x: auto;
}

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

.history-table th, .history-table td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.history-table th {
    font-weight: 600;
    color: var(--accent);
    background: rgba(255,255,255,0.02);
}

.history-table tr:hover {
    background: rgba(255,255,255,0.05);
}

/* Settings */
.settings-container {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.settings-card {
    background: var(--surface);
    border-radius: 16px;
    padding: 1.5rem;
    border: 1px solid var(--border);
}

.settings-card h3 {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-main);
    margin-bottom: 0.5rem;
}

.settings-desc {
    color: var(--text-muted);
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.danger-zone {
    border: 1px solid #ef4444;
}

.danger-zone h3 {
    color: #ef4444;
}

.btn-danger {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    border: 1px solid #ef4444;
    padding: 12px 24px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
}

.btn-danger:hover {
    background: #ef4444;
    color: white;
}

.input-group {
    display: flex;
    gap: 1rem;
}

.form-control {
    flex: 1;
    padding: 0.75rem 1rem;
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border);
    color: white;
    border-radius: 8px;
    font-family: inherit;
    font-size: 1rem;
}

/* Backtest Terminal UI */
.backtest-container {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.backtest-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: var(--surface);
    padding: 1rem 1.5rem;
    border-radius: 12px;
    border: 1px solid var(--border);
}

.terminal-window {
    background: #0f172a;
    border-radius: 12px;
    border: 1px solid #1e293b;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
}

.terminal-header {
    background: #1e293b;
    padding: 10px 15px;
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid #334155;
}

.terminal-header .dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.terminal-header .dot.red { background: #ef4444; }
.terminal-header .dot.yellow { background: #f59e0b; }
.terminal-header .dot.green { background: #10b981; }

.terminal-title {
    margin-left: auto;
    margin-right: auto;
    color: #94a3b8;
    font-size: 0.85rem;
    font-family: monospace;
}

.terminal-body {
    padding: 1.5rem;
    margin: 0;
    color: #38bdf8;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.9rem;
    line-height: 1.6;
    overflow-y: auto;
    max-height: 500px;
    white-space: pre-wrap;
    word-break: break-all;
}

.terminal-body span.money {
    color: #4ade80;
    font-weight: bold;
}

/* --- MOBILE RESPONSIVE --- */
@media (max-width: 1200px) {
    .app-container {
        flex-direction: column;
    }
    
    .sidebar {
        width: 100%;
        height: auto;
        padding: 15px;
        border-right: none;
        border-bottom: 1px solid var(--border);
        display: grid !important;
        grid-template-columns: 1fr auto !important;
        gap: 15px !important;
        align-items: center !important;
    }
    
    .logo {
        grid-row: 1 !important;
        grid-column: 1 !important;
        padding: 0 !important;
        margin-bottom: 0 !important;
        justify-self: start !important;
    }
    
    .user-profile {
        grid-row: 1 !important;
        grid-column: 2 !important;
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        gap: 10px !important;
        padding: 0 !important;
        justify-self: end !important;
        margin-top: 0 !important;
    }
    
    .user-profile #user-email,
    .user-profile i.fa-circle-user {
        display: none !important;
    }
    
    #user-remaining-days {
        margin: 0 !important;
        font-size: 13px !important;
        color: #00ff9d !important;
    }
    
    .logout-link {
        font-size: 0 !important;
        padding: 5px !important;
        margin: 0 !important;
        background: none !important;
        border: none !important;
        color: #ff4d4d !important;
    }
    
    .logout-link i {
        font-size: 16px !important;
    }
    
    .topbar {
        grid-row: 2 !important;
        grid-column: 1 / span 2 !important;
        padding: 0 !important;
        margin-bottom: 0 !important;
        background: none !important;
        border: none !important;
        display: flex !important;
        flex-direction: row !important;
        justify-content: center !important;
        gap: 10px !important;
        width: 100% !important;
    }
    
    .topbar .page-title {
        display: none !important;
    }
    
    .sidebar-nav {
        grid-row: 3 !important;
        grid-column: 1 / span 2 !important;
        display: flex !important;
        flex-direction: row !important;
        overflow-x: auto !important;
        padding: 5px 0 0 0 !important;
        scrollbar-width: none !important;
        width: 100% !important;
    }
    
    .sidebar-nav::-webkit-scrollbar {
        display: none;
    }
    
    .nav-item {
        white-space: nowrap;
        margin-bottom: 0;
        margin-right: 10px;
        padding: 12px 20px;
        font-size: 16px;
    }
    
    .user-profile {
        display: none;
    }
    
    .main-content {
        height: auto;
    }
    
    .topbar {
        padding: 15px 20px;
        flex-direction: column;
        gap: 15px;
        align-items: flex-start;
    }
    
    .header-actions {
        width: 100%;
        justify-content: space-between;
    }
    
    .header-actions .btn {
        flex: 1;
        justify-content: center;
        padding: 10px;
        font-size: 12px;
    }
    
    .dashboard {
        padding: 15px;
    }
    
    .result-grid {
        display: flex !important;
        flex-direction: column !important;
        gap: 20px;
    }
    
    #result-grid {
        display: flex !important;
        flex-direction: column !important;
    }
    
    /* Xử lý cho cầu vị trí trên mobile */
    #bridges-container {
        display: flex !important;
        flex-direction: row !important;
        overflow-x: auto !important;
        gap: 20px;
        padding-bottom: 10px;
    }
    
    .bridge-card {
        flex: 0 0 320px !important;
        margin-bottom: 0 !important;
    }
    
    .bridge-results-flow {
        flex-direction: column !important;
        overflow-x: visible !important;
    }
    
    /* Xử lý cho tab cài đặt trên mobile */
    .settings-tabs {
        flex-direction: column !important;
        gap: 10px !important;
    }
    
    .user-form > div {
        grid-template-columns: 1fr !important;
    }
    
    .user-list-container {
        overflow-x: auto !important;
    }
    
    .result-box {
        flex: 1 1 auto !important;
        width: 100% !important;
        margin-bottom: 10px;
    }
    
    .result-card {
        padding: 20px;
    }
    
    .numbers-display {
        gap: 10px;
        flex-wrap: wrap;
    }
    
    .numbers-display .num {
        font-size: 52px;
        min-width: 78px;
        min-height: 74px;
    }
    
    .de-stats {
        flex-direction: column;
        gap: 10px;
    }
    
    .de-lists {
        display: flex !important;
        flex-direction: column !important;
        gap: 20px;
    }
    
    .terminal-body {
        font-size: 0.8rem;
        padding: 1rem;
    }
}

/* Utilities */
.text-success { color: #4CAF50 !important; }
.text-danger { color: #f44336 !important; }

/* History Win Badge */
.win-badge {
    background-color: #4CAF50;
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: bold;
    display: inline-block;
    margin: 0 2px;
}

/* History Summary */
.summary-stats {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 15px 20px;
}
.summary-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 15px;
    color: var(--primary);
}
.summary-grid {
    display: flex;
    gap: 30px;
}
.stat-box {
    display: flex;
    flex-direction: column;
    gap: 5px;
}
.stat-label {
    font-size: 13px;
    color: var(--text-muted);
}
.stat-value {
    font-size: 18px;
    font-weight: bold;
}

.backtest-panel {
    margin-bottom: 20px;
    padding: 18px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.025);
}

.backtest-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.backtest-kicker {
    color: var(--primary);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
}

.backtest-header h3 {
    margin: 3px 0 0;
    color: #fff;
    font-size: 18px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.icon-btn-small {
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: #ffffff;
    color: var(--primary);
    cursor: pointer;
    font-size: 13px;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08);
}

.icon-btn-small:hover {
    background: #fff1f2;
    border-color: rgba(225, 29, 72, 0.35);
}

.backtest-meta {
    color: var(--text-muted);
    font-size: 13px;
    margin-bottom: 14px;
}

.backtest-score-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 15px;
}

.backtest-info-modal-content {
    max-width: 900px;
}

.backtest-info-modal-content .backtest-score-card {
    background: #fff;
    border-color: var(--border);
}

.backtest-detail-button {
    margin-bottom: 14px;
}

.backtest-modal-table-wrap {
    max-height: 60vh;
    overflow: auto;
}

.backtest-score-card {
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    padding: 14px;
    background: rgba(0, 0, 0, 0.18);
}

.backtest-score-title {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    color: #fff;
    font-weight: 700;
    margin-bottom: 10px;
}

.backtest-score-badge {
    color: #0f172a;
    background: var(--primary);
    border-radius: 999px;
    padding: 2px 8px;
    font-size: 12px;
    white-space: nowrap;
}

.backtest-metric-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.backtest-metric {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.backtest-metric span {
    color: var(--text-muted);
    font-size: 11px;
}

.backtest-metric strong {
    color: #fff;
    font-size: 15px;
}

.backtest-positive {
    color: #10b981 !important;
}

.backtest-negative {
    color: #ef4444 !important;
}

.backtest-detail-wrap {
    max-height: 360px;
    overflow: auto;
}

@media (max-width: 1100px) {
    .backtest-score-grid {
        grid-template-columns: 1fr;
    }
}

/* Confidence Badges */
.conf-badge {
  display: inline-block;
  margin-top: 10px;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.85em;
  font-weight: 600;
  margin-left: 10px;
}
.conf-high { background-color: rgba(16, 185, 129, 0.1); color: #10b981; }
.conf-med { background-color: rgba(245, 158, 11, 0.1); color: #f59e0b; }
.conf-low { background-color: rgba(239, 68, 68, 0.1); color: #ef4444; }


/* Lock Screen */
.lock-screen {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(10, 10, 15, 0.95);
  backdrop-filter: blur(10px);
  z-index: 9999;
  display: flex;
  justify-content: center;
  align-items: center;
  text-align: center;
}
.lock-screen.hidden {
  display: none;
}
.lock-content {
  background: var(--card-bg);
  padding: 40px;
  border-radius: 20px;
  border: 1px solid var(--border);
  max-width: 500px;
}
.lock-content h2 {
  color: #ef4444;
  margin-bottom: 10px;
}
.lock-content p {
  color: #aaa;
  line-height: 1.5;
}

/* AI Advisor Animations */
@keyframes pulse-glow {
  0% { box-shadow: 0 0 10px rgba(0, 255, 157, 0.4); transform: scale(1); }
  50% { box-shadow: 0 0 25px rgba(0, 255, 157, 0.8); transform: scale(1.05); }
  100% { box-shadow: 0 0 10px rgba(0, 255, 157, 0.4); transform: scale(1); }
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

/* --- MA TRẬN LÔ TÔ THÁNG --- */
.matrix-container-scroll {
    width: 100%;
    overflow-x: auto;
    overflow-y: auto;
    max-height: 70vh;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #ffffff;
    scrollbar-width: thin;
}

@media (max-width: 768px) {
    .matrix-container-scroll {
        max-height: 50vh; /* Giảm chiều cao trên mobile để dễ cuộn trang */
    }
}

.matrix-table {
    border-collapse: collapse;
    width: max-content;
    font-size: 13px;
    text-align: center;
}

.matrix-table th, .matrix-table td {
    border: 1px solid var(--border);
    padding: 6px;
    min-width: 35px;
    height: 40px;
}

/* Sticky Headers */
.matrix-table thead {
    position: sticky;
    top: 0;
    z-index: 10;
}

.matrix-table thead tr:nth-child(1) th {
    background: #fdf2f8;
    color: #be123c;
    font-weight: bold;
    font-size: 11px;
}

.matrix-table thead tr:nth-child(2) th {
    background: #fff1f2;
    color: #e11d48;
    font-weight: bold;
}

.matrix-table thead tr:nth-child(3) th {
    background: #ffe4e6;
    color: #9f1239;
    font-weight: bold;
    font-size: 14px;
}

/* Sticky first column */
.matrix-table th.sticky-col,
.matrix-table td.sticky-col {
    position: sticky;
    left: 0;
    width: 40px;
    min-width: 40px;
    background: #ffffff;
    z-index: 5;
    font-weight: bold;
    color: #475569;
    border-right: 1px solid var(--border);
}

.matrix-table th.sticky-col-2,
.matrix-table td.sticky-col-2 {
    position: sticky;
    left: 40px;
    width: 60px;
    min-width: 60px;
    background: #ffffff;
    z-index: 5;
    font-weight: bold;
    color: #0284c7;
    border-right: 1px solid var(--border);
}

.matrix-table th.sticky-col-3,
.matrix-table td.sticky-col-3 {
    position: sticky;
    left: 100px;
    width: 45px;
    min-width: 45px;
    background: #ffffff;
    z-index: 5;
    font-weight: bold;
    color: #ef4444;
    border-right: 2px solid var(--border);
}

.matrix-table thead th.sticky-col,
.matrix-table thead th.sticky-col-2,
.matrix-table thead th.sticky-col-3 {
    z-index: 15; /* Top left corner needs highest z-index */
    background: #ffe4e6;
}

/* AI Matrix Highlight */
@keyframes ai-glow-border {
  0% { box-shadow: inset 0 0 5px #eab308; background: rgba(234, 179, 8, 0.05); color: #b45309; }
  50% { box-shadow: inset 0 0 20px #eab308; background: rgba(234, 179, 8, 0.25); color: #713f12; }
  100% { box-shadow: inset 0 0 5px #eab308; background: rgba(234, 179, 8, 0.05); color: #b45309; }
}

tr.ai-highlight td {
    animation: ai-glow-border 2s infinite;
    border-top: 1px solid #eab308 !important;
    border-bottom: 1px solid #eab308 !important;
}

/* Cell Types */
.matrix-cell {
    color: #94a3b8; /* Empty or 0 hits */
}

.matrix-cell.count-1 {
    color: #1e293b; /* 1 hit */
}

.matrix-cell.count-2 {
    color: #059669;
    font-weight: bold;
    background: rgba(5, 150, 105, 0.05);
}

.matrix-cell.count-3-plus {
    color: #2563eb;
    font-weight: bold;
    background: rgba(37, 99, 235, 0.05);
}

.matrix-cell.is-special {
    background: #ef4444 !important;
    color: #fff !important;
    font-weight: bold;
}

.matrix-multiplier {
    display: block;
    font-size: 9px;
    opacity: 0.8;
    margin-top: -2px;
}

/* Matrix Summary */
.matrix-summary-panel {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-top: 20px;
}
.summary-card {
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 15px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.02);
}
.summary-card h3 {
    margin: 0 0 10px 0;
    font-size: 14px;
    color: var(--text-muted);
    text-transform: uppercase;
}
.summary-card .big-stat {
    font-size: 24px;
    font-weight: bold;
    color: var(--primary);
    margin-bottom: 5px;
}
.summary-card .small-stat {
    font-size: 13px;
    color: #475569;
}
.summary-card .gan-list {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}
.summary-card .gan-badge {
    background: #fee2e2;
    color: #b91c1c;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: bold;
}
.matrix-cam-row {
    background: #f8fafc;
}
.matrix-cam-row td {
    color: #0f172a !important;
    font-size: 11px;
    font-weight: bold;
}

/* Light theme polish */
.topbar {
    background: rgba(255, 255, 255, 0.88);
}

.sidebar {
    box-shadow: 8px 0 30px rgba(15, 23, 42, 0.04);
}

.nav-item:hover, .nav-item.active {
    background: #fff1f3;
    color: var(--accent);
}

.result-card,
.settings-card,
.strategy-card,
.summary-stats,
.backtest-panel,
.backtest-score-card,
.list-group {
    box-shadow: 0 14px 34px rgba(15, 23, 42, 0.06);
}

.history-table {
    background: #ffffff;
    color: var(--text-main);
}

.history-table th {
    background: #f1f5f9;
    color: #334155;
}

.history-table td {
    background: #ffffff;
    color: var(--text-main);
    border-color: var(--border);
}

.form-control,
input,
select,
textarea {
    background: #ffffff !important;
    color: var(--text-main) !important;
    border-color: var(--border) !important;
}

.toast {
    background: #ffffff;
    color: var(--text-main);
    box-shadow: 0 18px 40px rgba(15, 23, 42, 0.14);
}

.modal-overlay {
    background: rgba(15, 23, 42, 0.32);
}

.modal-content,
.terminal-window {
    background: #ffffff;
    color: var(--text-main);
    border-color: var(--border);
}

.terminal-body {
    background: #f8fafc;
    color: #334155;
}

.matrix-container-scroll {
    background: #ffffff;
    border-color: var(--border);
    scrollbar-color: #cbd5e1 #f8fafc;
}

.matrix-table th,
.matrix-table td {
    border-color: #e2e8f0;
}

.matrix-table thead tr:nth-child(1) th,
.matrix-table thead tr:nth-child(2) th {
    background: #f1f5f9;
    color: #334155;
}

.matrix-table thead tr:nth-child(3) th {
    background: #fff1f3;
    color: var(--accent);
}

.matrix-table th.sticky-col,
.matrix-table td.sticky-col {
    background: #f8fafc;
    color: #475569;
    border-right-color: #cbd5e1;
}

.matrix-cell {
    color: #94a3b8;
}

.matrix-cell.count-1 {
    color: #172033;
    background: #f8fafc;
}

.matrix-cell.count-2 {
    color: #047857;
    background: #ecfdf5;
}

.matrix-cell.count-3-plus {
    color: #0369a1;
    background: #eff6ff;
}

.reason-text {
    color: #475569;
}

/* Contrast fixes for legacy inline dark-theme styles */
.app-container [style*="color: #fff"],
.app-container [style*="color:#fff"],
.app-container [style*="color: white"],
.app-container [style*="color:white"],
.app-container [style*="color: #ffffff"],
.app-container [style*="color:#ffffff"] {
    color: var(--text-main) !important;
}

.app-container [style*="color: #aaa"],
.app-container [style*="color:#aaa"],
.app-container [style*="color: #94a3b8"],
.app-container [style*="color:#94a3b8"] {
    color: var(--text-muted) !important;
}

.app-container [style*="background: rgba(255,255,255"],
.app-container [style*="background: rgba(255, 255, 255"] {
    background: #f8fafc !important;
}

.app-container [style*="background: rgba(0,0,0"],
.app-container [style*="background: rgba(0, 0, 0"] {
    background: #f8fafc !important;
}

.btn-primary,
.btn-danger,
.win-badge,
.matrix-cell.is-special,
#password-modal-confirm {
    color: #ffffff !important;
}

.lo-card h3,
.lo-card .fa-crown {
    color: #b7791f !important;
}

.lo-khung-card h3,
.lo-khung-card .fa-shield-halved,
.btn-copy-section,
.xien-section h4,
#user-remaining-days {
    color: var(--accent) !important;
}

.backtest-header h3,
.backtest-score-title,
.backtest-metric strong,
.strategy-card h3,
.settings-card h3,
.modal-content h3,
.modal-content h4 {
    color: var(--text-main) !important;
}

.backtest-panel,
.backtest-score-card,
.strategy-card,
.settings-card,
.user-form,
.list-group {
    background: #ffffff !important;
    color: var(--text-main) !important;
    border-color: var(--border) !important;
}

.conf-badge,
.backtest-score-badge,
.matrix-cell.is-special span {
    color: inherit !important;
}

.bridges-grid-3 {
    display: grid;
    grid-template-columns: repeat(3, minmax(280px, 1fr));
    gap: 15px;
    align-items: start;
    overflow-x: auto;
    padding-bottom: 10px;
}

.bridge-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.6);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    backdrop-filter: blur(4px);
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
}
.bridge-modal-overlay.active {
    opacity: 1;
    visibility: visible;
}
.bridge-modal-content {
    background: #fff;
    border-radius: 12px;
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1), 0 10px 10px -5px rgba(0,0,0,0.04);
    transform: translateY(20px);
    transition: all 0.3s ease;
}
.bridge-modal-overlay.active .bridge-modal-content {
    transform: translateY(0);
}
.bridge-modal-header {
    padding: 15px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f8fafc;
    border-radius: 12px 12px 0 0;
}
.bridge-modal-close {
    cursor: pointer;
    background: #e2e8f0;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #475569;
    transition: background 0.2s;
}
.bridge-modal-close:hover {
    background: #cbd5e1;
}
.bridge-modal-body {
    padding: 20px;
    overflow-y: auto;
}

/* Hacker Matrix Modal */
#matrix-sync-modal.hidden {
    display: none !important;
}
.matrix-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.95);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
}
.matrix-canvas {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    z-index: 1;
}
.matrix-content {
    position: relative;
    z-index: 2;
    background: rgba(10, 10, 10, 0.85);
    border: 1px solid #22c55e;
    padding: 30px;
    border-radius: 8px;
    box-shadow: 0 0 20px rgba(34, 197, 94, 0.3);
    text-align: center;
    max-width: 500px;
    width: 90%;
    color: #22c55e;
    font-family: 'Courier New', Courier, monospace;
}
.matrix-content h2 {
    color: #22c55e !important;
    margin-top: 15px;
    font-size: 1.2rem;
    text-shadow: 0 0 5px #22c55e;
}
.hacker-text {
    text-align: left;
    margin-top: 20px;
    font-size: 0.9rem;
    line-height: 1.5;
    height: 120px;
    overflow-y: hidden;
    color: #4ade80;
}
.pulse {
    animation: pulse 1.5s infinite;
}
@keyframes pulse {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.1); opacity: 0.7; }
    100% { transform: scale(1); opacity: 1; }
}

/* ═══════════════════════════════════════════
   AI STRATEGY LAB OS - Giao diện Sáng
   ═══════════════════════════════════════════ */

/* The view-section takes full available space */
.lab-os-view {
  padding: 0 !important;
  margin: 0 !important;
  overflow: hidden;
}

#lab-desktop {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: calc(100vh - 0px);
  background: linear-gradient(135deg, #e8f5e9 0%, #f0faf5 40%, #e3f2fd 100%);
  overflow: hidden;
  font-family: 'Inter', sans-serif;
}

#lab-bg-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
  opacity: 0.4;
}

/* Thanh trạng thái trên cùng */
#lab-statusbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 40px;
  background: rgba(255,255,255,0.92);
  border-bottom: 1px solid rgba(16,185,129,0.25);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 1000;
  backdrop-filter: blur(12px);
  box-shadow: 0 1px 8px rgba(0,0,0,0.08);
}

/* Thanh taskbar dưới cùng */
#lab-taskbar {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 46px;
  background: rgba(255,255,255,0.92);
  border-top: 1px solid rgba(16,185,129,0.2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  z-index: 1000;
  backdrop-filter: blur(12px);
  box-shadow: 0 -1px 8px rgba(0,0,0,0.06);
  gap: 8px;
}
#lab-taskbar-apps { display: flex; gap: 6px; }
.lab-task-btn {
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  color: #64748b;
  border-radius: 6px;
  padding: 5px 14px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.lab-task-btn.active {
  background: rgba(16,185,129,0.12);
  border-color: rgba(16,185,129,0.5);
  color: #059669;
}
.lab-task-btn:hover { background: #e2e8f0; border-color: #10b981; color: #059669; }

/* Icon desktop */
#lab-desktop-icons {
  position: absolute;
  top: 50px;
  left: 12px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  z-index: 1;
}
.lab-desktop-icon {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  padding: 8px;
  border-radius: 10px;
  transition: background 0.15s;
  width: 72px;
}
.lab-desktop-icon:hover { background: rgba(16,185,129,0.12); }
.lab-desktop-icon .lab-icon-img {
  font-size: 28px;
  width: 52px; height: 52px;
  background: white;
  border: 1px solid rgba(16,185,129,0.3);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
  transition: transform 0.15s, box-shadow 0.15s;
}
.lab-desktop-icon:hover .lab-icon-img {
  transform: scale(1.08);
  box-shadow: 0 6px 20px rgba(16,185,129,0.2);
}
.lab-desktop-icon span {
  font-size: 10px;
  color: #374151;
  text-align: center;
  line-height: 1.2;
  font-weight: 600;
}

/* Cửa sổ OS */
.lab-window {
  position: absolute;
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 8px 30px rgba(0,0,0,0.12), 0 2px 8px rgba(0,0,0,0.06);
  min-width: 280px;
  min-height: 42px;
  z-index: 100;
  transition: box-shadow 0.15s;
}
.lab-window:focus-within {
  box-shadow: 0 12px 40px rgba(0,0,0,0.15), 0 0 0 2px rgba(16,185,129,0.3);
}

.lab-win-titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  height: 36px;
  background: linear-gradient(135deg, #f0fdf4, #ecfdf5);
  border-bottom: 1px solid #d1fae5;
  cursor: move;
  user-select: none;
  font-size: 13px;
  font-weight: 700;
  color: #065f46;
  flex-shrink: 0;
}
.lab-win-controls { display: flex; gap: 4px; }
.lab-win-controls button {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  font-size: 10px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: filter 0.1s;
}
.lab-win-close { background: #ef4444; color: transparent; }
.lab-win-close:hover { color: white; filter: brightness(1.1); }
.lab-win-min { background: #f59e0b; color: transparent; }
.lab-win-min:hover { color: #78350f; }
.lab-win-max { background: #10b981; color: transparent; }
.lab-win-max:hover { color: white; }

.lab-win-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: white;
  scrollbar-width: thin;
  scrollbar-color: rgba(16,185,129,0.3) transparent;
}

/* Nhãn form */
.lab-label {
  font-size: 11px;
  color: #6b7280;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  display: block;
  margin-bottom: 6px;
}
.lab-field { display: flex; flex-direction: column; }
.lab-select, .lab-input {
  width: 100%;
  background: #f8fafc;
  color: #1e293b;
  border: 1.5px solid #e2e8f0;
  border-radius: 7px;
  padding: 9px 10px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.lab-select:focus, .lab-input:focus {
  border-color: #10b981;
  box-shadow: 0 0 0 3px rgba(16,185,129,0.1);
}

.lab-type-btn, .lab-days-btn {
  background: #f1f5f9;
  border: 1.5px solid #e2e8f0;
  color: #64748b;
  border-radius: 7px;
  padding: 8px 6px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
}
.lab-type-btn.active, .lab-days-btn.active {
  background: #d1fae5;
  border-color: #10b981;
  color: #065f46;
}
.lab-type-btn:hover, .lab-days-btn:hover { border-color: #10b981; color: #059669; background: #ecfdf5; }

.lab-run-btn {
  background: linear-gradient(135deg, #10b981, #059669);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 12px;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 4px 14px rgba(16,185,129,0.35);
  transition: all 0.2s;
  margin-top: 4px;
}
.lab-run-btn:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(16,185,129,0.45); }
.lab-run-btn:disabled { opacity: 0.6; transform: none; cursor: wait; }

.lab-kpi {
  background: #f8fafc;
  border: 1.5px solid #e2e8f0;
  border-radius: 10px;
  padding: 10px 8px;
  text-align: center;
}
.lab-kpi-val { font-size: 20px; font-weight: 800; }
.lab-kpi-label { font-size: 10px; color: #6b7280; margin-top: 2px; text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }

.lab-deploy-btn {
  background: linear-gradient(135deg, #7c3aed, #6d28d9);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 10px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
  transition: all 0.2s;
  flex-shrink: 0;
  box-shadow: 0 4px 14px rgba(109,40,217,0.25);
}
.lab-deploy-btn:hover:not(:disabled) { filter: brightness(1.1); transform: translateY(-1px); }
.lab-deploy-btn:disabled { opacity: 0.4; cursor: not-allowed; }


