/* 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 */
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}
canvas { outline: none; }

body.mobile-layout {
    background-color: var(--bg-base);
    color: var(--text-primary);
    font-family: var(--font-sans);
    overflow: hidden;
    height: 100vh;
    height: 100dvh;
    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;
    padding: 0;
    margin: 0;
    line-height: 1;
}
.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;
    position: absolute;
    top: 0; left: 0; right: 0;
}

.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);
}

#portrait-lock { display: none; flex-direction: column; align-items: center; justify-content: center; position: fixed; top:0; left:0; width: 100vw; height: 100vh; background: var(--bg-base); z-index: 9999; }
#portrait-lock p { color: var(--text-secondary); }

@media screen and (orientation: landscape) and (max-width: 1023px) and (pointer: coarse) {
    #portrait-lock {
        display: flex;
    }
}

.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-content.show {
    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 --- */
.viewport-area {
    width: 100%;
    height: 100dvh;
    position: relative;
    background-image: radial-gradient(circle at center, rgba(99, 102, 241, 0.03) 0%, transparent 100%);
}

/* Empty State Onboarding */
.empty-state {
    position: absolute;
    top: 72px;
    left: 50%;
    transform: translateX(-50%);
    background-color: rgba(30, 30, 42, 0.90);
    backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 24px;
    padding: 24px;
    width: 90%;
    max-width: 500px;
    max-height: calc(100vh - 156px);
    max-height: calc(100dvh - 156px);
    overflow-y: auto;
    box-shadow: 0 12px 40px rgba(0,0,0,0.4);
    pointer-events: none;
    transition: opacity 0.4s ease, transform 0.4s ease;
    z-index: 5;
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.empty-state.hidden {
    opacity: 0;
    transform: translate(-50%, -40%);
    pointer-events: none !important;
}
.empty-header {
    text-align: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 16px;
}
.empty-header > i:first-child {
    font-size: 2.5rem;
    color: var(--accent);
    margin-bottom: 12px;
}
.empty-header h3 {
    margin: 0 0 8px 0;
    color: #f8fafc;
    font-size: 1.25rem;
    font-weight: 600;
}
.empty-header p {
    margin: 0;
    color: #cbd5e1;
    font-size: 0.95rem;
}
.empty-grid {
    display: grid;
    gap: 12px;
}
.empty-item {
    display: flex;
    gap: 16px;
    align-items: flex-start;
    padding: 12px;
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.05);
    border-radius: 16px;
}
.empty-item i {
    font-size: 1.4rem;
    color: var(--text-secondary);
    width: 24px;
    text-align: center;
    margin-top: 2px;
}
.empty-item strong {
    display: block;
    color: var(--text-primary);
    margin-bottom: 4px;
    font-size: 1rem;
}
.empty-item p {
    margin: 0;
    color: var(--text-secondary);
    font-size: 0.85rem;
    line-height: 1.4;
}
.empty-footer {
    text-align: center;
    font-size: 0.8rem;
    color: rgba(255,255,255,0.4);
    margin-top: 8px;
}

/* Unified Contextual UI */
/* 1. Radial FAB (Bottom Center) */
.radial-fab-container {
    position: absolute;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 150;
    display: flex;
    justify-content: center;
    align-items: center;
}
.radial-fab-container.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, 20px);
    transition: all 0.3s;
}

.fab-main {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background-color: var(--accent);
    color: white;
    font-size: 1.8rem;
    box-shadow: 0 4px 16px rgba(99, 102, 241, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275), background-color 0.2s;
    z-index: 10;
}
.fab-main.active {
    transform: rotate(135deg); /* Plus to X */
    background-color: #ef4444; 
}
.radial-menu {
    position: absolute;
    top: 50%; left: 50%;
    width: 0; height: 0;
    pointer-events: none;
    z-index: 5;
}
.radial-item {
    position: absolute;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background-color: var(--bg-card);
    color: var(--text-primary);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    border: 1px solid var(--border-glass);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.5);
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    pointer-events: none;
}
.radial-item.show {
    opacity: 1;
    pointer-events: all;
    /* JS will set the exact translate values based on angle */
}

/* 2. Contextual Edit Toolbar */
.contextual-toolbar {
    position: absolute;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 160;
    background-color: rgba(26, 26, 36, 0.85);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border-glass);
    padding: 10px 16px;
    border-radius: 24px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 12px;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    width: max-content;
    max-width: 95%;
}
.contextual-toolbar.hidden {
    opacity: 0;
    transform: translate(-50%, 50px);
    pointer-events: none;
}
.contextual-toolbar .props-list {
    flex-direction: row;
    flex-wrap: wrap;
    width: 100%;
    align-items: stretch;
    justify-content: center;
    gap: 10px;
}
.contextual-toolbar .prop-item {
    padding: 0;
    border: none;
    background: transparent;
    flex: 0 1 auto;
    gap: 4px;
}
.contextual-toolbar .prop-item label {
    font-size: 0.7rem;
    text-align: center;
}
.contextual-toolbar .num-input {
    border-radius: 12px;
}
.contextual-toolbar .btn-danger {
    margin-top: 0;
    padding: 0 16px;
    height: auto;
    border-radius: 12px;
    align-self: stretch;
    display: flex;
    align-items: center;
    justify-content: center;
}
.contextual-toolbar .segment-control {
    flex: 1;
    height: 38px;
}

.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;
    pointer-events: none;
}
.top-left { top: 72px; left: 12px; }
.bottom-right { bottom: 12px; right: 12px; }

.status-pill {
    pointer-events: auto;
    background-color: rgba(30, 30, 42, 0.85);
    color: #e2e8f0;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 500;
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 4px 16px rgba(0,0,0,0.3);
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    user-select: none;
    transform-origin: top left;
    max-width: 85vw;
}
.status-pill.dark {
    background-color: rgba(10, 10, 15, 0.8);
    border-color: rgba(255, 255, 255, 0.05);
}
.status-pill i {
    color: var(--accent);
    font-size: 1rem;
}
.status-pill span {
    white-space: normal;
    line-height: 1.3;
}

.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 {
    pointer-events: auto;
    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); }

/* Deleted bottom-sheet styles */

.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 {
    width: 60px;
    background: transparent;
    border: none;
    color: var(--text-primary);
    text-align: center;
    font-weight: 600;
    font-size: 0.9rem;
    padding: 8px 0;
    outline: none;
    -moz-appearance: textfield;
}
.num-input input::-webkit-outer-spin-button,
.num-input input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* 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 */
@media (min-width: 1024px) {
    .viewport-area {
        height: 100vh;
    }
}
    .mobile-header {
        position: absolute;
        top: 0; left: 0; right: 0;
    }
}
