/**
 * 组间比较模式样式
 * 用于热树矩阵和比较可视化
 * Version: 4.0 - 简洁设计系统
 */

/* ========== 比较矩阵容器 ========== */
/* Wrapper to handle full-width layout */
.comparison-matrix-wrapper {
    width: calc(100% + 2 * var(--spacing-xl));
    margin: 0 calc(0px - var(--spacing-xl));
    display: flex;
    flex-direction: column;
    /* Default: Center the matrix when it fits in the screen */
    align-items: center;
}

/* When the matrix overflows the screen, JS adds this class to switch alignment */
.comparison-matrix-wrapper.align-left {
    align-items: flex-start;
}

.comparison-matrix-container {
    /* Container fits its content */
    width: fit-content;
    max-width: none;
    /* Margin for vertical spacing only; horizontal alignment handled by wrapper */
    margin: var(--spacing-lg) 0;

    padding: clamp(var(--spacing-lg), 3vw, var(--spacing-xl));
    background: var(--bg-light);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    box-sizing: border-box;
    overflow-x: visible;
}

.matrix-title {
    font-size: var(--font-2xl);
    font-weight: 600;
    text-align: center;
    color: var(--text-primary);
    margin-bottom: var(--spacing-lg);
    padding: var(--spacing-md);
    background: var(--bg-white);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    /* Ensure title limits width to container */
    max-width: 100%;
}

/* ========== 矩阵网格 ========== */
.comparison-matrix-grid {
    display: grid;
    gap: var(--spacing-sm);
    /* Margin no longer needed for centering, handled by wrapper flex */
    margin: 0;
    background: var(--bg-white);
    padding: var(--spacing-md);
    border-radius: var(--radius-lg);
    box-shadow: none;
    border: 1px solid var(--border-color);
}

/* matrix label sizing: use a single CSS variable so row and column labels
   share the same size. Default to 40px (matches previous column label height). */
:root {
    --matrix-label-size: 36px;
}

@media (max-width: 1200px) {
    :root {
        --matrix-cell-min-width: clamp(110px, 20vw, 180px);
        --matrix-cell-min-height: clamp(120px, 22vw, 200px);
    }
}

@media (max-width: 768px) {
    :root {
        --matrix-cell-min-width: 110px;
        --matrix-cell-min-height: 120px;
    }
}

/* Let the grid size itself to its content so the container's scrollbar
   can handle overflow. Using max-content prevents the grid from forcing
   overflow outside the container while preserving column sizing. */
.comparison-matrix-grid {
    /* Let the grid size itself to its content so the scroll container (above)
       handles overflow while keeping cell sizing intact. */
    box-sizing: border-box;
    width: max-content;
    min-width: fit-content;
}

/* ========== 矩阵单元格 ========== */
.matrix-cell {
    position: relative;
    background: var(--tree-panel-bg, var(--bg-white));
    border: 1px solid var(--tree-panel-border, var(--border-color));
    border-radius: var(--radius-md);
    overflow: hidden;
    min-height: var(--matrix-cell-min-height, 150px);
    min-width: var(--matrix-cell-min-width, 150px);
    transition: var(--transition-base);
    box-shadow: var(--shadow-sm);
}

.matrix-cell:hover {
    transform: scale(1.02);
    box-shadow: var(--shadow-md);
    z-index: 10;
    border-color: var(--tree-panel-hover-border, var(--tree-panel-border, var(--border-color)));
}

.matrix-cell.empty-cell {
    background: transparent;
    border: none;
    box-shadow: none;
}

/* Hide the corner spacer cell so it doesn’t clash with theme backgrounds */
.comparison-matrix-grid > .matrix-cell.empty-cell:first-child {
    background: transparent;
    border: none;
    box-shadow: none;
    min-width: var(--matrix-label-size, 40px);
    min-height: var(--matrix-label-size, 40px);
    pointer-events: none;
}

.cell-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--text-light);
    font-size: var(--font-sm);
}

/* ========== 矩阵标签 ========== */
.matrix-row-label,
.matrix-col-label {
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: var(--font-base);
    color: var(--tree-panel-header-text, #ffffff);
    padding: var(--spacing-sm);
    text-align: center;
    background: var(--tree-panel-header-start, var(--primary-color));
    border-radius: var(--radius-md);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Column labels: use the label size as height so they remain thin */
.matrix-col-label {
    height: var(--matrix-label-size, 40px);
    line-height: var(--matrix-label-size, 40px);
    writing-mode: horizontal-tb;
    /* keep column labels horizontal */
}

/* Row labels: make them match the column label size (width) and display
   their text vertically. Use writing-mode + text-orientation for best
   cross-language support; fall back to rotate for older browsers if needed. */
.matrix-row-label {
    width: var(--matrix-label-size, 40px);
    min-width: var(--matrix-label-size, 40px);
    max-width: var(--matrix-label-size, 40px);
    height: auto;
    writing-mode: vertical-rl;
    text-orientation: mixed;
    transform-origin: center;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: calc(var(--spacing-xs));
}


/* ========== 迷你树 SVG ========== */
.mini-tree-svg {
    width: 100%;
    height: 100%;
}

.mini-tree-svg .link {
    fill: none;
    stroke-opacity: 0.6;
    transition: var(--transition-fast);
}

.mini-tree-svg .link:hover {
    stroke-opacity: 1;
    stroke-width: 2px !important;
}

.mini-tree-svg .node {
    transition: var(--transition-fast);
}

.mini-tree-svg .node:hover {
    r: 5 !important;
    stroke-width: 1.5px !important;
}

/* ========== 比较图例 ========== */
.comparison-legend {
    margin: var(--spacing-3xl) auto;
    max-width: 600px;
    padding: var(--spacing-xl);
    background: var(--bg-white);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-md);
}

.legend-title {
    font-size: var(--font-xl);
    font-weight: bold;
    text-align: center;
    color: var(--text-primary);
    margin-bottom: var(--spacing-lg);
}

.legend-gradient {
    height: 30px;
    border-radius: var(--radius-md);
    margin-bottom: 10px;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.legend-labels {
    display: flex;
    justify-content: space-between;
    font-size: var(--font-sm);
    color: var(--text-secondary);
    margin-bottom: var(--spacing-lg);
}

.legend-description {
    text-align: center;
    font-size: var(--font-base);
    color: var(--text-secondary);
    padding-top: 10px;
    border-top: 1px solid var(--border-color);
}

/* ========== 单个比较面板 ========== */
.comparison-panel {
    background: var(--tree-panel-bg, var(--bg-white));
    border: 1px solid var(--tree-panel-border, var(--border-color));
    box-shadow: var(--shadow-sm);
    min-width: var(--panel-min-width, 560px);
    max-width: var(--panel-min-width, 560px);
    width: var(--panel-min-width, 560px);
    margin-left: auto;
    margin-right: auto;
}

.comparison-panel .tree-panel-header {
    color: var(--tree-panel-header-text, #ffffff);
    font-size: var(--font-2xl);
    padding: var(--spacing-lg);
}

/* Increase the SVG drawing area height for two-group comparison panels */
.comparison-panel .tree-svg-container {
    height: var(--comparison-panel-svg-height, 800px);
    background: var(--tree-panel-bg, var(--bg-white));
    border-top: 1px solid var(--tree-panel-border, var(--border-color));
    padding: var(--spacing-md);
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.05);
}

.comparison-panel .tree-svg-container svg {
    background: var(--tree-panel-bg, #fafbfd);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-inner, inset 0 1px 3px rgba(0, 0, 0, 0.08));
}

.group-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px;
    margin: 5px 0;
    background: var(--bg-light);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    transition: var(--transition-fast);
}

.group-item:hover {
    background: var(--bg-light);
    border-color: var(--text-secondary);
    transform: none;
}

.group-name {
    font-weight: 600;
    color: var(--text-primary);
    flex: 0 0 150px;
}

.group-samples {
    flex: 1;
    font-size: var(--font-sm);
    color: var(--text-secondary);
    margin: 0 10px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.group-actions {
    display: flex;
    gap: 5px;
}

.btn-group-action {
    padding: var(--spacing-xs) var(--spacing-md);
    font-size: var(--font-sm);
    border-radius: var(--radius-sm);
    border: none;
    cursor: pointer;
    transition: var(--transition-fast);
    font-weight: 600;
}

.btn-group-delete {
    background: var(--danger-color);
    color: white;
}

.btn-group-delete:hover {
    background: var(--danger-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

/* ========== 分组定义模态框 ========== */
.group-modal {
    display: none;
    position: fixed;
    z-index: 10000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    animation: fadeIn 0.3s;
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.group-modal-content {
    position: relative;
    background-color: var(--bg-white);
    margin: 5% auto;
    padding: var(--spacing-3xl);
    border-radius: var(--radius-xl);
    width: 80%;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: var(--shadow-xl);
    animation: slideDown 0.3s;
}

@keyframes slideDown {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.group-modal-header {
    font-size: var(--font-3xl);
    font-weight: bold;
    margin-bottom: var(--spacing-xl);
    color: var(--text-primary);
    border-bottom: 2px solid var(--primary-color);
    padding-bottom: 10px;
}

.group-modal-close {
    position: absolute;
    right: var(--spacing-xl);
    top: var(--spacing-xl);
    font-size: 28px;
    font-weight: bold;
    color: var(--text-light);
    cursor: pointer;
    transition: var(--transition-fast);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
}

.group-modal-close:hover {
    color: var(--text-primary);
    background: var(--bg-light);
}

.group-form-field {
    margin-bottom: var(--spacing-xl);
}

.group-form-field label {
    display: block;
    font-weight: 600;
    margin-bottom: var(--spacing-sm);
    color: var(--text-primary);
    font-size: var(--font-md);
}

.group-form-field input[type="text"] {
    width: 100%;
    padding: 10px var(--spacing-md);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: var(--font-md);
    transition: var(--transition-fast);
}

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

.sample-checklist {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 10px;
    background: var(--bg-light);
}

.sample-checklist label {
    display: block;
    padding: var(--spacing-sm);
    margin: var(--spacing-xs) 0;
    background: var(--bg-white);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition-fast);
    font-size: var(--font-md);
}

.sample-checklist label:hover {
    background: var(--bg-light);
    transform: none;
}

.sample-checklist input[type="checkbox"] {
    margin-right: 10px;
    accent-color: var(--primary-color);
}

.group-form-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: var(--spacing-xl);
}

.btn-modal {
    padding: 10px var(--spacing-xl);
    border: none;
    border-radius: var(--radius-md);
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition-fast);
    font-size: var(--font-md);
}

.btn-modal-save {
    background: var(--primary-color);
    color: white;
}

.btn-modal-save:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: var(--shadow-primary);
}

.btn-modal-cancel {
    background: #e0e0e0;
    color: var(--text-primary);
}

.btn-modal-cancel:hover {
    background: #d0d0d0;
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}


/* ========== 响应式设计 ========== */
@media (max-width: 1200px) {
    .comparison-matrix-grid {
        gap: var(--spacing-sm);
    }

    .matrix-cell {
        min-height: 150px;
    }

    .matrix-row-label,
    .matrix-col-label {
        font-size: var(--font-xs);
        padding: var(--spacing-sm);
    }
}

@media (max-width: 768px) {
    .comparison-matrix-container {
        padding: 10px;
    }

    .matrix-title {
        font-size: var(--font-xl);
    }

    .comparison-matrix-grid {
        gap: var(--spacing-xs);
        padding: 10px;
    }

    .matrix-cell {
        min-height: 120px;
    }

    .group-modal-content {
        width: 95%;
        margin: 10% auto;
        padding: var(--spacing-xl);
    }

    .group-modal-header {
        font-size: var(--font-2xl);
    }
}
