/* ===========================================
   Company Ledger · Design System v2.0
   扁平 · 8px 间距 · 统一 Token · 暗色支持
   =========================================== */

/* ---------- Reset ---------- */
*,*::before,*::after { margin:0; padding:0; box-sizing:border-box; }
html { -webkit-text-size-adjust: 100%; }
button,input,select,textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; }

/* ---------- Tokens ---------- */
:root {
  /* Brand */
  --brand-50:  #eff6ff;
  --brand-100: #dbeafe;
  --brand-500: #2563eb;
  --brand-600: #1d4ed8;
  --brand-700: #1e40af;

  /* Status */
  --success-50:#ecfdf5; --success-500:#10b981; --success-600:#059669; --success-700:#047857;
  --warning-50:#fffbeb; --warning-500:#f59e0b; --warning-700:#b45309;
  --danger-50: #fef2f2; --danger-500: #ef4444; --danger-600:#dc2626; --danger-700:#b91c1c;
  --info-50:   #f0f9ff; --info-500:   #0ea5e9; --info-700:  #0369a1;

  /* Neutrals (slate) */
  --gray-0:   #ffffff;
  --gray-50:  #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-300: #cbd5e1;
  --gray-400: #94a3b8;
  --gray-500: #64748b;
  --gray-700: #334155;
  --gray-900: #0f172a;

  /* Surfaces */
  --bg:           var(--gray-50);
  --surface:      var(--gray-0);
  --surface-alt:  var(--gray-100);
  --text:         var(--gray-900);
  --text-muted:   var(--gray-500);
  --border:       var(--gray-200);
  --border-strong:var(--gray-300);

  /* Sidebar (dark-differentiated, flat) */
  --side-bg:        #0f172a;
  --side-bg-hover:  rgba(255,255,255,.06);
  --side-item:      #94a3b8;
  --side-active-bg: rgba(37,99,235,.18);
  --side-border:    rgba(255,255,255,.06);
  /* 侧栏滚动条滑块：--side-bg 的近似同族色（半透明白叠在深蓝底上，比 --gray-300 更贴合） */
  --side-scrollbar-thumb:       rgba(255,255,255,.16);
  --side-scrollbar-thumb-hover: rgba(255,255,255,.28);

  /* Type */
  --font-sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei",
               "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", Consolas, monospace;

  --fs-xs: 11px; --fs-sm: 12px; --fs-md: 14px; --fs-lg: 16px;
  --fs-xl: 18px; --fs-2xl: 22px; --fs-3xl: 28px;
  --lh-tight: 1.25; --lh-base: 1.6;

  /* Spacing (8px base) */
  --sp-1:4px; --sp-2:8px; --sp-3:12px; --sp-4:16px;
  --sp-5:20px; --sp-6:24px; --sp-8:32px; --sp-10:40px; --sp-14:56px;

  /* Radius */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-pill: 999px;

  /* Shadow */
  --shadow-xs: 0 1px 2px rgba(15,23,42,.04);
  --shadow-sm: 0 1px 3px rgba(15,23,42,.06), 0 1px 2px rgba(15,23,42,.04);
  --shadow-md: 0 4px 10px -2px rgba(15,23,42,.08), 0 2px 4px -2px rgba(15,23,42,.04);
  --shadow-lg: 0 12px 24px -8px rgba(15,23,42,.12);

  /* Motion */
  --ease: cubic-bezier(.4,0,.2,1);
  --dur-fast: 120ms;
  --dur-base: 180ms;
  --dur-slow: 260ms;
}

[data-theme="dark"] {
  --bg:           #0b1220;
  --surface:      #111827;
  --surface-alt:  #1f2937;
  --text:         #f1f5f9;
  --text-muted:   #94a3b8;
  --border:       #1f2937;
  --border-strong:#374151;
  --shadow-xs: 0 1px 2px rgba(0,0,0,.4);
  --shadow-sm: 0 1px 3px rgba(0,0,0,.5), 0 1px 2px rgba(0,0,0,.4);
  --shadow-md: 0 4px 10px -2px rgba(0,0,0,.5);
  --side-bg:    #0a0f1c;
  /* 底色更深，滑块 alpha 相应下调，保持与亮色主题一致的柔和度 */
  --side-scrollbar-thumb:       rgba(255,255,255,.13);
  --side-scrollbar-thumb-hover: rgba(255,255,255,.24);
}

/* ---------- 基础排版 ---------- */
body {
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  line-height: var(--lh-base);
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
a { color: var(--brand-500); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible {
  outline: 2px solid var(--brand-500);
  outline-offset: 2px;
  border-radius: 4px;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0ms !important;
    animation-duration: 0ms !important;
  }
}

/* ---------- 图标系统 ---------- */
.ico { display: inline-block; vertical-align: middle; flex-shrink: 0; }

/* ---------- 侧边栏 ---------- */
.sidebar {
  width: 232px;
  background: var(--side-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}
.sidebar .logo {
  padding: 18px 20px;
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  border-bottom: 1px solid var(--side-border);
  display: flex; align-items: center; gap: 10px;
  letter-spacing: .3px;
}
.sidebar .logo .ico { color: var(--brand-500); }
.nav {
  flex: 1; padding: 14px 12px; overflow-y: auto;
  /* Firefox：滑块/轨道 */
  scrollbar-width: thin;
  scrollbar-color: var(--side-scrollbar-thumb) transparent;
}
/* 侧栏滚动条：用侧栏底色的近似同族色（半透明白叠在 --side-bg 上，比 --gray-300 贴合）
   注：Chromium 121+ / Firefox 以标准属性 scrollbar-color、scrollbar-width 为准，
   并会忽略下方的 ::-webkit-scrollbar-*；Safari 与旧版 Chromium 才走 webkit 规则。
   两者颜色必须保持一致，改色时请同步修改 --side-scrollbar-thumb(-hover) */
.sidebar .nav::-webkit-scrollbar { width: 8px; }
.sidebar .nav::-webkit-scrollbar-track { background: transparent; }
.sidebar .nav::-webkit-scrollbar-thumb {
  background: var(--side-scrollbar-thumb);
  border-radius: var(--radius-pill);
}
.sidebar .nav::-webkit-scrollbar-thumb:hover {
  background: var(--side-scrollbar-thumb-hover);
}
.nav-group-title {
  padding: 14px 12px 8px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: #475569;
  font-weight: 600;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px;
  margin-bottom: 2px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--side-item);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
  border-left: 3px solid transparent;
  user-select: none;
  position: relative;
}
.nav-item:hover { background: var(--side-bg-hover); color: #fff; }
.nav-item:hover .ico { color: #fff; }
.nav-item.active {
  background: var(--side-active-bg);
  color: #fff;
  font-weight: 500;
}
.nav-item.active .ico { color: #fff; }
.nav-item .ico { width: 18px; height: 18px; color: var(--side-item); transition: color var(--dur-fast) var(--ease); }
.nav-item .badge {
  margin-left: auto;
  background: var(--brand-500);
  color: #fff;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: var(--radius-pill);
  font-weight: 600;
}
.sidebar-footer {
  padding: 12px 16px;
  font-size: 11px;
  color: #475569;
  border-top: 1px solid var(--side-border);
  display: flex; align-items: center; gap: 8px;
}

/* ---------- 侧边栏收起/展开 ---------- */
.sidebar { transition: width var(--dur-base) var(--ease); }
.sidebar-toggle {
  flex-shrink: 0;
  width: 28px; height: 28px;
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent;
  border: 1px solid var(--side-border);
  border-radius: 6px;
  color: var(--side-item);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.sidebar-toggle:hover { background: var(--side-bg-hover); color: #fff; }
.sidebar-toggle .ico { width: 16px; height: 16px; transition: transform var(--dur-base) var(--ease); transform: rotate(180deg); }
.sidebar-footer-text { white-space: nowrap; overflow: hidden; }

/* 手机抽屉遮罩（桌面常驻但不可见，手机打开抽屉时淡入） */
.sidebar-mask {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, .5);
  z-index: 90;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-slow) var(--ease);
}
/* 遮罩仅在「手机抽屉打开」时显示：规则见下方 ≤640px 媒体查询，
   若写在全局，手机开抽屉后横屏（宽度 >640）会残留遮罩 */

/* 收起态：宽度 64px，仅显示图标 */
body.sidebar-collapsed .sidebar { width: 64px; }
body.sidebar-collapsed .main { margin-left: 64px; }
body.sidebar-collapsed .sidebar .logo span,
body.sidebar-collapsed .nav-group-title,
body.sidebar-collapsed .sidebar-footer-text { display: none; }
body.sidebar-collapsed .sidebar .logo { justify-content: center; padding: 18px 0; }
body.sidebar-collapsed .nav-item { justify-content: center; padding: 12px 0; border-left: none; border-right: 3px solid transparent; font-size: 0; gap: 0; }
body.sidebar-collapsed .nav-item.active { border-right-color: var(--brand-500); border-left: none; }
body.sidebar-collapsed .nav-item .ico { color: var(--side-item); }
body.sidebar-collapsed .nav-item.active .ico { color: #fff; }
body.sidebar-collapsed .sidebar-footer { justify-content: center; padding: 12px 0; }
body.sidebar-collapsed .sidebar-toggle .ico { transform: rotate(0deg); }

/* ---------- 导航分组折叠/展开 ---------- */
.nav-group-title {
  display: flex; align-items: center; justify-content: space-between;
  cursor: pointer;
  user-select: none;
  transition: color var(--dur-fast) var(--ease);
}
.nav-group-title:hover { color: #cbd5e1; }
.nav-group-title .group-caret {
  width: 12px; height: 12px;
  color: #475569;
  transition: transform var(--dur-fast) var(--ease);
  flex-shrink: 0;
}
.nav-group-title.collapsed .group-caret { transform: rotate(-90deg); }
/* 收起态下隐藏分组标题的箭头（整个标题已隐藏） */
body.sidebar-collapsed .nav-group-title .group-caret { display: none; }

/* ---------- 主区域 ---------- */
.main { flex: 1; margin-left: 232px; display: flex; flex-direction: column; min-width: 0; }
.header {
  background: var(--surface);
  padding: 12px 24px;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
  backdrop-filter: blur(8px);
}
.header-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.menu-btn {
  display: none;
  width: 36px; height: 36px; flex: 0 0 auto;
  align-items: center; justify-content: center;
  background: transparent; border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.menu-btn:hover { background: var(--surface-alt); color: var(--text); }
.menu-btn .ico { width: 20px; height: 20px; }
.header .page-info { min-width: 0; }
.header .page-info h2 { font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header .page-info .sub { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.user-box { display: flex; align-items: center; gap: 10px; }
.user-trigger {
  display: inline-flex; align-items: center; gap: 10px;
  background: transparent; border: 1px solid transparent; padding: 4px 8px 4px 10px;
  border-radius: 10px; cursor: pointer; color: inherit;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}
.user-trigger:hover { background: var(--brand-50); }
.user-trigger[aria-expanded="true"] { background: var(--brand-50); border-color: var(--brand-100, var(--border)); }
.user-caret { display: inline-flex; color: var(--text-muted); transition: transform var(--dur-fast) var(--ease); }
.user-trigger[aria-expanded="true"] .user-caret { transform: rotate(180deg); color: var(--brand-500); }
.user-info { text-align: right; display: flex; flex-direction: column; }
.user-info .uname { font-size: 13px; font-weight: 600; color: var(--text); }
.user-info .urole { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.user-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--brand-500); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 600;
  font-size: 13px;
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 3px var(--brand-500);
}
.user-menu {
  position: absolute; top: calc(100% + 8px); right: 0;
  min-width: 220px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 6px;
  z-index: 200;
  opacity: 0; transform: translateY(-4px);
  pointer-events: none;
  transition: opacity var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.user-menu.open { opacity: 1; transform: translateY(0); pointer-events: auto; }
.user-menu-head {
  padding: 8px 10px 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
}
.user-menu-head .uname { font-size: 13px; font-weight: 600; color: var(--text); }
.user-menu-head .urole { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.user-menu-item {
  display: flex; align-items: center; gap: 8px;
  width: 100%;
  background: transparent; border: none;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px; color: var(--text);
  cursor: pointer; text-align: left;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.user-menu-item:hover { background: var(--brand-50); color: var(--brand-600); }
.user-menu-item.danger:hover { background: var(--danger-50); color: var(--danger-600); }
.user-menu-item .ico { color: currentColor; }
#userBox { position: relative; }
.readonly-note { color: var(--gray-400); font-size: 11px; display: inline-flex; align-items: center; gap: 4px; }

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

/* ---------- 页签栏 ---------- */
.tabbar {
  display: flex;
  align-items: stretch;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0 16px;
  scrollbar-width: thin;
  position: sticky;
  top: 56px;            /* header 高度 */
  z-index: 40;
  backdrop-filter: blur(8px);
}
.tabbar::-webkit-scrollbar { height: 4px; }
.tabbar::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 2px; }
.tabbar::-webkit-scrollbar-track { background: transparent; }

.tab-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 14px 8px;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-right: 1px solid var(--border);
  white-space: nowrap;
  position: relative;
  user-select: none;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
  min-width: 0;
}
.tab-item:first-child { border-left: 1px solid var(--border); }
.tab-item:hover { background: var(--bg-hover, var(--side-bg-hover)); color: var(--text); }
.tab-item.active {
  background: var(--bg);
  color: var(--brand-500);
  font-weight: 600;
}
.tab-item.active::after {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 2px;
  background: var(--brand-500);
}
.tab-item .tab-title {
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
}
.tab-close {
  margin-left: 2px;
  width: 18px; height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  flex: 0 0 auto;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.tab-close:hover { background: var(--danger); color: #fff; }
.tab-close svg { width: 10px; height: 10px; stroke-width: 2.5; }

/* ---------- 数据管理卡片（仪表盘内） ---------- */
.kv-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px 16px;
  margin-top: 4px;
}
.kv {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 0;
  border-bottom: 1px dashed var(--border);
  font-size: 13px;
}
.kv:last-child { border-bottom: none; }
.kv .k {
  width: 110px;
  color: var(--text-muted);
  flex: 0 0 auto;
}
.kv .v {
  flex: 1;
  color: var(--text);
  word-break: break-all;
  overflow-wrap: anywhere;
}
.kv .copy-btn { flex: 0 0 auto; }
.copy-btn { padding: 4px 6px; color: var(--text-muted); }
.copy-btn:hover { color: var(--brand-500); background: var(--brand-50); }

/* ---------- 卡片（Dashboard / Stats） ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  box-shadow: var(--shadow-xs);
  transition: box-shadow var(--dur-base) var(--ease), transform var(--dur-base) var(--ease);
}
.stat-card:hover { box-shadow: var(--shadow-sm); transform: translateY(-1px); }
.stat-card .label {
  font-size: 12px; color: var(--text-muted);
  margin-bottom: 8px;
  display: flex; align-items: center; gap: 6px;
}
.stat-card .value { font-size: var(--fs-2xl); font-weight: 700; font-variant-numeric: tabular-nums; line-height: var(--lh-tight); }
.stat-card .value.money { color: var(--brand-600); }
.stat-card .value.income { color: var(--success-700); }
.stat-card .value.expense { color: var(--danger-700); }
.stat-card .value.bal-pos { color: var(--brand-600); }
.stat-card .value.bal-neg { color: var(--danger-700); }
.stat-card .hint { font-size: 11px; color: var(--text-muted); margin-top: 8px; display: flex; align-items: center; gap: 4px; }
.stat-card .icon-badge {
  width: 28px; height: 28px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--brand-50); color: var(--brand-500);
  margin-bottom: 6px;
}
.stat-card.income-card .icon-badge { background: var(--success-50); color: var(--success-600); }
.stat-card.expense-card .icon-badge { background: var(--danger-50); color: var(--danger-500); }

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  box-shadow: var(--shadow-xs);
  margin-bottom: 20px;
}
.chart-card h3 { font-size: 14px; margin-bottom: 14px; color: var(--text); font-weight: 600; }
.chart-card h3 .ico { color: var(--brand-500); margin-right: 6px; }
.bar-wrap { display: flex; align-items: center; gap: 12px; margin: 10px 0; }
.bar-label { width: 80px; font-size: 12px; color: var(--text-muted); text-align: right; flex-shrink: 0; }
.bar-track { flex: 1; height: 22px; background: var(--surface-alt); border-radius: 4px; overflow: hidden; }
.bar-fill {
  height: 100%;
  background: var(--brand-500);
  border-radius: 4px;
  min-width: 2px;
  transition: width var(--dur-slow) var(--ease);
}
.bar-fill.income { background: var(--success-500); }
.bar-fill.expense { background: var(--danger-500); }
.bar-val { width: 100px; font-size: 12px; color: var(--text); flex-shrink: 0; text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- 按租户汇总表 ---------- */
.summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  box-shadow: var(--shadow-xs);
  margin-bottom: 20px;
}
.summary-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px; flex-wrap: wrap; gap: 10px;
}
.summary-head h3 { font-size: 14px; color: var(--text); font-weight: 600; margin: 0; }
.summary-head label { font-size: 12px; color: var(--text-muted); display: inline-flex; align-items: center; gap: 6px; }
.summary-head input[type=month] {
  padding: 5px 10px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface-alt); color: var(--text); font-size: 12px;
}
.summary-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.summary-table th, .summary-table td {
  padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border);
}
.summary-table th { color: var(--text-muted); font-weight: 600; font-size: 12px; background: var(--surface-alt); }
.summary-table td.num, .summary-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.summary-table td.strong { font-weight: 700; color: var(--text); }
.summary-table tfoot td { font-weight: 700; border-top: 2px solid var(--border); background: var(--surface-alt); color: var(--text); }
.summary-table td.empty { text-align: center; color: var(--text-muted); padding: 20px; }

/* ---------- 报表统计条 ---------- */
.report-meta {
  display: flex; flex-wrap: wrap; gap: 20px;
  margin: 12px 0 16px; padding: 10px 14px;
  background: var(--surface-alt); border: 1px solid var(--border);
  border-radius: var(--radius-md); font-size: 13px;
}
.report-meta span { display: inline-flex; align-items: center; gap: 6px; }
.report-meta b { font-size: 15px; }

/* ---------- 打印样式（导出 PDF） ---------- */
@media print {
  @page { size: A4 landscape; margin: 12mm; }
  .sidebar, .sidebar-mask, .header, .tabbar, .sidebar-footer { display: none !important; }
  .main { margin: 0 !important; padding: 0 !important; }
  #content { padding: 0 !important; }
  .report-print { box-shadow: none; border: none; background: #fff; overflow: visible !important; }
  .report-print .summary-head .btn, .report-print .summary-head label { display: none !important; }
  .report-print h3 { font-size: 16px; }
  .summary-table th, .summary-table td { padding: 4px 6px; font-size: 11px; }
  .tag { border: 1px solid #999 !important; color: #333 !important; }
}

/* ---------- 工具栏 / 输入 ---------- */
.toolbar {
  display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  box-shadow: var(--shadow-xs);
}
.toolbar .spacer { flex: 1; }
.toolbar input, .toolbar select { min-width: 140px; }
.toolbar .total {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 10px;
  background: var(--brand-50);
  color: var(--brand-700);
  border-radius: var(--radius-sm);
  font-size: 12px; font-weight: 500;
}
.input, .select, .textarea, .search-input,
input[type="text"], input[type="password"], input[type="number"], input[type="email"],
input[type="search"], input[type="date"], input[type="month"], input[type="time"],
input[type="url"], input[type="tel"], input:not([type]),
select, textarea {
  height: 36px;
  padding: 0 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: var(--fs-md);
  outline: none;
  box-sizing: border-box;
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
textarea, .textarea { padding: 10px 12px; height: auto; min-height: 80px; resize: vertical; line-height: 1.5; }
.input:focus, .select:focus, .textarea:focus, .search-input:focus,
input[type="text"]:focus, input[type="password"]:focus, input[type="number"]:focus,
input[type="email"]:focus, input[type="search"]:focus, input[type="date"]:focus,
input[type="month"]:focus, input[type="time"]:focus, input[type="url"]:focus,
input[type="tel"]:focus, input:not([type]):focus,
select:focus, textarea:focus {
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.input::placeholder, .search-input::placeholder,
input::placeholder, textarea::placeholder { color: var(--gray-400); }
input:disabled, select:disabled, textarea:disabled,
.input:disabled, .select:disabled, .textarea:disabled {
  background: var(--gray-100);
  color: var(--text-muted);
  cursor: not-allowed;
}
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type="number"] { -moz-appearance: textfield; }
input.search-input { width: 220px; padding-left: 32px; background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="%2394a3b8" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="11" cy="11" r="7"/><path d="m20 20-3.5-3.5"/></svg>'); background-repeat: no-repeat; background-position: 10px center; }
.select, select { padding-right: 28px; appearance: none; background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="%2364748b" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m6 9 6 6 6-6"/></svg>'); background-repeat: no-repeat; background-position: right 8px center; }
.search-wrap { position: relative; }
.search-wrap .ico { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--gray-400); pointer-events: none; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--brand-500);
  color: #fff;
  font-size: var(--fs-md);
  font-weight: 500;
  white-space: nowrap;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
  user-select: none;
}
.btn:hover { background: var(--brand-600); box-shadow: var(--shadow-sm); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; box-shadow: none; }
.btn.btn-sm   { height: 28px; padding: 0 10px; font-size: 12px; }
.btn.btn-lg   { height: 44px; padding: 0 20px; font-size: 16px; }
.btn.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn.btn-secondary:hover { background: var(--brand-50); color: var(--brand-600); border-color: var(--brand-500); box-shadow: none; transform: none; }
.btn.btn-ghost { background: transparent; color: var(--text-muted); }
.btn.btn-ghost:hover { background: var(--surface-alt); color: var(--text); box-shadow: none; transform: none; }
.btn.btn-danger { background: var(--danger-500); }
.btn.btn-danger:hover { background: var(--danger-600); }
.btn.btn-success { background: var(--success-500); }
.btn.btn-success:hover { background: var(--success-600); }
.btn .ico { width: 16px; height: 16px; }
.btn.btn-sm .ico { width: 14px; height: 14px; }

/* ---------- 表格 ---------- */
.table-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: auto;
  box-shadow: var(--shadow-xs);
}
table { width: 100%; border-collapse: collapse; font-size: var(--fs-md); }
thead th {
  background: var(--surface-alt);
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .5px;
  position: sticky; top: 0; z-index: 1;
}
tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  height: 48px;
  color: var(--text);
}
tbody tr { transition: background var(--dur-fast) var(--ease); }
tbody tr:hover { background: var(--surface-alt); }
tbody tr:nth-child(even) td { background: rgba(241,245,249,.35); }
tbody tr:nth-child(even):hover td { background: var(--surface-alt); }
tbody tr:last-child td { border-bottom: none; }
.table-card .num    { text-align: right; font-variant-numeric: tabular-nums; font-weight: 500; }
.table-card .money  { color: var(--text); font-weight: 600; }
.table-card .actions { text-align: right; white-space: nowrap; }
.table-card .actions .btn { margin-left: 4px; }

/* 分页控件 */
.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  background: var(--surface-alt);
  font-size: var(--fs-sm);
}
.pager-info { color: var(--muted); }
.pager-controls { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.pager-num { min-width: 32px; padding: 4px 8px; }
.pager-num.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.pager-dots { padding: 0 4px; color: var(--muted); }
.pager-size { color: var(--muted); display: inline-flex; align-items: center; gap: 4px; }
.pager-size select {
  padding: 3px 6px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); font-size: var(--fs-sm);
}
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }

.empty {
  text-align: center; padding: 60px 24px;
  color: var(--text-muted); font-size: 14px;
}
.empty .ico { color: var(--gray-300); margin-bottom: 12px; }

/* ---------- Status Tag ---------- */
.tag {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-size: var(--fs-xs);
  font-weight: 500;
  line-height: 1.4;
  white-space: nowrap;
}
.tag-dot::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor;
}
.tag-success  { background: var(--success-50); color: var(--success-700); }
.tag-warning  { background: var(--warning-50); color: var(--warning-700); }
.tag-danger   { background: var(--danger-50);  color: var(--danger-700); }
.tag-info     { background: var(--brand-50);   color: var(--brand-700); }
.tag-gray     { background: var(--gray-100);   color: var(--gray-700); }

/* ---------- 提示条（gen-banner） ---------- */
.gen-banner {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  background: var(--brand-50);
  border: 1px solid var(--brand-100);
  color: var(--brand-700);
  border-radius: var(--radius-md);
  font-size: 12px;
  margin-bottom: 14px;
}
.gen-banner .ico { color: var(--brand-500); }

/* ---------- Modal（dialog，可拖拽） ---------- */
.modal-mask {
  position: fixed; inset: 0;
  background: rgba(15,23,42,.45);
  display: flex; align-items: flex-start; justify-content: center;
  padding-top: 12vh;
  z-index: 200;
  animation: fadeIn var(--dur-base) var(--ease);
}
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 80px);
  overflow: auto;
  animation: slideUp var(--dur-slow) var(--ease);
  transition: box-shadow var(--dur-base) var(--ease);
}
.modal-head {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  cursor: move;
  user-select: none;
  background: var(--surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

/* ============ 考勤统计表三栏布局 ============ */
.att-report-wrap {
  display: grid;
  grid-template-columns: 180px 200px 1fr;
  gap: 12px;
  height: calc(100vh - 180px);
  min-height: 520px;
}
.att-col {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.att-col-head {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2, #f8fafc);
}
.att-col-head label { font-size: 12px; color: var(--text-muted); display: flex; align-items: center; gap: 6px; }
.att-col-head input[type="month"] { padding: 4px 8px; border: 1px solid var(--border); border-radius: 6px; font-size: 12px; }

/* 左侧部门列表 */
.att-dept-list, .att-emp-list {
  overflow-y: auto;
  flex: 1;
  padding: 6px;
}
.att-dept-item, .att-emp-item {
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  transition: background var(--dur-base) var(--ease);
  margin-bottom: 2px;
}
.att-dept-item:hover, .att-emp-item:hover { background: var(--hover, #f1f5f9); }
.att-dept-item.active, .att-emp-item.active {
  background: var(--brand-50, #eff6ff);
  color: var(--brand-700, #1d4ed8);
  font-weight: 600;
}
.att-emp-item { display: flex; flex-direction: column; gap: 2px; }
.att-emp-name { font-size: 13px; font-weight: 500; }
.att-emp-sub { font-size: 11px; color: var(--text-muted); }

/* 右侧详情 */
.att-detail {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
}
.att-emp-card {
  background: var(--surface-2, #f8fafc);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px 14px;
  margin-bottom: 8px;
}
.att-emp-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  flex-wrap: wrap;
}
.att-emp-sub {
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-muted);
}

/* 统计卡片网格 */
.att-stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}
.att-stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px;
  text-align: center;
}
.att-stat-val {
  font-size: 18px;
  font-weight: 700;
  line-height: 1.1;
}
.att-stat-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* 图例 */
.att-legend-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 11px;
  color: var(--text-muted);
}
.att-legend { display: inline-flex; align-items: center; gap: 4px; }
.att-legend i {
  display: inline-block;
  width: 12px; height: 12px;
  border-radius: 3px;
}

/* 月历 */
.att-calendar {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.att-cal-weekdays, .att-cal-week {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
}
.att-cal-weekdays {
  background: var(--surface-2, #f8fafc);
  border-bottom: 1px solid var(--border);
}
.att-cal-weekdays > div {
  padding: 4px 0;
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
}
.att-cal-week { border-bottom: 1px solid var(--border); }
.att-cal-week:last-child { border-bottom: none; }
.att-cal-cell {
  height: 42px;
  padding: 2px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-right: 1px solid var(--border);
  font-size: 10px;
  cursor: default;
  transition: transform var(--dur-base) var(--ease);
  box-sizing: border-box;
}
.att-cal-cell:last-child { border-right: none; }
.att-cal-cell:hover { transform: scale(1.04); z-index: 1; position: relative; box-shadow: 0 2px 8px rgba(0,0,0,0.10); }
.att-cal-cell.empty { background: var(--surface); border-right-color: transparent; }
.att-cal-day { font-size: 11px; font-weight: 600; line-height: 1; }
.att-cal-st { font-size: 9px; margin-top: 1px; opacity: 0.9; }
.att-cal-footer {
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-muted);
  text-align: right;
}

/* 暗色主题适配 */
[data-theme="dark"] .att-cal-cell.empty { background: transparent; }
[data-theme="dark"] .att-col-head { background: var(--surface-2, #1e293b); }
[data-theme="dark"] .att-emp-card { background: var(--surface-2, #1e293b); }

@media (max-width: 1100px) {
  .att-report-wrap { grid-template-columns: 140px 170px 1fr; }
  .att-stat-grid { grid-template-columns: repeat(4, 1fr); }
}

.modal-head:active { cursor: grabbing; }
.modal-head h3 { font-size: 16px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.modal-head h3 .drag-hint { color: var(--text-muted); opacity: .5; }
.modal-head .modal-close { cursor: pointer; }
.modal-body { padding: 20px; }
.modal-foot {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 8px;
}
.modal.dragging { box-shadow: 0 24px 48px -12px rgba(15,23,42,.25); transition: none; }
.modal-head:hover .drag-hint { opacity: .9; }
.form-row { display: grid; gap: 6px; margin-bottom: 14px; }
.form-row label { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.form-row .req::after { content: " *"; color: var(--danger-500); }
.form-row .input, .form-row .select, .form-row .textarea,
.form-row input, .form-row select, .form-row textarea { width: 100%; }

@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
@keyframes slideUp { from { opacity: 0; transform: translateY(8px) } to { opacity: 1; transform: translateY(0) } }

/* ---------- 滚动条 ---------- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: var(--radius-pill); }
::-webkit-scrollbar-thumb:hover { background: var(--gray-400); }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- 响应式 ----------
   断点策略：
   ≥1025px   桌面：完整侧栏 232px，可手动收起为 64px（localStorage 记忆）
   641–1024px 平板：JS 自动收起为 64px 图标栏；宽表横向滚动，不挤压列
   ≤640px    手机：抽屉式侧栏（汉堡按钮 + 遮罩），表单单列，卡片自适应
   JS 见 index.html：initSidebarFolding / applySidebarMode（跨断点同步） */

/* 平板 + 手机：表格超宽时横向滚动而非压缩列 */
@media (max-width: 1024px) {
  .content { padding: 16px 18px 28px; }
  .table-card { -webkit-overflow-scrolling: touch; }
  .table-card table,
  .summary-table { min-width: max-content; }
  .summary-card { overflow-x: auto; }
}

@media (max-width: 640px) {
  /* ---- 抽屉式侧栏 ---- */
  .sidebar {
    width: 232px;
    transform: translateX(-105%);
    box-shadow: none;
    transition: transform var(--dur-slow) var(--ease), width var(--dur-base) var(--ease);
  }
  body.sidebar-open .sidebar { transform: translateX(0); box-shadow: var(--shadow-lg); }
  body.sidebar-open .sidebar-mask { opacity: 1; pointer-events: auto; }
  /* 兜底：JS 在手机下会移除收起态，此处确保抽屉宽度不被 64px 干扰 */
  body.sidebar-collapsed .sidebar { width: 232px; }
  .main { margin-left: 0 !important; }

  /* ---- 顶栏 ---- */
  .menu-btn { display: inline-flex; }
  .header { padding: 8px 12px; }
  .header .page-info .sub { display: none; }
  .header .page-info h2 { font-size: 15px; }
  .user-info { display: none; }
  .user-trigger { gap: 6px; padding: 2px 6px; }
  .tabbar { top: 54px; padding: 0 6px; }
  .tab-item { padding: 8px 10px 7px; font-size: 12px; }
  .tab-item .tab-title { max-width: 100px; }

  .content { padding: 12px; }

  /* ---- 工具栏：搜索框独占一行，其余自然换行 ---- */
  .toolbar { padding: 10px; gap: 8px; }
  .toolbar .search-input { flex: 1 1 100%; width: auto; max-width: none; }
  .toolbar .spacer { display: none; }
  .toolbar input, .toolbar select { min-width: 0; flex: 1 1 auto; }
  .toolbar .btn { flex: 0 0 auto; }

  /* ---- 统计卡 ---- */
  .stat-grid { grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
  .stat-card { padding: 14px 16px; }
  .stat-card .value { font-size: 18px; }

  /* ---- 弹窗 / 表单 ---- */
  .modal-mask { padding-top: 8px; align-items: flex-start; }
  .modal { max-height: calc(100vh - 16px); width: calc(100vw - 32px); }
  .modal-head { padding: 12px 14px; }
  .modal-body { padding: 14px; }
  .modal-foot { padding: 12px 14px; }
  /* 表单单列：.form-grid2/.form-grid3 定义在 index.html 内联样式（后加载），覆盖见该文件 */
  .gen-banner { padding: 8px 10px; font-size: 11px; }

  /* ---- 考勤统计三栏纵排 ---- */
  .att-report-wrap {
    grid-template-columns: 1fr;
    height: auto; min-height: 0;
  }
  .att-col { height: 220px; }
  .att-col-right { height: 62vh; min-height: 320px; }
  .att-detail { padding: 8px; }
  .att-stat-grid { grid-template-columns: repeat(4, 1fr); gap: 6px; }
  .att-cal-cell { height: 44px; }

  /* ---- 汇总 / 图表 / 列表 ---- */
  .bar-label { width: 58px; font-size: 11px; }
  .bar-val { width: 76px; font-size: 11px; }
  .bar-wrap { gap: 8px; }
  .kv .k { width: 92px; }
  .kv { font-size: 12px; }
  .pager { padding: 8px 10px; }
}

/* 窄屏（<400px）进一步收紧 */
@media (max-width: 400px) {
  .stat-grid { grid-template-columns: 1fr; }
  .att-stat-grid { grid-template-columns: repeat(2, 1fr); }
  .header .page-info h2 { font-size: 14px; }
  .user-avatar { width: 32px; height: 32px; font-size: 12px; }
}
