/* Custom Advanced Search Styles */

/* Search Form */
.cas-search-wrapper {
    position: relative;
    max-width: 100%;
    margin: 2px;
}

.cas-search-form {
    position: relative;
    width: 100%;
}

/* Loại bỏ border và background của input */
.cas-search-input {
    flex: 1;
    padding: 10px 8px;
    border: none !important;
    outline: none !important;
    font-size: 15px;
    background: transparent !important;
    width: 100%;
    color: #333;
    box-shadow: none !important;
}

.cas-search-input:focus {
    border: none !important;
    outline: none !important;
    box-shadow: none !important;
}

/* Giữ border cho wrapper, không cho input */
.cas-search-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    background: #fff;
    border: 2px solid #333;
    border-radius: 50px;
    overflow: hidden;
    transition: all 0.3s ease;
    padding: 2px 2px 2px 20px;
    gap: 8px;
    height: 44px;
}

.cas-search-input-wrapper:focus-within {
    border-color: #333;
    box-shadow: none;
}

.cas-search-input::placeholder {
    color: #999;
}

.cas-search-button {
    padding: 0 !important;
    background: #ffffff !important;
    border: none !important;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #2d5f2e !important;
    transition: all 0.2s ease;
    flex-shrink: 0;
    border-radius: 0 !important;
    width: 40px !important;
    height: 40px !important;
}

.cas-search-button:hover {
    opacity: 0.8;
}

.cas-search-button svg {
    width: 24px;
    height: 24px;
    stroke-width: 5;
    fill: none !important;
    stroke: #2d5f2e !important;
}

/* Suggestions Dropdown */
.cas-suggestions {
    position: absolute;
    top: calc(100% + 5px);
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    max-height: 400px;
    overflow-y: auto;
    z-index: 9999;
    display: none;
    width: 100%;
}

.cas-suggestions.active {
    display: block;
}

.cas-suggestion-item {
    display: flex;
    align-items: center;
    padding: 12px;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    transition: background 0.2s ease;
    text-decoration: none;
    color: inherit;
}

.cas-suggestion-item:last-child {
    border-bottom: none;
}

.cas-suggestion-item:hover {
    background: #f5f5f5;
}

.cas-suggestion-image {
    width: 50px;
    height: 50px;
    object-fit: cover;
    border-radius: 4px;
    margin-right: 12px;
    flex-shrink: 0;
}

.cas-suggestion-content {
    flex: 1;
    min-width: 0;
}

.cas-suggestion-title {
    font-weight: 600;
    font-size: 15px;
    margin: 0 0 4px 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #333;
}

.cas-suggestion-excerpt {
    font-size: 13px;
    color: #666;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cas-no-suggestions {
    padding: 20px;
    text-align: center;
    color: #999;
    font-size: 14px;
}

.cas-loading {
    padding: 20px;
    text-align: center;
    color: #666;
    font-size: 14px;
}

/* Results Page */
.cas-results-page {
    padding: 40px 0;
    background: #f9f9f9;
    min-height: 60vh;
}

.cas-results-header {
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 2px solid #e0e0e0;
}

.cas-results-title {
    font-size: 32px;
    font-weight: 700;
    margin: 0 0 10px 0;
    color: #333;
}

.cas-results-count {
    font-size: 16px;
    color: #666;
    margin: 0;
}

.cas-results-count strong {
    color: #2196F3;
    font-weight: 700;
}

.cas-results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 30px;
    margin-bottom: 40px;
}

.cas-result-item {
    background: #fff;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.cas-result-item:hover {
    transform: translateY(-4px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

/* SỬA ĐỔI: Thiết lập tỷ lệ 4:3 cho khung ảnh */
.cas-result-image {
    width: 100%;
    height: auto; /* Để chiều cao tự động tính theo tỷ lệ */
    aspect-ratio: 4 / 3; /* Tỷ lệ chuẩn 4:3 */
    overflow: hidden;
    position: relative;
    background-color: #f0f0f0; /* Màu nền dự phòng khi ảnh đang load */
}

/* SỬA ĐỔI: Đảm bảo ảnh luôn phủ kín khung mà không bị méo */
.cas-result-image img {
    width: 100%;
    height: 100%;
    object-fit: cover; /* Cắt bớt phần thừa để vừa khung 4:3 */
    object-position: center; /* Luôn lấy trung tâm bức ảnh */
    transition: transform 0.3s ease;
    display: block; /* Loại bỏ khoảng trắng thừa */
}

/* Giữ nguyên hiệu ứng hover */
.cas-result-item:hover .cas-result-image img {
    transform: scale(1.05);
}

.cas-result-content {
    padding: 20px;
}

.cas-result-title {
    font-size: 18px;
    font-weight: 700;
    margin: 0 0 10px 0;
    line-height: 1.4;
}

.cas-result-title a {
    color: #333;
    text-decoration: none;
    transition: color 0.2s ease;
}

.cas-result-title a:hover {
    color: #2196F3;
}

.cas-result-meta {
    font-size: 13px;
    color: #999;
    margin-bottom: 10px;
}

.cas-result-excerpt {
    font-size: 14px;
    color: #666;
    line-height: 1.4;
    margin-bottom: 15px;
}

.cas-result-link {
    display: inline-block;
    color: #2196F3;
    text-decoration: none;
    font-weight: 600;
    font-size: 14px;
    transition: color 0.2s ease;
}

.cas-result-link:hover {
    color: #1976D2;
}

.cas-no-results {
    text-align: center;
    padding: 60px 20px;
    background: #fff;
    border-radius: 8px;
    grid-column: 1 / -1;
}

.cas-no-results p {
    font-size: 16px;
    color: #666;
    margin: 10px 0;
}

/* Pagination */
.cas-pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    margin-top: 40px;
    grid-column: 1 / -1;
}

.cas-pagination a,
.cas-pagination span {
    padding: 10px 16px;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    color: #333;
    text-decoration: none;
    transition: all 0.2s ease;
}

.cas-pagination a:hover {
    background: #2196F3;
    color: #fff;
    border-color: #2196F3;
}

.cas-pagination .current {
    background: #2196F3;
    color: #fff;
    border-color: #2196F3;
    font-weight: 600;
}

/* Responsive */
@media (max-width: 768px) {
    .cas-results-title {
        font-size: 24px;
    }
    
    .cas-results-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .cas-search-input {
        font-size: 15px;
        padding: 12px 8px;
    }
    
    /* FIX: Giữ kích thước icon kính lúp lớn hơn trên mobile */
    .cas-search-button {
        width: 40px !important;
        height: 40px !important;
    }
    
    .cas-search-button svg {
        width: 22px;
        height: 22px;
        stroke-width: 5;
    }
    
    .cas-search-input-wrapper {
        height: 44px;
    }
    
    .cas-suggestion-item {
        padding: 10px;
    }
    
    .cas-suggestion-image {
        width: 45px;
        height: 45px;
    }
    
    /* Trên mobile, danh sách gợi ý cũng theo chiều rộng ô tìm kiếm */
    .cas-suggestions {
        width: 100%;
        left: 0;
        right: 0;
        transform: none;
        min-width: unset;
        max-width: unset;
    }
}

@media (max-width: 480px) {
    .cas-results-page {
        padding: 20px 0;
    }
    
    .cas-result-content {
        padding: 15px;
    }
}