/* =====================================================
   Virtual Property Tours - Main Stylesheet
   Premium Real Estate Design
   ===================================================== */

:root {
    --color-primary: #1a365d;
    --color-primary-light: #2c5282;
    --color-primary-dark: #0f2444;
    --color-accent: #c9a84c;
    --color-accent-hover: #b8943f;
    --color-success: #276749;
    --color-danger: #c53030;
    --color-warning: #d69e2e;
    
    --color-text: #1a202c;
    --color-text-secondary: #4a5568;
    --color-text-muted: #718096;
    --color-bg: #f7fafc;
    --color-bg-alt: #edf2f7;
    --color-white: #ffffff;
    --color-border: #e2e8f0;
    
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-serif: 'Playfair Display', Georgia, serif;
    
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -1px rgba(0,0,0,0.04);
    --shadow-md: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -2px rgba(0,0,0,0.04);
    --shadow-lg: 0 20px 25px -5px rgba(0,0,0,0.08), 0 10px 10px -5px rgba(0,0,0,0.03);
    
    --radius: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    
    --header-height: 72px;
    --transition: 0.2s ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
    font-family: var(--font-sans);
    font-size: 16px;
    line-height: 1.6;
    color: var(--color-text);
    background: var(--color-bg);
    -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; height: auto; display: block; }
a { color: var(--color-primary); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--color-accent); }

.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

/* ========== HEADER ========== */
.site-header {
    position: sticky;
    top: 0;
    z-index: 1000;
    background: var(--color-white);
    border-bottom: 1px solid var(--color-border);
    height: var(--header-height);
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 100%;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 1.15rem;
    color: var(--color-primary);
}
.logo svg { color: var(--color-accent); }
.logo:hover { color: var(--color-primary); }

.main-nav {
    display: flex;
    gap: 32px;
}
.main-nav a {
    font-weight: 500;
    font-size: 0.95rem;
    color: var(--color-text-secondary);
}
.main-nav a:hover { color: var(--color-primary); }

.nav-toggle {
    display: none;
    flex-direction: column;
    gap: 5px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
}
.nav-toggle span {
    display: block;
    width: 24px;
    height: 2px;
    background: var(--color-text);
    transition: var(--transition);
}

/* ========== HERO ========== */
.hero {
    background: linear-gradient(135deg, var(--color-primary-dark) 0%, var(--color-primary) 50%, var(--color-primary-light) 100%);
    color: white;
    padding: 80px 20px 100px;
    text-align: center;
    position: relative;
    overflow: hidden;
}

.hero::before {
    content: '';
    position: absolute;
    inset: 0;
    background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.03'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

.hero-content {
    position: relative;
    max-width: 700px;
    margin: 0 auto;
}

.hero h1 {
    font-family: var(--font-serif);
    font-size: clamp(1.8rem, 4vw, 2.8rem);
    font-weight: 600;
    line-height: 1.25;
    margin-bottom: 16px;
}
.hero h1 span { color: var(--color-accent); }

.hero p {
    font-size: 1.1rem;
    opacity: 0.9;
    margin-bottom: 32px;
    font-weight: 300;
}

.hero-search {
    display: flex;
    gap: 8px;
    background: white;
    padding: 8px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    max-width: 600px;
    margin: 0 auto;
}

.hero-search input,
.hero-search select {
    flex: 1;
    border: none;
    padding: 12px 16px;
    font-size: 0.95rem;
    font-family: var(--font-sans);
    color: var(--color-text);
    background: transparent;
    outline: none;
}
.hero-search select { max-width: 140px; cursor: pointer; }

/* ========== BUTTONS ========== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    font-family: var(--font-sans);
    font-size: 0.95rem;
    font-weight: 500;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    white-space: nowrap;
}

.btn-primary {
    background: var(--color-accent);
    color: white;
}
.btn-primary:hover {
    background: var(--color-accent-hover);
    color: white;
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--color-primary);
    color: white;
}
.btn-secondary:hover {
    background: var(--color-primary-light);
    color: white;
}

.btn-outline {
    background: transparent;
    border: 2px solid var(--color-primary);
    color: var(--color-primary);
}
.btn-outline:hover {
    background: var(--color-primary);
    color: white;
}

.btn-360 {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-weight: 600;
    padding: 14px 28px;
    font-size: 1rem;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}
.btn-360:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.5);
    color: white;
}

.btn-sm { padding: 8px 16px; font-size: 0.875rem; }
.btn-lg { padding: 16px 32px; font-size: 1.05rem; }

/* ========== SECTIONS ========== */
.section { padding: 60px 0; }

.section-header {
    text-align: center;
    margin-bottom: 40px;
}
.section-header h2 {
    font-family: var(--font-serif);
    font-size: 1.8rem;
    color: var(--color-primary);
    margin-bottom: 8px;
}
.section-header p { color: var(--color-text-muted); }

/* ========== PROPERTY CARDS ========== */
.properties-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 28px;
}

.property-card {
    background: var(--color-white);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow);
    transition: transform var(--transition), box-shadow var(--transition);
}
.property-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
}

.card-image {
    position: relative;
    display: block;
    aspect-ratio: 16/10;
    overflow: hidden;
    background: var(--color-bg-alt);
}
.card-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.4s ease;
}
.property-card:hover .card-image img { transform: scale(1.05); }

.no-image {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--color-text-muted);
    font-size: 0.9rem;
}

.badge-360 {
    position: absolute;
    top: 12px;
    left: 12px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 5px 10px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.badge-operation {
    position: absolute;
    top: 12px;
    right: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 5px 12px;
    border-radius: 20px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.badge-operation.venta { background: var(--color-success); color: white; }
.badge-operation.renta { background: var(--color-primary); color: white; }

.card-body { padding: 20px; }

.card-price {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--color-primary);
    margin-bottom: 6px;
}

.card-title {
    font-size: 1.05rem;
    font-weight: 600;
    margin-bottom: 8px;
    line-height: 1.35;
}
.card-title a { color: var(--color-text); }
.card-title a:hover { color: var(--color-primary); }

.card-location {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.875rem;
    color: var(--color-text-muted);
    margin-bottom: 14px;
}

.card-features {
    display: flex;
    gap: 16px;
    padding-top: 14px;
    border-top: 1px solid var(--color-border);
    font-size: 0.875rem;
    color: var(--color-text-secondary);
}
.card-features strong { color: var(--color-text); }

/* ========== PAGINATION ========== */
.pagination {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 48px;
}
.pagination a {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: var(--radius);
    background: white;
    color: var(--color-text-secondary);
    font-weight: 500;
    border: 1px solid var(--color-border);
    transition: all var(--transition);
}
.pagination a:hover,
.pagination a.active {
    background: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
}

/* ========== EMPTY STATE ========== */
.empty-state {
    text-align: center;
    padding: 80px 20px;
    color: var(--color-text-muted);
}
.empty-state svg { margin: 0 auto 20px; opacity: 0.4; }
.empty-state h3 { color: var(--color-text); margin-bottom: 8px; }

/* ========== FOOTER ========== */
.site-footer {
    background: var(--color-primary-dark);
    color: rgba(255,255,255,0.8);
    padding: 60px 0 0;
    margin-top: 40px;
}
.footer-grid {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr;
    gap: 40px;
    padding-bottom: 40px;
}
.footer-brand .logo { color: white; margin-bottom: 12px; }
.footer-brand p { font-size: 0.9rem; line-height: 1.7; max-width: 300px; }
.footer-links h4 {
    color: white;
    font-size: 0.95rem;
    margin-bottom: 16px;
    font-weight: 600;
}
.footer-links a {
    display: block;
    color: rgba(255,255,255,0.7);
    font-size: 0.9rem;
    margin-bottom: 8px;
}
.footer-links a:hover { color: var(--color-accent); }
.footer-bottom {
    border-top: 1px solid rgba(255,255,255,0.1);
    padding: 20px 0;
    text-align: center;
    font-size: 0.85rem;
}

/* ========== PROPERTY DETAIL PAGE ========== */
.property-hero {
    position: relative;
    background: var(--color-primary-dark);
}

.gallery-main {
    position: relative;
    aspect-ratio: 21/9;
    max-height: 500px;
    overflow: hidden;
    background: #111;
}
.gallery-main img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.gallery-thumbs {
    display: flex;
    gap: 8px;
    padding: 12px 0;
    overflow-x: auto;
    scrollbar-width: thin;
}
.gallery-thumbs img {
    width: 100px;
    height: 70px;
    object-fit: cover;
    border-radius: var(--radius);
    cursor: pointer;
    opacity: 0.7;
    border: 2px solid transparent;
    transition: all var(--transition);
    flex-shrink: 0;
}
.gallery-thumbs img:hover,
.gallery-thumbs img.active {
    opacity: 1;
    border-color: var(--color-accent);
}

.property-content {
    display: grid;
    grid-template-columns: 1fr 360px;
    gap: 40px;
    padding: 40px 0;
}

.property-info h1 {
    font-family: var(--font-serif);
    font-size: 1.9rem;
    color: var(--color-primary);
    margin-bottom: 8px;
}

.property-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 20px;
    font-size: 0.9rem;
    color: var(--color-text-muted);
}
.property-meta span {
    display: flex;
    align-items: center;
    gap: 5px;
}

.property-price-tag {
    font-size: 2rem;
    font-weight: 700;
    color: var(--color-primary);
    margin-bottom: 24px;
}

.property-description {
    margin-bottom: 32px;
    line-height: 1.8;
    color: var(--color-text-secondary);
}

.features-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}
.feature-item {
    background: var(--color-bg);
    padding: 16px;
    border-radius: var(--radius);
    text-align: center;
}
.feature-item strong {
    display: block;
    font-size: 1.3rem;
    color: var(--color-primary);
    margin-bottom: 4px;
}
.feature-item span {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

/* Photos section with 360 buttons */
.photos-section { margin-bottom: 40px; }
.photos-section h2 {
    font-family: var(--font-serif);
    font-size: 1.4rem;
    margin-bottom: 20px;
    color: var(--color-primary);
}

.photo-room-group {
    margin-bottom: 28px;
}
.photo-room-group h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--color-text);
    display: flex;
    align-items: center;
    gap: 12px;
}

.photo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
}
.photo-item {
    position: relative;
    aspect-ratio: 4/3;
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
}
.photo-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s;
}
.photo-item:hover img { transform: scale(1.05); }

.btn-view-360 {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    font-size: 0.8rem;
    font-weight: 600;
    padding: 6px 12px;
    border-radius: 20px;
    border: none;
    cursor: pointer;
    transition: all var(--transition);
}
.btn-view-360:hover {
    transform: scale(1.05);
    color: white;
}

/* Sidebar */
.property-sidebar {
    position: sticky;
    top: calc(var(--header-height) + 20px);
    align-self: start;
}

.sidebar-card {
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 20px;
}

.sidebar-card h3 {
    font-size: 1rem;
    margin-bottom: 16px;
    color: var(--color-primary);
}

.agent-info {
    display: flex;
    gap: 14px;
    align-items: center;
    margin-bottom: 16px;
}
.agent-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--color-bg-alt);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: var(--color-primary);
    font-size: 1.2rem;
    overflow: hidden;
}
.agent-avatar img { width: 100%; height: 100%; object-fit: cover; }
.agent-name { font-weight: 600; }
.agent-role { font-size: 0.85rem; color: var(--color-text-muted); }

.contact-btns {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.contact-btns .btn { width: 100%; }

.share-btns {
    display: flex;
    gap: 10px;
}
.share-btns button,
.share-btns a {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: white;
    color: var(--color-text-secondary);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all var(--transition);
}
.share-btns button:hover,
.share-btns a:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
}

/* ========== 360 VIEWER ========== */
.tour-section {
    background: #0a0a0a;
    padding: 0;
    position: relative;
}

.tour-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: rgba(0,0,0,0.8);
    color: white;
}
.tour-header h2 {
    font-size: 1.1rem;
    font-weight: 500;
}
.tour-close {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 4px 8px;
    opacity: 0.7;
}
.tour-close:hover { opacity: 1; }

#panorama-viewer {
    width: 100%;
    height: 70vh;
    min-height: 400px;
    background: #111;
}

.tour-nav {
    display: flex;
    gap: 8px;
    padding: 16px 20px;
    background: rgba(0,0,0,0.9);
    overflow-x: auto;
    scrollbar-width: thin;
}
.tour-nav-btn {
    flex-shrink: 0;
    padding: 10px 20px;
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 24px;
    color: white;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}
.tour-nav-btn:hover,
.tour-nav-btn.active {
    background: var(--color-accent);
    border-color: var(--color-accent);
    color: white;
}

/* Fullscreen tour overlay */
.tour-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: #000;
    display: none;
    flex-direction: column;
}
.tour-overlay.active { display: flex; }

.tour-overlay #panorama-viewer {
    flex: 1;
    height: auto;
    min-height: 0; /* critical for flex children */
}

/* Pannellum internal canvas fill */
.tour-overlay .pnlm-container {
    width: 100% !important;
    height: 100% !important;
}
.tour-overlay .pnlm-render-container,
.tour-overlay .pnlm-render-container canvas {
    width: 100% !important;
    height: 100% !important;
}

/* ========== RESPONSIVE ========== */
@media (max-width: 900px) {
    .property-content {
        grid-template-columns: 1fr;
    }
    .property-sidebar {
        position: static;
    }
    .footer-grid {
        grid-template-columns: 1fr;
        gap: 30px;
    }
    .gallery-main {
        aspect-ratio: 16/10;
        max-height: 350px;
    }
}

@media (max-width: 768px) {
    .main-nav {
        display: none;
        position: absolute;
        top: var(--header-height);
        left: 0;
        right: 0;
        background: white;
        flex-direction: column;
        padding: 20px;
        border-bottom: 1px solid var(--color-border);
        gap: 16px;
        box-shadow: var(--shadow);
    }
    .main-nav.open { display: flex; }
    .nav-toggle { display: flex; }
    
    .hero { padding: 50px 20px 70px; }
    .hero-search {
        flex-direction: column;
    }
    .hero-search select { max-width: none; }
    
    .properties-grid {
        grid-template-columns: 1fr;
    }
    
    .section { padding: 40px 0; }

    /* ---- 360 Tour: mobile immersive ---- */
    .tour-overlay {
        /* Full viewport including safe areas (notch / home indicator) */
        height: 100dvh;
        height: -webkit-fill-available;
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }

    .tour-header {
        padding: 10px 14px;
        flex-shrink: 0;
        background: rgba(0, 0, 0, 0.75);
        backdrop-filter: blur(8px);
        -webkit-backdrop-filter: blur(8px);
    }
    .tour-header h2 {
        font-size: 0.95rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 70vw;
    }
    .tour-close {
        font-size: 1.8rem;
        padding: 6px 12px;
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        opacity: 1;
        border-radius: 50%;
        background: rgba(255,255,255,0.12);
    }

    .tour-overlay #panorama-viewer {
        flex: 1 1 auto;
        height: auto !important;
        min-height: 0;
        /* Maximize viewing area on phone */
        touch-action: none;
    }

    .tour-nav {
        flex-shrink: 0;
        padding: 10px 12px;
        padding-bottom: max(10px, env(safe-area-inset-bottom));
        gap: 8px;
        background: rgba(0, 0, 0, 0.85);
        backdrop-filter: blur(8px);
        -webkit-backdrop-filter: blur(8px);
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .tour-nav::-webkit-scrollbar { display: none; }

    .tour-nav-btn {
        padding: 12px 18px;
        font-size: 0.9rem;
        min-height: 44px; /* Apple HIG touch target */
        border-radius: 22px;
        -webkit-tap-highlight-color: transparent;
    }

    /* Larger 360 CTA on property page */
    .btn-360 {
        width: 100%;
        padding: 16px 24px;
        font-size: 1.05rem;
    }
    .btn-view-360 {
        padding: 8px 14px;
        font-size: 0.85rem;
        min-height: 36px;
    }
}

@media (max-width: 480px) {
    .card-features { gap: 10px; font-size: 0.8rem; }
    .property-price-tag { font-size: 1.5rem; }
    .features-grid { grid-template-columns: repeat(2, 1fr); }

    .tour-header {
        padding: 8px 12px;
    }
    .tour-nav-btn {
        padding: 11px 16px;
        font-size: 0.85rem;
    }
}

/* Landscape phone: give even more space to the panorama */
@media (max-width: 900px) and (orientation: landscape) {
    .tour-header {
        padding: 6px 14px;
    }
    .tour-header h2 { font-size: 0.85rem; }
    .tour-nav {
        padding: 6px 10px;
    }
    .tour-nav-btn {
        padding: 8px 14px;
        min-height: 36px;
        font-size: 0.8rem;
    }
}
