:root {
  --bg: #F6F7F9;
  --surface: #FFFFFF;
  --surface-subtle: #F9FAFB;
  --border: #E5E7EB;
  --border-light: #F1F5F9;
  --text: #111827;
  --text-secondary: #4B5563;
  --text-muted: #9CA3AF;

  --primary: #2563EB;
  --primary-hover: #1D4ED8;
  --primary-soft: #EFF6FF;

  /* 涨红跌绿（中国财务习惯） */
  --up: #DC2626;
  --up-bg: #FEF2F2;
  --down: #16A34A;
  --down-bg: #F0FDF4;
  --new-color: #D97706;
  --new-bg: #FFFBEB;
  --special-color: #7C3AED;
  --special-bg: #F5F3FF;
  --warn-color: #B45309;
  --warn-bg: #FEF3C7;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.05), 0 1px 2px rgba(15, 23, 42, 0.03);
  --shadow-md: 0 12px 32px rgba(15, 23, 42, 0.09), 0 2px 6px rgba(15, 23, 42, 0.04);
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.num {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}

.hidden { display: none !important; }

/* ---------------- 登录页 ---------------- */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at top left, #EEF2FF 0%, #F6F7F9 50%, #F8FAFC 100%);
}
.auth-card {
  width: 100%;
  max-width: 390px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 36px 32px 32px;
  box-shadow: var(--shadow-md);
}
.auth-logo {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: linear-gradient(135deg, #2563EB 0%, #4F46E5 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 18px;
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.25);
}
.auth-card h1 { margin: 0 0 6px; font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.auth-card p { margin: 0 0 24px; color: var(--text-secondary); font-size: 13px; }
.auth-error {
  margin-top: 12px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  background: var(--up-bg);
  color: var(--up);
  font-size: 13px;
}

/* ---------------- 顶部导航 ---------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.01em;
  color: var(--text);
  white-space: nowrap;
}
.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: linear-gradient(135deg, #2563EB 0%, #4F46E5 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
}
.nav-tabs {
  display: flex;
  align-items: center;
  background: #F1F5F9;
  padding: 4px;
  border-radius: 10px;
  gap: 2px;
}
.nav-tab {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13.5px;
  font-weight: 500;
  padding: 6px 15px;
  border-radius: 7px;
  cursor: pointer;
  transition: all 0.16s ease;
  white-space: nowrap;
}
.nav-tab:hover { color: var(--text); }
.nav-tab.active {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: var(--shadow-xs);
}
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ---------------- 按钮与输入 ---------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-subtle); border-color: #D1D5DB; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover { background: #F1F5F9; color: var(--text); border-color: transparent; }
.btn-danger {
  color: var(--up);
  border-color: #FECACA;
  background: #FFF;
}
.btn-danger:hover { background: var(--up-bg); border-color: #FCA5A5; }
.btn-sm { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn-icon { width: 34px; padding: 0; }

.input, .select, .textarea {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 13.5px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input[type="date"].input {
  display: flex;
  align-items: center;
  -webkit-appearance: none;
  appearance: none;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}
.select-compact {
  width: auto;
  height: 34px;
  padding: 0 28px 0 10px;
  font-size: 13px;
}

/* 导出下拉菜单 */
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 185px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 6px;
  z-index: 60;
}
.dropdown-item {
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  padding: 8px 10px;
  border-radius: 7px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.dropdown-item:hover { background: #F3F4F6; }
.dropdown-item small { color: var(--text-muted); font-size: 11.5px; }

/* ---------------- 主体布局 ---------------- */
.main-wrap {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px 24px 48px;
}

/* ---------------- AI 对话记账条 ---------------- */
.ai-bar-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}
.ai-input-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.ai-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: 999px;
  background: linear-gradient(135deg, #EFF6FF 0%, #F5F3FF 100%);
  color: #4F46E5;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}
.ai-input {
  flex: 1;
  height: 40px;
  border: 1px solid #E2E8F0;
  border-radius: 10px;
  padding: 0 14px;
  font-size: 14px;
  background: #FAFBFC;
  color: var(--text);
  outline: none;
  transition: all 0.16s;
}
.ai-input:focus {
  background: #FFF;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}
.ai-hints {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-muted);
  gap: 12px;
  flex-wrap: wrap;
}
.ai-status-link {
  color: var(--primary);
  cursor: pointer;
  background: none;
  border: none;
  font-size: 12px;
  padding: 0;
}
.ai-status-link:hover { text-decoration: underline; }

/* AI 待确认卡片区 */
.ai-draft-panel {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px dashed var(--border);
}
.ai-draft-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  gap: 12px;
}
.ai-draft-header h3 { margin: 0; font-size: 13.5px; font-weight: 600; }
.ai-draft-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.ai-draft-card {
  background: #F9FAFB;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
}
.ai-draft-grid {
  display: grid;
  grid-template-columns: 135px 135px minmax(0, 1fr) 165px auto;
  gap: 10px;
  align-items: center;
}
.ai-draft-grid > * {
  min-width: 0;
  max-width: 100%;
}
.ai-draft-toggles {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.ai-alert {
  margin-top: 8px;
  padding: 7px 11px;
  border-radius: 8px;
  font-size: 12.5px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.ai-alert--special { background: var(--special-bg); color: var(--special-color); }
.ai-alert--dup { background: var(--warn-bg); color: var(--warn-color); }

/* ---------------- 卡片与区块 ---------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-xs);
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.card-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-subtitle { font-size: 12.5px; color: var(--text-muted); font-weight: 400; }

/* ---------------- 看板视图 ---------------- */
.month-pills {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 16px;
  overflow-x: auto;
  padding-bottom: 4px;
}
.month-pill {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  padding: 5px 13px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}
.month-pill:hover { border-color: #CBD5E1; color: var(--text); }
.month-pill.active {
  background: var(--text);
  border-color: var(--text);
  color: #fff;
}

.kpi-formula-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 36px minmax(0, 1fr) 36px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  margin-bottom: 18px;
}
.kpi-operator {
  width: 32px;
  height: 32px;
  margin: 0 auto;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
  color: var(--text-secondary);
  font-size: 18px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow-xs);
  display: flex;
  flex-direction: column;
  gap: 8px;
  height: 100%;
  transition: border-color 0.16s, box-shadow 0.16s;
}
.kpi-card--clickable { cursor: pointer; }
.kpi-card--clickable:hover {
  border-color: #C4B5FD;
  box-shadow: 0 4px 14px rgba(124, 58, 237, 0.08);
}
.kpi-pill-sub {
  font-size: 11.5px;
  color: var(--text-muted);
  background: #F3F4F6;
  padding: 2px 7px;
  border-radius: 999px;
  font-weight: 500;
}
.kpi-pill-special {
  font-size: 11.5px;
  color: var(--special-color);
  background: var(--special-bg);
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 600;
}
.kpi-special-summary {
  color: var(--special-color);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
.kpi-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  gap: 6px;
}
.kpi-value-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}
.kpi-value {
  font-size: 27px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}
.kpi-meta {
  font-size: 12.5px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.chart-row-2 {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  gap: 18px;
  margin-top: 18px;
}
.chart-box { width: 100%; height: 320px; }
.chart-box--sm { width: 100%; height: 280px; }

.pie-layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 16px;
  align-items: center;
}
.pie-rank-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 270px;
  overflow-y: auto;
  padding-right: 4px;
}
.pie-rank-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 5px 8px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.14s;
}
.pie-rank-item:hover { background: #F8FAFC; }
.pie-rank-right {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}
.pie-rank-pct { color: var(--text-muted); font-size: 12px; min-width: 40px; text-align: right; }

.cat-chip-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}
.cat-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
}
.cat-chip.active {
  border-color: var(--chip-color);
  background: var(--chip-color);
  color: #FFFFFF;
  font-weight: 600;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.14);
}

.segment {
  display: inline-flex;
  background: #F1F5F9;
  padding: 3px;
  border-radius: 8px;
  gap: 2px;
}
.segment-btn {
  border: none;
  background: transparent;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
}
.segment-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-xs);
}

/* ---------------- 分类彩色徽章（实心深底白字，高辨识度）与环比标签 ---------------- */
.cat-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 7px;
  font-size: 12.5px;
  font-weight: 600;
  color: #FFFFFF;
  background: var(--cat-color);
  border: 1px solid rgba(0, 0, 0, 0.06);
  box-shadow: 0 1px 2px var(--cat-shadow, rgba(15, 23, 42, 0.16));
  white-space: nowrap;
  letter-spacing: 0.01em;
}
.cat-badge .icon {
  stroke: #FFFFFF;
  flex-shrink: 0;
}
.cat-badge--sm {
  padding: 3px 8px;
  font-size: 11.5px;
  gap: 4px;
  border-radius: 6px;
}

.mom {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.mom--up { color: var(--up); background: var(--up-bg); }
.mom--down { color: var(--down); background: var(--down-bg); }
.mom--new { color: var(--new-color); background: var(--new-bg); }
.mom--flat { color: var(--text-muted); background: #F3F4F6; }
.mom--none { color: #94A3B8; font-weight: 500; }
.mom--na { color: #94A3B8; font-weight: 500; }

/* ---------------- 月度统计矩阵表（Sheet 2 复刻） ---------------- */
.matrix-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
}
.matrix-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}
.matrix-table th, .matrix-table td {
  padding: 10px 10px;
  border-bottom: 1px solid var(--border-light);
  white-space: nowrap;
}
.matrix-table thead th {
  background: #F8FAFC;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 12.5px;
  border-bottom: 1px solid var(--border);
  text-align: right;
}
.matrix-table thead th.month-group {
  text-align: center;
  border-left: 1px solid var(--border-light);
}
.matrix-table thead th.month-group.is-current {
  color: var(--primary);
  background: #EFF6FF;
}
.matrix-table .sticky-col {
  position: sticky;
  left: 0;
  z-index: 10;
  background: var(--surface);
  border-right: 1px solid var(--border);
  text-align: left;
  min-width: 145px;
}
.matrix-table thead .sticky-col {
  background: #F8FAFC;
  z-index: 15;
}
.matrix-table tbody tr:hover td { background: #FAFBFD; }
.matrix-table tbody tr:hover .sticky-col { background: #FAFBFD; }

.matrix-cell-amt {
  text-align: right;
  border-left: 1px solid var(--border-light);
  font-weight: 500;
}
.matrix-cell-amt.clickable { cursor: pointer; }
.matrix-cell-amt.clickable:hover {
  color: var(--primary);
  text-decoration: underline;
  background: #EFF6FF !important;
}
.matrix-cell-amt.is-na { color: #94A3B8; font-weight: 400; }
.matrix-cell-mom { text-align: center; padding-left: 4px !important; }

.matrix-row-archived td { opacity: 0.72; }
.archived-tag {
  font-size: 10.5px;
  color: var(--text-muted);
  background: #F1F5F9;
  padding: 1px 5px;
  border-radius: 4px;
  margin-left: 4px;
}

.matrix-table tr.summary-total td {
  background: #F8FAFC;
  font-weight: 700;
  border-top: 2px solid var(--border);
  color: var(--text);
}
.matrix-table tr.summary-total .sticky-col { background: #F8FAFC; }

.matrix-table tr.summary-regular td {
  background: #EFF6FF;
  font-weight: 700;
  color: #1E3A8A;
}
.matrix-table tr.summary-regular .sticky-col { background: #EFF6FF; }

.matrix-table tr.summary-note td {
  background: #FDFCFE;
  font-size: 12px;
  color: var(--special-color);
  vertical-align: top;
  white-space: normal;
  min-width: 120px;
  max-width: 185px;
  line-height: 1.45;
  border-left: 1px solid var(--border-light);
}
.matrix-table tr.summary-note .sticky-col {
  background: #FDFCFE;
  color: var(--text-secondary);
  font-weight: 500;
}
.special-note-btn {
  border: none;
  background: var(--special-bg);
  color: var(--special-color);
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 12px;
  text-align: left;
  cursor: pointer;
  display: inline-block;
  line-height: 1.4;
}
.special-note-btn:hover { background: #EDE9FE; }

/* ---------------- 明细台账与分类管理 ---------------- */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.filter-bar .input-search { width: 220px; height: 34px; }
.filter-summary {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 13px;
  color: var(--text-secondary);
}
.filter-summary strong { color: var(--text); font-weight: 600; }

.data-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.data-table th {
  text-align: left;
  padding: 10px 14px;
  background: #F8FAFC;
  color: var(--text-secondary);
  font-size: 12.5px;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}
.data-table tbody tr:hover { background: #FAFBFD; }
.data-table .col-amount { text-align: right; font-weight: 600; white-space: nowrap; }
.data-table .col-actions { text-align: right; white-space: nowrap; }

.credit-tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 5px;
  font-size: 11.5px;
  font-weight: 500;
  color: #1D4ED8;
  background: #EFF6FF;
  border: 1px solid #BFDBFE;
}
.raw-remark-tag {
  display: inline-flex;
  align-items: center;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 11px;
  color: var(--warn-color);
  background: var(--warn-bg);
  margin-left: 6px;
}
.fx-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 6px;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  font-style: italic;
  color: #4F46E5;
  background: #EEF2FF;
  border: 1px solid #C7D2FE;
  cursor: help;
}
.fx-expr-inline {
  display: block;
  font-size: 11.5px;
  font-weight: 400;
  color: var(--text-muted);
  margin-top: 2px;
}

/* 特殊计项开关 */
.special-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
}
.special-toggle:hover { border-color: #C4B5FD; color: var(--special-color); }
.special-toggle.active {
  background: var(--special-bg);
  border-color: #C4B5FD;
  color: var(--special-color);
  font-weight: 600;
}

/* 分类管理网格 */
.cat-manage-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 12px;
}
.cat-manage-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.cat-manage-card.is-archived { background: #F8FAFC; opacity: 0.8; }
.cat-manage-meta { font-size: 12px; color: var(--text-muted); margin-top: 5px; }
.cat-manage-actions { display: flex; align-items: center; gap: 4px; }

/* ---------------- 弹窗与抽屉 ---------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.42);
  backdrop-filter: blur(3px);
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal {
  width: 100%;
  max-width: 500px;
  background: var(--surface);
  border-radius: 18px;
  box-shadow: var(--shadow-md);
  overflow: hidden;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
}
.modal-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h3 { margin: 0; font-size: 16px; font-weight: 600; }
.modal-body { padding: 20px 22px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.modal-footer {
  padding: 14px 22px;
  border-top: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  background: #FAFBFC;
}

.form-field { display: flex; flex-direction: column; gap: 6px; }
.form-field label { font-size: 12.5px; font-weight: 600; color: var(--text-secondary); }
.form-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-hint { font-size: 12px; color: var(--text-muted); }
.formula-preview { font-size: 12.5px; font-weight: 600; color: var(--primary); }
.formula-preview.error { color: var(--up); }

.checkbox-row {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}

/* 图标与颜色选择器 */
.color-picker-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.color-swatch {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  border: 2px solid transparent;
  cursor: pointer;
}
.color-swatch.active { border-color: #111827; transform: scale(1.1); }
.icon-picker-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
}
.icon-choice {
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.icon-choice:hover { background: #F3F4F6; }
.icon-choice.active { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }

/* 右侧下钻抽屉 */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  z-index: 75;
  display: flex;
  justify-content: flex-end;
}
.drawer {
  width: 100%;
  max-width: 520px;
  height: 100%;
  background: var(--surface);
  box-shadow: -10px 0 32px rgba(15, 23, 42, 0.12);
  display: flex;
  flex-direction: column;
}
.drawer-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.drawer-body { padding: 16px 22px; overflow-y: auto; flex: 1; }
.drawer-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-light);
}

/* Toast 提示 */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 120;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: #111827;
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: var(--shadow-md);
  animation: fadeUp 0.2s ease;
}
.toast--error { background: var(--up); }
.toast--success { background: #059669; }
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* 手机端原生账单卡片流（桌面隐藏，<= 640px 启用） */
.tx-mobile-list { display: none; }

/* 响应式 */
@media (max-width: 960px) {
  .topbar-inner {
    flex-wrap: wrap;
    height: auto;
    padding: 10px 14px;
    gap: 8px;
  }
  .nav-tabs {
    order: 3;
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    padding: 3px;
  }
  .nav-tab { text-align: center; }
  .topbar-actions { flex-wrap: wrap; }
  .chart-row-2, .pie-layout { grid-template-columns: 1fr; }
  .kpi-formula-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  .kpi-operator {
    width: 26px;
    height: 26px;
    font-size: 15px;
  }
  .ai-draft-grid { grid-template-columns: 1fr 1fr; }
  .main-wrap { padding: 14px 14px 40px; }
}

@media (max-width: 640px) {
  /* 防止 iOS Safari 聚焦输入框自动放大 */
  .input, .select, .textarea, .ai-input {
    font-size: 16px !important;
  }

  /* 顶栏紧凑布局 + 安全区 */
  .topbar {
    padding-top: env(safe-area-inset-top, 0px);
  }
  .topbar-inner {
    flex-wrap: wrap;
    height: auto;
    padding: 10px 12px;
    gap: 8px;
  }
  .brand { font-size: 15px; gap: 7px; }
  .brand-mark { width: 26px; height: 26px; border-radius: 7px; }
  .topbar-actions {
    gap: 5px;
    flex-wrap: nowrap;
  }
  .topbar-actions .btn,
  .topbar-actions .select-compact {
    height: 32px;
    padding: 0 9px;
    font-size: 12.5px !important;
  }
  #btn-ai-settings,
  #btn-logout {
    padding: 0 7px;
  }
  .nav-tabs {
    order: 3;
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    padding: 3px;
  }
  .nav-tab {
    padding: 7px 6px;
    font-size: 13px;
    text-align: center;
  }

  .main-wrap {
    padding: 12px 12px calc(32px + env(safe-area-inset-bottom, 0px));
  }

  /* AI 记账条手机端全宽输入 + 易点击大按钮 */
  .ai-bar-card {
    padding: 12px;
    border-radius: 14px;
    margin-bottom: 14px;
  }
  .ai-input-row {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .ai-badge {
    align-self: flex-start;
  }
  .ai-input {
    flex: none;
    width: 100%;
    height: 44px;
    min-height: 44px;
    padding: 0 12px;
  }
  #btn-ai-parse {
    width: 100%;
    height: 42px !important;
    font-size: 14.5px;
  }
  .ai-hints {
    font-size: 11.5px;
    gap: 6px;
  }
  .ai-draft-grid { grid-template-columns: minmax(0, 1fr); gap: 8px; }
  .ai-draft-card { padding: 12px; overflow: hidden; }

  /* 看板与 KPI 卡片手机端优化 */
  .card {
    padding: 14px;
    border-radius: 14px;
  }
  .kpi-card { padding: 15px 16px; border-radius: 14px; }
  .kpi-value { font-size: 25px; }
  .chart-box { height: 245px; }
  .chart-box--sm { height: 225px; }
  .pie-rank-list { max-height: none; }

  /* 月度统计矩阵表窄屏收紧固定列与单元格，丝滑横滑 */
  .matrix-wrap {
    -webkit-overflow-scrolling: touch;
    margin: 0 -4px;
  }
  .matrix-table { font-size: 12px; }
  .matrix-table th, .matrix-table td { padding: 8px 6px; }
  .matrix-table .sticky-col {
    min-width: 94px;
    max-width: 108px;
    padding-left: 8px;
    padding-right: 6px;
  }
  .matrix-table .sticky-col .cat-badge--sm {
    padding: 2px 6px;
    font-size: 11px;
    gap: 3px;
  }
  .matrix-table .archived-tag { display: none; }

  /* 明细页筛选栏网格对齐 + 桌面表格切手机账单流卡片 */
  .filter-bar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .filter-bar .select-compact {
    width: 100%;
    height: 38px;
    font-size: 14px !important;
  }
  .filter-bar .input-search {
    grid-column: 1 / -1;
    width: 100%;
    height: 40px;
  }
  .filter-summary {
    grid-column: 1 / -1;
    margin-left: 0;
    padding: 8px 10px;
    background: #F8FAFC;
    border-radius: 8px;
    justify-content: space-between;
    font-size: 12.5px;
  }

  .desktop-only-table { display: none; }
  .tx-mobile-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
  }
  .tx-mobile-card {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 13px;
    background: var(--surface);
    box-shadow: var(--shadow-xs);
  }
  .tx-mobile-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
  }
  .tx-mobile-left { min-width: 0; flex: 1; }
  .tx-mobile-badges {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 6px;
  }
  .tx-mobile-date { font-size: 12px; color: var(--text-muted); }
  .tx-mobile-detail {
    font-size: 14.5px;
    font-weight: 500;
    color: var(--text);
    word-break: break-word;
  }
  .tx-mobile-amount {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
    text-align: right;
    padding-top: 2px;
  }
  .tx-mobile-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 10px;
    padding-top: 9px;
    border-top: 1px solid var(--border-light);
  }
  .tx-mobile-ops { display: flex; align-items: center; gap: 4px; }

  /* 弹窗与抽屉切换为手机端 Bottom Sheet（底部圆角弹出） */
  .modal-backdrop {
    align-items: flex-end;
    padding: 0;
  }
  .modal {
    max-width: 100%;
    border-radius: 20px 20px 0 0;
    max-height: 90vh;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .form-row-2 { grid-template-columns: 1fr; }
  .icon-picker-grid { grid-template-columns: repeat(6, 1fr); }

  .drawer-backdrop { align-items: flex-end; }
  .drawer {
    max-width: 100%;
    height: 82vh;
    border-radius: 20px 20px 0 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .toast-container {
    left: 14px;
    right: 14px;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  }
  .toast { text-align: center; }
}
