/* File: assets/css/style.css */
:root { --primary: #0ea5e9; --primary-dark: #0284c7; --bg: #f8fafc; --sidebar: #ffffff; }
body { font-family: 'Inter', sans-serif; background-color: var(--bg); font-size: 0.9rem; color: #334155; }
.loading-overlay { position: fixed; inset: 0; background: rgba(255,255,255,0.9); z-index: 9999; display: flex; flex-direction: column; justify-content: center; align-items: center; }
.sidebar { width: 300px; background: var(--sidebar); height: 100%; overflow-y: auto; padding: 1.5rem; padding-bottom: 3rem; display: flex; flex-direction: column; border-right: 1px solid #e2e8f0; }
.canvas { flex: 1; padding: 2rem; overflow-y: auto; height: 100vh; background-color: var(--bg); }
.field-card { background: white; padding: 1rem 1.25rem; border: 1px solid #e2e8f0; border-left: 4px solid var(--primary); border-radius: 8px; margin-bottom: 1rem; position: relative; box-shadow: 0 1px 3px rgba(0,0,0,0.05); transition: 0.2s; }
.tool-btn { width: 100%; text-align: left; padding: 10px 15px; margin-bottom: 8px; border: 1px solid #e2e8f0; border-radius: 8px; background: white; font-weight: 500; transition: 0.2s; color: #475569; }
.tool-btn:hover { border-color: var(--primary); color: var(--primary); background: #f0f9ff; transform: translateX(2px); }
.table-container { max-height: calc(100vh - 200px); overflow: auto; background: white; }
.table-container table { min-width: 100%; border-collapse: separate; border-spacing: 0; }
.table-container thead th { position: sticky; top: 0; background-color: #f8f9fa !important; z-index: 10; border-bottom: 2px solid #dee2e6; white-space: nowrap; }
.sticky-left { position: sticky; left: 0; background-color: white; z-index: 5; border-right: 1px solid #e2e8f0; }
.table-container thead .sticky-left { z-index: 11; background-color: #f8f9fa !important; }
.sticky-right { position: sticky; right: 0; background-color: white; z-index: 5; border-left: 1px solid #e2e8f0; }
.table-container thead .sticky-right { z-index: 11; background-color: #f8f9fa !important; }
.text-truncate-custom { max-width: 250px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: inline-block; vertical-align: middle; }
.sort-header { cursor: pointer; user-select: none; transition: 0.2s; }
.sort-header:hover { color: var(--primary) !important; }
.btn-primary { background-color: var(--primary); border-color: var(--primary); }
.btn-primary:hover { background-color: var(--primary-dark); border-color: var(--primary-dark); }
.relation-grid-badge { cursor: pointer; transition: 0.2s; border: 1px solid #e2e8f0; }
.relation-grid-badge:hover { background-color: #f0f9ff !important; border-color: var(--primary) !important; transform: translateY(-1px); }
.nn-tag-btn { transition: 0.15s; cursor: pointer; }
.nn-tag-btn:hover:not(:disabled) { transform: scale(1.03); }
.btn-lazy-load { transition: 0.2s; background-color: #f8fafc; border: 1px solid #cbd5e1; color: #0ea5e9; }
.btn-lazy-load:hover { background-color: #e0f2fe; border-color: #0ea5e9; }

.data-sidebar { width: 70px; transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1); border-right: 1px solid #e2e8f0; display: flex; flex-direction: column; overflow: hidden; white-space: nowrap; z-index: 50; }
.data-sidebar:hover, .data-sidebar.pinned { width: 280px; box-shadow: 4px 0 15px rgba(0,0,0,0.05); }
.data-sidebar-text { opacity: 0; transition: opacity 0.2s; transition-delay: 0s; pointer-events: none; }
.data-sidebar:hover .data-sidebar-text, .data-sidebar.pinned .data-sidebar-text { opacity: 1; transition-delay: 0.15s; pointer-events: auto; }
.form-link-item { display: flex; align-items: center; padding: 14px 22px; color: #475569; text-decoration: none; transition: 0.2s; border-left: 4px solid transparent; font-size: 0.95rem; }
.form-link-item:hover { background-color: #f8fafc; color: var(--primary); }
.form-link-item.active { background-color: #f0f9ff; color: var(--primary); border-left-color: var(--primary); font-weight: 600; }
.custom-scrollbar::-webkit-scrollbar { width: 5px; }
.custom-scrollbar::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 5px; }

.lims-tabs-container { display: flex; overflow-x: auto; background: #e2e8f0; padding-top: 4px; padding-left: 4px; scrollbar-width: none; }
.lims-tabs-container::-webkit-scrollbar { display: none; }
.lims-tab { display: flex; align-items: center; gap: 6px; padding: 6px 12px; background: #f8fafc; border-radius: 6px 6px 0 0; margin-right: 2px; cursor: pointer; color: #64748b; font-size: 0.8rem; font-weight: 500; min-width: 120px; border: 1px solid transparent; border-bottom: none; transition: 0.1s; }
.lims-tab:hover { background: #f1f5f9; color: #334155; }
.lims-tab.active { background: white; color: var(--primary); font-weight: 600; box-shadow: 0 -2px 5px rgba(0,0,0,0.02); position: relative; }
.lims-tab.active::after { content: ''; position: absolute; bottom: -1px; left: 0; right: 0; height: 3px; background: white; }
.lims-tab.active::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px; background: var(--primary); border-radius: 6px 6px 0 0; }
.lims-tab-close { font-size: 1rem; opacity: 0.5; transition: 0.2s; padding: 2px; border-radius: 50%; line-height: 1; display: flex; align-items: center; justify-content: center; }
.lims-tab-close:hover { opacity: 1; background: #fee2e2; color: #ef4444; }
.dropdown-col-item { padding: 6px 16px; cursor: pointer; transition: 0.15s; user-select: none; }
.dropdown-col-item:hover { background-color: #f8fafc; color: var(--primary); }

/* ==============================================================
   TỐI ƯU HÓA DI ĐỘNG CHUYÊN SÂU CHO PHÂN HỆ DỮ LIỆU (USER VIEW)
   ============================================================== */

@media (max-width: 768px) {
/* 1. XỬ LÝ SIDEBAR TRÊN MOBILE (Thiết kế & Dữ liệu) */
@media (max-width: 768px) {
    /* Ép Sidebar Admin (Thiết kế) nổi lên trên cùng */
    .sidebar {
        position: fixed;
        left: -300px;
        top: 64px;
        z-index: 1040 !important; /* Thượng phương bảo kiếm đè mọi Canvas */
        transition: left 0.3s ease-in-out;
        background-color: white; /* Đảm bảo không bị xuyên thấu */
        height: calc(100vh - 64px) !important;
    }
    .sidebar.show-mobile { 
        left: 0; 
        width: 85% !important; 
        max-width: 320px; 
        box-shadow: 5px 0 15px rgba(0,0,0,0.1); 
    }
    
    /* Ép Sidebar User (Dữ liệu) nổi lên trên cùng */
    .data-sidebar {
        position: fixed;
        left: -280px;
        top: 64px;
        height: calc(100vh - 64px) !important;
        width: 280px !important;
        z-index: 1040 !important; /* Thượng phương bảo kiếm đè mọi Data Grid */
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: 5px 0 15px rgba(0,0,0,0.1);
        background-color: white;
    }
    .data-sidebar.show-mobile { transform: translateX(280px); }
    .data-sidebar-text { opacity: 1 !important; pointer-events: auto !important; }
}

/* 2. CHUYỂN ĐỔI BẢNG THÀNH DẠNG THẺ (CARD VIEW) - Áp dụng cả bảng cha và con */
    .table-container table, 
    .table-container thead, 
    .table-container tbody, 
    .table-container th, 
    .table-container td, 
    .table-container tr { display: block; }
    
    /* Giấu Header bảng ngang */
    .table-container thead tr { position: absolute; top: -9999px; left: -9999px; }
    
    /* Style Card cho mỗi hàng */
    .table-container tr { 
        border: 2px solid #e2e8f0; 
        border-radius: 12px; 
        margin-bottom: 1.5rem; 
        background: #ffffff; 
        padding-bottom: 12px; 
        box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
        overflow: hidden;
    }
    
    /* Gỡ ghim cột trên Mobile */
    .sticky-left, .sticky-right { 
        position: relative !important; 
        left: auto !important; 
        right: auto !important; 
        background-color: transparent !important;
    }

    /* Cấu hình hiển thị Tên Cột và Dữ Liệu */
    .table-container td { 
        border: none; 
        border-bottom: 1px solid #f1f5f9; 
        position: relative; 
        padding: 12px 16px 12px 42% !important; /* Dành chỗ cho nhãn ở bên trái */
        text-align: right !important; 
        min-height: 48px;
        display: flex;
        justify-content: flex-end;
        align-items: center;
        word-break: break-word;
        font-size: 0.95rem;
    }
    
    /* Hiển thị Nhãn Cột (được nhúng qua thuộc tính data-label) */
    .table-container td:before { 
        content: attr(data-label); 
        position: absolute; 
        left: 16px; 
        width: 35%; 
        padding-right: 10px; 
        white-space: normal; 
        text-align: left; 
        font-weight: 600; 
        color: #94a3b8; 
        font-size: 11px; 
        text-transform: uppercase;
        top: 50%; 
        transform: translateY(-50%);
    }

    /* Tinh chỉnh đặc biệt cho cột ID đầu tiên (Làm nổi bật Header của Card) */
    .table-container td.sticky-left {
        background-color: #f8fafc !important;
        border-bottom: 2px solid #e2e8f0;
        font-size: 1rem !important;
        color: var(--primary) !important;
    }

    /* Tinh chỉnh cột Nút bấm (Tác vụ / Mở rộng) */
    .table-container td:last-child {
        text-align: center !important; 
        padding: 16px !important; 
        border-bottom: none;
        justify-content: center;
        background-color: #fafafa;
    }
    .table-container td:last-child:before { content: none; }
    
    /* Nút trên Mobile bự ra để dễ chạm */
    .table-container .btn-group > .btn, 
    .table-container .btn-sm {
        padding: 8px 16px;
        font-size: 0.95rem;
    }

    /* Bảng chi tiết (Ngăn kéo) thu gọn padding */
    .p-4.bg-light.shadow-inner { padding: 16px !important; }

    /* Thu nhỏ Sidebar Admin trên Mobile khi mở ra */
    .sidebar {
        position: fixed; left: -300px; top: 64px; z-index: 1040; transition: 0.3s;
    }
    .sidebar.show-mobile { 
        left: 0; 
        width: 85% !important;
        max-width: 320px;
        box-shadow: 5px 0 15px rgba(0,0,0,0.1); 
    }
}

/* Sửa lỗi tiêu đề nhảy dòng trên Web PC */
.table-container thead th { 
    white-space: nowrap !important;
}

/* 3. TỐI ƯU MODAL NHẬP LIỆU (MOBILE) */
@media (max-width: 768px) {
    /* Phóng to ô nhập liệu để dễ chạm và chặn iOS Auto-Zoom */
    .modal-body .form-control, 
    .modal-body .form-select,
    .modal-body input {
        min-height: 48px;
        font-size: 16px !important; 
    }
    
    /* Giao diện nút ở đáy modal: Nằm ngang, thu gọn và căn phải */
    .modal-footer { 
        flex-direction: row !important; 
        flex-wrap: nowrap; 
        gap: 12px; 
        justify-content: flex-end !important; 
    }
    .modal-footer .btn {
        width: auto !important; /* Gỡ bỏ chiều dài 100% */
        min-width: 120px; /* Chiều rộng tối thiểu để dễ bấm bằng ngón tay */
        min-height: 48px;
        margin: 0;
    }
}
