:root {
    --bg-base: #0d1117;
    --bg-panel: #161b22;
    --border-color: #30363d;
    --text-main: #c9d1d9;
    --text-muted: #8b949e;
    --accent-blue: #58a6ff;
    --profit-green: #3fb950;
    --loss-red: #f85149;
    --font-stack: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    background-color: var(--bg-base);
    color: var(--text-main);
    font-family: var(--font-stack);
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header & Macro Ribbon */
.top-bar {
    display: flex;
    justify-content: space-between;
    padding: 15px 25px;
    background-color: var(--bg-panel);
    border-bottom: 1px solid var(--border-color);
}

.logo { font-weight: bold; font-size: 1.2rem; color: var(--text-main); }
.logo span { color: var(--accent-blue); }
.timestamp { color: var(--text-muted); font-size: 0.9rem; }

.macro-ribbon {
    display: flex;
    gap: 15px;
    padding: 15px 25px;
    background-color: var(--bg-base);
}

.macro-card {
    flex: 1;
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 15px;
    text-align: center;
}

.macro-card h3 { font-size: 0.9rem; color: var(--text-muted); margin-bottom: 5px; }
.macro-card .value { font-size: 1.2rem; font-weight: bold; }
.bullish { color: var(--profit-green); }
.bearish { color: var(--loss-red); }

/* Main Layout Grid */
.main-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
    padding: 0 25px 25px 25px;
    gap: 20px;
}

.sidebar { width: 350px; display: flex; flex-direction: column; gap: 20px; }
.content { flex: 1; display: flex; flex-direction: column; }

.panel {
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    height: 100%;
}

.panel h2 {
    font-size: 1rem;
    padding: 15px;
    border-bottom: 1px solid var(--border-color);
    background: #1c2128;
    color: var(--accent-blue);
}

.scroll-list, .news-list {
    overflow-y: auto;
    padding: 15px;
}

/* Portfolio Items */
.portfolio-item {
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 10px;
    margin-bottom: 10px;
}
.portfolio-item:last-child { border-bottom: none; }
.port-header { display: flex; justify-content: space-between; font-weight: bold; }
.port-details { font-size: 0.85rem; color: var(--text-muted); margin-top: 5px; }

/* News List */
.news-list { list-style: none; }
.news-list li { margin-bottom: 12px; font-size: 0.9rem; line-height: 1.4; }
.news-list a { color: var(--text-main); text-decoration: none; transition: color 0.2s; }
.news-list a:hover { color: var(--accent-blue); }

/* Table Styling */
.table-responsive { overflow-y: auto; }
table { width: 100%; border-collapse: collapse; text-align: left; }
th, td { padding: 12px 15px; border-bottom: 1px solid var(--border-color); }
th {
    position: sticky;
    top: 0;
    background: #1c2128;
    color: var(--text-muted);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
td { font-size: 0.95rem; }
tr:hover { background-color: #1c2128; }

.tag {
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: bold;
    background: #238636;
    color: white;
}
.tag-risk { background: #b62324; }


/* Kaufman ER Badge Styling */
.er-badge {
    padding: 4px 8px;
    border-radius: 4px;
    font-weight: 700;
    font-size: 0.85em;
    display: inline-block;
    text-align: center;
    min-width: 90px;
}

/* High ER: Smooth, easy to trade (Green) */
.er-high { 
    background-color: rgba(0, 255, 0, 0.1); 
    color: #00ff00; 
    border: 1px solid rgba(0, 255, 0, 0.4);
}

/* Mid ER: Normal market noise (Yellow) */
.er-mid { 
    background-color: rgba(255, 255, 0, 0.1); 
    color: #ffff00; 
    border: 1px solid rgba(255, 255, 0, 0.4);
}

/* Low ER: Violent, choppy, stop-loss hunting (Red/Orange) */
.er-low { 
    background-color: rgba(255, 69, 0, 0.1); 
    color: #ff4500; 
    border: 1px solid rgba(255, 69, 0, 0.4);
}

@keyframes flashWarning {
            0% { background-color: rgba(255, 68, 68, 0.1); border-left: 3px solid #ff4444; }
            50% { background-color: rgba(255, 68, 68, 0.3); border-left: 3px solid #ff0000; box-shadow: 0 0 10px rgba(255,0,0,0.5); }
            100% { background-color: rgba(255, 68, 68, 0.1); border-left: 3px solid #ff4444; }
        }
        .routine-alert {
            animation: flashWarning 1.5s infinite;
        }


/* --- INSTITUTIONAL ROUTINE ALERTS --- */
@keyframes flashWarning {
    0% { border-left-color: #ff4444; background-color: rgba(255, 0, 0, 0.2); }
    50% { border-left-color: transparent; background-color: rgba(0, 0, 0, 0.3); }
    100% { border-left-color: #ff4444; background-color: rgba(255, 0, 0, 0.2); }
}

.routine-alert {
    animation: flashWarning 1.5s infinite;
    border-left: 3px solid #ff4444 !important;
}


/* =========================================
   📱 MOBILE & TABLET RESPONSIVE OVERRIDES
   ========================================= */
@media (max-width: 900px) {
    /* 1. Unlock the Main Desktop Layout */
    .main-layout {
        flex-direction: column !important;
        overflow-y: auto !important; /* Unlocks vertical scrolling */
        padding: 10px !important;
    }
    
    /* 2. Free the Sidebar limits */
    .sidebar {
        width: 100% !important;
    }

    /* 3. Wrap the Top Navigation & P&L Header */
    .top-bar {
        flex-direction: column !important;
        height: auto !important;
        padding: 15px 10px !important;
        align-items: center !important;
        text-align: center;
    }
    #global-pnl-container {
        flex-wrap: wrap !important;
        justify-content: center !important;
        gap: 10px !important;
        margin-top: 10px;
    }
    #global-pnl-container > div[style*="width: 1px"] {
        display: none !important; /* Hides horizontal dividers on mobile */
    }
    
    /* 4. Center & Wrap the Main Buttons Row */
     body > div[style*="align-items: center"] {
        flex-wrap: wrap !important;
        justify-content: center;
    }
    body > div[style*="align-items: center"] > h2 {
        margin-left: 0 !important;
        width: 100%;
        text-align: center;
    }
    #single-ticker-input {
        width: 100% !important;
        margin-bottom: 10px;
    } 

    /* 5. Force ALL Modals to fit the phone screen */
    div[id$="-modal"] > div {
        width: 95% !important;
        height: 95vh !important;
        padding: 15px !important;
        overflow-x: hidden;
        overflow-y: auto;
    }
     
    /* 6. Force ALL Hardcoded Grids to Stack into 1 Column */
    div[style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
        gap: 15px !important;
    } 
    
    /* 7. Stack the Split-Headers inside Modals (ECI / Analytics) */
    div[id$="-modal"] div[style*="justify-content: space-between"] {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 10px !important;
    }
     
    /* 8. Expand Screener Cards to Full Width */
    #screener-grid > div > div > div {
        width: 100% !important;
        max-width: none !important;
    } 

    /* 9. Allow Analytics Table to Scroll Sideways safely */
    .table-wrapper {
        overflow-x: auto !important;
    }
    
    /* 10. Stack the Macro Ribbon Stats */
    #macro-container div[style*="display: flex"] {
        flex-direction: column !important;
        align-items: flex-start !important;
    } 
}