/* ========================================
   CRM 管理后台 - 完整样式
   ======================================== */

:root {
    --primary: #2B7AFF;
    --primary-light: #EBF4FF;
    --success: #18B456;
    --success-light: #E8F8EE;
    --warning: #F5A623;
    --warning-light: #FFF4E6;
    --danger: #F54B4B;
    --danger-light: #FFF0F0;
    --purple: #E040FB;
    --cyan: #00BCD4;
    --gray-50: #F5F6FA;
    --gray-100: #EEE;
    --gray-300: #CCC;
    --gray-500: #999;
    --gray-700: #666;
    --gray-900: #333;
    --sidebar-bg: #1E293B;
    --sidebar-hover: #334155;
    --sidebar-active: #2B7AFF;
    --radius: 8px;
    --shadow: 0 2px 12px rgba(0,0,0,0.06);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"PingFang SC","Microsoft YaHei",sans-serif; font-size: 14px; color: var(--gray-900); background: var(--gray-50); }

/* ========== 登录页 ========== */
.login-page {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; background: linear-gradient(135deg, #1E293B 0%, #2B7AFF 100%);
}
.login-card {
    background: #fff; border-radius: 16px; padding: 48px 40px;
    width: 420px; max-width: 90vw; box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}
.login-card h1 { font-size: 28px; text-align: center; color: var(--gray-900); margin-bottom: 4px; }
.login-subtitle { text-align: center; color: var(--gray-500); margin-bottom: 32px; font-size: 14px; }
.login-error { color: var(--danger); font-size: 13px; text-align: center; min-height: 20px; margin-bottom: 8px; }

/* ========== 应用布局 ========== */
.app-container { display: flex; min-height: 100vh; }
.sidebar {
    width: 240px; min-width: 240px; background: var(--sidebar-bg);
    color: #fff; display: flex; flex-direction: column; transition: margin-left 0.3s;
}
.sidebar.collapsed { margin-left: -240px; }
.sidebar-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 20px 16px; border-bottom: 1px solid rgba(255,255,255,0.1);
}
.sidebar-header h2 { font-size: 18px; font-weight: 600; }
.sidebar-toggle { cursor: pointer; font-size: 20px; padding: 4px 8px; border-radius: 4px; }
.sidebar-toggle:hover { background: var(--sidebar-hover); }

/* 收起后出现的展开按钮（浮动在页面左边缘） */
.sidebar-expand-btn {
    position: fixed; top: 12px; left: 8px; z-index: 100;
    width: 36px; height: 36px; display: flex; align-items: center; justify-content: center;
    background: var(--sidebar-bg); color: rgba(255,255,255,0.8);
    font-size: 18px; border-radius: 6px; cursor: pointer;
    transition: opacity 0.2s; box-shadow: 2px 2px 8px rgba(0,0,0,0.15);
}
.sidebar-expand-btn:hover { color: #fff; background: var(--sidebar-hover); }

/* 顶部栏里的展开按钮 */
.sidebar-expand-btn-inline {
    display: inline-flex; align-items: center; justify-content: center;
    width: 32px; height: 32px; margin-right: 8px;
    font-size: 18px; cursor: pointer; border-radius: 4px;
    color: var(--gray-500);
}
.sidebar-expand-btn-inline:hover { background: var(--gray-100); color: var(--gray-800); }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 8px 0; }

.nav-group { margin-bottom: 4px; }
.nav-group-title {
    padding: 12px 16px 8px; font-size: 11px; text-transform: uppercase;
    color: rgba(255,255,255,0.35); letter-spacing: 1px; cursor: default;
}
.nav-item {
    display: flex; align-items: center; padding: 10px 16px; cursor: pointer;
    font-size: 14px; color: rgba(255,255,255,0.7); transition: all 0.15s;
    border-left: 3px solid transparent; gap: 10px;
}
.nav-item:hover { background: var(--sidebar-hover); color: #fff; }
.nav-item.active { background: rgba(43,122,255,0.2); color: #fff; border-left-color: var(--primary); }
.nav-item .nav-icon { font-size: 18px; width: 22px; text-align: center; }

.main-area { flex: 1; display: flex; flex-direction: column; min-width: 0; }

/* ========== 顶部栏 ========== */
.topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 24px; height: 56px; background: #fff;
    box-shadow: 0 1px 4px rgba(0,0,0,0.04); z-index: 10;
}
.topbar-title { font-size: 18px; font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 16px; }
.topbar-user { color: var(--gray-700); }

/* ========== 内容区 ========== */
.content { flex: 1; padding: 24px; overflow-y: auto; }

/* ========== 通用组件 ========== */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 8px 20px; border-radius: var(--radius); border: 1px solid transparent;
    font-size: 14px; cursor: pointer; transition: all 0.2s; gap: 6px;
}
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: #1A6AEE; }
.btn-success { background: var(--success); color: #fff; border-color: var(--success); }
.btn-success:hover { background: #149E4A; }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: #E04040; }
.btn-outline { background: #fff; color: var(--gray-700); border-color: var(--gray-300); }
.btn-outline:hover { background: var(--gray-50); border-color: var(--gray-500); }
.btn-sm { padding: 4px 12px; font-size: 12px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.card {
    background: #fff; border-radius: 12px; padding: 24px;
    box-shadow: var(--shadow); margin-bottom: 20px;
}
.card-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 20px;
}
.card-title { font-size: 16px; font-weight: 600; }

/* ========== 统计卡片网格 ========== */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: #fff; border-radius: 12px; padding: 20px 24px; box-shadow: var(--shadow); }
.stat-card .stat-value {
    font-size: 32px; font-weight: 700; line-height: 1.2;
}
.stat-card .stat-label { font-size: 13px; color: var(--gray-500); margin-top: 4px; }

/* ========== 表格 ========== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
table th, table td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--gray-100); font-size: 13px; }
table th { background: var(--gray-50); color: var(--gray-700); font-weight: 600; white-space: nowrap; }
table tr:hover td { background: #FAFBFC; }
table td .actions { display: flex; gap: 8px; }
table td .link { color: var(--primary); cursor: pointer; }
table td .link:hover { text-decoration: underline; }
table td .link-danger { color: var(--danger); cursor: pointer; }
table td .link-danger:hover { text-decoration: underline; }

/* ========== 标签 ========== */
.tag {
    display: inline-block; padding: 2px 10px; border-radius: 20px;
    font-size: 12px; font-weight: 500; white-space: nowrap;
}
.tag-blue { background: var(--primary-light); color: var(--primary); }
.tag-green { background: var(--success-light); color: var(--success); }
.tag-orange { background: var(--warning-light); color: var(--warning); }
.tag-red { background: var(--danger-light); color: var(--danger); }
.tag-gray { background: #F0F0F0; color: var(--gray-500); }
.tag-purple { background: #F3E5F5; color: var(--purple); }

/* ========== 表单 ========== */
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block; font-size: 13px; color: var(--gray-700); margin-bottom: 6px; font-weight: 500;
}
.form-group label.required::after { content: ' *'; color: var(--danger); }
.form-group input, .form-group select, .form-group textarea {
    width: 100%; padding: 10px 12px; border: 1px solid var(--gray-300);
    border-radius: var(--radius); font-size: 14px; outline: none; transition: border 0.2s;
    font-family: inherit;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    border-color: var(--primary); box-shadow: 0 0 0 3px rgba(43,122,255,0.1);
}
.form-group textarea { min-height: 80px; resize: vertical; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-actions { display: flex; gap: 12px; margin-top: 24px; }

/* ========== 搜索栏 ========== */
.search-bar {
    display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; align-items: center;
}
.search-bar input, .search-bar select {
    padding: 8px 12px; border: 1px solid var(--gray-300); border-radius: var(--radius);
    font-size: 13px; outline: none;
}
.search-bar input:focus, .search-bar select:focus { border-color: var(--primary); }
.search-bar input { width: 220px; }
.search-bar select { min-width: 130px; }
.space { flex: 1; }

/* ========== 分页 ========== */
.pagination {
    display: flex; justify-content: center; align-items: center; gap: 8px; margin-top: 20px;
}
.pagination button {
    padding: 6px 14px; border: 1px solid var(--gray-300); border-radius: var(--radius);
    background: #fff; cursor: pointer; font-size: 13px;
}
.pagination button:hover { background: var(--gray-50); }
.pagination button.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }
.pagination .page-info { font-size: 13px; color: var(--gray-500); }

/* ========== 模态框 ========== */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.45);
    display: flex; align-items: center; justify-content: center; z-index: 1000;
}
.modal {
    background: #fff; border-radius: 12px; width: 560px; max-width: 90vw;
    max-height: 80vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 20px 24px; border-bottom: 1px solid var(--gray-100);
}
.modal-title { font-size: 16px; font-weight: 600; }
.modal-close { cursor: pointer; font-size: 20px; color: var(--gray-500); padding: 0 4px; }
.modal-close:hover { color: var(--gray-900); }
.modal-body { padding: 24px; overflow-y: auto; flex: 1; }

/* ========== Toast ========== */
.toast {
    position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
    padding: 10px 24px; border-radius: var(--radius); font-size: 14px;
    z-index: 2000; opacity: 0; transition: opacity 0.3s; pointer-events: none;
    color: #fff;
}
.toast.show { opacity: 1; }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.info { background: var(--primary); }

/* ========== 空状态 ========== */
.empty-state { text-align: center; padding: 60px 20px; color: var(--gray-500); }
.empty-state .empty-icon { font-size: 48px; display: block; margin-bottom: 12px; }

/* ========== 进度条 ========== */
.progress-bar {
    width: 100%; height: 6px; background: var(--gray-100); border-radius: 3px; overflow: hidden;
}
.progress-fill { height: 100%; border-radius: 3px; transition: width 0.3s; }

/* ========== 图表容器 ========== */
.chart-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; margin-top: 20px; }
.chart-box { background: #fff; border-radius: 12px; padding: 20px; box-shadow: var(--shadow); }
.chart-box h4 { margin-bottom: 16px; font-size: 15px; color: var(--gray-900); }
.bar-wrap { display: flex; flex-direction: column; gap: 10px; }
.bar-item { display: flex; align-items: center; gap: 10px; }
.bar-label { width: 100px; font-size: 12px; color: var(--gray-700); text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { flex: 1; height: 22px; background: var(--gray-100); border-radius: 4px; overflow: hidden; position: relative; }
.bar-fill { height: 100%; border-radius: 4px; transition: width 0.5s; min-width: 2px; }
.bar-val { font-size: 12px; color: var(--gray-700); min-width: 50px; }

/* ========== 响应式 ========== */
@media (max-width: 768px) {
    .sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 100; }
    .sidebar.collapsed { margin-left: -240px; }
    .form-row { grid-template-columns: 1fr; }
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .chart-row { grid-template-columns: 1fr; }
}
