/**
 * 模板选择对话框样式
 * ===========================================
 * 为模板选择对话框提供专门的样式定义，支持亮色和暗色主题
 */

/* 模板选择对话框遮罩 */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: var(--color-bg-overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}


/* 修复：模板选择对话框主容器高度 */
.modal-content.template-selection-modal {
    width: 80vw;
    max-width: 900px;
    min-width: 600px;
    height: 75vh; /* 增加高度 */
    max-height: 800px; /* 增加最大高度 */
    display: flex;
    flex-direction: column;
    padding: 0;
    margin: 0;
    overflow: hidden;
    transform: none;
    background: var(--color-bg-tertiary);
    border: none;
    border-radius: 8px;
    box-shadow: none;
}

/* 亮色主题适配 */
body.light-theme .modal-content.template-selection-modal {
    background: var(--sidebar-light-theme-bg);
    border: none;
    box-shadow: none;
}

/* 修复：确保亮色主题遮罩正确显示 */
body.light-theme .modal-overlay {
    background-color: rgba(0, 0, 0, 0.5);
}

[data-theme="light"] .modal-overlay {
    background-color: rgba(0, 0, 0, 0.5);
}

[data-theme="light"] .modal-content.template-selection-modal {
    background: var(--sidebar-light-theme-bg);
    border: none;
    box-shadow: none;
}

/* 对话框头部 */
.template-selection-modal .modal-header {
    background: var(--color-bg-primary);
    border-bottom: 1px solid var(--color-border-medium);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-radius: var(--border-radius) var(--border-radius) 0 0;
}

body.light-theme .template-selection-modal .modal-header {
    background: var(--sidebar-light-theme-input-bg);
    border-bottom: 1px solid var(--sidebar-light-theme-border);
}

.template-selection-modal .modal-header h3 {
    color: var(--color-primary);
    margin: 0;
    font-family: var(--app-font-family);
    font-size: var(--font-size-lg);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

body.light-theme .template-selection-modal .modal-header h3 {
    color: var(--sidebar-light-theme-text);
}

/* 关闭按钮 */
.modal-close-btn {
    background: none;
    border: none;
    color: var(--color-text-secondary);
    font-size: 24px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: var(--border-radius-sm);
    transition: all 0.2s ease;
}

.modal-close-btn:hover {
    color: var(--color-primary);
    background: rgba(0, 255, 65, 0.1);
}

body.light-theme .modal-close-btn {
    color: var(--sidebar-light-theme-text-secondary);
}

body.light-theme .modal-close-btn:hover {
    color: var(--sidebar-light-theme-text);
    background: var(--sidebar-light-theme-border);
}

/* 修复：对话框主体内容布局 */
.template-selection-modal .modal-body {
    flex: 1;
    padding: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0; /* 确保flex子元素可以正确计算高度 */
}

.template-selection-content {
    display: flex;
    flex: 1;
    min-height: 0; /* 确保flex子元素可以正确计算高度 */
    height: 100%; /* 明确设置高度 */
}

/* 模板信息区域 */
.template-info-section {
    flex: 0 0 300px;
    background: transparent;
    border-right: 1px solid var(--color-border-medium);
    padding: 20px;
    overflow-y: auto;
}

body.light-theme .template-info-section {
    background: transparent;
    border-right: 1px solid var(--sidebar-light-theme-border);
}

.template-info-section h4 {
    color: var(--color-text-primary);
    font-family: var(--app-font-family);
    font-size: var(--font-size-base);
    font-weight: 600;
    margin: 0 0 12px 0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

body.light-theme .template-info-section h4 {
    color: var(--sidebar-light-theme-text);
}

/* 模板预览信息 */
.template-preview {
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border-medium);
    border-radius: var(--border-radius-sm);
    padding: 16px;
    margin-bottom: 20px;
}

body.light-theme .template-preview {
    background: var(--sidebar-light-theme-bg);
    border: 1px solid var(--sidebar-light-theme-border);
}

.preview-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.preview-item:last-child {
    margin-bottom: 0;
}

.preview-label {
    color: var(--color-text-secondary);
    font-family: var(--app-font-family);
    font-size: var(--font-size-sm);
    font-weight: 500;
}

.preview-value {
    color: var(--color-text-primary);
    font-family: var(--app-font-family);
    font-size: var(--font-size-sm);
    font-weight: 600;
}

body.light-theme .preview-label {
    color: var(--sidebar-light-theme-text-secondary);
}

body.light-theme .preview-value {
    color: var(--sidebar-light-theme-text);
}

/* 统计信息 */
.preview-stats {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--color-border-medium);
}

.stats-item {
    color: var(--color-text-secondary);
    font-family: var(--app-font-family);
    font-size: var(--font-size-xs);
    margin-bottom: 4px;
}

.stats-error {
    color: var(--color-error);
    font-family: var(--app-font-family);
    font-size: var(--font-size-xs);
    font-style: italic;
}

body.light-theme .preview-stats {
    border-top: 1px solid var(--sidebar-light-theme-border);
}

body.light-theme .stats-item {
    color: var(--sidebar-light-theme-text-secondary);
}

/* 修复：模板树区域布局 */
.template-tree-section {
    flex: 1;
    padding: var(--spacing-sm, 8px);
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0; /* 确保flex子元素高度计算正确 */
    background: transparent;
    overflow: hidden; /* 防止内容溢出 */
}

/* 修复：模板树区域亮色主题适配 */
body.light-theme .template-tree-section {
    background: transparent;
}

[data-theme="light"] .template-tree-section {
    background: transparent;
}

.template-tree-section h4 {
    color: var(--color-text-primary);
    font-family: var(--app-font-family);
    font-size: var(--font-size-base);
    font-weight: 600;
    margin: 0 0 16px 0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    flex-shrink: 0; /* 防止标题被压缩 */
}

body.light-theme .template-tree-section h4 {
    color: var(--sidebar-light-theme-text);
}

/* 修复：模板名称输入区域间距 */
.template-name-input {
    margin-bottom: 16px; /* 减少底部间距 */
    flex-shrink: 0; /* 防止被压缩 */
}

.template-name-input label {
    display: block;
    color: var(--color-text-primary);
    font-family: var(--app-font-family);
    font-size: var(--font-size-sm);
    font-weight: 500;
    margin-bottom: 6px;
}

.template-name-input input {
    width: 100%;
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border-medium);
    border-radius: var(--border-radius-sm);
    padding: 8px 12px;
    color: var(--color-text-primary);
    font-family: var(--app-font-family);
    font-size: var(--font-size-sm);
    outline: none;
    transition: border-color 0.2s ease;
    box-sizing: border-box;
}

.template-name-input input:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(0, 255, 65, 0.2);
}

body.light-theme .template-name-input label {
    color: var(--sidebar-light-theme-text);
}

body.light-theme .template-name-input input {
    background: var(--sidebar-light-theme-input-bg);
    border: 1px solid var(--sidebar-light-theme-input-border);
    color: var(--sidebar-light-theme-text);
}

body.light-theme .template-name-input input:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(255, 107, 53, 0.2);
}

/* 修复：模板树容器高度和边框显示问题 - 恢复类选择器 */
.template-tree-container {
    flex: 1;
    background: var(--color-bg-primary);
    border: 1px solid var(--color-border-medium);
    border-radius: var(--border-radius-sm);
    padding: 10px;
    overflow-y: auto;
    box-sizing: border-box;
}

body.light-theme .template-tree-container {
    background: var(--sidebar-light-theme-input-bg);
    border: 1px solid var(--sidebar-light-theme-input-border);
}

/* 修复：确保亮色主题下数据主题选择器也生效 */
[data-theme="light"] .template-tree-container {
    background: var(--sidebar-light-theme-input-bg);
    border: 1px solid var(--sidebar-light-theme-input-border);
}

/* 修复：添加更多亮色主题适配 */
[data-theme="light"] .template-info-section {
    background: var(--sidebar-light-theme-input-bg);
    border-right: 1px solid var(--sidebar-light-theme-border);
}

[data-theme="light"] .template-preview {
    background: var(--sidebar-light-theme-bg);
    border: 1px solid var(--sidebar-light-theme-border);
}

[data-theme="light"] .template-info-section h4,
[data-theme="light"] .template-tree-section h4 {
    color: var(--sidebar-light-theme-text);
}

[data-theme="light"] .preview-label {
    color: var(--sidebar-light-theme-text-secondary);
}

[data-theme="light"] .preview-value {
    color: var(--sidebar-light-theme-text);
}

[data-theme="light"] .stats-item {
    color: var(--sidebar-light-theme-text-secondary);
}

[data-theme="light"] .template-name-input label {
    color: var(--sidebar-light-theme-text);
}

[data-theme="light"] .template-name-input input {
    background: var(--sidebar-light-theme-input-bg);
    border: 1px solid var(--sidebar-light-theme-input-border);
    color: var(--sidebar-light-theme-text);
}

[data-theme="light"] .template-node-name {
    color: var(--sidebar-light-theme-text);
}

[data-theme="light"] .tree-toggle {
    color: var(--sidebar-light-theme-text-secondary);
}

/* 修复：滚动条样式适配 - 恢复类选择器 */
.template-tree-container::-webkit-scrollbar {
    width: 8px;
}

.template-tree-container::-webkit-scrollbar-track {
    background: var(--color-bg-secondary);
    border-radius: 4px;
}

.template-tree-container::-webkit-scrollbar-thumb {
    background: var(--color-border-medium);
    border-radius: 4px;
}

.template-tree-container::-webkit-scrollbar-thumb:hover {
    background: var(--color-text-secondary);
}

.template-info-section::-webkit-scrollbar {
    width: 8px;
}

.template-info-section::-webkit-scrollbar-track {
    background: var(--color-bg-secondary);
    border-radius: 4px;
}

.template-info-section::-webkit-scrollbar-thumb {
    background: var(--color-border-medium);
    border-radius: 4px;
}

.template-info-section::-webkit-scrollbar-thumb:hover {
    background: var(--color-text-secondary);
}

/* 亮色主题滚动条适配 - 恢复类选择器 */
body.light-theme .template-tree-container::-webkit-scrollbar-track,
body.light-theme .template-info-section::-webkit-scrollbar-track {
    background: var(--sidebar-light-theme-border);
}

body.light-theme .template-tree-container::-webkit-scrollbar-thumb,
body.light-theme .template-info-section::-webkit-scrollbar-thumb {
    background: var(--sidebar-light-theme-text-secondary);
}

body.light-theme .template-tree-container::-webkit-scrollbar-thumb:hover,
body.light-theme .template-info-section::-webkit-scrollbar-thumb:hover {
    background: var(--sidebar-light-theme-text);
}

[data-theme="light"] .template-tree-container::-webkit-scrollbar-track,
[data-theme="light"] .template-info-section::-webkit-scrollbar-track {
    background: var(--sidebar-light-theme-border);
}

[data-theme="light"] .template-tree-container::-webkit-scrollbar-thumb,
[data-theme="light"] .template-info-section::-webkit-scrollbar-thumb {
    background: var(--sidebar-light-theme-text-secondary);
}

[data-theme="light"] .template-tree-container::-webkit-scrollbar-thumb:hover,
[data-theme="light"] .template-info-section::-webkit-scrollbar-thumb:hover {
    background: var(--sidebar-light-theme-text);
}

/* 模板树样式 */
.template-tree {
    list-style: none;
    padding: 0;
    margin: 0;
    font-family: var(--app-font-family);
}

.template-tree-node {
    margin: 0;
    padding: 0;
    position: relative;
}

.template-node-content {
    display: flex;
    align-items: center;
    padding: 6px 8px;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
}

.template-node-content:hover {
    background: rgba(0, 255, 65, 0.1);
}

.template-tree-node.selected > .template-node-content {
    background: rgba(255, 107, 53, 0.12);
    border: 1px solid rgba(255, 107, 53, 0.35);
}

/* 树节点展开/折叠图标 */
.tree-toggle {
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 6px;
    font-size: 10px;
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: color 0.2s ease;
}

.tree-toggle:hover {
    color: var(--color-primary);
}

body.light-theme .tree-toggle {
    color: var(--sidebar-light-theme-text-secondary);
}

body.light-theme .tree-toggle:hover {
    color: var(--color-primary);
}

.tree-spacer {
    width: 16px;
    height: 16px;
    margin-right: 6px;
}

/* 节点名称 */
.template-node-name {
    color: var(--color-text-primary);
    font-size: var(--font-size-sm);
    font-weight: 500;
    flex: 1;
}

body.light-theme .template-node-name {
    color: var(--sidebar-light-theme-text);
}

/* 子节点容器 */
.template-tree-children {
    list-style: none;
    padding: 0;
    margin: 0 0 0 20px;
    border-left: 1px dotted var(--color-border-medium);
    position: relative;
}

body.light-theme .template-tree-children {
    border-left: 1px dotted var(--sidebar-light-theme-border);
}

.template-tree-node.collapsed .template-tree-children {
    display: none;
}

/* 树错误状态 */
.tree-error {
    color: var(--color-error);
    font-family: var(--app-font-family);
    font-size: var(--font-size-sm);
    text-align: center;
    padding: 20px;
    font-style: italic;
}

/* 对话框底部 */
.template-selection-modal .modal-footer {
    background: transparent;
    border-top: 1px solid var(--color-border-medium);
    padding: 16px 20px;
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    border-radius: 0 0 var(--border-radius) var(--border-radius);
}

body.light-theme .template-selection-modal .modal-footer {
    background: transparent;
    border-top: 1px solid var(--sidebar-light-theme-border);
}

/* 按钮样式 */
.template-selection-modal .btn {
    padding: 8px 16px;
    border: 1px solid transparent;
    border-radius: var(--border-radius-sm);
    font-family: var(--app-font-family);
    font-size: var(--font-size-sm);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    outline: none;
    user-select: none;
}

.template-selection-modal .btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.template-selection-modal .btn-secondary {
    background: transparent;
    border-color: var(--color-border-medium);
    color: var(--color-text-secondary);
}

.template-selection-modal .btn-secondary:hover:not(:disabled) {
    background: var(--color-bg-primary);
    border-color: var(--color-text-secondary);
    color: var(--color-text-primary);
}

body.light-theme .template-selection-modal .btn-secondary {
    border-color: var(--sidebar-light-theme-border);
    color: var(--sidebar-light-theme-text-secondary);
}

body.light-theme .template-selection-modal .btn-secondary:hover:not(:disabled) {
    background: var(--sidebar-light-theme-input-bg);
    border-color: var(--sidebar-light-theme-text-secondary);
    color: var(--sidebar-light-theme-text);
}

.template-selection-modal .btn-primary {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: var(--color-text-inverse);
}

.template-selection-modal .btn-primary:hover:not(:disabled) {
    background: #00e040;
    border-color: #00e040;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 255, 65, 0.3);
}

.template-selection-modal .btn-primary:active {
    transform: translateY(0);
    box-shadow: none;
}

/* 响应式适配 */
@media (max-width: 768px) {
    .template-selection-modal {
        width: 95vw;
        height: 80vh;
        min-width: 320px;
    }

    .template-selection-content {
        flex-direction: column;
    }

    .template-info-section {
        flex: 0 0 auto;
        border-right: none;
        border-bottom: 1px solid var(--color-border);
        padding: 16px;
    }

    .template-tree-section {
        padding: 16px;
    }
}

/* 动画效果 */
.modal-overlay {
    animation: fadeIn 0.2s ease;
}

.template-selection-modal {
    animation: scaleIn 0.2s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}
