/* 全局样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #f5f5f5;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* 头部样式 */
header {
    text-align: center;
    margin-bottom: 30px;
}

header h1 {
    color: #2c3e50;
    font-size: 2.5em;
}

/* 面板布局 */
.panels {
    display: flex;
    gap: 20px;
    min-height: 600px;
    height: calc(100vh - 150px); /* 使用视口高度减去头部和边距 */
    overflow: hidden; /* 防止内容溢出 */
}

.panel {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    padding: 20px;
}

.template-panel {
    flex: 1;
    min-width: 300px;
    display: flex;
    flex-direction: column;
}

.variable-panel {
    flex: 2;
    display: flex;
    flex-direction: column;
    overflow: hidden; /* 确保内容不会溢出 */
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px; /* 减少底部边距 */
}

/* 模板树样式 */
.template-tree, .task-blocks {
    margin-top: 10px;
    overflow-y: auto;
    flex: 1;
    border: 1px solid #eee;
    border-radius: 4px;
    background-color: #fff;
}

.template-tree ul {
    list-style: none;
    padding: 0;
}

.template-tree li {
    margin: 0;
}

.template-tree .category {
    font-weight: bold;
    color: #2c3e50;
    border-bottom: 1px solid #eee;
    padding: 10px 15px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #f9f9f9;
    transition: background-color 0.2s;
}

.template-tree .category:hover {
    background-color: #f0f0f0;
}

.template-tree .category::after {
    content: '▼';
    font-size: 12px;
    color: #666;
    transition: transform 0.3s;
}

.template-tree .category.collapsed::after {
    transform: rotate(-90deg);
}

.template-tree .templates-container {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
}

.template-tree .templates-container.expanded {
    max-height: 500px; /* 根据实际内容调整 */
}

.template-tree .template {
    padding: 8px 15px 8px 25px;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    transition: background-color 0.2s;
}

.template-tree .template:hover {
    background-color: #f0f0f0;
}

.template-tree .template.selected {
    background-color: #e3f2fd;
    color: #1976d2;
}

/* 搜索框样式 */
.template-search {
    margin-bottom: 10px;
    position: relative;
    flex-shrink: 0;
}

.template-search input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.template-search input:focus {
    outline: none;
    border-color: #2196f3;
    box-shadow: 0 0 0 2px rgba(33,150,243,0.1);
}

.template-search .search-icon {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: #666;
}

/* 变量表单样式 */
.variable-form {
    margin-bottom: 20px;
    width: 100%;
    display: flex; /* Enable flex layout */
    flex-wrap: wrap; /* Allow items to wrap to the next line */
    gap: 15px 20px; /* Add row and column gaps */
}

.variable-form .form-group {
    margin-bottom: 0; /* Remove bottom margin as gap handles spacing */
    width: calc(50% - 10px); /* Set width for two columns, accounting for gap */
}

.variable-form label {
    display: block;
    margin-bottom: 5px;
    color: #666;
}

.variable-form input {
    width: 100%;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.variable-form input:focus {
    outline: none;
    border-color: #2196f3;
    box-shadow: 0 0 0 2px rgba(33,150,243,0.1);
}

/* 已选模板列表样式 */
.selected-templates {
    margin-bottom: 5px; /* 减少底部边距 */
}

.template-list {
    list-style: none;
    margin-top: 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.template-list li {
    display: flex;
    align-items: center;
    padding: 4px 10px;
    background: #e3f2fd;
    border-radius: 16px;
    font-size: 14px;
    border: 1px solid #bbdefb;
    color: #1976d2;
    white-space: nowrap;
}

.template-list .remove-btn {
    color: #1976d2;
    cursor: pointer;
    margin-left: 6px;
    font-size: 16px;
    font-weight: bold;
}

.template-list .remove-btn:hover {
    color: #dc3545;
}

/* 预览区域样式 */
.preview {
    flex: 1;
    margin-bottom: 5px; /* 减少底部边距 */
    display: flex;
    flex-direction: column;
    min-height: 0; /* 允许flex子元素收缩 */
    overflow: hidden;
}

.preview h3 {
    margin-bottom: 5px;
    flex-shrink: 0; /* 防止标题被压缩 */
}

.preview-header {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 5px;
    flex-shrink: 0;
}

.preview-content {
    background: #f8f9fa;
    padding: 15px;
    border-radius: 4px;
    font-family: monospace;
    white-space: pre-wrap;
    flex: 1; /* 填充剩余空间 */
    min-height: 250px; /* 增加最小高度 */
    overflow-y: auto;
    border: 1px solid #eee;
    outline: none; /* 移除可编辑状态下的默认轮廓线 */
}

.preview-content[contenteditable="true"] {
    background: #fff;
    border: 1px solid #2196f3;
    box-shadow: 0 0 0 2px rgba(33,150,243,0.1);
    cursor: text;
}

/* 编辑按钮样式 */
.btn.edit {
    background-color: #4caf50; /* 绿色背景 */
    color: white;
}

.btn.edit:hover {
    background-color: #43a047;
}

.btn.save-edit {
    background-color: #2196f3; /* 蓝色背景 */
    color: white;
}

.btn.cancel-edit {
    background-color: #f44336; /* 红色背景 */
    color: white;
}

.btn.cancel-edit:hover {
    background-color: #e53935;
}

/* 按钮样式 */
.actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 5px; /* 减少顶部边距 */
    flex-shrink: 0; /* 防止按钮被压缩 */
}

.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.2s;
}

.btn.primary {
    background-color: #2196f3;
    color: white;
}

.btn.primary:hover {
    background-color: #1976d2;
}

.btn.variable {
    background-color: #ff9800; /* 橙色背景 */
    color: white;
    font-weight: 500;
}

.btn.variable:hover {
    background-color: #f57c00; /* 深橙色 */
}

.btn:not(.primary):not(.variable) {
    background-color: #e0e0e0;
    color: #333;
}

.btn:not(.primary):not(.variable):hover {
    background-color: #d5d5d5;
}

/* 模态窗口样式 */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    z-index: 1000;
    overflow: hidden;
}

.modal-content {
    position: relative;
    background-color: white;
    margin: 10% auto;
    padding: 0;
    width: 80%;
    max-width: 600px;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

.modal-header {
    padding: 15px 20px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    color: #2c3e50;
}

.modal-header .close {
    color: #666;
    font-size: 24px;
    cursor: pointer;
}

.modal-header .close:hover {
    color: #333;
}

.modal-body {
    padding: 20px;
    max-height: 60vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch; /* 提高移动设备滚动体验 */
}

.modal-footer {
    padding: 15px 20px;
    border-top: 1px solid #eee;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .panels {
        flex-direction: column;
    }
    
    .template-panel,
    .variable-panel {
        width: 100%;
    }
    
    .modal-content {
        width: 95%;
        margin: 5% auto;
    }
}

/* Add styles for smaller screens if needed */
@media (max-width: 600px) {
    .variable-form .form-group {
        width: 100%; /* Stack variables on smaller screens */
    }
}

/* 选项卡样式 */
.tabs-nav {
    display: flex;
    background-color: #f1f1f1;
    border-top-left-radius: 6px;
    border-top-right-radius: 6px;
    overflow: hidden;
    margin: 0;
    position: relative;
    z-index: 1;
}

.tab-btn {
    flex: 1;
    padding: 10px 16px;
    background: #eee;
    border: none;
    cursor: pointer;
    font-size: 15px;
    font-weight: 500;
    color: #666;
    transition: all 0.2s;
    border-bottom: 1px solid #ddd;
    position: relative;
    text-align: center;
}

.tab-btn:first-child {
    border-right: 1px solid #ddd;
}

.tab-btn:hover {
    background-color: #e9e9e9;
    color: #2196f3;
}

.tab-btn.active {
    background-color: #fff;
    color: #2196f3;
    border-bottom-color: #fff;
}

.tab-btn.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 2px;
    background-color: #2196f3;
}

.tabs-content {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    background-color: #fff;
    border: 1px solid #ddd;
    border-top: none;
    border-radius: 0 0 6px 6px;
    margin-top: -1px;
    padding: 15px;
}

.tab-pane {
    display: none;
    flex: 1;
    flex-direction: column;
    overflow: hidden;
}

.tab-pane.active {
    display: flex;
}

/* 任务块样式 */
.task-blocks {
    margin-top: 10px;
    overflow-y: auto;
    flex: 1;
}

.task-block {
    padding: 10px 15px;
    border-bottom: 1px solid #eee;
    cursor: pointer;
    transition: background-color 0.2s;
}

.task-block:hover {
    background-color: #f0f0f0;
}

.task-block.active {
    background-color: #e3f2fd;
    color: #1976d2;
}

/* 预览高亮样式 */
.preview-content .highlight {
    background-color: #fff9c4;
    border-radius: 3px;
    padding: 2px 0;
}

/* 修改模板面板,使其支持选项卡 */
#templates-tab, #blocks-tab {
    padding: 0;
}

/* 预设管理样式 */
.preset-action {
    margin-bottom: 20px;
    border-bottom: 1px solid #eee;
    padding-bottom: 15px;
}

.preset-save-form {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}

.preset-save-form input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.preset-save-form input:focus {
    outline: none;
    border-color: #2196f3;
    box-shadow: 0 0 0 2px rgba(33,150,243,0.1);
}

.preset-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 300px;
    overflow-y: auto;
}

.preset-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px;
    background-color: #f8f9fa;
    border-radius: 4px;
    border: 1px solid #eee;
}

.preset-item:hover {
    background-color: #e9ecef;
}

.preset-name {
    font-weight: 500;
    flex: 1;
}

.preset-actions {
    display: flex;
    gap: 8px;
}

.preset-load-btn {
    color: #2196f3;
    cursor: pointer;
    padding: 5px 10px;
    background-color: #e3f2fd;
    border-radius: 4px;
    font-size: 14px;
}

.preset-load-btn:hover {
    background-color: #bbdefb;
}

.preset-delete-btn {
    color: #f44336;
    cursor: pointer;
    padding: 5px 10px;
    background-color: #ffebee;
    border-radius: 4px;
    font-size: 14px;
}

.preset-delete-btn:hover {
    background-color: #ffcdd2;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .preset-save-form {
        flex-direction: column;
    }
    
    .preset-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    
    .preset-actions {
        width: 100%;
        justify-content: flex-end;
    }
}