/* --- VARIABLES --- */
:root {
    --bg-dark: #0b1120;       /* Deepest Background */
    --bg-panel: #112240;      /* Component Background */
    --accent: #64ffda;        /* Brand Cyan */
    --text-main: #e6f1ff;     /* Bright Text */
    --text-muted: #8892b0;    /* Dim Text */
    --border: #233554;        /* Border Color */
    --sidebar-width: 260px;   /* Fixed Width for Sidebar */
}

body {
    margin: 0;
    background-color: var(--bg-dark);
    font-family: 'Inter', sans-serif;
    color: var(--text-main);
    overflow: hidden; /* CRITICAL: Prevent body scroll, we scroll internal areas */
}

/* --- LAYOUT CONTAINER (The Dashboard Structure) --- */
.app-container {
    display: flex;
    height: 100vh; /* Full Viewport Height */
    width: 100vw;
}

/* --- 1. LEFT SIDEBAR (Fixed) --- */
.sidebar {
    width: var(--sidebar-width);
    background: #020c1b;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 0;
    z-index: 10;
    /* Removed: 'position: fixed' and 'left: -300px'. It is now part of the flow. */
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 15px;
}

.brand-text {
    font-family: 'JetBrains Mono', monospace;
    font-weight: bold;
    font-size: 1.1rem;
    color: var(--accent);
    letter-spacing: 1px;
    line-height: 1.2;
}

.lab-nav {
    list-style: none;
    padding: 0;
    margin: 20px 0;
}

.lab-nav li {
    padding: 15px 25px;
    cursor: pointer;
    color: var(--text-muted);
    transition: 0.2s;
    border-left: 3px solid transparent;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    gap: 10px;
}

.lab-nav li:hover, .lab-nav li.active {
    background: rgba(100, 255, 218, 0.05);
    color: var(--accent);
    border-left: 3px solid var(--accent);
}

.lab-nav li i { width: 25px; text-align: center; }

/* --- 2. MAIN CONTENT AREA (Dynamic) --- */
.main-content {
    flex: 1; /* Takes remaining width */
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden; /* Prevent double scrollbars */
}

/* TOP HEADER RIBBON (Inside Main Content) */
.top-header {
    height: 60px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 30px;
    flex-shrink: 0; /* Prevent header from shrinking */
}

.status-badge {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.75rem;
    color: #64ffda;
    background: rgba(100, 255, 218, 0.1);
    padding: 5px 10px;
    border-radius: 4px;
    border: 1px solid rgba(100, 255, 218, 0.3);
}

/* SCROLLABLE CONTENT ZONE */
.content-zone {
    padding: 30px;
    overflow-y: auto; /* This makes ONLY the content scroll */
    height: 100%;
}

/* SECTIONS (Show/Hide Logic) */
.lab-section { display: none; animation: fadeIn 0.3s ease-in-out; }
.active-section { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

/* --- WIDGET STYLES (Cards, Stats, Etc.) --- */
.stats-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px; margin-top: 20px;
}
.stat-box {
    background: var(--bg-panel); border: 1px solid var(--border);
    padding: 20px; border-radius: 6px; text-align: center;
}
.stat-box h3 { font-size: 2.5rem; color: var(--accent); margin: 0; }

/* --- MODEL HUB LAYOUT --- */
.split-interface {
    display: grid; grid-template-columns: 300px 1fr;
    gap: 20px; height: 100%;
}

.model-controls {
    background: var(--bg-panel); border: 1px solid var(--border);
    padding: 20px; border-radius: 6px;
    height: fit-content;
}

.param-select {
    width: 100%; padding: 12px; background: #020c1b; border: 1px solid var(--border);
    color: white; border-radius: 4px; margin-bottom: 20px; font-family: 'JetBrains Mono';
}

/* SPREADSHEET CONTAINER FIXES (Your previous requirements) */
.model-workspace {
    background: var(--bg-panel); border: 1px solid var(--border);
    padding: 20px; border-radius: 6px;
    display: flex; flex-direction: column;
    /* Prevent overflow issues */
    max-width: 100%;
    overflow-x: hidden;
}

.spreadsheet-container {
    background: #fff !important;
    height: 500px !important; /* Made slightly taller for better view */
    width: 100%;
    max-width: 100%;
    overflow: hidden;
    position: relative;
    z-index: 1;
    border-radius: 4px;
}

.workspace-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 15px; border-bottom: 1px solid var(--border); padding-bottom: 10px;
}

.btn-run {
    background: var(--accent); color: #0b1120; border: none;
    padding: 8px 16px; border-radius: 4px; font-weight: bold; cursor: pointer;
    font-family: 'JetBrains Mono'; display: inline-flex; align-items: center; gap: 8px;
}
.btn-run:hover { background: #9effe8; }

.loading-overlay {
    display: none; position: absolute; top:0; left:0; width:100%; height:100%;
    background: rgba(17, 34, 64, 0.95); z-index: 100;
    flex-direction: column; justify-content: center; align-items: center; color: var(--accent);
}

/* --- MOBILE RESPONSIVENESS (Advanced Sticky Engine) --- */
@media (max-width: 768px) {
    /* 1. Global Reset for Mobile */
    .app-container { 
        flex-direction: column; 
        height: auto; 
        overflow: visible; 
    }
    body { 
        overflow: auto; /* Allow normal scrolling */
    } 

    /* 2. Sticky "Double-Decker" Header */
    .sidebar { 
        width: 100%; 
        height: auto; 
        border-right: none; 
        border-bottom: 1px solid var(--border); 
        
        /* THE MAGIC: Keeps nav stuck to top of screen */
        position: sticky; 
        top: 0; 
        z-index: 1000;
        background: rgba(2, 12, 27, 0.95); /* Glass effect */
        backdrop-filter: blur(10px);
    }

    .sidebar-header { 
        padding: 10px 15px;
        justify-content: space-between; /* Keep logo and close button apart */
    }
    
    /* 3. Brand Visibility */
    .brand-text { 
        display: block; /* Keep logo visible on mobile now */
        font-size: 1rem;
    }

    /* 4. Scrollable Pill Menu (Matching Main Landing Page) */
    .lab-nav { 
        display: flex; 
        overflow-x: auto; 
        margin: 0; 
        padding: 10px 15px;
        gap: 10px;
        scrollbar-width: none; /* Hide scrollbar Firefox */
    }
    .lab-nav::-webkit-scrollbar { display: none; } /* Hide scrollbar Chrome */

    .lab-nav li { 
        padding: 8px 16px; 
        font-size: 0.8rem; 
        white-space: nowrap; 
        
        /* Pill Styling */
        background: rgba(255,255,255,0.05);
        border: 1px solid rgba(255,255,255,0.1);
        border-radius: 20px;
        border-left: 1px solid rgba(255,255,255,0.1); /* Override desktop border */
        display: flex;
        align-items: center;
        gap: 8px;
    }
    
    .lab-nav li.active {
        background: var(--accent);
        color: var(--bg-dark);
        border-color: var(--accent);
    }

    /* 5. Content Layout Fixes */
    .main-content { overflow: visible; }
    .content-zone { 
        padding: 20px; 
        height: auto; 
        overflow: visible; 
    }

    .split-interface { grid-template-columns: 1fr; }
    
    /* 6. Registry & Spreadsheet Mobile Fixes */
    .registry-header { display: none; }
    .registry-row { 
        grid-template-columns: 1fr; 
        gap: 10px; 
        text-align: center;
        background: rgba(255,255,255,0.02);
        margin-bottom: 10px;
        border-radius: 6px;
        border: 1px solid var(--border);
    }

    /* --- INSERT YOUR NEW CODE HERE --- */
    .spreadsheet-container {
        height: 400px !important; /* Fixed height for viewing, but width is fluid */
        width: 100%;
        overflow-x: auto; /* Critical: Allows side-scrolling the table data */
        -webkit-overflow-scrolling: touch;
    }
    
    .model-workspace {
        padding: 10px;
        overflow-x: hidden; /* Prevents the whole lab page from shaking */
    }
    /* --------------------------------- */
    
    .deploy-cta { flex-direction: column; text-align: center; gap: 20px; }
    
    /* Ensure modal fits on small screens */
    .modal-box { width: 95%; padding: 20px; max-height: 90vh; overflow-y: auto; }
}

/* --- OVERVIEW REGISTRY STYLES --- */
.registry-container {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 6px;
    margin-top: 20px;
    overflow: hidden;
}

.registry-header {
    display: grid;
    grid-template-columns: 2fr 1.5fr 1fr 100px; /* Name | Author | Date | Status */
    padding: 15px 20px;
    background: rgba(2, 12, 27, 0.5);
    border-bottom: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.registry-row {
    display: grid;
    grid-template-columns: 2fr 1.5fr 1fr 100px;
    padding: 20px;
    border-bottom: 1px solid rgba(35, 53, 84, 0.5);
    align-items: center;
    transition: 0.2s;
    font-size: 0.9rem;
}

.registry-row:last-child { border-bottom: none; }
.registry-row:hover { background: rgba(100, 255, 218, 0.03); }

.model-name { color: var(--text-main); font-weight: 600; display: flex; align-items: center; gap: 10px; }
.model-author { color: var(--accent); font-family: 'JetBrains Mono'; font-size: 0.8rem; }
.model-date { color: var(--text-muted); font-size: 0.85rem; }

/* Status Badges */
.status-pill {
    font-size: 0.7rem; padding: 2px 8px; border-radius: 10px; text-align: center; font-weight: bold;
}
.status-active { background: rgba(100, 255, 218, 0.1); color: var(--accent); border: 1px solid var(--accent); }
.status-beta { background: rgba(255, 200, 100, 0.1); color: #ffc864; border: 1px solid #ffc864; }

/* --- DEPLOYMENT CTA (The Invitation) --- */
.deploy-cta {
    margin-top: 30px;
    padding: 30px;
    background: linear-gradient(145deg, rgba(17, 34, 64, 0.4) 0%, rgba(100, 255, 218, 0.05) 100%);
    border: 1px dashed var(--accent);
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    overflow: hidden;
}

.cta-content h3 { margin: 0 0 10px 0; color: white; font-size: 1.3rem; }
.cta-content p { margin: 0; color: var(--text-muted); max-width: 600px; }

/* Mobile fix for the grid */
@media (max-width: 768px) {
    .registry-header { display: none; } /* Hide headers on mobile */
    .registry-row { grid-template-columns: 1fr; gap: 5px; text-align: center; }
    .deploy-cta { flex-direction: column; text-align: center; gap: 20px; }
}

/* --- MODAL STYLES (New) --- */
.modal-overlay {
    display: none; /* Hidden by default */
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(2, 12, 27, 0.85);
    backdrop-filter: blur(5px);
    z-index: 2000;
    justify-content: center; align-items: center;
    opacity: 0; transition: opacity 0.3s ease;
}

.modal-open { display: flex; opacity: 1; }

.modal-box {
    background: var(--bg-panel);
    border: 1px solid var(--accent);
    border-radius: 8px;
    width: 90%; max-width: 500px;
    padding: 30px;
    position: relative;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    transform: translateY(20px); transition: transform 0.3s ease;
}
.modal-open .modal-box { transform: translateY(0); }

.modal-header { margin-bottom: 20px; border-bottom: 1px solid var(--border); padding-bottom: 10px; }
.modal-header h3 { margin: 0; color: white; }

.form-group { margin-bottom: 15px; }
.form-group label { display: block; color: var(--text-muted); margin-bottom: 5px; font-size: 0.9rem; }
.form-input {
    width: 100%; padding: 10px; background: #020c1b; border: 1px solid var(--border);
    color: white; border-radius: 4px; font-family: 'Inter', sans-serif;
    box-sizing: border-box; /* Fix padding width issue */
}
.form-input:focus { border-color: var(--accent); outline: none; }

.btn-close {
    position: absolute; top: 15px; right: 15px; color: var(--text-muted);
    cursor: pointer; font-size: 1.2rem;
}
.btn-close:hover { color: white; }