/* CSS Variables - Mobile First Soft UI */
:root {
    --bg-base: #0F0F13;
    --bg-sheet: #16161E;
    --bg-card: rgba(255, 255, 255, 0.05);
    
    --accent: #6366F1;
    --accent-hover: #818CF8;
    --accent-muted: rgba(99, 102, 241, 0.15);
    
    --text-primary: #F8FAFC;
    --text-secondary: #94A3B8;
    --text-muted: #64748B;
    
    --border-glass: rgba(255, 255, 255, 0.08);
    --border-active: rgba(99, 102, 241, 0.4);
    
    --shadow-soft: 0 -8px 32px rgba(0, 0, 0, 0.5);
    
    --font-sans: 'Inter', -apple-system, sans-serif;
    
    --radius-xl: 20px;
    --radius-lg: 12px;
    --radius-md: 8px;
    --radius-full: 9999px;
    
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none; /* Prevent text selection while dragging */
}

body.mobile-layout {
    background-color: var(--bg-base);
    color: var(--text-primary);
    font-family: var(--font-sans);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
    display: flex;
    flex-direction: column;
}

/* Custom Scrollbars */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 4px; }

/* Buttons General */
button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    background: none;
    outline: none;
    transition: var(--transition);
}

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
}
.icon-btn:hover { background-color: var(--bg-card); color: var(--text-primary); }

/* --- HEADER --- */
.mobile-header {
    height: 60px;
    background-color: rgba(15, 15, 19, 0.9);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-glass);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 10px;
    z-index: 100;
}

.view-toggle {
    display: flex;
    background-color: rgba(0,0,0,0.4);
    border-radius: var(--radius-full);
    padding: 4px;
    border: 1px solid var(--border-glass);
}

.toggle-btn {
    padding: 6px 16px;
    border-radius: var(--radius-full);
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 600;
}
.toggle-btn.active {
    background-color: var(--bg-sheet);
    color: var(--text-primary);
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Dropdown Menu */
.dropdown {
    position: relative;
    display: inline-block;
}
.dropdown-content {
    display: none;
    position: absolute;
    right: 0;
    top: 48px;
    background-color: var(--bg-sheet);
    min-width: 180px;
    box-shadow: var(--shadow-soft);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-glass);
    overflow: hidden;
    z-index: 101;
}
.dropdown:hover .dropdown-content, .dropdown:active .dropdown-content {
    display: block;
}
.dropdown-content button {
    color: var(--text-primary);
    padding: 14px 16px;
    text-align: left;
    width: 100%;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.9rem;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}
.dropdown-content button:hover {
    background-color: var(--accent-muted);
    color: var(--accent);
}

/* --- VIEWPORT (60%) --- */
.viewport-area {
    flex: 6; /* 60% approx */
    position: relative;
    background-image: radial-gradient(circle at center, rgba(99, 102, 241, 0.03) 0%, transparent 100%);
}

.canvas-container {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0; left: 0;
    display: none; /* toggled via active */
}
.canvas-container.active {
    display: block;
}

#canvas-2d, #three-container {
    width: 100%;
    height: 100%;
    touch-action: none; /* Important for custom touch panning */
}

/* Floating UI on Canvas */
.floating-ui {
    position: absolute;
    z-index: 10;
}
.top-left { top: 12px; left: 12px; }
.bottom-right { bottom: 12px; right: 12px; }

.status-pill {
    background-color: rgba(255, 255, 255, 0.9);
    color: #0F0F13;
    padding: 6px 14px;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}
.status-pill.dark {
    background-color: rgba(0,0,0,0.6);
    color: white;
    backdrop-filter: blur(4px);
    border: 1px solid var(--border-glass);
}

.zoom-controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
    background-color: rgba(26, 26, 36, 0.8);
    backdrop-filter: blur(8px);
    border: 1px solid var(--border-glass);
    padding: 6px;
    border-radius: var(--radius-full);
}
.float-btn {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    color: var(--text-secondary);
    display: flex; align-items: center; justify-content: center;
}
.float-btn:active { background-color: rgba(255,255,255,0.1); }

/* --- BOTTOM SHEET (40%) --- */
.bottom-sheet {
    flex: 4; /* 40% approx */
    background-color: var(--bg-sheet);
    border-top: 1px solid var(--border-glass);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    box-shadow: var(--shadow-soft);
    display: flex;
    flex-direction: column;
    z-index: 50;
    overflow: hidden;
}

/* Tabs */
.sheet-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-glass);
    background-color: rgba(0,0,0,0.2);
}
.sheet-tab {
    flex: 1;
    padding: 16px 0;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border-bottom: 2px solid transparent;
}
.sheet-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
    background-color: rgba(255,255,255,0.02);
}
.sheet-tab.glow {
    animation: pulseGlow 1s infinite alternate;
}
@keyframes pulseGlow {
    from { color: var(--text-primary); text-shadow: 0 0 10px var(--accent); }
    to { color: var(--accent); }
}

/* Contents */
.sheet-content {
    flex: 1;
    overflow-y: auto;
    position: relative;
}
.tab-pane {
    display: none;
    padding: 20px;
    animation: fadeIn 0.2s ease-out;
}
.tab-pane.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Tools & Library (Tab 1) */
.tools-row {
    display: flex;
    gap: 10px;
    margin-bottom: 24px;
}
.tool-btn {
    flex: 1;
    background-color: var(--bg-card);
    border: 1px solid var(--border-glass);
    padding: 12px 8px;
    border-radius: var(--radius-lg);
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 600;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}
.tool-btn i { font-size: 1.2rem; }
.tool-btn.active {
    background-color: var(--accent-muted);
    color: var(--accent);
    border-color: var(--accent);
}

.sub-heading {
    font-size: 0.85rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 12px;
}

/* Horizontal Scroll Library */
.library-scroll {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding-bottom: 10px;
    -webkit-overflow-scrolling: touch;
}
.lib-item {
    min-width: 80px;
    background-color: var(--bg-card);
    border: 1px solid var(--border-glass);
    border-radius: var(--radius-md);
    padding: 12px 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
    cursor: pointer;
}
.lib-item:active { transform: scale(0.95); }
.lib-item i { font-size: 1.5rem; }
.lib-item span { font-size: 0.7rem; font-weight: 500; text-align: center; }

/* Properties (Tab 2) & Project (Tab 3) */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    padding: 40px 20px;
    text-align: center;
    gap: 12px;
}
.empty-state i { font-size: 2rem; opacity: 0.5; }

.hidden { display: none !important; }

.props-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.prop-item {
    display: flex;
    flex-direction: column;
    gap: 8px;
    background-color: var(--bg-card);
    padding: 12px 16px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-glass);
}
.prop-item.row-layout {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
}
.prop-item label {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.num-input {
    display: flex;
    background-color: rgba(0,0,0,0.3);
    border-radius: var(--radius-sm);
    border: 1px solid rgba(255,255,255,0.1);
    overflow: hidden;
}
.num-input button {
    width: 40px;
    background: rgba(255,255,255,0.05);
    color: var(--text-primary);
    font-size: 1rem;
}
.num-input button:active { background: rgba(255,255,255,0.1); }
.num-input input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    text-align: center;
    font-weight: 600;
    font-size: 0.9rem;
    padding: 8px;
    outline: none;
}

/* Segmented Control for Doors/Windows */
.segment-control {
    display: flex;
    background-color: rgba(0,0,0,0.3);
    border-radius: var(--radius-sm);
    padding: 4px;
    border: 1px solid var(--border-glass);
}
.seg-btn {
    flex: 1;
    padding: 6px 0;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    border-radius: 4px;
}
.seg-btn.active {
    background-color: var(--accent);
    color: #fff;
}

/* Switch */
.toggle-row {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
}
.switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 22px;
}
.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: .4s;
    border-radius: 34px;
}
.slider:before {
    position: absolute; content: "";
    height: 16px; width: 16px;
    left: 3px; bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}
input:checked + .slider { background-color: var(--accent); }
input:checked + .slider:before { transform: translateX(18px); }

/* Destructive Button */
.btn-danger {
    background-color: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.3);
    padding: 12px;
    border-radius: var(--radius-md);
    font-weight: 600;
    margin-top: 8px;
    display: flex;
    justify-content: center;
    gap: 8px;
}
.btn-danger:active {
    background-color: rgba(239, 68, 68, 0.2);
}

/* Desktop override just in case it's opened on PC */
@media (min-width: 1024px) {
    body.mobile-layout {
        flex-direction: row;
    }
    .viewport-area {
        flex: 1;
        height: 100vh;
    }
    .bottom-sheet {
        width: 400px;
        flex: none;
        height: 100vh;
        border-radius: 0;
        border-top: none;
        border-left: 1px solid var(--border-glass);
    }
    .mobile-header {
        position: absolute;
        top: 0; left: 0; right: 400px;
    }
}
