/* =========================================
   GLOBAL RESET & VARIABLES
========================================= */
*{ margin:0; padding:0; box-sizing:border-box; }

:root {
    --sky-top: #4da6ff;
    --sky-mid: #1e2a35;
    --sky-bot: #0d0d0d;
    --primary: #00d7ff;
    --bg-dark: #1b1b1b;
    --panel-bg: #252526;
}

/* =========================================
   CUSTOM PRO SCROLLBARS (Industrial Design)
========================================= */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: #1e1e1e; }
::-webkit-scrollbar-thumb { background: #444; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--primary); }

/* =========================================
   MAIN APP LAYOUT
========================================= */
html, body {
    width: 100%; height: 100%; overflow: hidden;
    background: var(--bg-dark); color: #e8e8e8; font-family: "Segoe UI", sans-serif;
}

#app {
    display: grid; 
    height: 100dvh; 
    /* 🚀 FIX: 100% zapobiega ucinaniu i pojawianiu się pasków na Windowsie w przeciwieństwie do 100vw */
    width: 100%;
    max-width: 100%;
    overflow: hidden;
    /* 🚀 FIX: minmax(0, 1fr) pozwala na płynne dopasowanie okna w pionie! */
    grid-template-rows: auto 60px minmax(0, 1fr) 100px 26px;
}

/* --- NOWOCZESNY NAGŁÓWEK INŻYNIERSKI (HUD STYLE) --- */
.menubar {
    display: flex;
    flex-direction: column;
    padding: 12px 20px;
    background: #121212;
    border-bottom: 2px solid #333;
    user-select: none;
}

.menubar-top {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 10px;
    /* Efekt "szkła" i ramki */
    padding: 10px;
    border: 1px solid rgba(0, 215, 255, 0.2);
    border-radius: 4px;
    background: linear-gradient(90deg, rgba(0, 215, 255, 0.05) 0%, transparent 100%);
}

.menubar-title {
    font-size: 14px;
    font-weight: 700;
    color: #fff;
    text-transform: uppercase;
    letter-spacing: 1px;
    text-shadow: 0 0 5px rgba(0, 215, 255, 0.5);
}

.menubar-subtitle {
    font-size: 10px;
    color: var(--primary);
    font-weight: bold;
    letter-spacing: 2px;
}

.menubar-divider {
    height: 1px;
    background: linear-gradient(90deg, #333, transparent);
    margin-bottom: 10px;
}

.menubar-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
}

.nav-left, .nav-right {
    display: flex;
    gap: 25px;
}

.nav-item {
    color: #aaa;
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 4px 8px;
    border-radius: 2px;
}

.nav-item:hover {
    color: var(--primary);
    background: rgba(0, 215, 255, 0.1);
    text-shadow: 0 0 8px var(--primary);
}

.help-btn {
    border: 1px solid var(--primary);
    color: var(--primary);
}

.ribbon {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 15px; background: var(--panel-bg); border-bottom: 1px solid #3b3b3b;
    overflow-x: auto; 
    -ms-overflow-style: none;
    scrollbar-width: none;
}
.ribbon::-webkit-scrollbar { display: none; } 

.ribbon button {
    background: #333; color: white; border: 1px solid #555;
    padding: 8px 15px; cursor: pointer; font-size: 13px; border-radius: 2px;
    white-space: nowrap; transition: 0.2s ease;
}
.ribbon button:hover { background: #444; border-color: var(--primary); box-shadow: 0 0 8px rgba(0,215,255,0.4); }
.ribbon .divider { min-width: 1px; height: 30px; background: #555; margin: 0 10px; }

/* --- WORKSPACE (Panels & 3D) --- */
.workspace {
    display: grid; 
    /* 🚀 FIX: minmax(0, 1fr) to serce rozwiązania. Bez tego 1fr NIE SKURCZY SIĘ poniżej rozmiaru canvasu! */
    grid-template-columns: 260px minmax(0, 1fr) 300px; 
    overflow: hidden; 
    position: relative;
    min-width: 0; 
    min-height: 0;
}

.explorer, .properties { background: var(--panel-bg); overflow-y: auto; }
.explorer { border-right: 1px solid #3b3b3b; }
.properties { border-left: 1px solid #3b3b3b; }

/* 🚀 ZMIANA: Usunięcie ciemnego tła z paska, aby zlał się z głównym obszarem paneli */
.panel-header { 
    padding: 10px 15px; 
    background: transparent; /* ZMIENIONO: Było #2d2d30, teraz idealnie zlewa się z tłem aplikacji */
    border-bottom: 1px solid #444; /* Zostawione dla oddzielenia wizualnego */
    font-size: 12px; font-weight: bold; letter-spacing: 1px; color: #aaa;
}

.explorer ul { list-style: none; font-size: 13px; }
.explorer li { padding: 8px 15px; cursor: pointer; border-bottom: 1px solid rgba(255,255,255,.02); transition: 0.1s; }
.explorer li:hover { background: #2a2d2e; }
.explorer li.active { background: #004a77; border-left: 3px solid var(--primary); }

.field { padding: 15px 15px 0 15px; }
.field label { display: block; margin-bottom: 5px; font-size: 11px; color: #aaa; text-transform: uppercase;}
.field input { 
    width: 100%; background: #1e1e1e; border: 1px solid #444; 
    color: #fff; padding: 8px; outline: none; font-family: monospace; transition: 0.2s;
}
.field input:focus { border-color: var(--primary); box-shadow: 0 0 5px rgba(0, 215, 255, 0.3); }
.stats { padding: 15px; margin-top: 15px; border-top: 1px solid #444; font-size: 13px; line-height: 1.8; color: #bbb;}

/* --- VIEWPORT 3D --- */
.viewport { 
    position: relative; overflow: hidden; 
    background: linear-gradient(180deg, var(--sky-top) 0%, var(--sky-mid) 45%, var(--sky-bot) 100%);
    display: flex; flex-direction: column;
    min-width: 0;
    min-height: 0;
}

#webgl-container { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 1; }

#webgl-container canvas {
    width: 100% !important;
    height: 100% !important;
    display: block;
    outline: none;
}

.viewport-top-left, .viewport-bottom-right {
    position: absolute; background: rgba(0, 0, 0, 0.7); 
    border: 1px solid #444; padding: 6px 10px; font-size: 11px; 
    color: #aaa; pointer-events: none; z-index: 2; border-radius: 2px;
}
.viewport-top-left { top: 15px; left: 15px; }
.viewport-bottom-right { bottom: 15px; left: 15px; }

/* --- VIEW CONTROLS --- */
.view-controls {
    position: absolute; top: 15px; right: 15px;
    display: flex; flex-direction: column; gap: 5px;
    background: rgba(0, 0, 0, 0.6); padding: 10px;
    border-radius: 4px; border: 1px solid #444; z-index: 10;
    backdrop-filter: blur(2px);
}
.view-controls button {
    background: #333; color: white; border: 1px solid #555;
    padding: 6px 12px; cursor: pointer; font-size: 10px; font-weight: bold; border-radius: 2px;
    transition: 0.2s;
}
.view-controls button:hover { background: var(--primary); border-color: #fff; color: #000; box-shadow: 0 0 5px var(--primary); }

/* --- SEO & ARTICLES CONTENT (Odwijany Panel Desktop) --- */
.article-overlay {
    position: absolute; 
    top: 0; right: 0; bottom: 0;
    width: 600px;
    max-width: 100%;
    background: rgba(25, 25, 26, 0.75); 
    backdrop-filter: blur(8px); 
    border-left: 1px solid var(--primary);
    z-index: 20;
    padding: 40px; 
    overflow-y: auto; 
    color: #ddd;
    
    transform: translateX(100%); 
    transition: transform 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    display: block; 
}

.article-overlay.active { 
    transform: translateX(0); 
}

.close-article {
    position: absolute; top: 15px; left: 15px;
    cursor: pointer; color: #aaa; font-size: 28px;
    line-height: 1; transition: 0.2s;
}
.close-article:hover { color: #ff4444; text-shadow: 0 0 10px #ff4444; }

.article-overlay article { display: none; }
.article-overlay article.active { display: block; animation: fadeInText 0.4s ease-out; }
.article-overlay h1 { color: var(--primary); margin-bottom: 20px; font-size: 24px; padding-left: 20px;}
.article-overlay h2 { color: #fff; margin: 20px 0 10px 0; font-size: 18px;}
.article-overlay p { line-height: 1.6; margin-bottom: 15px; font-size: 14px; }

@keyframes fadeInText { from { opacity: 0; } to { opacity: 1; } }

/* --- CONSOLE & STATUSBAR --- */
.console { background: #0a0a0a; border-top: 1px solid #333; padding: 10px; overflow-y: auto; }
.console-log { color: #00ff7f; font-family: Consolas, monospace; font-size: 13px; white-space: pre-wrap; line-height: 1.4; }
.statusbar { 
    display: flex; justify-content: space-between; align-items: center; 
    padding: 0 20px; background: #005a9e; color: white; font-size: 12px; font-weight: bold;
    overflow: hidden;
}

/* --- MODAL POMOCY --- */
.modal-overlay {
    display: none; position: fixed; inset: 0; background: rgba(0, 0, 0, 0.85);
    z-index: 9999; justify-content: center; align-items: center; backdrop-filter: blur(5px);
}
.modal-content { background: var(--panel-bg); width: 90%; max-width: 600px; border: 1px solid #444; border-radius: 4px; display: flex; flex-direction: column; box-shadow: 0 0 30px rgba(0,0,0,0.5); }
/* 🚀 ZMIANA dla spójności okien modalnych: */
.modal-header { padding: 15px; background: transparent; border-bottom: 1px solid #444; display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 20px; overflow-y: auto; font-size: 14px; line-height: 1.6; color: #ccc; }
.modal-body h3 { color: var(--primary); margin-bottom: 10px; }
.close-btn { cursor: pointer; color: #fff; font-size: 24px; font-weight: bold; }
.close-btn:hover { color: #ff4444; }

/* =========================================
   📱 MOBILE RESPONSIVENESS (SMARTPHONY)
========================================= */
@media (max-width: 900px) {
    /* Uwolnienie wysokości ekranu */
    html, body { 
        height: auto !important; 
        overflow: visible !important; 
        overflow-y: auto !important; 
    }
    
    #app { 
        display: flex !important;
        flex-direction: column !important;
        height: auto !important; 
        max-height: none !important;
        overflow: visible !important; 
    }
    
    .menubar    { order: 1; }
    .ribbon     { order: 2; }
    .workspace  { order: 3; }
    .console    { order: 4; } 
    .statusbar  { order: 5; } 

    .menubar-title { font-size: 12px; line-height: 1.4; text-shadow: 0 0 5px rgba(0, 215, 255, 0.8); }
    .brand-subtitle { font-size: 10px; }
    
    .menubar-bottom { padding-bottom: 4px; gap: 15px; font-size: 12px; justify-content: flex-start; overflow-x: auto; white-space: nowrap; }
    
    .ribbon {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 6px;
        padding: 10px;
        height: auto;
        white-space: normal;
        flex-shrink: 0;
    }
    
    .ribbon button:nth-child(1) { grid-column: span 2; font-weight: bold; }
    .ribbon button { white-space: normal; height: 100%; min-height: 44px; padding: 5px; }
    .ribbon .divider { display: none; }
    
    .workspace {
        display: flex !important; 
        flex-direction: column !important;
        overflow: visible !important;
        height: auto !important;
        width: 100%;
    }

    /* 🚀 1. Ekran 3D na samej górze (proporcja 4:3) */
    .viewport { 
        order: 1; 
        width: 100% !important; 
        height: auto !important; 
        aspect-ratio: 4 / 3 !important; 
        flex: none !important; 
        min-height: 0 !important;
        border-bottom: 2px solid var(--primary);
        position: relative;
        flex-shrink: 0;
    }

    /* 🚀 2. Nawigacja tuż pod widokiem 3D */
    .explorer { 
        order: 2; 
        border-right: none; 
        border-bottom: 2px solid #3b3b3b; 
        flex-shrink: 0; 
        padding-top: 10px;
        padding-bottom: 25px;
        margin-top: 0;
    }
    
    .properties { 
        order: 3; 
        border-left: none; 
        flex-shrink: 0; 
        padding-bottom: 40px;
        border-bottom: 2px solid #3b3b3b;
    }
    
    .console {
        height: auto !important;
        min-height: 140px !important;
        max-height: 300px !important;
        margin-top: 20px;
        margin-bottom: 5px;
        padding: 12px;
    }
    
    .view-controls { transform: scale(0.85); transform-origin: top right; top: 10px; right: 10px; } 
    .statusbar span.mobile-hide { display: none; }
    
    /* 🚀 3. WYCIĄGNIĘCIE ZAKŁADEK Z WIDOKU 3D NA CAŁY EKRAN PONIŻEJ */
    .article-overlay {
        position: fixed !important; /* Wyrywa panel z okienka 3D! */
        top: auto !important; 
        left: 0 !important; 
        right: 0 !important; 
        bottom: 0 !important;
        width: 100% !important; 
        height: 75dvh !important; /* Panel zajmuje 75% ekranu od dołu */
        background: rgba(25, 25, 26, 0.98) !important; /* Ciemne tło maskujące to, co pod spodem */
        border-top: 3px solid var(--primary) !important;
        border-left: none !important;
        transform: translateY(100%); 
        padding: 70px 20px 20px 20px !important; /* Zwiększony margines na przycisk ZAMKNIJ */
        z-index: 9999 !important; /* Zawsze na wierzchu! */
        box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.8) !important;
    }
    
    .article-overlay.active {
        transform: translateY(0) !important; 
    }
    
    /* 🚀 4. NOWY, NEONOWY PRZYCISK ZAMYKANIA "X" NA TELEFONIE (Zamiast czerwonego wirusa) */
    .close-article {
        top: 15px !important; 
        right: 15px !important;
        left: auto !important;
        font-size: 32px !important;
        /* Kolor X to teraz neonowy błękit */
        color: var(--primary) !important;
        /* Tło jest przezroczyste lub ciemne */
        background: rgba(0, 0, 0, 0.6) !important; 
        border-radius: 50% !important;
        /* Dodana neonowa ramka */
        border: 1px solid var(--primary) !important;
        width: 44px !important; 
        height: 44px !important;
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
        /* MOCNY NEONOWY BLASK (Cyan Glow) */
        box-shadow: 0 0 15px rgba(0, 215, 255, 0.7) !important;
        text-shadow: 0 0 10px var(--primary) !important;
        position: absolute !important;
        z-index: 10000 !important;
        transition: 0.2s ease !important;
    }
    
    .close-article:hover {
        background: rgba(0, 215, 255, 0.2) !important;
        box-shadow: 0 0 25px rgba(0, 215, 255, 0.9) !important;
    }

    .article-overlay h1 { font-size: 22px; }
}

/* =========================================
   POSTER DO ŁADOWANIA MODELU 3D (Zamiast autostartu)
========================================= */
#model-poster {
    position: absolute;
    inset: 0;
    z-index: 5;
    background: radial-gradient(circle at center, var(--sky-mid) 0%, var(--sky-bot) 100%);
    display: flex;
    justify-content: center;
    align-items: center;
}
#model-poster button {
    padding: 15px 30px;
    font-size: 16px;
    background: var(--primary);
    color: #000;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
    box-shadow: 0 0 15px rgba(0, 215, 255, 0.5);
    transition: 0.3s;
}
#model-poster button:hover {
    transform: scale(1.05);
}