/* ========================================
   MapPulse - 游戏热力图分析平台 · 暗色主题
   ======================================== */

:root {
    --bg-base: #0f0f17;
    --bg-surface: #16161f;
    --bg-card: #1c1c28;
    --bg-elevated: #22222f;
    --bg-input: #1a1a26;
    --text-primary: #e8e8ed;
    --text-secondary: #8888a0;
    --text-muted: #55556a;
    --accent: #6366f1;
    --accent-light: #818cf8;
    --accent-glow: rgba(99, 102, 241, 0.15);
    --border: rgba(255, 255, 255, 0.06);
    --border-light: rgba(255, 255, 255, 0.1);
    --red: #ef4444;
    --yellow: #eab308;
    --blue: #3b82f6;
    --green: #22c55e;
    --purple: #a855f7;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --shadow: 0 1px 3px rgba(0,0,0,0.3), 0 4px 12px rgba(0,0,0,0.2);
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
    background: var(--bg-base);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* ======== 顶部导航 ======== */
.top-bar {
    height: 48px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    flex-shrink: 0;
    z-index: 10;
}

.top-bar-left {
    display: flex;
    align-items: center;
    gap: 24px;
}

.logo {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: -0.3px;
}

.tab-bar {
    display: flex;
    gap: 2px;
}

.tab-btn {
    padding: 6px 16px;
    background: none;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: var(--transition);
}

.tab-btn:hover { color: var(--text-primary); background: var(--bg-elevated); }
.tab-btn.active { color: var(--accent-light); background: var(--accent-glow); }

.top-bar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 6px var(--green);
}

.status-text {
    font-size: 12px;
    color: var(--text-secondary);
}

/* ======== Tab Content ======== */
.tab-content { display: none; flex: 1; overflow: hidden; }
.tab-content.active { display: flex; }

/* ======== 工作区 ======== */
.workspace {
    display: flex;
    width: 100%;
    height: 100%;
    gap: 0;
}

/* ======== 左侧边栏 ======== */
.sidebar {
    width: 272px;
    flex-shrink: 0;
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 12px;
    gap: 10px;
    overflow-y: auto;
}

.card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    padding: 14px;
}

.card-grow { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }

.card-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    margin-bottom: 12px;
}

.card-title svg { color: var(--accent-light); }

/* Form */
.form-row { margin-bottom: 10px; }
.form-row:last-child { margin-bottom: 0; }
.form-row label {
    display: block;
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

select {
    width: 100%;
    padding: 8px 10px;
    background: var(--bg-input);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 13px;
    outline: none;
    cursor: pointer;
    transition: var(--transition);
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%238888a0' fill='none' stroke-width='1.5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
}

select:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-glow); }

/* Sliders */
.slider-group { display: flex; flex-direction: column; gap: 10px; }


.slider-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 6px;
}

.slider-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.slider-label {
    font-size: 12px;
    color: var(--text-secondary);
    flex: 1;
}

.slider-val {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary);
    min-width: 24px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

input[type="range"] {
    width: 100%;
    height: 4px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--border-light);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent-light);
    border: 2px solid var(--bg-card);
    box-shadow: 0 0 6px var(--accent-glow);
    cursor: pointer;
    transition: transform 0.15s;
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

input[type="range"]::-webkit-slider-thumb:active {
    transform: scale(1.1);
    background: var(--accent);
}

/* Map Grid */
.map-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    flex: 1;
    overflow-y: auto;
    padding: 2px;
}

.map-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    overflow: hidden;
}

.map-card:hover {
    border-color: var(--accent);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.map-card.selected {
    border-color: var(--accent);
    background: var(--accent-glow);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

.map-thumb {
    height: 60px;
    background: var(--bg-base);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.map-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.map-thumb .no-img-icon {
    font-size: 24px;
    opacity: 0.3;
}

.map-info {
    padding: 6px 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.map-name {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.map-meta {
    font-size: 10px;
    color: var(--text-muted);
}

.map-badge {
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 8px;
    display: inline-block;
    width: fit-content;
}

.map-badge.data-yes {
    background: rgba(34, 197, 94, 0.15);
    color: var(--green);
}

.map-badge.data-no {
    background: rgba(255,255,255,0.05);
    color: var(--text-muted);
}

/* Rec tag */
.rec-tag {
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 8px;
    background: var(--accent-glow);
    color: var(--accent-light);
    margin-left: 6px;
    font-weight: 400;
}

/* 算法切换 */
.algo-switch {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
}
.switch-label {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
}
.algo-select {
    flex: 1;
    padding: 4px 6px;
    font-size: 11px;
}

.rec-tag.flash {
    animation: recFlash 0.6s ease;
}

@keyframes recFlash {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; background: var(--accent); color: #fff; }
}

/* Action buttons */
.action-group {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.btn {
    padding: 8px 14px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.btn-run {
    flex: 1;
    justify-content: center;
    background: var(--accent);
    color: #fff;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

.btn-run:hover { background: var(--accent-light); box-shadow: 0 4px 16px rgba(99, 102, 241, 0.4); }
.btn-run:active { transform: scale(0.98); }
.btn-run:disabled { opacity: 0.4; cursor: not-allowed; box-shadow: none; }
.btn-run.running { background: #4b5563; box-shadow: none; animation: pulse 1.5s infinite; }

@keyframes pulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

.btn-ghost {
    background: var(--bg-elevated);
    color: var(--text-secondary);
    border: 1px solid var(--border-light);
}

.btn-ghost:hover { color: var(--text-primary); border-color: var(--accent); }

/* ======== 中间地图区 ======== */
.map-area {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg-base);
}

/* 地图工具栏 */
.map-toolbar {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 12px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.tb-btn {
    padding: 4px 10px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-light);
    border-radius: 4px;
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: var(--transition);
    line-height: 1;
}
.tb-btn:hover { border-color: var(--accent); color: var(--accent-light); }
.tb-btn:active { background: var(--accent-glow); }

.tb-sep {
    width: 1px;
    height: 18px;
    background: var(--border-light);
    margin: 0 4px;
}

.tb-label {
    font-size: 12px;
    color: var(--text-muted);
    min-width: 36px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.map-viewport {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
    background:
        radial-gradient(circle at 50% 50%, rgba(99, 102, 241, 0.03) 0%, transparent 70%),
        linear-gradient(var(--bg-base), var(--bg-base));
}

/* 工作区全屏（隐藏底部数据面板，地图区纵向撑满） */
.workspace.map-expanded .data-panel {
    display: none;
}

.map-viewport img.visible {
    display: block;
}

.map-viewport img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    cursor: crosshair;
    border-radius: 4px;
    display: none;
    flex-shrink: 0;
}

.map-placeholder { text-align: center; user-select: none; }
.map-placeholder.hidden { display: none; }
.placeholder-icon { margin-bottom: 16px; color: var(--text-muted); }
.placeholder-main { font-size: 15px; color: var(--text-secondary); margin-bottom: 6px; }
.placeholder-sub { font-size: 12px; color: var(--text-muted); }

/* Progress */
.progress-track { height: 3px; background: var(--border); flex-shrink: 0; }
.progress-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent), var(--purple)); transition: width 0.3s ease; border-radius: 0 2px 2px 0; }

/* 地图底部状态栏 */
.map-status-bar {
    flex-shrink: 0;
    padding: 6px 16px;
    font-size: 12px;
    color: var(--text-secondary);
    background: var(--bg-surface);
    border-top: 1px solid var(--border);
}

/* === 颜色配置行 === */
.color-config-group { display: flex; flex-direction: column; gap: 6px; }

.color-config-row {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    color: var(--text-secondary);
}

.color-config-row input[type="color"] {
    width: 22px;
    height: 22px;
    border: 1px solid var(--border-light);
    border-radius: 4px;
    padding: 0;
    cursor: pointer;
    background: none;
    -webkit-appearance: none;
}

.color-config-row input[type="color"]::-webkit-color-swatch-wrapper { padding: 1px; }
.color-config-row input[type="color"]::-webkit-color-swatch { border-radius: 3px; border: none; }

.cc-label { width: 28px; font-weight: 600; color: var(--text-primary); font-size: 11px; }
.cc-ref { font-weight: 600; color: var(--text-muted); min-width: 20px; }

.num-input {
    width: 42px;
    padding: 3px 5px;
    background: var(--bg-input);
    border: 1px solid var(--border-light);
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 12px;
    text-align: center;
    outline: none;
    -moz-appearance: textfield;
}
.num-input::-webkit-inner-spin-button { opacity: 0.3; }
.num-input:focus { border-color: var(--accent); }

/* === 底部数据面板 === */
.data-panel {
    flex-shrink: 0;
    background: var(--bg-surface);
    border-top: 1px solid var(--border);
    max-height: 200px;
    display: flex;
    flex-direction: column;
}

.data-tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.data-tab {
    padding: 6px 16px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    font-size: 12px;
    cursor: pointer;
    transition: var(--transition);
}
.data-tab:hover { color: var(--text-primary); }
.data-tab.active { color: var(--accent-light); border-bottom-color: var(--accent); }

.data-tab-content { display: none; flex: 1; overflow: hidden; padding: 8px 16px; }
.data-tab-content.active { display: flex; flex-direction: column; }

.data-strip-info { margin-bottom: 4px; font-size: 12px; color: var(--text-secondary); flex-shrink: 0; }

.data-tab-content textarea {
    flex: 1;
    width: 100%;
    padding: 6px 10px;
    background: var(--bg-input);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 11px;
    font-family: "SF Mono", "Fira Code", monospace;
    resize: none;
    outline: none;
}
.data-tab-content textarea:focus { border-color: var(--accent); }

.table-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
    font-size: 12px;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.btn-sm {
    padding: 3px 10px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-light);
    border-radius: 4px;
    color: var(--text-secondary);
    font-size: 11px;
    cursor: pointer;
    transition: var(--transition);
}
.btn-sm:hover { border-color: var(--accent); color: var(--accent-light); }

.data-table-wrap { flex: 1; overflow: auto; }

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
    font-family: "SF Mono", monospace;
}
.data-table th {
    position: sticky;
    top: 0;
    background: var(--bg-card);
    padding: 5px 8px;
    text-align: left;
    color: var(--text-muted);
    font-size: 10px;
    text-transform: uppercase;
    border-bottom: 1px solid var(--border);
}
.data-table td {
    padding: 3px 8px;
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
}
.data-table tr:hover td { background: var(--bg-elevated); }

/* === 导入弹窗 === */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: 24px;
    width: 440px;
    max-width: 90vw;
    box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}

.modal-content h3 { margin-bottom: 16px; font-size: 16px; }

.modal-content .form-row { margin-bottom: 10px; }
.modal-content .form-row label {
    display: block;
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 4px;
    text-transform: uppercase;
}
.modal-content .form-row input[type="text"],
.modal-content .form-row input[type="number"] {
    width: 100%;
    padding: 7px 10px;
    background: var(--bg-input);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 13px;
    outline: none;
}
.modal-content .form-row input:focus { border-color: var(--accent); }
.modal-content .form-row input[type="file"] {
    font-size: 12px;
    color: var(--text-secondary);
}

.modal-actions {
    display: flex;
    gap: 8px;
    margin-top: 16px;
}

.import-status {
    margin-top: 10px;
    font-size: 13px;
    color: var(--text-secondary);
    min-height: 20px;
}

/* ======== 右侧结果面板 ======== */
.result-panel {
    width: 320px;
    flex-shrink: 0;
    background: var(--bg-surface);
    border-left: 1px solid var(--border);
    padding: 12px;
    display: flex;
    flex-direction: column;
}

.result-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 10px;
    background: var(--bg-base);
    border-radius: var(--radius-sm);
    padding: 3px;
}

.result-tab {
    flex: 1;
    padding: 7px 8px;
    background: none;
    border: none;
    border-radius: 4px;
    color: var(--text-secondary);
    font-size: 11px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    white-space: nowrap;
}

.result-tab:hover { color: var(--text-primary); }
.result-tab.active { background: var(--bg-card); color: var(--accent-light); box-shadow: var(--shadow); }

.badge {
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 10px;
    background: var(--bg-elevated);
    color: var(--text-muted);
    font-weight: 600;
}

.result-tab.active .badge {
    background: var(--accent-glow);
    color: var(--accent-light);
}

.result-scroll {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.result-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.result-table th {
    position: sticky;
    top: 0;
    background: var(--bg-card);
    padding: 8px 8px;
    text-align: left;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    border-bottom: 1px solid var(--border);
}

.result-table td {
    padding: 7px 8px;
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
}

.result-table tr:hover td { background: var(--bg-elevated); color: var(--text-primary); }

.result-footer {
    display: flex;
    gap: 6px;
    margin-top: 10px;
    flex-shrink: 0;
}

.btn-icon {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 7px 10px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 12px;
    cursor: pointer;
    transition: var(--transition);
}

.btn-icon:hover { border-color: var(--accent); color: var(--accent-light); }

/* ======== Help Page ======== */
.help-page {
    flex: 1;
    overflow-y: auto;
    display: flex;
    justify-content: center;
    padding: 40px 20px;
}

.help-card {
    max-width: 640px;
    width: 100%;
    line-height: 1.7;
}

.help-card h1 {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 4px;
}

.help-subtitle {
    color: var(--text-secondary);
    margin-bottom: 32px;
}

.help-card h2 {
    font-size: 16px;
    font-weight: 600;
    color: var(--accent-light);
    margin: 28px 0 12px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
}

.steps {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.step {
    display: flex;
    gap: 14px;
    align-items: flex-start;
}

.step-num {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--accent-glow);
    color: var(--accent-light);
    font-size: 13px;
    font-weight: 700;
    flex-shrink: 0;
}

.step strong { display: block; margin-bottom: 2px; }
.step p { font-size: 13px; color: var(--text-secondary); margin: 0; }

.color-legend {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-secondary);
}

.legend-item i {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    display: inline-block;
}

.help-card code {
    background: var(--bg-elevated);
    padding: 2px 7px;
    border-radius: 4px;
    font-size: 12px;
    font-family: "SF Mono", "Fira Code", monospace;
    color: var(--accent-light);
}

.help-card p { color: var(--text-secondary); font-size: 14px; margin-bottom: 6px; }

/* ======== Toast ======== */
.toast {
    position: fixed;
    top: 60px;
    right: 16px;
    padding: 10px 18px;
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 13px;
    z-index: 9999;
    opacity: 0;
    transform: translateX(20px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
    box-shadow: var(--shadow);
}

.toast.show { opacity: 1; transform: translateX(0); }
.toast.success { border-left: 3px solid var(--green); }
.toast.error { border-left: 3px solid var(--red); }
.toast.info { border-left: 3px solid var(--accent); }

/* ======== Scrollbar ======== */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.15); }

/* ======== Responsive ======== */
@media (max-width: 1100px) {
    .workspace { flex-direction: column; }
    .sidebar { width: 100%; flex-direction: row; flex-wrap: wrap; overflow-y: visible; border-right: none; border-bottom: 1px solid var(--border); }
    .result-panel { width: 100%; border-left: none; border-top: 1px solid var(--border); }
}
