/*
resizable-layout.css: CSS cho layout resize + chatbot demo
*/
#row-content {
    display: flex;
    width: 100%;
    height: 100%;
}

.resizable-col {
    position: relative;
    background: #fafbfc;
    transition: background 0.2s;
}

.resizable-col .resize-handle {
    position: absolute;
    top: 0;
    right: -4px;
    /* Dịch sang phải để nằm giữa biên 2 cột, không che scrollbar bên trong */
    width: 8px;
    /* Thu hẹp lại chút cho tinh tế */
    height: 100%;
    cursor: col-resize;
    margin-right: 10px;
    z-index: 100;
    /* Đảm bảo nổi lên trên */
    background: transparent;
    transition: all 0.2s ease;
}

/* Visual feedback khi hover */
.resizable-col .resize-handle:hover {
    background: rgba(139, 69, 19, 0.1);
    cursor: col-resize;
}

/* Visual feedback khi active/dragging */
.resizable-col .resize-handle:active,
.resizable-col .resize-handle.dragging {
    background: rgba(139, 69, 19, 0.2);
    cursor: col-resize;
    width: 12px;
    right: -6px;
}

.resizable-col.left .resize-handle {
    right: -4px;
}

.resizable-col.middle .resize-handle {
    right: 0;
}

.resizable-col.right .resize-handle {
    left: 0;
    /* Đặt hoàn toàn bên trong cột phải để không đè lên scrollbar cột giữa */
    right: auto;
}

/* Hover effect cho cột right */
.resizable-col.right .resize-handle:hover {
    background: rgba(139, 69, 19, 0.1);
    cursor: col-resize;
}

/* Active effect cho cột right */
.resizable-col.right .resize-handle:active,
.resizable-col.right .resize-handle.dragging {
    background: rgba(139, 69, 19, 0.2);
    cursor: col-resize;
    width: 16px;
    left: 0;
}

/* Tablet responsive */
@media (min-width: 768px) and (max-width: 1024px) {
    .chatbot-box {
        max-height: calc(100vh - 80px);
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }

    .chatbot-history {
        max-height: calc(100vh - 200px);
        overflow-y: auto;
        flex: 1 1 0%;
        min-height: 0;
    }

    .chatbot-input {
        flex-shrink: 0 !important;
        position: sticky !important;
        bottom: 0 !important;
        z-index: 1000 !important;
        background: white !important;
        border-top: 1px solid #e9ecef !important;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1) !important;
        margin-top: auto !important;
        /* Tránh bị che bởi navigation bar */
        padding-bottom: env(safe-area-inset-bottom, 10px) !important;
        margin-bottom: env(safe-area-inset-bottom, 0px) !important;
    }

    /* Đảm bảo chatbot-input luôn visible trên tablet */
    .chatbot-input .input-group {
        margin-bottom: 0 !important;
    }

    /* Thêm padding bottom để tránh bị che bởi virtual keyboard và navigation bar */
    .chatbot-input {
        padding-bottom: max(env(keyboard-inset-height, 0px), env(safe-area-inset-bottom, 10px)) !important;
    }

    /* Detect navigation bar height và adjust */
    @supports (padding-bottom: env(safe-area-inset-bottom)) {
        .chatbot-input {
            padding-bottom: calc(10px + env(safe-area-inset-bottom)) !important;
        }

        .chatbot-history {
            padding-bottom: calc(20px + env(safe-area-inset-bottom)) !important;
        }
    }

    /* Fallback cho tablets không support safe-area */
    @media (pointer: coarse) and (hover: none) {
        .chatbot-input {
            margin-bottom: 60px !important;
            /* Estimate navigation bar height */
        }

        .chatbot-history {
            padding-bottom: 80px !important;
        }
    }

    /* Tối ưu resize handles cho tablet touch */
    .resizable-col .resize-handle {
        width: 20px !important;
        /* Tăng từ 12px lên 20px cho dễ touch */
        right: 0 !important;
        /* Luôn nằm trong cột */
        touch-action: pan-x;
        /* Chỉ cho phép pan ngang */
        -webkit-touch-callout: none;
        /* Tắt callout trên iOS */
        -webkit-user-select: none;
        /* Tắt text selection */
        user-select: none;
    }

    .resizable-col.right .resize-handle {
        width: 20px !important;
        left: 0 !important;
        right: auto !important;
    }

    /* Visual feedback rõ hơn cho tablet */
    .resizable-col .resize-handle:active,
    .resizable-col .resize-handle.dragging {
        width: 24px !important;
        right: 0 !important;
        background: rgba(139, 69, 19, 0.3) !important;
    }

    .resizable-col.right .resize-handle:active,
    .resizable-col.right .resize-handle.dragging {
        width: 24px !important;
        left: 0 !important;
        background: rgba(139, 69, 19, 0.3) !important;
    }
}

/* Tablet Portrait - Tối ưu đặc biệt cho tablet dọc */
@media (min-width: 768px) and (max-width: 1024px) and (orientation: portrait) {

    /* Resize handles lớn hơn cho tablet dọc */
    .resizable-col .resize-handle {
        width: 24px !important;
        /* Tăng lên 24px cho tablet dọc */
        right: 0 !important;
        background: rgba(139, 69, 19, 0.05) !important;
        /* Hiển thị nhẹ để dễ nhìn */
        border-radius: 2px;
    }

    .resizable-col.right .resize-handle {
        width: 24px !important;
        left: 0 !important;
        right: auto !important;
    }

    /* Visual feedback mạnh hơn khi touch */
    .resizable-col .resize-handle:active,
    .resizable-col .resize-handle.dragging {
        width: 28px !important;
        right: 0 !important;
        background: rgba(139, 69, 19, 0.4) !important;
        box-shadow: 0 0 8px rgba(139, 69, 19, 0.3);
    }

    .resizable-col.right .resize-handle:active,
    .resizable-col.right .resize-handle.dragging {
        left: 0 !important;
        background: rgba(139, 69, 19, 0.4) !important;
        box-shadow: 0 0 8px rgba(139, 69, 19, 0.3);
    }

    /* Tối ưu layout cho tablet dọc */
    #col-left {
        width: 12vw !important;
        min-width: 250px !important;
        max-width: 20vw !important;
    }

    #col-middle {
        min-width: 40vw !important;
        max-width: 70vw !important;
    }
}

/* Mobile responsive */
@media (max-width: 767.98px) {

    #col-left,
    #col-right {
        display: none !important;
    }

    #col-middle {
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
        height: 100vh !important;
        height: calc(var(--vh, 1vh) * 100) !important;
        overflow: hidden !important;
    }

    /* ✅ FIX: Đảm bảo chatbot-box có layout flexbox đúng trên mobile */
    .chatbot-box {
        display: flex !important;
        flex-direction: column !important;
        height: 100vh !important;
        height: calc(var(--vh, 1vh) * 100) !important;
        overflow: hidden !important;
        min-height: 0 !important;
    }

    /* ✅ FIX: chatbot-header cố định */
    .chatbot-header {
        flex-shrink: 0 !important;
        height: 45px !important;
    }

    /* ✅ FIX: chatbot-history chiếm phần còn lại, có scroll */
    .chatbot-history {
        flex: 1 !important;
        overflow-y: auto !important;
        min-height: 0 !important;
        padding-bottom: 80px !important;
        /* Tránh bị che bởi chatbot-input */
        background: #fff !important;
    }

    /* Đảm bảo chatbot-input luôn nổi ở chân trang trên mobile */
    .chatbot-input {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        z-index: 1000 !important;
        background: white !important;
        border-top: 1px solid #e9ecef !important;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1) !important;
        padding-bottom: env(safe-area-inset-bottom, 0px) !important;
        flex-shrink: 0 !important;
    }
}

/* Global cursor states cho resize */
.resizing {
    cursor: col-resize !important;
    -webkit-user-select: none;
    user-select: none;
}

.resizing * {
    cursor: col-resize !important;
    -webkit-user-select: none;
    user-select: none;
}

/* Đảm bảo resize handles luôn có cursor đúng */
.resize-handle,
.resizable-col .resize-handle {
    cursor: col-resize !important;
}

/* Chatbot UI demo - Fixed height layout */
.chatbot-box {
    min-height: 0;
    height: 100%;
}

.chatbot-header {
    background: #f8f9fa;
    height: 45px;
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.chatbot-history {
    background: #fff;
    min-height: 0;
    flex: 1 1 0%;
    overflow-y: auto;
}

.chatbot-input {
    background: #f8f9fa;
    border-top: 1px solid #FBF0E1;
    flex-shrink: 0;
}

/* Modern rounded chat input - Fixed border radius */
.chat-input-rounded {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #ffffff;
    border-radius: 20px !important;
    /* Fixed 20px cho mọi trường hợp */
    padding: 8px 10px;
    border: 1px solid rgba(0, 0, 0, 0.08);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    width: 100%;
}

.chat-input-rounded .form-control {
    border: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    outline: none !important;
    min-height: 40px;
    font-size: 0.95rem;
}

.chat-input-rounded .btn-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 0;
    background: transparent;
    color: #6c757d;
}

.chat-input-rounded .btn-icon:hover {
    background: rgba(0, 0, 0, 0.05);
    color: #495057;
}

.chat-input-rounded .btn-send {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 0;
    background: var(--brown-tone, #5D4037);
    color: #ffffff;
    box-shadow: 0 4px 10px rgba(93, 64, 55, 0.35);
}

.chat-input-rounded .btn-send i {
    font-size: 1.05rem;
    transform: rotate(0deg);
}

.chat-input-rounded .btn-send:hover {
    background: var(--brown-dark, #3E2723);
}

.chat-input-rounded:focus-within {
    border-color: var(--brown-tone, #5D4037);
    box-shadow: 0 0 0 3px rgba(93, 64, 55, 0.15);
}

.chat-input-rounded .form-control::placeholder {
    color: #9aa1a7;
    opacity: 1;
}

/* Fixed height layout cho desktop/tablet */
@media (min-width: 768px) {

    /* Cột phải cố định 300px, không cho flex-grow */
    #col-right {
        flex: 0 0 300px !important;
        width: 300px !important;
        min-width: 300px !important;
        max-width: 300px !important;
    }

    #main-layout {
        height: 100vh !important;
        overflow: hidden !important;
    }

    #row-content {
        height: 100vh !important;
        overflow: hidden !important;
    }

    #col-left,
    #col-middle,
    #col-right {
        height: 100vh !important;
        overflow: visible !important;
        /* Cho phép handle hiển thị ra ngoài biên */
    }

    .chatbot-box {
        height: 100vh !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
    }

    .chatbot-history {
        flex: 1 !important;
        overflow-y: auto !important;
        min-height: 0 !important;
        margin-bottom: 0 !important;
        padding-bottom: 10px !important;
    }

    .chatbot-input {
        flex-shrink: 0 !important;
        margin-bottom: 0 !important;
        padding-bottom: 15px !important;
        position: relative !important;
    }
}

/* Header sections cho cột trái và phải */
.col-header-section {
    height: 45px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-bottom: 1px solid #FBF0E1;
    background: #FBF0E1;
    flex-shrink: 0;
}

.col-content-section {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

/* Logo section styling */
.logo-section {
    justify-content: center;
}

.logo-section img {
    max-width: 250px;
    height: auto;
    margin: 0;
    padding: 0;
}

/* User section styling */
.user-section {
    justify-content: flex-end;
    padding-right: 15px;
}

.user-section .dropdown-toggle {
    color: #333;
    font-size: 0.9rem;
}

.user-section .dropdown-toggle:hover {
    color: #8B4513;
}

/* Đảm bảo min-width cho cột trái */
#col-left {
    min-width: 250px !important;
}

/* Navigation bar detection styles */
.has-navigation-bar .chatbot-input {
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1), 0 -60px 0 rgba(255, 255, 255, 0.9) !important;
}

.has-navigation-bar .chatbot-history {
    scroll-padding-bottom: 100px !important;
}

/* Tablet navigation bar specific adjustments */
@media (min-width: 768px) and (max-width: 1024px) {
    .has-navigation-bar .chatbot-input {
        position: fixed !important;
        bottom: 60px !important;
        /* Estimate navigation bar height */
        left: 0 !important;
        right: 0 !important;
        z-index: 1001 !important;
        margin: 0 !important;
        border-radius: 0 !important;
    }

    .has-navigation-bar #col-middle .chatbot-input {
        position: sticky !important;
        bottom: 60px !important;
        left: auto !important;
        right: auto !important;
        border-radius: 0 !important;
    }
}

/* Android tablet - Fixed height layout không cần navigation bar spacing */
@media (min-width: 768px) and (max-width: 1024px) and (pointer: coarse) {

    /* Fixed height layout - không cần extra margin cho navigation bar */
    .chatbot-input {
        margin-bottom: 0 !important;
        padding-bottom: 15px !important;
        position: relative !important;
    }

    .chatbot-history {
        padding-bottom: 10px !important;
    }

    /* Khi keyboard mở - giảm padding */
    @media (max-height: 500px) {
        .chatbot-input {
            padding-bottom: 10px !important;
        }

        .chatbot-history {
            padding-bottom: 5px !important;
        }
    }
}

/* Disable navigation bar detection cho fixed height layout */
@supports (-webkit-appearance: none) {
    @media (min-width: 768px) and (max-width: 1024px) and (pointer: coarse) {
        .chatbot-input {
            /* Fixed height layout - không cần extra spacing */
            margin-bottom: 0 !important;
            padding-bottom: 15px !important;
        }
    }
}

/* Samsung Internet và các browser khác - Fixed height */
@media (min-width: 768px) and (max-width: 1024px) and (pointer: coarse) and (hover: none) {
    .chatbot-input {
        /* Fixed height layout - minimal spacing */
        margin-bottom: 0 !important;
        padding-bottom: 15px !important;
    }

    .chatbot-history {
        padding-bottom: 10px !important;
    }
}

/* Toggle cột phải - Desktop/Tablet (≥768px = md breakpoint) */
@media (min-width: 768px) {

    /* Đảm bảo cột phải có position relative để nút absolute hoạt động */
    #col-right {
        position: relative;
        transition: all 0.3s ease-in-out;
        opacity: 1;
    }

    /* Ẩn cột phải với animation */
    body.col-right-hidden #col-right {
        width: 0 !important;
        min-width: 0 !important;
        max-width: 0 !important;
        flex: 0 0 0 !important;
        overflow: visible !important;
        /* Để nút vẫn hiển thị */
        opacity: 1;
        /* Giữ opacity để nút vẫn thấy */
        transition: all 0.3s ease-in-out;
    }

    /* Mở rộng cột giữa khi cột phải bị ẩn */
    body.col-right-hidden #col-middle {
        flex: 1 1 auto !important;
        max-width: none !important;
        transition: all 0.3s ease-in-out;
    }

    #col-middle {
        transition: all 0.3s ease-in-out;
    }

    /* Nút toggle tại border - luôn hiển thị */
    #btn-toggle-right-col {
        transition: all 0.2s ease;
        background: white !important;
        z-index: 100 !important;
        /* Thấp hơn modal (1050) */
    }

    #btn-toggle-right-col:hover {
        background: #f8f9fa !important;
        border-color: var(--brown-tone, #8B4513) !important;
        box-shadow: -2px 0 12px rgba(0, 0, 0, 0.15) !important;
    }

    /* Đổi icon khi cột phải bị ẩn */
    body.col-right-hidden #btn-toggle-right-col .bi-chevron-right::before {
        content: "\f285" !important;
        /* bi-chevron-left */
    }

    /* Di chuyển nút ra ngoài khi cột phải bị ẩn */
    body.col-right-hidden #btn-toggle-right-col {
        left: 0 !important;
        transform: translate(-80%, -50%) !important;
        /* Lùi ra ngoài thêm để luôn nhìn thấy */
    }
}