/* =========================================
   9. CSS RIÊNG CHO TRANG CHI TIẾT (LISTING DETAIL)
   ========================================= */

/* Quan trọng: Đảm bảo padding và border nằm trong kích thước width */
*, *::before, *::after {
    box-sizing: border-box;
}

/* Khóa chiều ngang của trang web */
html, body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden; /* Cắt bỏ phần thừa ngang */
    margin: 0;
    padding: 0;
    -webkit-text-size-adjust: 100%; /* Ngăn iOS tự phóng to chữ */
}

/* Đảm bảo ảnh không bao giờ to hơn khung chứa nó */
img {
    max-width: 100%;
    height: auto;
    display: block;
}

/* Container chính */
.detail-container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 30px 20px;
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

/* Header Tin Đăng */
.listing-header {
    text-align: center;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 1px solid #eee;
}
.listing-header h1 {
    margin: 0 0 10px 0;
    color: #333;
    font-size: 1.8rem;
    line-height: 1.4;
}
.listing-meta {
    color: #6c757d;
    font-size: 0.95em;
}

/* Phần Ảnh & Gallery (Đã cập nhật tỉ lệ 3:1) */
.main-image-wrapper {
    margin-bottom: 10px;
    border: 1px solid #ddd;
    border-radius: 8px;
    overflow: hidden;
    position: relative; /* Để định vị nút next/prev */
    width: 100%;
}

#main-image {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 3 / 1; /* Tỉ lệ 3:1 như bạn yêu cầu */
    object-fit: cover;
}

/* Nút điều hướng ảnh */
.main-image-nav {
    position: absolute; top: 50%; transform: translateY(-50%);
    background-color: rgba(0, 0, 0, 0.4); color: white;
    border: none; font-size: 2em; cursor: pointer; z-index: 10;
    width: 40px; height: 40px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    line-height: 1; transition: background-color 0.2s;
}
.main-image-nav:hover { background-color: rgba(0, 0, 0, 0.7); }
.main-image-nav.prev { left: 10px; }
.main-image-nav.next { right: 10px; }

/* Thumbnail strip */
.thumbnail-strip {
    display: flex; gap: 10px; overflow-x: auto; padding-bottom: 10px;
}
.thumbnail-image {
    width: 80px; height: 60px; object-fit: cover;
    border-radius: 4px; cursor: pointer;
    border: 2px solid transparent; transition: border-color 0.2s;
}
.thumbnail-image:hover { border-color: #007bff; }
.thumbnail-image.active { border-color: #0056b3; box-shadow: 0 0 5px rgba(0, 86, 179, 0.5); }

/* Thông tin chi tiết */
.detail-section { margin-bottom: 30px; }
.detail-section h3 {
    font-size: 1.4em; color: #0056b3;
    margin-bottom: 15px; border-bottom: 2px solid #0056b3; padding-bottom: 8px;
}

.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 10px 20px;
}
.info-item { padding: 5px 0; }
.info-item strong { color: #495057; min-width: 120px; display: inline-block; }

.description-content {
    white-space: pre-wrap;
    background-color: #fdfdfd;
    padding: 15px;
    border-radius: 4px;
    border-left: 4px solid #007bff;
    line-height: 1.7;
}

/* Thông tin liên hệ */
#contact-info-section .show-info-button {
    background-color: #28a745; color: white; border: none;
    padding: 12px 20px; font-size: 1.1em; border-radius: 5px;
    cursor: pointer; margin-top: 10px; transition: background-color 0.2s;
}
#contact-info-section .show-info-button:hover { background-color: #218838; }
#contact-info-section .show-info-button:disabled { background-color: #ccc; }

.sensitive-info-placeholder { font-style: italic; color: #999; }
#listing-phone-number a { color: #d9534f; font-weight: bold; text-decoration: none; font-size: 1.1em; }

/* Admin Actions */
.admin-actions-detail {
    text-align: right; padding-top: 20px; border-top: 1px solid #eee; margin-top: 30px;
}

/* Status & Error */
#listing-status { text-align: center; padding: 20px; font-size: 1.1em; }
.status-error { background-color: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; border-radius: 4px; }

/* Tin liên quan (Related Listings) */
.related-listings-wrapper {
    position: relative; /* Làm gốc để định vị các nút */
}

#related-listings-container {
        display: flex;
        overflow: hidden; 
        gap: 15px;
    }


/* Kích thước của mỗi card tin đăng */
 #related-listings-container .listing-card {
        flex-shrink: 0; 
        width: 100%; 
        box-sizing: border-box;
        padding: 0; /* <-- THÊM DÒNG NÀY ĐỂ VÔ HIỆU HÓA PADDING GÂY LỖI */
    }

/* Nút điều hướng (sử dụng lại style cũ và tùy chỉnh) */
.related-listings-wrapper .slider-nav {
    top: 40%; /* Điều chỉnh vị trí nút cho phù hợp với card */
}

/* Ẩn nút nếu có class .hidden */
.related-listings-wrapper .slider-nav.hidden {
    display: none;
}


/* Responsive riêng cho trang chi tiết */
@media (min-width: 768px) {
    #related-listings-container .listing-card {
        width: calc(50% - 7.5px);
    }
}

@media (max-width: 768px) {
    /* Trên điện thoại, đổi tỉ lệ ảnh về 16:9 cho dễ nhìn */
    #main-image { aspect-ratio: 16 / 9; }
    
    /* Các tinh chỉnh khác cho mobile */
    .detail-container { padding: 20px 15px; }
    .listing-header h1 { font-size: 1.5em; }
}

/* 1. Fix lỗi Banner Slider bị tràn */
.banner-slider-container {
    width: 100% !important; /* Ép về 100% khung chứa */
    max-width: 100vw !important; /* Không vượt quá chiều rộng màn hình */
    margin: 0 auto 20px auto;
}

/* 2. Fix lỗi Modal Bộ lọc (Do sticky footer dùng margin âm) */
.filter-form-reset {
    overflow-x: hidden; /* Ngăn margin âm làm tràn khung */
    width: 100%;
}

/* 3. Fix lỗi Container chính */
main {
    width: 100%;
    padding: 0 15px; /* Giảm padding trên mobile cho đỡ chật */
    overflow: hidden; /* Ngăn con tràn ra ngoài */
}

/* 4. Fix lỗi Tin Liên Quan (Slider ngang) */
.related-listings-wrapper {
    width: 100%;
    overflow: hidden; /* Cắt phần thừa */
}
#related-listings-container {
    padding-bottom: 20px; /* Chừa chỗ cho thanh cuộn nếu có */
    /* Đảm bảo flex container không bị đẩy dãn */
    width: 100%; 
}

/* 5. Reset lại margin âm của Sticky Actions trên mobile (nếu cần thiết) */
@media (max-width: 768px) {
    .sticky-actions {
        margin-left: 0;
        margin-right: 0;
        padding-right: 0;
        width: 100%;
        justify-content: space-between; /* Dàn đều nút trên mobile */
    }
    
    .sticky-actions button {
        flex: 1; /* Nút to dễ bấm */
    }
}