/* =======================================================
   MACORNER VIDEO HUB - MODERN MINIMALIST SAAS THEME
======================================================== */

:root {
    /* Core Brand Colors */
    --primary: #ea580c;        /* Macorner Orange */
    --primary-hover: #c2410c;
    --primary-light: #fff7ed;
    --primary-border: #fed7aa;

    /* Backgrounds & Surfaces */
    --bg-body: #f8fafc;        /* Slate 50 - Very clean off-white */
    --bg-surface: #ffffff;     /* Pure white cards */
    --bg-sidebar: #ffffff;     /* White sidebar for minimalist look */
    
    /* Text Colors */
    --text-main: #0f172a;      /* Slate 900 */
    --text-body: #334155;      /* Slate 700 */
    --text-muted: #64748b;     /* Slate 500 */
    
    /* Borders & Accents */
    --border-light: #e2e8f0;   /* Slate 200 */
    --border-divider: #f1f5f9; /* Slate 100 */
    
    /* Layout Variables */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.03);
    --shadow-card: 0 4px 6px -1px rgb(0 0 0 / 0.02), 0 2px 4px -2px rgb(0 0 0 / 0.02);
    --shadow-dropdown: 0 10px 15px -3px rgb(0 0 0 / 0.05), 0 4px 6px -4px rgb(0 0 0 / 0.025);
    
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
}

/* ================== RESET & BASE ================== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-body);
    display: flex;
    height: 100vh;
    overflow: hidden;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* Custom Scrollbar Minimalist */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ================== SIDEBAR ================== */
.sidebar {
    width: 260px;
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
    z-index: 50;
}

.logo {
    padding: 32px 24px;
    font-size: 20px;
    font-weight: 800;
    letter-spacing: -0.5px;
    margin-bottom: 8px;
}

.brand-emphasis {
    color: var(--primary);
}

.brand-sub {
    color: var(--text-main);
}

.sidebar nav {
    flex: 1;
    padding: 0 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.nav-item {
    padding: 12px 16px;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-muted);
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 12px;
}

.nav-item i {
    font-size: 20px;
}

.nav-item:hover {
    background-color: var(--bg-body);
    color: var(--text-main);
}

.nav-item.active {
    background-color: var(--primary-light);
    color: var(--primary);
    font-weight: 600;
}

/* ================== MAIN CONTENT AREA ================== */
.main-content {
    flex: 1;
    overflow-y: auto;
    position: relative;
}

.main-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 40px;
}

.view-pane {
    display: none;
    animation: fadeIn 0.3s ease;
}
.view-pane.active { display: block; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ================== HEADERS & TITLES ================== */
.top-nav {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 32px;
}

.top-nav h2 {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-main);
    letter-spacing: -0.5px;
    margin-bottom: 4px;
}

.subtitle {
    color: var(--text-muted);
    font-size: 14px;
}

.text-primary { color: var(--primary); }

.section-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.card-title {
    display: flex;
    align-items: center;
    gap: 12px;
}

.card-title h3 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-main);
}

.step-badge {
    width: 28px;
    height: 28px;
    background: var(--primary-light);
    color: var(--primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
}

/* ================== CARDS ================== */
.card {
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    padding: 32px;
    margin-bottom: 24px;
    box-shadow: var(--shadow-card);
    border: 1px solid var(--border-light);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-header-flex {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.card-header-flex h3 { margin-bottom: 0; }

.info-badge {
    background: var(--bg-body);
    padding: 4px 10px;
    border-radius: 99px;
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
}

/* ================== BUTTONS ================== */
.btn-primary {
    background-color: var(--primary);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 2px 4px rgba(234, 88, 12, 0.2);
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(234, 88, 12, 0.3);
}

.btn-primary:disabled {
    background-color: #cbd5e1;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn-secondary {
    background-color: var(--bg-surface);
    color: var(--text-main);
    border: 1px solid var(--border-light);
    padding: 10px 20px;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    box-shadow: var(--shadow-sm);
}

.btn-secondary:hover {
    background-color: var(--bg-body);
    border-color: #cbd5e1;
}

/* ================== SEARCH BAR ================== */
.search-bar {
    display: flex;
    gap: 16px;
    align-items: center;
    position: relative;
    margin-top: 20px;
}

.search-icon {
    position: absolute;
    left: 16px;
    color: #94a3b8;
    font-size: 20px;
}

.search-bar input[type="text"] {
    flex: 1;
    padding: 14px 16px 14px 48px;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    font-size: 15px;
    outline: none;
    transition: all 0.2s;
    font-family: inherit;
    background: var(--bg-surface);
    box-shadow: var(--shadow-sm);
}

.search-bar input[type="text"]:focus {
    border-color: var(--primary-border);
    box-shadow: 0 0 0 4px rgba(251, 146, 60, 0.1);
}

/* ================== TABS ================== */
.tab-container {
    display: flex;
    gap: 8px;
    margin-top: 20px;     
    margin-bottom: 24px;
    border-bottom: 1px solid var(--border-light);
    padding-bottom: 16px;
    overflow-x: auto;
}

.tab-btn {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid transparent;
    padding: 8px 16px;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.2s;
    white-space: nowrap;
}

.tab-btn:hover {
    color: var(--text-main);
    background: var(--bg-body);
}

.tab-btn.active {
    background: var(--primary-light);
    color: var(--primary);
}

.tab-pane { display: none; animation: fadeIn 0.2s ease; }
.tab-pane.active { display: block; }

/* ================== TABLES ================== */
.table-container {
    width: 100%;
    overflow-x: auto;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-light);
    background: var(--bg-surface);
}

.table-container.no-border {
    border: none;
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    font-size: 14px;
}

th {
    background-color: var(--bg-body);
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 12px;
    letter-spacing: 0.5px;
    padding: 16px;
    border-bottom: 1px solid var(--border-light);
}

td {
    padding: 16px;
    border-bottom: 1px solid var(--border-divider);
    color: var(--text-main);
    vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background-color: #f8fafc; }

/* Highlight cho các cặp E2-E4 đã tồn tại trong History */
td.cell-history {
    background-color: var(--primary-light) !important; /* Phủ nền màu cam nhạt */
    box-shadow: inset 0 0 0 1px var(--primary-border); /* Bo viền cam tinh tế */
}

/* (Tùy chọn) Thêm một chấm nhỏ màu cam góc trên báo hiệu đã chạy */
td.cell-history::after {
    content: "";
    position: absolute;
    top: 6px;
    right: 6px;
    width: 6px;
    height: 6px;
    background-color: var(--primary);
    border-radius: 50%;
}

td {
    position: relative; /* Cần thiết để cái chấm nhỏ ở trên hiển thị đúng vị trí */
}

/* Code Boxes (E1, E2...) */
.code-box {
    display: inline-block;
    padding: 4px 10px;
    background: var(--bg-body);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 13px;
    color: var(--text-body);
    cursor: help;
    transition: all 0.2s;
}

.code-box:hover {
    background: var(--primary-light);
    color: var(--primary);
    border-color: var(--primary-border);
}

.full-code-text {
    font-family: 'JetBrains Mono', 'Courier New', monospace;
    font-weight: 700;
    color: var(--text-main);
    cursor: help;
    text-decoration: underline;
    text-decoration-style: dashed;
    text-decoration-color: #cbd5e1;
    text-underline-offset: 4px;
}

.full-code-text:hover {
    color: var(--primary);
    text-decoration-color: var(--primary);
}

.round-checkbox {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
    cursor: pointer;
}

/* ================== STATUS & EMPTY STATES ================== */
.status-tag {
    background: #f1f5f9;
    color: #475569;
    padding: 8px 16px;
    border-radius: 99px;
    font-size: 13px;
    font-weight: 600;
    border: 1px solid var(--border-light);
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.empty-state {
    padding: 60px 20px;
    text-align: center;
    color: var(--text-muted);
    background: #f8fafc;
    border-radius: var(--radius-md);
    border: 1px dashed #cbd5e1;
}

.empty-state i {
    font-size: 40px;
    margin-bottom: 16px;
    color: #cbd5e1;
}

.empty-state h4 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 8px;
}

.empty-state p {
    font-size: 14px;
}

/* ================== OVERRIDING JS INJECTED INLINE STYLES ================== */
#pb-container {
    border-radius: var(--radius-md) !important;
    border: 1px solid var(--border-light) !important;
    box-shadow: var(--shadow-sm) !important;
    padding: 24px !important;
    overflow: visible !important;
}

.prompt-builder-wrapper {
    background: #fafaf9 !important; 
    border: 1px solid var(--border-light) !important;
    box-shadow: none !important;
    border-radius: var(--radius-md) !important;
    padding: 24px !important;
}

.prompt-builder-wrapper h4 {
    color: var(--text-main) !important;
    font-size: 16px !important;
}

#gallery-container-wrap, #store-container-wrap {
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    background: transparent !important;
}

#gallery-toolbar, #store-toolbar {
    background: var(--bg-surface) !important;
    border: 1px solid var(--border-light) !important;
    box-shadow: var(--shadow-sm) !important;
    padding: 16px !important;
    border-radius: var(--radius-md) !important;
}

.gallery-card {
    border: 1px solid var(--border-light) !important;
    border-radius: var(--radius-md) !important;
    box-shadow: var(--shadow-sm) !important;
    transition: all 0.3s ease;
}
.gallery-card:hover {
    box-shadow: var(--shadow-dropdown) !important;
    transform: translateY(-4px);
}

/* ================== REFERENCE GALLERY UPLOAD (HOVER COLLAPSE) ================== */
.ref-gallery-module {
    position: relative;
    display: inline-block;
}

/* Trạng thái thu gọn (Stack) */
.ref-stack-trigger {
    position: relative;
    width: 46px;
    height: 46px;
    cursor: pointer;
    transition: transform 0.2s ease;
}
.ref-stack-trigger:hover { transform: scale(1.05); }

.ref-stack-img {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    object-fit: cover;
    border-radius: 8px;
    border: 2px solid white;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    background: #f1f5f9;
}

.ref-stack-badge {
    position: absolute;
    bottom: -6px; right: -6px;
    width: 22px; height: 22px;
    background: rgba(30, 41, 59, 0.85);
    color: white;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 13px;
    z-index: 10;
    border: 2px solid white;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

/* Menu mở rộng thả xuống (Dropdown UI) */
.ref-expanded-dropdown {
    position: absolute;
    top: calc(100% + 8px); 
    right: 0; 
    background: #1e293b; /* Dark Navy Slate */
    border-radius: 12px;
    padding: 16px;
    width: max-content;
    box-shadow: 0 10px 25px rgba(0,0,0,0.25);
    display: none; 
    z-index: 9999;
    flex-direction: column;
    gap: 16px;
}

/* CẦU NỐI TÀNG HÌNH ĐỂ GIỮ HOVER (Sửa lỗi vùng chết Dead Zone) */
.ref-expanded-dropdown::before {
    content: '';
    position: absolute;
    top: -15px; /* Phủ lên khoảng hở 8px phía trên */
    left: 0;
    width: 100%;
    height: 15px;
    background: transparent; /* Hoàn toàn vô hình */
}

/* Kích hoạt hiển thị khi rê chuột vào cả cụm module */
.ref-gallery-module:hover .ref-expanded-dropdown {
    display: flex;
}

/* Nút Local Upload trong Dropdown */
.ref-expanded-add {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #e2e8f0;
    font-size: 14px;
    cursor: pointer;
    padding: 0;
    transition: 0.2s;
}
.ref-expanded-add i { font-size: 18px; }
.ref-expanded-add:hover { color: #fff; }

/* Grid ảnh bên trong Menu */
.ref-expanded-scroll {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    max-width: 280px; 
}

.ref-expanded-thumb {
    position: relative;
    width: 60px;
    height: 60px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid #475569;
}
.ref-expanded-thumb img {
    width: 100%; height: 100%; object-fit: cover;
}
.ref-expanded-del {
    position: absolute;
    top: 0; right: 0; bottom: 0; left: 0;
    background: rgba(0,0,0,0.6);
    color: white;
    border: none;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    opacity: 0;
    transition: 0.2s;
    font-size: 20px;
}
.ref-expanded-thumb:hover .ref-expanded-del {
    opacity: 1;
}

/* ================== TOOLTIPS & MODALS ================== */
.tooltip {
    display: none;
    position: absolute;
    background: #0f172a;
    color: #f8fafc;
    padding: 16px;
    border-radius: var(--radius-md);
    font-size: 13px;
    z-index: 9999;
    max-width: 320px;
    box-shadow: var(--shadow-dropdown);
    pointer-events: none;
    line-height: 1.6;
    border: 1px solid #334155;
}

.tooltip b {
    display: block;
    color: #fed7aa;
    margin-bottom: 6px;
    font-size: 14px;
}

.tooltip i {
    color: #cbd5e1;
    font-style: normal;
}

.fullcode-preview table { background: transparent; }
.fullcode-preview th, .fullcode-preview td {
    padding: 8px 12px;
    border-bottom: 1px solid #334155;
    color: white;
}
.fullcode-preview th {
    background: rgba(255,255,255,0.05);
    color: #94a3b8;
}

.modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(15, 23, 42, 0.7);
    backdrop-filter: blur(8px);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: var(--bg-surface);
    padding: 32px;
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 700px;
    position: relative;
    box-shadow: 0 25px 50px -12px rgb(0 0 0 / 0.25);
}

.modal-close-btn {
    position: absolute;
    top: 24px; right: 24px;
    background: #f8fafc;
    border: none;
    width: 36px; height: 36px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    color: var(--text-muted);
    transition: 0.2s;
    font-size: 18px;
}

.modal-close-btn:hover {
    background: #fee2e2;
    color: #ef4444;
}

.modal-body-text {
    line-height: 1.7;
    font-size: 15px;
    color: var(--text-body);
}

/* ================== FREEZE MATRIX HEADER (DÒNG & CỘT ĐẦU) ================== */

/* 1. Giới hạn chiều cao của khung bảng để bật thanh cuộn dọc */
#matrixContainer .matrix-scroll-area {
    max-height: 65vh; /* Sếp có thể thay đổi số này (vd: 500px) để chỉnh độ dài khung hiển thị */
    overflow-y: auto;
    padding-top: 0 !important; /* Gỡ khoảng hở trên cùng để tiêu đề bám sát mí */
}

/* 2. Đóng băng dòng đầu tiên (Dòng E2) */
#matrixContainer th {
    position: sticky;
    top: 0;
    background-color: var(--bg-body) !important; /* Đổ nền đặc che nội dung cuộn bên dưới */
    z-index: 20;
    box-shadow: 0 1px 0 var(--border-light); /* Dùng bóng đổ thay cho border-bottom bị mất khi cuộn */
}

/* 3. Đóng băng cột đầu tiên (Cột E4) */
#matrixContainer td:first-child,
#matrixContainer th:first-child {
    position: sticky;
    left: 0;
    background-color: var(--bg-surface);
    z-index: 15;
    box-shadow: 1px 0 0 var(--border-light); /* Bóng đổ thay cho border-right */
}

/* 4. Đồng bộ màu nền của cột E4 khi rê chuột (Hover) ngang qua dòng */
#matrixContainer tr:hover td:first-child {
    background-color: #f8fafc; 
}

/* 5. Góc trên cùng bên trái (Ô giao điểm E4 \ E2) cần nổi lên cao nhất */
#matrixContainer th:first-child {
    z-index: 25;
    background-color: var(--bg-body) !important;
    box-shadow: 1px 1px 0 var(--border-light);
}

/* ================== PHỤC HỒI GIAO DIỆN NÚT ADD (+) MATRIX ================== */

/* Khung bao bọc cần set relative để định vị nút + */
.canva-matrix-wrapper { 
    position: relative; 
    display: inline-block; 
    min-width: 100%; 
}
.canva-matrix-wrapper table { 
    width: 100%; border-collapse: collapse; margin: 0; 
}

/* Định hình nút bấm thành hình tròn tròn nổi lên */
.canva-add-btn { 
    width: 26px; height: 26px; border-radius: 50%; background: #ffffff; 
    border: 1.5px solid #cbd5e1; color: #64748b; font-size: 18px; font-weight: 500; 
    display: flex; align-items: center; justify-content: center; cursor: pointer; 
    box-shadow: 0 2px 5px rgba(0,0,0,0.15); transition: all 0.2s ease; 
    position: absolute; z-index: 30; /* Set cao hơn sticky header để không bị đè */
    user-select: none; padding-bottom: 2px; box-sizing: border-box; 
}
.canva-add-btn:hover { 
    background: #fff7ed; color: #ea580c; border-color: #ea580c; 
    transform: scale(1.15); 
}

/* Ép vị trí nút E2 sang mép phải, căn giữa chiều dọc */
.canva-add-btn.e2-btn { 
    top: 50%; right: 0px; 
    transform: translate(50%, -50%); 
}
.canva-add-btn.e2-btn:hover { 
    transform: translate(50%, -50%) scale(1.15); 
}

/* Ép vị trí nút E4 xuống đáy, căn giữa chiều ngang */
.canva-add-btn.e4-btn { 
    bottom: 0px; left: 50%; 
    transform: translate(-50%, 50%); 
}
.canva-add-btn.e4-btn:hover { 
    transform: translate(-50%, 50%) scale(1.15); 
}

/* logout */
.logout-container {
    margin-top: auto;
    padding: 16px;
}

.logout-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-radius: 10px;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    transition: background 0.2s, color 0.2s;
}

.logout-link:hover {
    background: var(--bg-body);
    color: var(--text-main);
}

.logout-link i {
    font-size: 20px;
}