/* 树形规则管理器样式 */

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

:root {
    --primary-color: #4a90e2;
    --primary-hover: #357abd;
    --primary-light: rgba(74, 144, 226, 0.1);
    --success-color: #28a745;
    --success-hover: #218838;
    --secondary-color: #6c757d;
    --secondary-hover: #5a6268;
    --danger-color: #dc3545;
    --danger-hover: #c82333;
    --warning-color: #ffc107;
    --bg-color: #f5f7fa;
    --card-bg: #ffffff;
    --sidebar-bg: #f8f9fa;
    --text-primary: #2c3e50;
    --text-secondary: #6c757d;
    --border-color: #e1e8ed;
    --tree-line-color: #d0d7de;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-hover: 0 4px 12px rgba(0, 0, 0, 0.15);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft YaHei', sans-serif;
    background: var(--bg-color);
    min-height: 100vh;
    color: var(--text-primary);
}

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

/* ==================== 头部样式 ==================== */

.header {
    background: var(--card-bg);
    padding: 20px 30px;
    border-radius: 12px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
}

.header-title h1 {
    font-size: 1.75rem;
    color: var(--primary-color);
    margin-bottom: 5px;
    font-weight: 600;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

/* ==================== 按钮样式 ==================== */

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.3s ease;
    text-decoration: none;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-hover);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.btn-icon {
    width: 16px;
    height: 16px;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-secondary {
    background: var(--secondary-color);
    color: white;
}

.btn-secondary:hover {
    background: var(--secondary-hover);
}

.btn-danger {
    background: var(--danger-color);
    color: white;
}

.btn-danger:hover {
    background: var(--danger-hover);
}

.btn-outline {
    background: transparent;
    border: 2px solid var(--primary-color);
    color: var(--primary-color);
}

.btn-outline:hover {
    background: var(--primary-color);
    color: white;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.875rem;
}

.btn-icon-sm {
    width: 32px;
    height: 32px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-icon-sm:hover {
    background: var(--primary-light);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.btn-icon-sm svg {
    width: 16px;
    height: 16px;
}

/* ==================== 主布局 ==================== */

.main-layout {
    display: flex;
    gap: 20px;
    min-height: calc(100vh - 140px);
}

/* ==================== 侧边栏（树形结构） ==================== */

.sidebar {
    width: 380px;
    min-width: 380px;
    background: var(--card-bg);
    border-radius: 12px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header {
    padding: 15px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-header h3 {
    font-size: 1.1rem;
    color: var(--text-primary);
}

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

.tree-container {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
}

/* ==================== 树形节点样式 ==================== */

.tree-node {
    position: relative;
}

.tree-node-content {
    display: flex;
    align-items: center;
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 2px;
}

.tree-node-content:hover {
    background: var(--primary-light);
}

.tree-node-content.active {
    background: var(--primary-color);
    color: white;
}

.tree-node-content.active .node-code {
    color: rgba(255, 255, 255, 0.8);
}

.tree-toggle {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 6px;
    cursor: pointer;
    transition: transform 0.2s;
}

.tree-toggle.expanded {
    transform: rotate(90deg);
}

.tree-toggle svg {
    width: 14px;
    height: 14px;
    color: var(--text-secondary);
}

.tree-node-content.active .tree-toggle svg {
    color: rgba(255, 255, 255, 0.8);
}

.node-icon {
    width: 20px;
    height: 20px;
    margin-right: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.node-icon svg {
    width: 16px;
    height: 16px;
}

.node-info {
    flex: 1;
    min-width: 0;
}

.node-name {
    font-weight: 500;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.node-code {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

.tree-children {
    margin-left: 20px;
    position: relative;
}

.tree-children::before {
    content: '';
    position: absolute;
    left: -12px;
    top: 0;
    bottom: 0;
    width: 1px;
    background: var(--tree-line-color);
}

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

/* 树节点层级缩进 */
.tree-node[data-level="0"] > .tree-node-content {
    padding-left: 10px;
}

.tree-node[data-level="1"] > .tree-node-content {
    padding-left: 20px;
}

.tree-node[data-level="2"] > .tree-node-content {
    padding-left: 30px;
}

.tree-node[data-level="3"] > .tree-node-content {
    padding-left: 40px;
}

.tree-node[data-level="4"] > .tree-node-content {
    padding-left: 50px;
}

.tree-node[data-level="5"] > .tree-node-content {
    padding-left: 60px;
}

/* ==================== 内容区域 ==================== */

.content {
    flex: 1;
    background: var(--card-bg);
    border-radius: 12px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.content-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
}

.content-header h2 {
    font-size: 1.25rem;
    color: var(--text-primary);
}

.content-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.content-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

/* ==================== 空状态 ==================== */

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-secondary);
    text-align: center;
    padding: 40px;
}

.empty-icon {
    width: 80px;
    height: 80px;
    margin-bottom: 20px;
    opacity: 0.5;
}

.empty-state p {
    font-size: 1.1rem;
}

/* ==================== 规则详情 ==================== */

.rule-detail {
    max-width: 800px;
}

.detail-card {
    background: var(--bg-color);
    border-radius: 10px;
    padding: 25px;
    margin-bottom: 25px;
}

.detail-row {
    display: flex;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-color);
}

.detail-row:last-child {
    border-bottom: none;
}

.detail-label {
    width: 120px;
    color: var(--text-secondary);
    font-weight: 500;
    flex-shrink: 0;
}

.detail-value {
    flex: 1;
    color: var(--text-primary);
    font-weight: 500;
}

/* ==================== 子规则列表 ==================== */

.children-section {
    margin-top: 30px;
}

.children-section h4 {
    font-size: 1.1rem;
    color: var(--text-primary);
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--primary-color);
    display: inline-block;
}

.children-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 15px;
}

.child-item {
    background: var(--bg-color);
    border-radius: 8px;
    padding: 15px;
    border-left: 4px solid var(--primary-color);
    transition: all 0.2s;
    position: relative;
}

.child-item.with-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-right: 10px;
}

.child-item.with-actions .child-content {
    flex: 1;
    cursor: pointer;
}

.child-item.with-actions:hover {
    background: var(--primary-light);
    box-shadow: var(--shadow);
}

.child-actions {
    display: flex;
    gap: 5px;
    opacity: 0;
    transition: opacity 0.2s;
}

.child-item.with-actions:hover .child-actions {
    opacity: 1;
}

.btn-icon-action {
    width: 28px;
    height: 28px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-icon-action svg {
    width: 14px;
    height: 14px;
}

.btn-icon-action.edit {
    color: var(--primary-color);
}

.btn-icon-action.edit:hover {
    background: var(--primary-light);
}

.btn-icon-action.delete {
    color: var(--danger-color);
}

.btn-icon-action.delete:hover {
    background: rgba(220, 53, 69, 0.1);
}

.child-name {
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 5px;
}

.child-code {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* ==================== 模态框样式 ==================== */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.modal-content {
    background: var(--card-bg);
    border-radius: 12px;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-hover);
    animation: modalSlideIn 0.3s ease;
}

.modal-small {
    max-width: 400px;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    margin: 0;
    color: var(--text-primary);
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;
}

.modal-close:hover {
    background: var(--bg-color);
    color: var(--text-primary);
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 20px;
    border-top: 1px solid var(--border-color);
}

/* ==================== 表单样式 ==================== */

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--text-primary);
}

.form-group input {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 1rem;
    transition: border-color 0.3s;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.form-group input.error {
    border-color: var(--danger-color);
}

.form-group input[readonly] {
    background: var(--bg-color);
    cursor: not-allowed;
}

.required {
    color: var(--danger-color);
}

.error-message {
    display: block;
    color: var(--danger-color);
    font-size: 0.875rem;
    margin-top: 5px;
    min-height: 20px;
}

.hint {
    display: block;
    color: var(--text-secondary);
    font-size: 0.8rem;
    margin-top: 5px;
}

/* ==================== 确认删除模态框 ==================== */

.confirm-message {
    color: var(--text-secondary);
    margin-bottom: 10px;
}

.confirm-warning {
    color: var(--danger-color);
    font-size: 0.875rem;
    margin-bottom: 15px;
}

.confirm-rule-name {
    font-weight: 600;
    color: var(--danger-color);
    padding: 10px;
    background: rgba(220, 53, 69, 0.1);
    border-radius: 4px;
}

/* ==================== 加载动画 ==================== */

.loading-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 0.8s linear infinite;
    margin-right: 8px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ==================== Toast 消息 ==================== */

.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    padding: 15px 20px;
    border-radius: 8px;
    color: white;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: var(--shadow-hover);
    animation: toastSlideIn 0.3s ease;
    min-width: 250px;
}

.toast.success {
    background: var(--success-color);
}

.toast.error {
    background: var(--danger-color);
}

.toast.warning {
    background: var(--warning-color);
    color: var(--text-primary);
}

@keyframes toastSlideIn {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.toast-close {
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    font-size: 1.2rem;
    margin-left: auto;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.toast-close:hover {
    opacity: 1;
}

/* ==================== 响应式设计 ==================== */

@media (max-width: 1024px) {
    .main-layout {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        min-width: auto;
        max-height: 400px;
    }

    .tree-container {
        max-height: 300px;
    }
}

@media (max-width: 768px) {
    .container {
        padding: 10px;
    }

    .header {
        padding: 15px 20px;
    }

    .header-title h1 {
        font-size: 1.4rem;
    }

    .header-content {
        flex-direction: column;
        text-align: center;
    }

    .sidebar {
        max-height: 350px;
    }

    .content-header {
        flex-direction: column;
        align-items: stretch;
    }

    .content-actions {
        justify-content: stretch;
    }

    .content-actions .btn {
        flex: 1;
        justify-content: center;
    }

    .children-list {
        grid-template-columns: 1fr;
    }

    .detail-row {
        flex-direction: column;
        gap: 5px;
    }

    .detail-label {
        width: auto;
    }

    .modal-content {
        margin: 10px;
        max-height: calc(100vh - 20px);
    }

    .toast-container {
        left: 10px;
        right: 10px;
        top: 10px;
    }

    .toast {
        min-width: auto;
    }
}

@media (max-width: 480px) {
    .header-title h1 {
        font-size: 1.2rem;
    }

    .tree-actions {
        display: none;
    }

    .modal-footer {
        flex-direction: column;
    }

    .modal-footer .btn {
        width: 100%;
        justify-content: center;
    }
}
