:root {
    --primary: #667eea;
    --primary-dark: #5a67d8;
    --secondary: #e2e8f0;
    --danger: #e74c3c;
    --bg-color: #f5f7fa;
    --sidebar-width: 320px;
    --text-color: #2c3e50;
    --border-color: #cbd5e1;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    overflow: hidden;
    height: 100vh;
}

/* 布局 */
.app-container { display: flex; height: 100vh; width: 100vw; position: relative; }

/* 侧边栏 */
.sidebar {
    width: var(--sidebar-width);
    background: white;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    z-index: 20;
    box-shadow: 2px 0 10px rgba(0,0,0,0.03);
    transition: transform 0.3s ease;
    flex-shrink: 0;
}

.sidebar.closed { transform: translateX(-100%); position: absolute; height: 100%; }

.sidebar-header {
    padding: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.brand { font-size: 1.2rem; font-weight: bold; margin-bottom: 10px; display: flex; justify-content: space-between; align-items: center;}

.project-control { display: flex; flex-direction: column; gap: 8px; }

.project-select {
    width: 100%; padding: 8px; border-radius: 4px; border: 1px solid rgba(255,255,255,0.2);
    background: rgba(255,255,255,0.1); color: white; font-size: 0.9rem; cursor: pointer;
}
.project-select option { background: #333; color: white; }

.btn-group-mini { display: flex; gap: 5px; justify-content: flex-end; }

.btn-icon {
    background: rgba(255,255,255,0.15); border: 1px solid rgba(255,255,255,0.2);
    color: white; border-radius: 4px; width: 32px; height: 32px; cursor: pointer;
    display: flex; align-items: center; justify-content: center; font-size: 1rem;
    transition: all 0.2s;
}
.btn-icon:hover { background: rgba(255,255,255,0.3); }
.btn-icon.danger:hover { background: rgba(231, 76, 60, 0.8); }

.sidebar-content { flex: 1; overflow-y: auto; padding: 10px; }
.sidebar-footer { padding: 15px; border-top: 1px solid var(--border-color); }

/* --- 资源树状列表 --- */
.res-list { display: flex; flex-direction: column; gap: 2px; height: 100%; }

/* 拖拽视觉反馈 */
.drag-over {
    border: 2px dashed var(--primary) !important;
    background-color: #eef2ff !important;
}
.dragging {
    opacity: 0.5;
}

/* 文件夹行 */
.res-folder {
    display: flex; align-items: center; padding: 8px; margin-bottom: 2px;
    border-radius: 6px; cursor: pointer; font-weight: 600; color: #475569;
    background: transparent; border: 2px solid transparent; /* 预留边框位置防止抖动 */
}
.res-folder:hover { background: #f1f5f9; }
.res-folder .folder-icon { margin-right: 6px; transition: transform 0.2s; font-size: 1rem; }
.res-folder.open .folder-icon { transform: rotate(90deg); }

/* 文件夹内容容器 */
.folder-children {
    display: none;
    padding-left: 14px; /* 缩进 */
    border-left: 1px solid #e2e8f0;
    margin-left: 9px;
}
.folder-children.open { display: block; }

/* 资源行 */
.res-item {
    display: flex; align-items: center; padding: 8px; margin-bottom: 2px;
    background: white; border: 1px solid transparent; border-radius: 6px;
    cursor: grab; transition: all 0.2s; position: relative;
}
.res-item:active { cursor: grabbing; }
.res-item:hover { border-color: var(--primary); background: #f8fafc; }

.res-icon { margin-right: 8px; font-size: 1.1rem; width: 20px; text-align: center; }
.res-info { flex: 1; overflow: hidden; margin-right: 5px; }
.res-name { font-size: 0.85rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* 资源操作按钮 */
.res-actions { display: none; gap: 4px; }
.res-item:hover .res-actions, .res-folder:hover .res-actions { display: flex; }

.btn-res-action {
    background: white; border: 1px solid var(--border-color); color: #64748b;
    width: 22px; height: 22px; border-radius: 4px; font-size: 0.75rem;
    display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.btn-res-action:hover { background: var(--primary); color: white; border-color: var(--primary); }
.btn-res-action.del:hover { background: var(--danger); border-color: var(--danger); }

.empty-tip { text-align: center; color: #94a3b8; font-size: 0.9rem; margin-top: 20px; }

/* 主区域 & 工具栏 */
.main-area { flex: 1; display: flex; flex-direction: column; position: relative; overflow: hidden; }

.toolbar {
    min-height: 50px; background: white; border-bottom: 1px solid var(--border-color);
    display: flex; align-items: center; padding: 5px 15px; gap: 10px;
    z-index: 10; flex-wrap: wrap;
}

.project-title-input {
    border: 1px solid transparent; background: transparent; font-size: 1rem; font-weight: bold;
    color: var(--text-color); padding: 5px 10px; border-radius: 4px; min-width: 120px; max-width: 200px;
    transition: all 0.2s;
}
.project-title-input:hover { background: #f1f5f9; border-color: #e2e8f0; }
.project-title-input:focus { background: white; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1); }
.project-title-input:disabled { opacity: 0.5; cursor: not-allowed; }

.divider { width: 1px; height: 20px; background: var(--border-color); margin: 0 5px; }
.spacer { flex: 1; }
.status-text { font-size: 0.8rem; color: #94a3b8; margin-right: 10px; white-space: nowrap; }

/* 通用按钮 */
.tool-btn { padding: 6px 12px; border: 1px solid var(--border-color); background: white; border-radius: 4px; cursor: pointer; font-size: 0.9rem; transition: background 0.2s; white-space: nowrap; }
.tool-btn:hover { background: #f1f5f9; }
.tool-btn.primary { background: var(--primary); color: white; border-color: var(--primary); }
.tool-btn.danger { color: var(--danger); border-color: #fecaca; background: #fef2f2; }
.tool-btn.danger:hover { background: #fee2e2; }

.btn-primary { background: var(--primary); color: white; border: none; padding: 10px 20px; border-radius: 6px; cursor: pointer; font-weight: 500; }
.btn-secondary { background: white; color: var(--text-color); border: 1px solid var(--border-color); padding: 10px 20px; border-radius: 6px; cursor: pointer; font-weight: 500; }
.btn-secondary:hover { background: #f1f5f9; }
.btn-primary.small { padding: 5px 10px; font-size: 0.85rem; }
.btn-danger { background: var(--danger); color: white; border: none; padding: 5px 10px; border-radius: 6px; cursor: pointer; }
.btn-text { background: none; border: none; color: #64748b; cursor: pointer; padding: 10px; }
.full-width { width: 100%; }

/* 画布 */
.canvas-wrapper { flex: 1; position: relative; overflow: hidden; background-image: radial-gradient(#cbd5e1 1px, transparent 1px); background-size: 20px 20px; background-color: #f8fafc; }
canvas { display: block; width: 100%; height: 100%; cursor: grab; touch-action: none; }
canvas:active { cursor: grabbing; }

/* 弹窗 */
.modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); z-index: 100; display: flex; align-items: center; justify-content: center; backdrop-filter: blur(2px); }
.modal-box { background: white; width: 450px; max-width: 90%; padding: 25px; border-radius: 12px; box-shadow: 0 10px 25px rgba(0,0,0,0.1); }
.form-group { margin-bottom: 15px; }
.form-group label { display: block; margin-bottom: 6px; font-size: 0.9rem; font-weight: 600; color: #475569; }
.form-input { width: 100%; padding: 8px 12px; border: 1px solid var(--border-color); border-radius: 6px; font-size: 0.95rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* 节点菜单 */
.node-menu { position: absolute; background: white; padding: 15px; border-radius: 8px; box-shadow: 0 5px 20px rgba(0,0,0,0.15); border: 1px solid var(--border-color); width: 240px; z-index: 50; }
.menu-actions { display: flex; gap: 10px; margin-top: 10px; }

/* Toast */
.toast { position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%); background: rgba(30, 41, 59, 0.9); color: white; padding: 10px 20px; border-radius: 30px; font-size: 0.9rem; opacity: 0; pointer-events: none; transition: opacity 0.3s; z-index: 200; }
.toast.show { opacity: 1; }

@media (max-width: 768px) {
    .sidebar { position: absolute; width: 100%; height: 100%; transform: translateX(-100%); transition: transform 0.3s ease; }
    .sidebar.closed { transform: translateX(-100%); }
    .sidebar:not(.closed) { transform: translateX(0); }
    .toolbar { padding: 10px; gap: 8px; }
    .status-text { display: none; }
    .tool-btn { flex: 1; padding: 8px 5px; font-size: 0.8rem; display: flex; justify-content: center; }
    .spacer { display: none; }
    .project-title-input { flex: 2; width: auto; font-size: 0.9rem; min-width: 80px; }
    .res-actions { display: flex; }
}