/* ===== 变量 ===== */
:root {
    --bg: #1a1a1a;
    --panel: #252525;
    --panel-header: #2a2a2a;
    --border: #3a3a3a;
    --accent: #5d8c3e;
    --accent-hover: #4a7a2e;
    --text: #e0e0e0;
    --text-dim: #888;
    --highlight: #55ff55;
    --danger: #ff5555;
    --radius: 6px;
}

/* ===== 重置 ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
    font-size: 13px;
}

/* ===== 布局 ===== */
.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* ===== 顶部工具栏 ===== */
.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.toolbar-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo { font-size: 22px; }

.toolbar h1 {
    font-size: 16px;
    font-weight: 600;
    color: var(--highlight);
}

/* ===== 按钮 ===== */
.btn {
    padding: 6px 14px;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 12px;
    transition: all 0.15s;
    white-space: nowrap;
}
.btn:hover { background: var(--border); border-color: var(--accent); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn:disabled:hover { background: var(--bg); border-color: var(--border); }

.btn-sm { padding: 4px 8px; font-size: 14px; }

.btn-primary {
    background: var(--accent);
    border-color: var(--accent-hover);
    color: #fff;
    font-weight: 600;
    font-size: 13px;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled:hover { background: var(--accent); }

.btn-block { width: 100%; padding: 10px; font-size: 14px; }

.btn-ghost {
    background: transparent;
    border-color: transparent;
    color: var(--text-dim);
}
.btn-ghost:hover { color: var(--text); background: rgba(255,255,255,0.05); border-color: transparent; }

/* ===== 主内容 ===== */
.main {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ===== 面板通用 ===== */
.panel {
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    overflow: hidden;
}

.panel:last-child { border-right: none; }

.panel-header {
    padding: 10px 14px;
    background: var(--panel-header);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.panel-header h2 {
    font-size: 13px;
    font-weight: 600;
    color: var(--highlight);
}

/* ===== 地图面板 ===== */
.map-panel {
    width: 380px;
    min-width: 300px;
    flex-shrink: 0;
}

.search-bar {
    display: flex;
    gap: 6px;
    padding: 8px 10px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.search-bar input {
    flex: 1;
    padding: 6px 10px;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: var(--radius);
    font-size: 12px;
    outline: none;
}
.search-bar input:focus { border-color: var(--accent); }

.map-container {
    flex: 1;
    min-height: 200px;
}

.selection-info {
    padding: 8px 12px;
    background: var(--panel-header);
    border-top: 1px solid var(--border);
    font-size: 11px;
    color: var(--text-dim);
    flex-shrink: 0;
}

/* ===== 控制面板 ===== */
.controls-panel {
    width: 240px;
    min-width: 200px;
    flex-shrink: 0;
    overflow-y: auto;
}

.control-group {
    padding: 8px 14px;
    border-bottom: 1px solid rgba(255,255,255,0.04);
}

.control-group label {
    display: block;
    font-size: 11px;
    color: var(--text-dim);
    margin-bottom: 4px;
}

.control-group select {
    width: 100%;
    padding: 5px 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: var(--radius);
    font-size: 12px;
    outline: none;
}
.control-group select:focus { border-color: var(--accent); }

.checkbox-label {
    display: flex !important;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    margin-bottom: 0 !important;
}

.checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
}

.checkbox-label span {
    font-size: 12px;
    color: var(--text);
}

.divider {
    height: 1px;
    background: var(--border);
    margin: 8px 14px;
}

/* ===== 图例 ===== */
.legend {
    padding: 8px 14px;
}

.legend h3 {
    font-size: 11px;
    color: var(--text-dim);
    margin-bottom: 8px;
    font-weight: 500;
}

.legend-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    color: var(--text-dim);
}

.legend-color {
    width: 12px;
    height: 12px;
    border-radius: 2px;
    border: 1px solid rgba(255,255,255,0.15);
    flex-shrink: 0;
}

/* ===== 统计 ===== */
.stats {
    padding: 8px 14px;
}

.stats h3 {
    font-size: 11px;
    color: var(--text-dim);
    margin-bottom: 8px;
    font-weight: 500;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    padding: 3px 0;
    font-size: 11px;
}

.stat-row span:first-child { color: var(--text-dim); }
.stat-row span:last-child { color: var(--text); font-weight: 500; }

/* ===== 预览面板 ===== */
.preview-panel {
    flex: 1;
    min-width: 400px;
}

.preview-panel .panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 12px;
}

.view-tabs {
    display: flex;
    gap: 2px;
    background: var(--bg);
    padding: 3px;
    border-radius: var(--radius);
}

.view-btn {
    padding: 4px 14px;
    background: transparent;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    border-radius: 4px;
    font-size: 12px;
    transition: all 0.15s;
}
.view-btn:hover { color: var(--text); background: rgba(255,255,255,0.05); }
.view-btn.active { background: var(--accent); color: #fff; }

.view-actions {
    display: flex;
    gap: 4px;
}

.preview-container {
    flex: 1;
    position: relative;
    background: #0a0a0a;
    overflow: hidden;
}

.view-container {
    display: none;
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
}
.view-container.active { display: block; }

.view-container canvas {
    width: 100%;
    height: 100%;
    display: block;
}

.view-overlay {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(0,0,0,0.6);
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 11px;
    color: var(--text-dim);
    pointer-events: none;
}

/* ===== 空状态 ===== */
.empty-state {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-dim);
    text-align: center;
    pointer-events: none;
}

.empty-state.hidden { display: none; }

.empty-icon {
    font-size: 64px;
    margin-bottom: 16px;
    opacity: 0.3;
}

.empty-state p { margin: 4px 0; font-size: 14px; }
.empty-hint { font-size: 12px !important; color: #666; }

/* ===== 底部状态栏 ===== */
.statusbar {
    display: flex;
    justify-content: space-between;
    padding: 4px 16px;
    background: var(--panel);
    border-top: 1px solid var(--border);
    font-size: 11px;
    color: var(--text-dim);
    flex-shrink: 0;
}

/* ===== 加载遮罩 ===== */
.loading-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.85);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 10000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
}
.loading-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.loading-content {
    text-align: center;
    max-width: 360px;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border);
    border-top-color: var(--highlight);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-content p {
    font-size: 14px;
    color: var(--text);
    margin-bottom: 12px;
}

.loading-progress {
    width: 100%;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 8px;
}

.progress-bar {
    height: 100%;
    width: 0%;
    background: var(--accent);
    border-radius: 2px;
    transition: width 0.3s;
}

.loading-detail {
    font-size: 12px !important;
    color: var(--text-dim) !important;
}

/* ===== 弹窗 ===== */
.modal {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.7);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 5000;
}
.modal.active { display: flex; }

.modal-content {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    width: 460px;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    font-size: 15px;
    color: var(--highlight);
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 22px;
    cursor: pointer;
    line-height: 1;
}
.modal-close:hover { color: var(--text); }

.modal-body {
    padding: 18px;
}

.howto-steps {
    list-style: decimal;
    padding-left: 20px;
    margin-bottom: 16px;
}

.howto-steps li {
    padding: 6px 0;
    font-size: 13px;
    line-height: 1.5;
}

.howto-steps strong { color: var(--highlight); }

.howto-tips {
    background: var(--bg);
    padding: 12px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

.howto-tips p {
    font-size: 12px;
    margin-bottom: 8px;
    color: var(--text);
}

.howto-tips ul {
    list-style: disc;
    padding-left: 18px;
}

.howto-tips li {
    font-size: 12px;
    color: var(--text-dim);
    padding: 2px 0;
    line-height: 1.5;
}

/* ===== Leaflet 自定义 ===== */
.leaflet-container {
    background: #1a1a1a;
}

.area-rect {
    border: 2px solid var(--highlight);
    background: rgba(85, 255, 85, 0.15);
}

/* ===== 滚动条 ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #555; }

/* ===== 响应式 ===== */
@media (max-width: 1100px) {
    .controls-panel { width: 200px; min-width: 180px; }
    .map-panel { width: 320px; min-width: 260px; }
}

@media (max-width: 900px) {
    .main { flex-direction: column; }
    .map-panel, .controls-panel {
        width: 100%;
        min-width: unset;
        max-height: 250px;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    .preview-panel { min-width: unset; min-height: 300px; }
}

/* ===== 预设城市 ===== */
.preset-cities {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 6px 10px;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    flex-shrink: 0;
}

.preset-label {
    font-size: 11px;
    color: var(--text-dim);
    margin-right: 2px;
}

.city-chip {
    padding: 2px 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text-dim);
    border-radius: 12px;
    cursor: pointer;
    font-size: 11px;
    transition: all 0.15s;
    white-space: nowrap;
}

.city-chip:hover {
    background: var(--accent);
    border-color: var(--accent-hover);
    color: #fff;
}

.preset-landmarks {
    border-top: none;
    padding-top: 0;
}

.landmark-chip {
    border-color: #8b5e3c;
    color: #d4b96a;
}

.landmark-chip:hover {
    background: #8b5e3c;
    border-color: #a0724e;
    color: #fff;
}

/* ===== 自定义方块映射 ===== */
.custom-block-panel {
    padding: 6px 14px;
    border-bottom: 1px solid var(--border);
}

.custom-block-panel.hidden { display: none; }

.block-mapping {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.block-mapping label {
    font-size: 11px;
    color: var(--text-dim);
    width: 36px;
    flex-shrink: 0;
    margin-bottom: 0;
}

.block-mapping select {
    flex: 1;
    padding: 3px 6px;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: var(--radius);
    font-size: 11px;
    outline: none;
}

.block-mapping select:focus { border-color: var(--accent); }

/* ===== 导出面板 ===== */
.export-panel {
    margin-top: 4px;
}

.export-panel.hidden { display: none; }

.export-panel h3 {
    font-size: 12px;
    color: var(--text-dim);
    margin-bottom: 8px;
}

.btn-export {
    width: 100%;
    padding: 10px 12px;
    margin-bottom: 6px;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 13px;
    text-align: left;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-export:hover {
    background: var(--panel-header);
    border-color: var(--accent);
    color: var(--highlight);
}

.btn-export:active {
    transform: scale(0.98);
}
