: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;
}

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-row .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;
}

.lat-display {
    font-size: 13px;
    color: #555;
    text-align: center;
    padding-top: 4px;
}

/* 开关行 */
.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;
}

.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;
}

/* 热力图图例 */
.heatmap-legend {
    margin-top: 12px;
    padding: 10px;
    background: #fff;
    border-radius: 6px;
}

.legend-bar {
    height: 16px;
    border-radius: 4px;
    background: linear-gradient(90deg, 
        #313695, #4575b4, #74add1, #abd9e9, 
        #e0f3f8, #ffffbf, #fee090, #fdae61, 
        #f46d43, #d73027, #a50026);
}

.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 .stat-row {
    display: flex;
    justify-content: space-between;
    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;
}

.sunlight-stats .stat-value.good {
    color: #28a745;
}

.sunlight-stats .stat-value.warning {
    color: #ffc107;
}

.sunlight-stats .stat-value.bad {
    color: #dc3545;
}

/* 户型信息面板 */
.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;
}

/* 指南针 */
#compass {
    position: absolute;
    bottom: 18px;
    right: 18px;
    width: 80px;
    height: 80px;
    pointer-events: none;
    z-index: 5;
}

/* 空状态提示 */
#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;
}

/* 图例提示 */
.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: 18px;
    transition: background 0.2s;
    z-index: 11;
    color: var(--text);
}

.sidebar-toggle:hover {
    background: #e2e8f0;
}

/* 收起状态 */
#controls.collapsed {
    width: 52px;
    height: 52px;
    padding: 8px;
    border-radius: 12px;
}

#controls.collapsed .panel-content {
    opacity: 0;
    pointer-events: none;
}

/* 移动端适配 */
@media (max-width: 600px) {
    #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;
        font-size: 16px;
    }

    #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);
    }

    #compass {
        width: 64px;
        height: 64px;
        bottom: calc(env(safe-area-inset-bottom, 16px) + 56px);
        right: 12px;
    }

    .unit-info-panel {
        left: 8px;
        right: 8px;
        bottom: calc(env(safe-area-inset-bottom, 10px) + 66px);
        width: auto;
    }
}