/* ==========================================================================
   STYLE CHO TRANG CHI TIẾT TIN ĐĂNG (LISTING DETAIL)
   Đã tối ưu & chuẩn hóa cấu trúc - Dễ dàng bảo trì
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. BIẾN TOÀN CỤC (VARIABLES) - Đổi màu/kích thước tại đây
   -------------------------------------------------------------------------- */
:root {
    --primary-color: #007bff;     /* Xanh dương chủ đạo */
    --primary-hover: #0056b3;
    --success-color: #28a745;     /* Xanh lá (Hotline, Chính chủ) */
    --danger-color: #d9534f;      /* Đỏ (Giá, Map) */
    --warning-color: #ff9800;     /* Cam (Tin nhắn) */
    --info-color: #17a2b8;        /* Xanh lơ (Lời nhắn) */
    
    --text-main: #333333;
    --text-muted: #666666;
    --bg-light: #f8f9fa;
    --border-color: #eeeeee;
    
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-pill: 30px;
}

/* --------------------------------------------------------------------------
   2. LAYOUT CHUNG (LAYOUT)
   -------------------------------------------------------------------------- */
.detail-container {
    width: 100%;
}
.detail-layout-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 30px;
    margin-top: 20px;
}
.detail-left-column {
    min-width: 0;
}
.detail-right-column {
    position: sticky;
    top: 90px;
    height: fit-content;
}
.detail-section {
    margin-bottom: 30px;
}
.detail-section h3 {
    font-size: 1.3rem;
    color: var(--text-main);
    border-left: 4px solid var(--primary-color);
    padding-left: 10px;
    margin-bottom: 20px;
    font-weight: 700;
}

/* --------------------------------------------------------------------------
   3. HEADER & ĐỊA CHỈ (TITLE & ADDRESS)
   -------------------------------------------------------------------------- */
.responsive-title {
    font-size: clamp(20px, 4vw, 26px);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    width: 100%;
    color: #222;
    font-weight: 700;
    margin-bottom: 15px;
    line-height: 1.4;
    text-align: center;
}

.custom-address-wrapper {
    text-align: center;
    width: 100%;
}

.custom-address-row {
    display: inline-block; /* QUAN TRỌNG: Giữ khối nền xám không bị vỡ khi chữ rớt dòng */
    line-height: 1.6;
    padding: 6px 15px;
    background: var(--bg-light);
    border-radius: var(--radius-sm);
    max-width: 100%; /* Tránh tràn viền trên điện thoại */
    text-align: left; /* Để chữ chảy tự nhiên từ trái sang phải */
    cursor: pointer;
    transition: background 0.2s, box-shadow 0.2s;
}
.custom-address-row:hover {
    background-color: #e6f2ff;
    box-shadow: 0 0 5px rgba(0, 123, 255, 0.2);
}

.custom-address-row .address-icon {
    color: var(--danger-color);
    font-size: 1.2rem;
    margin-right: 5px;
    vertical-align: middle;
}

.custom-address-row .address-text {
    color: var(--text-main); /* Hoặc dùng var(--success-color) nếu bạn thích chữ xanh lá */
    font-size: 1.05rem;
    font-weight: 600;
    display: inline; /* QUAN TRỌNG: Bắt buộc chữ phải chảy liên tục, tự động rớt dòng */
    word-break: break-word;
    vertical-align: middle;
}

/* ÉP NÚT COPY PHẢI DÍNH LIỀN VỚI CHỮ */
.custom-address-row .copy-addr-btn {
    display: inline-block !important; 
    color: var(--primary-color) !important;
    font-size: 1.1rem !important;
    cursor: pointer !important;
    margin-left: 6px !important; /* Cách chữ cuối cùng 1 xíu cho đẹp */
    vertical-align: baseline !important; /* Canh chân icon bằng với chân chữ */
    transition: transform 0.2s;
}

.custom-address-row .copy-addr-btn:hover {
    transform: scale(1.2);
}

.action-buttons-center {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    margin-top: 20px;
    width: 100%;
}
.action-buttons-center .action-button {
    padding: 8px 25px;
    border-radius: var(--radius-pill);
    background: #fff;
    border: 1px solid #ddd;
    font-weight: 500;
    color: #555;
    display: flex; align-items: center; gap: 5px;
    transition: 0.2s;
}
.action-buttons-center .action-button:hover { background: var(--bg-light); color: var(--primary-color); border-color: var(--primary-color); }
.action-buttons-center .copy-link-button { background-color: #e9ecef; border-color: #ced4da; }

/* --------------------------------------------------------------------------
   4. THƯ VIỆN ẢNH (GALLERY)
   -------------------------------------------------------------------------- */
.main-image-wrapper { 
    position: relative; width: 100%; aspect-ratio: 16/9; 
    background: #f0f0f0; border-radius: var(--radius-md); 
    overflow: hidden; border: 1px solid #ddd; margin-bottom: 10px; 
}
#main-image { width: 100%; height: 100%; object-fit: contain; background-color: #000; }
.thumbnail-strip { display: flex; gap: 10px; overflow-x: auto; padding: 5px 0 10px; }
.thumbnail-image {
    width: 90px; height: 65px; object-fit: cover; border-radius: 4px;
    border: 2px solid #fff; cursor: pointer; flex-shrink: 0; opacity: 0.7; transition: 0.2s;
}
.thumbnail-image.active, .thumbnail-image:hover { border-color: var(--primary-color); opacity: 1; }

.main-image-nav {
    position: absolute; top: 50%; transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.85); border: none; border-radius: 50%;
    width: 40px; height: 40px; font-size: 24px; line-height: 1;
    color: var(--text-main); cursor: pointer; z-index: 10;
    display: flex; justify-content: center; align-items: center;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2); transition: all 0.2s ease;
}
.main-image-nav:hover { background: var(--primary-color); color: white; }
.main-image-nav.prev { left: 10px; }
.main-image-nav.next { right: 10px; }

/* --------------------------------------------------------------------------
   5. THÔNG SỐ & MÔ TẢ (SPECS & DESCRIPTION)
   -------------------------------------------------------------------------- */
.specs-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}
.spec-item {
    display: flex; flex-direction: column; padding: 15px;
    background: #fff; border-radius: var(--radius-sm);
    border: 1px solid #f0f0f0; box-shadow: 0 2px 4px rgba(0,0,0,0.02);
}
.spec-item.highlight-item { background: #fffcf0; border-color: #fbe7a1; }
.spec-label { font-size: 0.9rem; color: #777; margin-bottom: 5px; }
.spec-value { font-size: 1.05rem; font-weight: 700; color: var(--text-main); }
.description-content { font-size: 1rem; line-height: 1.8; color: #444; text-align: justify; }

/* --------------------------------------------------------------------------
   6. BẢN ĐỒ & TIỆN ÍCH (MAPS)
   -------------------------------------------------------------------------- */
.map-section { border-top: 1px solid var(--border-color); padding-top: 20px; }
.map-container {
    width: 100%; height: 400px; border-radius: var(--radius-md);
    overflow: hidden; border: 1px solid #ddd; position: relative;
    background: #f9f9f9; box-shadow: 0 4px 10px rgba(0,0,0,0.05);
}
.map-container iframe { width: 100%; height: 100%; border: 0; }

.expand-map-btn {
    position: absolute; bottom: 15px; right: 15px;
    background: #fff; border: 1px solid #ddd; padding: 8px 15px;
    border-radius: var(--radius-pill); font-weight: 600; cursor: pointer;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1); transition: 0.2s;
    z-index: 999; display: flex; align-items: center; gap: 5px;
    touch-action: manipulation;
}
.expand-map-btn:hover { background: var(--primary-color); color: white; border-color: var(--primary-color); }

.map-utilities-container { margin-top: 15px; }
.map-utilities-label { font-size: 0.95rem; color: var(--text-main); margin-bottom: 10px; font-weight: 600; }
.utility-chips-wrapper { display: flex; flex-wrap: wrap; gap: 10px; }
.utility-chip {
    display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px;
    border-radius: 20px; border: 1px solid #e0e0e0; background-color: #fff;
    color: #555; font-size: 0.9rem; cursor: pointer; transition: all 0.2s ease; user-select: none;
}
.utility-chip i { font-size: 1rem; color: #777; }
.utility-chip:hover { background-color: #f5f5f5; border-color: #d0d0d0; }
.utility-chip.active { background-color: #e3f2fd; color: #0d47a1; border-color: #2196f3; font-weight: 500; }
.utility-chip.active i { color: #0d47a1; }
.utility-chip[data-type="location"].active { background-color: #e8f5e9; color: #2e7d32; border-color: #4caf50; }
.utility-chip[data-type="location"].active i { color: #2e7d32; }

/* --------------------------------------------------------------------------
   7. LIÊN HỆ & LEAD CRM (CONTACT BOX)
   -------------------------------------------------------------------------- */
.contact-box { 
    background: #fff; padding: 20px; border-radius: var(--radius-md); 
    border: 1px solid #e0e0e0; box-shadow: 0 4px 12px rgba(0,0,0,0.05); text-align: center;
}
.contact-action-wrapper { display: flex; flex-direction: column; gap: 12px; width: 100%; }

.action-btn-custom {
    width: 100%; padding: 12px; border-radius: var(--radius-pill);
    font-weight: 600; font-size: 1.05rem; display: flex; justify-content: center; align-items: center;
    gap: 8px; border: none; color: white; cursor: pointer;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1); transition: transform 0.2s;
}
.action-btn-custom:active { transform: scale(0.95); }
.btn-show-contact { background-color: var(--success-color); }
.btn-leave-message { background-color: var(--info-color); }
.btn-view-leads { background-color: var(--warning-color); }

/* --------------------------------------------------------------------------
   8. TIN ĐĂNG LIÊN QUAN (RELATED LISTINGS)
   -------------------------------------------------------------------------- */
#related-listings-section { position: relative; padding: 20px 20px 0; margin-top: 40px; border-top: 1px solid var(--border-color); }
.related-listings-wrapper { position: relative; width: 100%; overflow: hidden; }
#related-listings-container {
    display: flex; flex-wrap: nowrap; gap: 15px; overflow-x: auto;
    scroll-behavior: auto; padding-bottom: 10px;
    scrollbar-width: none; -ms-overflow-style: none; /* Ẩn scrollbar */
}
#related-listings-container::-webkit-scrollbar { display: none; }

/* Thẻ tin liên quan thu nhỏ */
#related-listings-container .listing-card {
    flex: 0 0 calc(25% - 12px); max-width: 280px;
    display: flex; flex-direction: column; min-height: 280px; height: 100%;
    border: 1px solid #eee; background: #fff; border-radius: var(--radius-md);
    overflow: hidden; transition: transform 0.2s; box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}
#related-listings-container .listing-card:hover { transform: translateY(-3px); box-shadow: 0 5px 15px rgba(0,0,0,0.1); }
#related-listings-container .listing-card-image-container { width: 100%; height: 160px; flex: none; }
#related-listings-container .listing-card-image-container img { width: 100%; height: 100%; object-fit: cover; }
#related-listings-container .listing-card-info { padding: 10px; flex: 1; display: flex; flex-direction: column; width: 100%; }
#related-listings-container .listing-card-title { font-size: 0.95rem; font-weight: 600; line-height: 1.3; height: 2.6em; overflow: hidden; margin-bottom: 2px; }
#related-listings-container .listing-card-price { font-size: 1.1rem; color: var(--danger-color); font-weight: bold; }
#related-listings-container .listing-card-footer-date { display: flex; align-items: center; gap: 5px; font-size: 0.75rem; color: #888; margin-top: auto; padding-top: 5px; }
#related-listings-container .listing-card-details { margin-top: auto; gap: 5px; }
#related-listings-container .listing-card-details span { font-size: 0.8rem; padding: 2px 6px; background: #f1f1f1; border: none; color: #555; }

/* Ẩn các nút hành động & badge trong tin liên quan cho gọn */
#related-listings-container .listing-card-description,
#related-listings-container .listing-card-type-row,
#related-listings-container .listing-card-actions,
#related-listings-container .listing-card-new-badge-inline, 
#related-listings-container .listing-card-verified-badge-inline { display: none; }

/* Nút trượt slider */
.related-nav-btn {
    position: absolute; top: 50%; transform: translateY(-50%);
    width: 40px; height: 40px; border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.9); border: 1px solid #ddd;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15); color: #333; font-size: 1.2rem;
    cursor: pointer; z-index: 10; display: flex; align-items: center; justify-content: center; transition: all 0.2s;
}
.related-nav-btn:hover { background-color: #fff; color: var(--primary-color); box-shadow: 0 4px 10px rgba(0,0,0,0.2); }
#related-prev-btn { left: -10px; }
#related-next-btn { right: -10px; }

/* --------------------------------------------------------------------------
   9. MODALS (BẢN ĐỒ & LỜI NHẮN)
   -------------------------------------------------------------------------- */
.map-modal-overlay {
    display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(0, 0, 0, 0.85); z-index: 99999;
    justify-content: center; align-items: center; padding: 20px; animation: fadeIn 0.3s ease;
}
.map-modal-content {
    position: relative; width: 95%; height: 90%; max-width: 1200px;
    background: #fff; border-radius: var(--radius-md); overflow: hidden; box-shadow: 0 5px 25px rgba(0,0,0,0.5);
}
.map-modal-content iframe { width: 100%; height: 100%; border: none; }
.close-map-btn {
    position: absolute; top: 15px; right: 15px; background: #fff; color: #333;
    border: none; border-radius: 50%; width: 40px; height: 40px; font-size: 24px;
    cursor: pointer; box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    display: flex; justify-content: center; align-items: center; transition: all 0.2s;
}
.close-map-btn:hover { background: var(--danger-color); color: white; transform: rotate(90deg); }
#lead-form-modal { z-index: 100000 !important; }

/* ==========================================================================
   10. MOBILE RESPONSIVE (TẤT CẢ GIAO DIỆN ĐIỆN THOẠI GOM VÀO ĐÂY)
   ========================================================================== */
@media (max-width: 768px) {
    
    /* Layout: 1 Cột dọc */
    .detail-container .detail-layout-grid { display: flex !important; flex-direction: column !important; }
    body { padding-bottom: 90px !important; }

    /* Header & Ảnh Mobile */
    .custom-address-row { padding: 4px 8px !important; line-height: 1.5 !important; }
    .custom-address-row .address-text { font-size: 0.9rem !important; }
    .custom-address-row .address-icon, .custom-address-row .copy-addr-btn { font-size: 1rem !important; }
    .detail-container .main-image-wrapper {
        aspect-ratio: 4/3; border-radius: 0; margin-left: -20px; margin-right: -20px;
        width: calc(100% + 40px); border: none; max-height: 200px;
    }
    .detail-container .specs-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    
    /* Hiển thị lại nút lưu nếu lỡ bị ẩn toàn cục */
    #detail-save-button { display: flex !important; }

    /* --- THANH LIÊN HỆ DÍNH ĐÁY (STICKY BOTTOM) --- */
    .detail-container .detail-right-column {
        position: fixed !important; top: auto !important; bottom: 0 !important; left: 0 !important;
        width: 100% !important; background: #fff !important; padding: 12px 15px !important;
        box-shadow: 0 -4px 15px rgba(0,0,0,0.15) !important; z-index: 99999 !important;
        margin: 0 !important; border-top: 1px solid var(--border-color) !important;
    }
    .detail-container .contact-box {
        display: flex !important; flex-direction: row !important; align-items: center !important; justify-content: space-between !important;
        gap: 12px !important; padding: 0 !important; border: none !important; box-shadow: none !important; background: transparent !important;
    }
    .detail-container .contact-box h3, #listing-leads-container { display: none !important; }
    
    .contact-action-wrapper { flex-direction: row; justify-content: space-between; align-items: center; }
    
    /* Chưa đăng nhập (Khách) */
    .contact-text-info { flex: 1; text-align: left; }
    .btn-leave-message { flex: 0 0 auto; width: auto; padding: 10px 18px; font-size: 0.95rem; }

    /* Đã đăng nhập */
    .btn-show-contact { flex: 1; }
    #leads-btn-placeholder { display: block; }
    .contact-action-wrapper.has-leads .btn-show-contact,
    .contact-action-wrapper.has-leads #leads-btn-placeholder { flex: 1; width: 50%; }
    .contact-action-wrapper.has-leads .btn-view-leads { width: 100%; font-size: 0.95rem; padding: 12px 5px; }

    /* --- TIN LIÊN QUAN (2 CỘT MOBILE) --- */
    #related-listings-container { gap: 12px !important; padding-bottom: 15px !important; }
    #related-listings-container .listing-card {
        flex: 0 0 calc(50% - 6px) !important; width: calc(50% - 6px) !important;
        max-width: none !important; min-height: 240px !important;
    }
    #related-listings-container .listing-card-image-container { height: 130px !important; }
    #related-listings-container .listing-card-info { padding: 8px !important; gap: 3px !important; }
    #related-listings-container .listing-card-title { font-size: 0.85rem !important; line-height: 1.4 !important; height: auto !important; -webkit-line-clamp: 2 !important; margin-bottom: 2px !important; }
    #related-listings-container .listing-card-price { font-size: 0.95rem !important; white-space: nowrap !important; }
    #related-listings-container .listing-card-details { flex-wrap: wrap !important; gap: 4px !important; }
    #related-listings-container .listing-card-details span { font-size: 0.7rem !important; padding: 2px 5px !important; }
    .related-nav-btn { display: none; } /* Ẩn nút mũi tên, dùng vuốt tay */
}