:root {
    --bg-color: #0b0d11;
    --glass-bg: rgba(23, 25, 35, 0.4);
    --glass-border: rgba(255, 255, 255, 0.08);
    --primary: #6366f1;
    --primary-glow: rgba(99, 102, 241, 0.3);
    --primary-dark: #4f46e5;
    --accent: #f43f5e;
    --accent-glow: rgba(244, 63, 94, 0.3);
    --success: #10b981;
    --success-glow: rgba(16, 185, 129, 0.2);
    --warning: #f59e0b;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --card-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    --sidebar-width: 280px;
}

@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;600;700&family=Fira+Code:wght@400;500&display=swap');

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

body {
    background-color: var(--bg-color);
    background-image:
        radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.15) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(244, 63, 94, 0.1) 0px, transparent 50%);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    display: flex;
}

.glass {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    box-shadow: var(--card-shadow);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.glass:hover {
    box-shadow: 0 12px 40px 0 rgba(0, 0, 0, 0.45);
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    background: rgba(11, 13, 17, 0.98);
    border-right: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    z-index: 1000;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 1.5rem 1.25rem 1rem;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 0 1.25rem;
    scrollbar-width: none;
}

.sidebar-nav::-webkit-scrollbar {
    display: none;
}

.sidebar-footer {
    padding: 1.25rem;
    border-top: 1px solid var(--glass-border);
    background: rgba(0, 0, 0, 0.2);
}

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, #fff 0%, var(--primary) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    text-align: left;
    margin-bottom: 0.5rem;
    letter-spacing: -0.5px;
}

nav ul {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

nav li {
    padding: 0.85rem 1rem;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 500;
    font-size: 0.9rem;
}

nav li:hover {
    background: rgba(255, 255, 255, 0.03);
    color: #fff;
    transform: translateX(4px);
}

nav li.active {
    background: linear-gradient(90deg, var(--primary-dark), var(--primary));
    color: #fff;
    box-shadow: 0 4px 15px var(--primary-glow);
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 2.5rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2.5rem;
    scrollbar-width: thin;
    scrollbar-color: var(--primary) transparent;
}

.main-content::-webkit-scrollbar {
    width: 6px;
}

.main-content::-webkit-scrollbar-thumb {
    background: var(--glass-border);
    border-radius: 10px;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 2rem;
}

.stat-card {
    padding: 1.5rem;
}

.stat-card h3 {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.stat-card .value {
    font-size: 1.5rem;
    font-weight: 700;
}

/* Training Monitor */
.monitor-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1.5rem;
    flex: 1;
}

.graph-container {
    padding: 1.5rem;
    min-height: 400px;
    display: flex;
    flex-direction: column;
}

.graph-container canvas {
    flex: 1;
    width: 100% !important;
    height: 100% !important;
}

.log-container {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    overflow: hidden;
    /* Ensure only internal content scrolls */
    min-height: 0;
    /* Important for flex child scrolling */
}

/* Activity Monitor Styles */
#event-logs,
#ai-logs {
    flex: 1;
    font-family: 'Fira Code', monospace;
    font-size: 0.8rem;
    overflow-y: auto;
    background: #05070a;
    padding: 1rem;
    border-radius: 4px;
    box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
}

.log-entry {
    padding: 0.4rem 0.75rem;
    border-radius: 4px;
    margin-bottom: 2px;
    line-height: 1.4;
    border-left: 2px solid transparent;
    transition: background 0.2s;
}

.log-entry:hover {
    background: rgba(255, 255, 255, 0.03);
}

.log-entry.info {
    color: var(--text-secondary);
    border-left-color: var(--primary);
}

.log-entry.success {
    color: var(--success);
    background: rgba(16, 185, 129, 0.05);
    border-left-color: var(--success);
}

.log-entry.warning {
    color: var(--warning);
    background: rgba(245, 158, 11, 0.05);
    border-left-color: var(--warning);
}

.log-entry.error {
    color: var(--accent);
    background: rgba(244, 63, 94, 0.05);
    border-left-color: var(--accent);
}

.log-timestamp {
    opacity: 0.4;
    margin-right: 0.75rem;
    font-size: 0.7rem;
    user-select: none;
}

.live-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    display: inline-block;
    margin-right: 8px;
    box-shadow: 0 0 10px var(--success-glow);
    animation: livePulse 1.5s infinite;
}

@keyframes livePulse {
    0% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(1.4);
        opacity: 0.5;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Auth Overlay */
#auth-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(8px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.auth-card {
    width: 400px;
    padding: 2.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

input {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    padding: 0.75rem 1rem;
    border-radius: 8px;
    color: white;
    outline: none;
}

button {
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.75rem;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.3s;
}

button:hover {
    opacity: 0.9;
    box-shadow: 0 0 15px var(--primary-glow);
}

.hidden {
    display: none !important;
}

/* AI Management Specifics */
.ai-view-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
}

.scenario-item:hover {
    background: rgba(255, 255, 255, 0.04) !important;
    transform: scale(1.01);
}

#ai-logs {
    font-family: 'Fira Code', 'Courier New', monospace;
    font-size: 0.85rem;
    color: #e2e8f0;
    line-height: 1.6;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    scrollbar-width: thin;
    scrollbar-color: var(--primary) transparent;
}

#ai-logs::-webkit-scrollbar {
    width: 6px;
}

#ai-logs::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: 10px;
}

@keyframes pulse-success {
    0% {
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(16, 185, 129, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
    }
}

.active-pulse {
    animation: pulse-success 2s infinite;
}

/* Topology Overlay Specifics */
#topo-overlay {
    backdrop-filter: blur(24px) !important;
    background: rgba(15, 23, 42, 0.9) !important;
    border: 1px solid rgba(99, 102, 241, 0.2) !important;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6) !important;
    padding: 1.5rem !important;
    border-radius: 16px !important;
    min-width: 220px;
    max-height: 80vh;
    /* Prevent overflow off screen */
    overflow-y: auto;
    /* Enable scrolling */
    animation: slideInRight 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes slideInRight {
    from {
        transform: translateX(20px);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

#topo-node-name {
    font-size: 1.1rem;
    letter-spacing: 0.5px;
    margin-bottom: 0.5rem;
    font-weight: 700;
}

#topo-node-details {
    line-height: 1.6;
}

/* Scrollbar refinement */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary);
}

/* Glow animation for active scenario */
.active-scenario-glow {
    box-shadow: 0 0 20px var(--primary-glow);
    border-color: var(--primary) !important;
}