@charset "UTF-8";
/* ========================================================== */
/* Biến CSS (Custom Properties) */
/* Định nghĩa các màu sắc và giá trị thường dùng để dễ quản lý */
/* ========================================================== */
:root {
    --primary-blue: #3498db;
    --dark-blue: #2c3e50;
    --light-text: #ecf0f1;
    --dark-text: #333;
    --light-gray-bg: #f0f2f5;
    --very-light-bg: #f9fbfd;
    --border-color: #eee;
    --shadow-light: rgba(0,0,0,0.05);
    --shadow-medium: rgba(0,0,0,0.1);
    --shadow-heavy: rgba(0,0,0,0.15);
    --success-green: #2ecc71;
    --success-green-dark: #27ae60;
    --danger-red: #e74c3c;
    --danger-red-dark: #c0392b;
    --secondary-gray: #95a5a6;
    --secondary-gray-dark: #7f8c8d;
    --info-blue-light: #007bff;
    --info-blue-dark: #0056b3;
    --teal-color: #1abc9c;
    --teal-color-dark: #16a085;
    --warning-orange: #e67e22;
    --warning-orange-dark: #d35400;
    --console-bg: #2d2d2d;
    --console-text: #00ff00;
}

/* ========================================================== */
/* Cài đặt chung cho Body & Layout */
/* Áp dụng font chữ, màu nền, và cấu trúc flexbox chính */
/* ========================================================== */
body {
    margin: 0;
    padding: 0;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--light-gray-bg);
    color: var(--dark-text);
    display: flex;
    min-height: 200vh; /* Chiều cao tối thiểu bằng chiều cao viewport */
    justify-content: center; /* Căn giữa nội dung chính theo chiều ngang */
    align-items: flex-start; /* Căn nội dung chính lên đầu trang */
    padding: 20px; /* Khoảng đệm xung quanh nội dung chính */
    box-sizing: border-box; /* Đảm bảo padding không làm tràn layout */
}

/* Container chính cho toàn bộ ứng dụng (Sidebar + Main Content) */
.container1 {
    margin-top: 50px;
    display: flex;
    width: 100%;
    max-width: 2000px; /* Chiều rộng tối đa cho container chính */
}

/* ========================================================== */
/* Sidebar - Thanh điều hướng bên trái */
/* ========================================================== */
.sidebar {
    width: 250px;
    background-color: var(--dark-blue);
    color: var(--light-text);
    padding: 20px;
    box-shadow: 2px 0 5px var(--shadow-medium);
    display: flex;
    flex-direction: column;
    border-radius: 8px; /* Bo góc sidebar */
}

.sidebar .logo {
    text-align: center;
    margin-bottom: 30px;
}

.sidebar .logo h1 {
    margin: 0;
    font-size: 1.8em;
    color: var(--primary-blue);
}

.nav-menu ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.nav-menu li {
    margin-bottom: 10px;
}

.nav-menu a {
    color: var(--light-text);
    text-decoration: none;
    display: block;
    padding: 10px 15px;
    border-radius: 5px;
    transition: background-color 0.3s ease;
}

.nav-menu a:hover,
.nav-menu li.active a {
    background-color: #34495e; /* Màu nền khi hover/active */
    color: #fff;
}

.nav-menu i {
    margin-right: 10px;
}

.status-panel {
    margin-top: auto; /* Đẩy panel trạng thái xuống dưới cùng */
    padding-top: 20px;
    border-top: 1px solid #34495e;
}

.status-panel h3 {
    margin-top: 0;
    font-size: 1.1em;
    color: #bdc3c7; /* Màu xám nhạt hơn cho tiêu đề */
}

.status-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 0.95em;
}

.status-value {
    font-weight: bold;
}

.status-value.connected { color: var(--success-green); }
.status-value.printing { color: #f39c12; } /* Màu cam cho trạng thái in */
.status-value.disconnected { color: var(--danger-red); }

/* ========================================================== */
/* Main Content - Phần nội dung chính bên phải Sidebar */
/* ========================================================== */
.main-content {
    flex-grow: 1;
    padding: 30px;
    background-color: var(--very-light-bg);
    border-radius: 8px; /* Bo góc nội dung chính */
    margin-left: 20px; /* Khoảng cách với sidebar */
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
}

.header h2 {
    margin: 0;
    font-size: 1.8em;
    color: var(--dark-blue);
}

.header-actions button {
    margin-left: 10px;
}

/* ========================================================== */
/* Các nút bấm chung */
/* Định nghĩa kiểu dáng cho các loại nút khác nhau */
/* ========================================================== */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1em;
    transition: background-color 0.2s ease, transform 0.1s ease;
    width: fit-content;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn-primary {
    background-color: var(--success-green);
    color: white;
}

.btn-primary:hover {
    background-color: var(--success-green-dark);
}

.btn-danger {
    background-color: var(--danger-red);
    color: white;
}

.btn-danger:hover {
    background-color: var(--danger-red-dark);
}

.btn-secondary {
    background-color: var(--secondary-gray);
    color: white;
}

.btn-secondary:hover {
    background-color: var(--secondary-gray-dark);
}

.btn-sm {
    padding: 8px 15px;
    font-size: 0.9em;
    background-color: var(--primary-blue);
    color: white;
    border-radius: 4px;
}

.btn-sm:hover {
    background-color: #2980b9;
}

/* ========================================================== */
/* Input Row - Hàng chứa Input và Button (ví dụ: Connect IP) */
/* ========================================================== */
.input-row {
    display: flex;
    gap: 8px;
    margin-bottom: 15px;
    align-items: center;
    margin-top: 17px;
}

.input-row input[type="text"] {
    flex-grow: 1;
    padding: 10px 12px;
    border: 1px solid #dcdcdc;
    border-radius: 6px;
    font-size: 15px;
    color: var(--dark-text);
    outline: none;
    transition: all 0.2s ease;
}

.input-row input[type="text"]:focus {
    border-color: #6a8de4;
    box-shadow: 0 0 0 2px rgba(106, 141, 228, 0.2);
}

.input-row button {
    padding: 10px 16px;
    background-color: #4a78e8; /* Màu xanh dương hiện đại */
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 15px;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
    display: flex;
    align-items: center;
    gap: 6px;
}

.input-row button:hover {
    background-color: #3a62d0;
    transform: translateY(-0.5px);
}

.input-row button:active {
    background-color: #2b4daa;
    transform: translateY(0);
}

/* Spinner cho nút kết nối */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.input-row button.connecting .spinner {
    animation: spin 1s linear infinite;
}

.spinner {
    display: none;
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-top: 2px solid #fff;
    border-radius: 50%;
    width: 14px;
    height: 14px;
}

/* ========================================================== */
/* Main Layout Container - Chứa khung 3D và các Panel chính */
/* ========================================================== */
.main-layout-container {
    display: flex;
    flex-direction: column; /* Thay đổi để top-section và bottom-dashboard-grid xếp chồng */
    gap: 20px;
    width: 100%;
}

.top-section {
    display: flex;
    flex-wrap: wrap; /* Cho phép các phần tử trong top-section xuống dòng */
    gap: 20px;
    justify-content: center; /* Căn giữa các khối khi xuống dòng */
    align-items: flex-start; /* Căn trên cùng */
}

/* ========================================================== */
/* Simulation Section - Khối chứa khung 3D và controls của nó */
/* ========================================================== */
.simulation-section {
    display: flex;
    flex-direction: column;
    gap: 15px; /* Khoảng cách giữa khung 3D và panel controls */
    flex: 2; /* Cho phép nó mở rộng gấp đôi side-panels */
    min-width: 450px; /* Kích thước tối thiểu cho 3D viewer */
    max-width: 70%; /* Giới hạn chiều rộng tối đa */
}

/* Khung hiển thị mô phỏng 3D (Three.js) */
#gcode-container {
    flex-grow: 1;
    height: 450px; /* Giảm chiều cao mặc định */
    border: 20px solid #1056b1; /* Viền nổi bật */
    border-radius: 50px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.25);
    position: relative;
    overflow: hidden;
    background-color: #1a1a1a; /* Nền trước khi Three.js render */
}

/* Đảm bảo canvas của Three.js lấp đầy container */
canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
}

/* Panel điều khiển mô phỏng (dưới khung 3D) */
.simulation-controls-panel {
    background-color: rgba(47, 65, 64, 0.95);
    padding: 15px 20px;
    border-radius: 25px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.simulation-controls-panel .control-group {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.simulation-controls-panel label {
    margin-right: 10px;
    white-space: nowrap;
    font-weight: 600;
    color: #1273d4; /* Màu xanh */
}

/* Input Range (thanh trượt tiến độ) */
.simulation-controls-panel input[type="range"] {
    flex-grow: 1;
    vertical-align: middle;
    margin-right: 10px;
    min-width: 150px;
    -webkit-appearance: none;
    appearance: none;
    height: 8px;
    background: #d3d3d3;
    outline: none;
    opacity: 0.7;
    transition: opacity .2s;
    border-radius: 4px;
}
.simulation-controls-panel input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--info-blue-light);
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}
.simulation-controls-panel input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--info-blue-light);
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}
.simulation-controls-panel input[type="range"]:hover {
    opacity: 1;
}

#progressValue {
    display: inline-block;
    width: 45px;
    text-align: right;
    vertical-align: middle;
    font-weight: bold;
    color: var(--info-blue-light);
}

/* Nút chọn G-code và nút xoay tự động */
#toggleRotateBtn, #selectGcodeForSimBtn {
    padding: 10px 20px;
    color: white;
    border: none;
    border-radius: 18px;
    cursor: pointer;
    font-size: 1em;
    transition: background-color 0.2s ease, transform 0.1s ease;
    margin-top: 10px;
    font-weight: 600;
}
#toggleRotateBtn {
    background-color: var(--info-blue-light);
}
#toggleRotateBtn:hover {
    background-color: var(--info-blue-dark);
}
#selectGcodeForSimBtn {
    background-color: var(--success-green);
}
#selectGcodeForSimBtn:hover {
    background-color: var(--success-green-dark);
}

#unifiedFileNameDisplay {
    font-size: 0.9em;
    color: #6c757d;
    margin-top: 5px;
    text-align: center;
    width: 100%;
    padding: 5px 0;
    border: 1px dashed #ced4da;
    border-radius: 5px;
    background-color: #f8f9fa;
}

/* ========================================================== */
/* Side Panels (Nhiệt độ hiện tại & Điều khiển trục) */
/* ========================================================== */
.side-panels {
    display: flex;
    flex-direction: column; /* Xếp chồng các card con */
    gap: 20px;
    flex: 1; /* Cho phép nó mở rộng nhưng ít hơn simulation */
    min-width: 300px; /* Đảm bảo đủ không gian */
    max-width: 350px; /* Giới hạn chiều rộng tối đa */
}


/* ========================================================== */
/* Bottom Dashboard Grid - Lưới hiển thị các Card thông tin dưới */
/* ========================================================== */
.bottom-dashboard-grid {
    display: grid;
    /* Chia thành 3 cột, cột cuối tự động co giãn */
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 25px;
    /* Định nghĩa khu vực lưới để sắp xếp các card */
    grid-template-areas:
        "color-card console-card sd-card"; /* Cập nhật grid areas */
    margin-top: 0; /* Khoảng cách đã được xử lý bởi main-layout-container */
    width: 100%; /* Đảm bảo nó chiếm toàn bộ chiều rộng */
}

/* Gán tên khu vực cho từng card cụ thể */
.bottom-dashboard-grid > .card:nth-child(1) { grid-area: color-card; }
.bottom-dashboard-grid > .console-card { grid-area: console-card; }
.bottom-dashboard-grid > .sd-card-files { grid-area: sd-card; } /* Updated grid area name */


/* Kiểu dáng chung cho mỗi Card */
.card {
    background-color: #fff;
    padding: 25px;
    border-radius: 8px;
    box-shadow: 0 4px 10px var(--shadow-light);
    transition: transform 0.2s ease;
}

.card:hover {
    transform: translateY(-3px);
}

.card h3 {
    margin-top: 0;
    margin-bottom: 20px;
    color: #34495e;
    font-size: 1.3em;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 10px;
}

/* ========================================================== */
/* Card Nhiệt độ hiện tại */
/* ========================================================== */
.temp-display {
    display: flex;
    justify-content: space-around;
    margin-bottom: 20px;
    font-size: 1.1em;
    flex-wrap: wrap; /* Cho phép xuống dòng */
    gap: 15px; /* Khoảng cách giữa các mục nhiệt độ */
}

.temp-item {
    text-align: center;
    flex: 1;
    min-width: 120px; /* Đảm bảo đủ không gian */
}

.temp-value {
    display: block;
    font-size: 2.2em; /* Tăng kích thước giá trị nhiệt độ */
    font-weight: bold;
    color: var(--primary-blue); /* Blue */
    margin-top: 5px;
}

.temp-controls {
    display: flex; /* Sử dụng flexbox cho các hàng điều khiển */
    flex-direction: column; /* Xếp chồng các hàng điều khiển */
    gap: 15px; /* Khoảng cách giữa các hàng điều khiển (VD: giữa đầu phun và bàn nhiệt) */
    align-items: center; /* Căn giữa các hàng theo chiều ngang */
}

.temp-controls .control-row {
    display: flex; /* Sử dụng flexbox cho từng hàng label-input-button */
    align-items: center; /* Căn giữa các item trong hàng */
    gap: 10px; /* Khoảng cách giữa label, input và button */
    flex-wrap: wrap; /* Cho phép các phần tử trong hàng xuống dòng nếu không đủ chỗ */
    justify-content: center; /* Căn giữa các phần tử khi wrap */
    width: 100%; /* Đảm bảo hàng chiếm hết chiều rộng có thể */
}

.temp-controls label {
    flex-shrink: 0; /* Ngăn label bị co lại */
    font-weight: 600;
    white-space: nowrap; /* Giữ label trên một dòng */
    min-width: 90px; /* Đặt chiều rộng tối thiểu cho label để căn chỉnh */
    text-align: right; /* Căn phải label để gần input hơn */
}

.temp-controls input[type="number"] {
    flex-grow: 1; /* Cho phép input co giãn */
    max-width: 120px; /* Giới hạn chiều rộng tối đa cho input */
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 5px;
    font-size: 1em;
    box-sizing: border-box; /* Đảm bảo padding và border không làm tăng kích thước tổng thể */
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.temp-controls input[type="number"]:focus {
    border-color: var(--primary-blue);
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
}

.temp-controls .btn-sm {
    flex-shrink: 0; /* Ngăn button bị co lại */
    padding: 8px 15px;
    font-size: 0.9em;
}

/* ========================================================== */
/* Card Điều khiển trục (Axis Controls) */
/* ========================================================== */
.axis-controls {
    display: flex;
    justify-content: space-around;
    gap: 20px;
    margin-bottom: 20px;
}

.axis-group {
    text-align: center;
}

.axis-group span {
    display: block;
    font-weight: bold;
    margin-bottom: 10px;
    font-size: 1.1em;
}

.control-pad {
    display: grid;
    grid-template-columns: repeat(3, 60px);
    grid-template-rows: repeat(3, 60px);
    gap: 5px;
    justify-content: center;
    align-items: center;
    width: 190px;
    height: 190px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: #f8f8f8;
}

.control-pad.vertical {
    grid-template-columns: 60px;
    grid-template-rows: repeat(3, 60px);
    height: 190px;
    width: 60px;
    justify-content: center;
}

.move-btn {
    width: 60px;
    height: 60px;
    background-color: var(--primary-blue);
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 1.1em;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
    display: flex;
    justify-content: center;
    align-items: center;
}

.move-btn:hover {
    background-color: #2980b9;
    transform: translateY(-2px);
}

.move-btn.home-btn {
    background-color: var(--warning-orange);
    font-size: 1.3em;
}

.move-btn.home-btn:hover {
    background-color: var(--warning-orange-dark);
}

.move-distance {
    text-align: center;
}
.move-distance select {
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    width: 100px;
}

/* ========================================================== */
/* Card Console & Logs */
/* ========================================================== */
.console-card {
    height: 400px;
    display: flex;
    flex-direction: column;
}
.console-output {
    background-color: var(--console-bg);
    color: var(--console-text);
    padding: 15px;
    border-radius: 5px;
    flex-grow: 1;
    overflow-y: auto;
    margin-bottom: 15px;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.9em;
}

.console-output pre {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-all;
}

.console-input {
    display: flex;
    gap: 10px;
}

.console-input input[type="text"] {
    flex-grow: 1;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 5px;
    font-size: 1em;
}

/* ========================================================== */
/* Card Biểu đồ nhiệt độ (Chart Card) */
/* (Removed and replaced with SD Card Files) */
/* ========================================================== */

/* ========================================================== */
/* Card SD Card Files (New) */
/* ========================================================== */
.sd-card-files {
    height: 400px; /* Keep consistent height with other cards */
    display: flex;
    flex-direction: column;
}

.sd-file-list {
    flex-grow: 1;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    padding: 10px;
    margin-bottom: 15px;
    background-color: var(--very-light-bg);
}

.sd-file-list ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.sd-file-list li {
    padding: 8px 0;
    border-bottom: 1px dashed #e0e0e0;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.sd-file-list li:last-child {
    border-bottom: none;
}

.sd-file-list li:hover {
    background-color: #e9ecef;
}

.sd-file-list li.selected-file {
    background-color: var(--primary-blue);
    color: white;
    font-weight: bold;
}


/* ========================================================== */
/* Card Màu nhựa in (Filament Color Control) */
/* ========================================================== */
.card:has(.filament-colors) {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.filament-colors {
    display: flex;
    justify-content: space-around;
    gap: 15px;
    margin-bottom: 25px;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: #f8f8f8;
    width: 100%;
    max-width: 300px;
}

.color-slot {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.color-option {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 5px var(--shadow-light);
    transition: transform 0.2s ease, box-shadow 0.2s ease, border 0.2s ease;
    border: 3px solid transparent;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

.color-option span {
    color: white;
    font-weight: bold;
    font-size: 0.9em;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.6);
    pointer-events: none;
}

.color-slot:hover .color-option span {
    opacity: 0.7;
}

.color-option:hover {
    transform: translateY(-3px);
    box-shadow: 0 4px 8px var(--shadow-medium);
}

.color-option.selected {
    border-color: var(--primary-blue);
    transform: scale(1.05);
    box-shadow: 0 0 0 4px rgba(52, 152, 219, 0.5);
}

.edit-color-btn {
    position: absolute;
    top: 5px;
    right: 5px;
    background-color: rgba(0, 0, 0, 0.4);
    color: white;
    border: none;
    border-radius: 50%;
    width: 25px;
    height: 25px;
    font-size: 0.8em;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s ease, background-color 0.2s ease;
}

.color-slot:hover .edit-color-btn {
    opacity: 1;
}

.edit-color-btn:hover {
    background-color: rgba(0, 0, 0, 0.6);
}

.selected-color-info {
    font-size: 1.1em;
    margin-bottom: 15px;
    font-weight: bold;
    color: #555;
}

.card:has(.filament-colors) .btn {
    margin-bottom: 15px;
}
.card:has(.filament-colors) .btn:last-child {
    margin-bottom: 0;
}

.filament-change-btn {
    background-color: var(--teal-color);
    color: white;
}

.filament-change-btn:hover {
    background-color: var(--teal-color-dark);
}

/* ========================================================== */
/* Modal chung (Pop-up) */
/* ========================================================== */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.4);
    justify-content: center;
    align-items: center;
}

.modal-content {
    background-color: #fefefe;
    padding: 30px;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    width: 90%;
    max-width: 400px;
    position: relative;
    animation-name: animatetop;
    animation-duration: 0.4s;
}

@keyframes animatetop {
    from {top: -300px; opacity: 0}
    to {top: 0; opacity: 1}
}

.close-button {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    position: absolute;
    top: 10px;
    right: 20px;
    cursor: pointer;
}

.close-button:hover,
.close-button:focus {
    color: black;
    text-decoration: none;
    cursor: pointer;
}

.modal-content h3 {
    margin-top: 0;
    margin-bottom: 20px;
    color: #34495e;
    text-align: center;
    border-bottom: none;
}

.modal-content label {
    display: block;
    margin-bottom: 8px;
    font-weight: bold;
}

.modal-content input[type="color"] {
    width: 100%;
    height: 50px;
    border: 1px solid #ccc;
    border-radius: 5px;
    margin-bottom: 20px;
    padding: 0;
    cursor: pointer;
}

.modal-content input[type="text"] {
    width: calc(100% - 22px);
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 5px;
    margin-bottom: 20px;
    font-size: 1em;
}

.modal-content .btn {
    width: 100%;
    padding: 12px;
    font-size: 1.1em;
}

/* ========================================================== */
/* Responsive adjustments - Điều chỉnh cho các kích thước màn hình khác nhau */
/* ========================================================== */
@media (max-width: 1200px) {
    .top-section {
        flex-direction: column; /* Chuyển sang cột nếu không gian hẹp */
        align-items: center;
    }
    .simulation-section, .side-panels {
        max-width: 100%; /* Cho phép chiếm toàn bộ chiều rộng */
        min-width: unset;
        flex: none; /* Bỏ flex grow */
        width: 100%; /* Đảm bảo chiếm đủ chiều rộng */
    }
    #gcode-container {
        height: 500px; /* Tăng chiều cao khi chiếm toàn bộ chiều rộng */
    }
    .bottom-dashboard-grid {
        grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
        grid-template-areas: unset;
    }
}

@media (max-width: 900px) {
    .container {
        flex-direction: column;
    }
    .sidebar {
        width: 100%;
        padding: 15px;
        box-shadow: 0 2px 5px var(--shadow-medium);
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        flex-wrap: wrap;
        margin-left: 0; /* Bỏ margin-left khi ở chế độ cột */
    }
    .sidebar .logo {
        margin-bottom: 0;
    }
    .nav-menu {
        display: none; /* Ẩn menu điều hướng trên màn hình nhỏ */
    }
    .status-panel {
        margin-top: 15px;
        padding-top: 15px;
        width: 100%;
        border-top: 1px solid #34495e;
    }
    .main-content {
        padding: 20px; /* Giảm padding cho nội dung chính */
        margin-left: 0; /* Bỏ margin-left khi ở chế độ cột */
        margin-top: 20px; /* Khoảng cách từ sidebar */
    }
    .header {
        flex-direction: column;
        align-items: flex-start;
    }
    .header-actions {
        margin-top: 15px;
    }
    .main-layout-container {
        flex-direction: column;
        gap: 15px; /* Giảm khoảng cách */
    }
    .simulation-section, #gcode-container {
        min-width: unset; /* Bỏ min-width để tự co giãn */
        height: 400px; /* Chiều cao mặc định cho khung 3D trên mobile */
        flex-basis: auto;
    }
    .bottom-dashboard-grid {
        grid-template-columns: 1fr; /* Sắp xếp thành 1 cột */
        grid-template-areas: unset; /* Đặt lại khu vực lưới */
        gap: 15px; /* Giảm khoảng cách giữa các card */
    }
    .bottom-dashboard-grid > .card {
        grid-area: unset !important;
    }
}

@media (max-width: 768px) {
    .filament-colors {
        flex-wrap: wrap;
        justify-content: center;
    }
    .color-slot {
        flex-basis: 45%;
        margin-bottom: 15px;
    }
    /* Responsive adjustments */
    .temp-controls .control-row {
        flex-direction: column; /* Chuyển sang cột trên màn hình nhỏ */
        align-items: center; /* Căn giữa các mục khi ở dạng cột */
    }
    .temp-controls label {
        width: 100%; /* Label chiếm toàn bộ chiều rộng */
        text-align: center; /* Căn giữa label */
        margin-bottom: 5px; /* Khoảng cách dưới label */
    }
    .temp-controls input[type="number"] {
        width: 80%; /* Input chiếm phần lớn chiều rộng */
        max-width: 150px; /* Giới hạn chiều rộng input trên mobile */
        margin-bottom: 10px; /* Khoảng cách dưới input */
    }
    .temp-controls .btn-sm {
        width: 60%; /* Nút chiếm phần lớn chiều rộng */
        max-width: 100px; /* Giới hạn chiều rộng nút */
    }
}
       #gcodeFilesList { 
            border: 1px solid #dcdcdc; /* Màu viền nhẹ nhàng hơn */
            padding: 5px; /* Giảm padding tổng thể */
            min-height: 150px; 
            max-height: 300px; 
            overflow-y: auto; 
            background-color: #ffffff; /* Nền trắng */
            border-radius: 8px; /* Bo tròn góc nhiều hơn */
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); /* Thêm đổ bóng nhẹ */
            display: flex; /* Dùng flexbox cho căn giữa khi rỗng */
            flex-direction: column;
            justify-content: flex-start; /* Ban đầu căn trên */
        }
        #gcodeFilesList.empty-list { /* Class để căn giữa khi không có tệp */
            justify-content: center;
            align-items: center;
        }
        #gcodeFilesList div { 
            cursor: pointer; 
            padding: 8px 12px; /* Tăng padding cho từng mục */
            border-bottom: 1px solid #f0f0f0; /* Đường phân cách mảnh hơn */
            transition: background-color 0.2s ease, transform 0.1s ease; /* Thêm transition */
            font-size: 14px;
            color: #555;
        }
        #gcodeFilesList div:last-child {
            border-bottom: none;
        }
        #gcodeFilesList div:hover { 
            background-color: #e9ecef; /* Màu hover tinh tế hơn */
            transform: translateY(-1px); /* Nâng nhẹ khi hover */
        }
        #gcodeFilesList div.selected { 
            background-color: #add8e6; /* Màu xanh nhạt dễ chịu */
            font-weight: bold; 
            color: #1a1a1a; /* Màu chữ đậm hơn một chút */
            border-left: 4px solid #007bff; /* Thanh màu bên trái để nhấn mạnh */
            padding-left: 8px; /* Điều chỉnh padding do có border-left */
        } 
        #gcodeFilesList p { /* Style cho thông báo "Chưa có tệp nào" */
            color: #777;
            text-align: center;
            margin: auto; /* Căn giữa theo cả chiều dọc và ngang trong flex container */
            padding: 10px;
        }