/* style.css */
* { 
    box-sizing: border-box; 
    margin: 0; 
    padding: 0; 
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; 
}

body { 
    display: flex; 
    height: 100vh; 
    background-color: #f4f6f9; 
    overflow: hidden; 
    font-size: 13px; /* Font size chuẩn toàn hệ thống */
    color: #333;
}

/* ================= 1. SIDEBAR VERTICAL MENU ================= */
.sidebar {
    width: 230px;
    background-color: #1e293b;
    color: #fff;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    box-shadow: 2px 0 5px rgba(0,0,0,0.1);
    flex-shrink: 0;
}

.sidebar-brand {
    padding: 16px 18px;
    font-size: 16px;
    font-weight: bold;
    color: #38bdf8;
    border-bottom: 1px solid #334155;
    display: flex;
    align-items: center;
    gap: 8px;
}

.sidebar-menu { 
    list-style: none; 
    padding: 10px 0; 
    flex-grow: 1; 
}

.sidebar-menu li { 
    cursor: pointer; 
}

.sidebar-menu li a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 18px;
    color: #94a3b8;
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s ease;
}

.sidebar-menu li:hover a, 
.sidebar-menu li.active a {
    background-color: #0f172a;
    color: #38bdf8;
    border-left: 3px solid #38bdf8;
}

.sidebar-footer {
    padding: 12px 18px;
    border-top: 1px solid #334155;
    font-size: 12px;
    color: #64748b;
}

/* ================= 2. MAIN CONTENT AREA ================= */
.main-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.top-navbar {
    background: white;
    padding: 12px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #e2e8f0;
}

.top-navbar h3 {
    font-size: 16px;
    font-weight: 600;
}

.content-body { 
    padding: 20px; 
}

/* TAB VIEWS */
.tab-view { 
    display: none; 
}

.tab-view.active { 
    display: block; 
}

/* UI COMPONENTS */
.card { 
    background: white; 
    padding: 16px 20px; 
    border-radius: 8px; 
    box-shadow: 0 1px 3px rgba(0,0,0,0.05); 
    margin-bottom: 16px; 
}

.project-bar { 
    display: flex; 
    align-items: center; 
    gap: 10px; 
    margin-bottom: 12px; 
    font-size: 13px;
}

table { 
    width: 100%; 
    border-collapse: collapse; 
    margin-top: 8px; 
    background: white; 
    font-size: 13px;
}

th, td { 
    border: 1px solid #dee2e6; 
    padding: 8px 12px; 
    text-align: left; 
}

th { 
    background: #e9ecef; 
    color: #495057; 
    font-weight: 600;
}

.status-ok { 
    color: #28a745; 
    font-weight: bold; 
    font-size: 12px;
}

.status-err { 
    color: #dc3545; 
    font-size: 12px;
}

/* BUTTONS & INPUTS */
.btn { 
    padding: 6px !important; 
    background: #007bff; 
    color: white; 
    border: none; 
    border-radius: 4px; 
    cursor: pointer; 
    font-size: 11px; 
    font-weight: 600; 
}

.btn:hover { background: #0056b3; }
.btn-add { background: #28a745; padding: 6px; font-size: 13px;}
.btn-add:hover { background: #218838; }
.btn-project { background: #6f42c1; padding: 6px; font-size: 13px;}
.btn-project:hover { background: #593196; }
.btn-config { background: #17a2b8; margin-left: 0px; padding: 6px !important; font-size: 11px;}
.btn-config:hover { background: #138496; }
.btn-delete { background: #dc3545; margin-left: 4px; padding: 6px !important; ont-size: 11px;}
.btn-delete:hover { background: #bd2130; }
.btn-save { background: #28a745; padding: 6px; font-size: 13px;}
.btn-cancel { background: #6c757d; padding: 6px; font-size: 13px;}
.btn-cancel:hover { background: #5a6268; }

select, input[type="number"], input[type="text"] { 
    padding: 5px 8px; 
    border: 1px solid #ccc; 
    border-radius: 4px; 
    font-size: 13px;
}

.config-row { 
    display: none; 
    background-color: #f1f8ff; 
}

.config-box { 
    padding: 8px 12px; 
    display: flex; 
    gap: 10px; 
    align-items: center; 
    flex-wrap: wrap; 
}

.config-item { 
    display: flex; 
    align-items: center; 
    gap: 5px; 
    font-size: 12px; 
}

.badge-off { 
    font-size: 11px; 
    background: #6c757d; 
    color: white; 
    padding: 2px 5px; 
    border-radius: 3px; 
    margin-left: 4px; 
}

.badge-on { 
    font-size: 11px; 
    background: #28a745; 
    color: white; 
    padding: 2px 5px; 
    border-radius: 3px; 
    margin-left: 4px; 
}

.badge-disconnect { 
    font-size: 12px; 
    color: #dc3545; 
    font-weight: bold; 
}

/* POPUP MODAL */
.modal { 
    display: none; 
    position: fixed; 
    z-index: 1000; 
    left: 0; 
    top: 0; 
    width: 100%; 
    height: 100%; 
    background: rgba(0,0,0,0.5); 
}

.modal-content { 
    background: white; 
    width: 380px; 
    margin: 30px auto; 
    padding: 16px 20px; 
    border-radius: 8px; 
    box-shadow: 0 4px 8px rgba(0,0,0,0.2); 
    max-height: 84.7vh !important;
    overflow-y: auto !important;
}

.modal-header { 
    font-size: 15px; 
    font-weight: bold; 
    margin-bottom: 15px; 
    border-bottom: 1px solid #ddd; 
    padding-bottom: 8px; 
}

.form-group { 
    margin-bottom: 15px; 
    display: flex; 
    flex-direction: column; 
    gap: 4px; 
}

.form-group label { 
    font-size: 13px; 
    font-weight: bold; 
    color: #333; 
}

.modal-footer { 
    display: flex; 
    justify-content: flex-end; 
    gap: 8px; 
    margin-top: 15px; 
}

/* ================= 3. MOBILE RESPONSIVE DESIGN ================= */
@media screen and (max-width: 768px) {
    body {
        flex-direction: column;
        height: auto;
        overflow-x: hidden;
        overflow-y: auto;
    }

    .sidebar {
        width: 100%;
        height: auto;
        position: sticky;
        top: 0;
        z-index: 100;
    }

    .sidebar-menu {
        display: flex;
        justify-content: space-around;
        padding: 5px 0;
    }

    .sidebar-menu li a {
        padding: 8px 10px;
        font-size: 12px;
        border-left: none !important;
        border-bottom: 3px solid transparent;
    }

    .sidebar-menu li.active a {
        border-bottom: 3px solid #38bdf8;
    }

    .sidebar-footer {
        display: none;
    }

    .top-navbar {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .project-bar {
        flex-direction: column;
        align-items: stretch !important;
        gap: 10px;
    }

    .project-bar div {
        width: 100%;
    }

    .project-bar select {
        flex-grow: 1;
        width: 100% !important;
    }

    .project-bar button {
        width: 100%;
        padding: 8px;
    }

    table, thead, tbody, th, td, tr {
        display: block;
    }

    thead tr {
        position: absolute;
        top: -9999px;
        left: -9999px;
    }

    tr[id^="row_main_"] {
        background: #fff;
        border: 1px solid #e2e8f0;
        border-radius: 8px;
        margin-bottom: 12px;
        padding: 10px;
        box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    }

tr[id^="row_main_"] td {
        border: none;
        padding: 6px 0;
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        font-size: 13px;
        border-bottom: 1px dashed #f1f5f9;
        gap: 15px;
        text-align: right; /* Đẩy nội dung giá trị bên phải căn phải */
    }

    /* Ép phần nhãn tiêu đề (ID, Tên thiết bị, Tín hiệu...) cố định nằm bên trái */
    tr[id^="row_main_"] td::before {
        text-align: left !important;
        flex-shrink: 0;
    }

    tr[id^="row_main_"] td:last-child {
        border-bottom: none;
        justify-content: flex-end;
        padding-top: 10px;
    }

    tr[id^="row_main_"] td::before {
        content: attr(data-label);
        font-weight: bold;
        color: #64748b;
        font-size: 12px;
    }

    #projectTable tr {
        background: #fff;
        border: 1px solid #e2e8f0;
        border-radius: 8px;
        margin-bottom: 12px;
        padding: 10px;
        box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    }

    #projectTable td {
        border: none;
        padding: 6px 0;
        display: flex;
        justify-content: space-between;
        align-items: center;
        font-size: 13px;
        border-bottom: 1px dashed #f1f5f9;
    }

    #projectTable td:last-child {
        border-bottom: none;
        justify-content: flex-end;
        padding-top: 10px;
        gap: 6px;
    }

    #projectTable td::before {
        content: attr(data-label);
        font-weight: bold;
        color: #64748b;
        font-size: 12px;
    }

    .config-row td {
        padding: 10px !important;
    }

    .config-box {
        flex-direction: column;
        align-items: stretch;
    }

    .config-item {
        justify-content: space-between;
    }

    .config-item input, .config-item select {
        width: 60% !important;
    }

    .modal-content {
        width: 96%;
        margin: 10px auto;
    }
}


/* ================= TỐI ƯU POPUP CHI TIẾT CHO ĐIỆN THOẠI ================= */
@media screen and (max-width: 768px) {
    /* Mở rộng chiều rộng popup tối đa trên điện thoại */
    #detailDeviceModal .modal-content {
        width: 96% !important;
        max-width: 100% !important;
        margin: 10px auto !important;
        padding: 12px !important;
    }

    /* Chuyển dạng hiển thị 2 cột thành 1 cột dọc */
    #detailDeviceModal .modal-content > div[style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
        gap: 10px !important;
    }

    /* Đưa phần lịch sử cảnh báo về 1 cột trên mobile */
    #detailDeviceModal .card[style*="grid-column: span 2"] {
        grid-column: span 1 !important;
    }

    /* Cấu hình các thẻ thống kê không bị vỡ chữ/rớt dòng */
    #detailDeviceModal .card {
        padding: 12px !important;
    }

    #detailDeviceModal div[style*="border-left"] {
        padding: 8px 10px !important;
        font-size: 12px !important;
    }

    #detailDeviceModal div[style*="border-left"] span {
        white-space: nowrap;
    }

    #detailDeviceModal div[style*="border-left"] b {
        font-size: 13px !important;
        white-space: nowrap;
    }
}

/* ================= TỐI ƯU BẢNG CẢNH BÁO TRÊN ĐIỆN THOẠI ================= */
@media screen and (max-width: 768px) {
    /* Biến mỗi dòng cảnh báo thành một thẻ card nhỏ gọn trên mobile */
    #alarmsTableBody tr {
        display: block !important;
        background: #f8fafc !important;
        border: 1px solid #e2e8f0 !important;
        border-radius: 6px !important;
        margin-bottom: 8px !important;
        padding: 8px 10px !important;
        box-shadow: none !important;
    }

    /* Ẩn tiêu đề bảng (thead) trên mobile */
    #detailDeviceModal .card table thead {
        display: none !important;
    }

    /* Định dạng lại các cột bên trong thẻ card cảnh báo */
    #alarmsTableBody td {
        display: flex !important;
        justify-content: space-between !important;
        align-items: center !important;
        border: none !important;
        padding: 3px 0 !important;
        font-size: 12px !important;
    }

    /* Hiển thị nhãn (label) cho từng thông tin */
    #alarmsTableBody td:nth-child(1)::before { content: "🕒 Thời gian:"; font-weight: 600; color: #64748b; }
    #alarmsTableBody td:nth-child(2)::before { content: "⚡ Loại:"; font-weight: 600; color: #64748b; }
    #alarmsTableBody td:nth-child(3)::before { content: "📊 Giá trị:"; font-weight: 600; color: #64748b; }
    #alarmsTableBody td:nth-child(4)::before { content: "📝 Chi tiết:"; font-weight: 600; color: #64748b; display: none; }

    /* Riêng dòng nội dung chi tiết cho xuống dòng và làm nổi bật */
    #alarmsTableBody td:nth-child(4) {
        display: block !important;
        margin-top: 4px !important;
        padding-top: 4px !important;
        border-top: 1px dashed #cbd5e1 !important;
        color: #334155;
        font-size: 11px !important;
    }
}

#new_rs485_settings .form-group input,
#new_rs485_settings .form-group select {
    width: 100% !important;
    box-sizing: border-box;
}

#new_rs485_settings div[style*="display: flex"] {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

#new_rs485_settings div[style*="display: flex"] > div {
    flex: 1 1 30% !important;
    min-width: 100px;
}

#new_rs485_settings {
    max-height: none !important;
}

#new_rs485_settings .form-group {
    margin-bottom: 8px !important;
}


/* ================= CSS MỚI CHO 4 LOẠI CẢM BIẾN TRONG MODAL CHI TIẾT ================= */

/* 1. Bồn nước (Tank Level) */
.tank-outer {
    position: relative;
    width: 100px;
    height: 140px;
    border: 3px solid #0284c7;
    border-radius: 8px;
    background: #e2e8f0;
    overflow: hidden;
    display: flex;
    align-items: flex-end;
}

.tank-inner-water {
    width: 100%;
    background: linear-gradient(to top, #0284c7, #38bdf8);
    transition: height 0.5s ease-in-out;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* 2. Đồng hồ áp suất (Pressure Gauge) */
.pressure-gauge-outer {
    position: relative;
    width: 130px;
    height: 130px;
    border-radius: 50%;
    border: 5px solid #f59e0b;
    background: #fffbeb;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.pressure-gauge-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1; /* Đặt phần chữ số ở lớp phía dưới */
    margin-top: 50px;
}

.pressure-needle {
    position: absolute;
    bottom: 50%;
    left: calc(50% - 2px);
    width: 4px;
    height: 45px;
    background: #dc3545;
    transform-origin: bottom center;
    transition: transform 0.4s ease-in-out;
    border-radius: 2px;
    z-index: 5; /* Đặt kim đồng hồ ở lớp phía trên cao hơn chữ */
}

/* 3. Nhiệt kế (Thermometer) */
.thermometer-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin: 5px 0;
}

.thermometer-tube {
    position: relative;
    width: 20px;
    height: 120px;
    background: #e2e8f0;
    border-radius: 10px 10px 0 0;
    overflow: hidden;
    border: 2px solid #cbd5e1;
    display: flex;
    align-items: flex-end;
}

.thermometer-mercury {
    width: 100%;
    background: #ef4444;
    transition: height 0.5s ease-in-out;
}

.thermometer-bulb {
    width: 32px;
    height: 32px;
    background: #ef4444;
    border-radius: 50%;
    border: 2px solid #cbd5e1;
    margin-top: -4px;
    z-index: 2;
}

/* Giao diện khung hiển thị thiết bị phân tích (Analysis) dạng hình vuông */
.analysis-box {
    width: 150px;
    height: 130px;
    border-radius: 10px;
    border: 3px solid #8b5cf6;
    background: #f5f3ff;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    transition: border-color 0.3s ease, background 0.3s ease;
}

.analysis-val {
    font-size: 22px;
    font-weight: bold;
    color: #1e293b;
}

.analysis-unit {
    font-size: 12px;
    color: #64748b;
    font-weight: 600;
}

.analysis-progress-container {
    width: 85%;
    background: #e2e8f0;
    border-radius: 4px;
    height: 8px;
    overflow: hidden;
    position: relative;
}

.analysis-progress-bar {
    height: 100%;
    width: 0%;
    background: #8b5cf6;
    border-radius: 4px;
    transition: width 0.3s ease, background 0.3s ease;
}

.analysis-progress-label {
    font-size: 10px;
    color: #64748b;
    font-weight: 500;
}

/* Nổi bật dải viền ngoài đồng hồ áp suất */
.pressure-gauge-outer {
    position: relative;
    width: 140px;
    height: 140px;
    border-radius: 50%;
    border: 6px solid #f59e0b;
    background: #fffdf5;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    transition: border-color 0.3s ease, background 0.3s ease;
}

/* Hiệu ứng phát sáng nhấp nháy khi có cảnh báo ngưỡng Cao (Đỏ) */
@keyframes alarmPulseHigh {
    0% { box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.7); border-color: #dc3545; }
    70% { box-shadow: 0 0 0 10px rgba(220, 53, 69, 0); border-color: #dc3545; }
    100% { box-shadow: 0 0 0 0 rgba(220, 53, 69, 0); border-color: #dc3545; }
}

/* Hiệu ứng phát sáng nhấp nháy khi có cảnh báo ngưỡng Thấp (Cam) */
@keyframes alarmPulseLow {
    0% { box-shadow: 0 0 0 0 rgba(217, 119, 6, 0.7); border-color: #d97706; }
    70% { box-shadow: 0 0 0 10px rgba(217, 119, 6, 0); border-color: #d97706; }
    100% { box-shadow: 0 0 0 0 rgba(217, 119, 6, 0); border-color: #d97706; }
}

.alarm-effect-high {
    animation: alarmPulseHigh 1.5s infinite;
}

.alarm-effect-low {
    animation: alarmPulseLow 1.5s infinite;
}

/* Khung ngoài đồng hồ áp suất */
.pressure-gauge-outer {
    position: relative;
    width: 145px;
    height: 145px;
    border-radius: 50%;
    border: 6px solid #f59e0b;
    background: #f8fafc;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    transition: border-color 0.3s ease, background 0.3s ease;
}

/* Khung nền trắng bên trong đồng hồ áp suất */
.pressure-gauge-outer::before {
    content: "";
    position: absolute;
    width: 131px;
    height: 131px;
    border-radius: 50%;
    background: #ffffff;
    z-index: 1;
}

/* Vùng quạt nền hiển thị chuẩn xác ở nửa vòng trên */
.pressure-sector {
    position: absolute;
    width: 120px;
    height: 65px; /* Bằng nửa chiều rộng để tạo thành bán nguyệt nửa trên */
    top: 5.9px;
    left: 6.4px;
    border-top-left-radius: 60px;
    border-top-right-radius: 60px;
    background: rgba(245, 158, 11, 0.12);
    z-index: 2;
    transition: background 0.3s ease;
}

/* Khối hiển thị số ở tâm */
.pressure-gauge-center {
    position: relative;
    z-index: 3;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 45px;
}

/* Kim đồng hồ định vị chính xác tại tâm và hướng lên */
.pressure-needle {
    position: absolute;
    width: 3px;
    height: 52px;
    background: #f59e0b;
    top: 50%;
    left: 50%;
    /* Gốc xoay nằm ở đuôi kim (chính giữa tâm đồng hồ) */
    transform-origin: 50% 100%;
    transform: translate(-50%, -100%) rotate(-90deg);
    transition: transform 0.3s ease, background 0.3s ease;
    z-index: 4;
    border-radius: 2px;
}




/* Tổng thể hiện đại */
.modern-settings-card {
    max-width: 600px;
    margin: 0px auto;
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    border: 1px solid #e2e8f0;
}

.settings-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 20px;
    color: #0284c7;
    border-bottom: 1px solid #f1f5f9;
    padding-bottom: 10px;
}

.account-info-box {
    margin-bottom: 24px;
    background: #f8fafc;
    padding: 16px;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
}

.box-subtitle {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 12px;
    color: #334155;
}

.info-row {
    margin-bottom: 8px;
    font-size: 13px;
    color: #64748b;
}

.info-row strong {
    color: #0f172a;
}

/* Kiểu dáng input hiện đại chung */
.modern-input {
    width: 100%;
    padding: 8px;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    font-size: 13px;
    box-sizing: border-box;
    transition: all 0.2s ease;
    outline: none;
    background-color: #fff;
}

.modern-input:focus {
    border-color: #0284c7;
    box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.15);
}

.modern-select {
    cursor: pointer;
}



/* Nút bấm giao diện */
.modern-btn-save {
    background-color: #10b981 !important;
    color: white;
    border: none;
    padding: 8px;
    border-radius: 4px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.modern-btn-save:hover {
    background-color: #059669 !important;
}

.modern-btn-cancel {
    background-color: #e2e8f0 !important;
    color: #475569;
    border: none;
    padding: 8px 12px;
    border-radius: 4px;
    font-weight: 500;
    cursor: pointer;
}

.modern-btn-cancel:hover {
    background-color: #cbd5e1 !important;
}

/* Modal tuỳ chỉnh */
.modern-modal-backdrop {
    background: rgba(15, 23, 42, 0.6) !important;
    backdrop-filter: blur(4px);
}

.modern-modal-box {
    max-width: 480px !important;
    border-radius: 8px !important;
    overflow: hidden;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    border: none !important;
    padding: 0 !important;
}

.modern-modal-header {
    padding: 18px 24px !important;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    font-weight: 600;
}

.modern-modal-backdrop .modal-body {
    padding: 2px 20px;
}

.modern-modal-footer {
    padding: 16px 24px !important;
    background: #f8fafc;
    border-top: 1px solid #e2e8f0;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}









/* ================= CSS RESPONSIVE CHO NHÓM THIẾT BỊ TRÊN DASHBOARD ================= */
.dashboard-groups-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr); /* Mặc định 2 nhóm trên 1 hàng */
    gap: 15px;
}

.device-group-box {
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.02);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.device-group-header {
    background: #f1f5f9;
    padding: 8px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #cbd5e1;
}

.device-group-body {
    padding: 0;
    flex-grow: 1;
}

/* Tự động co dãn thành 1 cột duy nhất trên màn hình điện thoại hoặc máy tính bảng nhỏ (< 992px) */
@media screen and (max-width: 992px) {
    .dashboard-groups-grid {
        grid-template-columns: 1fr; /* 1 nhóm trên 1 hàng */
    }
}






/* ================= TỰ ĐỘNG CO DÃN FULL 100% TRÊN MỌI THIẾT BỊ ================= */
.dashboard-groups-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    width: 100%;
    box-sizing: border-box;
}

.device-group-box {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    overflow: hidden;
}

.device-group-body {
    width: 100% !important;
    box-sizing: border-box;
    overflow-x: hidden; /* Ngăn chặn cuộn ngang gây lệch khung */
}

.device-group-body table {
    width: 100% !important;
    max-width: 100% !important;
    table-layout: auto !important;
    border-collapse: collapse;
}

/* GIAO ĐIỆN ĐIỆN THOẠI */
@media screen and (max-width: 768px) {
    .dashboard-groups-grid {
        grid-template-columns: 1fr !important; /* Xếp 1 cột trên điện thoại */
        gap: 10px;
        padding: 0; /* Tránh sát mép màn hình điện thoại */
    }

    .device-group-box {
        width: 100% !important;
    }

    .device-group-body table {
        width: 100% !important;
        display: table !important;
    }

    .device-group-body tr {
        display: table-row !important;
    }

    .device-group-body th, 
    .device-group-body td {
        display: table-cell !important;
        box-sizing: border-box;
    }
}

/* ================= CỐ ĐỘNG CÁC CỘT & GIÃN TÊN THIẾT BỊ TRÊN PC/MOBILE ================= */
    .device-group-body table {
        width: 100% !important;
        table-layout: fixed !important; /* Cố định cấu trúc bảng tuyệt đối */
    }

    /* 1. Cố định cứng cột STT */
    .device-group-body th:nth-child(1),
    .device-group-body td:nth-child(1) {
        width: 30px !important; 
        min-width: 30px !important;
        max-width: 30px !important;
        text-align: center !important;
        white-space: nowrap;
    }

    /* 2. Cố định cứng cột Giá trị */
    .device-group-body th:nth-child(3),
    .device-group-body td:nth-child(3) {
        width: 50px !important; 
        min-width: 50px !important;
        max-width: 50px !important;
        text-align: right !important;
        white-space: nowrap;
    }

    /* 3. Cố định cứng cột Đơn vị */
    .device-group-body th:nth-child(4),
    .device-group-body td:nth-child(4) {
        width: 50px !important; 
        min-width: 50px !important;
        max-width: 50px !important;
        text-align: center !important;
        white-space: nowrap;
    }

    /* Ép cột thứ 2 (Thông số / Tên thiết bị) tự động co dãn chiếm hết toàn bộ phần không gian còn lại */
    .device-group-body th:nth-child(2),
    .device-group-body td:nth-child(2) {
        width: 100% !important; 
    }
    
    
    





/* ================= CĂN LỀ CHUẨN XÁC 8 CỘT CHO MÁY TÍNH ================= */
@media screen and (min-width: 768px) {
    /* 1. Căn lề tiêu đề (th) tương ứng */
    table th:nth-child(1) { text-align: center !important; } /* ID */
    table th:nth-child(2) { text-align: left !important; }   /* Tên thiết bị */
    table th:nth-child(3) { text-align: center !important; } /* Loại */
    table th:nth-child(4) { text-align: center !important; } /* Tín hiệu */
    table th:nth-child(5) { text-align: right !important; }  /* Giá trị tức thời */
    table th:nth-child(6) { text-align: right !important; }  /* Giá trị tích lũy */
    table th:nth-child(7) { text-align: center !important; } /* Cập nhật */
    table th:nth-last-child(1) { text-align: center !important; } /* Thao tác */

    /* 2. Căn lề dữ liệu các ô (td) bên trong #dataTable */
    #dataTable tr td:nth-child(1) { text-align: center !important; } /* ID */
    #dataTable tr td:nth-child(2) { text-align: left !important; }   /* Tên thiết bị */
    #dataTable tr td:nth-child(3) { text-align: center !important; } /* Loại */
    #dataTable tr td:nth-child(4) { text-align: center !important; } /* Tín hiệu */
    #dataTable tr td:nth-child(5) { text-align: right !important; }  /* Giá trị tức thời */
    #dataTable tr td:nth-child(6) { text-align: right !important; }  /* Giá trị tích lũy */
    #dataTable tr td:nth-child(7) { text-align: center !important; } /* Cập nhật */
    #dataTable tr td:nth-last-child(1) { text-align: center !important; } /* Thao tác */

    
    /* 2. BẢNG QUẢN LÝ DỰ ÁN (#projectTable)     */
    /* ----------------------------------------- */
    #projectTable tr td:nth-child(1) { text-align: center !important; } /* Mã (ID) */
    #projectTable tr td:nth-child(2) { text-align: left !important; }   /* Tên dự án */
    #projectTable tr td:nth-child(3) { text-align: left !important; }   /* Mô tả */
    #projectTable tr td:nth-child(4) { text-align: center !important; } /* Ngày tạo */

    /* Ép buộc căn giữa cụm nút Chia sẻ / Sửa / Xóa trong bảng dự án */
    #projectTable tr td:nth-last-child(1),
    #projectTable tr td:nth-last-child(1) div {
        text-align: center !important;
        justify-content: center !important;
        gap: 4px;
        margin: 0 auto;
    }
    
    /* Giới hạn độ rộng cột Tên thiết bị và hiển thị dấu ... khi bị tràn */
    #dataTable td:nth-child(2) {
    max-width: 220px; /* Bạn có thể chỉnh độ rộng tùy ý (VD: 200px - 250px) */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    }
    
}

