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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    overflow: hidden;
    /* Until viewer.js runs, match default dark tone; JS sets body to the active clearColor */
    background: #101820;
}

#app {
    display: flex;
    flex-direction: row-reverse;
    height: 100vh;
    width: 100vw;
}

.sidebar-drawer {
    flex-shrink: 0;
    position: relative;
    display: flex;
    align-items: stretch;
    min-height: 0;
    z-index: 20;
}

#sidebar {
    --sidebar-width: 320px;
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: linear-gradient(180deg, #16213e 0%, #1a1a2e 100%);
    color: #e0e0e0;
    display: flex;
    flex-direction: column;
    border-left: 1px solid #0f3460;
    z-index: 10;
    transition:
        width 0.28s ease,
        min-width 0.28s ease,
        opacity 0.22s ease,
        border-color 0.2s ease;
}

#app:not(.sidebar-drawer-open) #sidebar {
    width: 0;
    min-width: 0;
    opacity: 0;
    padding: 0;
    border-left-color: transparent;
    overflow: hidden;
    pointer-events: none;
}

.sidebar-toggle {
    position: absolute;
    right: 100%;
    top: 50%;
    transform: translateY(-50%);
    margin-right: -1px;
    z-index: 25;
    width: 28px;
    height: 52px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #0f3460;
    border-right: none;
    border-radius: 8px 0 0 8px;
    background: linear-gradient(180deg, #16213e 0%, #1a1a2e 100%);
    color: #e0e0e0;
    cursor: pointer;
    font-size: 1.35rem;
    line-height: 1;
    transition: background 0.2s, color 0.2s, box-shadow 0.2s;
}

.sidebar-toggle:hover {
    background: #0f3460;
    color: #fff;
}

.sidebar-toggle:focus-visible {
    outline: 2px solid #e94560;
    outline-offset: 2px;
}

#app:not(.sidebar-drawer-open) .sidebar-toggle {
    position: fixed;
    right: 0;
    margin-right: 0;
    border: 1px solid #0f3460;
    border-radius: 8px 0 0 8px;
    border-right: none;
    box-shadow: -2px 0 12px rgba(0, 0, 0, 0.35);
}

@media (prefers-reduced-motion: reduce) {
    #sidebar {
        transition: none;
    }
}

.sidebar-header {
    padding: 20px;
    background: #0f3460;
    border-bottom: 1px solid #1a1a2e;
}

.sidebar-header h1 {
    font-size: 1.4rem;
    font-weight: 600;
    color: #fff;
    margin-bottom: 4px;
}

.sidebar-header p {
    font-size: 0.85rem;
    color: #94a3b8;
}

.search-container {
    padding: 16px 20px;
    border-bottom: 1px solid #0f3460;
}

#searchInput {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid #0f3460;
    border-radius: 8px;
    background: #1a1a2e;
    color: #fff;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

#searchInput:focus {
    border-color: #e94560;
    box-shadow: 0 0 0 3px rgba(233, 69, 96, 0.2);
}

#searchInput::placeholder {
    color: #64748b;
}

.building-container {
    padding: 16px 20px;
    border-bottom: 1px solid #0f3460;
}

.building-container h3 {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: #94a3b8;
    margin-bottom: 12px;
}

#buildingSelector {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid #0f3460;
    border-radius: 8px;
    background: #1a1a2e;
    color: #fff;
    font-size: 0.9rem;
    outline: none;
}

#buildingSelector:focus {
    border-color: #e94560;
    box-shadow: 0 0 0 3px rgba(233, 69, 96, 0.2);
}

.floor-controls {
    padding: 16px 20px;
    border-bottom: 1px solid #0f3460;
}

.floor-controls h3 {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: #94a3b8;
    margin-bottom: 12px;
}

.floor-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 360px;
    overflow-y: auto;
    padding-right: 4px;
}

.floor-status-panel {
    margin-bottom: 12px;
}

.floor-status-row {
    appearance: none;
    width: 100%;
    border: 1px solid #384355;
    background: #2a2c3a;
    border-radius: 4px;
    padding: 8px;
    display: grid;
    grid-template-columns: minmax(120px, 1fr) auto;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    text-align: left;
}

.floor-status-row:hover {
    border-color: #9ba8bf;
}

.floor-status-row.active {
    border-color: #f5f5f5;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.28);
}

.floor-status-row-all {
    background: #202736;
}

.floor-status-name {
    color: #f5f5f5;
    font-size: 0.85rem;
    font-weight: 700;
    text-align: left;
    letter-spacing: 0.02em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.floor-status-counts {
    display: flex;
    gap: 6px;
}

.floor-status-chip {
    min-width: 30px;
    height: 30px;
    border-radius: 2px;
    border: 1px solid rgba(0, 0, 0, 0.35);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #111827;
    font-size: 1rem;
    font-weight: 800;
    line-height: 1;
}

.floor-status-empty {
    color: #94a3b8;
    font-size: 0.8rem;
    padding: 6px 2px;
}

#floorSelector {
    width: 100%;
    padding: 10px;
    background: #1a1a2e;
    color: #fff;
    border: 1px solid #0f3460;
    border-radius: 8px;
    outline: none;
}

.floor-btn {
    padding: 8px 16px;
    border: 1px solid #0f3460;
    border-radius: 6px;
    background: transparent;
    color: #e0e0e0;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
}

.floor-btn:hover {
    background: #0f3460;
    border-color: #e94560;
}

.floor-btn.active {
    background: #e94560;
    border-color: #e94560;
    color: #fff;
}

.floor-btn.hidden-floor {
    opacity: 0.5;
    text-decoration: line-through;
}

#showAllBtn {
    background: #0f3460;
    border-color: #0f3460;
}

#showAllBtn:hover {
    background: #16213e;
}

.room-list {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
}

.room-list h3 {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: #94a3b8;
    margin-bottom: 12px;
}

.room-item {
    padding: 12px 16px;
    margin-bottom: 8px;
    background: #16213e;
    border: 1px solid #0f3460;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
}

.room-item-text {
    min-width: 0;
}

.room-status-counts {
    display: flex;
    flex-shrink: 0;
    gap: 6px;
    align-items: center;
}

.room-item:hover {
    background: #1a2744;
    border-color: #e94560;
    transform: translateX(4px);
}

.room-item.selected {
    background: linear-gradient(135deg, #e94560 0%, #0f3460 100%);
    border-color: #e94560;
}

.room-item .room-name {
    font-weight: 500;
    color: #fff;
    margin-bottom: 4px;
}

.room-item .room-meta {
    font-size: 0.8rem;
    color: #94a3b8;
}

.room-item .room-type {
    display: inline-block;
    padding: 2px 8px;
    background: #0f3460;
    border-radius: 4px;
    font-size: 0.7rem;
    text-transform: uppercase;
    margin-top: 6px;
}

#canvas-container {
    --floor-pane-width: 24%;
    flex: 1;
    position: relative;
    /* Scene clearColor is set in JS; avoid white here or it masks grey/dark tones before paint */
    background: transparent;
}

#renderCanvas {
    width: 100%;
    height: 100%;
    touch-action: none;
}

.dual-view-floor-pane {
    position: absolute;
    top: 0;
    left: 0;
    width: var(--floor-pane-width);
    height: 100%;
    pointer-events: none;
    border-right: 1px solid rgba(148, 163, 184, 0.5);
    box-shadow: inset -12px 0 30px rgba(2, 6, 23, 0.3);
    z-index: 5;
}

.dual-view-pane-label {
    position: absolute;
    top: 12px;
    left: 12px;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.72rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #cbd5e1;
    background: rgba(15, 23, 42, 0.65);
    border: 1px solid rgba(100, 116, 139, 0.5);
}

.floor-pane-toggle {
    position: absolute;
    top: 50%;
    left: calc(var(--floor-pane-width) - 13px);
    transform: translateY(-50%);
    width: 26px;
    height: 52px;
    padding: 0;
    border: 1px solid rgba(100, 116, 139, 0.9);
    border-left: none;
    border-radius: 0 8px 8px 0;
    background: rgba(15, 23, 42, 0.85);
    color: #cbd5e1;
    cursor: pointer;
    z-index: 8;
}

.floor-pane-toggle:hover {
    color: #fff;
    border-color: rgba(56, 189, 248, 0.95);
}

.floor-pane-resizer {
    position: absolute;
    top: 0;
    left: calc(var(--floor-pane-width) - 4px);
    width: 8px;
    height: 100%;
    margin: 0;
    padding: 0;
    border: none;
    background: transparent;
    cursor: ew-resize;
    z-index: 7;
}

#canvas-container.dual-view-enabled .floor-pane-resizer {
    display: block !important;
}

#canvas-container.dual-view-enabled.active-pane-floor .dual-view-floor-pane {
    border-right-color: rgba(56, 189, 248, 0.95);
    box-shadow:
        inset -12px 0 30px rgba(2, 6, 23, 0.45),
        inset 0 0 0 2px rgba(56, 189, 248, 0.45);
}

#canvas-container.dual-view-enabled .floor-pane-toggle {
    display: block !important;
}

#canvas-container.dual-view-enabled.floor-pane-collapsed .dual-view-floor-pane {
    width: 0;
    border-right: none;
    box-shadow: none;
}

#canvas-container.dual-view-enabled.floor-pane-collapsed .dual-view-pane-label {
    display: none;
}

#canvas-container.dual-view-enabled.floor-pane-collapsed .floor-pane-toggle {
    left: 0;
    border: 1px solid rgba(100, 116, 139, 0.9);
    border-radius: 0 8px 8px 0;
}

#canvas-container.dual-view-enabled.floor-pane-collapsed .floor-pane-resizer {
    display: none !important;
}

#room-info-panel {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 300px;
    background: rgba(22, 33, 62, 0.95);
    backdrop-filter: blur(10px);
    border: 1px solid #0f3460;
    border-radius: 12px;
    padding: 20px;
    color: #fff;
    display: none;
    z-index: 100;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

#room-info-panel.visible {
    display: block;
    animation: slideIn 0.3s ease;
}

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

#room-info-panel .close-btn {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 28px;
    height: 28px;
    border: none;
    background: #0f3460;
    color: #fff;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.2rem;
    line-height: 1;
    transition: background 0.2s;
}

#room-info-panel .close-btn:hover {
    background: #e94560;
}

#room-info-panel h2 {
    font-size: 1.2rem;
    margin-bottom: 4px;
    padding-right: 30px;
}

#room-info-panel .room-id {
    font-size: 0.85rem;
    color: #94a3b8;
    margin-bottom: 16px;
}

.info-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.info-item {
    background: #0f3460;
    padding: 12px;
    border-radius: 8px;
}

.info-item .label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #94a3b8;
    margin-bottom: 4px;
}

.info-item .value {
    font-size: 1rem;
    font-weight: 500;
    color: #fff;
}

.info-item.full-width {
    grid-column: 1 / -1;
}

#info-anchors {
    white-space: pre-wrap;
    font-size: 0.85rem;
    font-weight: 400;
    line-height: 1.35;
    word-break: break-word;
}

#floor-data-panel {
    margin-top: 12px;
    padding: 10px 12px;
    background: #0f3460;
    border-radius: 8px;
    font-size: 0.8rem;
    line-height: 1.45;
    color: #cbd5e1;
}

#floor-data-panel h4 {
    margin: 0 0 8px;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #94a3b8;
}

#floor-data-body {
    white-space: pre-wrap;
    word-break: break-word;
}

#loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.94);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 3px solid #cbd5e1;
    border-top-color: #64748b;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

#loading-overlay p {
    margin-top: 16px;
    color: #64748b;
    font-size: 0.9rem;
}

.hidden {
    display: none !important;
}

.viewer-reset-btn {
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 12;
    padding: 8px 14px;
    font-size: 0.82rem;
    font-weight: 600;
    color: #e2e8f0;
    background: rgba(15, 23, 42, 0.88);
    border: 1px solid rgba(100, 116, 139, 0.85);
    border-radius: 8px;
    cursor: pointer;
    box-shadow: 0 2px 12px rgba(2, 6, 23, 0.35);
}

.viewer-reset-btn:hover {
    color: #fff;
    border-color: rgba(56, 189, 248, 0.9);
    background: rgba(30, 41, 59, 0.95);
}

.viewer-reset-btn:focus-visible {
    outline: 2px solid #38bdf8;
    outline-offset: 2px;
}

.controls-hint {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid #e2e8f0;
    padding: 10px 20px;
    border-radius: 8px;
    color: #475569;
    font-size: 0.8rem;
    pointer-events: none;
    box-shadow: 0 2px 12px rgba(15, 23, 42, 0.08);
}

