/* --- GLOBAL SETUP --- */
:root {
    --p-blue: #00f3ff; 
    --p-orange: #ff7b00; 
    --p-dark: #000000; 
    --p-border: #1f2a38;
    --text-main: #e0f0ff; 
    --glass: rgba(0,0,0,0.5); 
    --mission-red: #ef4444; 
    --mission-green: #22c55e;
    --mission-yellow: #ffd700;
    --cyan: #00e5ff;
    --glass-border: rgba(255, 255, 255, 0.1);
    --safe-area-bottom: env(safe-area-inset-bottom);
}

* { box-sizing: border-box; }

html, body {
    width: 100%; height: 100%; margin: 0; padding: 0; 
    background: #000000; font-family: 'Inter', sans-serif; overflow: hidden; 
}

.intel-ticker {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 35px;
    background: rgba(0, 0, 0, 0.95);
    border-bottom: 1px solid rgba(0, 243, 255, 0.2);
    display: flex;
    align-items: center;
    padding: 0 20px;
    z-index: 9999;
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    color: var(--p-blue);
    backdrop-filter: blur(10px);
    box-shadow: 0 10px 20px rgba(0,0,0,0.5);
}

.ticker-node {
    width: 8px; height: 8px;
    background: var(--p-blue);
    border-radius: 50%;
    box-shadow: 0 0 10px var(--p-blue);
    animation: blink 2s infinite;
    margin-right: 15px;
    flex-shrink: 0;
}

.ticker-time-top {
    color: #666;
    margin-right: 20px;
    flex-shrink: 0;
    border-right: 1px solid #333;
    padding-right: 15px;
    font-weight: 700;
}

.ticker-feed-container {
    flex: 1;
    overflow: hidden;
    position: relative;
    height: 100%;
    display: flex;
    align-items: center;
    mask-image: linear-gradient(90deg, transparent, #000 20px, #000 95%, transparent);
    -webkit-mask-image: linear-gradient(90deg, transparent, #000 20px, #000 95%, transparent);
}

.ticker-text-top {
    color: #fff;
    white-space: nowrap;
    display: inline-block;
    padding-left: 100%; 
    animation: topScroll 12s linear infinite; 
}

@keyframes topScroll { 
    0% { transform: translate3d(0, 0, 0); } 
    100% { transform: translate3d(-100%, 0, 0); } 
}

.liquid-glass {
    background: rgba(10, 10, 10, 0.45) !important;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.08) !important;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.5);
    position: relative;
}

/* --- ADDED MISSING NAV BAR WRAPPER STYLES --- */
.nav-bar-wrapper {
    display: flex;
    flex-wrap: wrap; 
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    min-height: 50px; /* Adjusted scale */
    height: auto !important;
    position: relative; 
    z-index: 999; 
    margin-top: 35px; /* CLEARS THE TOP TICKER BAR */
    background: rgba(0, 0, 0, 0.85); 
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
}

#page1-root {
    font-family: 'Chakra Petch', sans-serif;
    background: radial-gradient(circle at 50% 50%, #1a1a2e 0%, #000000 80%);
    color: var(--text-main); 
    position: fixed; 
    top: 35px; 
    bottom: calc(80px + env(safe-area-inset-bottom)); 
    left: 0; right: 0;
    overflow: hidden; display: flex; flex-direction: column;
}

.v21-app-container { width: 100%; height: 100%; display: flex; flex-direction: column; overflow: hidden; }

.v21-workspace { flex: 1; display: grid; grid-template-columns: 320px 1fr 320px; overflow: hidden; min-height: 0; gap: 0; }

.col-ingest { display: flex; flex-direction: column; height: 100%; overflow: hidden; border-right: 1px solid rgba(255,255,255,0.05); }
.stream-section { flex: 1 1 0px; display: flex; flex-direction: column; border-bottom: 1px solid rgba(255,255,255,0.05); overflow: hidden; min-height: 0;}
.v21-panel-head { padding: 12px 18px; font-weight: 700; font-size: 11px; letter-spacing: 2px; color: #fff; display: flex; justify-content: space-between; align-items: center; background: rgba(255, 255, 255, 0.02); flex-shrink: 0; border-bottom: 1px solid rgba(255,255,255,0.05); text-transform: uppercase; }
.stream-box { flex: 1; overflow-y: auto; padding: 15px; display: flex; flex-direction: column; gap: 8px; }

.stream-item { background: rgba(0,0,0,0.6); border: 1px solid rgba(255,255,255,0.1); padding: 10px; font-size: 10px; display: flex; justify-content: space-between; align-items: center; border-left: 3px solid var(--p-blue); flex-shrink: 0; animation: slideIn 0.3s ease; }

.col-chat { display: flex; flex-direction: column; background: transparent; position: relative; overflow: hidden; height: 100%; min-height: 0; }
.grid-bg { position: absolute; inset: 0; pointer-events: none; z-index: 0; background-image: linear-gradient(rgba(0, 243, 255, 0.03) 1px, transparent 1px), linear-gradient(90deg, rgba(0, 243, 255, 0.03) 1px, transparent 1px); background-size: 40px 40px; }

/* --- FIXED CHAT FEED SCROLLING --- */
.v21-chat-feed { 
    flex: 1; 
    overflow-y: auto; /* ENABLED SCROLLING */
    padding: 20px; 
    display: flex; 
    flex-direction: column; 
    gap: 15px; 
    z-index: 1; 
    min-height: 0; 
    scroll-behavior: smooth; 
    /* Removed Mask that was hiding scrollbars excessively */
}

.v21-chat-input-area { height: 60px; border-top: 1px solid rgba(255,255,255,0.1); background: rgba(0,0,0,0.4); display: flex; align-items: center; padding: 0 20px; z-index: 2; flex-shrink: 0; backdrop-filter: blur(5px); }
.v21-term-input { width: 100%; background: transparent; border: none; outline: none; color: var(--p-blue); font-family: 'JetBrains Mono', monospace; font-size: 14px; }
.v21-term-prompt { color: var(--p-orange); margin-right: 10px; font-weight: bold; font-family: 'JetBrains Mono', monospace; }

/* --- FIXED CHAT BUBBLE WIDTH --- */
.chat-bubble { 
    width: fit-content;
    max-width: 65%; /* CHANGED FROM 85% TO 65% FOR BETTER READABILITY */
    padding: 12px 16px; 
    border-radius: 4px 16px 16px 16px; 
    font-size: 13px; 
    line-height: 1.4; 
    position: relative; 
    box-shadow: 0 4px 15px rgba(0,0,0,0.3); 
    backdrop-filter: blur(5px); 
    border: 1px solid transparent; 
}

.cb-sys { align-self: flex-start; border-color: var(--p-blue); background: rgba(0, 243, 255, 0.08); color: #fff; border-left: 3px solid var(--p-blue); border-radius: 4px 16px 16px 16px; }
.cb-user { align-self: flex-end; border-color: #333; background: rgba(17, 17, 17, 0.8); color: #ccc; border-right: 3px solid #ff7b00; border-radius: 16px 4px 16px 16px; }

.cb-staff { align-self: flex-start; border-color: #0088ff; background: rgba(0, 136, 255, 0.1); color: #bde0ff; border-left: 3px solid #0088ff; }
.cb-staff .cb-meta { color: #0088ff; }

.cb-meta { font-size: 9px; opacity: 0.8; margin-bottom: 6px; display: block; font-weight: 700; color: var(--p-orange); font-family: 'JetBrains Mono', monospace; text-transform: uppercase; letter-spacing: 1px; }

.cb-time { float: right; font-size: 9px; opacity: 1; font-weight: 700; font-family: 'Share Tech Mono'; margin-left: 10px; color: #ffffff; margin-top: 2px; text-shadow: 0 0 5px rgba(255,255,255,0.5); }

.reply-ref {
    display: block;
    font-family: 'Share Tech Mono';
    font-size: 9px;
    color: rgba(255,255,255,0.5);
    background: rgba(0,0,0,0.3);
    padding: 6px 10px;
    border-radius: 4px;
    margin-bottom: 8px;
    border-left: 2px solid var(--p-orange);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.col-stats { padding: 20px; display: flex; flex-direction: column; gap: 15px; border-left: 1px solid rgba(255,255,255,0.05); height: 100%; overflow-y: auto; }
.kpi-card { background: rgba(0,0,0,0.4); border: 1px solid rgba(255,255,255,0.1); padding: 15px; position: relative; flex-shrink: 0; border-left: 4px solid transparent; backdrop-filter: blur(4px); }
.kpi-val { font-size: 28px; font-weight: 700; color: #fff; font-family: 'Chakra Petch', sans-serif; position: relative; z-index: 1; }
.kpi-green { border-left-color: var(--mission-green); } .kpi-green .kpi-val { color: var(--mission-green); }
.kpi-blue { border-left-color: var(--p-blue); } .kpi-blue .kpi-val { color: var(--p-blue); }

.chart-card { height: 140px; background: rgba(0,0,0,0.4); border: 1px solid rgba(255,255,255,0.1); position: relative; overflow: hidden; padding: 10px; display: flex; flex-direction: column; flex-shrink: 0; backdrop-filter: blur(4px); }

/* --- NAVIGATION (FIXED 5-COLUMN LAYOUT) --- */
.bottom-nav {
    position: fixed; bottom: 0; left: 0; width: 100%; height: 90px;
    background: rgba(0,0,0,0.98); backdrop-filter: blur(15px);
    border-top: 1px solid rgba(255,255,255,0.1);
    display: grid; 
    /* 5 Columns: Button | Button | Search | Button | Button */
    /* !IMPORTANT ADDED TO OVERRIDE ANY GHOST STYLES */
    grid-template-columns: 1fr 1fr 80px 1fr 1fr !important;
    align-items: center; justify-items: center;
    z-index: 9999; padding-bottom: env(safe-area-inset-bottom);
}

.nav-group {
    width: 100%; height: 100%; display: flex; 
    align-items: center; justify-content: center; position: relative;
}

.nav-trigger {
    background: none; border: none; color: #666; font-size: 20px;
    display: flex; flex-direction: column; align-items: center; gap: 6px;
    cursor: pointer; transition: 0.3s; width: 100%;
}

.nav-trigger:hover, .nav-trigger.active {
    color: var(--p-orange); text-shadow: 0 0 15px rgba(255, 123, 0, 0.4);
}

.nav-label {
    font-size: 9px; font-weight: 800; font-family: 'Chakra Petch'; 
    text-transform: uppercase; letter-spacing: 0.5px;
}

/* CENTER SEARCH BUTTON */
.center-btn-wrapper {
    position: relative; width: 60px; height: 60px; 
    display: flex; align-items: center; justify-content: center;
    top: -15px; /* Floats slightly above */
}

.center-master-btn {
    width: 50px; height: 50px; border-radius: 50%;
    background: var(--p-orange); border: 3px solid #000; color: #000;
    font-size: 20px; display: flex; align-items: center; justify-content: center;
    cursor: pointer; box-shadow: 0 0 20px rgba(255, 123, 0, 0.4);
    transition: 0.3s;
}

.center-master-btn:hover { transform: scale(1.05); box-shadow: 0 0 30px rgba(255, 123, 0, 0.6); }

/* POP-UP STACKS */
.nav-stack {
    position: absolute; bottom: 85px; left: 50%; transform: translateX(-50%) translateY(20px);
    width: 160px; background: rgba(10, 10, 10, 0.95);
    border: 1px solid rgba(255,255,255,0.1); border-radius: 8px;
    display: flex; flex-direction: column; opacity: 0; pointer-events: none;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 -10px 30px rgba(0,0,0,0.8); z-index: 10000; padding: 5px 0;
}

.nav-stack.active { opacity: 1; pointer-events: auto; transform: translateX(-50%) translateY(0); border-color: var(--p-orange); }

.nav-stack a {
    text-decoration: none; color: #ccc; font-family: 'JetBrains Mono';
    font-size: 10px; padding: 12px 15px; text-align: center;
    border-bottom: 1px solid rgba(255,255,255,0.05); transition: 0.2s;
    text-transform: uppercase; letter-spacing: 1px; display: block;
}
.nav-stack a:hover { background: rgba(255, 123, 0, 0.1); color: #fff; }
.nav-stack a:last-child { border-bottom: none; }
.nav-stack a.active-link { color: var(--p-orange); font-weight: 800; }

/* SEARCH OVERLAY */
.search-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.95); backdrop-filter: blur(10px);
    z-index: 20000; display: none; flex-direction: column; align-items: center; justify-content: center;
}
.search-overlay.active { display: flex; animation: fadeIn 0.2s; }

.search-box {
    display: flex; border-bottom: 2px solid var(--p-orange); width: 80%; max-width: 600px; margin-top: 20px;
}
.search-box input {
    flex: 1; background: none; border: none; color: #fff; font-family: 'Chakra Petch';
    font-size: 24px; padding: 10px; outline: none; text-transform: uppercase;
}
.search-box button { background: none; border: none; color: var(--p-orange); font-size: 24px; cursor: pointer; }
.close-search-btn {
    background: none; border: 1px solid #333; color: #666; 
    width: 40px; height: 40px; border-radius: 50%; font-size: 20px;
    cursor: pointer; transition: 0.2s; display: flex; align-items: center; justify-content: center;
    margin-bottom: 10px;
}
.close-search-btn:hover { border-color: #fff; color: #fff; transform: scale(1.1); }
@keyframes fadeIn { from { opacity:0; } to { opacity:1; } }

@keyframes slideIn { from { opacity: 0; transform: translateX(-20px); } to { opacity: 1; transform: translateX(0); } }

/* --- MOBILE & RESPONSIVE FIXES --- */
@media screen and (max-width: 768px) {
    /* Adjust Navigation Grid for Mobile */
    /* !IMPORTANT ADDED HERE TOO */
    .bottom-nav { grid-template-columns: 1fr 1fr 60px 1fr 1fr !important; }
    .nav-label { font-size: 8px; }
    
    /* Fix HOME Stack (Left Edge) */
    #stack-home {
        left: 5px; transform: translateY(20px); 
        border-radius: 12px 12px 12px 0;
    }
    #stack-home.active { transform: translateY(0); }

    /* Fix CRM Stack (Right Edge) */
    #stack-crm {
        left: auto; right: 5px; transform: translateY(20px); 
        border-radius: 12px 12px 0 12px;
    }
    #stack-crm.active { transform: translateY(0); }
    
    /* COMMS Stack (keep reasonably centered but safe) */
    #stack-comms { width: 140px; }

    .center-master-btn { width: 45px; height: 45px; font-size: 18px; }
}