/* ==========================================================================
   DEVELOPER TYPOGRAPHY & CORE RESET
   ========================================================================== */
@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;700&display=swap');

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body {
    display: flex;
    flex-direction: column;
    height: 100vh; 
    background-color: #f4f8fa; 
    color: #333;
    overflow: hidden;
}

/* ==========================================================================
   LAYOUT STRUCTURE COMPONENTS
   ========================================================================== */
header {
    background-color: #34495e; 
    padding: 6px 20px; 
    text-align: center;
    flex-shrink: 0;
}

header h1 {
    font-size: 1.1rem; 
    color: #ffffff; 
}

nav {
    display: flex;
    background-color: #34495e; 
    border-bottom: 2px solid #e6f0fa;
    justify-content: center;
    flex-shrink: 0;
}

.menu-item {
    padding: 8px 25px; 
    color: #ecf0f1; 
    text-decoration: none;
    font-weight: 500;
    font-size: 0.95rem;
    transition: all 0.2s ease;
}

.menu-item:hover, .menu-item.active {
    background-color: #1abc9c; 
    color: #ffffff;
}

.sub-nav-bar {
    background-color: #eaeff2;
    border-bottom: 1px solid #cfe2f3;
    padding: 5px 20px;
    height: 40px;
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.shell-btn-group {
    display: flex;
    gap: 6px;
    align-items: center;
}

.mini-btn-shell {
    background: transparent;
    border: none;
    color: #4a6b82;
    padding: 4px 10px;
    cursor: pointer;
    font-size: 0.95rem;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.mini-btn-shell:hover {
    background-color: #d0e4f7;
}

.mini-btn-shell.btn-run {
    background: #1a446c;
    color: #ffffff;
    font-weight: bold;
}

.mini-btn-shell.btn-run:disabled {
    background-color: #cccccc !important;
    cursor: not-allowed;
    opacity: 0.6;
}

.divider {
    width: 1px;
    height: 20px;
    background-color: #bdc3c7;
    margin: 0 8px;
}

#mode-label {
    font-size: 0.8rem;
    font-weight: bold;
    color: #4a6b82;
    white-space: nowrap;
}

#mode-selector {
    min-width: 180px;
    padding: 3px 8px;
    font-size: 0.85rem;
    border: 1px solid #cfe2f3;
    border-radius: 4px;
    background: white;
    outline: none;
    cursor: pointer;
    color: #333;
}

/* ==========================================================================
   WORKSPACE CONTENT & CORE SYSTEM
   ========================================================================== */
.main-container {
    display: flex;
    flex: 1;
    overflow: hidden;
    position: relative;
}

.workspace-wrapper {
    display: flex;
    width: 100%;
    height: 100%;
    flex: 1;
}

.sidebar {
    background-color: #ffffff;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    flex: 0 0 30%; /* Thiết lập mặc định phần nhập code là 30% */
}

.main-content {
    flex: 1;
    background-color: #ffffff;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.resizer {
    width: 4px;                      
    cursor: col-resize;
    background-color: #cfe2f3;      
    flex-shrink: 0;
    transition: background-color 0.2s;
}

.resizer:hover {
    background-color: #1abc9c;
}

/* Cấu hình bộ chữ JetBrains Mono cho toàn vùng Terminal & CodeMirror */
:root {
    --workspace-font: 'JetBrains Mono', monospace;
    --workspace-font-size: 13px;
}

.CodeMirror {
    flex: 1;
    height: 100% !important;
}

.CodeMirror, .CodeMirror * {
    font-family: var(--workspace-font) !important;
    font-size: var(--workspace-font-size) !important;
}

#unified-container {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    background: #fcfcfd;
}

#output {
    padding: 12px;
    font-family: var(--workspace-font);
    font-size: var(--workspace-font-size);
    white-space: pre-wrap;
    border-bottom: 1px solid #cfe2f3;
}

#plot {
    background: #ffffff;
    padding: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
}

#plot img {
    max-width: 100%;
    height: auto;
    object-fit: contain;
}

#statusText {
    font-family: var(--workspace-font);
    font-size: 0.75rem;
    color: #5c7b93;
    padding: 5px 12px;
    background: #fafbfd;
    border-top: 1px solid #cfe2f3;
    text-align: right;
    flex-shrink: 0;
}

/* ==========================================================================
   DOCUMENTATION PAGE CONTENT
   ========================================================================== */
.page-content {
    padding: 30px;
    overflow-y: auto;
    width: 100%;
    height: 100%;
    background: #ffffff;
}

.page-content h2 {
    color: #1a446c;
    margin-bottom: 15px;
}

.docs-list {
    margin-top: 15px;
    padding-left: 20px;
}

.docs-list li {
    margin-bottom: 10px;
}

.docs-list a {
    color: #16a085;
    text-decoration: none;
    font-weight: 500;
}

.docs-list a:hover {
    text-decoration: underline;
}

footer {
    background-color: #34495e; 
    text-align: center;
    padding: 6px; 
    font-size: 0.8rem;
    color: #bdc3c7; 
    border-top: 1px solid #cfe2f3;
    flex-shrink: 0;
}

/* ==========================================================================
   DYNAMIC CSS PRINT TARGET SYSTEM (@media print)
   ========================================================================== */
@media print {
    body * { visibility: hidden; height: auto !important; }
    #print-pdf-layout, #print-pdf-layout * { visibility: visible; }
    #print-pdf-layout {
        position: absolute; left: 0; top: 0; width: 100%; padding: 20px;
        display: block !important; background: #ffffff; color: #000000;
    }
    .pdf-header { border-bottom: 2px solid #1a446c; padding-bottom: 8px; margin-bottom: 20px; text-align: center; }
    .pdf-title { font-size: 1.6rem; font-weight: bold; color: #1a446c; }
    .pdf-box { 
        background: #fcfcfd; border: 1px solid #cfe2f3; padding: 12px; margin-bottom: 15px;
        font-family: 'JetBrains Mono', monospace; font-size: 11px; white-space: pre-wrap; 
    }
    .pdf-img-container { text-align: center; border: 1px solid #cfe2f3; padding: 10px; }
    .pdf-img-container img { max-width: 90% !important; height: auto !important; }
}

/* ==========================================================================
   INTEGRATED RESPONSIVE SYSTEM (MÀN HÌNH BÉ < 768PX)
   ========================================================================== */
@media (max-width: 768px) {
    body {
        height: auto;
        overflow: auto;
    }

    nav {
        flex-wrap: wrap;
    }

    .menu-item {
        flex: 1 1 auto;
        text-align: center;
    }
    
    .shell-btn-group {
        flex-wrap: wrap;
        gap: 8px;
    }
    
    .sub-nav-bar {
        height: auto;
        padding: 8px 20px;
    }

    /* Đổi hướng khu vực bao bọc workspace và container chính thành dạng cột dọc */
    .main-container, .workspace-wrapper {
        flex-direction: column;
    }

    /* Màn hình trái (Editor) chiếm toàn bộ chiều rộng, chiều cao 35% vùng nhìn */
    .sidebar {
        width: 100%;
        height: 35vh;
        flex: none;
    }

    /* Màn hình phải (Output & Plot) chiếm toàn bộ chiều rộng, chiều cao 60% vùng nhìn */
    .main-content {
        width: 100%;
        height: 60vh;
        flex: none;
    }

    /* Ẩn thanh resizer kéo dãn khi ở màn hình bé để tránh lỗi giao diện */
    .resizer {
        display: none;
    }
}
