/* CRM 系统全局样式 */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-light: #eff6ff;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --info: #0891b2;
  --bg: #f1f5f9;
  --sidebar-bg: #0f172a;
  --sidebar-w: 240px;
  --header-h: 60px;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --card-shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --radius: 10px;
}

body { font-family: 'Segoe UI','PingFang SC','Microsoft YaHei',sans-serif; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.6; }

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== 布局 ===== */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w); background: var(--sidebar-bg); color: #cbd5e1;
  display: flex; flex-direction: column; position: fixed; top: 0; left: 0; height: 100vh;
  z-index: 100; transition: width .25s;
}
.sidebar-logo {
  padding: 0 20px; height: var(--header-h); display: flex; align-items: center;
  gap: 10px; border-bottom: 1px solid rgba(255,255,255,.07);
}
.sidebar-logo .logo-icon { width: 32px; height: 32px; background: var(--primary); border-radius: 8px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.sidebar-logo .logo-icon svg { width: 18px; height: 18px; fill: #fff; }
.sidebar-logo .logo-text { font-size: 15px; font-weight: 700; color: #f1f5f9; white-space: nowrap; }

.sidebar-nav { flex: 1; padding: 12px 0; overflow-y: auto; }
.nav-group { padding: 8px 0; }
.nav-group-title { padding: 4px 20px; font-size: 11px; font-weight: 600; color: #475569; text-transform: uppercase; letter-spacing: .05em; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 9px 20px; color: #94a3b8;
  cursor: pointer; transition: all .15s; border-left: 3px solid transparent; }
.nav-item:hover { background: rgba(255,255,255,.06); color: #e2e8f0; }
.nav-item.active { background: rgba(37,99,235,.2); color: #93c5fd; border-left-color: var(--primary); }
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; fill: currentColor; }
.nav-item .label { font-size: 13.5px; }
.nav-badge { margin-left: auto; background: #dc2626; color: #fff; font-size: 10px; padding: 1px 6px; border-radius: 10px; min-width: 18px; text-align: center; }

.sidebar-footer { padding: 16px 20px; border-top: 1px solid rgba(255,255,255,.07); }
.user-card { display: flex; align-items: center; gap: 10px; }
.user-avatar { width: 36px; height: 36px; background: var(--primary); border-radius: 50%;
  display: flex; align-items: center; justify-content: center; color: #fff; font-size: 14px; font-weight: 600; flex-shrink: 0; }
.user-info .name { font-size: 13px; color: #e2e8f0; font-weight: 500; }
.user-info .role { font-size: 11px; color: #64748b; }
.btn-logout { margin-left: auto; background: none; border: none; color: #64748b; cursor: pointer; padding: 4px; border-radius: 6px; transition: color .15s; }
.btn-logout:hover { color: #ef4444; }
.btn-logout svg { width: 18px; height: 18px; fill: currentColor; display: block; }

.main { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; min-height: 100vh; }

.header {
  height: var(--header-h); background: #fff; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 24px; gap: 16px;
  position: sticky; top: 0; z-index: 50;
}
.header-title { font-size: 16px; font-weight: 600; color: var(--text); flex: 1; }
.header-actions { display: flex; align-items: center; gap: 10px; }

.page-content { padding: 24px; flex: 1; }

/* ===== 通用组件 ===== */
.card { background: #fff; border-radius: var(--radius); box-shadow: var(--card-shadow); }
.card-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.card-header h3 { font-size: 15px; font-weight: 600; flex: 1; }
.card-body { padding: 20px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: #fff; border-radius: var(--radius); padding: 20px; box-shadow: var(--card-shadow); display: flex; align-items: flex-start; gap: 14px; }
.stat-icon { width: 48px; height: 48px; border-radius: 12px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.stat-icon svg { width: 24px; height: 24px; fill: #fff; }
.stat-icon.blue { background: linear-gradient(135deg, #3b82f6, #2563eb); }
.stat-icon.green { background: linear-gradient(135deg, #22c55e, #16a34a); }
.stat-icon.orange { background: linear-gradient(135deg, #f59e0b, #d97706); }
.stat-icon.red { background: linear-gradient(135deg, #f87171, #dc2626); }
.stat-icon.purple { background: linear-gradient(135deg, #a78bfa, #7c3aed); }
.stat-icon.cyan { background: linear-gradient(135deg, #22d3ee, #0891b2); }
.stat-value { font-size: 28px; font-weight: 700; color: var(--text); line-height: 1.1; }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.stat-change { font-size: 11px; margin-top: 4px; }
.stat-change.up { color: var(--success); }
.stat-change.down { color: var(--danger); }

/* ===== 按钮 ===== */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border-radius: 8px; font-size: 13.5px; font-weight: 500; cursor: pointer; border: none; transition: all .15s; white-space: nowrap; }
.btn svg { width: 15px; height: 15px; fill: currentColor; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #15803d; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-outline { background: #fff; color: var(--text); border: 1.5px solid var(--border); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-xs { padding: 3px 8px; font-size: 11px; border-radius: 6px; }
.btn-icon { padding: 7px; }

/* ===== 表格 ===== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th { background: #f8fafc; font-size: 12px; font-weight: 600; color: var(--text-muted); padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
tbody tr { transition: background .12s; }
tbody tr:hover { background: #f8fafc; }
tbody td { padding: 11px 14px; border-bottom: 1px solid var(--border); font-size: 13.5px; vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }

/* ===== 表单 ===== */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-full { grid-column: 1 / -1; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label { font-size: 13px; font-weight: 500; color: #374151; }
.form-control { padding: 9px 12px; border: 1.5px solid var(--border); border-radius: 8px; font-size: 13.5px; color: var(--text); outline: none; transition: border-color .15s, box-shadow .15s; width: 100%; background: #fff; }
.form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
textarea.form-control { resize: vertical; min-height: 80px; }
select.form-control { cursor: pointer; }

/* ===== 筛选栏 ===== */
.filter-bar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.filter-bar .form-control { width: auto; min-width: 140px; padding: 7px 10px; }
.search-box { position: relative; }
.search-box input { padding-left: 34px; }
.search-box svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; fill: #94a3b8; }

/* ===== 徽标/状态 ===== */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 20px; font-size: 11.5px; font-weight: 500; }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-active, .badge-completed, .badge-paid { background: #dcfce7; color: #15803d; }
.badge-potential { background: #eff6ff; color: #2563eb; }
.badge-inactive { background: #f1f5f9; color: #64748b; }
.badge-lost, .badge-cancelled { background: #fef2f2; color: #dc2626; }
.badge-pending, .badge-draft { background: #fef9c3; color: #a16207; }
.badge-confirmed, .badge-partial { background: #e0f2fe; color: #0369a1; }
.badge-production { background: #fae8ff; color: #7c3aed; }
.badge-shipped { background: #ecfdf5; color: #059669; }
.badge-unpaid { background: #fef2f2; color: #dc2626; }
.level-A { color: #dc2626; font-weight: 700; }
.level-B { color: #d97706; font-weight: 700; }
.level-C { color: #2563eb; font-weight: 600; }
.level-D { color: #64748b; }

/* ===== 分页 ===== */
.pagination { display: flex; align-items: center; gap: 6px; padding: 16px 0; justify-content: flex-end; }
.pagination .page-info { color: var(--text-muted); font-size: 13px; margin-right: 8px; }
.page-btn { width: 32px; height: 32px; border: 1.5px solid var(--border); border-radius: 6px; background: #fff; cursor: pointer; font-size: 13px; display: flex; align-items: center; justify-content: center; transition: all .15s; color: var(--text); }
.page-btn:hover { border-color: var(--primary); color: var(--primary); }
.page-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.page-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ===== 模态框 ===== */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 20px; opacity: 0; pointer-events: none; transition: opacity .2s; }
.modal-overlay.show { opacity: 1; pointer-events: all; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 640px; max-height: 90vh; display: flex; flex-direction: column; transform: translateY(20px) scale(.97); transition: transform .2s; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal-overlay.show .modal { transform: none; }
.modal.modal-lg { max-width: 820px; }
.modal.modal-xl { max-width: 1000px; }
.modal-header { padding: 18px 22px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.modal-header h3 { font-size: 16px; font-weight: 600; flex: 1; }
.modal-close { background: none; border: none; cursor: pointer; color: #94a3b8; padding: 8px; border-radius: 6px; transition: color .15s, background .15s; display: flex; align-items: center; justify-content: center; flex-shrink: 0; min-width: 36px; min-height: 36px; }
.modal-close:hover { color: var(--danger); background: rgba(220,38,38,.08); }
.modal-close svg { width: 20px; height: 20px; fill: currentColor; display: block; pointer-events: none; }
.modal-body { padding: 22px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; align-items: center; justify-content: flex-end; gap: 10px; flex-shrink: 0; }

/* ===== 空状态 ===== */
.empty-state { padding: 60px 20px; text-align: center; color: var(--text-muted); }
.empty-state svg { width: 64px; height: 64px; fill: #cbd5e1; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }

/* ===== Toast ===== */
#toastContainer { position: fixed; top: 20px; right: 20px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #1e293b; color: #f1f5f9; padding: 12px 18px; border-radius: 10px; font-size: 13.5px; box-shadow: 0 4px 20px rgba(0,0,0,.25); display: flex; align-items: center; gap: 8px; min-width: 240px; animation: slideIn .25s ease; }
.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }
.toast.info { border-left: 4px solid var(--info); }
@keyframes slideIn { from { opacity:0; transform: translateX(20px); } to { opacity:1; transform: none; } }

/* ===== 提醒角标 ===== */
.remind-dot { display: inline-flex; width: 8px; height: 8px; background: #ef4444; border-radius: 50%; }

/* ===== 图表容器 ===== */
.chart-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 24px; }
.chart-wrap { background: #fff; border-radius: var(--radius); padding: 20px; box-shadow: var(--card-shadow); }
.chart-wrap h4 { font-size: 14px; font-weight: 600; margin-bottom: 14px; }
.chart-container { position: relative; height: 240px; }

/* ===== 快捷入口 ===== */
.quick-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 24px; }
.quick-btn { display: flex; align-items: center; gap: 8px; padding: 10px 18px; background: #fff; border: 1.5px solid var(--border); border-radius: 10px; cursor: pointer; font-size: 13.5px; color: var(--text); transition: all .15s; }
.quick-btn:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }
.quick-btn svg { width: 16px; height: 16px; fill: currentColor; }

/* ===== 响应式 ===== */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: none; }
  .main { margin-left: 0; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .chart-row { grid-template-columns: 1fr; }
}
