/**
 * 宏基因组层级分类结构可视化平台 - 样式文件
 * Version: 3.0 - 统一设计系统
 */

/* ========== CSS 变量 - 简洁设计系统 ========== */
:root {
    --page-zoom-scale: 1;
    /* 主色调 - 提升为更明亮温和的蓝灰色 */
    --primary-color: #6b7fa8;
    --primary-dark: #5a6d8f;
    --primary-light: #98a8c4;
    --secondary-color: #6674db;
    --secondary-dark: #5563c9;
    
    /* 状态颜色 - 适度饱和 */
    --success-color: #52c785;
    --success-dark: #42b573;
    --danger-color: #f76b6b;
    --danger-dark: #e85555;
    --info-color: #4fa8eb;
    --info-dark: #3d93d9;
    
    /* 中性色 - 更深的灰度 */
    --text-primary: #1a202c;
    --text-secondary: #4a5568;
    --text-light: #718096;
    --border-color: #e2e8f0;
    --border-light: #edf2f7;
    --bg-white: #ffffff;
    --bg-light: #f7fafc;
    --bg-lighter: #fafbfd;
    --bg-body: #f0f4f8;
    
    /* 渐变 - 更明亮柔和的渐变 */
    --gradient-primary: linear-gradient(135deg, #6b7fa8 0%, #5a6d8f 100%);
    --gradient-primary-hover: linear-gradient(135deg, #5a6d8f 0%, #4d5e7a 100%);
    --gradient-success: linear-gradient(135deg, #52c785 0%, #42b573 100%);
    --gradient-info: linear-gradient(135deg, #4fa8eb 0%, #3d93d9 100%);
    --gradient-danger: linear-gradient(135deg, #f76b6b 0%, #e85555 100%);
    --gradient-bg: linear-gradient(135deg, #f7fafc 0%, #edf2f7 100%);
    --gradient-accent: linear-gradient(135deg, #7687ed 0%, #6674db 100%);

    /* Tree panel specific */
    --tree-panel-bg: #fafbfd;
    --tree-panel-bg-alt: #f5f7fa;
    --tree-panel-border: #dfe4ee;
    --tree-panel-hover-border: #d0d7e6;
    --tree-panel-header-start: #6b7fa8;
    --tree-panel-header-end: #6674db;
    --tree-panel-header-text: #ffffff;
    --tree-label-default-color: #4a5568;
    --sidebar-activity-bg: var(--bg-light);
    --sidebar-activity-border: var(--border-color);
    --sidebar-activity-icon: var(--text-secondary);
    --sidebar-activity-icon-active: var(--primary-dark);
    --sidebar-activity-indicator: var(--secondary-color);
    --sidebar-activity-hover-bg: var(--bg-lighter);
    --sidebar-activity-active-bg: var(--bg-white);
    --sidebar-activity-active-ring: var(--secondary-color);

    /* Scrollbars */
    --scrollbar-track: transparent;
    --scrollbar-thumb: rgba(152, 168, 196, 0.2);
    --scrollbar-thumb-hover: rgba(107, 127, 168, 0.8);
    --scrollbar-panel-track: #f1f3f5;
    --scrollbar-panel-thumb: var(--gradient-primary);
    --scrollbar-panel-thumb-hover: var(--gradient-primary-hover);
    --scrollbar-soft-thumb: rgba(152, 168, 196, 0.28);
    --scrollbar-soft-thumb-hover: rgba(107, 127, 168, 0.75);
    --scrollbar-soft-color: rgba(152, 168, 196, 0.35);

    /* Range slider */
    --range-track-color: var(--border-color);
    --range-track-color-hover: var(--text-light);
    --range-track-fill: var(--primary-dark);
    --range-thumb-color: var(--bg-white);
    --range-thumb-border: var(--primary-dark);
    
    /* 间距系统 */
    --spacing-xs: 3px;
    --spacing-sm: 7px;
    --spacing-md: 10px;
    --spacing-lg: 14px;
    --spacing-xl: 18px;
    --spacing-2xl: 21px;
    --spacing-3xl: 26px;
    
    /* 圆角 - 更小更简洁 */
    --radius-sm: 3px;
    --radius-md: 3px;
    --radius-lg: 5px;
    --radius-xl: 7px;
    --radius-2xl: 9px;
    
    /* 阴影 - 更微妙 */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 2px 4px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 4px 8px rgba(0, 0, 0, 0.08);
    --shadow-xl: 0 8px 16px rgba(0, 0, 0, 0.1);
    --shadow-primary: 0 4px 8px rgba(107, 127, 168, 0.18);
    --shadow-success: 0 4px 8px rgba(82, 199, 133, 0.22);
    
    /* 字体大小 */
    --font-xs: 10px;
    --font-sm: 11px;
    --font-base: 12px;
    --font-md: 12px;
    --font-lg: 13px;
    --font-xl: 14px;
    --font-2xl: 15px;
    --font-3xl: 16px;
    --font-4xl: 18px;
    --font-5xl: 22px;
    
    /* 过渡动画 */
    --transition-fast: all 0.2s ease;
    --transition-base: all 0.3s ease;

    /* Layout defaults */
    --matrix-cell-min-width: clamp(110px, 16vw, 200px);
    --matrix-cell-min-height: clamp(125px, 18vw, 215px);

    /* 新增：面板最小高度和 SVG 默认高度，方便统一调整 */
    --panel-min-height: 380px;       /* 面板最小高度（可按需调整） */
    --panel-svg-height: 470px;       /* SVG 面板默认高度（可按需调整） */
}

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

/* ========== 全局滚动条美化 ========== */
::-webkit-scrollbar {
    width: 9px;
    height: 9px;
}

::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
}

::-webkit-scrollbar-thumb {
    background-color: var(--scrollbar-thumb);
    border-radius: 4px;
    border: 2px solid transparent;
    background-clip: content-box;
}

::-webkit-scrollbar-thumb:hover {
    background-color: var(--scrollbar-thumb-hover);
}

html, body {
    height: 100%;
}

body {
    /* zoom: 0.9; */ /*! 使用缩放会影响所有元素的尺寸计算 */
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-body);
    min-height: calc(100vh / var(--page-zoom-scale));
    padding: var(--spacing-xl);
    font-size: var(--font-md);
    color: var(--text-primary);
    line-height: 1.6;
}

body.info-modal-open {
    overflow: hidden;
}


.container {
    max-width: 100%;
    margin: 0 auto;
    background: var(--bg-white);
    border: var(--app-frame-border, none);
    border-radius: var(--radius-xl);
    box-shadow: var(--app-frame-shadow, var(--shadow-lg));
    overflow: hidden; /* keep scrolling inside app-body panes */
    display: flex;
    flex-direction: column;
    height: calc((100vh - (var(--spacing-xl) * 2)) / var(--page-zoom-scale)); /* compensate CSS zoom */
    min-height: 0;
}

/* ========== 主体两栏布局（左侧控制栏 + 右侧可视区） ========== */
.app-body {
    display: flex;
    gap: 0; /* move gutter to main-content padding-left so its area captures scroll */
    padding: var(--spacing-xl);
    flex: 1 1 auto;       /* layout grows with content */
    min-height: 0;
    overflow: hidden;     /* each pane handles its own scrolling */
}

.sidebar {
    width: 330px;
    min-width: 240px;
    max-width: 460px;
    display: flex;
    flex-direction: row;
    align-items: stretch;
    gap: 0;
    border-right: 2px solid var(--border-color);
    box-shadow: 1px 0 0 rgba(0,0,0,0.03);
    background: linear-gradient(180deg, var(--bg-lighter) 0%, var(--bg-light) 100%);
    padding-right: 0;
    overflow: hidden;
    position: relative;
    height: 100%;
    min-height: 0;
    z-index: 2; /* ensure above main if any overlap occurs */
    resize: horizontal; /* allow users to widen the sidebar if needed */
    /* 在侧边栏局部覆盖字体变量，使侧边栏整体字体比全局小一号（每个字号都减 1px） */
    --font-xs: 9px;
    --font-sm: 10px;
    --font-base: 11px;
    --font-md: 12px;
    --font-lg: 13px;
    --font-xl: 14px;
    --font-2xl: 15px;
    --font-3xl: 17px;
    --font-4xl: 20px;
    --font-5xl: 24px;
}

.sidebar-activity-bar {
    display: flex;
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: stretch;
    width: 58px;
    min-width: 58px;
    gap: 6px;
    padding: var(--spacing-md) 7px;
    background: linear-gradient(180deg, var(--sidebar-activity-bg) 0%, var(--bg-body) 100%);
    border-right: 1px solid var(--sidebar-activity-border);
    border-radius: 0;
    box-shadow: inset -1px 0 0 color-mix(in srgb, var(--primary-dark) 8%, transparent);
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0;
}

.sidebar-activity-btn {
    width: 100%;
    min-height: 96px;
    border: 1px solid color-mix(in srgb, var(--sidebar-activity-border) 65%, transparent);
    border-radius: var(--radius-md);
    background: color-mix(in srgb, var(--bg-white) 58%, transparent);
    color: var(--sidebar-activity-icon);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    padding: 10px 0 12px;
    font-size: var(--font-base);
    font-weight: 600;
    line-height: 1;
    position: relative;
    overflow: hidden;
    cursor: pointer;
    transition: background-color 0.18s ease, color 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}

.sidebar-activity-btn::before {
    content: "";
    position: absolute;
    left: 0;
    top: 8px;
    bottom: 8px;
    width: 3px;
    border-radius: 2px;
    background: transparent;
    transition: background-color 0.18s ease;
}

.sidebar-activity-btn svg {
    width: 17px;
    height: 17px;
    flex-shrink: 0;
    transform: none;
}

.sidebar-activity-btn span {
    display: inline-block;
    transform: none;
    white-space: nowrap;
    font-size: 12px;
    line-height: 1;
    margin: 0;
    writing-mode: vertical-rl;
    text-orientation: mixed;
}

.sidebar-activity-btn:hover {
    color: var(--text-primary);
    background: var(--bg-white);
    border-color: var(--primary-light);
    box-shadow: 0 1px 6px color-mix(in srgb, var(--primary-dark) 14%, transparent);
    transform: translateX(1px);
}

.sidebar-activity-btn.active {
    color: var(--sidebar-activity-icon-active);
    background: linear-gradient(180deg, var(--sidebar-activity-active-bg) 0%, var(--bg-light) 100%);
    border-color: var(--sidebar-activity-active-ring);
    box-shadow: inset 0 0 0 1px var(--sidebar-activity-active-ring), 0 2px 8px color-mix(in srgb, var(--sidebar-activity-active-ring) 22%, transparent);
}

.sidebar-activity-btn.active::before {
    background: var(--sidebar-activity-indicator);
}

.sidebar-activity-btn:focus-visible {
    outline: 2px solid var(--secondary-color);
    outline-offset: 1px;
}

.sidebar-sections {
    flex: 1 1 auto;
    height: 100%;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xl);
    padding: 0 var(--spacing-xs) var(--spacing-md) var(--spacing-xs);
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.sidebar-sections .sidebar-nav-panel {
    display: none;
    flex: 0 0 auto; /* prevent panel from shrinking and clipping expanded content */
}

.sidebar-sections .sidebar-nav-panel.is-active {
    display: flex;
}

.sidebar-toggle {
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 1px solid color-mix(in srgb, var(--primary-color) 40%, transparent);
    border-radius: var(--radius-lg);
    background: var(--bg-white);
    color: var(--primary-dark);
    box-shadow: var(--shadow-md);
    cursor: pointer;
    transition: var(--transition-base);
}

.sidebar-toggle-inline {
    margin-top: auto;
    align-self: center;
    margin-bottom: var(--spacing-sm);
    flex: 0 0 auto;
}

.sidebar-toggle-collapsed {
    align-self: flex-start;
    margin: var(--spacing-xl) var(--spacing-xs) 0 var(--spacing-xs);
    display: none;
}

.sidebar-toggle:hover {
    background: var(--bg-light);
    color: var(--text-primary);
    border-color: var(--primary-light);
    box-shadow: var(--shadow-lg);
}

.sidebar-toggle:focus-visible {
    outline: 2px solid var(--secondary-color);
    outline-offset: 2px;
}

.sidebar-toggle .toggle-icon {
    display: inline-block;
    font-size: 18px;
    line-height: 1;
    transition: transform 0.25s ease;
}

.app-body.sidebar-collapsed .sidebar {
    display: none;
}

.app-body.sidebar-collapsed .sidebar-toggle-collapsed {
    display: inline-flex;
}

.app-body:not(.sidebar-collapsed) .sidebar-toggle-collapsed {
    display: none;
}

.app-body.sidebar-collapsed .sidebar-toggle .toggle-icon {
    transform: rotate(180deg);
}

.app-body.sidebar-collapsed .sidebar-toggle-collapsed {
    width: 44px;
    height: 44px;
    padding: 0;
    border-color: var(--secondary-color);
    background: var(--gradient-accent);
    color: #ffffff;
    box-shadow: 0 8px 18px color-mix(in srgb, var(--secondary-color) 32%, transparent);
}

.app-body.sidebar-collapsed .main-content {
    padding-left: var(--spacing-sm);
}

@keyframes sidebarHintPulse {
    0%, 100% {
        box-shadow:
            inset -1px 0 0 color-mix(in srgb, var(--primary-dark) 8%, transparent),
            inset 0 0 0 0 color-mix(in srgb, var(--secondary-color) 0%, transparent);
        background: linear-gradient(180deg, var(--sidebar-activity-bg) 0%, var(--bg-body) 100%);
    }
    50% {
        box-shadow:
            inset -1px 0 0 color-mix(in srgb, var(--primary-dark) 8%, transparent),
            inset 0 0 0 2px color-mix(in srgb, var(--secondary-color) 62%, transparent);
        background: linear-gradient(
            180deg,
            color-mix(in srgb, var(--sidebar-activity-bg) 80%, var(--secondary-color) 20%) 0%,
            color-mix(in srgb, var(--bg-body) 90%, var(--secondary-color) 10%) 100%
        );
    }
}

@keyframes sidebarToggleHintPulse {
    0%, 100% {
        box-shadow: 0 8px 18px color-mix(in srgb, var(--secondary-color) 32%, transparent);
    }
    50% {
        box-shadow: 0 10px 24px color-mix(in srgb, var(--secondary-color) 40%, transparent), 0 0 0 7px color-mix(in srgb, var(--secondary-color) 18%, transparent);
    }
}

@keyframes sidebarHintActiveButtonPulse {
    0%, 100% {
        transform: scale(1);
        box-shadow: inset 0 0 0 1px var(--sidebar-activity-active-ring), 0 2px 8px color-mix(in srgb, var(--sidebar-activity-active-ring) 22%, transparent);
    }
    50% {
        transform: scale(1.05);
        box-shadow:
            inset 0 0 0 1px var(--sidebar-activity-active-ring),
            0 8px 16px color-mix(in srgb, var(--sidebar-activity-active-ring) 32%, transparent),
            0 0 0 2px color-mix(in srgb, var(--sidebar-activity-active-ring) 45%, transparent);
    }
}

.sidebar-activity-bar.nav-attention {
    animation: sidebarHintPulse 1.05s ease-in-out infinite;
}

.sidebar-activity-bar.nav-attention .sidebar-activity-btn.active {
    animation: sidebarHintActiveButtonPulse 1.05s ease-in-out infinite;
}

.app-body.sidebar-collapsed .sidebar-toggle-collapsed.nav-attention {
    animation: sidebarToggleHintPulse 1.05s ease-in-out infinite;
}

/* A visible, non-interactive gutter to emphasize the boundary between panels */
/* removed gutter overlay to avoid overlapping the scroll hit area */

.main-content {
    flex: 1 1 auto;
    min-width: 0; /* allow grid to shrink */
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-xl);
    padding-right: var(--spacing-sm);
    padding-left: var(--spacing-sm); /* tighter gutter to reduce dead space between sidebar and panels */
    position: relative;
    height: 100%;
    z-index: 1;
    overflow-y: auto;     /* scroll only right side content */
}

.header {
    background: var(--app-header-bg, var(--gradient-primary));
    color: var(--app-header-text, #ffffff);
    padding: var(--spacing-sm) var(--spacing-lg);
    text-align: left;
    border-bottom: var(--app-header-border, none);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    position: relative;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    grid-template-areas:
        ". title links"
        "subtitle subtitle subtitle";
    align-items: center;
    column-gap: var(--spacing-md);
    row-gap: 1px;
}

/* Title row: keep paragraph centered but place icon next to H1 in a horizontal row */
.header .title-row {
    grid-area: title;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-width: 0;
    justify-self: center;
}

.header .title-row .title-link {
    display: flex;
    align-items: center;
    gap: 8px;
    color: inherit;
    text-decoration: none;
}

.header .title-row .title-link:hover,
.header .title-row .title-link:focus-visible {
    opacity: 0.95;
    text-decoration: none;
}

.header .title-row .title-link:focus {
    outline: 2px dashed var(--app-header-outline, rgba(255, 255, 255, 0.6));
    outline-offset: 4px;
}

.site-icon {
    width: 24px;
    height: 24px;
    display: inline-block;
    object-fit: contain;
}

.header h1 {
    font-size: var(--font-4xl);
    margin-bottom: 0;
    font-weight: 600;
    letter-spacing: -0.5px;
    line-height: 1.05;
}

.header-version-label {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 1px 3px;
    font-size: var(--font-sm);
    font-weight: 500;
    line-height: 1.2;
    color: var(--app-header-link-color, var(--app-header-text, #ffffff));
    opacity: 0.82;
    white-space: nowrap;
}

.header-version-text {
    opacity: 0.9;
}

.subtitle-version-label {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
}

.header p {
    grid-area: subtitle;
    font-size: var(--font-md);
    opacity: 0.95;
    font-weight: 400;
    margin: 0;
    text-align: center;
    position: relative;
}

.header-subtitle-text {
    display: block;
    white-space: nowrap;
    padding-right: 88px;
    padding-left: 88px;
}

.header-links {
    grid-area: links;
    position: static;
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    justify-self: end;
    align-self: center;
}

.header-links a,
.header-links .header-link-button {
    color: var(--app-header-link-color, var(--app-header-text, #ffffff));
    text-decoration: none;
    font-size: var(--font-md);
    font-weight: 600;
    line-height: 1.2;
    padding: 1px 3px;
    border: none;
    border-radius: 0;
    background: transparent;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: var(--transition-fast);
}

.header-links .header-link-button {
    font-family: inherit;
    line-height: 1.2;
    cursor: pointer;
}

.header-links a:hover,
.header-links a:focus-visible,
.header-links .header-link-button:hover,
.header-links .header-link-button:focus-visible {
    background: transparent;
    text-decoration: underline;
}

.header-links a:focus-visible,
.header-links .header-link-button:focus-visible {
    outline: 2px solid var(--app-header-outline, rgba(255, 255, 255, 0.7));
    outline-offset: 2px;
}

.header-link-icon {
    width: 13px;
    height: 13px;
    flex-shrink: 0;
}

.about-section {
    margin: var(--spacing-lg) var(--spacing-lg) var(--spacing-md);
    padding: var(--spacing-md) var(--spacing-xl);
    background: var(--bg-lighter);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    text-align: center;
}

.about-content {
    max-width: 960px;
    margin: 0 auto;
}

.about-text {
    margin: 0;
    font-size: var(--font-base);
    color: var(--text-secondary);
    text-align: center;
}

.about-text strong {
    color: var(--text-primary);
}

.about-inline-link {
    margin-left: var(--spacing-xs);
    color: var(--secondary-color);
    font-weight: 600;
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: var(--transition-fast);
}

.about-inline-link:hover,
.about-inline-link:focus-visible {
    color: var(--secondary-dark);
    border-bottom-color: currentColor;
}


.control-panel {
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing-lg);
    padding: var(--spacing-xl) 22px;
    background: var(--bg-white);
    border-bottom: none;
    align-items: flex-start;
}

/* Ensure the panel title and each control-row occupy a full row inside .control-panel
   so controls align to the left and avoid large empty gutters. */
.control-panel > .panel-title,
.control-panel > .control-row {
    flex: 1 1 100%;
}

/* Ensure the comparison-controls wrapper spans full row like control-row */
.control-panel > .comparison-controls {
    flex: 1 1 100%;
}

/* Collapsible control-panel: hide rows when collapsed to save vertical space */
.control-panel.collapsed .control-row,
.control-panel.collapsed .sample-selection-panel,
.control-panel.collapsed .comparison-controls {
    display: none;
}

.control-panel.collapsed > :not(.panel-title) {
    display: none;
}

/* Ensure the toggle button in panel title aligns visually */
.panel-title .toggle-btn {
    margin-left: var(--spacing-md);
    padding: var(--spacing-sm) 9px;
}

/* Theme panel */
.theme-panel-body {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-lg);
    margin-top: var(--spacing-lg);
}

.control-panel.collapsed .theme-panel-body {
    display: none;
}

.theme-zoom-card {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-light);
    padding: var(--spacing-md);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.theme-zoom-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--spacing-sm);
}

.theme-zoom-row label {
    font-size: var(--font-sm);
    font-weight: 600;
    color: var(--text-secondary);
}

.theme-zoom-value {
    min-width: 42px;
    text-align: right;
    font-weight: 600;
    color: var(--text-primary);
}

.theme-zoom-controls {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.theme-zoom-controls input[type="range"] {
    flex: 1;
    min-width: 0;
}

.theme-preset-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--spacing-md);
}

@media (max-width: 640px) {
    .theme-preset-list {
        grid-template-columns: 1fr;
    }
}

.theme-chip {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
    padding: var(--spacing-md);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    background: var(--bg-light);
    cursor: pointer;
    transition: var(--transition-base);
    text-align: left;
}

.theme-chip:hover {
    border-color: var(--primary-color);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
}

.theme-chip.active {
    border-color: var(--primary-color);
    box-shadow: inset 0 0 0 1px var(--primary-color);
    background: var(--bg-white);
}

.theme-chip-name {
    font-weight: 600;
    font-size: var(--font-md);
    color: var(--text-primary);
}

.theme-chip-desc {
    font-size: var(--font-sm);
    color: var(--text-light);
}

.theme-chip-swatches {
    display: flex;
    gap: 4px;
}

.theme-chip-swatch {
    flex: 1;
    height: 6px;
    border-radius: 999px;
}

.custom-theme-card {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: var(--spacing-lg);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-lg);
    background: var(--bg-light);
}

.custom-theme-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    color: var(--text-secondary);
}

.custom-theme-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--spacing-md);
}

@media (max-width: 640px) {
    .custom-theme-grid {
        grid-template-columns: 1fr;
    }
}

.custom-theme-field {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm) var(--spacing-md);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    background: var(--bg-white);
    font-size: var(--font-sm);
    color: var(--text-secondary);
}

.custom-theme-field span {
    flex: 1;
    min-width: 0;
}

.custom-theme-field input[type="color"] {
    width: 40px;
    height: 25px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-white);
    cursor: pointer;
    padding: 0;
}

.custom-theme-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing-md);
    justify-content: flex-end;
}

.zero-color-control {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.zero-color-control label {
    margin: 0;
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.zero-color-input {
    width: 43px;
    height: 27px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    padding: 0;
}

.zero-color-input.disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

/* Modal overlay for expanded comparison view */
.comparison-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
}

.comparison-modal-content {
    width: 90%;
    height: 90%;
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.comparison-modal-header {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    padding: 10px 14px;
    border-bottom: var(--comparison-modal-header-border, 1px solid var(--border-light));
    background: var(--comparison-modal-header-bg, var(--bg-light));
    color: var(--comparison-modal-header-text, inherit);
    position: relative;
}

/* Modal header actions (export icons + close) */
.comparison-modal-header .modal-actions {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.comparison-modal-header .btn-icon {
    width: 28px;
    height: 28px;
    background: transparent;
    color: var(--comparison-modal-header-icon, var(--text-secondary));
    border: none;
    box-shadow: none;
    transition: color 0.15s ease, background 0.15s ease;
}

.comparison-modal-header .btn-icon:hover {
    color: var(--comparison-modal-header-icon-hover, var(--text-primary));
    background: var(--comparison-modal-header-icon-bg-hover, rgba(0, 0, 0, 0.06));
}

.modal-title {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    font-weight: 700;
    font-size: var(--font-lg);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: calc(100% - 120px);
}

.comparison-modal-body {
    flex: 1 1 auto;
    padding: 10px;
    overflow: auto;
    display: flex;            /* ensure inner wrapper can flex and be constrained */
    flex-direction: column;
    min-height: 0;            /* allow children to shrink below content height (fixes inner scrollbar placement) */
}

/* Wrapper for comparison results table inside modal. Make it the scrolling container
   so horizontal scrollbar remains visible without having to scroll the outer modal. */
.comparison-results-table-wrapper {
    flex: 1 1 auto;
    min-height: 0;           /* important for flex children to respect container height */
    overflow: auto;          /* allow both horizontal and vertical scroll inside wrapper */
    padding: 6px;
}

/* Allow wide tables to determine their own width while still supporting a minimum
   fill of the wrapper width. This makes horizontal scrolling appear on the wrapper. */
.comparison-results-table-wrapper table.info-sample-table {
    width: max-content;
    min-width: 100%;
}

.comparison-modal-close {
    margin-left: auto;
    background: var(--text-primary);
    color: var(--bg-white);
    border: none;
    font-size: var(--font-md);
    cursor: pointer;
    padding: var(--spacing-sm) 10px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    transition: var(--transition-fast);
    font-weight: 600;
}

.comparison-modal-close:hover {
    background: #000;
    transform: translateY(-1px);
    box-shadow: var(--shadow-lg);
}


/* 卡片式面板 */
.card-panel {
    background: linear-gradient(135deg, var(--bg-lighter) 0%, var(--bg-light) 100%);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 0;
    margin-bottom: 0;
    transition: var(--transition-base);
    overflow: hidden;
}

.card-panel:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--primary-light);
    background: linear-gradient(135deg, var(--bg-white) 0%, var(--bg-lighter) 100%);
}

.panel-title {
    font-weight: 600;
    font-size: var(--font-xl);
    color: var(--text-primary);
    padding: var(--spacing-md) var(--spacing-lg);
    background: linear-gradient(135deg, var(--bg-light) 0%, var(--bg-lighter) 100%);
    border-bottom: 1px solid var(--border-color);
    margin: 0;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--spacing-md);
}

.panel-title::after {
    display: none;
}

.control-row {
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing-lg);
    padding: var(--spacing-md) var(--spacing-lg);
    align-items: center;
    border-bottom: 1px solid var(--border-light);
    transition: var(--transition-fast);
}

.control-row:last-child {
    border-bottom: none;
}

.control-row.no-divider {
    border-bottom: none;
}

.control-row:hover {
    background-color: transparent;
}



/* 分组显示区域 */
.group-display {
    margin: 10px 0;
    padding: 12px;
    background: #f8f9fa;
    border: 1px solid #e8ebf0;
    border-radius: 8px;
    max-height: 180px;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 8px;
    width: 100%;
    box-sizing: border-box;
}

.group-display > div {
    padding: 8px 12px;
    background: linear-gradient(135deg, #fafbfd 0%, #f8f9fb 100%);
    border-radius: 6px;
    font-size: 13px;
    border: 1px solid #e0e6ed;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    transition: all 0.2s ease;
}

.group-display > div:hover {
    border-color: var(--text-secondary);
    box-shadow: var(--shadow-sm);
    transform: none;
    background: linear-gradient(135deg, #ffffff 0%, #fafbfd 100%);
}


.full-width {
    flex: 1 1 100%;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap; /* allow controls to wrap within sidebar width */
}

.control-group.vertical {
    flex-direction: column;
    align-items: flex-start;
}

.layout-size-group {
    width: 100%;
    align-items: stretch;
    gap: 6px;
}

.layout-size-inline {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap;
    width: 100%;
}

.layout-size-inline .layout-size-slider {
    flex: 1 1 auto;
    min-width: 120px;
    width: auto;
}

.layout-size-inline input[type="number"] {
    flex: 0 0 70px;
}

/* Prevent sidebar content from bleeding horizontally; enable scroll for wide inner blocks */
.sidebar .control-row,
.sidebar .collapsible-content,
.sidebar .group-display,
.sidebar #color-previews-wrapper,
.sidebar #custom-color-controls,
.sidebar #sample-selection-panel {
    max-width: 100%;
    overflow-x: auto;
}

/* Inputs/selects should not overflow the sidebar */
.sidebar input[type="number"],
.sidebar input[type="text"],
.sidebar select {
    max-width: 100%;
}

/* Ensure custom color controls behave inside sidebar when shown */
#custom-color-controls.flex {
    /* display is controlled by JS (setColorScheme). Do not override here. */
    flex-wrap: wrap;
    align-items: center;
    gap: var(--spacing-sm);
}

#custom-color-controls input[type="color"] {
    width: 44px;
    height: 28px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 2px;
    box-shadow: var(--shadow-sm);
    cursor: pointer;
}

#custom-color-controls input[type="color"]:hover {
    border-color: var(--primary-color);
    box-shadow: var(--shadow-md);
}

#custom-color-controls label,
#custom-color-controls select,
#custom-color-controls button,
#custom-color-controls span {
    max-width: 100%;
}

.control-group label {
    font-weight: 500;
    /* color: var(--text-primary); */
    font-size: var(--font-md);
}

/* ========== 统一表单元素样式 ========== */
select {
    padding: 8px var(--spacing-md);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: var(--font-md);
    background: var(--bg-white);
    cursor: pointer;
    transition: var(--transition-fast);
    box-shadow: var(--shadow-sm);
    font-weight: 500;
    color: var(--text-primary);
}

select:hover {
    border-color: var(--primary-color);
    box-shadow: var(--shadow-md);
}

select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(74, 85, 104, 0.1);
}

input[type="range"] {
    width: 100px;
    height: 16px;
    margin: 0 var(--spacing-sm);
    cursor: pointer;
    accent-color: var(--range-track-fill);
    background: transparent;
    -webkit-appearance: none;
    appearance: none;
    --range-progress: 50%;
}

input[type="range"]::-webkit-slider-runnable-track {
    height: 6px;
    border-radius: 999px;
    background: linear-gradient(
        to right,
        var(--range-track-fill) 0%,
        var(--range-track-fill) var(--range-progress),
        var(--range-track-color) var(--range-progress),
        var(--range-track-color) 100%
    );
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--range-thumb-color);
    border: 2px solid var(--range-thumb-border);
    box-shadow: var(--shadow-sm);
    margin-top: -4px;
}

input[type="range"]:hover::-webkit-slider-runnable-track {
    background: linear-gradient(
        to right,
        var(--range-track-fill) 0%,
        var(--range-track-fill) var(--range-progress),
        var(--range-track-color-hover) var(--range-progress),
        var(--range-track-color-hover) 100%
    );
}

input[type="range"]::-moz-range-track {
    height: 6px;
    border: none;
    border-radius: 999px;
    background: var(--range-track-color);
}

input[type="range"]::-moz-range-progress {
    height: 6px;
    border-radius: 999px;
    background: var(--range-track-fill);
}

input[type="range"]::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--range-thumb-color);
    border: 2px solid var(--range-thumb-border);
    box-shadow: var(--shadow-sm);
}

input[type="range"]:hover::-moz-range-track {
    background: var(--range-track-color-hover);
}

input[type="checkbox"] {
    width: 14px;
    height: 14px;
    cursor: pointer;
    margin-right: var(--spacing-sm);
    accent-color: var(--primary-color);
}

input[type="number"],
input[type="text"] {
    padding: 7px 9px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: var(--font-base);
    transition: var(--transition-fast);
    box-shadow: var(--shadow-sm);
    color: var(--text-primary);
}

input[type="number"] {
    width: 56px;
}

input[type="number"]:focus,
input[type="text"]:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(74, 85, 104, 0.1);
}

.control-group span[id$="-value"] {
    display: inline-block;
    min-width: 40px;
    font-weight: 600;
    color: var(--primary-color);
    font-size: var(--font-sm);
}

input[type="file"] {
    display: none;
}

.file-upload-label {
    background: var(--gradient-primary);
    color: white;
    padding: 10px var(--spacing-xl);
    border-radius: var(--radius-lg);
    cursor: pointer;
    font-weight: 600;
    transition: var(--transition-base);
    display: inline-block;
    font-size: var(--font-md);
    box-shadow: var(--shadow-md);
}

.file-upload-label:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-primary);
    background: var(--gradient-primary-hover);
}

/* ========== 统一按钮样式 ========== */
button {
    padding: 8px 14px;
    border: none;
    border-radius: var(--radius-md);
    font-size: var(--font-base);
    background: var(--gradient-primary);
    color: white;
    cursor: pointer;
    transition: var(--transition-fast);
    font-weight: 600;
    box-shadow: var(--shadow-sm);
    font-family: inherit;
}

button:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-primary);
    background: var(--gradient-primary-hover);
}

button:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(74, 85, 104, 0.15);
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.btn-secondary {
    background: var(--bg-white);
    color: var(--primary-color);
    border: 2px solid var(--primary-color);
}

.btn-secondary:hover {
    background: var(--primary-color);
    color: white;
    box-shadow: var(--shadow-primary);
}

/* De-emphasize reset utility action compared with primary upload actions */
#load-example {
    padding: 6px 10px;
    font-size: var(--font-sm);
    font-weight: 500;
    border-width: 1px;
    color: var(--text-secondary);
    border-color: #c9d2df;
    background: transparent;
    box-shadow: none;
}

#load-example:hover:not(:disabled) {
    transform: none;
    box-shadow: none;
    background: #f8fafc;
    color: var(--text-primary);
    border-color: #b0bccd;
}

#load-example:disabled {
    opacity: 0.75;
    background: #f8fafc;
    color: var(--text-light);
    border-color: #d8e0eb;
}

/* ========== 帮助图标 ========== */
.help-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    color: var(--text-light);
    cursor: help;
    margin-left: var(--spacing-xs);
    transition: var(--transition-fast);
}

.help-icon:hover {
    color: var(--text-secondary);
}

.label-with-help {
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-sm);
    flex-wrap: wrap;
}

.info-icon-btn {
    border: 1px solid rgba(102, 116, 219, 0.22);
    background: linear-gradient(135deg, #f4f7ff 0%, #eef2ff 100%);
    padding: 4px 10px 4px 8px;
    min-height: 26px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    color: var(--secondary-dark);
    cursor: pointer;
    border-radius: 999px;
    transition: var(--transition-fast);
    box-shadow: 0 1px 3px rgba(90, 109, 143, 0.12);
    font-size: var(--font-sm);
    font-weight: 600;
    line-height: 1;
}

.info-icon-btn:hover,
.info-icon-btn:focus-visible {
    color: var(--secondary-dark);
    border-color: rgba(102, 116, 219, 0.42);
    background: linear-gradient(135deg, #edf2ff 0%, #e5ebff 100%);
    box-shadow: 0 4px 10px rgba(102, 116, 219, 0.18);
    transform: translateY(-1px);
    outline: none;
}

.info-icon-btn svg {
    pointer-events: none;
    flex-shrink: 0;
}

.info-icon-btn__text {
    white-space: nowrap;
}

.info-modal {
    position: fixed;
    inset: 0;
    z-index: 1600;
    display: none;
    align-items: center;
    justify-content: center;
}

.info-modal.is-visible {
    display: flex;
}

.info-modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
}

.info-modal-content {
    position: relative;
    z-index: 1;
    background: var(--bg-white);
    border-radius: var(--radius-2xl);
    box-shadow: 0 18px 40px rgba(15, 23, 42, 0.2);
    width: min(680px, 94vw);
    max-height: 85vh;
    padding: var(--spacing-2xl);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-lg);
}

.info-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--spacing-md);
}

.info-modal-header h3 {
    margin: 0;
    font-size: var(--font-2xl);
}

.info-modal-close {
    border: none;
    background: transparent;
    font-size: 26px;
    line-height: 1;
    color: var(--text-light);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius-md);
    transition: var(--transition-fast);
}

.info-modal-close:hover,
.info-modal-close:focus-visible {
    color: var(--primary-color);
    background: rgba(102, 116, 219, 0.12);
    outline: none;
}

.info-modal-body {
    font-size: var(--font-md);
    color: var(--text-secondary);
    line-height: 1.7;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-lg);
}

.about-modal-body p {
    margin: 0;
}

.about-modal-body h4 {
    margin: 0;
    color: var(--text-primary);
    font-size: var(--font-lg);
}

.about-modal-body .about-version {
    color: var(--text-primary);
    font-size: var(--font-base);
}

.about-modal-body .about-citation {
    padding: 10px 12px;
    border-left: 3px solid var(--primary-color);
    background: var(--bg-light);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
}

.about-modal-body .info-modal-list a {
    color: var(--secondary-color);
    text-decoration: none;
}

.about-modal-body .info-modal-list a:hover,
.about-modal-body .info-modal-list a:focus-visible {
    color: var(--secondary-dark);
    text-decoration: underline;
}

.info-example {
    border: 1px solid var(--border-light);
    border-radius: var(--radius-xl);
    background: var(--bg-lighter);
    padding: var(--spacing-lg);
    box-shadow: var(--shadow-sm);
}

.info-example-title {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--spacing-sm);
}

.info-modal-body pre {
    background: #0f172a;
    color: #f8fafc;
    border-radius: var(--radius-md);
    padding: var(--spacing-md);
    overflow-x: auto;
    font-family: 'Fira Code', 'SFMono-Regular', Consolas, monospace;
    font-size: 12px;
    margin: var(--spacing-sm) 0;
}

.info-table-wrapper {
    overflow-x: auto;
    margin-top: var(--spacing-sm);
}

.info-sample-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--font-sm);
    background: white;
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.info-sample-table th,
.info-sample-table td {
    border: 1px solid var(--border-light);
    padding: 8px 10px;
    text-align: left;
    white-space: nowrap;
}

.info-sample-table thead {
    background: rgba(102, 116, 219, 0.08);
    color: var(--text-primary);
}

.info-sample-table tbody tr:nth-child(even) {
    background: var(--bg-lighter);
}

/* 排序指示器（简约风格） */
.info-sample-table th {
    cursor: pointer;
    position: relative;
    padding-right: 28px; /* 留出空间给箭头 */
    -webkit-user-select: none; /* 支持 Safari / iOS Safari 3+ */
    user-select: none;
}

.info-sample-table th::after {
    content: '';
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 10px;
    color: var(--text-light);
    opacity: 0.9;
    transition: transform 0.12s ease, color 0.12s ease, opacity 0.12s ease;
}

.info-sample-table th.sorted-asc::after {
    content: '▲';
    color: var(--primary-color);
    transform: translateY(-50%) translateY(-1px);
}

.info-sample-table th.sorted-desc::after {
    content: '▼';
    color: var(--primary-color);
    transform: translateY(-50%) translateY(1px);
}

.info-sample-table th:hover::after {
    color: var(--primary-dark);
    opacity: 1;
}

.info-modal-list {
    margin: var(--spacing-sm) 0 0;
    padding-left: var(--spacing-xl);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.info-modal-list li {
    list-style: disc;
}

@media (max-width: 640px) {
    .info-modal-content {
        width: 92vw;
        padding: var(--spacing-xl);
    }
}

/* ========== 可视化容器 ========== */
.viz-container {
    position: relative;
    padding: clamp(var(--spacing-lg), 4vw, var(--spacing-3xl));
    background: var(--bg-white);
    /* Grid layout moved to .viz-panel-sub to support independent layout for each mode sub-container */
}

.viz-panel-sub {
    --panel-grid-gap: var(--spacing-xl);
    display: grid;
    grid-template-columns: repeat(
        auto-fit,
        minmax(
            min(var(--panel-min-width, 560px), 100%),
            var(--panel-min-width, 560px)
        )
    );
    gap: var(--panel-grid-gap);
    justify-content: center;

    /* 新增：确保每一行至少有固定最小高度，便于控制面板高度 */
    grid-auto-rows: minmax(var(--panel-min-height), auto);
    align-items: start;
    width: 100%;
}

.tree-panel {
    position: relative;
    border: 1px solid var(--tree-panel-border, var(--border-color));
    border-radius: var(--radius-lg);
    background: var(--tree-panel-bg, #fafbfd);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    transition: var(--transition-base);
}

.tree-panel:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--tree-panel-hover-border, var(--tree-panel-border, #d4dae3));
}

.tree-panel-header {
    /* 使用纯色背景，移除渐变 */
    background: var(--tree-panel-header-start, var(--primary-color));
    color: var(--tree-panel-header-text, #ffffff);
    height: 36px;
    padding: 2px var(--spacing-lg);
    box-sizing: border-box;
    font-weight: 600;
    font-size: var(--font-md);
    display: flex;
    align-items: center;
    justify-content: space-between; /* title centered via absolute; actions right */
    position: relative;
    /* Header border: defaults to 1px on all sides; color follows theme.
       Classical theme can override to keep only bottom border to avoid overlapping
       with the panel outer border. */
    border-style: solid;
    border-color: var(--tree-panel-header-border-color, transparent);
    border-width:
        var(--tree-panel-header-border-top, var(--tree-panel-header-border-width, 1px))
        var(--tree-panel-header-border-right, var(--tree-panel-header-border-width, 1px))
        var(--tree-panel-header-border-bottom, var(--tree-panel-header-border-width, 1px))
        var(--tree-panel-header-border-left, var(--tree-panel-header-border-width, 1px));
}

/* Title text inside header */
.tree-panel-header .panel-title-text {
    color: var(--tree-panel-header-text, #ffffff);
    font-weight: 700;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: calc(100% - 120px);
    pointer-events: none;
}

/* Right-aligned action area */
.tree-panel-header .panel-actions {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

/* Make header icons subtle and blend with background */
.tree-panel-header .btn-icon {
    width: 28px;
    height: 28px;
    background: transparent;
    color: rgba(255, 255, 255, 0.75);
    border: none;
    box-shadow: none;
    transition: color 0.15s ease, background 0.15s ease, transform 0.15s ease;
}

.tree-panel-header .btn-icon:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.18);
    border: none;
    transform: none;
}

.tree-panel-header .btn-icon:active {
    background: rgba(255, 255, 255, 0.26);
}

/* Classical/Void: reveal header action icons when hovering the header area */
:root[data-theme='theme-classic'] .tree-panel-header .btn-icon,
:root[data-theme='theme-void'] .tree-panel-header .btn-icon {
    color: transparent;
}

:root[data-theme='theme-classic'] .tree-panel-header:hover .btn-icon,
:root[data-theme='theme-classic'] .tree-panel-header .btn-icon:focus-visible,
:root[data-theme='theme-void'] .tree-panel-header:hover .btn-icon,
:root[data-theme='theme-void'] .tree-panel-header .btn-icon:focus-visible {
    color: rgba(0, 0, 0, 0.72);
}

:root[data-theme='theme-classic'] .tree-panel-header .btn-icon:hover,
:root[data-theme='theme-void'] .tree-panel-header .btn-icon:hover {
    color: #000000;
    background: rgba(0, 0, 0, 0.08);
}

:root[data-theme='theme-classic'] .tree-panel-header .btn-icon:active,
:root[data-theme='theme-void'] .tree-panel-header .btn-icon:active {
    background: rgba(0, 0, 0, 0.14);
}

/* Subtle back button inside the colored header */
.tree-panel-header .btn-back {
    background: transparent;
    color: var(--tree-panel-header-text, #ffffff);
    border: 1px solid rgba(255, 255, 255, 0.65);
    height: 28px;
    padding: 0 10px;
    border-radius: var(--radius-md);
    box-shadow: none;
}

.tree-panel-header .btn-back:hover {
    background: rgba(255, 255, 255, 0.18);
    color: var(--tree-panel-header-text, #ffffff);
    transform: none;
    box-shadow: none;
}

.tree-svg-container {
    width: 100%;
    /* 使用统一变量以便于高度统一配置；回退值改为更合理的默认值 */
    height: var(--panel-svg-height, 520px);
    position: relative;
}

.sample-checkboxes {
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing-lg);
    align-items: center;
    max-height: calc(40vh - 40px);
    overflow-y: auto;
    padding-right: var(--spacing-sm);
}

.sample-selection-panel {
    background: linear-gradient(135deg, #fafbfd 0%, #f5f7fa 100%);
    border-top: 1px solid var(--border-light);
    border-bottom: 1px solid var(--border-light);
    padding: var(--spacing-xl) var(--spacing-3xl);
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-in-out, padding 0.3s ease-in-out;
}

.sample-selection-panel.expanded {
    max-height: 50vh;
    padding: var(--spacing-xl) var(--spacing-3xl);
    overflow-y: auto;
}

.toggle-btn {
    background: var(--gradient-primary);
    color: white;
    border: none;
    padding: var(--spacing-sm) 14px;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: var(--font-sm);
    font-weight: 600;
    transition: var(--transition-fast);
    min-width: 90px;
    box-shadow: var(--shadow-sm);
}

.toggle-btn:hover {
    background: var(--gradient-primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.toggle-btn.expanded {
    background: var(--gradient-primary-hover);
}

/* ========== Color scheme preview tiles ========== */
#color-previews {
    display: flex;
    gap: var(--spacing-sm);
    flex-wrap: wrap;
}

.color-preview {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-sm);
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
    font-size: var(--font-sm);
    transition: var(--transition-fast);
}

.color-preview .swatches {
    display: flex;
    gap: 2px;
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    transition: var(--transition-fast);
}

.color-preview .swatch {
    width: 20px;
    height: 10px;
}

.color-preview.selected .swatches {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

.color-preview:hover .swatches {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.checkbox-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    cursor: pointer;
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--radius-md);
    transition: var(--transition-fast);
    background: rgba(255, 255, 255, 0.3);
}

.checkbox-item:hover {
    background: rgba(91, 109, 138, 0.08);
}

.checkbox-item input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--primary-color);
}

.checkbox-item label {
    cursor: pointer;
    font-size: var(--font-md);
    font-weight: 500;
    color: var(--text-primary);
    -webkit-user-select: none;
    user-select: none;
}


/* ========== Tooltip 样式 ========== */
.tooltip {
    position: absolute;
    padding: var(--spacing-md) var(--spacing-lg);
    /* Slightly translucent black for a softer, modern look */
    background: rgba(0, 0, 0, 0.5);
    /* soft border helps tooltips stand out over varying backgrounds */
    border: 1px solid rgba(255, 255, 255, 0.06);
    color: white;
    border-radius: var(--radius-lg);
    /* allow pointer events so text can be selected; visibility is managed in JS to avoid flicker */
    pointer-events: none;
    -webkit-user-select: text;
    user-select: text;
    font-size: var(--font-base);
    line-height: 1.6;
    opacity: 0;
    transition: opacity 0.3s;
    z-index: 10050;
    max-width: 300px;
    box-shadow: var(--shadow-xl);
    -webkit-backdrop-filter: blur(5px);
    backdrop-filter: blur(5px);
}

.tooltip.show {
    opacity: 1;
    pointer-events: auto;
}

.tooltip-taxon {
    font-weight: bold;
    color: #64b5f6;
    margin-bottom: var(--spacing-sm);
}

.tooltip-abundance {
    color: #81c784;
}

/* Tooltip path (full_path) - allow long paths to wrap nicely inside the tooltip */
.tooltip-path {
    color: #ddd;
    margin-bottom: var(--spacing-sm);
    display: block;
    box-sizing: border-box;
    max-width: 100%;
    white-space: normal;         /* allow wrapping */
    /* Force breaks for very long tokens (no spaces) so they don't overflow */
    word-break: break-all;       /* break within words if needed */
    overflow-wrap: anywhere;     /* ensure very long tokens wrap */
}

/* ========== Legend 样式 ========== */
.legend {
    position: absolute;
    top: 60px;
    right: var(--spacing-xl);
    background: var(--bg-white);
    padding: var(--spacing-lg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    font-size: var(--font-xs);
    z-index: 100;
}

.comparison-legend {
    display: block;
    padding: var(--spacing-lg) var(--spacing-xl);
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    text-align: center;
    margin: var(--spacing-xl) auto;
    width: -moz-fit-content; /* Firefox fallback */
    width: fit-content;
}

#shared-legend.comparison-legend {
    grid-column: 1 / -1;
    justify-self: center;
    align-self: start;
}

.shared-legend {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin: var(--spacing-md) auto var(--spacing-2xl) auto;
    width: 100%;
    max-width: 720px;
    pointer-events: none;
}

.shared-legend .legend-labels {
    width: 100%;
    display: flex;
    justify-content: space-between;
    margin-top: var(--spacing-sm);
    font-size: var(--font-sm);
    color: var(--text-secondary);
}

.shared-legend .transform-hint {
    margin: 0 var(--spacing-sm);
    font-size: var(--font-xs);
    color: var(--text-light);
    text-align: center;
}

.legend-title {
    font-weight: 600;
    margin-bottom: 10px;
    color: var(--text-primary);
    font-size: var(--font-sm);
    text-align: center;
}

.legend-gradient {
    width: 360px;
    height: 20px;
    border-radius: var(--radius-sm);
    margin: var(--spacing-sm) auto 0 auto;
}

.legend-labels {
    width: 360px;
    display: flex;
    justify-content: space-between;
    margin: var(--spacing-xs) auto 0 auto;
    font-size: var(--font-xs);
    color: var(--text-secondary);
}

.legend-description {
    margin-top: 10px;
    font-size: var(--font-xs);
    color: var(--text-secondary);
    text-align: center;
}


/* ========== 统计面板 ========== */
.stats-panel {
    background: var(--gradient-bg);
    padding: var(--spacing-xl) var(--spacing-3xl);
    border-top: 1px solid var(--border-light);
    display: flex;
    gap: 40px;
    flex-wrap: wrap;
    justify-content: center; /* 居中对齐每个统计项 */
}

.stat-item {
    flex: 1;
    min-width: 150px;
    display: flex;
    flex-direction: column;
    align-items: center;   /* 水平居中内容 */
    text-align: center;    /* 文本居中 */
}

.stat-label {
    font-size: var(--font-sm);
    color: var(--text-secondary);
    margin-bottom: var(--spacing-sm);
    font-weight: 500;
}

.stat-value {
    font-size: var(--font-4xl);
    font-weight: 700;
    color: var(--primary-color);
}

.filename-display {
    color: var(--text-secondary);
    font-size: var(--font-base);
    font-style: italic;
    max-width: 240px;              /* keep text concise beside buttons */
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}


/* ========== 响应式设计 ========== */
@media (max-width: 768px) {
    .container { height: auto; min-height: calc((100vh - (var(--spacing-md) * 2)) / var(--page-zoom-scale)); overflow: visible; }
    .app-body { flex-direction: column; padding: var(--spacing-lg); gap: var(--spacing-lg); }
    .sidebar { flex: none; min-width: unset; max-width: none; height: auto; position: relative; top: 0; flex-direction: column; border-right: none; border-bottom: 1px solid var(--border-light); padding-right: 0; overflow: hidden; resize: none; }
    .sidebar-activity-bar { width: auto; min-width: 0; flex-direction: row; flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; padding: var(--spacing-sm); border-right: none; border-bottom: 1px solid var(--sidebar-activity-border); }
    .sidebar-activity-btn { width: auto; height: 34px; flex: 0 0 auto; display: inline-flex; flex-direction: row; align-items: center; justify-content: center; gap: 6px; padding: 0 10px; border: 1px solid var(--border-color); background: var(--bg-white); transform: none; }
    .sidebar-activity-btn::before { display: none; }
    .sidebar-activity-btn svg { width: 14px; height: 14px; transform: none; }
    .sidebar-activity-btn span { transform: none; margin-top: 0; white-space: nowrap; font-size: var(--font-sm); }
    .sidebar-sections { padding: var(--spacing-md) 0 0 0; overflow: visible; }
    .sidebar-toggle-inline { margin-top: 0; margin-bottom: 0; margin-left: auto; align-self: center; }
    .sidebar-toggle-collapsed { align-self: flex-end; margin: var(--spacing-md) 0 0 auto; }
    .app-body.sidebar-collapsed .sidebar-toggle-collapsed { width: 40px; height: 40px; padding: 0; }
    .app-body.sidebar-collapsed .main-content { padding-left: 0; }
    .main-content { padding-right: 0; position: static; height: auto; overflow: visible; }
    body {
        padding: var(--spacing-md);
    }

    .header {
        grid-template-columns: 1fr;
        grid-template-areas:
            "title"
            "links"
            "subtitle";
        text-align: center;
        row-gap: var(--spacing-sm);
    }

    .header .title-row {
        justify-content: center;
    }
    
    .header h1 {
        font-size: var(--font-4xl);
    }
    
    .header p {
        font-size: var(--font-sm);
    }

    .header-links {
        position: static;
        justify-content: center;
        flex-wrap: wrap;
        margin-bottom: 0;
        gap: 6px;
        justify-self: center;
    }

    .subtitle-version-label {
        right: 0;
    }

    .about-section {
        margin: var(--spacing-md) var(--spacing-sm);
        padding: var(--spacing-md);
    }
    
    .control-panel {
        flex-direction: column;
        align-items: stretch;
        padding: var(--spacing-lg) var(--spacing-xl);
    }

    .control-group {
        flex-direction: column;
        align-items: stretch;
    }

    .legend {
        position: relative;
        top: auto;
        right: auto;
        margin: var(--spacing-xl) 0;
    }

    .legend-gradient,
    .legend-labels {
        width: 260px;
    }
    
    .viz-container {
        padding: var(--spacing-xl);
        gap: var(--spacing-lg);
    }
}

/* ========== SVG节点和连线样式 ========== */
.node circle {
    cursor: pointer;
    transition: var(--transition-base);
}

.node circle:hover {
    stroke-width: 3px;
}

/* ========== 比较模式按钮样式 ========== */
.btn-run-comparison {
    padding: 10px var(--spacing-2xl);
    background: var(--gradient-success);
    color: white;
    border: none;
    border-radius: var(--radius-lg);
    font-weight: 600;
    font-size: var(--font-md);
    cursor: pointer;
    transition: var(--transition-fast);
    box-shadow: var(--shadow-md);
}

.btn-run-comparison:hover {
    background: linear-gradient(135deg, #229954 0%, #1e8449 100%);
    transform: translateY(-1px);
    box-shadow: var(--shadow-success);
}

.btn-export-comparison {
    padding: var(--spacing-sm) 18px;
    background: var(--gradient-info);
    color: white;
    border: none;
    border-radius: var(--radius-lg);
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition-fast);
    box-shadow: var(--shadow-md);
}

.btn-export-comparison:hover {
    background: linear-gradient(135deg, #2980b9 0%, #21618c 100%);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(52, 152, 219, 0.3);
}

/* ========== 图标按钮（紧凑样式） ========== */
.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border-radius: var(--radius-md);
    background: var(--bg-white);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    transition: var(--transition-fast);
    cursor: pointer;
    box-shadow: var(--shadow-sm);
}

.btn-icon:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.btn-icon-danger {
    color: var(--danger-color);
    border-color: #fde8e7;
}

.btn-icon-danger:hover {
    color: var(--bg-white);
    background: var(--gradient-danger);
    border-color: var(--danger-dark);
    box-shadow: 0 3px 8px rgba(231, 76, 60, 0.3);
}

/* ========== 图标按钮（主色强调样式） ========== */
.btn-icon-primary {
    color: var(--primary-color);
    border-color: var(--primary-color);
}

.btn-icon-primary:hover {
    color: var(--bg-white);
    background: var(--gradient-primary);
    border-color: var(--primary-dark);
    box-shadow: var(--shadow-primary);
}

/* ========== 小按钮样式 ========== */
.btn-small {
    background: var(--gradient-primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    padding: var(--spacing-xs) 10px;
    font-size: var(--font-sm);
    cursor: pointer;
    transition: var(--transition-fast);
    box-shadow: var(--shadow-sm);
    font-weight: 600;
}

/* ========== Utility classes (replacing inline styles) ========== */
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.ai-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-6 { gap: 6px; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.mt-6 { margin-top: 6px; }
.mt-8 { margin-top: 8px; }
.ml-8 { margin-left: 8px; }
.ml-10 { margin-left: 10px; }
.ml-12 { margin-left: 12px; }
.ml-auto { margin-left: auto; }
.mx-4 { margin-left: 4px; margin-right: 4px; }
.mr-8 { margin-right: 8px; }

.w-60 { width: 60px; }
.w-65 { width: 65px; }
.w-100 { width: 100%; }
.w-120 { width: 120px; }
.w-140 { width: 140px; }
.w-180 { width: 180px; }
.minw-140 { min-width: 140px; }
.minw-160 { min-width: 160px; }

.p-6 { padding: 6px; }
.pad-8-12 { padding: 8px 12px; }

.bg-light-surface { background: #f8f9fa; }
.br-4 { border-radius: 4px; }
.overflow-y-auto { overflow-y: auto; }

/* Grid utilities */
.grid { display: grid; }

.text-muted { color: #666; }
.text-light { color: #999; }
.fs-12 { font-size: 12px; }
.fs-13 { font-size: 13px; }
.fw-500 { font-weight: 500; }

/* Defaults for collapsible/hidden sections (was inline style="display:none;") */
#meta-filters-content,
#custom-color-controls,
#custom-color-mid,
#custom-arrow-mid,
#data-params-content,
#sample-selection-panel,
#comparison-controls,
#group-mode-settings,
#matrix-group-selection,
#significance-thresholds-row,
#export-comparison,
#stats-panel {
    display: none;
}

/* Section divider and titles (replacing inline styles) */
.section-divider { margin-top: 30px; padding-top: 20px; border-top: 2px solid #e0e0e0; }
.section-title { font-weight: 600; margin-bottom: 15px; color: #2c3e50; }

.btn-small:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
    background: var(--gradient-primary-hover);
}

.custom-delimiter-input {
    display: none;
    width: 100%;
}

.custom-delimiter-input.visible {
    display: block;
}

.btn-small:active {
    transform: translateY(0);
    box-shadow: var(--shadow-sm);
}


/* ========== 分组显示区域 ========== */
.group-display {
    margin: 10px 0;
    padding: var(--spacing-md);
    background: var(--bg-light);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    max-height: 180px;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: var(--spacing-sm);
    width: 100%;
    box-sizing: border-box;
}

.group-display > div {
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--bg-white);
    border-radius: var(--radius-md);
    font-size: var(--font-base);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    transition: var(--transition-fast);
}

.group-display > div:hover {
    border-color: var(--primary-color);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

#existing-groups-list {
    max-height: 260px;
    overflow-y: auto;
}

/* ========== 可折叠面板（元数据筛选） ========== */
.control-group.collapsible {
    padding: var(--spacing-md) var(--spacing-lg);
    border-bottom: 1px solid var(--border-light);
}

.collapsible .collapsible-header {
    display: flex;
    align-items: center;
    gap: 10px;
}

.collapsible .collapsible-title {
    font-weight: 600;
    color: var(--text-primary);
    font-size: var(--font-md);
}

.collapsible .collapsible-content {
    margin-top: var(--spacing-sm);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: var(--spacing-md);
    background: linear-gradient(135deg, #f8f9fb 0%, #f3f5f8 100%);
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.03);
}

#samples-toggle-group {
    margin-top: var(--spacing-sm);
}


/* ========== 自定义滚动条样式 ========== */
.group-display::-webkit-scrollbar,
#existing-groups-list::-webkit-scrollbar,
.collapsible-content::-webkit-scrollbar,
.sample-checkboxes::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

.group-display::-webkit-scrollbar-track,
#existing-groups-list::-webkit-scrollbar-track,
.collapsible-content::-webkit-scrollbar-track,
.sample-checkboxes::-webkit-scrollbar-track {
    background: var(--scrollbar-panel-track);
    border-radius: 3px;
}

.group-display::-webkit-scrollbar-thumb,
#existing-groups-list::-webkit-scrollbar-thumb,
.collapsible-content::-webkit-scrollbar-thumb,
.sample-checkboxes::-webkit-scrollbar-thumb {
    background: var(--scrollbar-panel-thumb);
    border-radius: 3px;
    transition: var(--transition-fast);
}

.group-display::-webkit-scrollbar-thumb:hover,
#existing-groups-list::-webkit-scrollbar-thumb:hover,
.collapsible-content::-webkit-scrollbar-thumb:hover,
.sample-checkboxes::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-panel-thumb-hover);
}

/* ========== 选择分组/样本容器：半透明滚动条（覆盖上面的渐变样式） ========== */
.group-display::-webkit-scrollbar-track,
.sample-checkboxes::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
}

.group-display::-webkit-scrollbar-thumb,
.sample-checkboxes::-webkit-scrollbar-thumb {
    background: var(--scrollbar-soft-thumb);
    border-radius: 4px;
    border: 1px solid transparent;
    background-clip: content-box;
    transition: var(--transition-fast);
}

.group-display::-webkit-scrollbar-thumb:hover,
.sample-checkboxes::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-soft-thumb-hover);
}

/* Firefox */
.group-display,
.sample-checkboxes {
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-soft-color) var(--scrollbar-track);
}

/* ========== 输入框焦点增强效果 ========== */
input[type="range"]:focus,
input[type="checkbox"]:focus {
    outline: 2px solid rgba(74, 85, 104, 0.2);
    outline-offset: 2px;
    border-radius: 2px;
}

/* ========== 微调动画 ========== */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.card-panel {
    animation: fadeIn 0.3s ease-out;
}

/* ========== Taxon 筛选样式 ========== */
.taxon-filter-box {
    max-height: 120px;
    overflow-y: auto;
    overflow-x: hidden;
    border: 1px solid var(--border-color);
    padding: 6px;
    background: #f9f9f9;
    border-radius: var(--radius-sm);
    font-size: 10px;
    word-break: break-all;
    width: 100%;
    box-sizing: border-box;
}

.taxon-filter-box.filter-list {
    background: var(--bg-white);
    max-height: 100px;
}

.taxon-filter-expand-btn {
    margin-left: 8px;
    padding: 2px 8px;
    font-size: 11px;
    cursor: pointer;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    transition: var(--transition-fast);
}

.taxon-filter-expand-btn:hover {
    background: var(--primary-dark);
}

.taxon-filter-box::-webkit-scrollbar {
    width: 6px;
}

.taxon-filter-box::-webkit-scrollbar-track {
    background: var(--scrollbar-panel-track);
    border-radius: 3px;
}

.taxon-filter-box::-webkit-scrollbar-thumb {
    background: var(--scrollbar-panel-thumb);
    border-radius: 3px;
}

.taxon-item {
    padding: 4px 6px;
    margin: 2px 0;
    background: var(--bg-white);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    font-family: 'Courier New', monospace;
    font-size: 10px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    transition: var(--transition-fast);
    width: 100%;
    box-sizing: border-box;
}

.taxon-item:hover {
    background: var(--bg-light);
    border-color: var(--primary-color);
}

.taxon-item-name {
    flex: 1;
    min-width: 0;
    word-wrap: break-word;
    overflow-wrap: break-word;
    word-break: break-all;
    font-size: 10px;
    line-height: 1.3;
}

.taxon-item-remove {
    cursor: pointer;
    color: var(--danger-color);
    font-weight: bold;
    padding: 0 4px;
    margin-left: 4px;
    border-radius: 2px;
    transition: var(--transition-fast);
    flex-shrink: 0;
    font-size: 14px;
}

.taxon-item-remove:hover {
    background: var(--danger-color);
    color: white;
}

#taxon-search-input {
    width: 100%;
}

.flex-1 {
    flex: 1;
}

/* Taxon 编辑弹窗 */
.taxon-edit-modal {
    display: none;
    position: fixed;
    z-index: 10000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.6);
    -webkit-backdrop-filter: blur(3px);
    backdrop-filter: blur(3px);
}

.taxon-edit-modal-content {
    background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
    margin: 5% auto;
    padding: 0;
    border: none;
    border-radius: 12px;
    width: 80%;
    max-width: 800px;
    max-height: 80vh;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
}

.taxon-edit-modal-header {
    background: var(--gradient-primary);
    color: white;
    padding: 20px 24px;
    border-radius: 12px 12px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.taxon-edit-modal-header h3 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
}

.taxon-edit-modal-close {
    color: white;
    font-size: 32px;
    font-weight: bold;
    cursor: pointer;
    border: none;
    background: none;
    padding: 0;
    width: 32px;
    height: 32px;
    line-height: 28px;
    text-align: center;
    border-radius: 50%;
    transition: var(--transition-fast);
}

.taxon-edit-modal-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.taxon-edit-modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.taxon-edit-list {
    max-height: 400px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 8px;
    background: white;
    margin-bottom: 16px;
}

.taxon-edit-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    margin: 4px 0;
    background: var(--bg-light);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    font-family: 'Courier New', monospace;
    font-size: 12px;
    transition: var(--transition-fast);
}

.taxon-edit-item:hover {
    background: white;
    border-color: var(--primary-color);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.taxon-edit-item-name {
    flex: 1;
    word-break: break-all;
    margin-right: 12px;
}

.taxon-edit-item-remove {
    cursor: pointer;
    color: white;
    background: var(--danger-color);
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 14px;
    transition: var(--transition-fast);
    border: none;
    min-width: 60px;
}

.taxon-edit-item-remove:hover {
    background: var(--danger-dark);
    transform: scale(1.05);
}

.taxon-manual-add {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 2px solid var(--border-color);
}

.taxon-manual-add input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 13px;
}

.taxon-manual-add button {
    padding: 8px 16px;
    background: var(--success-color);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 600;
    transition: var(--transition-fast);
}

.taxon-manual-add button:hover {
    background: var(--success-dark);
}

.taxon-edit-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 2px solid var(--border-color);
}

.taxon-edit-actions button {
    padding: 10px 24px;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    transition: var(--transition-fast);
}

.taxon-edit-actions .btn-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
}

.taxon-edit-actions .btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(88, 86, 214, 0.3);
}

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

.taxon-edit-actions .btn-secondary:hover {
    background: var(--border-light);
}

.taxon-edit-stats {
    text-align: center;
    padding: 12px;
    background: var(--bg-light);
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
    font-size: 14px;
    color: var(--text-secondary);
}

.taxon-edit-stats strong {
    color: var(--primary-color);
    font-size: 18px;
}

/* ========== 右键菜单 - 标签颜色 ========== */
.context-menu {
    position: fixed;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    z-index: 10060;
    min-width: 240px;
    padding: 0;
    display: none;
}

.context-menu-header {
    padding: 12px 16px;
    font-weight: 600;
    font-size: 13px;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-light);
    background: var(--bg-light);
}

.context-menu-section {
    padding: 12px 16px;
}

.context-menu-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    margin: 0;
    font-size: 13px;
    font-weight: 500;
}

.context-menu-label span {
    margin-right: 12px;
}

.context-menu-label input[type="color"] {
    cursor: pointer;
    border: 1px solid var(--border-color);
    background: transparent;
    width: 60px;
    height: 36px;
    border-radius: 4px;
    padding: 2px;
}

.context-menu-label input[type="color"]:hover {
    border-color: var(--primary-color);
}

.context-menu-actions {
    display: flex;
    gap: 6px;
    padding: 12px 16px;
    border-top: 1px solid var(--border-light);
    background: white;
}

.context-menu-btn {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    background: white;
    color: #333;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition-fast);
    white-space: nowrap;
    min-width: 60px;
    text-align: center;
    display: inline-block;
}

.context-menu-btn:hover {
    background: var(--bg-light);
    border-color: var(--primary-color);
    color: var(--primary-color);
    transform: translateY(-1px);
}

.context-menu-divider {
    height: 1px;
    background: var(--border-light);
    margin: 0;
}

/* 屏蔽 panel 区域的浏览器右键菜单 */
#viz-container,
svg {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Toast Notification */
.toast-notification {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background-color: var(--text-primary);
    color: var(--bg-white);
    padding: 12px 24px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: 10000;
    font-size: var(--font-md);
    font-weight: 500;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.3s ease, transform 0.3s ease;
    pointer-events: none;
}

.toast-notification.show {
    opacity: 1;
    transform: translateY(0);
}

/* ========== Modal Styles (Centered) ========== */
.info-modal {
    display: none;
    position: fixed;
    z-index: 10000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: rgba(0, 0, 0, 0.5);
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(2px);
}

.info-modal[aria-hidden="false"] {
    display: flex !important;
}

.info-modal-content {
    background: white;
    margin: auto;
    padding: 0;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    display: flex;
    flex-direction: column;
    max-height: 90vh;
    width: 90%;
    max-width: 1200px;
    position: relative;
    animation: fadeIn 0.3s ease;
}

.info-modal-header {
    padding: 16px 24px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-light);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.info-modal-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.info-modal-close {
    background: none;
    border: none;
    font-size: 24px;
    line-height: 1;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: var(--transition-fast);
}

.info-modal-close:hover {
    background: rgba(0,0,0,0.1);
    color: var(--text-primary);
}

.info-modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.info-modal-overlay {
    position: absolute;
    inset: 0;
    z-index: -1;
}
/* Ensure modals have white background */
.info-modal-body, .info-modal-container, .info-modal-content {
    background-color: var(--bg-white, #fff);
}
#file-preview-modal .info-modal-container, 
#column-mapping-modal .info-modal-container {
    background-color: var(--bg-white, #fff);
}

/* Drag and drop styles */
.dragging {
    opacity: 0.5;
    background-color: #f0f0f0;
}


/* Mode Switcher Styles */
.mode-control-group {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
    container-type: inline-size;
    flex: 1; /* Allow to fill available space */
    width: 100%; /* Fallback/Force width */
    min-width: 0; /* Critical for container queries in flex items */
    align-items: stretch; /* Override .control-group's center */
    flex-wrap: nowrap; /* Prevent wrapping issues in column layout */
}

.mode-switcher {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
    background: var(--bg-light);
    padding: 4px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
}

@container (max-width: 340px) {
    .mode-switcher {
        grid-template-columns: repeat(2, 1fr);
    }
}

@container (max-width: 180px) {
    .mode-switcher {
        grid-template-columns: 1fr;
    }
}

.mode-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px 2px;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    cursor: pointer;
    color: var(--text-secondary);
    transition: var(--transition-fast);
    font-size: 10px;
    font-weight: 600;
    white-space: nowrap;
}

/* Make mode switcher labels bold for clarity */
.mode-btn span {
    font-weight: 700;
}

.mode-btn:hover {
    background: rgba(0, 0, 0, 0.03);
    color: var(--primary-color);
}

.mode-btn.active {
    background: var(--bg-white);
    color: var(--primary-color);
    border-color: var(--border-color);
    box-shadow: var(--shadow-sm);
    font-weight: 600;
}

.mode-btn svg {
    opacity: 0.7;
    transition: var(--transition-fast);
}

.mode-btn.active svg {
    opacity: 1;
    stroke: var(--primary-color);
}

/* ========== Tab Navigation Styles ========== */
.tab-nav {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    padding: 3px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    background: var(--bg-light);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.65);
    margin-bottom: var(--spacing-md);
    gap: 4px;
}

.tab-btn {
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    padding: calc(var(--spacing-sm) + 1px) var(--spacing-md);
    font-size: var(--font-sm);
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    min-height: 30px;
    transition: var(--transition-fast);
}

.tab-btn:hover:not(.active) {
    color: var(--text-primary);
    background-color: rgba(107, 127, 168, 0.18);
    background-color: color-mix(in srgb, var(--primary-color) 20%, #ffffff);
    border-color: var(--primary-color);
    box-shadow: 0 1px 4px rgba(90, 109, 143, 0.16);
}

.tab-btn.active {
    color: #ffffff;
    background: var(--gradient-primary);
    border-color: var(--primary-dark);
    box-shadow: 0 2px 6px rgba(90, 109, 143, 0.22);
}

.tab-btn:focus-visible {
    outline: 2px solid var(--secondary-color);
    outline-offset: 1px;
}

.tab-content {
    display: none;
    animation: fadeIn 0.2s ease-in-out;
}

.tab-content.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(2px); }
    to { opacity: 1; transform: translateY(0); }
}

.tab-content-wrapper {
    min-height: 420px; /* Prevent layout jumping when switching tabs */
    display: flex;
    flex-direction: column;
}
