/* CSS Variables and Theme Configuration */
:root {
    --bg-app: #090d16;
    --bg-sidebar: rgba(15, 23, 42, 0.6);
    --bg-card: rgba(30, 41, 59, 0.45);
    --bg-card-hover: rgba(30, 41, 59, 0.7);
    --bg-input: rgba(15, 23, 42, 0.8);
    
    --border-color: rgba(255, 255, 255, 0.08);
    --border-hover: rgba(255, 255, 255, 0.18);
    
    --color-primary: #8b5cf6; /* Glowing violet */
    --color-primary-glow: rgba(139, 92, 246, 0.5);
    --color-primary-hover: #a78bfa;
    
    --color-secondary: #06b6d4; /* Glowing cyan */
    --color-secondary-glow: rgba(6, 182, 212, 0.5);
    
    --color-text-main: #f8fafc;
    --color-text-muted: #94a3b8;
    --color-text-dark: #64748b;
    --color-danger: #ef4444;
    --color-danger-glow: rgba(239, 68, 68, 0.4);
    
    --font-heading: 'Outfit', 'Inter', sans-serif;
    --font-body: 'Inter', sans-serif;
    
    --glass-blur: 16px;
    --transition-speed: 0.3s;
}

/* General Resets */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: var(--bg-app);
    color: var(--color-text-main);
    font-family: var(--font-body);
    height: 100vh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

/* App Layout */
.app-container {
    display: flex;
    width: 100vw;
    height: 100vh;
    position: relative;
}

/* Sidebar Styling */
.sidebar {
    width: 360px;
    background: var(--bg-sidebar);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 10;
    transition: all var(--transition-speed) ease;
}

.sidebar-header {
    padding: 24px;
    border-bottom: 1px solid var(--border-color);
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo i {
    font-size: 28px;
    color: var(--color-primary);
    filter: drop-shadow(0 0 8px var(--color-primary-glow));
}

.logo span {
    font-family: var(--font-heading);
    font-size: 22px;
    font-weight: 700;
    letter-spacing: 0.5px;
    background: linear-gradient(135deg, #fff 30%, var(--color-primary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    font-size: 12px;
    color: var(--color-text-muted);
    margin-top: 4px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Tabs Navigation */
.sidebar-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
    padding: 0 16px;
    background: rgba(0, 0, 0, 0.1);
}

.tab-btn {
    flex: 1;
    background: none;
    border: none;
    color: var(--color-text-muted);
    padding: 14px 8px;
    font-family: var(--font-heading);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s ease;
    border-bottom: 2px solid transparent;
}

.tab-btn:hover {
    color: var(--color-text-main);
}

.tab-btn.active {
    color: var(--color-primary);
    border-bottom: 2px solid var(--color-primary);
}

/* Tab Content */
.tab-content {
    display: none;
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.tab-content.active {
    display: flex;
    flex-direction: column;
}

/* Form & Input Styles */
.form-group {
    margin-bottom: 20px;
}

label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--color-text-muted);
    margin-bottom: 8px;
}

input[type="text"],
input[type="url"],
textarea {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px 14px;
    color: var(--color-text-main);
    font-family: var(--font-body);
    font-size: 14px;
    transition: all 0.2s ease;
}

input[type="text"]:focus,
input[type="url"]:focus,
textarea:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.2);
    outline: none;
}

/* Button Styles */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    border-radius: 8px;
    font-family: var(--font-heading);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    border: none;
}

.btn-primary {
    background: linear-gradient(135deg, var(--color-primary), #6d28d9);
    color: #fff;
    box-shadow: 0 4px 14px var(--color-primary-glow);
}

.btn-primary:hover {
    filter: brightness(1.1);
    box-shadow: 0 6px 18px rgba(139, 92, 246, 0.7);
    transform: translateY(-1px);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.08);
    color: var(--color-text-main);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.15);
}

.btn-danger {
    background: rgba(239, 68, 68, 0.15);
    color: #fca5a5;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
    background: var(--color-danger);
    color: white;
    box-shadow: 0 4px 12px var(--color-danger-glow);
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--color-text-muted);
}

.btn-outline:hover {
    border-color: var(--color-primary);
    color: var(--color-text-main);
}

.btn-full {
    width: 100%;
}

.btn-sm {
    padding: 8px 14px;
    font-size: 12px;
}

.btn-xs {
    padding: 6px 10px;
    font-size: 11px;
}

/* Action Bar & Hints */
.action-bar {
    margin-bottom: 24px;
}

.hint-text {
    font-size: 11px;
    color: var(--color-text-muted);
    margin-top: 8px;
    line-height: 1.5;
    display: flex;
    align-items: flex-start;
    gap: 4px;
}

.hint-text i {
    font-size: 14px;
    color: var(--color-primary);
    flex-shrink: 0;
}

/* Section Title */
.section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--color-text-muted);
}

.badge {
    background: var(--color-primary);
    color: #fff;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: bold;
    box-shadow: 0 0 6px var(--color-primary-glow);
}

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
    color: var(--color-text-dark);
    border: 1px dashed var(--border-color);
    border-radius: 12px;
}

.empty-state i {
    font-size: 40px;
    margin-bottom: 12px;
}

.empty-state p {
    font-size: 13px;
    font-weight: 500;
}

/* Hotspot List */
.hotspot-list-wrapper {
    flex: 1;
    min-height: 150px;
}

.hotspot-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.hotspot-item {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    transition: all 0.2s ease;
}

.hotspot-item:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-hover);
    transform: translateX(2px);
}

.hotspot-item.active {
    background: rgba(139, 92, 246, 0.15);
    border-color: var(--color-primary);
    box-shadow: 0 0 10px rgba(139, 92, 246, 0.15);
}

.hotspot-item-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.hotspot-item-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--color-primary);
    box-shadow: 0 0 6px var(--color-primary-glow);
}

.hotspot-item.active .hotspot-item-dot {
    background-color: var(--color-secondary);
    box-shadow: 0 0 6px var(--color-secondary-glow);
}

.hotspot-item-title {
    font-size: 14px;
    font-weight: 600;
}

.hotspot-item-actions {
    display: flex;
    gap: 8px;
}

.hotspot-item-action-btn {
    background: none;
    border: none;
    color: var(--color-text-dark);
    cursor: pointer;
    font-size: 16px;
    transition: color 0.2s;
    padding: 4px;
}

.hotspot-item-action-btn:hover {
    color: var(--color-text-main);
}

.hotspot-item-action-btn.delete:hover {
    color: var(--color-danger);
}

/* File Upload & Settings Section */
.settings-section {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 20px;
}

.settings-section h3 {
    font-family: var(--font-heading);
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--color-text-main);
}

.file-upload-area {
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    padding: 20px 10px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.file-upload-area:hover, .file-upload-area.dragover {
    border-color: var(--color-primary);
    background: rgba(139, 92, 246, 0.05);
}

.file-upload-area i {
    font-size: 32px;
    color: var(--color-text-muted);
}

.file-upload-area p {
    font-size: 11px;
    color: var(--color-text-muted);
    line-height: 1.4;
    padding: 0 10px;
}

.file-info {
    font-size: 11px;
    color: var(--color-text-muted);
    margin-top: 8px;
    text-align: center;
    word-break: break-all;
}

.project-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.setting-row:last-child {
    margin-bottom: 0;
}

.setting-row label {
    margin-bottom: 0;
    text-transform: none;
    font-size: 13px;
    font-weight: 500;
    color: var(--color-text-main);
}

/* Switch styling */
.switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 20px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.1);
    transition: .3s;
    border: 1px solid var(--border-color);
}

.slider:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 2px;
    bottom: 2px;
    background-color: var(--color-text-muted);
    transition: .3s;
}

input:checked + .slider {
    background-color: var(--color-primary);
}

input:checked + .slider:before {
    transform: translateX(20px);
    background-color: white;
}

.slider.round {
    border-radius: 20px;
}

.slider.round:before {
    border-radius: 50%;
}

/* Main Viewport Area */
.viewport-area {
    flex: 1;
    position: relative;
    background-color: #0b0f17;
    height: 100vh;
}

.canvas-container {
    width: 100%;
    height: 100%;
    position: relative;
}

model-viewer {
    width: 100%;
    height: 100%;
    background-color: transparent;
    --poster-color: transparent;
}

/* Loading Overlay */
.loading-progress-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #090d16;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    transition: opacity 0.5s ease, visibility 0.5s ease;
}

.loading-progress-overlay.hide {
    opacity: 0;
    visibility: hidden;
}

.spinner-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.custom-spinner {
    width: 50px;
    height: 50px;
    border: 3px solid rgba(139, 92, 246, 0.1);
    border-radius: 50%;
    border-top-color: var(--color-primary);
    animation: spin 1s linear infinite;
    box-shadow: 0 0 15px rgba(139, 92, 246, 0.1);
}

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

#loading-percentage {
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 15px;
    color: var(--color-text-main);
}

.loading-error-card {
    max-width: 85%;
    text-align: center;
    padding: 28px;
    background: rgba(15, 23, 42, 0.85);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    display: flex;
    flex-direction: column;
    align-items: center;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.loading-error-card i {
    font-size: 48px;
    color: var(--color-danger);
    filter: drop-shadow(0 0 10px rgba(239, 68, 68, 0.4));
    margin-bottom: 16px;
}

.loading-error-card h3 {
    font-family: var(--font-heading);
    color: #fff;
    font-size: 18px;
    margin-bottom: 8px;
    font-weight: 600;
}

.loading-error-card p {
    font-size: 13px;
    color: var(--color-text-muted);
    line-height: 1.6;
    margin-bottom: 24px;
    max-width: 320px;
}

.loading-error-card .error-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
    width: 100%;
}

.loading-error-card .error-hint {
    font-size: 11px;
    color: var(--color-text-dark);
    line-height: 1.4;
    max-width: 320px;
}

/* Overlay indicator for Place Hotspot mode */
.viewport-overlay-message {
    position: absolute;
    top: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(8px);
    border: 1px solid var(--color-primary);
    padding: 10px 20px;
    border-radius: 30px;
    display: none;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    font-weight: 500;
    color: #fff;
    box-shadow: 0 4px 20px rgba(139, 92, 246, 0.3);
    z-index: 5;
    pointer-events: none;
    animation: breathe 2s infinite ease-in-out;
}

.viewport-overlay-message.show {
    display: flex;
}

.viewport-overlay-message i {
    color: var(--color-primary);
    font-size: 18px;
    animation: flash 1.5s infinite;
}

@keyframes flash {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 1; }
}

@keyframes breathe {
    0%, 100% { transform: translate(-50%, 0); }
    50% { transform: translate(-50%, -4px); }
}

/* 3D Hotspot Element inside model-viewer */
.hotspot {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: none;
    background-color: var(--color-primary);
    box-shadow: 0 0 10px var(--color-primary-glow);
    cursor: pointer;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 10;
}

.hotspot::after {
    content: "";
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 2px solid var(--color-primary);
    animation: pulse 2s infinite;
    box-sizing: border-box;
    pointer-events: none;
}

.hotspot:hover {
    background-color: var(--color-primary-hover);
    box-shadow: 0 0 15px var(--color-primary-glow);
    transform: scale(1.15);
}

.hotspot.active {
    background-color: var(--color-secondary);
    box-shadow: 0 0 15px var(--color-secondary-glow);
    transform: scale(1.25);
    z-index: 20;
}

.hotspot.active::after {
    border-color: var(--color-secondary);
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% {
        transform: scale(1);
        opacity: 0.8;
    }
    100% {
        transform: scale(2.2);
        opacity: 0;
    }
}

/* Floating Hotspot Annotation Card (dynamic position next to hotspot) */
.annotation-card {
    display: none;
    position: absolute;
    bottom: 28px;
    left: 50%;
    transform: translateX(-50%);
    width: 280px;
    background: rgba(15, 23, 42, 0.92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 16px;
    color: #fff;
    cursor: default;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5), 0 0 1px rgba(255, 255, 255, 0.2);
    z-index: 99;
    opacity: 0;
    transition: opacity 0.25s ease, transform 0.25s ease;
    pointer-events: auto; /* Allow clicking on cards! */
}

/* Triangular speech bubble arrow */
.annotation-card::after {
    content: "";
    position: absolute;
    bottom: -8px;
    left: 50%;
    transform: translateX(-50%);
    border-width: 8px 8px 0;
    border-style: solid;
    border-color: rgba(15, 23, 42, 0.92) transparent;
    display: block;
    width: 0;
}

.hotspot.active .annotation-card {
    display: flex;
    flex-direction: column;
    opacity: 1;
    transform: translateX(-50%) translateY(-5px);
}

.annotation-close-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    background: none;
    border: none;
    color: var(--color-text-muted);
    font-size: 16px;
    cursor: pointer;
    padding: 4px;
    line-height: 1;
    transition: color 0.2s;
    z-index: 10;
}

.annotation-close-btn:hover {
    color: #fff;
}

.annotation-img {
    width: 100%;
    max-height: 120px;
    object-fit: cover;
    border-radius: 6px;
    margin-bottom: 12px;
    background-color: rgba(255, 255, 255, 0.05);
}

.annotation-title {
    font-family: var(--font-heading);
    font-size: 15px;
    font-weight: 700;
    margin-bottom: 6px;
    color: #fff;
    line-height: 1.3;
    padding-right: 16px; /* Avoid overlapping close btn */
}

.annotation-desc {
    font-size: 12px;
    color: var(--color-text-muted);
    line-height: 1.5;
    margin-bottom: 12px;
    white-space: pre-wrap;
    max-height: 80px;
    overflow-y: auto;
}

.annotation-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    padding: 8px 12px;
    background: linear-gradient(135deg, var(--color-primary), #6d28d9);
    color: #fff;
    text-decoration: none;
    border-radius: 6px;
    font-family: var(--font-heading);
    font-size: 12px;
    font-weight: 600;
    text-align: center;
    transition: opacity 0.2s;
}

.annotation-link:hover {
    opacity: 0.9;
}

/* Hover-only simple tooltip (when NOT active) */
.hotspot-tooltip {
    display: block;
    position: absolute;
    bottom: 26px;
    left: 50%;
    transform: translateX(-50%) translateY(4px);
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(4px);
    border: 1px solid var(--border-color);
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 500;
    color: #fff;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s, transform 0.2s;
    z-index: 8;
}

.hotspot:hover .hotspot-tooltip {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Hide basic tooltip when hotspot is active and showing the main card */
.hotspot.active .hotspot-tooltip {
    display: none !important;
}

/* Floating Editor Panel (Slides in/out from right side of viewport) */
.editor-panel {
    position: absolute;
    top: 24px;
    right: -420px; /* Hidden by default */
    width: 380px;
    height: calc(100vh - 48px);
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--border-color);
    border-radius: 16px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
    z-index: 15;
    display: flex;
    flex-direction: column;
    transition: right 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

.editor-panel.open {
    right: 24px;
}

.editor-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.editor-header h3 {
    font-family: var(--font-heading);
    font-size: 16px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--color-text-main);
}

.btn-close {
    background: none;
    border: none;
    color: var(--color-text-muted);
    font-size: 20px;
    cursor: pointer;
    transition: color 0.2s;
}

.btn-close:hover {
    color: var(--color-text-main);
}

.editor-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.image-upload-wrapper {
    display: flex;
    gap: 16px;
    align-items: center;
}

.image-preview-container {
    width: 80px;
    height: 80px;
    border: 1px dashed var(--border-color);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.2);
    cursor: pointer;
    text-align: center;
    color: var(--color-text-dark);
    padding: 6px;
    overflow: hidden;
    flex-shrink: 0;
}

.image-preview-container img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 6px;
}

.image-preview-container i {
    font-size: 20px;
    margin-bottom: 2px;
    color: var(--color-text-muted);
}

.image-preview-container span {
    font-size: 9px;
    line-height: 1.2;
}

.image-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.editor-actions {
    display: flex;
    justify-content: space-between;
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
    gap: 10px;
}

.editor-actions .btn {
    flex: 1;
}

.editor-actions #btn-delete-hotspot {
    flex: 0 0 auto;
}

.sidebar-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border-color);
    font-size: 10px;
    color: var(--color-text-dark);
    text-align: center;
    font-weight: 500;
}

/* Responsive styles */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }
    .sidebar {
        width: 100%;
        height: auto;
        max-height: 40vh;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }
    .viewport-area {
        height: 60vh;
    }
    .editor-panel {
        width: calc(100vw - 32px);
        height: calc(60vh - 32px);
        top: 16px;
        right: -100vw;
    }
    .editor-panel.open {
        right: 16px;
    }
}

/* Visitor Mode Overrides (Hides editing tools by default) */
body.visitor-mode .sidebar-tabs,
body.visitor-mode .action-bar,
body.visitor-mode .hotspot-item-actions,
body.visitor-mode .settings-section,
body.visitor-mode #editor-panel,
body.visitor-mode #loading-error .error-actions {
    display: none !important;
}

body.visitor-mode .sidebar-header {
    border-bottom: none;
    padding-bottom: 12px;
}
