/* ---------- Theme Tokens ---------- */
:root {
    --primary-color: #A31C2E;
    --primary-strong: #7C1523;
    --accent-color: #3BA7C6;
    --text-color: #494949;
    --muted-text-color: #727272;
    --border-color: #E0E0E0;
    --surface-strong: rgba(255, 255, 255, 0.92);
    --surface-soft: rgba(255, 255, 255, 0.85);
    --glass-highlight: rgba(255, 255, 255, 0.08);
    --blur-strong: 12px;
    --radius-card: 12px;
    --radius-sm: 8px;
    --radius-pill: 999px;
    --shadow-soft: 0 8px 24px rgba(0, 0, 0, 0.18);
    --shadow-strong: 0 14px 40px rgba(0, 0, 0, 0.28);
    --space-2xs: 4px;
    --space-xs: 8px;
    --space-sm: 12px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --font-primary: "Sora", "Segoe UI", system-ui, -apple-system, sans-serif;
    --font-text: "Manrope", "Segoe UI", system-ui, sans-serif;
}

body,
html {
    margin: 0;
    padding: 0;
    height: 100%;
    width: 100%;
    font-family: var(--font-text);
    color: var(--text-color);
    background-color: #F5F4F4;
    overflow: hidden;
    text-rendering: optimizeLegibility;
}

#container {
    position: relative;
    width: 100%;
    height: 100%;
}

#panorama {
    width: 100%;
    height: 100%;
    z-index: 1;
}

/* ---------- Loading Overlay ---------- */
#loading-overlay {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, rgba(163, 28, 46, 0.92), rgba(99, 117, 138, 0.9));
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: opacity 0.5s ease, visibility 0.5s ease;
    padding: var(--space-lg);
}

#loading-overlay.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.loading-content {
    text-align: center;
    color: #ffffff;
    font-family: var(--font-primary);
    max-width: 360px;
    width: min(90%, 380px);
    padding: var(--space-lg);
    border-radius: var(--radius-card);
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.92), rgba(245, 244, 244, 0.9));
    border: 1px solid rgba(0, 0, 0, 0.05);
    box-shadow: var(--shadow-strong);
    backdrop-filter: blur(var(--blur-strong));
}

.spinner {
    width: 54px;
    height: 54px;
    border: 4px solid rgba(255, 255, 255, 0.14);
    border-left-color: var(--primary-color);
    border-top-color: var(--accent-color);
    border-radius: 50%;
    margin: 0 auto var(--space-md);
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

#loading-text {
    font-size: clamp(1.1rem, 2vw, 1.5rem);
    margin-bottom: var(--space-sm);
    font-weight: 700;
    letter-spacing: 0.2px;
}

#loading-details {
    font-size: clamp(0.9rem, 1.5vw, 1rem);
    color: rgba(255, 255, 255, 0.82);
    margin-top: var(--space-xs);
}

.progress-container {
    width: 100%;
    height: 8px;
    background: rgba(255, 255, 255, 0.12);
    border-radius: var(--radius-pill);
    overflow: hidden;
    margin-top: var(--space-sm);
    border: 1px solid rgba(0, 0, 0, 0.05);
}

#progress-bar {
    width: 0%;
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color), var(--accent-color));
    transition: width 0.3s ease;
}

/* ---------- Branding & Chrome ---------- */
#logo {
    position: absolute;
    top: var(--space-lg);
    left: var(--space-lg);
    z-index: 3;
    max-width: clamp(90px, 12vw, 150px);
    height: auto;
    filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.25));
    transition: transform 0.2s ease, opacity 0.2s ease;
    opacity: 0.96;
}

#logo:hover {
    transform: scale(1.05);
    opacity: 1;
}

/* Autohide UI */
.ui-hidden {
    opacity: 0;
    pointer-events: none;
}

#controls, #logo {
    transition: opacity 0.5s ease;
}

/* ---------- Map ---------- */
#map {
    position: absolute;
    top: var(--space-sm);
    right: var(--space-sm);
    width: clamp(210px, 26vw, 340px);
    height: clamp(160px, 20vh, 240px);
    z-index: 2;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-card);
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.9), rgba(245, 244, 244, 0.92));
    box-shadow: var(--shadow-soft), 0 0 0 1px var(--glass-highlight), inset 0 1px 0 rgba(255, 255, 255, 0.45);
    backdrop-filter: blur(calc(var(--blur-strong) + 4px));
    overflow: hidden; /* Keep map contents clipped to border radius */
    min-width: 150px;
    min-height: 120px;
    max-width: 80vw;
    max-height: 80vh;
    transition: opacity 0.5s ease, width 0s, height 0s; /* Disable transition for width/height during drag */
}

.map-resize-handle {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 26px;
    height: 26px;
    background: linear-gradient(45deg, var(--primary-color) 50%, transparent 50%);
    cursor: sw-resize;
    z-index: 9999; /* Above Leaflet controls */
    border-top-right-radius: 6px;
    box-shadow: 2px -2px 6px rgba(0, 0, 0, 0.2);
    opacity: 0.9;
    transition: opacity 0.2s;
    touch-action: none;
}

.map-resize-handle:hover {
    opacity: 1;
}

/* Map Toggle Button */
.map-toggle {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 26px;
    height: 26px;
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: var(--radius-sm);
    color: var(--text-color);
    font-weight: 700;
    line-height: 24px;
    text-align: center;
    cursor: pointer;
    z-index: 1002; /* Above resize handle */
    font-family: monospace;
    box-shadow: 0 1px 6px rgba(0, 0, 0, 0.16);
    transition: transform 0.15s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.map-toggle:hover {
    background: white;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2);
    transform: translateY(-1px);
}

/* Minimized Map State */
#map.minimized {
    width: 44px !important; /* Override inline styles from resize */
    height: 44px !important;
    border-radius: 50%;
    overflow: hidden;
    cursor: pointer;
    min-width: 0;
    min-height: 0;
    border: 1px solid rgba(0, 0, 0, 0.08);
    background: rgba(255, 255, 255, 0.96);
}

#map.minimized .leaflet-control-container,
#map.minimized .map-resize-handle {
    display: none;
}

/* Adjust toggle position when minimized */
#map.minimized .map-toggle {
    top: 0;
    right: 0;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: transparent;
    border: none;
    color: transparent;
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="%23494949" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="1 6 1 22 8 18 16 22 23 18 23 2 16 6 8 2 1 6"></polygon><line x1="8" y1="2" x2="8" y2="18"></line><line x1="16" y1="6" x2="16" y2="22"></line></svg>');
    background-position: center;
    background-repeat: no-repeat;
    background-size: 20px;
}

/* ---------- Viewer Controls ---------- */
#controls {
    position: absolute;
    bottom: clamp(12px, 3vh, 28px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 2;
    background: var(--surface-strong);
    padding: var(--space-sm) var(--space-lg);
    border-radius: var(--radius-pill);
    color: var(--text-color);
    display: flex;
    gap: var(--space-md);
    align-items: center;
    box-shadow: var(--shadow-soft);
    backdrop-filter: blur(var(--blur-strong));
    -webkit-backdrop-filter: blur(var(--blur-strong));
    border: 1px solid var(--border-color);
}

button {
    cursor: pointer;
    padding: var(--space-xs) var(--space-md);
    background: rgba(255, 255, 255, 0.94);
    color: var(--text-color);
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: var(--radius-pill);
    font-weight: 700;
    font-family: var(--font-primary);
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease, color 0.2s ease;
    font-size: clamp(0.85rem, 1.5vw, 0.95rem);
    letter-spacing: 0.2px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.16);
}

button:hover {
    background: white;
    transform: translateY(-1px);
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.2);
}

button:active {
    transform: translateY(0);
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.18);
}

button:focus-visible,
.map-toggle:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

#btn-share {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-strong));
    color: #ffffff;
    border-color: rgba(0, 0, 0, 0.12);
    box-shadow: 0 6px 18px rgba(163, 28, 46, 0.32);
}

#btn-share:hover {
    background: linear-gradient(135deg, var(--primary-strong), var(--primary-color));
    box-shadow: 0 8px 22px rgba(124, 21, 35, 0.4);
}

#frame-display {
    font-family: var(--font-primary);
    font-weight: 600;
    letter-spacing: 0.6px;
    color: var(--text-color);
}

#controls button span.icon {
    display: none;
}

/* ---------- Hotspots ---------- */
.custom-hotspot {
    height: clamp(64px, 12vw, 110px);
    width: clamp(64px, 12vw, 110px);
    background-image: url('../ui/SVG/chevron-up.svg');
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
    cursor: pointer;
    transition: transform 0.2s, filter 0.2s;
    filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.4));
    position: relative;
}

.custom-hotspot:hover {
    transform: scale(1.18);
    filter: drop-shadow(0 10px 18px rgba(0, 0, 0, 0.55));
}

.custom-hotspot::after {
    content: "";
    position: absolute;
    inset: -10px;
    border-radius: 50%;
    background: radial-gradient(ellipse at center, rgba(59, 167, 198, 0.28), rgba(163, 28, 46, 0));
    opacity: 0;
    transform: scale(0.9);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.custom-hotspot:hover::after {
    opacity: 1;
    transform: scale(1.05);
}

/* Flip the back arrow visually */
.hotspot-prev {
    transform: rotate(180deg);
}

.hotspot-prev:hover {
    transform: rotate(180deg) scale(1.12);
}

/* Debug info text under arrows */
.custom-tooltip span {
    display: block;
    position: absolute;
    top: 120%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: var(--accent-color);
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-family: monospace;
    white-space: nowrap;
    pointer-events: none;
    line-height: 1.3;
    text-align: left;
}

/* Force Hide Pannellum Compass */
.pnlm-compass {
    display: none !important;
}

/* ---------- Responsiveness ---------- */
@media (max-width: 960px) {
    #controls {
        padding: var(--space-xs) var(--space-md);
        gap: var(--space-sm);
    }
}

@media (max-width: 640px) {
    #logo {
        max-width: clamp(72px, 20vw, 110px);
        top: var(--space-md);
        left: var(--space-md);
    }

    #map {
        width: clamp(190px, 40vw, 240px);
        height: clamp(140px, 26vh, 190px);
    }

    #controls button span.text { display: none; }
    #controls button span.icon { display: inline; }
    #controls { gap: var(--space-xs); }
}

@media (max-width: 480px) {
    #controls {
        bottom: var(--space-sm);
        padding: var(--space-xs) var(--space-sm);
    }

    #map {
        top: var(--space-xs);
        right: var(--space-xs);
    }
}
