/* ============================================================
   医药营销投入产出管理系统 — 设计系统
   主题：墨绿账本 + 琥珀批注
   ============================================================ */

@import url("https://miaoda.feishu.cn/fonts/css2?family=Noto+Sans+SC:wght@400;500;700&family=Space+Grotesk:wght@400;500;600&display=swap");

:root {
  --background: hsl(40 24% 97%);
  --foreground: hsl(168 16% 15%);
  --card: hsl(0 0% 100%);
  --card-foreground: hsl(168 16% 15%);
  --popover: hsl(0 0% 100%);
  --popover-foreground: hsl(168 16% 15%);
  --primary: hsl(163 45% 23%);
  --primary-foreground: hsl(40 30% 98%);
  --secondary: hsl(155 16% 94%);
  --secondary-foreground: hsl(163 40% 18%);
  --muted: hsl(155 14% 95%);
  --muted-foreground: hsl(165 7% 43%);
  --accent: hsl(155 18% 93%);
  --accent-foreground: hsl(163 40% 18%);
  --info: hsl(206 70% 44%);
  --info-foreground: hsl(206 90% 97%);
  --destructive: hsl(2 68% 48%);
  --destructive-foreground: hsl(0 0% 100%);
  --success: hsl(158 46% 31%);
  --success-foreground: hsl(150 60% 97%);
  --warning: hsl(32 88% 46%);
  --warning-foreground: hsl(38 100% 96%);
  --border: hsl(155 12% 87%);
  --input: hsl(155 12% 85%);
  --ring: hsl(163 45% 30%);
  --chart-1: hsl(163 55% 27%);
  --chart-2: hsl(32 88% 50%);
  --chart-3: hsl(206 70% 48%);
  --chart-4: hsl(158 40% 45%);
  --chart-5: hsl(200 8% 45%);
  --sidebar: hsl(163 42% 18%);
  --sidebar-foreground: hsl(45 30% 94%);
  --sidebar-primary: hsl(40 30% 98%);
  --sidebar-primary-foreground: hsl(163 45% 20%);
  --sidebar-accent: hsl(163 38% 25%);
  --sidebar-accent-foreground: hsl(45 40% 97%);
  --sidebar-border: hsl(163 30% 26%);
  --sidebar-ring: hsl(40 30% 90%);

  --status-steady: hsl(158 46% 31%);
  --status-steady-bg: hsl(155 55% 93%);
  --status-potential: hsl(30 88% 46%);
  --status-potential-bg: hsl(34 95% 93%);
  --status-fluctuant: hsl(206 70% 44%);
  --status-fluctuant-bg: hsl(206 85% 94%);
  --status-overdraft: hsl(2 68% 48%);
  --status-overdraft-bg: hsl(2 80% 94%);
  --status-low: hsl(200 6% 48%);
  --status-low-bg: hsl(200 12% 94%);
  --status-idle: hsl(200 8% 30%);
  --status-idle-bg: hsl(200 10% 90%);
  --status-warn-bg: hsl(34 95% 91%);
  --status-danger-bg: hsl(2 82% 92%);

  --font-sans: 'Noto Sans SC', 'LarkHackSafariFont', '-apple-system', 'BlinkMacSystemFont', 'Helvetica Neue', 'Tahoma', 'PingFang SC', 'Microsoft Yahei', 'Arial', sans-serif;
  --font-mono: 'Space Grotesk', 'JetBrains Mono', ui-monospace, monospace;
  --radius: 6px;
  --radius-lg: 10px;
  --shadow-sm: 0px 2px 12px 0px hsl(0 0% 0% / 0.02), 0px 1px 2px -1px hsl(0 0% 0% / 0.02);
  --shadow-md: 0px 2px 12px 0px hsl(0 0% 0% / 0.04), 0px 4px 6px -1px hsl(0 0% 0% / 0.05);
  --shadow-lg: 0px 4px 20px 0px hsl(0 0% 0% / 0.08), 0px 8px 16px -4px hsl(0 0% 0% / 0.08);
}

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

body {
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--foreground);
  background: var(--background);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
input, select, textarea { font-family: inherit; }

.font-display { font-family: var(--font-sans); letter-spacing: -0.01em; font-weight: 700; }
.tnum { font-variant-numeric: tabular-nums; font-family: var(--font-mono); letter-spacing: -0.01em; }

/* ---------- 应用外壳布局 ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: var(--sidebar);
  color: var(--sidebar-foreground);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 30;
}

.sidebar-brand {
  height: 60px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px;
  border-bottom: 1px solid var(--sidebar-border);
}
.sidebar-brand .logo {
  width: 28px; height: 28px;
  border-radius: 7px;
  background: var(--sidebar-primary);
  color: var(--sidebar-primary-foreground);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 15px;
  flex-shrink: 0;
}
.sidebar-brand .brand-title { font-weight: 700; font-size: 14.5px; letter-spacing: -0.01em; }
.sidebar-brand .brand-sub { font-size: 11px; color: var(--sidebar-foreground); opacity: 0.6; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 14px 12px; }
.nav-group { margin-bottom: 18px; }
.nav-group-title {
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--sidebar-foreground);
  opacity: 0.45;
  padding: 0 10px;
  margin-bottom: 6px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius);
  color: var(--sidebar-foreground);
  font-size: 13.5px;
  transition: background 0.15s ease, color 0.15s ease;
  margin-bottom: 2px;
}
.nav-item:hover { background: var(--sidebar-accent); color: var(--sidebar-accent-foreground); }
.nav-item.active { background: var(--sidebar-accent); color: var(--sidebar-accent-foreground); font-weight: 500; }
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; }

.sidebar-foot {
  padding: 12px 16px;
  border-top: 1px solid var(--sidebar-border);
  font-size: 11.5px;
  color: var(--sidebar-foreground);
  opacity: 0.55;
}

.main { flex: 1; margin-left: 232px; display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
  height: 60px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-title { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.topbar-user { display: flex; align-items: center; gap: 9px; font-size: 13px; }
.topbar-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--primary);
  color: var(--primary-foreground);
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 13px;
}
.topbar-meta { line-height: 1.25; }
.topbar-meta .name { font-weight: 500; }
.topbar-meta .role { font-size: 11px; color: var(--muted-foreground); }

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

/* ---------- 顶栏左侧与侧边栏折叠 ---------- */
.topbar-left { display: flex; align-items: center; gap: 12px; }
.sidebar-toggle-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--foreground);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s ease;
}
.sidebar-toggle-btn:hover { background: var(--muted); }
.sidebar-toggle-btn svg { width: 18px; height: 18px; transition: transform 0.2s ease; }

.sidebar { transition: width 0.2s ease; }
.main { transition: margin-left 0.2s ease; }

body.sidebar-collapsed .sidebar { width: 64px; }
body.sidebar-collapsed .main { margin-left: 64px; }
body.sidebar-collapsed .sidebar-brand { justify-content: center; padding: 0; }
body.sidebar-collapsed .brand-text { display: none; }
body.sidebar-collapsed .nav-group-title { display: none; }
body.sidebar-collapsed .nav-item span { display: none; }
body.sidebar-collapsed .nav-item { justify-content: center; padding: 8px 0; gap: 0; }
body.sidebar-collapsed .sidebar-foot { display: none; }
body.sidebar-collapsed .sidebar-toggle-btn svg { transform: rotate(180deg); }

/* ---------- 卡片 ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 20px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.card-title { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.card-desc { font-size: 12.5px; color: var(--muted-foreground); margin-top: 2px; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
  line-height: 1.4;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn svg { width: 15px; height: 15px; }
.btn-primary { background: var(--primary); color: var(--primary-foreground); }
.btn-primary:hover { background: hsl(163 45% 27%); }
.btn-secondary { background: var(--secondary); color: var(--secondary-foreground); border-color: var(--border); }
.btn-secondary:hover { background: var(--accent); }
.btn-outline { background: transparent; color: var(--foreground); border-color: var(--border); }
.btn-outline:hover { background: var(--muted); }
.btn-destructive { background: var(--destructive); color: var(--destructive-foreground); }
.btn-destructive:hover { background: hsl(2 68% 44%); }
.btn-ghost { background: transparent; color: var(--foreground); }
.btn-ghost:hover { background: var(--muted); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { padding: 6px; border-radius: var(--radius); }

/* ---------- 表单 ---------- */
.form-grid { display: grid; gap: 16px; }
.form-grid.two { grid-template-columns: 1fr 1fr; }
.form-grid.three { grid-template-columns: 1fr 1fr 1fr; }
.form-item { display: flex; flex-direction: column; gap: 6px; }
.form-item label { font-size: 12.5px; font-weight: 500; color: var(--foreground); }
.form-item label .req { color: var(--destructive); margin-left: 2px; }
.form-item .hint { font-size: 11.5px; color: var(--muted-foreground); }
.input, .select, .textarea {
  width: 100%;
  border: 1px solid var(--input);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--foreground);
  padding: 8px 11px;
  font-size: 13.5px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--ring);
  box-shadow: 0 0 0 3px hsl(163 45% 30% / 0.12);
}
.textarea { min-height: 76px; resize: vertical; }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table thead th {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted-foreground);
  background: var(--muted);
  text-align: left;
  padding: 5px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table tbody td {
  padding: 5px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
/* 矩阵录入表格内的输入框/下拉紧凑显示，减小行高 */
.table .input, .table .select {
  height: 28px;
  padding: 3px 8px;
  font-size: 13px;
}
.table tbody tr:hover td { background: var(--accent); }
.table tbody tr:last-child td { border-bottom: none; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--font-mono); }
.table .actions { text-align: right; white-space: nowrap; }

/* ---------- 用户选择器 ---------- */
.user-picker-field { display: flex; align-items: center; gap: 4px; }
.user-picker-trigger {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  min-width: 160px; width: 100%; height: 34px;
  padding: 0 10px;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--foreground); font-size: 13px; cursor: pointer;
}
.user-picker-trigger:hover { border-color: var(--primary); }
.user-picker-value { flex: 1; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-picker-value.placeholder { color: var(--muted-foreground); }
.user-picker-caret { color: var(--muted-foreground); display: flex; }
.user-picker-clear {
  display: flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border: none; border-radius: 50%;
  background: transparent; color: var(--muted-foreground); cursor: pointer;
}
.user-picker-clear:hover { background: var(--muted); color: var(--foreground); }

.user-picker-tools { display: flex; gap: 8px; margin-bottom: 10px; }
.user-picker-tools .input { flex: 1; min-width: 140px; }
.user-picker-tools .select { width: 160px; }
.user-picker-bar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px;
}
.up-selectall { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }
.user-picker-list {
  max-height: 320px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 4px;
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 6px;
}
.up-item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 9px; border-radius: 6px; cursor: pointer; font-size: 13px;
}
.up-item:hover { background: var(--accent); }
.up-item.checked { background: var(--accent); }
.up-check {
  width: 16px; height: 16px; flex-shrink: 0;
  border: 1px solid var(--border); border-radius: 4px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--card);
}
.up-item.checked .up-check { background: var(--primary); border-color: var(--primary); }
.up-item.checked .up-check::after {
  content: ''; width: 4px; height: 8px;
  border: solid #fff; border-width: 0 2px 2px 0;
  transform: rotate(45deg); margin-top: -2px;
}
.up-name { font-weight: 500; }
.up-dept { color: var(--muted-foreground); font-size: 12px; }

/* ---------- 徽章 ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge-neutral { background: var(--muted); color: var(--muted-foreground); }
.badge-primary { background: hsl(163 45% 92%); color: var(--primary); }
.badge-success { background: var(--status-steady-bg); color: var(--status-steady); }
.badge-warning { background: var(--status-warn-bg); color: var(--warning); }
.badge-danger { background: var(--status-danger-bg); color: var(--destructive); }
.badge-info { background: var(--status-fluctuant-bg); color: var(--status-fluctuant); }

/* 形态诊断 */
.badge-steady { background: var(--status-steady-bg); color: var(--status-steady); }
.badge-potential { background: var(--status-potential-bg); color: var(--status-potential); }
.badge-fluctuant { background: var(--status-fluctuant-bg); color: var(--status-fluctuant); }
.badge-overdraft { background: var(--status-overdraft-bg); color: var(--status-overdraft); }
.badge-low { background: var(--status-low-bg); color: var(--status-low); }
.badge-idle { background: var(--status-idle-bg); color: var(--status-idle); }

/* 数值色调 */
.tone-danger { color: var(--destructive); font-weight: 600; }
.tone-warning { color: var(--warning); font-weight: 600; }
.tone-success { color: var(--status-steady); font-weight: 600; }
.tone-muted { color: var(--muted-foreground); }

/* ---------- 筛选栏 ---------- */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  margin-bottom: 16px;
}
.filter-bar .filter-item { display: flex; flex-direction: column; gap: 5px; }
.filter-bar .filter-item label { font-size: 12px; color: var(--muted-foreground); }

/* ---------- 分页 ---------- */
.pagination { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 16px; font-size: 13px; color: var(--muted-foreground); }
.pagination .btn { padding: 5px 11px; }

/* ---------- 弹窗 ---------- */
.modal-mask {
  position: fixed;
  inset: 0;
  background: hsl(168 16% 10% / 0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  z-index: 100;
  padding: 60px 20px 20px;
  overflow-y: auto;
}
.modal {
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 560px;
  animation: modalIn 0.18s ease both;
}
.modal-lg { max-width: 760px; }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 15px; font-weight: 600; }
.modal-close { background: transparent; border: none; cursor: pointer; color: var(--muted-foreground); padding: 4px; border-radius: 6px; display: flex; }
.modal-close:hover { background: var(--muted); }
.modal-body { padding: 20px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); }
@keyframes modalIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

/* ---------- Toast ---------- */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.toast {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 11px 16px;
  font-size: 13.5px;
  display: flex;
  align-items: center;
  gap: 9px;
  animation: toastIn 0.2s ease both;
  min-width: 220px;
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--destructive); }
.toast.info { border-left: 3px solid var(--info); }
@keyframes toastIn {
  from { opacity: 0; transform: translateX(16px); }
  to { opacity: 1; transform: none; }
}

/* ---------- 统计卡片 KPI ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.kpi-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}
.kpi-label { font-size: 12px; color: var(--muted-foreground); margin-bottom: 8px; }
.kpi-value { font-size: 26px; font-weight: 700; font-family: var(--font-mono); letter-spacing: -0.02em; }
.kpi-sub { font-size: 12px; color: var(--muted-foreground); margin-top: 6px; }
.kpi-link { margin-top: 8px; font-size: 12.5px; }
.kpi-link a { color: var(--primary); text-decoration: none; }
.kpi-link a:hover { text-decoration: underline; }

/* ---------- 图表 ---------- */
.chart-box { width: 100%; height: 280px; }

/* ---------- 页面标题 ---------- */
.page-head { margin-bottom: 20px; }
.page-title { font-size: 20px; font-weight: 700; letter-spacing: -0.02em; }
.page-desc { font-size: 13px; color: var(--muted-foreground); margin-top: 4px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.mb-16 { margin-bottom: 16px; }
.mt-16 { margin-top: 16px; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.text-muted { color: var(--muted-foreground); }
.text-sm { font-size: 12.5px; }
.text-right { text-align: right; }
.w-full { width: 100%; }

/* ---------- 空状态 / 加载 ---------- */
.empty-state { text-align: center; padding: 48px 20px; color: var(--muted-foreground); font-size: 13.5px; }
.loading { text-align: center; padding: 32px; color: var(--muted-foreground); }

/* ---------- 标签页 ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tab {
  padding: 9px 16px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--muted-foreground);
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  margin-bottom: -1px;
}
.tab:hover { color: var(--foreground); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ---------- 登录页 ---------- */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(1200px 600px at 20% 0%, hsl(163 45% 24% / 0.14), transparent 60%),
              radial-gradient(900px 500px at 90% 100%, hsl(32 88% 46% / 0.10), transparent 55%),
              var(--background);
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  padding: 36px 32px;
}
.login-brand { display: flex; align-items: center; gap: 11px; margin-bottom: 6px; }
.login-brand .logo {
  width: 40px; height: 40px;
  border-radius: 10px;
  background: var(--primary);
  color: var(--primary-foreground);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 20px;
}
.login-brand .title { font-size: 18px; font-weight: 700; letter-spacing: -0.02em; }
.login-sub { color: var(--muted-foreground); font-size: 13px; margin-bottom: 26px; }

/* ---------- 响应式 ---------- */
@media (max-width: 900px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .form-grid.two, .form-grid.three { grid-template-columns: 1fr; }
  .sidebar { width: 200px; }
  .main { margin-left: 200px; }
}
