/* =========================================
   1. 全局变量 & 重置 (Base)
   ========================================= */
:root {
    /* 核心颜色 - 采用第二段配置 */
    --bg-color: #f1f5f9;
    --card-bg: #ffffff;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    
    /* 尺寸与阴影 - 采用第二段配置，保留第一段的shadow定义以备用 */
    --radius: 8px;
    --header-height: 60px;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

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

body { 
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; 
    background: var(--bg-color); 
    color: var(--text-main); 
    /* 采用第二段的 App 模式布局 (全屏无滚动，内容区滚动) */
    height: 100vh; 
    overflow: hidden; 
    line-height: 1.6;
}

/* 辅助类 */
.hidden { display: none !important; }

/* =========================================
   2. 按钮系统 (Buttons)
   ========================================= */
/* 基础样式以第二段为准 */
.btn { 
    display: inline-flex; 
    align-items: center; 
    justify-content: center; 
    padding: 0.5rem 1rem; 
    border-radius: 6px; 
    font-size: 0.9rem; 
    font-weight: 500; 
    cursor: pointer; 
    transition: all 0.2s; 
    border: 1px solid transparent; 
    text-decoration: none;
    gap: 0.5rem; 
}
.btn:disabled { opacity: 0.7; cursor: not-allowed; }

/* 变体 */
.btn-primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }

.btn-outline { background: white; color: var(--text-main); border-color: var(--border); }
.btn-outline:hover { background: #f8fafc; border-color: #cbd5e1; }

.btn-danger { background: #fee2e2; color: #dc2626; border-color: #fee2e2; }
.btn-danger:hover { background: #fecaca; }

.btn-text { background: transparent; color: var(--text-muted); padding: 4px; }
.btn-text:hover { color: var(--primary); background: #eff6ff; }

/* 保留第一段的 btn-sm，因为第二段未定义但很有用 */
.btn-sm { padding: 0.25rem 0.75rem; font-size: 0.8rem; }

/* =========================================
   3. 表单系统 (Forms)
   ========================================= */
/* 样式以第二段为准 */
.form-group { margin-bottom: 1.25rem; }

.form-group label { 
    display: block; 
    font-size: 0.85rem; 
    font-weight: 600; 
    margin-bottom: 0.4rem; 
    color: var(--text-main); 
}

.form-input { 
    width: 100%; 
    padding: 0.6rem; 
    border: 1px solid var(--border); 
    border-radius: 6px; 
    font-size: 0.9rem; 
    outline: none; 
    transition: border-color 0.2s; 
    background: white; 
}
.form-input:focus { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1); }
.form-input:read-only { background: #f8fafc; color: var(--text-muted); cursor: not-allowed; }

.form-check { display: flex; align-items: center; gap: 0.5rem; cursor: pointer; user-select: none; }

/* 密码框组件 */
.password-wrapper { position: relative; }
.password-toggle { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); cursor: pointer; color: var(--text-muted); }
.password-toggle:hover { color: var(--text-main); }

/* =========================================
   4. 布局与导航 (Layout & Nav)
   ========================================= */
/* 导航栏 - 采用第二段 (固定高度) */
.navbar { 
    height: var(--header-height); 
    background: white; 
    border-bottom: 1px solid var(--border); 
    display: flex; 
    align-items: center; 
    justify-content: space-between; 
    padding: 0 1.5rem; 
    position: sticky; 
    top: 0; 
    z-index: 50; 
}

.brand { 
    font-weight: 700; 
    font-size: 1.1rem; 
    color: var(--primary); 
    text-decoration: none;
    display: flex; 
    align-items: center; 
    gap: 0.5rem; 
}

/* 保留第一段的导航链接样式，适配可能存在的顶部菜单 */
.nav-links { display: flex; gap: 1.5rem; }
.nav-links a { color: var(--text-muted); text-decoration: none; font-size: 0.95rem; transition: color 0.2s; }
.nav-links a:hover { color: var(--primary); }

/* 布局模式 A: 普通容器 (来自第一段) */
.container { max-width: 1200px; margin: 0 auto; padding: 2rem; }

/* 布局模式 B: 双栏管理后台布局 (来自第二段) */
.admin-layout { display: grid; grid-template-columns: 320px 1fr; height: calc(100vh - var(--header-height)); }

/* 左侧边栏 */
.sidebar { background: white; border-right: 1px solid var(--border); display: flex; flex-direction: column; }
.sidebar-header { padding: 1rem; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }

/* 右侧主内容区 */
.main-content { padding: 2rem; overflow-y: auto; display: flex; justify-content: center; }

/* =========================================
   5. 列表与卡片视图 (Views)
   ========================================= */
/* --- 列表视图 (Sidebar List) --- */
.project-list { overflow-y: auto; flex: 1; padding: 0.5rem; }
.list-item { display: flex; flex-direction: column; gap: 4px; padding: 0.8rem; border-radius: 6px; cursor: pointer; border: 1px solid transparent; transition: all 0.2s; margin-bottom: 4px; }
.list-item:hover { background: #f8fafc; }
.list-item.active { background: #eff6ff; border-color: #bfdbfe; }
.item-title { font-weight: 600; font-size: 0.95rem; display: flex; justify-content: space-between; }
.item-meta { font-size: 0.8rem; color: var(--text-muted); display: flex; gap: 8px; align-items: center; }

/* 状态圆点 */
.status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot-green { background: #22c55e; }
.dot-gray { background: #94a3b8; }

/* --- 网格视图 (Project Grid - 来自第一段) --- */
.project-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1.5rem; }
.project-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; transition: transform 0.2s, box-shadow 0.2s; display: flex; flex-direction: column; }
.project-card:hover { transform: translateY(-4px); box-shadow: var(--shadow); border-color: #cbd5e1; }

.card-icon { width: 48px; height: 48px; background: #eff6ff; border-radius: 10px; display: flex; align-items: center; justify-content: center; margin-bottom: 1rem; color: var(--primary); }
.card-icon.locked { background: #fef2f2; color: #ef4444; }
.card-title { font-size: 1.1rem; font-weight: 700; margin-bottom: 0.5rem; color: var(--text-main); }
.card-meta { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 1.5rem; flex-grow: 1; }
.card-actions { display: flex; gap: 0.5rem; margin-top: auto; }

/* --- 编辑器卡片 (Editor - 来自第二段) --- */
.editor-card { background: white; padding: 2rem; border-radius: var(--radius); border: 1px solid var(--border); width: 100%; max-width: 800px; box-shadow: 0 1px 3px rgba(0,0,0,0.05); }
.editor-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 2rem; padding-bottom: 1rem; border-bottom: 1px solid var(--border); }

/* =========================================
   6. 数据表格 (Tables)
   ========================================= */
/* 来自第一段，保留用于展示数据 */
.admin-panel { background: white; border-radius: var(--radius); border: 1px solid var(--border); overflow: hidden; }
.admin-header { padding: 1.5rem; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; background: #f8fafc; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td { padding: 1rem; text-align: left; border-bottom: 1px solid var(--border); }
.data-table th { background: #f8fafc; font-weight: 600; font-size: 0.85rem; color: var(--text-muted); text-transform: uppercase; }
.data-table tr:last-child td { border-bottom: none; }

/* 徽标 (Badges) */
.badge { padding: 0.25rem 0.75rem; border-radius: 99px; font-size: 0.75rem; font-weight: 600; display: inline-block; }
.badge-green { background: #dcfce7; color: #166534; }
.badge-gray { background: #f1f5f9; color: #475569; }
.badge-red { background: #fee2e2; color: #991b1b; }

/* =========================================
   7. 交互组件 (Modals & Toasts)
   ========================================= */
/* Modal 弹窗 - 采用第二段 (更现代的样式) */
.modal-overlay { 
    position: fixed; 
    inset: 0; 
    background: rgba(0,0,0,0.4); 
    backdrop-filter: blur(2px); 
    z-index: 3000; 
    display: flex; 
    justify-content: center; 
    align-items: center; 
    opacity: 0; 
    pointer-events: none; 
    transition: opacity 0.2s; 
}
.modal-overlay.active { opacity: 1; pointer-events: auto; }

.modal-box { 
    background: white; 
    width: 90%; 
    max-width: 400px; 
    padding: 1.5rem; 
    border-radius: 12px; 
    box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1); 
    transform: scale(0.95); 
    transition: transform 0.2s; 
}
.modal-overlay.active .modal-box { transform: scale(1); }

.modal-title { font-size: 1.1rem; font-weight: 700; margin-bottom: 0.5rem; }
.modal-desc { color: var(--text-muted); font-size: 0.95rem; margin-bottom: 1.5rem; line-height: 1.5; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.75rem; }

/* Toast 提示 */
.toast-container { position: fixed; top: 20px; right: 20px; z-index: 2000; display: flex; flex-direction: column; gap: 10px; }
.toast { background: white; padding: 1rem 1.5rem; border-radius: 8px; box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1); border-left: 4px solid var(--primary); display: flex; align-items: center; animation: slideIn 0.3s ease; min-width: 300px; }
.toast.success { border-left-color: #22c55e; }
.toast.error { border-left-color: #ef4444; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* 登录层 */
.login-layer { position: fixed; inset: 0; background: #f8fafc; z-index: 5000; display: flex; align-items: center; justify-content: center; }
.login-card { background: white; width: 360px; padding: 2.5rem; border-radius: 12px; box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1); border: 1px solid var(--border); }


/* 新增：搜索框 */
.search-box { position: relative; max-width: 400px; width: 100%; }
.search-input { width: 100%; padding: 0.6rem 1rem 0.6rem 2.5rem; border-radius: 99px; border: 1px solid var(--border); background: #f8fafc; font-size: 0.9rem; outline: none; transition: all 0.2s; }
.search-input:focus { background: white; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }
.search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-muted); width: 16px; height: 16px; }

/* Admin: 代码编辑器相关 */
.tabs { display: flex; border-bottom: 1px solid var(--border); margin-bottom: 1.5rem; }
.tab { padding: 0.8rem 1.5rem; cursor: pointer; color: var(--text-muted); font-weight: 500; border-bottom: 2px solid transparent; transition: all 0.2s; }
.tab:hover { color: var(--primary); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.code-layout { display: grid; grid-template-columns: 200px 1fr; gap: 1rem; height: 400px; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.file-list { background: #f8fafc; border-right: 1px solid var(--border); overflow-y: auto; padding: 0.5rem; }
.file-item { padding: 0.5rem; cursor: pointer; font-size: 0.85rem; border-radius: 4px; color: var(--text-main); display: flex; align-items: center; gap: 6px; }
.file-item:hover { background: #e2e8f0; }
.file-item.active { background: #dbeafe; color: var(--primary); font-weight: 500; }
.code-area { width: 100%; height: 100%; border: none; padding: 1rem; font-family: 'Menlo', 'Monaco', 'Courier New', monospace; font-size: 0.9rem; line-height: 1.5; outline: none; resize: none; background: #fff; }

.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 0.5rem; margin-top: 0.5rem; }
.lib-item { border: 1px solid var(--border); padding: 0.5rem; border-radius: 6px; font-size: 0.85rem; cursor: pointer; display: flex; align-items: center; gap: 6px; user-select: none; }
.lib-item:hover { border-color: var(--primary); background: #eff6ff; }
