/**
 * 基础：CSS 变量、Reset、滚动条、加载遮罩、侧边栏骨架与头尾
 *
 * 由原单文件 css/style.css 按区块切分而来（R164）。
 * 注意：本文件的引入顺序即级联顺序，调整顺序可能改变样式优先级。
 */

/* ===== CSS Variables ===== */
:root {
    --bg-primary: #f0f2f5;
    --bg-secondary: #ffffff;
    --bg-panel: rgba(255, 255, 255, 0.97);
    --bg-hover: #f5f7fa;
    --bg-selected: #eef3ff;
    --bg-active: #e8edf5;
    
    --text-primary: #1a1a2e;
    --text-secondary: #6b7280;
    --text-muted: #9ca3af;
    --text-inverse: #ffffff;
    --tooltip-bg: #ffffff;
    --tooltip-text: #334155;
    --tooltip-border: #cbd5e1;
    
    --border-color: #e5e7eb;
    --border-light: #f3f4f6;
    
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 24px rgba(0, 0, 0, 0.10);
    --shadow-lg: 0 8px 48px rgba(0, 0, 0, 0.15);
    --shadow-xl: 0 12px 64px rgba(0, 0, 0, 0.20);
    
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 10px;
    --radius-xl: 12px;
    
    --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    
    /* R72：用户反馈"恢复成最开始的 UI 配色"——还原 R64 之前的蓝色主题
       （accent 蓝 #4f6ef7 / 冷灰蓝背景 / success 绿 / danger 红 / warning 琥珀 / info 蓝） */
    --accent-color: #4f6ef7;
    --accent-hover: #3b5de7;
    --accent-light: rgba(79, 110, 247, 0.12);
    --accent-gradient: linear-gradient(135deg, #4f6ef7 0%, #3158d8 100%);

    --success-color: #10b981;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --info-color: #3b82f6;

    /* 地图标注扫边（halo）颜色：亮色主题白边 / 暗色主题深色边 */
    --label-halo: rgba(255, 255, 255, 0.92);

    /* R83：Copernicus 式全高左侧边栏布局 */
    --sidebar-width: 380px;
    --sidebar-header-height: 60px;
    --map-tool-size: 38px;

    /* R94：地图底色随主题变化——瓦片加载中/未覆盖区域露出该底色，
       暗色主题下若仍是浅色，换底图时会出现刺眼亮块（用户反馈「切换颜色模式颜色不正常」） */
    --map-bg: #e5e3df;

    /* R168：侧边栏标题栏配色（两主题各一套）。
       亮色——蓝底白字，渐变直接锚定主题色：终点即 accent #4f6ef7、起点略提亮，
       与整体蓝色调一致，同时比 R154 之前的 #4f6ef7→#3158d8 明显更浅（R154 反馈「过深」）。
       起点 #5f7df5 配白字对比度约 3.7:1，满足 WCAG 大文字 3:1；再叠 8% 高光增加层次。 */
    --header-bg: linear-gradient(135deg, #5f7df5 0%, #4f6ef7 100%);
    --header-highlight: radial-gradient(120% 140% at 4% 0%, rgba(255, 255, 255, 0.08) 0%, rgba(255, 255, 255, 0) 58%);
    --header-text: #ffffff;
    --header-text-muted: rgba(255, 255, 255, 0.85);
    --header-btn-hover: rgba(255, 255, 255, 0.16);
    --header-btn-active: rgba(255, 255, 255, 0.24);
    --header-icon-shadow: rgba(0, 0, 0, 0.25);
    /* 蓝底与下方白面板已有明显色差，无需分隔线 */
    --header-border: transparent;
    /* 白字在蓝底上的极轻投影，提升浅色区域的字形清晰度 */
    --header-text-shadow: 0 1px 2px rgba(30, 44, 130, 0.28);
}

[data-theme="dark"] {
    --bg-primary: #0f0f1a;
    --bg-secondary: #1a1a2e;
    --bg-panel: rgba(26, 26, 46, 0.92);
    --bg-hover: #252540;
    --bg-selected: rgba(79, 110, 247, 0.15);
    --bg-active: #2a2a4a;
    
    --text-primary: #e8e8f0;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;
    --tooltip-bg: #1e293b;
    --tooltip-text: #f8fafc;
    --tooltip-border: #475569;
    
    --border-color: #2d2d4a;
    --border-light: #1f1f38;
    
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 24px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 48px rgba(0, 0, 0, 0.5);
    --shadow-xl: 0 12px 64px rgba(0, 0, 0, 0.6);

    --label-halo: rgba(15, 15, 26, 0.92);

    /* R94：暗色主题地图底色（与 Esri 暗黑底图色调一致），避免瓦片加载中露出浅色 */
    --map-bg: #16161f;

    /* R168：暗色标题栏同为蓝调，但压暗成深靛蓝（accent #4f6ef7 的低明度版本），
       比面板 #1a1a2e 略亮一档形成层次，配浅色文字对比度约 10:1；高光减弱避免在深色界面发白。 */
    --header-bg: linear-gradient(135deg, #2c3b6e 0%, #1e2a4d 100%);
    --header-highlight: radial-gradient(120% 140% at 4% 0%, rgba(255, 255, 255, 0.06) 0%, rgba(255, 255, 255, 0) 58%);
    --header-text: #eef1fb;
    --header-text-muted: rgba(238, 241, 251, 0.76);
    --header-btn-hover: rgba(255, 255, 255, 0.08);
    --header-btn-active: rgba(255, 255, 255, 0.15);
    --header-icon-shadow: rgba(0, 0, 0, 0.45);
    --header-border: rgba(255, 255, 255, 0.07);
    --header-text-shadow: none;
}

/* ===== Reset & Base ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

body {
    font-family: 'Segoe UI Variable', 'Microsoft YaHei UI', 'PingFang SC', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    transition: background var(--transition-base);
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
    width: 4px;
    height: 4px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ===== 数据集加载中遮罩 ===== */
.global-loading {
    position: fixed;
    inset: 0;
    z-index: 4000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    background: color-mix(in srgb, var(--bg-primary) 55%, transparent);
    -webkit-backdrop-filter: blur(3px);
    backdrop-filter: blur(3px);
    transition: opacity var(--transition-fast);
}
.global-loading[hidden] { display: none; }
.loading-spinner {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 3px solid color-mix(in srgb, var(--accent-color) 25%, transparent);
    border-top-color: var(--accent-color);
    animation: loading-spin 0.8s linear infinite;
}
.loading-text {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    background: var(--bg-panel);
    padding: 6px 14px;
    border-radius: 999px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
}
@keyframes loading-spin { to { transform: rotate(360deg); } }

/* ===== Sidebar ===== */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-width);
    /* R96：应用户要求去掉透明/毛玻璃——面板改为完全不透明实心背景
       （R89–R93 的 35% 透明 + backdrop blur 已移除，杜绝面板透出地图造成的观感问题） */
    background: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    z-index: 2000;
    box-shadow: 2px 0 18px rgba(0, 0, 0, 0.12);
    transition: transform var(--transition-base);
    border-radius: 0 var(--radius-xl) var(--radius-xl) 0;
    overflow: hidden;
    container-type: inline-size;
    container-name: sidebar;
}

/* 移动端抽屉为非全屏卡片，保留右侧圆角，圆角处应透出地图（透明） */
@media (max-width: 820px) {
    .sidebar { border-radius: 0 var(--radius-xl) var(--radius-xl) 0; }
}

/* 头部/底部跟随面板右侧圆角，避免渐变与背景溢出直角 */
.sidebar-header {
    border-top-right-radius: var(--radius-xl);
}
.sidebar-footer {
    border-bottom-right-radius: var(--radius-xl);
}

.sidebar-header {
    height: var(--sidebar-header-height);
    /* R168：配色主题化并锚定主题色——亮色为 accent 蓝系渐变（终点即 #4f6ef7）、
       暗色为同色系深靛蓝，均叠一层左上微弱高光增加层次。
       此前（R154）是硬编码 #7aa0f7→#5880f3，暗色主题下会非常突兀。 */
    background-image: var(--header-highlight), var(--header-bg);
    color: var(--header-text);
    /* 暗色下蓝底与深面板色差较小，用一条极淡分隔线明确头部边界（亮色下为 transparent） */
    box-shadow: inset 0 -1px 0 var(--header-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    flex-shrink: 0;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    min-width: 0;
}

.brand-icon {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* 品牌图标：与 favicon 同款（古地图撕边纸片），img 背景透明无固定圆角（防裁剪撕边），
   drop-shadow 投影跟随纸片不规则形状 */
.brand-icon img {
    width: 34px;
    height: 34px;
    display: block;
    filter: drop-shadow(0 2px 6px rgba(79, 110, 247, 0.35));
}

.brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
    min-width: 0;
    overflow: hidden;
}

.brand-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

/* 侧边栏头部内的按钮：跟随标题栏配色变量（蓝底上用白/浅色） */
.sidebar-header-actions .nav-btn {
    width: 36px;
    height: 36px;
    font-size: 15px;
    color: var(--header-text-muted);
    text-shadow: var(--header-text-shadow);
}

.sidebar-header-actions .nav-btn:hover {
    background: var(--header-btn-hover);
    color: var(--header-text);
}

.sidebar-header-actions .nav-btn.active {
    background: var(--header-btn-active);
    color: var(--header-text);
}

/* 侧边栏头部品牌文字跟随标题栏前景色（蓝底上为白色 + 极轻投影） */
.sidebar-header .brand-title {
    color: var(--header-text);
    text-shadow: var(--header-text-shadow);
}

.sidebar-header .brand-icon img {
    filter: drop-shadow(0 2px 6px var(--header-icon-shadow));
}

.nav-btn {
    position: relative;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--text-secondary);
    font-size: 16px;
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.nav-btn.active {
    background: var(--accent-light);
    color: var(--accent-color);
}

/* ===== Sidebar Body / Footer ===== */
.sidebar-body {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: transparent;
}

.sidebar-footer {
    height: 44px;
    flex-shrink: 0;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 0 12px;
    background: transparent;
}

/* 关于：底部轻量胶囊（ghost）按钮，信息图标染主题色，hover 浅蓝底，与面板整体风格协调 */
.sidebar-footer-btn {
    height: 30px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 0 12px;
    border: none;
    border-radius: 999px;
    background: transparent;
    color: var(--text-secondary);
    font: inherit;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: background var(--transition-fast), color var(--transition-fast);
}

.sidebar-footer-btn i {
    font-size: 12.5px;
    color: var(--accent-color);
    opacity: 0.92;
}

.sidebar-footer-btn:hover {
    background: var(--accent-light);
    color: var(--accent-color);
}

.sidebar-footer-btn:active {
    transform: scale(0.97);
}

.sidebar-footer-version {
    margin-left: auto;
    flex-shrink: 0;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    font-size: 10.5px;
    color: var(--text-muted);
    letter-spacing: 0.02em;
    user-select: none;
}

/* R86：侧边栏宽度拖拽调节手柄（桌面端，右缘） */
/* 侧边栏宽度拖拽调节手柄（R88：移出 sidebar，避免被圆角 overflow 裁剪）。
   固定于侧边栏右缘：left 对齐 --sidebar-width，再左移 3px 使手柄跨在边缘上。 */
.sidebar-resizer {
    position: fixed;
    top: 0;
    left: var(--sidebar-width);
    transform: translateX(-3px);
    width: 9px;
    height: 100%;
    cursor: col-resize;
    z-index: 2001;
    background: transparent;
    transition: background var(--transition-fast);
    touch-action: none;
}

/* 侧边栏折叠（桌面端滑出视口）或移动端抽屉时隐藏拖拽手柄 */
.sidebar--collapsed ~ .sidebar-resizer { display: none; }
@media (max-width: 820px) {
    .sidebar-resizer { display: none; }
}

.sidebar-resizer::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 2px;
    height: 40px;
    border-radius: 2px;
    background: var(--border-color);
    opacity: 0;
    transition: opacity var(--transition-fast), background var(--transition-fast);
}

.sidebar-resizer:hover::after,
.sidebar-resizer:active::after {
    opacity: 1;
    background: var(--accent-color);
}

/* 拖拽中：临时关闭侧边栏/地图过渡，避免跟手卡顿 */
body.resizing .sidebar,
body.resizing .map-area {
    transition: none !important;
}
