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

:root {
    --workspace-font: 'JetBrains Mono', monospace;
    --workspace-font-size: 13px;
    --primary-bg: #34495e;
    --border-color: #cfe2f3;
}

* {
    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;
}

/* ==========================================================================
   2. LAYOUT STRUCTURE (HEADER, NAV, FOOTER)
   ========================================================================== */
header, nav, footer {
    background-color: var(--primary-bg);
    flex-shrink: 0;
}

header {
    padding: 6px 20px; 
    text-align: center;
}

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

nav {
    display: flex;
    justify-content: center;
    border-bottom: 2px solid #e6f0fa;
}

.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;
    outline: none;
}

/* Sub-navigation bar & Buttons */
.sub-nav-bar {
    background-color: #eaeff2;
    border-bottom: 1px solid var(--border-color);
    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;
    font-family: var(--workspace-font) !important;
}

.mini-btn-shell:hover {
    background-color: #d0e4f7 !important;
    color: #1a446c !important;
}

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

.mini-btn-shell: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 var(--border-color);
    border-radius: 4px;
    background: #ffffff;
    outline: none;
    cursor: pointer;
    color: #333;
}

footer {
    text-align: center;
    padding: 6px; 
    font-size: 0.8rem;
    color: #bdc3c7; 
    border-top: 1px solid var(--border-color);
}

/* ==========================================================================
   3. WORKSPACE CORE LAYOUT & CANVAS
   ========================================================================== */
.main-container, 
.workspace-wrapper {
    display: flex;
    flex: 1;
    overflow: hidden;
    height: 100%;
}

.main-container { position: relative; }
.workspace-wrapper { width: 100%; }

.sidebar {
    background-color: #ffffff;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    flex: 0 0 30%;
    height: 100%;
}

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

.resizer {
    width: 4px;                   
    cursor: col-resize;
    background-color: var(--border-color);      
    flex-shrink: 0;
    transition: background-color 0.2s;
}

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

/* Canvas Viewport */
#cv {
    touch-action: none;              /* Chống trượt trang khi tương tác di động */
    -webkit-touch-callout: none;     /* Khử menu giữ ngón tay trên iOS */
    -webkit-user-select: none;
    user-select: none;
    cursor: crosshair;
}

#cv-container, 
.canvas-wrapper {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
    touch-action: none;
}

/* CodeMirror & Output Workspace */
.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, 
#statusText { 
    font-family: var(--workspace-font); 
}

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

#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-size: 0.75rem;
    color: #5c7b93;
    padding: 5px 12px;
    background: #fafbfd;
    border-top: 1px solid var(--border-color);
    text-align: right;
    flex-shrink: 0;
}

/* ==========================================================================
   4. SIDEBAR CONTENT & CONTROL PANELS
   ========================================================================== */
#sidebar-content {
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    box-sizing: border-box;
    padding: 10px 10px 40px 10px;
}

#sidebar-content, 
#sidebar-content * {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif !important;
}

#sidebar-content textarea,
#sidebar-content input[type="text"],
#sidebar-content .snap-label,
#sidebar-content h4 {
    font-family: var(--workspace-font) !important;
}

aside h1, aside h2, aside h3, aside h4, aside h5, aside h6, 
aside label, aside .section-title, aside legend {
    font-size: 13px !important;
    color: #5f6368 !important;
    margin-bottom: 4px !important;
}

/* Form Controls */
#sidebar-content input { 
    width: 100%; 
    height: 100%;  
    text-align: center;
}

#sidebar-content input[type="button"] { width: 50px; }

#sidebar-content textarea {
    width: 100% !important;
    max-width: 100%;
    height: 80px;
    font-size: 11px;
    padding: 6px;
    margin-bottom: 10px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background-color: #fafbfc;
    resize: vertical;
}

#sidebar-content table, 
#sidebar-content td, 
#sidebar-content th {
    border: 0;
    border-collapse: collapse;
    font-size: 10px;
    text-align: center;
}

/* Scrollbar Sidebar */
#sidebar-content::-webkit-scrollbar { width: 6px; }
#sidebar-content::-webkit-scrollbar-thumb {
    background-color: #ccc;
    border-radius: 3px;
}

/* --- Project title --- */
.box { display: flex; align-items: center; gap: 8px; }
.box input { border: 1px solid #ccc; }

/* Grid System Controls */
.grid-ultra-mini-box {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #f1f3f4;
    padding: 6px 8px;
    border-radius: 4px;
    margin: 4px 0;
    gap: 10px;
    width: 100%;
}

.grid-inputs-stack {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
    min-width: 0;
}

.grid-row-item {
    display: flex;
    align-items: center;
    width: 100%;
}

.grid-row-item span {
    font-weight: bold;
    font-size: 11px;
    color: #444444;
    width: 18px;
    flex-shrink: 0;
}

.grid-row-item input[type="text"] {
    flex: 1;
    padding: 4px 6px;
    font-size: 11px;
    border: 1px solid #cccccc;
    border-radius: 3px;
    background: #ffffff;
}

.grid-action-side {
    display: flex;
    flex-direction: column;
    align-items: center;      
    justify-content: center;
    gap: 4px;
    padding-left: 10px;
    border-left: 1px solid #dadce0;
    flex-shrink: 0;
}

/* ==========================================================================
   5. UNIFIED POPUP SYSTEM (FEM NODES, LOADS & BOUNDARIES)
   ========================================================================== */
.fem-popup-box,
[id^="fem-"][id$="-popup-box"] {
    position: absolute;
    z-index: 1000;
    display: none;
    background: #ffffff;
    border: 1px solid #999999;
    border-radius: 2px;
    padding: 6px;
    box-shadow: 2px 2px 5px rgba(0, 0, 0, 0.1);
    font-family: monospace;
    font-size: 11px;
    width: 110px;
}

.fem-popup-box.wide,
#fem-elemprop-popup-box { 
    width: 135px; 
}

.fem-popup-title {
    font-weight: bold;
    border-bottom: 1px dashed #cccccc;
    padding-bottom: 3px;
    margin-bottom: 5px;
}

.fem-popup-row,
[id^="fem-"][id$="-popup-box"] div { 
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px; 
}

.fem-popup-row input[type="number"],
[id^="fem-"][id$="-popup-box"] input[type="number"] {
    width: 50px;
    border: 1px solid #cccccc;
    padding: 1px 3px;
    font-family: monospace;
    font-size: 11px;
}

.fem-popup-box.wide .fem-popup-row input[type="number"],
#fem-elemprop-popup-box input[type="number"] { 
    width: 75px; 
}

.fem-popup-check {
    display: flex;
    align-items: center;
    margin-bottom: 3px;
}

.fem-popup-check input { 
    margin-right: 4px; 
}

.fem-popup-btn-container,
[id^="fem-"][id$="-popup-box"] .btn-container { 
    display: flex; 
    gap: 4px; 
    margin-top: 5px; 
}

.fem-popup-btn-container button,
[id^="fem-"][id$="-popup-box"] button {
    flex: 1;
    width: 100%;
    cursor: pointer;
    border: 1px solid #777777;
    background: #eeeeee;
    padding: 2px 0;
    font-family: monospace;
    font-size: 10px;
}

.fem-popup-btn-container button:hover,
[id^="fem-"][id$="-popup-box"] button:hover { 
    background: #dddddd; 
}

#fem-elemprop-popup-box .release-container { 
    display: flex; 
    justify-content: space-between; 
    gap: 4px; 
    margin: 6px 0; 
}

#fem-elemprop-popup-box .release-container label { 
    display: flex; 
    align-items: center; 
    gap: 2px; 
    cursor: pointer; 
}

/* Radio Mode Options Container (Nodal Load & Element Load) */
.fem-popup-options {
    margin: 12px 0;
    display: flex;
    justify-content: space-around;
    font-size: 0.9em;
}
/* ==========================================================================
   6. DOCUMENTATION PAGE
   ========================================================================== */
.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; }

/* ==========================================================================
   7. PRINT INTEGRATION (@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 var(--border-color); 
        padding: 12px; 
        margin-bottom: 15px;
        font-family: var(--workspace-font); 
        font-size: 11px; 
        white-space: pre-wrap; 
    }
    
    .pdf-img-container { 
        text-align: center; 
        border: 1px solid var(--border-color); 
        padding: 10px; 
    }
    
    .pdf-img-container img { 
        max-width: 90% !important; 
        height: auto !important; 
    }
}

/* ==========================================================================
   8. RESPONSIVE MOBILE INTEGRATION (< 768px)
   ========================================================================== */
@media (max-width: 768px) {
    body { 
        height: auto; 
        overflow: auto; 
    }
    
    nav, 
    .shell-btn-group { 
        flex-wrap: wrap; 
    }
    
    .menu-item { 
        flex: 1 1 auto; 
        text-align: center; 
    }
    
    .shell-btn-group { gap: 8px; }
    
    .sub-nav-bar { 
        height: auto; 
        padding: 8px 20px; 
    }
    
    .main-container, 
    .workspace-wrapper { 
        flex-direction: column; /* Xếp theo chiều dọc */
    }
    
    /* --- ĐẢO THỨ TỰ HIỂN THỊ --- */
    .main-content { 
        order: 1;           /* Đưa phần Đồ họa / Canvas lên đầu */
        width: 100%; 
        height: 60vh; 
        flex: none; 
    }

    .sidebar { 
        order: 2;           /* Đưa phần Sidebar xuống dưới */
        width: 100%; 
        height: 40vh;       /* Tăng chút chiều cao cho dễ thao tác nếu cần */
        flex: none; 
    }
    
    .resizer { display: none; }

    /* Touch Controls Adaptations */
    button, 
    .fem-btn, 
    .btn {
        min-height: 40px;
        min-width: 40px;
        padding: 8px 12px;
        font-size: 14px;
    }

    input[type="text"], 
    input[type="number"] {
        font-size: 16px; /* Ngăn iOS Safari tự Zoom khi bấm vào ô nhập */
        padding: 6px 8px;
    }

    /* Popup Tối ưu hóa cho Cảm ứng Mobile */
    .fem-popup-box,
    [id^="fem-"][id$="-popup-box"] {
        width: 150px;
        padding: 8px;
    }

    .fem-popup-btn-container button,
    [id^="fem-"][id$="-popup-box"] button {
        min-height: 32px;
        font-size: 12px;
    }
}
}
