/* ==========================================================================
   GIAO DIỆN BÁO GIÁ (MATERIAL DESIGN 3) - PHILO SALES CRM
========================================================================== */
.philo-md3-quote-layout { display: flex; gap: 24px; align-items: flex-start; max-width: 1200px; margin: 0 auto; font-family: 'Roboto', 'Segoe UI', Arial, sans-serif; box-sizing: border-box; }
.philo-md3-quote-layout * { box-sizing: border-box; }

/* Khối Báo giá chính */
.philo-md3-quote-card { flex: 1; background: #ffffff; border-radius: 24px; padding: 40px; box-shadow: 0 4px 8px 3px rgba(0,0,0,0.03), 0 1px 3px rgba(0,0,0,0.05); border: 1px solid #eef2f6; color: #1f1f1f; line-height: 1.6; position: relative; z-index: 1; width: 100%; }

/* Header Báo giá */
.pq-md3-header { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 24px; }
.pq-md3-logo { max-width: 250px; }
.pq-md3-logo img { display: block; max-width: 100%; height: auto; max-height: 60px; object-fit: contain; }
.pq-md3-company-info { text-align: right; font-size: 14px; color: #44474e; }
.pq-md3-divider { border: 0; border-top: 2px solid #eef2f6; margin-bottom: 32px; }

/* Tiêu đề */
.pq-md3-title-sec { text-align: center; margin-bottom: 40px; }
.pq-md3-title-sec h2 { margin: 0 0 8px 0; font-size: 28px; text-transform: uppercase; font-weight: 800; color: #041e49; letter-spacing: 0.5px; }
.pq-md3-title-sec p { margin: 0; color: #74777f; font-weight: 600; font-size: 15px; }

/* Grid Thông tin 2 cột */
.pq-md3-info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; margin-bottom: 40px; background: transparent; padding: 24px; border-radius: 20px; border: 1px solid #eef2f6; }
.pq-md3-col h4 { margin: 0 0 12px 0; color: #0b57d0; font-size: 14px; text-transform: uppercase; font-weight: 700; letter-spacing: 0.5px; }
.pq-md3-col-title { font-size: 20px; font-weight: 800; margin-bottom: 16px; display: block; color: #1f1f1f; }
.pq-md3-col p { display: flex; margin: 0 0 8px 0; font-size: 14px; color: #44474e; }
.pq-md3-col p span:first-child { width: 100px; font-weight: 600; flex-shrink: 0; }
.pq-md3-col p span:last-child { color: #1f1f1f; }

/* Nội dung văn bản (WYSIWYG) */
.pq-md3-wysiwyg { margin-bottom: 40px; font-size: 15px; color: #44474e; }
.pq-md3-wysiwyg h4 { color: #041e49; font-size: 18px; margin: 24px 0 12px 0; font-weight: 700; }
.pq-md3-wysiwyg ul, .pq-md3-wysiwyg ol { padding-left: 20px; margin-bottom: 16px; }
.pq-md3-wysiwyg li { margin-bottom: 8px; }

/* Bảng Chi phí (Table) */
.pq-md3-table-responsive { width: 100%; overflow-x: auto; margin-bottom: 40px; border-radius: 16px; border: 1px solid #eef2f6; }
.pq-md3-table { width: 100%; border-collapse: collapse; min-width: 600px; }
.pq-md3-table th { background: transparent; color: #041e49; padding: 16px; text-align: left; font-weight: 700; font-size: 14px; border-bottom: 2px solid #c2e7ff; }
.pq-md3-table td { padding: 16px; border-bottom: 1px solid #eef2f6; color: #1f1f1f; font-size: 15px; }
.pq-md3-table tfoot td { background: #f8fafd; font-size: 16px; color: #1f1f1f; border-top: 2px solid #eef2f6; }
.pq-md3-table tfoot td:last-child { color: #b3261e; font-size: 20px; font-weight: 800; }

/* Khu vực Ký duyệt */
.pq-md3-sign-area { margin-top: 40px; border-top: 1px dashed #c2e7ff; padding-top: 32px; display: flex; flex-direction: column; align-items: flex-end; }
.pq-md3-sign-title { font-size: 16px; color: #1f1f1f; font-weight: 700; margin: 0 0 8px 0; width: 100%; text-align: right;}
.pq-md3-sign-desc { font-size: 14px; color: #74777f; margin: 0 0 20px 0; width: 100%; text-align: right;}
.pq-md3-canvas-box { border: 2px dashed #a8c7fa; background: #fdfdfd; border-radius: 16px; width: 100%; max-width: 400px; margin-bottom: 16px; overflow: hidden; }

/* Nút bấm (dùng chung) */
.pq-md3-actions { display: flex; justify-content: flex-end; gap: 16px; align-items: center; width: 100%; }
.pq-md3-btn { padding: 12px 24px; border-radius: 100px; font-weight: 600; font-size: 15px; cursor: pointer; border: none; transition: all 0.2s; display: inline-flex; align-items: center; gap: 8px; text-decoration: none; }
.pq-md3-btn-primary { background: #0b57d0; color: #ffffff; }
.pq-md3-btn-primary:hover { background: #0842a0; transform: translateY(-2px); box-shadow: 0 4px 8px rgba(11, 87, 208, 0.2); }
.pq-md3-btn-tonal { background: #f9dedc; color: #410e0b; }
.pq-md3-btn-tonal:hover { background: #f2b8b5; }
.pq-md3-btn-warning { background: #ffb900; color: #000000; }
.pq-md3-btn-warning:hover { background: #e5a600; transform: translateY(-2px); box-shadow: 0 4px 8px rgba(255, 185, 0, 0.2); }

/* Sidebar Chat MD3 */
.philo-md3-chat-sidebar { width: 360px; background: #ffffff; border: 1px solid #eef2f6; border-radius: 24px; position: sticky; top: 40px; display: flex; flex-direction: column; height: 650px; box-shadow: 0 4px 8px 3px rgba(0,0,0,0.03); overflow: hidden; flex-shrink: 0; }
.pq-md3-chat-header { background: #f0f6fc; color: #041e49; padding: 20px 24px; font-weight: 700; border-bottom: 1px solid #eef2f6; font-size: 16px; display: flex; justify-content: space-between; align-items: center; }
.pq-md3-chat-body { flex: 1; padding: 24px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; background: #fdfdfd; }
.pq-md3-chat-footer { padding: 16px 24px; border-top: 1px solid #eef2f6; background: #ffffff; }

/* ==========================================================================
   CSS IN ẤN (TỐI ƯU KHẮC PHỤC LỖI TRẮNG TRANG & CẮT NỘI DUNG)
========================================================================== */
@media print {
    @page { margin: 15mm; }
    html, body { background: #fff !important; margin: 0 !important; padding: 0 !important; }
    
    /* Ẩn các phần tử không cần thiết khi in */
    #wpadminbar, header, footer, nav, aside, #header, #footer, .philo-md3-chat-sidebar, .philo-no-print { display: none !important; }
    
    /* Reset Layout cha để tương thích trình in */
    .philo-md3-quote-layout { display: block !important; margin: 0 !important; padding: 0 !important; max-width: 100% !important; }
    .philo-md3-quote-card { position: relative !important; width: 100% !important; margin: 0 !important; padding: 0 !important; border: none !important; box-shadow: none !important; }
    
    /* Watermark được đưa xuống background (z-index: -1) để không đè layout */
    .philo-md3-quote-card::before { 
        content: "PHILO CREATIVE"; 
        position: fixed; 
        top: 50%; 
        left: 50%; 
        transform: translate(-50%, -50%) rotate(-45deg); 
        font-size: 80px; 
        font-weight: 900; 
        color: #000; 
        opacity: 0.03; 
        z-index: -1; 
        pointer-events: none; 
        white-space: nowrap; 
    }
    
    /* KHẮC PHỤC LỖI GRID: Chuyển sang Flex để in không bị lỗi khoảng trắng */
    .pq-md3-info-grid { 
        display: flex !important; 
        gap: 20px !important; 
        padding: 15px !important; 
        margin-bottom: 24px !important; 
        page-break-inside: avoid !important;
    }
    .pq-md3-col { flex: 1 !important; width: 50% !important; }
    
    /* KHẮC PHỤC LỖI NGẮT TRANG: Chỉ áp dụng cho khối thật sự cần */
    table, tr, img, .pq-md3-canvas-box { 
        /*page-break-inside: avoid !important; */
        /*break-inside: avoid !important; */
    }
    h1, h2, h3, h4, h5, h6 { 
        page-break-after: avoid !important; 
        break-after: avoid !important; 
    }
    
    /* Thu gọn khoảng cách để tiết kiệm giấy in */
    .pq-md3-title-sec { margin-bottom: 20px !important; }
    .pq-md3-wysiwyg { margin-bottom: 20px !important; }
    .pq-md3-table-responsive { margin-bottom: 20px !important; }
    .pq-md3-table td, .pq-md3-table th { padding: 10px !important; }
}

@media screen and (max-width: 992px) {
    .philo-md3-quote-layout { flex-direction: column; }
    .philo-md3-quote-card { padding: 20px; }
    .pq-md3-header { flex-direction: column; align-items: center; text-align: center; gap: 16px; }
    .pq-md3-company-info { text-align: center; }
    .pq-md3-info-grid { grid-template-columns: 1fr; gap: 24px; padding: 20px; }
    .pq-md3-actions { flex-direction: column; }
    .pq-md3-actions button { width: 100%; justify-content: center; }
    
    .philo-chat-fab { display: flex !important; position: fixed; bottom: 20px; right: 20px; width: 60px; height: 60px; border-radius: 50%; background: #0b57d0; color: white; align-items: center; justify-content: center; font-size: 28px; cursor: pointer; z-index: 999999; box-shadow: 0 4px 15px rgba(0,0,0,0.3); border: none; }
    .philo-md3-chat-sidebar { position: fixed; top: auto; bottom: 90px; right: 20px; width: calc(100% - 40px); max-width: 380px; height: 500px; max-height: 70vh; z-index: 9998; display: none; box-shadow: 0 10px 30px rgba(0,0,0,0.2); }
    .philo-md3-chat-sidebar.active { display: flex; }
}

/* ==========================================================================
   CSS TỐI ƯU KHUNG CHAT BONG BÓNG (MD3 CHAT BUBBLES)
========================================================================== */
.pq-md3-chat-body {
    display: flex;
    flex-direction: column;
    gap: 16px; 
}

/* Khung bọc tin nhắn để điều khiển vị trí bằng Flexbox */
.msg-wrapper {
    display: flex;
    flex-direction: column;
    width: 100%;
    animation: chatFadeIn 0.3s ease-in-out;
}

.msg-me {
    align-items: flex-end; /* Căn phải cho tin nhắn của mình */
}

.msg-them {
    align-items: flex-start; /* Căn trái cho tin nhắn của đối phương */
}

/* Thông tin người gửi & thời gian */
.msg-meta {
    font-size: 11px;
    color: #74777f;
    margin-bottom: 4px;
    font-weight: 500;
}

/* Kiểu dáng chung của bong bóng chat */
.msg-bubble {
    padding: 10px 16px;
    font-size: 14px;
    line-height: 1.5;
    max-width: 85%;
    word-wrap: break-word;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

/* Tin nhắn của mình (Màu Primary) */
.msg-me .msg-bubble {
    background-color: #0b57d0; 
    color: #ffffff;
    border-radius: 20px 20px 4px 20px; /* Cạnh dưới bên phải nhọn theo MD3 */
}

/* Tin nhắn của đối phương (Màu Surface Variant) */
.msg-them .msg-bubble {
    background-color: #f0f6fc; 
    color: #1f1f1f;
    border: 1px solid #eef2f6;
    border-radius: 20px 20px 20px 4px; /* Cạnh dưới bên trái nhọn theo MD3 */
}

/* Căn giữa hiển thị trạng thái chưa có tin nhắn */
.pq-md3-empty-chat {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    height: 100%;
    color: #74777f;
    font-size: 14px;
}
.pq-md3-empty-chat .icon {
    font-size: 32px;
    background: #f0f6fc;
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    margin-bottom: 12px;
}

/* Animation Gõ phím (Typing Indicator) */
.typing-bubble {
    display: flex !important;
    gap: 4px;
    align-items: center;
    padding: 14px 16px !important;
}
.philo-dot {
    width: 6px;
    height: 6px;
    background-color: #74777f;
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out both;
}
.philo-dot:nth-child(1) { animation-delay: -0.32s; }
.philo-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingBounce {
    0%, 80%, 100% { transform: scale(0); opacity: 0.5; }
    40% { transform: scale(1); opacity: 1; }
}

@keyframes chatFadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}
/* ==========================================================================
   V1.0.3: TỐI ƯU HIỂN THỊ BẢNG (TABLE) TRONG NỘI DUNG WYSIWYG - MD3 (Bổ sung viền cột)
========================================================================== */
/* Đặt lại cấu trúc bảng chung */
.pq-md3-wysiwyg table {
    width: 100%;
    border-collapse: separate; /* Dùng separate để viền bo góc hoạt động tốt */
    border-spacing: 0;
    margin: 24px 0;
    background-color: transparent;
    border-radius: 16px; /* Bo góc mượt mà theo chuẩn MD3 */
    overflow: hidden;
    border: 1px solid #eef2f6; /* Viền ngoài màu Outline Variant */
}

/* Tiêu đề cột (Table Header) */
.pq-md3-wysiwyg th {
    background-color: #f8fafd; /* Màu nền Surface rất nhẹ */
    color: #041e49; /* Màu chữ Primary */
    font-weight: 700;
    text-align: left;
    padding: 16px;
    font-size: 15px;
    border-bottom: 2px solid #eef2f6; /* Viền dưới đậm hơn để tách biệt header */
    border-right: 1px solid #eef2f6; /* Viền dọc phân tách các cột */
}

/* Ô dữ liệu (Table Data) */
.pq-md3-wysiwyg td {
    padding: 16px;
    color: #1f1f1f; /* Màu chữ On Surface */
    font-size: 15px;
    border-bottom: 1px solid #eef2f6; /* Dải phân cách ngang */
    border-right: 1px solid #eef2f6; /* Viền dọc phân tách các cột */
    vertical-align: top;
    line-height: 1.6;
}

/* Fix viền đôi: Bỏ viền phải của cột cuối cùng */
.pq-md3-wysiwyg th:last-child,
.pq-md3-wysiwyg td:last-child {
    border-right: none;
}

/* Fix viền đôi: Bỏ viền dưới cùng của dòng cuối cùng */
.pq-md3-wysiwyg tr:last-child td {
    border-bottom: none;
}

/* Hiệu ứng hover cho dòng (Tùy chọn cho Desktop) */
.pq-md3-wysiwyg tbody tr {
    transition: background-color 0.2s ease;
}
.pq-md3-wysiwyg tbody tr:hover {
    background-color: #fcfcfc;
}

/* Responsive: Cho phép bảng cuộn ngang trên điện thoại */
@media screen and (max-width: 768px) {
    .pq-md3-wysiwyg {
        overflow-x: auto;
    }
    .pq-md3-wysiwyg table {
        min-width: 600px; /* Đảm bảo bảng không bị bóp méo quá đà trên mobile */
    }
}