/* ============ 全局样式 ============ */
:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #dbeafe;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #06b6d4;
    --bg: #f3f4f6;
    --card-bg: #ffffff;
    --text: #1f2937;
    --text-secondary: #6b7280;
    --border: #e5e7eb;
    --sidebar-bg: #1e293b;
    --sidebar-hover: #334155;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
                 "Hiragino Sans GB", "Microsoft YaHei", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.6;
    min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ============ 侧边栏 ============ */
.layout { display: flex; min-height: 100vh; }

.sidebar {
    width: 240px;
    background: var(--sidebar-bg);
    color: #e2e8f0;
    flex-shrink: 0;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    overflow-y: auto;
    z-index: 100;
}

.sidebar-logo {
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar-logo .logo-icon {
    width: 36px; height: 36px;
    background: var(--primary);
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-weight: bold; font-size: 18px;
}
.sidebar-logo .logo-text { font-size: 16px; font-weight: 600; color: #fff; }

.sidebar-menu { list-style: none; padding: 12px 0; }
.sidebar-menu .menu-group { padding: 12px 20px 4px; font-size: 11px; color: #64748b; text-transform: uppercase; letter-spacing: 1px; }
.sidebar-menu li a {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 20px;
    color: #cbd5e1;
    transition: all 0.2s;
    border-left: 3px solid transparent;
}
.sidebar-menu li a:hover { background: var(--sidebar-hover); color: #fff; text-decoration: none; }
.sidebar-menu li a.active { background: var(--sidebar-hover); color: #fff; border-left-color: var(--primary); }
.sidebar-menu .menu-icon { width: 18px; text-align: center; }

/* ============ 主内容区 ============ */
.main {
    flex: 1;
    margin-left: 240px;
    display: flex;
    flex-direction: column;
}

.topbar {
    background: #fff;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
}
.topbar .page-title { font-size: 16px; font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 16px; }
.topbar-right .user-info { display: flex; align-items: center; gap: 8px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: bold; font-size: 13px; }

.content { flex: 1; padding: 24px; }

/* ============ 卡片 ============ */
.card {
    background: #fff;
    border-radius: 10px;
    border: 1px solid var(--border);
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.card-title { font-size: 15px; font-weight: 600; }
.card-body { padding: 20px; }

/* ============ 表格 ============ */
.table-wrap { overflow-x: auto; }
.table {
    width: 100%;
    border-collapse: collapse;
}
.table th, .table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.table th {
    background: #f9fafb;
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 13px;
    white-space: nowrap;
}
.table tbody tr:hover { background: #f9fafb; }
.table .actions { display: flex; gap: 8px; }

/* ============ 按钮 ============ */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 16px;
    border: 1px solid transparent;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    background: #fff;
    color: var(--text);
}
.btn:hover { opacity: 0.9; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-outline { border-color: var(--border); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-link { background: none; border: none; color: var(--primary); padding: 0; cursor: pointer; }
.btn-link:hover { text-decoration: underline; }

/* ============ 表单 ============ */
.form-group { margin-bottom: 16px; }
.form-label { display: block; margin-bottom: 6px; font-weight: 500; font-size: 13px; }
.form-control, .form-select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    transition: border-color 0.2s;
    background: #fff;
}
.form-control:focus, .form-select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
.form-textarea { min-height: 120px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }

/* ============ Badge/Tag ============ */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 500;
}
.badge-success { background: #dcfce7; color: #166534; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-info { background: #cffafe; color: #155e75; }
.badge-secondary { background: #f1f5f9; color: #475569; }
.badge-primary { background: var(--primary-light); color: var(--primary-dark); }

/* ============ 统计卡片 ============ */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
    background: #fff;
    border-radius: 10px;
    padding: 20px;
    border: 1px solid var(--border);
}
.stat-card .stat-label { font-size: 13px; color: var(--text-secondary); margin-bottom: 8px; }
.stat-card .stat-value { font-size: 28px; font-weight: 700; color: var(--text); }
.stat-card .stat-trend { font-size: 12px; margin-top: 6px; }
.stat-card .stat-trend.up { color: var(--success); }
.stat-card .stat-trend.down { color: var(--danger); }
.stat-card .stat-icon {
    float: right; width: 44px; height: 44px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px;
}
.stat-card.blue .stat-icon { background: #dbeafe; color: var(--primary); }
.stat-card.green .stat-icon { background: #dcfce7; color: var(--success); }
.stat-card.orange .stat-icon { background: #fef3c7; color: var(--warning); }
.stat-card.red .stat-icon { background: #fee2e2; color: var(--danger); }

/* ============ 进度条 ============ */
.progress { height: 8px; background: #e5e7eb; border-radius: 10px; overflow: hidden; }
.progress-bar { height: 100%; background: var(--primary); border-radius: 10px; transition: width 0.3s; }
.progress-bar.green { background: var(--success); }
.progress-bar.orange { background: var(--warning); }
.progress-bar.red { background: var(--danger); }

/* ============ 模态框 ============ */
.modal-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    display: none;
    align-items: center; justify-content: center;
    z-index: 1000;
}
.modal-overlay.show { display: flex; }
.modal {
    background: #fff;
    border-radius: 12px;
    width: 560px;
    max-width: 90vw;
    max-height: 90vh;
    overflow: hidden;
    display: flex; flex-direction: column;
}
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-title { font-size: 16px; font-weight: 600; }
.modal-close { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--text-secondary); }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 16px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

/* ============ 分页 ============ */
.pagination { display: flex; justify-content: center; align-items: center; gap: 4px; padding: 16px 0; }
.pagination a, .pagination span {
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
}
.pagination a:hover { background: var(--primary-light); text-decoration: none; }
.pagination .current { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ============ Toast 提示 ============ */
.toast-container { position: fixed; top: 20px; right: 20px; z-index: 2000; display: flex; flex-direction: column; gap: 10px; }
.toast { padding: 12px 20px; border-radius: 8px; color: #fff; box-shadow: 0 4px 12px rgba(0,0,0,0.15); animation: slideIn 0.3s ease; }
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-warning { background: var(--warning); color: #000; }
.toast-info { background: var(--info); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ============ 空状态 ============ */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-secondary); }
.empty-state .empty-icon { font-size: 48px; margin-bottom: 16px; }

/* ============ 标签颜色 ============ */
.color-blue { background: #dbeafe; color: #1d4ed8; }
.color-green { background: #dcfce7; color: #15803d; }
.color-orange { background: #fef3c7; color: #b45309; }
.color-red { background: #fee2e2; color: #b91c1c; }
.color-purple { background: #ede9fe; color: #6d28d9; }
.color-pink { background: #fce7f3; color: #be185d; }

/* ============ 变量占位符 ============ */
.var-chip {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 4px 10px;
    background: var(--primary-light);
    color: var(--primary-dark);
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    border: 1px solid #bfdbfe;
    transition: all 0.2s;
}
.var-chip:hover { background: var(--primary); color: #fff; }

/* ============ 登录页 ============ */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.login-box {
    background: #fff;
    border-radius: 16px;
    padding: 40px;
    width: 400px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.login-box h2 { text-align: center; margin-bottom: 8px; color: var(--primary); }
.login-box .subtitle { text-align: center; color: var(--text-secondary); margin-bottom: 28px; }

/* ============ 响应式 ============ */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); transition: transform 0.3s; }
    .sidebar.show { transform: translateX(0); }
    .main { margin-left: 0; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
