:root {
    --ui-bg: rgba(255, 255, 255, 0.96);
    --brand: #0b74ff;
    --text: #2b2f36;
    --radius: 12px;
}

html,
body {
    height: 100%;
}

body {
    margin: 0;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
    background: #e6f3ff;
}

#canvas-container {
    width: 100%;
    height: 100vh;
    display: block;
}

/* 控制面板 */
#controls {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 340px;
    max-width: calc(100vw - 32px);
    background: var(--ui-bg);
    padding: 16px;
    padding-top: 52px;
    border-radius: var(--radius);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.15);
    z-index: 10;
    backdrop-filter: saturate(180%) blur(8px);
    transition: width .3s ease, height .3s ease, padding .3s ease;
    overflow: hidden;
}

.panel-content {
    max-height: calc(90vh - 80px);
    overflow-y: auto;
}

.control-group {
    margin-bottom: 14px;
}

#controls label {
    display: block;
    margin-bottom: 6px;
    font-weight: 700;
    font-size: 14px;
    color: var(--text);
}

select,
input[type="range"],
input[type="number"] {
    width: 100%;
}

select,
input[type="number"] {
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid #dcdfe6;
    background: #fff;
    color: #333;
    font-size: 14px;
}

input[type="range"] {
    accent-color: var(--brand);
}

.time-display {
    text-align: center;
    margin-top: 6px;
    font-weight: 800;
    color: var(--brand);
    font-size: 18px;
    letter-spacing: 0.5px;
}

h2 {
    margin: 0 0 12px;
    font-size: 16px;
    text-align: center;
    color: #111;
    border-bottom: 1px solid #e9eef5;
    padding-bottom: 10px;
}

/* 文件上传按钮 */
.file-upload {
    position: relative;
    display: inline-block;
    width: 100%;
}

.file-upload input[type="file"] {
    display: none;
}

.file-upload-btn {
    width: 100%;
    padding: 10px;
    background: #28a745;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    text-align: center;
    font-weight: bold;
    font-size: 14px;
    display: block;
    box-sizing: border-box;
    transition: background 0.2s;
}

.file-upload-btn:hover {
    background: #218838;
}

/* 位置配置 */
.location-config {
    background: #f0f7ff;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid #c5dcf7;
}

.location-config label {
    color: #0056b3;
    margin-bottom: 10px;
}

.location-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    align-items: end;
    margin-bottom: 8px;
}

.location-row.single {
    grid-template-columns: 1fr;
}

.location-row .field {
    display: flex;
    flex-direction: column;
}

.location-config .field {
    display: flex;
    flex-direction: column;
}

.location-row .field span {
    display: block;
    font-size: 12px;
    color: #666;
    margin-bottom: 4px;
}

.location-config .field span {
    display: block;
    font-size: 12px;
    color: #666;
    margin-bottom: 4px;
}

.location-row select,
.location-row input {
    width: 100%;
    margin-bottom: 0;
    box-sizing: border-box;
}

.location-config .field input,
.location-config .field select {
    width: 100%;
    margin-bottom: 0;
    box-sizing: border-box;
}

.lat-display {
    font-size: 13px;
    color: #555;
    text-align: center;
    padding-top: 4px;
}

.muted {
    font-size: 12px;
    color: #666;
}

/* 开关行 */
.inline-row {
    display: flex;
    align-items: center;
    gap: 8px;
    user-select: none;
}

.inline-row input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--brand);
}

/* 日照分析样式 */
.sunlight-analysis .analysis-config {
    background: #fff8e6;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid #f0d878;
}

.sunlight-analysis .inline-row span:first-of-type {
    font-size: 12px;
    color: #666;
    min-width: 60px;
}

.sunlight-analysis .inline-row select {
    flex: 1;
    padding: 6px 8px;
    font-size: 13px;
}

.calc-btn {
    width: 100%;
    padding: 12px;
    margin-top: 10px;
    background: linear-gradient(135deg, #ff9500, #ff6b00);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    font-size: 14px;
    transition: all 0.2s;
    box-shadow: 0 2px 8px rgba(255, 107, 0, 0.3);
}

.calc-btn:hover:not(:disabled) {
    background: linear-gradient(135deg, #ffaa22, #ff7711);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(255, 107, 0, 0.4);
}

.calc-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
    box-shadow: none;
}

.calc-progress {
    margin-top: 10px;
    text-align: center;
    position: relative;
    padding-right: 30px;
}

.progress-bar {
    height: 8px;
    background: #e0e0e0;
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 6px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #4caf50, #8bc34a);
    width: 0%;
    transition: width 0.3s ease;
}

#progressText {
    font-size: 12px;
    color: #666;
}

.cancel-calc-btn {
    position: absolute;
    right: 0;
    bottom: -4px;
    width: 24px;
    height: 24px;
    padding: 0;
    border: 1px solid #c7ccd1;
    border-radius: 4px;
    background: #fff;
    color: #555;
    font-size: 18px;
    line-height: 20px;
    cursor: pointer;
}

.cancel-calc-btn:hover {
    background: #f1f3f5;
}

/* 热力图图例 */
.heatmap-legend {
    margin-top: 12px;
    padding: 10px;
    background: #fff;
    border-radius: 6px;
}

.legend-bar {
    height: 16px;
    border-radius: 4px;
    background: linear-gradient(90deg, 
        #fffacd, #ffefaa, #ffdf82, #ffc85a, 
        #ffaa3c, #f58c28, #dc6414);
}

.legend-labels {
    display: flex;
    justify-content: space-between;
    margin-top: 4px;
    font-size: 11px;
    color: #666;
}

/* 日照统计 */
.sunlight-stats {
    margin-top: 12px;
    padding: 10px;
    background: #f8f9fa;
    border-radius: 6px;
    font-size: 12px;
    line-height: 1.6;
}

.sunlight-stats .stats-section + .stats-section {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #e3e8ee;
}

.sunlight-stats .stats-section-title {
    margin: 0 0 6px;
    font-size: 12px;
    font-weight: 700;
    color: #2c3e50;
}

.sunlight-stats .stat-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 4px 0;
    border-bottom: 1px dashed #e0e0e0;
}

.sunlight-stats .stat-row:last-child {
    border-bottom: none;
}

.sunlight-stats .stat-label {
    color: #666;
}

.sunlight-stats .stat-value {
    font-weight: 600;
    color: #333;
    text-align: right;
}

.sunlight-stats .stat-value.good {
    color: #28a745;
}

.sunlight-stats .stat-value.warning {
    color: #ffc107;
}

.sunlight-stats .stat-value.bad {
    color: #dc3545;
}

.sunlight-stats .stat-note {
    color: #6b7280;
    font-size: 11px;
    line-height: 1.5;
}

/* 户型信息面板 */
.unit-info-panel {
    position: absolute;
    left: 16px;
    bottom: 16px;
    width: 280px;
    background: var(--ui-bg);
    border-radius: var(--radius);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.15);
    z-index: 15;
    backdrop-filter: saturate(180%) blur(8px);
    overflow: hidden;
}

.unit-info-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
}

.unit-info-header span {
    font-weight: 600;
    font-size: 14px;
}

.unit-info-header button {
    background: none;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.unit-info-header button:hover {
    opacity: 1;
}

#unitInfoContent {
    padding: 16px;
    font-size: 13px;
    line-height: 1.6;
}

#unitInfoContent .info-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    border-bottom: 1px solid #eee;
}

#unitInfoContent .info-row:last-child {
    border-bottom: none;
}

#unitInfoContent .info-label {
    color: #666;
}

#unitInfoContent .info-value {
    font-weight: 600;
    color: #333;
}

#unitInfoContent .sunlight-bar {
    margin-top: 10px;
    height: 24px;
    background: #e0e0e0;
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}

#unitInfoContent .sunlight-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.3s;
}

#unitInfoContent .sunlight-text {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    font-size: 12px;
    font-weight: 600;
    color: #333;
    text-shadow: 0 0 3px white;
}

/* 空状态提示 */
#empty-state {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: #666;
    font-size: 16px;
    z-index: 4;
    pointer-events: none;
}

.loading-overlay,
.drop-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.16s ease, visibility 0.16s ease;
}

.loading-overlay {
    z-index: 60;
    background: rgba(12, 24, 38, 0.42);
}

.drop-overlay {
    z-index: 55;
    background: rgba(15, 57, 74, 0.45);
}

.loading-overlay.is-active,
.drop-overlay.is-active {
    opacity: 1;
    visibility: visible;
}

.loading-overlay.is-active {
    pointer-events: all;
}

.loading-panel,
.drop-target {
    width: min(420px, calc(100vw - 40px));
    border-radius: 8px;
    text-align: center;
}

.loading-panel {
    padding: 18px 20px;
    background: rgba(255, 255, 255, 0.98);
    color: #23313f;
    border: 1px solid rgba(255, 255, 255, 0.75);
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.2);
    font-size: 14px;
    font-weight: 600;
}

.loading-spinner {
    width: 34px;
    height: 34px;
    margin: 0 auto 12px;
    border: 3px solid #d8e2ea;
    border-top-color: #1976d2;
    border-radius: 50%;
    animation: viewer-loading-spin 0.8s linear infinite;
}

.drop-target {
    padding: 26px;
    border: 2px dashed rgba(255, 255, 255, 0.9);
    background: rgba(20, 42, 54, 0.82);
    color: #fff;
    font-size: 18px;
    font-weight: 700;
}

@keyframes viewer-loading-spin {
    to { transform: rotate(360deg); }
}

.export-analysis-btn {
    width: 100%;
    margin-top: 10px;
    padding: 9px 12px;
    border: 1px solid #5f6f7d;
    border-radius: 6px;
    background: #fff;
    color: #324453;
    font-weight: 700;
    cursor: pointer;
}

.export-analysis-btn:hover:not(:disabled) {
    background: #eef4f7;
}

.export-analysis-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.precomputed-status {
    min-height: 16px;
    margin-top: 6px;
    color: #526575;
    font-size: 11px;
    line-height: 1.45;
}

/* GitHub 图标链接 */
.github-link {
    position: absolute;
    top: 16px;
    left: 16px;
    width: 48px;
    height: 48px;
    background: var(--ui-bg);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #24292e;
    text-decoration: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
    z-index: 10;
    backdrop-filter: saturate(180%) blur(8px);
}

.github-link:hover {
    transform: scale(1.1) rotate(5deg);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
    background: rgba(255, 255, 255, 1);
}

.github-link svg {
    width: 28px;
    height: 28px;
}

/* 图例提示 */
.legend {
    display: flex;
    gap: 10px;
    font-size: 12px;
    margin-top: 8px;
    justify-content: center;
    color: #666;
}

/* 切换按钮 */
.sidebar-toggle {
    position: absolute;
    left: 12px;
    top: 12px;
    width: 36px;
    height: 36px;
    background: #f0f4f8;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    transition: all 0.2s;
    z-index: 11;
    color: var(--text);
    padding: 0;
}

.sidebar-toggle:hover {
    background: #e2e8f0;
    transform: scale(1.05);
}

.sidebar-toggle:active {
    transform: scale(0.95);
}

/* 切换按钮图标 */
.sidebar-toggle::before {
    content: '×';
    font-size: 28px;
    font-weight: 300;
    line-height: 1;
}

/* 收起状态的按钮 */
#controls.collapsed .sidebar-toggle::before {
    content: '◀';
    font-size: 16px;
}

/* 收起状态 */
#controls.collapsed {
    width: 52px;
    height: 52px;
    padding: 8px;
    border-radius: 12px;
}

#controls.collapsed .panel-content {
    opacity: 0;
    pointer-events: none;
}

/* 移动端适配 */
@media (max-width: 600px) {
    .github-link {
        top: env(safe-area-inset-top, 8px);
        left: 8px;
        width: 42px;
        height: 42px;
    }

    .github-link svg {
        width: 24px;
        height: 24px;
    }

    #controls {
        top: env(safe-area-inset-top, 8px);
        right: 8px;
        width: 280px;
        padding: 12px;
        padding-top: 48px;
    }

    #controls.collapsed {
        width: 48px;
        height: 48px;
        padding: 6px;
    }

    .sidebar-toggle {
        width: 34px;
        height: 34px;
    }
    
    .sidebar-toggle::before {
        font-size: 24px;
    }
    
    #controls.collapsed .sidebar-toggle::before {
        font-size: 14px;
    }

    #timeBlock {
        display: none;
    }

    #timeDock {
        position: absolute;
        left: 10px;
        right: 10px;
        bottom: env(safe-area-inset-bottom, 10px);
        height: 56px;
        background: var(--ui-bg);
        border-radius: 14px;
        box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
        display: flex;
        align-items: center;
        gap: 10px;
        padding: 8px 12px;
        z-index: 12;
        backdrop-filter: saturate(180%) blur(8px);
    }

    #timeDock .timeLabel {
        font-size: 13px;
        color: #3b3f46;
        font-weight: 700;
        white-space: nowrap;
    }

    #timeDock input[type="range"] {
        flex: 1;
        height: 28px;
        accent-color: var(--brand);
    }

    #timeDock .timeValue {
        width: 64px;
        text-align: right;
        font-weight: 800;
        color: var(--brand);
    }

    .unit-info-panel {
        left: 8px;
        right: 8px;
        bottom: calc(env(safe-area-inset-bottom, 10px) + 66px);
        width: auto;
    }
}

/* 语言切换按钮 */
.lang-switcher {
    display: flex;
    gap: 4px;
    background: rgba(0, 0, 0, 0.05);
    padding: 2px;
    border-radius: 6px;
}

.lang-btn {
    padding: 4px 10px;
    border: none;
    background: transparent;
    color: #666;
    font-size: 12px;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
    font-weight: 500;
}

.lang-btn:hover {
    background: rgba(0, 0, 0, 0.08);
    color: #333;
}

.lang-btn.active {
    background: white;
    color: var(--brand);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* 自定义日期选择器样式 */
#customDatePicker {
    margin-top: 8px;
}

#customDateInput {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #dcdfe6;
    border-radius: 8px;
    background: #fff;
    font-size: 14px;
    color: #333;
    box-sizing: border-box;
    cursor: pointer;
}

#customDateInput::-webkit-calendar-picker-indicator {
    cursor: pointer;
    opacity: 0.6;
}

#customDateInput:hover::-webkit-calendar-picker-indicator {
    opacity: 1;
}

#customDateInput:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(11, 116, 255, 0.1);
}

.room-walk-controls { margin:8px 0; padding:8px; background:#edf5f1; color:#244e40; border:1px solid #b6d0c4; border-radius:6px; font-size:13px; }
.room-walk-controls[hidden] { display:none; }
.room-walk-controls div { display:flex; gap:5px; flex-wrap:wrap; margin-top:6px; }
.room-walk-controls button { flex:1; min-width:60px; padding:8px; user-select:none; }
.room-walk-controls output { display:block; margin-top:4px; }

.room-scene-overlay {position:absolute;inset:0;pointer-events:none;overflow:hidden;z-index:3;}
.room-scene-overlay[hidden],.room-name-label[hidden] {display:none;}
.room-name-label {position:absolute;transform:translate(-50%,-50%);padding:4px 9px;border:1px solid #ffffffaa;border-radius:5px;background:#173e35d9;color:white;font:13px sans-serif;white-space:nowrap;box-shadow:0 1px 5px #0003;}
.room-compass {position:absolute;right:18px;top:18px;width:102px;height:130px;display:flex;align-items:center;flex-direction:column;color:#244e40;}
.room-compass-dial {position:relative;flex-shrink:0;width:96px;height:96px;border:2px solid #789b8f;border-radius:50%;background:#fffffff0;box-shadow:0 2px 6px #0002;}
.room-compass-dial b {position:absolute;font:11px sans-serif;}
.room-compass-dial .north {top:5px;left:34px;color:#bf3939;}.room-compass-dial .south {bottom:5px;left:34px;}.room-compass-dial .east {right:4px;top:42px;}.room-compass-dial .west {left:4px;top:42px;}
.room-compass-dial span {position:absolute;left:37px;top:26px;color:#bf3939;font-size:34px;}
.room-compass output {margin-top:5px;padding:3px 6px;border-radius:4px;background:#fffffff0;font:12px sans-serif;white-space:nowrap;}

.room-current-name {position:absolute;left:50%;top:18px;transform:translateX(-50%);padding:6px 12px;border-radius:6px;background:#173e35dd;color:#fff;font:14px sans-serif;}
.room-current-name:empty {display:none;}

#canvas-container .room-compass {left:18px;right:auto;top:74px;}
