/* ========== 模板管理特有样式 ========== */  

.template-nav-submenu {
    display: none;
    padding: 0;
}

.template-nav-item.expanded .template-nav-submenu {
    display: block;
}

.template-nav-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 38px;
    padding: 6px 0;
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 600;
}

.template-nav-header .btn-icon,
.template-nav-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 0;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--surface-color);
    color: var(--text-secondary);
    cursor: pointer;
}

.template-category-control {
    position: relative;
    flex: 0 0 auto;
}

#template-manager-view [hidden] {
    display: none !important;
}

.template-category-filter {
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-width: 150px;
    height: 36px;
    padding: 0 12px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--surface-color);
    color: var(--text-secondary);
    cursor: pointer;
}

.template-category-filter:hover,
.template-category-filter[aria-expanded="true"] {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.template-category-popover {
    position: absolute;
    z-index: 40;
    top: calc(100% + 8px);
    left: 0;
    width: 280px;
    padding: 8px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--surface-color);
    box-shadow: 0 10px 28px rgba(15, 23, 42, 0.14);
}

.template-category-popover[hidden] {
    display: none;
}

.template-category-popover-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 38px;
    padding: 2px 4px 8px 8px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
    font-size: 13px;
}

.template-category-popover .sidebar-tree {
    max-height: 320px;
    padding-top: 8px;
    overflow-y: auto;
}

.template-category-popover .tree-item {
    padding: 8px 10px;
}

.template-category-actions {
    display: inline-flex;
    gap: 2px;
    margin-left: auto;
}

.template-category-actions button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    padding: 0;
    border: 0;
    border-radius: 3px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
}

.template-category-actions button:hover {
    background: var(--hover-color);
    color: var(--primary-color);
}

.template-nav-header .btn-icon:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.template-nav-submenu .template-scope-switch {
    display: block;
    padding: 0;
    border: 0;
}

.template-nav-submenu .template-scope-btn {
    width: 100%;
    height: auto;
    min-height: 36px;
    justify-content: flex-start;
    padding: 8px 16px 8px 48px;
    border: 0;
    border-left: 3px solid transparent;
    border-radius: 0;
    background: transparent;
    font-size: 14px;
}

.template-nav-submenu .template-scope-btn.active {
    border-left-color: var(--primary-color);
    background: rgba(var(--primary-color-rgb), 0.1);
}

.template-nav-submenu .scope-count {
    margin-left: auto;
}

.template-nav-submenu .sidebar-tree {
    overflow: visible;
}

.template-nav-submenu .tree-item {
    min-height: 36px;
    margin: 0;
    padding: 8px 16px 8px 48px;
    border-left: 3px solid transparent;
    border-radius: 0;
    font-size: 14px;
}

.template-nav-submenu .tree-item.active {
    border-left-color: var(--primary-color);
    background: rgba(var(--primary-color-rgb), 0.1);
    color: var(--primary-color);
}

.template-add-category {
    width: 100%;
    justify-content: space-between;
    border: 0;
    background: transparent;
    cursor: pointer;
}

.template-nav-toggle {
    display: none;
    flex: 0 0 34px;
    width: 34px;
    height: 34px;
}

.template-scope-switch {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-color);
}

.template-view-scope {
    display: inline-flex;
    flex: 0 0 auto;
    gap: 2px;
    padding: 3px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--background-color);
}

.template-view-scope .template-scope-btn {
    min-height: 34px;
    padding: 0 12px;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
}

.template-view-scope .template-scope-btn.active {
    background: var(--surface-color);
    color: var(--primary-color);
    box-shadow: 0 1px 3px rgba(35, 55, 80, 0.12);
}

.template-view-scope .scope-count {
    margin-left: 4px;
    font-size: 12px;
}

@media (max-width: 768px) {
    .sidebar:has(.template-nav-item.mobile-open) {
        z-index: 35;
        overflow: visible;
    }

    .template-nav-toggle {
        display: inline-flex;
    }

    .template-nav-item .template-nav-submenu,
    .template-nav-item.expanded .template-nav-submenu {
        display: none;
    }

    .template-nav-item.mobile-open .template-nav-submenu {
        position: fixed;
        z-index: 30;
        top: var(--header-height);
        bottom: var(--footer-height);
        left: 56px;
        display: block;
        width: min(260px, calc(100vw - 56px));
        padding: 12px 0;
        overflow-y: auto;
        background: var(--surface-color);
        border-right: 1px solid var(--border-color);
        box-shadow: 8px 0 20px rgba(15, 23, 42, 0.12);
    }

    .template-category-control {
        min-width: 0;
    }

    .template-category-filter {
        min-width: 0;
        max-width: 132px;
    }

    .template-category-popover {
        position: fixed;
        top: auto;
        right: 12px;
        bottom: 12px;
        left: 68px;
        width: auto;
        max-height: 70vh;
    }
}

.template-scope-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-width: 0;
    height: 34px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--surface-color);
    color: var(--text-secondary);
    cursor: pointer;
}

.template-scope-btn.active {
    border-color: var(--primary-color);
    background: color-mix(in srgb, var(--primary-color) 10%, white);
    color: var(--primary-color);
    font-weight: 600;
}

.scope-count {
    min-width: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: var(--background-color);
    font-size: 11px;
    line-height: 18px;
}

.template-source-badge,
.template-access-badge {
    display: inline-flex;
    align-items: center;
    height: 20px;
    padding: 0 7px;
    border-radius: 3px;
    background: #e8f1ff;
    color: #2563eb;
    font-size: 11px;
}

.template-access-badge {
    background: #eaf8ef;
    color: #16803c;
}

.template-access-badge.is-member {
    background: #fff3dc;
    color: #a15c00;
}

.empty-state span {
    display: block;
    margin-top: 8px;
    color: var(--text-secondary);
    font-size: 13px;
}
  
/* 分类右键菜单 */  
.category-context-menu {  
    position: fixed;  
    background: var(--surface-color);  
    border: 1px solid var(--border-color);  
    border-radius: 6px;  
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);  
    z-index: 10000;  
    min-width: 140px;  
    padding: 4px 0;  
}  
  
.category-context-menu .context-menu-item {  
    padding: 10px 16px;  
    cursor: pointer;  
    transition: background 0.2s;  
    display: flex;  
    align-items: center;  
    gap: 8px;  
    font-size: 14px;  
}  
  
.category-context-menu .context-menu-item:hover {  
    background: var(--background-color);  
}  
  
.category-context-menu .context-menu-item-danger {  
    color: #ef4444;  
}  
  
.category-context-menu .context-menu-item-danger:hover {  
    background: rgba(239, 68, 68, 0.1);  
}  
  
.category-badge {  
    display: inline-block;  
    padding: 2px 8px;  
    border-radius: 3px;  
    font-size: 11px;  
    font-weight: 500;  
    background: var(--primary-color);  
    color: white;  
    max-width: 120px;  
    overflow: hidden;  
    text-overflow: ellipsis;  
    white-space: nowrap;  
    vertical-align: middle;  
}

/* 拖拽中的卡片样式 */  
.template-card.dragging {  
    cursor: move;  
}  
  
/* 拖拽悬停的分类样式 */  
.tree-item.drag-over {  
    background-color: var(--primary-color);  
    color: white;  
    border-left: 3px solid var(--primary-dark);  
}  
  
.tree-item.drag-over .tree-icon,  
.tree-item.drag-over .tree-name,  
.tree-item.drag-over .item-count {  
    color: white;  
}  
  
/* 拖拽时的光标 */  
.template-card[draggable="true"] {  
    cursor: grab;  
}  
  
.template-card[draggable="true"]:active {  
    cursor: grabbing;  
}
.template-workspace-header {
    flex: 0 0 auto;
    margin: 0 20px;
    padding: 18px 0;
}

.template-workspace-header .btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-height: 40px;
    white-space: nowrap;
}

@media (max-width: 640px) {
    .template-workspace-header {
        margin: 0 14px;
        padding-top: 16px;
    }
}
