/* ==========================================
   🏛️ 悬浮外挂侧边栏（Fixed 脱离文档流）
   ========================================== */

.template-sidebar {
    position: fixed;
    left: calc(50% - 500px - 220px - 20px); /* 算法：屏幕中点 - 1000px版心一半 - 侧边栏自身宽度 - 间隙 */
    top: 100px;
    width: 220px;
    background: #fff;
    border: 1px solid #c2d1e5;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    z-index: 100;
    
    display: flex;
    flex-direction: column;
    
    /* 核心精髓：内容少时自适应，内容多时最大占屏幕高度 70% 锁死 */
    max-height: 70vh; 
    overflow: hidden;
    animation: slideInLeft 0.3s ease-out;
}

@keyframes slideInLeft {
    from { opacity: 0; transform: translateX(-20px); }
    to { opacity: 1; transform: translateX(0); }
}

/* 当屏幕小于 1480px 时（侧边栏会撞上版心内容），我们把它优雅地隐藏，或者通过媒体查询改变位置 */
@media (max-width: 1480px) {
    .template-sidebar {
        position: static; /* 回归普通文档流 */
        width: 100%;
        max-height: 300px;
        margin-bottom: 20px;
    }
}

.sidebar-header {
    background-color: #eef3f9;
    border-bottom: 1px solid #c2d1e5;
    padding: 10px 15px;
    font-size: 14px;
    color: #003366;
    font-weight: bold;
    flex-shrink: 0;
}

.template-list {
    flex: 1;
    overflow-y: auto; /* 核心：超过最大高度自动出滚动条 */
    padding: 12px;
}

/* 模板卡片 */
.template-card {
    background: #fafafa;
    border: 1px solid #c2d1e5;
    border-radius: 4px;
    padding: 12px;
    margin-bottom: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.template-card:last-child {
    margin-bottom: 0;
}

.template-card:hover {
    background-color: #fffdf4;
    border-color: #ff9900;
    transform: translateY(-1px);
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

.template-card-title {
    font-size: 13px;
    font-weight: bold;
    color: #003366;
    margin-bottom: 4px;
    font-family: "SimHei", sans-serif;
}

.template-card-desc {
    font-size: 12px;
    color: #666;
    line-height: 1.4;
    font-family: "SimSun", serif;
    text-align: justify;
}


/* ==========================================
   ⚖️ 主体 1:1 对照区（不受侧边栏挤压）
   ========================================== */
.workspace-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    height: calc(100vh - 280px);
    min-height: 550px;
}

@media (max-width: 768px) {
    .workspace-grid {
        grid-template-columns: 1fr;
        height: auto;
    }
}

.workspace-grid .content-panel {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    background: #fff;
    border: 1px solid #c2d1e5;
    border-radius: 4px;
}

.tree-container, .code-preview-container {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
}

.top-bar-actions {
    padding: 10px 15px;
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
    background: #fff;
    border: 1px solid #c2d1e5;
    border-radius: 4px;
}


/* ==========================================
   🧩 节点可视化积木组件规范
   ========================================== */
.node-item {
    background: #fafafa;
    border: 1px solid #c2d1e5;
    border-radius: 4px;
    padding: 10px;
    margin-bottom: 10px;
    position: relative;
    font-family: sans-serif;
}

.node-item:hover {
    background-color: #fffdf4;
    border-color: #ff9900;
}

.node-header {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.node-drag-handle {
    cursor: move;
    color: #888;
    user-select: none;
    font-weight: bold;
}

.node-key-input { width: 140px; font-weight: bold; color: #003366; padding: 4px 6px; border: 1px solid #ccc; border-radius: 3px; font-size: 13px;}
.node-value-input { width: 150px; padding: 4px 6px; border: 1px solid #ccc; border-radius: 3px; font-size: 13px;}

.node-type-select {
    padding: 3px;
    font-size: 13px;
    border: 1px solid #ccc;
    border-radius: 3px;
}

.node-children {
    margin-top: 10px;
    padding-left: 20px;
    border-left: 2px dashed #c2d1e5;
}

.code-preview-container {
    background-color: #282c34;
    color: #abb2bf;
    font-family: "Consolas", "Courier New", monospace;
    font-size: 14px;
    line-height: 1.5;
}

#json-code-output {
    white-space: pre-wrap;
    word-break: break-all;
}

.bottom-sticky-bar {
    background: #fff;
    border: 1px solid #c2d1e5;
    padding: 15px 20px;
    margin-top: 20px;
    border-radius: 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 -2px 5px rgba(0,0,0,0.05);
}

.status-tip {
    font-size: 13px;
    color: #666;
    font-family: "SimSun", serif;
}

.action-buttons {
    display: flex;
    gap: 15px;
}

/* --- 💾 底部粘性操作栏拟物按钮 --- */
.bottom-sticky-bar .action-buttons {
    display: flex;
    gap: 15px;
}

/* ==========================================
   ⚙️ 尺寸微调（给小积木块里的按钮瘦身）
   ========================================== */
.btn-clay-sm {
    padding: 2px 8px !important;
    font-size: 12px !important;
    border-radius: 3px !important;
}

/* ==========================================
   ⚪ 拟物浅银蓝：导入现有 JSON (优雅、不刺眼)
   ========================================== */
.btn-clay-silver-blue {
    background: linear-gradient(to bottom, #f0f4f8, #d9e2ec);
    color: #334e68 !important; /* 深蓝灰色文字，阅读更舒适 */
    border: 1px solid #bcccdc;
}

.btn-clay-silver-blue:hover {
    background: linear-gradient(to bottom, #f7f9fc, #e1e7ed);
    border-color: #9fb3c8;
}

/* ==========================================
   🔴 拟物红大号：清空重置画布 (醒目警示)
   ========================================== */
.btn-clay-danger-large {
    background: linear-gradient(to bottom, #d9534f, #c9302c);
    color: #ffffff !important;
    border: 1px solid #ac2925;
}

.btn-clay-danger-large:hover {
    background: linear-gradient(to bottom, #e06e6a, #d24e4a);
}

/* 基础拟物按钮类 */
.btn-clay {
    display: inline-block;
    padding: 10px 24px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15), inset 0 1px 0 rgba(255, 255, 255, 0.4);
    text-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
}

.btn-clay:active {
    transform: translateY(1px);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15), inset 0 1px 3px rgba(0, 0, 0, 0.3);
}

/* 移除按钮点击后的聚焦轮廓 */
.btn-clay:focus {
    outline: none !important;
}

/* ==========================================
   🔴 拟物红：危险/删除操作 (你要的删除按钮)
   ========================================== */
.btn-clay-danger {
    background: linear-gradient(to bottom, #d9534f, #c9302c); /* 红色渐变 */
    color: #ffffff !important; /* 强制白色文字 */
    border: 1px solid #ac2925; /* 深红色边框 */
}

.btn-clay-danger:hover {
    background: linear-gradient(to bottom, #e06e6a, #d24e4a); /* 悬停时稍微变亮 */
    border-color: #ac2925;
}

/* 🟢 拟物绿：保存至本地沙盒缓存 */
.btn-clay-save {
    background: linear-gradient(to bottom, #5cb85c, #449d44);
    color: #ffffff;
    border: 1px solid #398439;
}

.btn-clay-save:hover {
    background: linear-gradient(to bottom, #67c167, #4cae4c);
}

/* 🔵 拟物蓝：下载标准 JSON 文件 */
.btn-clay-download {
    background: linear-gradient(to bottom, #2585c4, #1a6296);
    color: #ffffff;
    border: 1px solid #15517e;
}

.btn-clay-download:hover {
    background: linear-gradient(to bottom, #2a96dc, #1e71ad);
}

/* 移除按钮点击后的聚焦轮廓 */
.bottom-sticky-bar button:focus,
.action-buttons button:focus {
    outline: none !important;
    box-shadow: none !important;
}

/* 拖拽块的透明度 */
.node-item.dragging {
    opacity: 0.35;
    border: 1px dashed #666;
}

/* 蓝色悬浮轮廓线：标识落点 */
.node-item.drag-over {
    background-color: #f0f8ff !important;
    outline: 2px dashed #003366;
    outline-offset: -2px;
}

/* 💡 上方预备排序：产生顶端描边 */
.node-item.drag-over-top {
    border-top: 3px solid #409eff !important;
}

/* 💡 下方预备排序：产生底端描边 */
.node-item.drag-over-bottom {
    border-bottom: 3px solid #409eff !important;
}