<?php if (!defined('ABSPATH')) exit; ?>
<?php
$prop = new IPP_Property_Helper(get_the_ID());
$images = $prop->gallery_images('large');
$featured = $prop->featured_image('large');
$has_gallery = !empty($images) && count($images) > 1;
$has_any_image = !empty($featured) || !empty($images);
$share_url = urlencode(get_permalink());
$share_title = urlencode(get_the_title());
?>
<style>
/*
 * ============================================================
 * THEME COMPATIBILITY RESET
 * Targets specific theme selectors that restrict content width
 * (Twenty Twenty-One, Twenty Twenty-Two, GeneratePress, etc.)
 * ============================================================
 */

/* Override theme CSS variables that cap content width */
body.single-palace-properties .site-main,
body.single-palace-properties .site-content,
body.single-palace-properties .content-area,
body.single-palace-properties #primary,
body.single-palace-properties .entry-content,
body.single-palace-properties article {
    --responsive--aligndefault-width: 100%;
    --responsive--alignwide-width: 100%;
    --wp--style--global--content-size: 100%;
    max-width: none !important;
    width: 100% !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
    margin-left: auto !important;
    margin-right: auto !important;
}

/* The wrapper itself */
.ipp-single-page {
    max-width: none !important;
    width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
}

/* Override theme rules that target direct children of site-main/entry-content */
body.single-palace-properties .site-main > *,
body.single-palace-properties .entry-content > *,
body.single-palace-properties .site-main > article > * {
    max-width: none !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
}

/* Override ipp-base.css grid on .ipp-single — this template uses .ipp-layout for its own grid */
.ipp-single.ipp-tpl-palace {
    display: block !important;
    grid-template-columns: none !important;
}

/* Map customizer variables to template variables.
   Customizer sets --ipp-color-primary etc on .ipp-tpl-palace.
   Template uses --ipp-primary etc internally.
   This mapping ensures customizer values flow through. */
.ipp-tpl-palace {
    --ipp-primary: var(--ipp-color-primary, #1a2a4a);
    --ipp-accent: var(--ipp-color-accent, #2563eb);
    --ipp-accent-light: #dbeafe;
    --ipp-success: var(--ipp-color-success, #059669);
    --ipp-success-light: #d1fae5;
    --ipp-warning: #d97706;
    --ipp-warning-light: #fef3c7;
    --ipp-danger: #dc2626;
    --ipp-danger-light: #fee2e2;
    --ipp-gray-50: var(--ipp-color-surface, #f9fafb);
    --ipp-gray-100: #f3f4f6;
    --ipp-gray-200: var(--ipp-color-border, #e5e7eb);
    --ipp-gray-300: #d1d5db;
    --ipp-gray-400: #9ca3af;
    --ipp-gray-500: var(--ipp-color-text-light, #6b7280);
    --ipp-gray-600: #4b5563;
    --ipp-gray-700: #374151;
    --ipp-gray-800: var(--ipp-color-text, #1f2937);
    --ipp-gray-900: #111827;
    --ipp-radius-sm: 8px;
    --ipp-radius-lg: 16px;
    --ipp-shadow-md: 0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -2px rgba(0,0,0,.1);
    --ipp-shadow-lg: 0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -4px rgba(0,0,0,.1);
    --ipp-font: var(--ipp-font-body, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif);
    --ipp-transition: all .2s ease;
    font-family: var(--ipp-font);
    color: var(--ipp-gray-800);
    line-height: 1.6;
}

/* Hero Gallery */
.ipp-tpl-palace .ipp-hero {
    position: relative !important;
    width: 100vw !important;
    max-width: 100vw !important;
    margin-left: calc(-50vw + 50%) !important;
    background: var(--ipp-gray-900) !important;
    overflow: hidden !important;
    grid-column: 1 / -1 !important;
}
.ipp-tpl-palace .ipp-hero__main {
    position: relative;
    max-height: 560px;
    overflow: hidden;
    cursor: pointer;
}
.ipp-tpl-palace .ipp-hero__main img {
    width: 100%;
    height: 560px;
    object-fit: cover;
    display: block;
    transition: transform .4s ease;
}
.ipp-tpl-palace .ipp-hero__main:hover img {
    transform: scale(1.02);
}
.ipp-tpl-palace .ipp-hero__overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 120px;
    background: linear-gradient(transparent, rgba(0,0,0,.5));
    pointer-events: none;
}
.ipp-tpl-palace .ipp-hero__count {
    position: absolute;
    bottom: 16px;
    right: 16px;
    background: rgba(0,0,0,.7);
    backdrop-filter: blur(8px);
    color: #fff;
    padding: 8px 16px;
    border-radius: 100px;
    font-size: 14px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 6px;
    z-index: 2;
}
.ipp-tpl-palace .ipp-hero__count svg {
    width: 16px;
    height: 16px;
}
.ipp-tpl-palace .ipp-hero__thumbstrip {
    display: flex;
    gap: 4px;
    padding: 4px;
    background: var(--ipp-gray-900);
    overflow-x: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--ipp-gray-600) transparent;
}
.ipp-tpl-palace .ipp-hero__thumbstrip::-webkit-scrollbar {
    height: 4px;
}
.ipp-tpl-palace .ipp-hero__thumbstrip::-webkit-scrollbar-thumb {
    background: var(--ipp-gray-600);
    border-radius: 2px;
}
.ipp-tpl-palace .ipp-hero__thumb {
    flex: 0 0 auto;
    width: 100px;
    height: 68px;
    border: none;
    padding: 0;
    cursor: pointer;
    border-radius: 6px;
    overflow: hidden;
    opacity: .6;
    transition: var(--ipp-transition);
    background: none;
    outline: none;
}
.ipp-tpl-palace .ipp-hero__thumb:hover,
.ipp-tpl-palace .ipp-hero__thumb.is-active {
    opacity: 1;
    box-shadow: 0 0 0 2px var(--ipp-accent);
}
.ipp-tpl-palace .ipp-hero__thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.ipp-tpl-palace .ipp-hero--single img {
    height: 480px;
}

/* Quick Info Bar */
.ipp-tpl-palace .ipp-quickbar {
    display: flex !important;
    flex-wrap: wrap;
    align-items: center;
    gap: 16px;
    padding: 20px 24px !important;
    margin: 0 auto !important;
    max-width: 1200px !important;
    border-bottom: 1px solid var(--ipp-gray-200);
    grid-column: 1 / -1 !important;
}
.ipp-tpl-palace .ipp-quickbar__rent {
    font-size: 32px;
    font-weight: 800;
    color: var(--ipp-primary);
    letter-spacing: -.02em;
    line-height: 1;
}
.ipp-tpl-palace .ipp-quickbar__period {
    font-size: 14px;
    color: var(--ipp-gray-500);
    font-weight: 400;
}
.ipp-tpl-palace .ipp-quickbar__divider {
    width: 1px;
    height: 32px;
    background: var(--ipp-gray-200);
}
.ipp-tpl-palace .ipp-quickbar__badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: 100px;
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.ipp-tpl-palace .ipp-quickbar__badge--status {
    background: var(--ipp-success-light);
    color: var(--ipp-success);
}
.ipp-tpl-palace .ipp-quickbar__badge--status.is-inactive {
    background: var(--ipp-danger-light);
    color: var(--ipp-danger);
}
.ipp-tpl-palace .ipp-quickbar__badge--class {
    background: var(--ipp-accent-light);
    color: var(--ipp-accent);
}
.ipp-tpl-palace .ipp-quickbar__available {
    margin-left: auto;
    font-size: 14px;
    color: var(--ipp-gray-600);
}
.ipp-tpl-palace .ipp-quickbar__available strong {
    color: var(--ipp-gray-800);
}

/* Key Stats Row */
.ipp-tpl-palace .ipp-stats {
    display: flex !important;
    flex-wrap: wrap;
    gap: 10px;
    padding: 20px 24px !important;
    max-width: 1200px !important;
    margin: 0 auto !important;
    grid-column: 1 / -1 !important;
}
.ipp-tpl-palace .ipp-stat {
    display: inline-flex !important;
    align-items: center !important;
    gap: 8px !important;
    padding: 10px 18px !important;
    border-radius: 100px !important;
    font-size: 15px !important;
    font-weight: 600 !important;
    transition: var(--ipp-transition);
    line-height: 1.2 !important;
    white-space: nowrap !important;
}
.ipp-tpl-palace .ipp-stat:hover {
    transform: translateY(-1px);
    box-shadow: var(--ipp-shadow-md);
}
.ipp-tpl-palace .ipp-stat svg {
    width: 20px !important;
    height: 20px !important;
    min-width: 20px !important;
    max-width: 20px !important;
    flex-shrink: 0 !important;
}
.ipp-tpl-palace .ipp-stat--bed { background: #eff6ff; color: #1e40af; }
.ipp-tpl-palace .ipp-stat--bath { background: #f0fdfa; color: #0f766e; }
.ipp-tpl-palace .ipp-stat--ensuite { background: #fdf4ff; color: #7e22ce; }
.ipp-tpl-palace .ipp-stat--car { background: #f3f4f6; color: #374151; }
.ipp-tpl-palace .ipp-stat--parking { background: #fefce8; color: #854d0e; }

/* Two Column Layout */
.ipp-tpl-palace .ipp-layout {
    display: grid !important;
    grid-template-columns: 1fr 380px !important;
    gap: 40px !important;
    max-width: 1200px !important;
    margin: 32px auto 0 !important;
    padding: 0 24px 60px !important;
    grid-column: 1 / -1 !important;
}

/* Section Styles */
.ipp-tpl-palace .ipp-section {
    margin-bottom: 36px;
}
.ipp-tpl-palace .ipp-section__title {
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--ipp-gray-500);
    margin: 0 0 16px;
    padding-left: 14px;
    border-left: 3px solid var(--ipp-accent);
    line-height: 1;
    padding-top: 2px;
    padding-bottom: 2px;
}

/* Address */
.ipp-tpl-palace .ipp-address {
    margin-bottom: 32px;
}
.ipp-tpl-palace .ipp-address__main {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    font-size: 26px;
    font-weight: 700;
    color: var(--ipp-gray-900);
    line-height: 1.3;
    margin-bottom: 8px;
}
.ipp-tpl-palace .ipp-address__main svg {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    color: var(--ipp-accent);
    margin-top: 2px;
}
.ipp-tpl-palace .ipp-address__sub {
    font-size: 15px;
    color: var(--ipp-gray-500);
    padding-left: 40px;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}
.ipp-tpl-palace .ipp-address__sub span:not(:last-child)::after {
    content: "\00b7";
    margin-left: 6px;
    color: var(--ipp-gray-300);
}

/* Description */
.ipp-tpl-palace .ipp-description {
    font-size: 16px;
    line-height: 1.8;
    color: var(--ipp-gray-700);
}
.ipp-tpl-palace .ipp-description p {
    margin-bottom: 16px;
}

/* Details Grid */
.ipp-tpl-palace .ipp-details {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
    border-radius: var(--ipp-radius);
    overflow: hidden;
    border: 1px solid var(--ipp-gray-200);
}
.ipp-tpl-palace .ipp-detail {
    display: flex;
    flex-direction: column;
    padding: 14px 18px;
    border-bottom: 1px solid var(--ipp-gray-100);
}
.ipp-tpl-palace .ipp-detail:nth-child(odd) {
    border-right: 1px solid var(--ipp-gray-100);
}
.ipp-tpl-palace .ipp-detail:nth-child(4n+1),
.ipp-tpl-palace .ipp-detail:nth-child(4n+2) {
    background: var(--ipp-gray-50);
}
.ipp-tpl-palace .ipp-detail__label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--ipp-gray-400);
    margin-bottom: 4px;
}
.ipp-tpl-palace .ipp-detail__value {
    font-size: 15px;
    font-weight: 500;
    color: var(--ipp-gray-800);
    display: flex;
    align-items: center;
    gap: 6px;
}
.ipp-tpl-palace .ipp-detail__icon--yes { color: var(--ipp-success); }
.ipp-tpl-palace .ipp-detail__icon--no { color: var(--ipp-danger); }

/* Amenities Tags */
.ipp-tpl-palace .ipp-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.ipp-tpl-palace .ipp-tag {
    display: inline-block;
    padding: 6px 14px;
    background: var(--ipp-gray-100);
    color: var(--ipp-gray-700);
    border-radius: 100px;
    font-size: 13px;
    font-weight: 500;
    transition: var(--ipp-transition);
}
.ipp-tpl-palace .ipp-tag:hover {
    background: var(--ipp-accent-light);
    color: var(--ipp-accent);
}

/* Feature Details */
.ipp-tpl-palace .ipp-feature-text {
    font-size: 15px;
    line-height: 1.7;
    color: var(--ipp-gray-600);
}

/* Custom Fields Table */
.ipp-tpl-palace .ipp-custom-table {
    width: 100%;
    border-collapse: collapse;
    border-radius: var(--ipp-radius);
    overflow: hidden;
    border: 1px solid var(--ipp-gray-200);
}
.ipp-tpl-palace .ipp-custom-table th,
.ipp-tpl-palace .ipp-custom-table td {
    padding: 10px 16px;
    text-align: left;
    font-size: 14px;
}
.ipp-tpl-palace .ipp-custom-table th {
    background: var(--ipp-gray-100);
    font-weight: 600;
    color: var(--ipp-gray-600);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.ipp-tpl-palace .ipp-custom-table tr:nth-child(even) td {
    background: var(--ipp-gray-50);
}
.ipp-tpl-palace .ipp-custom-table td {
    border-top: 1px solid var(--ipp-gray-100);
}

/* Virtual Tour */
.ipp-tpl-palace .ipp-tour__btn {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 14px 28px;
    background: var(--ipp-accent);
    color: #fff;
    border-radius: var(--ipp-radius-sm);
    font-size: 15px;
    font-weight: 600;
    text-decoration: none;
    transition: var(--ipp-transition);
    margin-bottom: 20px;
}
.ipp-tpl-palace .ipp-tour__btn:hover {
    background: #1d4ed8;
    transform: translateY(-1px);
    box-shadow: var(--ipp-shadow-lg);
    color: #fff;
}
.ipp-tpl-palace .ipp-tour__btn svg {
    width: 20px;
    height: 20px;
}
.ipp-tpl-palace .ipp-tour__embed {
    width: 100%;
    height: 400px;
    border: none;
    border-radius: var(--ipp-radius);
    box-shadow: var(--ipp-shadow);
}

/* Map */
.ipp-tpl-palace .ipp-map-wrap {
    border-radius: var(--ipp-radius);
    overflow: hidden;
    box-shadow: var(--ipp-shadow);
}
.ipp-tpl-palace .ipp-map-wrap iframe {
    width: 100%;
    height: 400px;
    border: none;
    display: block;
}

/* Sidebar */
.ipp-tpl-palace .ipp-sidebar {
    position: sticky;
    top: 2rem;
    align-self: start;
}

/* Agent Card */
.ipp-tpl-palace .ipp-agent-card {
    background: #fff;
    border-radius: var(--ipp-radius-lg);
    box-shadow: var(--ipp-shadow-lg);
    padding: 28px;
    margin-bottom: 24px;
    border: 1px solid var(--ipp-gray-100);
}
.ipp-tpl-palace .ipp-agent-card__avatar {
    width: 72px;
    height: 72px;
    background: var(--ipp-accent-light);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
}
.ipp-tpl-palace .ipp-agent-card__avatar svg {
    width: 36px;
    height: 36px;
    color: var(--ipp-accent);
}
.ipp-tpl-palace .ipp-agent-card__name {
    font-size: 20px !important;
    font-weight: 700 !important;
    color: var(--ipp-gray-900) !important;
    text-align: center !important;
    margin: 0 0 4px !important;
}
.ipp-tpl-palace .ipp-agent-card__title {
    font-size: 14px !important;
    color: var(--ipp-gray-500) !important;
    text-align: center !important;
    margin: 0 0 20px !important;
}
.ipp-tpl-palace .ipp-agent-card__contacts {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}
.ipp-tpl-palace .ipp-agent-card__link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: var(--ipp-gray-50);
    border-radius: var(--ipp-radius-sm);
    text-decoration: none;
    color: var(--ipp-gray-700);
    font-size: 14px;
    font-weight: 500;
    transition: var(--ipp-transition);
}
.ipp-tpl-palace .ipp-agent-card__link:hover {
    background: var(--ipp-accent-light);
    color: var(--ipp-accent);
}
.ipp-tpl-palace .ipp-agent-card__link svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    color: var(--ipp-gray-400);
}
.ipp-tpl-palace .ipp-agent-card__link:hover svg {
    color: var(--ipp-accent);
}
.ipp-tpl-palace .ipp-agent-card__enquire {
    display: block;
    width: 100%;
    padding: 14px;
    background: var(--ipp-accent);
    color: #fff;
    border: none;
    border-radius: var(--ipp-radius-sm);
    font-size: 15px;
    font-weight: 600;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    transition: var(--ipp-transition);
}
.ipp-tpl-palace .ipp-agent-card__enquire:hover {
    background: #1d4ed8;
    transform: translateY(-1px);
    box-shadow: var(--ipp-shadow-lg);
    color: #fff;
}

/* Quick Facts Sidebar */
.ipp-tpl-palace .ipp-quickfacts {
    background: #fff;
    border-radius: var(--ipp-radius-lg);
    box-shadow: var(--ipp-shadow);
    padding: 24px;
    margin-bottom: 24px;
    border: 1px solid var(--ipp-gray-100);
}
.ipp-tpl-palace .ipp-quickfacts__title {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--ipp-gray-400);
    margin: 0 0 14px;
}
.ipp-tpl-palace .ipp-quickfacts__item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    font-size: 14px;
}
.ipp-tpl-palace .ipp-quickfacts__item:not(:last-child) {
    border-bottom: 1px solid var(--ipp-gray-100);
}
.ipp-tpl-palace .ipp-quickfacts__label {
    color: var(--ipp-gray-500) !important;
}
.ipp-tpl-palace .ipp-quickfacts__value {
    font-weight: 600 !important;
    color: var(--ipp-gray-800) !important;
}

/* Share */
.ipp-tpl-palace .ipp-share {
    background: #fff;
    border-radius: var(--ipp-radius-lg);
    box-shadow: var(--ipp-shadow);
    padding: 24px;
    border: 1px solid var(--ipp-gray-100);
}
.ipp-tpl-palace .ipp-share__title {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--ipp-gray-400);
    margin: 0 0 14px;
}
.ipp-tpl-palace .ipp-share__links {
    display: flex;
    gap: 10px;
}
.ipp-tpl-palace .ipp-share__link {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: var(--ipp-radius-sm);
    background: var(--ipp-gray-50);
    color: var(--ipp-gray-600);
    text-decoration: none;
    transition: var(--ipp-transition);
}
.ipp-tpl-palace .ipp-share__link:hover {
    transform: translateY(-2px);
    box-shadow: var(--ipp-shadow-md);
}
.ipp-tpl-palace .ipp-share__link--facebook:hover { background: #1877f2; color: #fff; }
.ipp-tpl-palace .ipp-share__link--twitter:hover { background: #0f1419; color: #fff; }
.ipp-tpl-palace .ipp-share__link--email:hover { background: var(--ipp-accent); color: #fff; }
.ipp-tpl-palace .ipp-share__link svg {
    width: 20px;
    height: 20px;
}

/* No Image Placeholder */
.ipp-tpl-palace .ipp-hero__placeholder {
    height: 320px;
    background: linear-gradient(135deg, var(--ipp-gray-100), var(--ipp-gray-200));
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--ipp-gray-400);
}
.ipp-tpl-palace .ipp-hero__placeholder svg {
    width: 64px;
    height: 64px;
}

/* Responsive */
@media (max-width: 768px) {
    .ipp-tpl-palace .ipp-layout {
        grid-template-columns: 1fr !important;
        gap: 24px !important;
        padding: 0 16px 40px !important;
    }
    .ipp-tpl-palace .ipp-sidebar {
        position: static;
    }
    .ipp-tpl-palace .ipp-quickbar {
        padding: 16px;
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    .ipp-tpl-palace .ipp-quickbar__divider {
        display: none;
    }
    .ipp-tpl-palace .ipp-quickbar__available {
        margin-left: 0;
    }
    .ipp-tpl-palace .ipp-stats {
        padding: 16px;
    }
    .ipp-tpl-palace .ipp-hero__main img,
    .ipp-tpl-palace .ipp-hero--single img {
        height: 280px;
    }
    .ipp-tpl-palace .ipp-details {
        grid-template-columns: 1fr;
    }
    .ipp-tpl-palace .ipp-detail:nth-child(odd) {
        border-right: none;
    }
    .ipp-tpl-palace .ipp-address__main {
        font-size: 20px;
    }
}
@media (min-width: 769px) and (max-width: 1024px) {
    .ipp-tpl-palace .ipp-layout {
        grid-template-columns: 1fr 300px !important;
        gap: 28px !important;
    }
}
</style>

<div class="ipp-single ipp-tpl-palace">

    <!-- ==================== HERO GALLERY ==================== -->
    <div class="ipp-hero">
        <?php if ($has_gallery) : ?>
            <div class="ipp-gallery ipp-hero__main">
                <img id="ipp-gallery-main-img"
                     src="<?php echo esc_url($images[0]['url']); ?>"
                     data-full="<?php echo esc_url($images[0]['full']); ?>"
                     alt="<?php echo esc_attr($images[0]['alt'] ?: get_the_title()); ?>" />
                <div class="ipp-hero__overlay"></div>
                <span class="ipp-hero__count ipp-gallery__count">
                    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="8.5" cy="8.5" r="1.5"/><path d="m21 15-5-5L5 21"/></svg>
                    <?php echo esc_html(count($images)); ?> Photos
                </span>
            </div>
            <div class="ipp-gallery__thumbs ipp-hero__thumbstrip">
                <?php foreach ($images as $i => $img) : ?>
                    <button class="ipp-gallery__thumb ipp-hero__thumb<?php echo $i === 0 ? ' is-active' : ''; ?>"
                            data-full="<?php echo esc_url($img['full']); ?>"
                            data-url="<?php echo esc_url($img['url']); ?>"
                            data-alt="<?php echo esc_attr($img['alt']); ?>"
                            type="button">
                        <img src="<?php echo esc_url($img['thumb']); ?>" alt="<?php echo esc_attr($img['alt']); ?>" loading="lazy" />
                    </button>
                <?php endforeach; ?>
            </div>
        <?php elseif ($has_any_image) : ?>
            <div class="ipp-gallery ipp-hero__main ipp-hero--single">
                <?php
                $single_img = !empty($featured) ? $featured : $images[0];
                $img_url = is_array($single_img) ? $single_img['url'] : $single_img;
                $img_full = is_array($single_img) ? ($single_img['full'] ?? $single_img['url']) : $single_img;
                ?>
                <img id="ipp-gallery-main-img"
                     src="<?php echo esc_url($img_url); ?>"
                     data-full="<?php echo esc_url($img_full); ?>"
                     alt="<?php echo esc_attr(get_the_title()); ?>" />
                <div class="ipp-hero__overlay"></div>
            </div>
        <?php else : ?>
            <div class="ipp-hero__placeholder">
                <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="8.5" cy="8.5" r="1.5"/><path d="m21 15-5-5L5 21"/></svg>
            </div>
        <?php endif; ?>
    </div>

    <!-- ==================== QUICK INFO BAR ==================== -->
    <div class="ipp-quickbar ipp-container">
        <?php if ($prop->show('status') && $prop->status()) : ?>
            <span class="ipp-quickbar__badge ipp-quickbar__badge--status ipp-badge <?php echo strtolower($prop->status()) === 'active' ? 'ipp-badge--active' : 'ipp-badge--inactive is-inactive'; ?>">
                <svg width="8" height="8" viewBox="0 0 8 8"><circle cx="4" cy="4" r="4" fill="currentColor"/></svg>
                <?php echo esc_html($prop->status()); ?>
            </span>
        <?php endif; ?>

        <?php if ($prop->show('class') && $prop->property_class()) : ?>
            <span class="ipp-quickbar__badge ipp-quickbar__badge--class">
                <?php echo esc_html($prop->property_class()); ?>
            </span>
        <?php endif; ?>

        <?php if ($prop->show('rent') && $prop->formatted_rent()) : ?>
            <div class="ipp-quickbar__divider"></div>
            <div>
                <span class="ipp-quickbar__rent"><?php echo esc_html($prop->formatted_rent()); ?></span>
                <?php if ($prop->rental_period()) : ?>
                    <span class="ipp-quickbar__period">/ <?php echo esc_html($prop->rental_period()); ?></span>
                <?php endif; ?>
            </div>
        <?php endif; ?>

        <?php if ($prop->show('date_available') && $prop->formatted_date_available()) : ?>
            <div class="ipp-quickbar__divider"></div>
            <span class="ipp-quickbar__available">
                Available <strong><?php echo esc_html($prop->formatted_date_available()); ?></strong>
            </span>
        <?php endif; ?>
    </div>

    <!-- ==================== KEY STATS ROW ==================== -->
    <?php
    $has_stats = ($prop->show('bedrooms') && $prop->bedrooms()) ||
                 ($prop->show('bathrooms') && $prop->bathrooms()) ||
                 ($prop->show('ensuites') && $prop->ensuites()) ||
                 ($prop->show('cars') && $prop->cars()) ||
                 ($prop->show('parking') && $prop->parking());
    ?>
    <?php if ($has_stats) : ?>
    <div class="ipp-stats ipp-container">
        <?php if ($prop->show('bedrooms') && $prop->bedrooms()) : ?>
            <span class="ipp-stat ipp-stat--bed">
                <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M2 4v16"/><path d="M2 8h18a2 2 0 0 1 2 2v10"/><path d="M2 17h20"/><path d="M6 8v2a2 2 0 0 0 2 2h2a2 2 0 0 0 2-2V8"/></svg>
                <?php echo esc_html($prop->bedrooms()); ?> Bed<?php echo (int)$prop->bedrooms() !== 1 ? 's' : ''; ?>
            </span>
        <?php endif; ?>
        <?php if ($prop->show('bathrooms') && $prop->bathrooms()) : ?>
            <span class="ipp-stat ipp-stat--bath">
                <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 12h16a1 1 0 0 1 1 1v3a4 4 0 0 1-4 4H7a4 4 0 0 1-4-4v-3a1 1 0 0 1 1-1z"/><path d="M6 12V5a2 2 0 0 1 2-2h3v2.25"/><path d="M4 21h16"/></svg>
                <?php echo esc_html($prop->bathrooms()); ?> Bath<?php echo (int)$prop->bathrooms() !== 1 ? 's' : ''; ?>
            </span>
        <?php endif; ?>
        <?php if ($prop->show('ensuites') && $prop->ensuites()) : ?>
            <span class="ipp-stat ipp-stat--ensuite">
                <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 12h16a1 1 0 0 1 1 1v3a4 4 0 0 1-4 4H7a4 4 0 0 1-4-4v-3a1 1 0 0 1 1-1z"/><path d="M6 12V5a2 2 0 0 1 2-2h3v2.25"/></svg>
                <?php echo esc_html($prop->ensuites()); ?> Ensuite<?php echo (int)$prop->ensuites() !== 1 ? 's' : ''; ?>
            </span>
        <?php endif; ?>
        <?php if ($prop->show('cars') && $prop->cars()) : ?>
            <span class="ipp-stat ipp-stat--car">
                <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M19 17h2c.6 0 1-.4 1-1v-3c0-.9-.7-1.7-1.5-1.9L18 10l-2.7-3.4A1 1 0 0 0 14.5 6h-5a1 1 0 0 0-.8.4L6 10l-2.5 1.1C2.7 11.3 2 12.1 2 13v3c0 .6.4 1 1 1h2"/><circle cx="7" cy="17" r="2"/><circle cx="17" cy="17" r="2"/></svg>
                <?php echo esc_html($prop->cars()); ?> Car<?php echo (int)$prop->cars() !== 1 ? 's' : ''; ?>
            </span>
        <?php endif; ?>
        <?php if ($prop->show('parking') && $prop->parking()) : ?>
            <span class="ipp-stat ipp-stat--parking">
                <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2"/><path d="M9 17V7h4a3 3 0 0 1 0 6H9"/></svg>
                <?php echo esc_html($prop->parking()); ?>
            </span>
        <?php endif; ?>
    </div>
    <?php endif; ?>

    <!-- ==================== TWO COLUMN LAYOUT ==================== -->
    <div class="ipp-layout ipp-container">

        <!-- ===== LEFT COLUMN ===== -->
        <div class="ipp-single__content">

            <!-- Address -->
            <?php if ($prop->full_address()) : ?>
            <div class="ipp-address ipp-section">
                <div class="ipp-address__main">
                    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M20 10c0 6-8 12-8 12s-8-6-8-12a8 8 0 0 1 16 0Z"/><circle cx="12" cy="10" r="3"/></svg>
                    <span><?php echo esc_html($prop->full_address()); ?></span>
                </div>
                <div class="ipp-address__sub">
                    <?php if ($prop->suburb()) : ?>
                        <span><?php echo esc_html($prop->suburb()); ?></span>
                    <?php endif; ?>
                    <?php if ($prop->region()) : ?>
                        <span><?php echo esc_html($prop->region()); ?></span>
                    <?php endif; ?>
                    <?php if ($prop->postcode()) : ?>
                        <span><?php echo esc_html($prop->postcode()); ?></span>
                    <?php endif; ?>
                </div>
            </div>
            <?php endif; ?>

            <!-- Description -->
            <?php
            $description = $prop->advert_text() ?: get_the_content();
            if ($prop->show('advert_text') && $description) : ?>
            <div class="ipp-section ipp-single__section">
                <h2 class="ipp-section__title ipp-single__section-title">Description</h2>
                <div class="ipp-description">
                    <?php echo wp_kses_post(wpautop($description)); ?>
                </div>
            </div>
            <?php endif; ?>

            <!-- Header -->
            <?php if ($prop->show('header') && $prop->header()) : ?>
            <div class="ipp-section ipp-single__section">
                <h2 class="ipp-section__title ipp-single__section-title">Headline</h2>
                <div class="ipp-description">
                    <?php echo wp_kses_post(wpautop($prop->header())); ?>
                </div>
            </div>
            <?php endif; ?>

            <!-- Property Details Grid -->
            <?php
            $details = [];
            if ($prop->show('property_code') && $prop->property_code()) $details[] = ['Property Code', $prop->property_code()];
            if ($prop->show('class') && $prop->property_class()) $details[] = ['Property Class', $prop->property_class()];
            if ($prop->show('management_type') && $prop->management_type()) $details[] = ['Management Type', $prop->management_type()];
            if ($prop->show('year_built') && $prop->year_built()) $details[] = ['Year Built', $prop->year_built()];
            if ($prop->show('stories') && $prop->stories()) $details[] = ['Stories', $prop->stories()];
            if ($prop->show('floor_area') && $prop->floor_area()) $details[] = ['Floor Area', $prop->floor_area()];
            if ($prop->show('land_area_sqm') && $prop->land_area_sqm()) $details[] = ['Land Area (m²)', $prop->land_area_sqm() . ' m²'];
            if ($prop->show('land_area_hectares') && $prop->land_area_hectares()) $details[] = ['Land Area (ha)', $prop->land_area_hectares() . ' ha'];
            if ($prop->show('furnishings') && $prop->furnishings()) $details[] = ['Furnishings', $prop->furnishings()];
            if ($prop->show('new_construction') && $prop->new_construction()) $details[] = ['New Construction', $prop->new_construction()];
            if ($prop->show('pets_allowed')) $details[] = ['Pets Allowed', $prop->pets_allowed() ? 'Yes' : 'No', $prop->pets_allowed()];
            if ($prop->show('smokers_allowed')) $details[] = ['Smokers Allowed', $prop->smokers_allowed() ? 'Yes' : 'No', $prop->smokers_allowed()];
            if ($prop->show('unit') && $prop->unit()) $details[] = ['Unit', $prop->unit()];
            ?>
            <?php if (!empty($details)) : ?>
            <div class="ipp-section ipp-single__section">
                <h2 class="ipp-section__title ipp-single__section-title">Property Details</h2>
                <div class="ipp-details">
                    <?php foreach ($details as $d) : ?>
                        <div class="ipp-detail ipp-single__detail-row">
                            <span class="ipp-detail__label ipp-single__detail-label"><?php echo esc_html($d[0]); ?></span>
                            <span class="ipp-detail__value ipp-single__detail-value">
                                <?php if (isset($d[2])) : ?>
                                    <?php if ($d[2]) : ?>
                                        <svg class="ipp-detail__icon--yes" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><path d="M20 6 9 17l-5-5"/></svg>
                                    <?php else : ?>
                                        <svg class="ipp-detail__icon--no" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg>
                                    <?php endif; ?>
                                <?php endif; ?>
                                <?php echo esc_html($d[1]); ?>
                            </span>
                        </div>
                    <?php endforeach; ?>
                </div>
            </div>
            <?php endif; ?>

            <!-- Amenities -->
            <?php if ($prop->show('amenities') && $prop->amenities()) : ?>
            <div class="ipp-section ipp-single__section">
                <h2 class="ipp-section__title ipp-single__section-title">Amenities</h2>
                <div class="ipp-tags">
                    <?php
                    $amenity_list = preg_split('/[,;\n]+/', $prop->amenities());
                    foreach ($amenity_list as $amenity) :
                        $amenity = trim($amenity);
                        if ($amenity) : ?>
                            <span class="ipp-tag"><?php echo esc_html($amenity); ?></span>
                        <?php endif;
                    endforeach; ?>
                </div>
            </div>
            <?php endif; ?>

            <!-- Feature Details -->
            <?php if ($prop->show('feature_details') && $prop->feature_details()) : ?>
            <div class="ipp-section ipp-single__section">
                <h2 class="ipp-section__title ipp-single__section-title">Feature Details</h2>
                <div class="ipp-feature-text">
                    <?php echo wp_kses_post(wpautop($prop->feature_details())); ?>
                </div>
            </div>
            <?php endif; ?>

            <!-- Custom Fields -->
            <?php
            $custom = $prop->custom_fields();
            if (!empty($custom)) : ?>
            <div class="ipp-section ipp-single__section">
                <h2 class="ipp-section__title ipp-single__section-title">Additional Information</h2>
                <table class="ipp-custom-table">
                    <thead>
                        <tr>
                            <th>Field</th>
                            <th>Value</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($custom as $key => $value) : ?>
                            <tr>
                                <td><?php echo esc_html($key); ?></td>
                                <td><?php echo esc_html($value); ?></td>
                            </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            </div>
            <?php endif; ?>

            <!-- Virtual Tour -->
            <?php if ($prop->show('virtual_tour_url') && $prop->virtual_tour_url()) : ?>
            <div class="ipp-section ipp-single__section">
                <h2 class="ipp-section__title ipp-single__section-title">Virtual Tour</h2>
                <a href="<?php echo esc_url($prop->virtual_tour_url()); ?>" target="_blank" rel="noopener noreferrer" class="ipp-tour__btn">
                    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polygon points="5 3 19 12 5 21 5 3"/></svg>
                    Take Virtual Tour
                </a>
                <iframe class="ipp-tour__embed" src="<?php echo esc_url($prop->virtual_tour_url()); ?>" allowfullscreen loading="lazy"></iframe>
            </div>
            <?php endif; ?>

            <!-- Web Link -->
            <?php if ($prop->show('web_link_url') && $prop->web_link_url()) : ?>
            <div class="ipp-section ipp-single__section">
                <a href="<?php echo esc_url($prop->web_link_url()); ?>" target="_blank" rel="noopener noreferrer" class="ipp-tour__btn">
                    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"/><polyline points="15 3 21 3 21 9"/><line x1="10" y1="14" x2="21" y2="3"/></svg>
                    View External Link
                </a>
            </div>
            <?php endif; ?>

            <!-- Map -->
            <?php if ($prop->show('geographic_location') && $prop->has_map_coords()) : ?>
            <div class="ipp-section ipp-single__section">
                <h2 class="ipp-section__title ipp-single__section-title">Location</h2>
                <div class="ipp-map-wrap ipp-map">
                    <iframe src="<?php echo esc_url($prop->map_embed_url()); ?>" allowfullscreen loading="lazy" referrerpolicy="no-referrer-when-downgrade"></iframe>
                </div>
            </div>
            <?php endif; ?>

        </div>

        <!-- ===== RIGHT COLUMN (SIDEBAR) ===== -->
        <div class="ipp-single__sidebar ipp-sidebar">

            <!-- Agent Card -->
            <?php if ($prop->agent_name()) : ?>
            <div class="ipp-agent-card ipp-agent">
                <div class="ipp-agent-card__avatar">
                    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"/><circle cx="12" cy="7" r="4"/></svg>
                </div>
                <h3 class="ipp-agent-card__name ipp-agent__name"><?php echo esc_html($prop->agent_name()); ?></h3>
                <?php if ($prop->agent_title()) : ?>
                    <p class="ipp-agent-card__title ipp-agent__role"><?php echo esc_html($prop->agent_title()); ?></p>
                <?php else : ?>
                    <p class="ipp-agent-card__title ipp-agent__role">Property Agent</p>
                <?php endif; ?>

                <div class="ipp-agent-card__contacts ipp-agent__contact">
                    <?php if ($prop->agent_phone_mobile()) : ?>
                        <a href="tel:<?php echo esc_attr($prop->agent_phone_mobile()); ?>" class="ipp-agent-card__link">
                            <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72c.127.96.361 1.903.7 2.81a2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45c.907.339 1.85.573 2.81.7A2 2 0 0 1 22 16.92z"/></svg>
                            <?php echo esc_html($prop->agent_phone_mobile()); ?>
                        </a>
                    <?php endif; ?>
                    <?php if ($prop->agent_phone_work()) : ?>
                        <a href="tel:<?php echo esc_attr($prop->agent_phone_work()); ?>" class="ipp-agent-card__link">
                            <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="2" y="4" width="20" height="16" rx="2"/><path d="M2 8h20"/><path d="M12 4v4"/></svg>
                            <?php echo esc_html($prop->agent_phone_work()); ?>
                        </a>
                    <?php endif; ?>
                    <?php if ($prop->agent_email()) : ?>
                        <a href="mailto:<?php echo esc_attr($prop->agent_email()); ?>" class="ipp-agent-card__link">
                            <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect width="20" height="16" x="2" y="4" rx="2"/><path d="m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7"/></svg>
                            <?php echo esc_html($prop->agent_email()); ?>
                        </a>
                    <?php endif; ?>
                    <?php if ($prop->agent_email2()) : ?>
                        <a href="mailto:<?php echo esc_attr($prop->agent_email2()); ?>" class="ipp-agent-card__link">
                            <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect width="20" height="16" x="2" y="4" rx="2"/><path d="m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7"/></svg>
                            <?php echo esc_html($prop->agent_email2()); ?>
                        </a>
                    <?php endif; ?>
                </div>

                <a href="mailto:<?php echo esc_attr($prop->agent_email()); ?>?subject=<?php echo esc_attr('Enquiry: ' . get_the_title()); ?>&body=<?php echo esc_attr("Hi " . $prop->agent_name() . ",\n\nI am interested in the property: " . get_the_title() . " (" . get_permalink() . ").\n\nPlease get in touch.\n\nThank you."); ?>"
                   class="ipp-agent-card__enquire ipp-btn ipp-btn--primary ipp-agent__action">
                    Enquire Now
                </a>
            </div>
            <?php endif; ?>

            <!-- Quick Facts -->
            <div class="ipp-quickfacts">
                <h4 class="ipp-quickfacts__title">Property Quick Facts</h4>
                <?php if ($prop->property_code()) : ?>
                <div class="ipp-quickfacts__item">
                    <span class="ipp-quickfacts__label">Code</span>
                    <span class="ipp-quickfacts__value"><?php echo esc_html($prop->property_code()); ?></span>
                </div>
                <?php endif; ?>
                <?php if ($prop->status()) : ?>
                <div class="ipp-quickfacts__item">
                    <span class="ipp-quickfacts__label">Status</span>
                    <span class="ipp-quickfacts__value"><?php echo esc_html($prop->status()); ?></span>
                </div>
                <?php endif; ?>
                <?php if ($prop->management_type()) : ?>
                <div class="ipp-quickfacts__item">
                    <span class="ipp-quickfacts__label">Management</span>
                    <span class="ipp-quickfacts__value"><?php echo esc_html($prop->management_type()); ?></span>
                </div>
                <?php endif; ?>
            </div>

            <!-- Share -->
            <div class="ipp-share">
                <h4 class="ipp-share__title">Share This Property</h4>
                <div class="ipp-share__links">
                    <a href="https://www.facebook.com/sharer/sharer.php?u=<?php echo $share_url; ?>" target="_blank" rel="noopener noreferrer" class="ipp-share__link ipp-share__link--facebook" title="Share on Facebook">
                        <svg viewBox="0 0 24 24" fill="currentColor"><path d="M18 2h-3a5 5 0 0 0-5 5v3H7v4h3v8h4v-8h3l1-4h-4V7a1 1 0 0 1 1-1h3z"/></svg>
                    </a>
                    <a href="https://twitter.com/intent/tweet?url=<?php echo $share_url; ?>&text=<?php echo $share_title; ?>" target="_blank" rel="noopener noreferrer" class="ipp-share__link ipp-share__link--twitter" title="Share on X">
                        <svg viewBox="0 0 24 24" fill="currentColor"><path d="M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z"/></svg>
                    </a>
                    <a href="mailto:?subject=<?php echo $share_title; ?>&body=Check%20out%20this%20property:%20<?php echo $share_url; ?>" class="ipp-share__link ipp-share__link--email" title="Share via Email">
                        <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect width="20" height="16" x="2" y="4" rx="2"/><path d="m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7"/></svg>
                    </a>
                </div>
            </div>

        </div>

    </div>

    <!-- ==================== SCHEMA.ORG ==================== -->
    <?php echo $prop->schema_json_ld(); ?>

</div>
