/**
 * Giao diện CSS Live Search AJAX Premium cho DoDo Wordpress All in One
 */

.dodo-search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 99999;
    margin-top: 8px;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 12px;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.1), 0 5px 15px rgba(0, 0, 0, 0.05);
    overflow: hidden;
    display: none;
    text-align: left;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
}

/* Danh sách kết quả */
.dodo-search-items-list {
    max-height: 380px;
    overflow-y: auto;
}

/* Mỗi sản phẩm trong danh sách */
.dodo-search-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.04);
    text-decoration: none !important;
    color: #2d3748 !important;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.dodo-search-item:last-child {
    border-bottom: none;
}

.dodo-search-item:hover {
    background: rgba(230, 91, 32, 0.04);
}

/* Ảnh sản phẩm */
.dodo-search-item-image {
    width: 48px;
    height: 48px;
    border-radius: 8px;
    overflow: hidden;
    margin-right: 14px;
    border: 1px solid rgba(0, 0, 0, 0.06);
    background: #f7fafc;
    flex-shrink: 0;
}

.dodo-search-item-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.dodo-search-item:hover .dodo-search-item-image img {
    transform: scale(1.08);
}

/* Thông tin sản phẩm */
.dodo-search-item-info {
    flex: 1;
    min-width: 0; /* Khắc phục lỗi bóp méo flexbox, cho phép ellipsis hoạt động */
}

.dodo-search-item-title {
    font-size: 14.5px;
    font-weight: 600;
    color: #2d3748;
    line-height: 1.4;
    margin-bottom: 4px;
    white-space: normal; /* Cho phép xuống dòng tự nhiên */
    display: -webkit-box;
    -webkit-line-clamp: 2; /* Giới hạn tối đa 2 dòng tên sản phẩm */
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    word-break: break-word;
}

/* Khối meta chứa Giá và SKU ngay dưới tiêu đề */
.dodo-search-item-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
    margin-top: 4px;
}

.dodo-search-item-sku {
    font-size: 11px;
    color: #718096;
    background: #edf2f7;
    padding: 1px 6px;
    border-radius: 4px;
}

/* Trạng thái hết hàng */
.dodo-search-item-stock.out-of-stock {
    display: inline-block;
    font-size: 10px;
    font-weight: 600;
    color: #e53e3e;
    background: rgba(229, 62, 62, 0.1);
    padding: 1px 6px;
    border-radius: 4px;
    margin-top: 4px;
}

/* Giá sản phẩm */
.dodo-search-item-price {
    font-size: 14px;
    font-weight: 700;
    color: #e65b20;
    white-space: nowrap;
}

.dodo-search-item-price del {
    font-size: 12px;
    color: #a0aec0;
    font-weight: normal;
    margin-right: 6px;
    display: inline-block;
}

.dodo-search-item-price ins {
    text-decoration: none;
    background: transparent;
}

/* Làm nổi bật từ khóa */
.dodo-highlight {
    background: rgba(230, 91, 32, 0.12);
    color: #e65b20;
    font-weight: 700;
    padding: 1px 3px;
    border-radius: 3px;
}

/* Trạng thái tải và rỗng */
.dodo-search-loading,
.dodo-search-no-results {
    padding: 24px 16px;
    text-align: center;
    color: #718096;
    font-size: 13.5px;
}

.dodo-search-no-results strong {
    color: #2d3748;
}

/* Spinner quay tròn */
.dodo-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(230, 91, 32, 0.15);
    border-radius: 50%;
    border-top-color: #e65b20;
    animation: dodo-spin 0.8s linear infinite;
    margin-right: 8px;
    vertical-align: -2px;
}

@keyframes dodo-spin {
    to { transform: rotate(360deg); }
}

/* Dropdown footer */
.dodo-search-footer {
    background: #f7fafc;
    padding: 10px 16px;
    border-top: 1px solid rgba(0, 0, 0, 0.04);
    text-align: center;
}

.dodo-search-footer a {
    display: block;
    color: #e65b20 !important;
    font-size: 12.5px;
    font-weight: 600;
    text-decoration: none !important;
    transition: color 0.2s ease;
}

.dodo-search-footer a:hover {
    color: #c04512 !important;
}

/* Custom thanh cuộn */
.dodo-search-items-list::-webkit-scrollbar {
    width: 6px;
}

.dodo-search-items-list::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.02);
}

.dodo-search-items-list::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 3px;
}

.dodo-search-items-list::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.2);
}

/* Responsive cho thiết bị di động */
@media (max-width: 768px) {
    .dodo-search-results {
        border-radius: 8px;
        box-shadow: 0 10px 25px rgba(0,0,0,0.1);
    }
    
    .dodo-search-item {
        padding: 10px 12px;
    }
    
    .dodo-search-item-image {
        width: 40px;
        height: 40px;
        margin-right: 10px;
    }
    
    .dodo-search-item-title {
        font-size: 13px;
    }
    
    .dodo-search-item-price {
        font-size: 12.5px;
    }
}

/* Giao diện shortcode form tìm kiếm sản phẩm - Mẫu Ly Champagne */
.dodo-search-form-wrapper {
    width: 100%;
    max-width: 100%; /* Luôn chiếm 100% width của cột cha */
    margin: 0 auto;
}

@media (min-width: 768px) {
    .dodo-search-form-wrapper {
        min-width: 380px; /* Ép chiều rộng tối thiểu trên Desktop để thanh tìm kiếm rộng rãi, cân đối */
    }
}

.dodo-searchform-container {
    position: relative;
    margin: 0;
    width: 100%;
}

.dodo-search-input-group {
    display: flex;
    align-items: center; /* Căn giữa nút tròn theo chiều dọc */
    position: relative;
    border: 1px solid rgba(220, 200, 180, 0.45); /* Viền mỏng tông kem nhạt */
    border-radius: 30px; /* Dạng viên thuốc hoàn hảo */
    overflow: hidden;
    background: linear-gradient(135deg, #fdfbf7 0%, #f4ebd9 100%); /* Gradient kem champagne */
    height: 42px; /* Chiều cao thon gọn, sang trọng cho header */
    padding: 3px 4px 3px 3px; /* Khoảng đệm để nút tròn nổi bật bên trong và sát viền phải */
    box-sizing: border-box;
    box-shadow: 0 6px 16px rgba(188, 170, 151, 0.2); /* Bóng đổ kem champagne mềm mại */
    transition: all 0.3s ease;
}

.dodo-search-input-group:focus-within {
    border-color: #e65b20;
    box-shadow: 0 6px 20px rgba(230, 91, 32, 0.12), 0 0 0 3px rgba(230, 91, 32, 0.04);
}

/* Icon kính lúp nhã nhặn ở bên trái */
.dodo-search-icon-left {
    display: flex;
    align-items: center;
    justify-content: center;
    padding-left: 14px;
    color: #a39585; /* Tông màu kem trầm */
    flex-shrink: 0;
}

.dodo-search-field-input {
    flex: 1;
    border: none !important;
    outline: none !important;
    padding: 0 10px !important; /* Giảm padding trái vì đã có icon */
    font-size: 14px !important;
    background: transparent !important;
    color: #5c5246 !important; /* Chữ màu kem đậm */
    height: 100% !important;
    box-shadow: none !important;
}

.dodo-search-field-input::placeholder {
    color: #b5a999 !important;
}

/* Nút tròn màu đen ở bên phải */
.dodo-search-submit {
    border: none !important;
    background: #231f20 !important; /* Nút tròn màu đen tối sang trọng */
    width: 32px !important; /* Thu nhỏ nút tròn lại */
    height: 32px !important;
    border-radius: 50% !important; /* Hình tròn hoàn hảo */
    color: #f4ebd9 !important; /* Mũi tên màu champagne sáng */
    cursor: pointer !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 0 !important;
    flex-shrink: 0 !important;
    margin-right: 1px !important; /* Dịch sát viền phải hơn */
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1) !important;
    box-shadow: 0 2px 5px rgba(0,0,0,0.15) !important;
}

.dodo-search-submit:hover {
    background: #000000 !important;
    transform: scale(1.05);
}

.dodo-search-submit svg {
    display: block;
    width: 13px; /* Icon mũi tên nhỏ lại phù hợp nút 32px */
    height: 13px;
}

/* Giao diện đóng/mở Overlay tìm kiếm trên Mobile */
.dodo-search-trigger-mobile {
    display: none; /* Mặc định ẩn trên Desktop */
}

.dodo-search-mobile-header {
    display: none; /* Mặc định ẩn trên Desktop */
}

/* Cấu hình hiển thị theo thiết bị */
@media (min-width: 768px) {
    .dodo-search-device-mobile {
        display: none !important;
    }
    
    /* Ẩn các class cha bọc ngoài của Flatsome nếu nó chứa tìm kiếm chỉ dành cho mobile */
    .html:has(.dodo-search-device-mobile),
    .header-button:has(.dodo-search-device-mobile),
    .header-nav-main .html:has(.dodo-search-device-mobile),
    .header-nav .html:has(.dodo-search-device-mobile),
    .flex-col:has(.dodo-search-device-mobile) {
        display: none !important;
    }
}

@media (max-width: 767px) {
    /* Ẩn các thanh tìm kiếm chỉ dành cho Desktop khi ở Mobile */
    .dodo-search-device-desktop {
        display: none !important;
    }
    
    /* Ẩn các class cha bọc ngoài của Flatsome nếu nó chứa tìm kiếm chỉ dành cho desktop */
    .html:has(.dodo-search-device-desktop),
    .header-button:has(.dodo-search-device-desktop),
    .header-nav-main .html:has(.dodo-search-device-desktop),
    .header-nav .html:has(.dodo-search-device-desktop),
    .flex-col:has(.dodo-search-device-desktop) {
        display: none !important;
    }

    /* Ghi đè CSS của Flatsome di động để hiển thị widget HTML chứa tìm kiếm ở dòng trên cùng (ngoại trừ cái chỉ dành cho desktop) */
    .html:has(.dodo-search-mobile-collapse:not(.dodo-search-device-desktop)),
    .header-button:has(.dodo-search-mobile-collapse:not(.dodo-search-device-desktop)),
    .header-nav-main .html:has(.dodo-search-mobile-collapse:not(.dodo-search-device-desktop)),
    .header-nav .html:has(.dodo-search-mobile-collapse:not(.dodo-search-device-desktop)),
    .flex-col:has(.dodo-search-mobile-collapse:not(.dodo-search-device-desktop)) {
        display: inline-block !important;
        vertical-align: middle !important;
    }

    /* Khi tuỳ chọn thu gọn trên mobile được bật */
    .dodo-search-mobile-collapse {
        display: inline-block !important;
        vertical-align: middle !important;
        margin: 0 6px !important;
        min-width: 38px !important;
        min-height: 38px !important;
        width: 38px !important;
        height: 38px !important;
        flex-shrink: 0 !important;
    }

    .dodo-search-mobile-collapse .dodo-searchform-container {
        display: none !important;
    }
    
    .dodo-search-mobile-collapse .dodo-search-trigger-mobile {
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        width: 38px !important;
        height: 38px !important;
        min-width: 38px !important;
        min-height: 38px !important;
        flex-shrink: 0 !important;
        border-radius: 50% !important;
        background: linear-gradient(135deg, #fdfbf7 0%, #f4ebd9 100%) !important;
        border: 1px solid rgba(220, 200, 180, 0.45) !important;
        color: #231f20 !important; /* Icon kính lúp màu đen */
        cursor: pointer !important;
        padding: 0 !important;
        box-shadow: 0 4px 10px rgba(188, 170, 151, 0.15) !important;
        transition: all 0.2s ease !important;
    }

    .dodo-search-mobile-collapse .dodo-search-trigger-mobile:hover {
        background: #231f20 !important;
        color: #f4ebd9 !important;
    }

    /* Khóa scroll trang khi overlay hiển thị */
    body.dodo-search-overlay-active {
        overflow: hidden !important;
    }

    /* Hiển thị form dưới dạng overlay tràn màn hình */
    body.dodo-search-overlay-active .dodo-search-mobile-collapse.dodo-active-wrapper .dodo-searchform-container {
        display: flex !important;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 999999;
        background: rgba(253, 251, 247, 0.99) !important; /* Nền champagne đục nhẹ sang trọng */
        padding: 65px 15px 20px; /* Chừa khoảng trên cho header */
        flex-direction: column;
        align-items: stretch;
        box-sizing: border-box;
        animation: dodoFadeInMobile 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    }

    /* Header di động ở góc trên overlay */
    body.dodo-search-overlay-active .dodo-search-mobile-collapse.dodo-active-wrapper .dodo-search-mobile-header {
        display: flex !important;
        align-items: center;
        justify-content: space-between;
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        height: 55px;
        padding: 0 20px;
        border-bottom: 1px solid rgba(220, 200, 180, 0.2);
        background: #fdfbf7;
    }

    body.dodo-search-overlay-active .dodo-search-mobile-collapse.dodo-active-wrapper .dodo-search-mobile-title {
        font-size: 15px;
        font-weight: 600;
        color: #5c5246;
    }

    body.dodo-search-overlay-active .dodo-search-mobile-collapse.dodo-active-wrapper .dodo-search-close-overlay-mobile {
        border: none !important;
        background: rgba(0, 0, 0, 0.05) !important;
        color: #8c7b6c !important;
        font-size: 12px !important;
        font-weight: 500 !important;
        cursor: pointer !important;
        padding: 6px 12px !important;
        border-radius: 20px !important;
        box-shadow: none !important;
        transition: all 0.2s ease;
    }

    body.dodo-search-overlay-active .dodo-search-mobile-collapse.dodo-active-wrapper .dodo-search-close-overlay-mobile:hover {
        background: rgba(0, 0, 0, 0.1) !important;
    }

    body.dodo-search-overlay-active .dodo-search-mobile-collapse.dodo-active-wrapper .dodo-search-input-group {
        width: 100% !important;
        max-width: 100% !important;
        height: 44px !important; /* Rộng rãi hơn chút ở Mobile */
    }

    /* Điều chỉnh dropdown kết quả trong overlay */
    body.dodo-search-overlay-active .dodo-search-mobile-collapse.dodo-active-wrapper .dodo-search-results {
        position: relative !important;
        top: 0 !important;
        left: 0 !important;
        width: 100% !important;
        margin-top: 15px !important;
        box-shadow: none !important;
        border: none !important;
        background: transparent !important;
        max-height: calc(100vh - 130px) !important;
        overflow-y: auto !important;
        display: block !important;
        padding: 0 !important;
    }

    body.dodo-search-overlay-active .dodo-search-mobile-collapse.dodo-active-wrapper .dodo-search-item {
        background: #ffffff !important;
        border: 1px solid rgba(220, 200, 180, 0.2) !important;
        border-radius: 8px !important;
        margin-bottom: 8px !important;
        box-shadow: 0 2px 6px rgba(188, 170, 151, 0.05) !important;
        padding: 10px !important;
    }
}

@keyframes dodoFadeInMobile {
    from { opacity: 0; transform: translateY(-15px); }
    to { opacity: 1; transform: translateY(0); }
}
