:root {
    --primary: #00f3ff;
    --primary-dim: rgba(0, 243, 255, 0.1);
    --secondary: #ff0055;
    --bg: #050505;
    --surface: #0a0a0a;
    --border: #333;
    --grid-line: rgba(0, 243, 255, 0.05);
    --text: #e0e0e0;
    --text-muted: #888;
    --font-mono: 'JetBrains Mono', monospace;
    --font-title: 'Orbitron', sans-serif;
    --font-ui: 'Rajdhani', sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    scrollbar-width: thin;
    scrollbar-color: var(--primary) var(--surface);
}

body {
    background-color: var(--bg);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 14px;
    height: 100vh;
    overflow: hidden;
    position: relative;
}

/* OVERLAYS */
.scanlines {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        to bottom,
        rgba(255,255,255,0),
        rgba(255,255,255,0) 50%,
        rgba(0,0,0,0.2) 50%,
        rgba(0,0,0,0.2)
    );
    background-size: 100% 4px;
    pointer-events: none;
    z-index: 10;
    animation: scanline 0.2s linear infinite;
    opacity: 0.15;
}

.vignette {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle, transparent 60%, black 100%);
    pointer-events: none;
    z-index: 11;
}

@keyframes scanline {
    0% { transform: translateY(0); }
    100% { transform: translateY(4px); }
}

/* CONTAINER */
.hud-container {
    display: grid;
    grid-template-columns: 260px 1fr;
    height: 100vh;
    position: relative;
    z-index: 5;
}

/* SIDEBAR */
.sidebar {
    background: rgba(10, 10, 10, 0.95);
    border-right: 1px solid var(--border);
    padding: 2rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    backdrop-filter: blur(10px);
}

.logo-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 3rem;
    position: relative;
}

.logo-ring {
    width: 60px;
    height: 60px;
    border: 2px solid var(--primary);
    border-radius: 50%;
    position: absolute;
    top: -10px;
    animation: pulse 2s infinite;
    box-shadow: 0 0 15px var(--primary-dim);
}

.logo-text {
    font-family: var(--font-title);
    font-size: 2rem;
    color: var(--primary);
    letter-spacing: 4px;
    z-index: 2;
    text-shadow: 0 0 10px var(--primary);
    margin-top: 10px;
}

.logo-sub {
    font-size: 0.7rem;
    color: var(--text-muted);
    letter-spacing: 2px;
    margin-top: 0.5rem;
}

@keyframes pulse {
    0% { transform: scale(1); opacity: 0.8; }
    50% { transform: scale(1.1); opacity: 0.4; }
    100% { transform: scale(1); opacity: 0.8; }
}

.nav-links {
    list-style: none;
    flex: 1;
}

.nav-links li {
    padding: 1rem;
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: all 0.3s;
    border-left: 2px solid transparent;
    opacity: 0.6;
    display: flex;
    align-items: center;
    font-family: var(--font-ui);
    font-size: 1.1rem;
    letter-spacing: 1px;
}

.nav-links li:hover {
    background: rgba(255, 255, 255, 0.05);
    opacity: 1;
    padding-left: 1.5rem;
}

.nav-links li.active {
    border-left: 2px solid var(--primary);
    background: linear-gradient(90deg, var(--primary-dim) 0%, transparent 100%);
    opacity: 1;
    color: var(--primary);
    font-weight: bold;
    padding-left: 1.5rem;
    text-shadow: 0 0 5px var(--primary-dim);
}

.nav-icon {
    margin-right: 10px;
    font-size: 1.2rem;
}

.system-status {
    border-top: 1px solid var(--border);
    padding-top: 1.5rem;
}

.status-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.5rem;
    font-size: 0.8rem;
    font-family: var(--font-ui);
}

.status-row .label {
    color: var(--text-muted);
}

.status-row .value {
    color: var(--primary);
    font-weight: bold;
}

.status-row .value.success {
    color: #00ff80;
    text-shadow: 0 0 5px rgba(0, 255, 128, 0.5);
}

/* CONTENT AREA */
.content-area {
    display: flex;
    flex-direction: column;
    padding: 2rem;
    overflow: hidden;
    position: relative;
    background-image: 
        linear-gradient(var(--grid-line) 1px, transparent 1px),
        linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
    background-size: 40px 40px;
}

/* TOP BAR */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    border-bottom: 1px solid var(--border);
    padding-bottom: 1rem;
    font-family: var(--font-title);
    background: rgba(10, 10, 10, 0.8);
    backdrop-filter: blur(5px);
    padding: 1rem;
    border: 1px solid var(--border);
}

.header-left {
    display: flex;
    flex-direction: column;
}

.breadcrumb {
    color: var(--primary);
    font-size: 1rem;
    letter-spacing: 2px;
    text-shadow: 0 0 5px var(--primary-dim);
}

.security-level {
    font-size: 0.6rem;
    color: var(--secondary);
    letter-spacing: 1px;
    margin-top: 0.25rem;
}

.header-center {
    text-align: center;
}

.digital-clock {
    font-size: 2rem;
    color: var(--text);
    letter-spacing: 2px;
    text-shadow: 0 0 10px rgba(255, 255, 255, 0.2);
}

.date-display {
    font-size: 0.8rem;
    color: var(--text-muted);
    letter-spacing: 2px;
}

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

.connection-status {
    font-size: 0.8rem;
    color: #00ff80;
    border: 1px solid rgba(0, 255, 128, 0.3);
    padding: 0.5rem 1rem;
    border-radius: 4px;
    background: rgba(0, 255, 128, 0.05);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.blink {
    animation: blinker 1s linear infinite;
}

@keyframes blinker {
    50% { opacity: 0; }
}

/* VIEW PANELS */
.view-panel {
    display: none;
    height: 100%;
    overflow: hidden;
    flex: 1;
}

.view-panel.active {
    display: block;
    animation: fadeIn 0.5s ease-in-out;
}

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

/* DASHBOARD GRID (Bento Box) */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: 1fr 1.5fr;
    gap: 1.5rem;
    height: 100%;
    padding-bottom: 2rem; /* space for scroll */
}

/* Custom layout logic for specific panels */
.metrics-panel {
    grid-column: 1 / 2;
    grid-row: 1 / 2;
}

.agents-panel {
    grid-column: 2 / 4; /* Span 2 columns */
    grid-row: 1 / 2;
}

.terminal-panel {
    grid-column: 1 / 3; /* Span 2 columns */
    grid-row: 2 / 3;
}

.memory-panel {
    grid-column: 3 / 4;
    grid-row: 2 / 3;
}

/* PANEL STYLES */
.panel {
    background: rgba(18, 18, 18, 0.8);
    border: 1px solid var(--border);
    position: relative;
    backdrop-filter: blur(10px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
}

.panel::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--primary), transparent);
    opacity: 0.5;
}

.panel::after { /* Corner accents */
    content: '';
    position: absolute;
    bottom: 0;
    right: 0;
    width: 20px;
    height: 20px;
    border-bottom: 2px solid var(--primary);
    border-right: 2px solid var(--primary);
}

.panel-header {
    background: rgba(255, 255, 255, 0.03);
    padding: 0.75rem 1rem;
    font-family: var(--font-ui);
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    letter-spacing: 1px;
}

.full-panel {
    height: 100%;
}

/* METRICS CONTENT */
.metrics-content {
    padding: 1rem;
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    gap: 1rem;
    flex: 1;
}

.metric-dial {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.dial-label {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.8rem;
    color: var(--text-muted);
}

.metric-stat {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.05);
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.metric-stat .label {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}

.metric-stat .value {
    font-size: 1.2rem;
    color: var(--primary);
    font-family: var(--font-mono);
}

/* TERMINAL CONTENT */
.terminal-content {
    padding: 1rem;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: #ccc;
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column-reverse; /* New logs at bottom, scroll stays at bottom naturally */
    gap: 0.25rem;
}

.log-entry {
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding: 2px 0;
    display: flex;
    gap: 0.5rem;
}

.log-time {
    color: var(--text-muted);
    min-width: 70px;
}

.log-msg {
    color: var(--text);
}

.log-type-INFO { color: #00f3ff; }
.log-type-WARN { color: #ffaa00; }
.log-type-ERROR { color: #ff0055; }
.log-type-SYSTEM { color: #00ff80; }

/* AGENTS LIST MINI */
.agents-list-mini {
    padding: 1rem;
    overflow-y: auto;
    flex: 1;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1rem;
}

.agent-card-mini {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border);
    padding: 0.75rem;
    font-size: 0.8rem;
    position: relative;
    transition: all 0.3s;
}

.agent-card-mini:hover {
    border-color: var(--primary);
    background: rgba(0, 243, 255, 0.05);
}

.agent-card-mini h3 {
    color: var(--primary);
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.agent-status {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #00ff80;
    box-shadow: 0 0 5px #00ff80;
}

/* TIMELINE FEED MINI */
.timeline-feed-mini {
    padding: 1rem;
    overflow-y: auto;
    flex: 1;
}

.feed-item {
    margin-bottom: 1rem;
    padding-left: 1rem;
    border-left: 2px solid var(--border);
    position: relative;
}

.feed-item::before {
    content: '';
    position: absolute;
    left: -5px;
    top: 0;
    width: 8px;
    height: 8px;
    background: var(--bg);
    border: 1px solid var(--primary);
    border-radius: 50%;
}

.feed-date {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.feed-title {
    color: #fff;
    font-weight: bold;
    font-size: 0.85rem;
    margin: 0.25rem 0;
}

.feed-body {
    font-size: 0.8rem;
    color: #aaa;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* FULL VIEW STYLES */
.network-viz {
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.2);
}

.agents-grid-view, .skills-grid-view, .logs-container {
    padding: 1.5rem;
    overflow-y: auto;
    height: 100%;
    display: grid;
    gap: 1.5rem;
}

.agents-grid-view { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.skills-grid-view { grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }

/* SCROLLBAR */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: var(--surface);
}
::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--primary);
}

/* ACTION BUTTONS */
.action-btn {
    background: rgba(0, 243, 255, 0.1);
    border: 1px solid var(--primary);
    color: var(--primary);
    padding: 1rem;
    font-family: var(--font-ui);
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s;
    text-transform: uppercase;
    letter-spacing: 1px;
    width: 100%;
    text-align: center;
}
.action-btn:hover {
    background: var(--primary);
    color: #000;
    box-shadow: 0 0 15px var(--primary-dim);
}
.action-btn:active {
    transform: scale(0.98);
}

/* CHAT STYLES */
.msg {
    padding: 0.75rem;
    border-radius: 4px;
    font-size: 0.9rem;
    line-height: 1.4;
    max-width: 85%;
    word-wrap: break-word;
}
.msg.system {
    color: var(--secondary);
    font-size: 0.75rem;
    text-align: center;
    max-width: 100%;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    padding-bottom: 0.5rem;
    margin-bottom: 0.5rem;
}
.msg.jarvis {
    background: rgba(0, 243, 255, 0.1);
    border-left: 2px solid var(--primary);
    align-self: flex-start;
    color: var(--text);
}
.msg.user {
    background: rgba(255, 255, 255, 0.1);
    border-right: 2px solid #fff;
    align-self: flex-end;
    text-align: right;
    color: #fff;
}

/* BOTTOM NAV (Mobile Only) */
.bottom-nav {
    display: none; /* Desktop */
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 70px;
    background: rgba(0, 0, 0, 0.95);
    border-top: 1px solid var(--primary);
    backdrop-filter: blur(10px);
    z-index: 9999;
    justify-content: space-around;
    align-items: center;
    box-shadow: 0 -5px 15px rgba(0, 0, 0, 0.5);
}

.bottom-nav .nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    height: 100%;
    color: var(--text-muted);
    font-family: var(--font-ui);
    cursor: pointer;
    transition: all 0.2s;
    border-top: 2px solid transparent;
}

.bottom-nav .nav-item.active {
    color: var(--primary);
    border-top: 2px solid var(--primary);
    background: linear-gradient(to bottom, var(--primary-dim) 0%, transparent 100%);
}

.bottom-nav .nav-icon {
    font-size: 1.5rem;
    margin-bottom: 2px;
}

.bottom-nav .nav-label {
    font-size: 0.7rem;
    letter-spacing: 1px;
}

/* =========================================
   MOBILE RESPONSIVE OVERRIDES (v2.2.0)
   ========================================= */
@media (max-width: 768px) {
    /* 1. Layout Reset & Touch Basics */
    .hud-container {
        display: block; /* Stack layout */
        height: 100vh; /* Viewport height */
        overflow: hidden;
    }
    
    .sidebar {
        display: none !important; /* Hide sidebar completely */
    }

    .bottom-nav {
        display: flex !important; /* Show bottom nav */
    }

    body {
        font-size: 13px; /* Slightly smaller base font */
        overflow: hidden; /* Prevent body scroll, handle in content-area */
    }

    /* 3. Content Area & Header */
    .content-area {
        height: 100vh;
        overflow-y: auto; /* Enable scroll here */
        padding: 1rem;
        padding-bottom: 90px; /* Space for bottom nav */
        padding-top: 60px; /* Space for fixed header/btn */
        -webkit-overflow-scrolling: touch;
    }

    .top-bar {
        position: fixed; /* Sticky top bar for dashboard title */
        top: 0;
        left: 0;
        width: 100%;
        z-index: 1000;
        height: 50px;
        display: flex;
        justify-content: center;
        align-items: center;
        padding: 0 1rem;
        margin: 0;
        background: rgba(0, 0, 0, 0.9);
        border-bottom: 1px solid var(--border);
    }

    .header-left {
        width: auto;
        text-align: center;
        border: none;
        padding: 0;
        margin: 0;
    }
    
    .breadcrumb {
        font-size: 0.9rem;
    }

    .header-center {
        display: none; 
    }

    .header-right {
        display: none; /* Save space */
    }

    /* 4. Dashboard Grid Stacking & Scroll Fixes */
    /* FORCE SINGLE VIEW MODE: Only the active view-panel is shown */
    .view-panel {
        height: calc(100vh - 120px); /* Full height minus header (50px) and nav (70px) */
        overflow-y: auto; /* Scroll internally */
        display: none; /* Hide by default */
        padding-bottom: 20px;
    }

    .view-panel.active {
        display: block; /* Show only active */
    }

    /* Dashboard-specific inner layout */
    .dashboard-grid {
        display: flex;
        flex-direction: column;
        height: auto; 
        min-height: 100%;
        overflow: visible; 
        gap: 1rem;
        padding-top: 10px;
    }

    .panel {
        min-height: auto;
        margin-bottom: 0;
        width: 100%;
        flex-shrink: 0; /* Prevent crushing */
    }

    /* Reset grid positioning for flex layout */
    .metrics-panel, .agents-panel, .terminal-panel, .actions-panel {
        grid-column: auto;
        grid-row: auto;
    }
    
    .terminal-panel {
        order: 99; /* Put terminal at bottom */
        height: 300px !important; /* Fixed height for terminal on mobile dashboard */
    }

    /* 5. Visualization Optimizations & Scrollable Areas */
    .metrics-content {
        padding: 0.5rem;
        gap: 0.5rem;
    }
    
    .metric-dial canvas {
        max-width: 90px;
        max-height: 90px;
    }

    /* FIX SCROLL BLOCKS */
    .terminal-content {
        font-size: 0.75rem; 
        height: 100%; /* Fill the fixed panel height */
        overflow-y: auto; 
    }

    .agents-list-mini {
        display: grid;
        grid-template-columns: 1fr; 
        max-height: 200px;
        overflow-y: auto;
    }
    
    .actions-content {
        max-height: none; /* Let it flow in the flex stack */
        overflow-y: visible;
    }

    /* Full views padding */
    .agents-grid-view, .skills-grid-view, .mission-log-container {
        padding: 0.5rem;
        gap: 1rem;
        overflow-y: auto;
        min-height: 100%;
        display: flex;
        flex-direction: column;
    }
    
    .network-viz {
        touch-action: none;
        height: 100%; 
    }
    
    /* Chat on mobile - Fill available space */
    .chat-container {
        height: 100%;
        display: flex;
        flex-direction: column;
        padding-bottom: 0;
    }
    
    #chat-history {
        flex: 1;
        overflow-y: auto;
        padding-bottom: 1rem;
    }

    /* Fix Particles on Mobile (behind content) */
    .particles canvas {
        z-index: 1;
    }
}

/* MISSION LOG STYLES (Global) */
.mission-log-container {
    padding: 1.5rem;
    overflow-y: auto;
    height: 100%;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.mission-item {
    background: rgba(255, 255, 255, 0.05);
    border-left: 3px solid var(--primary);
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    position: relative;
    transition: all 0.3s;
}

.mission-item:hover {
    background: rgba(255, 255, 255, 0.08);
    transform: translateX(5px);
}

.mission-time {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
    letter-spacing: 1px;
}

.mission-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
}

.mission-title {
    font-family: var(--font-ui);
    font-weight: bold;
    font-size: 1rem;
    line-height: 1.2;
}

.mission-type {
    font-size: 0.6rem;
    background: rgba(255, 255, 255, 0.1);
    padding: 2px 6px;
    border-radius: 2px;
    white-space: nowrap;
    border: 1px solid rgba(255,255,255,0.1);
}

.mission-desc {
    font-size: 0.85rem;
    color: #ccc;
    line-height: 1.4;
}

.mission-status {
    font-size: 0.7rem;
    font-weight: bold;
    text-align: right;
    margin-top: 0.25rem;
    letter-spacing: 1px;
}
