:root {
    --top-pane-height: 44vh;
    --table-height: 28vh;
    --primary-color: #007bff;
    --secondary-color: #6c757d;
    --success-color: #28a745;
    --danger-color: #dc3545;
    --info-color: #17a2b8;
    --warning-color: #ffc107;
    --border-color: #ccc;
    --bg-light: #f8f9fa;
    --bg-white: #ffffff;
}

* {
    box-sizing: border-box;
}

body {
    display: flex;
    margin: 0;
    height: 100vh;
    font-family: 'Microsoft YaHei', sans-serif;
    overflow: hidden;
}

/* GitHub 图标链接 */
.github-link {
    position: absolute;
    top: 16px;
    left: 16px;
    width: 48px;
    height: 48px;
    background: rgba(255, 255, 255, 0.96);
    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: 100;
    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;
}

/* 左侧画布区 */
#canvas-wrapper {
    flex: 1;
    background: #333;
    position: relative;
    overflow: hidden;
    cursor: grab;
}

#canvas-wrapper.grabbing {
    cursor: grabbing;
}

#canvas-wrapper.drag-over {
    outline: 3px dashed #31a36f;
    outline-offset: -3px;
}

#canvas-wrapper.drag-over::after {
    content: attr(data-drag-label);
    position: absolute;
    inset: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    border: 2px dashed rgba(255, 255, 255, 0.9);
    border-radius: 8px;
    background: rgba(22, 48, 58, 0.82);
    color: #fff;
    text-align: center;
    white-space: pre-line;
    font-size: 18px;
    font-weight: 700;
    pointer-events: none;
    z-index: 120;
}

canvas {
    background: white;
    display: none;
    transform-origin: 0 0;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
}

#empty-tip {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #888;
    font-size: 18px;
    pointer-events: none;
}

#zoom-info {
    position: absolute;
    bottom: 10px;
    left: 10px;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 12px;
    pointer-events: none;
}

/* 右侧边栏 */
#sidebar {
    width: 460px;
    background: var(--bg-light);
    border-left: 1px solid var(--border-color);
    padding: 16px;
    display: flex;
    flex-direction: column;
    z-index: 10;
    box-shadow: -2px 0 5px rgba(0, 0, 0, 0.05);
    overflow: hidden;
    gap: 8px;
}

/* 上半部分 */
#topPane {
    height: var(--top-pane-height);
    min-height: 180px;
    overflow: auto;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    background: var(--bg-white);
    padding: 10px;
}

/* 分隔条 */
.resizer {
    height: 8px;
    cursor: row-resize;
    border-radius: 6px;
    background: repeating-linear-gradient(90deg, #d7dee6 0, #d7dee6 6px, #e7edf3 6px, #e7edf3 12px);
    box-shadow: inset 0 0 0 1px #cfd6dd;
    user-select: none;
}

.resizer.active {
    background: #c7d7e7;
    box-shadow: inset 0 0 0 1px #9fb8d3;
}

/* 下半部分 */
#bottomPane {
    flex: 1;
    min-height: 200px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

h3 {
    margin: 0 0 10px;
    color: #333;
    border-bottom: 2px solid var(--primary-color);
    padding-bottom: 10px;
}

/* 步骤卡片 */
.step {
    margin-bottom: 14px;
    padding: 12px;
    background: var(--bg-white);
    border-radius: 6px;
    border: 1px solid #ddd;
}

.step.active {
    border-color: var(--primary-color);
    box-shadow: 0 0 5px rgba(0, 123, 255, 0.2);
}

.step.is-focused {
    border-color: #0d6efd;
    background: #f0f7ff;
    box-shadow: 0 0 0 2px rgba(13, 110, 253, 0.28);
}

#sidebar label {
    display: block;
    margin-bottom: 6px;
    font-weight: bold;
    font-size: 13px;
}

input[type="text"],
input[type="number"],
input[type="file"],
select,
textarea {
    width: 100%;
    box-sizing: border-box;
    padding: 8px;
    margin-bottom: 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 14px;
}

.inline-inputs {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 8px;
}

.inline-inputs .field {
    display: flex;
    flex-direction: column;
}

.inline-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
}

.inline-row input[type="checkbox"] {
    transform: scale(1.1);
}

.muted {
    color: #666;
    font-size: 12px;
    margin-bottom: 4px;
}

/* 按钮样式 */
button {
    width: 100%;
    padding: 10px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    margin-bottom: 6px;
    font-size: 14px;
    transition: background 0.2s;
}

button:hover {
    background: #0069d9;
}

button.secondary {
    background: var(--secondary-color);
}

button.secondary:hover {
    background: #5a6268;
}

button.info {
    background: var(--info-color);
}

button.info:hover {
    background: #138496;
}

button.success {
    background: var(--success-color);
}

button.success:hover {
    background: #218838;
}

button.warning {
    background: var(--warning-color);
    color: #333;
}

button:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.btn-outline {
    background: transparent;
    color: var(--primary-color);
    border: 1px solid #80bdff;
}

.btn-outline:hover {
    background: #e7f1ff;
}

/* 位置/纬度配置区 */
.location-config {
    background: #f1f8ff;
    padding: 10px;
    border-radius: 4px;
    margin-bottom: 10px;
    border: 1px solid #d0e3ff;
}

.location-config label {
    color: #0056b3;
    font-weight: bold;
    margin-bottom: 8px;
}

.location-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.location-row .field {
    flex: 1;
}

.draw-action-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
}

.draw-action-grid #btnDrawMode {
    grid-column: 1 / -1;
}

.draw-action-grid button {
    min-width: 0;
}

.location-config .field {
    display: flex;
    flex-direction: column;
}

.location-row select,
.location-row input {
    margin-bottom: 0;
}

.location-config .field input,
.location-config .field select {
    width: 100%;
    box-sizing: border-box;
}

/* 表格区 */
#step-table {
    margin: 0;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    background: var(--bg-white);
}

#table-wrapper {
    height: var(--table-height);
    min-height: 120px;
    overflow: auto;
    border: 1px solid #eee;
    border-radius: 6px;
    background: var(--bg-white);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

thead th {
    position: sticky;
    top: 0;
    background: #f1f3f5;
    z-index: 1;
}

th,
td {
    border-bottom: 1px solid #eee;
    padding: 6px;
    text-align: left;
}

td input {
    width: 100%;
    padding: 6px;
    box-sizing: border-box;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 12px;
}

#tableBody tr.building-row {
    cursor: pointer;
}

#tableBody tr.building-row.is-selected td {
    background: #e8f3ff;
}

#tableBody tr.building-row.is-selected td:first-child {
    box-shadow: inset 3px 0 0 #1976d2;
}

td select,
td textarea {
    width: 100%;
    padding: 6px;
    box-sizing: border-box;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 12px;
    font-family: inherit;
}

td textarea {
    resize: vertical;
    min-height: 72px;
    line-height: 1.45;
}

td .btn-mini {
    display: inline-block;
    padding: 4px 8px;
    font-size: 12px;
    border-radius: 4px;
    border: none;
    cursor: pointer;
}

.btn-danger {
    background: var(--danger-color);
    color: #fff;
}

.btn-danger:hover {
    background: #c82333;
}

.split-config-row td {
    background: #fbfdff;
    padding: 0;
}

.split-config-card {
    padding: 10px 12px 12px;
    border-top: 1px solid #eef3f8;
}

.split-config-title {
    margin: 0;
    color: #1f4d7a;
    font-size: 12px;
    font-weight: 700;
}

.split-config-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
}

.split-config-header .btn-mini {
    width: auto;
    margin: 0;
}

.split-config-grid {
    display: grid;
    grid-template-columns: 120px 160px minmax(220px, 1fr);
    gap: 10px;
    align-items: start;
}

.split-config-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.split-config-label {
    color: #425466;
    font-size: 12px;
    font-weight: 600;
}

.split-config-help {
    color: #6b7280;
    font-size: 11px;
    line-height: 1.45;
}

.split-config-help.invalid {
    color: #c0392b;
}

.split-config-input.invalid {
    border-color: #dc3545;
    background: #fff5f5;
}

.editor-loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 240;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(15, 29, 42, 0.42);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.16s ease, visibility 0.16s ease;
}

.editor-loading-overlay.is-active {
    opacity: 1;
    visibility: visible;
    pointer-events: all;
}

.editor-loading-panel {
    width: min(360px, calc(100vw - 40px));
    padding: 18px 20px;
    border-radius: 8px;
    background: #fff;
    color: #243442;
    text-align: center;
    font-weight: 600;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.2);
}

.editor-loading-spinner {
    width: 34px;
    height: 34px;
    margin: 0 auto 12px;
    border: 3px solid #d8e2ea;
    border-top-color: #1976d2;
    border-radius: 50%;
    animation: editor-loading-spin 0.8s linear infinite;
}

@keyframes editor-loading-spin {
    to { transform: rotate(360deg); }
}

.editor-modal {
    position: fixed;
    inset: 0;
    z-index: 220;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(12, 25, 38, 0.55);
}

.editor-modal[hidden] {
    display: none;
}

.editor-modal-dialog {
    width: min(720px, calc(100vw - 32px));
    max-height: min(760px, calc(100vh - 32px));
    overflow: auto;
    padding: 18px;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 22px 55px rgba(0, 0, 0, 0.28);
}

.editor-modal-header,
.editor-modal-footer,
.visual-split-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.editor-modal-header {
    justify-content: space-between;
    margin-bottom: 16px;
}

.editor-modal-header h2 {
    margin: 0;
    font-size: 18px;
    letter-spacing: 0;
}

.editor-modal-subtitle {
    margin-top: 3px;
    color: #667584;
    font-size: 12px;
}

.icon-button {
    width: 36px;
    height: 36px;
    flex: 0 0 36px;
    margin: 0;
    padding: 0;
    border-radius: 6px;
    background: #eef2f5;
    color: #263746;
    font-size: 22px;
}

.visual-split-controls {
    display: grid;
    grid-template-columns: minmax(140px, 0.45fr) minmax(260px, 1fr);
    gap: 12px;
    margin-bottom: 16px;
}

.visual-split-controls label {
    margin: 0;
    font-size: 12px;
}

.angle-control {
    display: grid;
    grid-template-columns: 1fr 88px;
    gap: 8px;
}

.angle-control input {
    margin: 0;
}

.visual-split-bar {
    position: relative;
    height: 78px;
    overflow: hidden;
    border: 1px solid #aebbc5;
    border-radius: 6px;
    background: #eef2f5;
    user-select: none;
    touch-action: none;
}

.visual-split-segment {
    position: absolute;
    top: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    color: #17212b;
    font-size: 12px;
    font-weight: 700;
    border-right: 1px solid rgba(30, 48, 62, 0.35);
}

.visual-split-segment:nth-child(4n + 1) { background: #9fd5c1; }
.visual-split-segment:nth-child(4n + 2) { background: #f4cb87; }
.visual-split-segment:nth-child(4n + 3) { background: #a9c8e8; }
.visual-split-segment:nth-child(4n + 4) { background: #d8b6df; }

.visual-split-handle {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 14px;
    margin-left: -7px;
    border: 0;
    border-radius: 0;
    background: transparent;
    cursor: ew-resize;
    touch-action: none;
}

.visual-split-handle::before {
    content: '';
    position: absolute;
    top: 8px;
    bottom: 8px;
    left: 6px;
    width: 2px;
    background: #243b4a;
}

.visual-split-inputs {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    gap: 8px;
    margin-top: 12px;
}

.visual-split-inputs label {
    margin: 0;
    color: #445463;
    font-size: 11px;
}

.visual-split-inputs input {
    margin: 4px 0 0;
}

.visual-split-actions {
    margin-top: 14px;
}

.editor-modal-footer {
    justify-content: flex-end;
    margin-top: 18px;
    padding-top: 14px;
    border-top: 1px solid #e3e8ec;
}

.visual-split-actions button,
.editor-modal-footer button {
    width: auto;
    min-width: 120px;
    margin: 0;
}

/* 响应式 */
@media (max-width: 768px) {
    .github-link {
        top: 8px;
        left: 8px;
        width: 42px;
        height: 42px;
    }

    .github-link svg {
        width: 24px;
        height: 24px;
    }

    #sidebar {
        width: 100vw;
        position: absolute;
        right: 0;
        left: 0;
        bottom: 0;
        max-height: 60vh;
        overflow: hidden;
    }

    #topPane {
        max-height: 55vh;
    }

    #table-wrapper {
        max-height: 55vh;
    }

    .split-config-grid {
        grid-template-columns: 1fr;
    }

    .draw-action-grid {
        grid-template-columns: 1fr 1fr;
    }

    .draw-action-grid #btnUndoEdit {
        grid-column: 1 / -1;
    }

    .visual-split-controls {
        grid-template-columns: 1fr;
    }

    .visual-split-actions,
    .editor-modal-footer {
        flex-wrap: wrap;
    }

    .visual-split-actions button,
    .editor-modal-footer button {
        flex: 1 1 130px;
    }
}

/* 语言切换按钮 */
.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: #007bff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

/* 步骤向导与上传说明卡 */
.wizard-steps {
    display: flex;
    gap: 4px;
    margin-bottom: 4px;
    flex-wrap: wrap;
}
.wizard-step {
    flex: 1;
    min-width: 56px;
    border: 1px solid #d0d7de;
    background: #f6f8fa;
    border-radius: 8px;
    padding: 6px 4px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    color: #57606a;
}
.wizard-step .wizard-num {
    width: 20px; height: 20px; border-radius: 50%;
    background: #d0d7de; color: #fff; font-size: 12px; line-height: 20px; text-align: center;
}
.wizard-step .wizard-label { font-size: 11px; }
.wizard-step.is-done .wizard-num { background: #28a745; }
.wizard-step.is-current {
    border-color: #007bff; background: #e8f2ff; color: #0b5ed7;
}
.wizard-step.is-current .wizard-num { background: #007bff; }
.wizard-hint {
    margin: 0 0 8px; font-size: 12px; color: #57606a; line-height: 1.45;
    background: #fff8e6; border: 1px solid #ffe8a3; border-radius: 6px; padding: 8px 10px;
}
.upload-cards { display: flex; flex-direction: column; gap: 8px; }
.upload-card {
    border: 1px solid #d0d7de; border-radius: 8px; padding: 10px; background: #f8fafc;
}
.upload-card strong { display: block; margin-bottom: 4px; font-size: 13px; }
.upload-card .muted { margin: 0 0 8px; font-size: 12px; line-height: 1.4; }
