/* --- Base Reset & Core Layout Structure --- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: #f5f5f7;
    color: #1d1d1f;
    overflow: hidden;
    display: flex;
    flex-direction: row;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
}

.tool-btn, 
.tab-btn, 
.btn-ar, 
.btn-danger, 
#sidebar,
.swatch {
    -webkit-user-select: none;
    user-select: none;
}

/* --- Master WebGL Workspace Container Viewport --- */
#canvas-container {
    flex: 1;
    height: 100%;
    position: relative;
    outline: none;
}

/* --- Live Dimension Readout Tag --- */
#dimension-badge {
    position: absolute;
    top: 20px;
    right: 20px;
    background-color: rgba(29, 29, 31, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: #ffffff;
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 0.78rem;
    font-weight: 600;
    font-family: monospace;
    z-index: 90;
    display: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* --- Dynamic Measurement HUD Label --- */
#measure-floating-label {
    position: absolute;
    background-color: #34c759;
    color: #ffffff;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 700;
    font-family: monospace;
    pointer-events: none;
    z-index: 95;
    display: none;
    transform: translate(-50%, -100%);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

/* --- Live Commercial Budget Interface Container --- */
#budget-container {
    background-color: #f5f5f7;
    border: 1px solid #d2d2d7;
    border-radius: 12px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 4px;
}
.budget-label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    color: #86868b;
    letter-spacing: 0.03em;
}
#budget-tally {
    font-size: 1.4rem;
    font-weight: 700;
    color: #34c759;
    font-family: monospace;
}

/* --- Floating Camera Snapshot Button --- */
.btn-snapshot {
    position: absolute;
    top: 20px;
    left: 20px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background-color: #ffffff;
    border: 1px solid #d2d2d7;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 90;
    font-size: 1.2rem;
    transition: transform 0.2s ease;
}
.btn-snapshot:active {
    transform: scale(0.92);
    background-color: #f5f5f7;
}

/* --- Floating Quick-Action Mobile HUD Toolbar --- */
#mobile-transform-toolbar {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100;
    display: flex;
    background-color: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding: 6px;
    border-radius: 16px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    gap: 4px;
    align-items: center;
    width: calc(100% - 40px);
    max-width: 580px;
}

.tool-btn {
    flex: 1;
    border: none;
    background: transparent;
    padding: 10px 2px;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 10px;
    color: #515154;
    white-space: nowrap;
    text-align: center;
    transition: all 0.2s ease;
    cursor: pointer;
}

.tool-btn.active-tool {
    background-color: #ffffff;
    color: #007aff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.tool-btn.delete-tool-mode.active-tool {
    background-color: #ff3b30 !important;
    color: #ffffff !important;
    box-shadow: 0 2px 8px rgba(255, 59, 48, 0.3);
}

.tool-btn.delete-tool-mode {
    color: #ff3b30;
}

.btn-ar {
    flex: 1.5;
    background-color: #007aff;
    color: #ffffff;
    border: none;
    border-radius: 12px;
    padding: 10px 10px;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    box-shadow: 0 4px 10px rgba(0, 122, 255, 0.15);
    white-space: nowrap;
    cursor: pointer;
}
.btn-ar:active {
    background-color: #0066cc;
}
.btn-ar:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* --- Control Management Panel Sidebar --- */
#sidebar {
    width: 320px;
    height: 100%;
    background-color: #ffffff;
    border-right: 1px solid #d2d2d7;
    display: flex;
    flex-direction: column;
    padding: 24px;
    gap: 16px;
    z-index: 10;
    box-shadow: 2px 0 12px rgba(0, 0, 0, 0.03);
    overflow-y: auto;
}

h2 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.022em;
}

.subtitle {
    font-size: 0.8rem;
    color: #86868b;
    line-height: 1.4;
}

.divider {
    border: 0;
    border-top: 1px solid #e5e5ea;
    margin: 4px 0;
}

.back-link {
    display: inline-flex;
    align-items: center;
    font-size: 0.85rem;
    font-weight: 600;
    color: #86868b;
    text-decoration: none;
    padding: 4px 0;
}

#category-tabs {
    display: flex;
    gap: 4px;
    background-color: #f5f5f7;
    padding: 4px;
    border-radius: 10px;
    border: 1px solid #e5e5ea;
}

.tab-btn {
    flex: 1;
    font-size: 0.78rem;
    font-weight: 600;
    padding: 8px 2px;
    background-color: transparent;
    color: #515154;
    border-radius: 7px;
    border: none;
    cursor: pointer;
}

.tab-btn.active {
    background-color: #ffffff;
    color: #007aff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
}

#catalog-list {
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    padding-right: 4px;
    min-height: 160px;
}

/* --- Dynamic Variant Material Drawer - HIDDEN FOR NOW --- */
#variant-container {
    background-color: #f5f5f7;
    border-radius: 12px;
    padding: 14px;
    display: none;
    flex-direction: column;
    gap: 8px;
}
.variant-title {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    color: #86868b;
    letter-spacing: 0.05em;
}
.swatch-group {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}
.swatch {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid #ffffff;
    box-shadow: 0 0 0 1px #d2d2d7;
    cursor: pointer;
    transition: transform 0.15s ease;
}
.swatch:hover, .swatch.active-swatch {
    transform: scale(1.15);
    box-shadow: 0 0 0 2px #007aff;
}

.catalog-item.visual-card {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    height: 115px;
    background-color: #ffffff;
    border: 1px solid #d2d2d7;
    border-radius: 12px;
    position: relative;
    cursor: pointer;
}

.thumb-wrapper {
    width: 100%;
    height: 80px;
    background-color: #f5f5f7;
    overflow: hidden;
}

.catalog-thumb {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.card-meta {
    height: 35px;
    background-color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
    border-top: 1px solid #e5e5ea;
}

.card-meta span {
    font-size: 0.72rem;
    font-weight: 600;
    color: #1d1d1f;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-transform: uppercase;
}

#controls-hint {
    background-color: #f5f5f7;
    border-radius: 12px;
    padding: 14px;
    font-size: 0.78rem;
    color: #515154;
    line-height: 1.5;
}

kbd {
    background-color: #ffffff;
    border: 1px solid #d2d2d7;
    border-radius: 4px;
    padding: 1px 4px;
    font-size: 0.7rem;
}

.btn-danger {
    background-color: #ff3b30;
    color: #ffffff;
    border: none;
    border-radius: 10px;
    padding: 10px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
}

/* --- Responsive Media Layout for Portrait Devices --- */
@media (orientation: portrait) {
    body {
        flex-direction: column-reverse;
    }
    #sidebar {
        width: 100%;
        height: 42dvh;
        border-right: none;
        border-top: 1px solid #d2d2d7;
        padding: 16px;
    }
    #controls-hint {
        display: none;
    }
    #mobile-transform-toolbar {
        bottom: calc(42dvh + 16px);
    }
    /* Vertically shift layout badge elements to stack safely above bottom interfaces */
    #snapshot-btn {
        top: auto;
        bottom: calc(42dvh + 82px);
        left: 20px;
    }
    #dimension-badge {
        top: auto;
        bottom: calc(42dvh + 82px);
        right: 20px;
    }
}

.state-loading { opacity: 0.6; pointer-events: none; }
.error-state { border-color: #ff3b30 !important; }
.empty-notice { grid-column: span 2; text-align: center; font-size: 0.78rem; color: #86868b; padding: 40px 10px; }
