:root {
  --bg: #f1fafa;             /* 浅青白背景（对齐 bb.zstskq.com） */
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-2: #64748b;
  --text-3: #94a3b8;
  --primary: #24909c;        /* 主色：青绿 teal */
  --primary-strong: #1c707a; /* 主色 hover/深色 */
  --primary-soft: #e6f4f5;   /* 主色浅底 */
  --green: #16a34a;   /* 亏损/下降（跌绿） */
  --red: #dc2626;     /* 盈利/增长（涨红） */
  --amber: #d97706;
  --teal: #0d9488;
  --purple: #7c3aed;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .04);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px;
}

.app { display: flex; height: 100vh; overflow: hidden; }

/* ===== 侧边栏（深色，对齐 bb.zstskq.com 布局） ===== */
.sidebar {
  width: 216px; min-width: 216px; background: #0f172a;
  border-right: none; display: flex; flex-direction: column;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 16px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand-logo {
  width: 38px; height: 38px; border-radius: 10px; background: linear-gradient(135deg, #24909c, #1c707a);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 700;
}
.brand-title { font-size: 16px; font-weight: 700; color: #f1f5f9; }
.brand-sub { font-size: 11px; color: #64748b; margin-top: 1px; }

.nav { flex: 1; padding: 10px 10px; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 9px;
  cursor: pointer; color: #94a3b8; font-weight: 500; transition: all .15s; margin-bottom: 2px;
}
.nav-item .ico { font-size: 16px; }
.nav-item:hover { background: rgba(255,255,255,.06); color: #e2e8f0; }
.nav-item.active { background: var(--primary); color: #fff; font-weight: 600; }

.sidebar-foot { padding: 12px 16px; border-top: 1px solid rgba(255,255,255,.08); display: flex; align-items: center; gap: 8px; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: #475569; flex-shrink: 0; }
.status-dot.ok { background: #22c55e; }
.status-dot.warn { background: #f59e0b; }
.status-text { font-size: 12px; color: #94a3b8; }

/* ===== 顶栏 ===== */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 56px; background: var(--card); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; padding: 0 20px;
}
.topbar-title { font-size: 17px; font-weight: 700; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.update-info { font-size: 12px; color: var(--text-3); }
.update-info b { color: var(--text-2); font-weight: 600; }

.btn {
  border: 1px solid var(--border); background: var(--card); color: var(--text);
  padding: 7px 13px; border-radius: 8px; cursor: pointer; font-size: 13px; font-weight: 500; transition: all .15s;
}
.btn:hover { background: #f3f5f9; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-strong); }
.btn-ghost:hover { border-color: #d0d5dd; }

/* ===== 内容 ===== */
.content { flex: 1; overflow-y: auto; padding: 20px; }
.hidden { display: none !important; }

/* 按住鼠标拖拽滚动（替代滚轮，全局生效） */
body.is-drag { cursor: grabbing; }
body.is-drag .content { cursor: grabbing; user-select: none; -webkit-user-select: none; }


/* KPI 卡片（紧凑 + 彩色顶边条，对齐参考布局） */
.kpi-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; margin-bottom: 14px; }
@media (max-width: 1100px) { .kpi-grid { grid-template-columns: repeat(3, 1fr); } }
.kpi {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  border-top: 3px solid var(--primary);
  padding: 12px 14px; box-shadow: var(--shadow);
}
.kpi.c-amber  { border-top-color: #f59e0b; }
.kpi.c-purple { border-top-color: #7c3aed; }
.kpi.c-green  { border-top-color: #16a34a; }
.kpi.c-red    { border-top-color: #dc2626; }
.kpi.c-blue   { border-top-color: #378add; }
.kpi-label { font-size: 12px; color: var(--text-2); margin-bottom: 6px; }
.kpi-value { font-size: 20px; font-weight: 700; letter-spacing: -.3px; }
.kpi-sub { font-size: 11px; color: var(--text-3); margin-top: 5px; line-height: 1.5; }
.kpi.up .kpi-value { color: var(--red); }
.kpi.down .kpi-value { color: var(--green); }

/* 卡片容器（紧凑） */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); margin-bottom: 14px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.card-title { font-size: 14px; font-weight: 700; display: inline; }
.card-sub { font-size: 12px; color: var(--text-3); margin-top: 2px; line-height: 1.5; }
/* 标题旁注释：与标题同一水平线，用括号包裹 */
.card-title + .card-sub { display: inline; margin-top: 0; margin-left: 2px; }
.card-title + .card-sub:not(:empty)::before { content: "（"; }
.card-title + .card-sub:not(:empty)::after { content: "）"; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
@media (max-width: 900px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* 图表 */
.chart { width: 100%; }
.chart svg { width: 100%; height: auto; display: block; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 12px; }
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-2); }
.legend-dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }

/* 分类结构列表（替代圆环：色块文字 + 金额 + 占比 + 横向占比条） */
.bd-list { display: flex; flex-direction: column; gap: 10px; }
.bd-top { display: flex; align-items: center; gap: 10px; }
.bd-label { flex: 1; display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text); min-width: 0; white-space: nowrap; }
.bd-label i { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.bd-amt { font-weight: 600; font-size: 13px; white-space: nowrap; }
.bd-pct { width: 54px; text-align: right; font-weight: 700; font-size: 13px; color: var(--text); white-space: nowrap; }
.bd-bar { height: 6px; background: #eef1f6; border-radius: 3px; overflow: hidden; margin-top: 4px; }
.bd-bar span { display: block; height: 100%; border-radius: 3px; }

/* 表格（深 teal 表头，横竖实线网格，内容居中，表头滚动固定）
   ⚠️ sticky 表头只有在「滚动容器」内才能正确吸顶。若容器 overflow:visible（页面级滚动），
   th 吸顶受 table 包含块约束，随滚动会在表头与内容之间露出随滚动增大的空隙。
   故 .table-wrap--page 也统一改为容器内滚动（与审批单据明细页一致）。 */
.table-wrap { overflow: auto; max-height: 76vh; }
.table-wrap--page { overflow: auto; max-height: 560px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 8px 12px; text-align: center; white-space: nowrap; border: 1px solid var(--border); }
td.wrap { white-space: normal; word-break: break-all; text-align: left; min-width: 110px; max-width: 240px; }
th {
  background: var(--primary); color: #fff; font-weight: 600;
  position: sticky; top: 0; z-index: 3;
  border-color: rgba(255,255,255,.28);
  box-shadow: inset 0 -1px 0 rgba(255,255,255,.35);
}
tbody tr:hover { background: #fafbfd; }
.num-up { color: var(--red); font-weight: 600; }
.num-down { color: var(--green); font-weight: 600; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.tag-loss { background: #ecfdf3; color: var(--green); }
.tag-profit { background: #fef2f2; color: var(--red); }
.tag-gray { background: #f1f5f9; color: var(--text-2); }
.tag-warn { background: #fff7ed; color: var(--amber); }

/* 子表轻量编辑表格（替换 Luckysheet，双击改数值） */
.ledger-edit-table td[data-row] { cursor: cell; min-width: 80px; }
.ledger-edit-table td[data-row]:hover { background: #eef7f7; outline: 1px solid var(--primary); outline-offset: -1px; }
.ledger-edit-table td.row-op { width: 36px; min-width: 36px; background: #fafafa; }

/* 筛选栏 */
.filter-bar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; align-items: center; }
.filter-bar select, .filter-bar input {
  padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; background: #fff; color: var(--text);
}
.filter-bar label { font-size: 13px; color: var(--text-2); }

/* 快捷筛选按钮组（今日/近7天/本月…，对齐参考布局） */
.chip-group { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.chip {
  padding: 5px 13px; border-radius: 999px; font-size: 12px; cursor: pointer; transition: all .15s;
  border: 1px solid var(--border); background: #fff; color: var(--text-2); font-weight: 500;
}
.chip:hover { border-color: var(--primary); color: var(--primary); }
.chip.active { background: var(--primary-soft); color: var(--primary); border-color: var(--primary); font-weight: 600; }

/* 排名徽章 + 可排序表头 + 低于均值标红 */
.rank-badge {
  display: inline-flex; width: 22px; height: 22px; border-radius: 50%; flex-shrink: 0;
  background: var(--primary); color: #fff; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600;
}
th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { background: var(--primary-strong); }
.below-avg { color: #dc2626; }

/* Tab */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tab {
  padding: 9px 16px; cursor: pointer; font-size: 13px; color: var(--text-2); font-weight: 500;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

/* 表单 */
.form-row { display: flex; gap: 14px; margin-bottom: 14px; flex-wrap: wrap; }
.form-row label { display: block; font-size: 12px; color: var(--text-2); margin-bottom: 5px; }
.form-row input, .form-row select, .form-row textarea {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; width: 100%; min-width: 180px;
}
.form-row .field { flex: 1; min-width: 180px; }
.form-row textarea { min-height: 70px; resize: vertical; }

/* 提示条 */
.alert { padding: 12px 15px; border-radius: 9px; font-size: 13px; margin-bottom: 14px; line-height: 1.6; }
.alert-info { background: var(--primary-soft); color: #0f766e; }
.alert-warn { background: #fffbeb; color: #92400e; }
.alert-ok { background: #ecfdf5; color: #065f46; }

/* 导出进度小转圈（export 弹窗进度提示用） */
.spin {
  display: inline-block; width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid rgba(36,144,156,.25); border-top-color: #24909c;
  animation: spin .8s linear infinite; vertical-align: -2px; margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* 弹窗 */
.modal-mask {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 100;
  display: flex; align-items: center; justify-content: center;
}
.modal {
  background: #fff; border-radius: 14px; padding: 22px; width: 520px; max-width: 92vw;
  max-height: 86vh; overflow-y: auto; box-shadow: 0 20px 40px rgba(0,0,0,.2);
}
.modal-title { font-size: 16px; font-weight: 700; margin-bottom: 16px; }

/* 步骤/文档 */
.doc-step { display: flex; gap: 12px; margin-bottom: 14px; }
.doc-step .n {
  width: 22px; height: 22px; border-radius: 50%; background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; flex-shrink: 0;
}
.doc-step .b { font-size: 13px; line-height: 1.6; color: var(--text); }
.doc-step code {
  background: #f1f5f9; padding: 1px 6px; border-radius: 5px; font-size: 12px; color: #be185d;
}

/* ===== 登录界面 ===== */
.login-wrap {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #e6f4f5 0%, #f1fafa 40%, #e2f0f1 100%);
}
.login-card {
  width: 380px; max-width: 92vw; background: #fff; border-radius: 16px;
  padding: 40px 36px 32px; text-align: center; box-shadow: 0 20px 50px rgba(15, 23, 42, .12);
}
.login-logo {
  width: 56px; height: 56px; margin: 0 auto 16px; border-radius: 14px;
  background: linear-gradient(135deg, #24909c, #1c707a); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 28px; font-weight: 700;
}
.login-card h1 { font-size: 20px; color: #1e293b; font-weight: 700; }
.login-sub { font-size: 13px; color: #64748b; margin: 8px 0 24px; }
.login-field { margin-bottom: 14px; }
.login-field input {
  width: 100%; padding: 12px 14px; border: 1px solid #e2e8f0; border-radius: 10px;
  font-size: 15px; color: #1e293b; outline: none; transition: border-color .15s;
}
.login-field input:focus { border-color: #24909c; box-shadow: 0 0 0 3px #e6f4f5; }
.login-btn {
  width: 100%; padding: 12px; border: none; border-radius: 10px; margin-top: 4px;
  background: #24909c; color: #fff; font-size: 16px; font-weight: 600; cursor: pointer;
}
.login-btn:hover { background: #1c707a; }
.login-err { margin-top: 12px; font-size: 13px; color: #dc2626; min-height: 18px; }

/* 用户信息 chip */
.user-chip { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; color: #334155; padding: 5px 10px; background: #e6f4f5; border-radius: 999px; }
.user-chip b { color: #1c707a; }

/* ===== 移动端响应式 ===== */
@media (max-width: 900px) {
  .app { flex-direction: column; height: auto; min-height: 100vh; overflow: auto; }
  .sidebar { width: 100%; min-width: 0; flex-direction: row; align-items: center; border-right: none; border-bottom: 1px solid var(--border); }
  .brand { border-bottom: none; padding: 10px 12px; flex-shrink: 0; }
  .brand-sub { display: none; }
  .nav { display: flex; flex-direction: row; overflow-x: auto; padding: 6px 4px; gap: 2px; }
  .nav-item { white-space: nowrap; padding: 8px 12px; }
  .nav-item .ico { display: none; }
  .sidebar-foot { display: none; }
  .main { min-width: 0; }
  .topbar { height: auto; min-height: 56px; flex-wrap: wrap; gap: 8px; padding: 12px 14px; }
  .topbar-right { flex-wrap: wrap; }
  .update-info { display: none; }   /* 移动端隐藏次要的数据版本信息，减少顶栏拥挤 */
  .content { padding: 14px; }
}
@media (max-width: 600px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .table-wrap { overflow-x: auto; }
  .brand-title { font-size: 14px; }
  .topbar-title { font-size: 15px; }

  /* ===== 移动端触控与布局优化 ===== */
  .btn { padding: 9px 14px; font-size: 14px; }                 /* 加大触控目标 */
  .chip { padding: 7px 14px; font-size: 13px; }
  .nav-item { padding: 10px 14px; }
  .form-row { flex-direction: column; gap: 10px; }              /* 表单字段竖排，避免横向溢出 */
  .form-row .field, .form-row input, .form-row select, .form-row textarea { min-width: 0; width: 100%; }
  .filter-bar select, .filter-bar input { max-width: 100%; font-size: 16px; }  /* 16px 防 iOS 聚焦自动放大 */
  .login-field input { font-size: 16px; }                        /* 同上，登录框防 iOS 缩放 */
  .modal { padding: 16px; }
  .kpi-value { font-size: 18px; }
  .topbar-right .btn { padding: 7px 10px; }
  .kpi-sub { font-size: 10px; }
  /* 滚动容器加 iOS 惯性滚动，提升长列表/宽表格滑动体验 */
  .content, .nav, .table-wrap { -webkit-overflow-scrolling: touch; }
}
