/* ==========================================================================
   ProjectTracker 设计系统
   克制中性底 + 白卡 + 单一主色 · 8px 栅格 · 语义色胶囊 · 细边框柔和阴影
   目标：专业、有审美，不做成后台管理模板样，不用 emoji 装饰
   ========================================================================== */

:root {
  /* 中性色阶 */
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #fbfcfd;
  --border: #e7e9ec;
  --border-strong: #d9dce1;
  --text: #1b1f24;
  --text-2: #5a636e;
  --text-3: #8b939d;

  /* 单一主色（沉稳的墨蓝，专业不刺眼） */
  --primary: #3559a8;
  --primary-hover: #2c4a8c;
  --primary-soft: #eef2fb;
  --primary-line: #d3ddf2;

  /* 语义色 —— 进度框状态 */
  --todo-bg: #f1f3f5;   --todo-fg: #6b7280;   --todo-dot: #c3c9d0;
  --doing-bg: #eaf1fd;  --doing-fg: #2d6cdf;  --doing-dot: #3b82f6;
  --done-bg: #e8f5ee;   --done-fg: #1f8a54;   --done-dot: #22a06b;
  --blocked-bg: #fdecec;--blocked-fg: #c0392b;--blocked-dot: #e05252;

  /* 语义色 —— 项目状态 */
  --st-active: #2d6cdf;  --st-active-bg: #eaf1fd;
  --st-serving:#1f8a54;  --st-serving-bg:#e8f5ee;
  --st-expired:#c2703a;  --st-expired-bg:#fdf1e6;
  --st-done:   #8b939d;  --st-done-bg:   #f1f3f5;
  --st-paused: #7a6ba8;  --st-paused-bg: #f0edf8;

  /* 警示 */
  --danger: #c0392b; --danger-bg: #fdecec; --danger-line: #f3c9c4;
  --warn: #c2703a;

  /* 8px 栅格间距体系 */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px;
  --s5: 24px; --s6: 32px; --s7: 48px;

  /* 圆角与阴影（细边框 + 柔和阴影建立层次，不用重描边） */
  --r-sm: 6px; --r: 10px; --r-lg: 14px; --r-pill: 999px;
  --sh-1: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
  --sh-2: 0 4px 12px rgba(16, 24, 40, .07), 0 1px 3px rgba(16, 24, 40, .05);
  --sh-3: 0 12px 32px rgba(16, 24, 40, .14), 0 2px 8px rgba(16, 24, 40, .08);

  --sidebar-w: 232px;
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei",
          "Segoe UI", Roboto, sans-serif;
}

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

html, body { height: 100%; }

body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

::selection { background: var(--primary-soft); }

/* 细滚动条 */
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: #d3d7dd; border-radius: 8px; border: 3px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: #bfc4cc; background-clip: content-box; }
*::-webkit-scrollbar-track { background: transparent; }

/* ==========================================================================
   布局：左侧边栏 + 主区域
   ========================================================================== */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  padding: var(--s5) var(--s4) var(--s4);
  border-bottom: 1px solid var(--border);
}
.brand-name {
  font-size: 15px; font-weight: 650; letter-spacing: .2px; color: var(--text);
  display: flex; align-items: center; gap: var(--s2);
}
.brand-mark {
  width: 22px; height: 22px; border-radius: 6px;
  background: linear-gradient(135deg, var(--primary), #5b7fc7);
  display: inline-block; flex: 0 0 auto;
}
.brand-sub { font-size: 12px; color: var(--text-3); margin-top: 3px; }

.nav { padding: var(--s3) var(--s2); flex: 1; }
.nav-group { margin-bottom: var(--s2); }
.nav-label {
  font-size: 11px; color: var(--text-3); text-transform: none;
  letter-spacing: .4px; padding: var(--s2) var(--s3) var(--s1); font-weight: 600;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px var(--s3); border-radius: var(--r-sm);
  color: var(--text-2); cursor: pointer; font-size: 13.5px; font-weight: 500;
  transition: background .12s, color .12s; user-select: none;
  border: 1px solid transparent;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active {
  background: var(--primary-soft); color: var(--primary-hover);
  border-color: var(--primary-line); font-weight: 600;
}
.nav-dot {
  width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto;
  background: var(--text-3);
}
.nav-count {
  margin-left: auto; font-size: 11.5px; color: var(--text-3);
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--r-pill); padding: 0 7px; line-height: 17px; min-width: 20px; text-align: center;
}
.nav-item.active .nav-count { background: #fff; color: var(--primary); border-color: var(--primary-line); }
.nav-sep { height: 1px; background: var(--border); margin: var(--s3) var(--s3); }

.sidebar-foot { padding: var(--s3) var(--s4); border-top: 1px solid var(--border); font-size: 11.5px; color: var(--text-3); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: 60px; flex: 0 0 60px;
  background: rgba(255,255,255,.86); backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: var(--s4);
  padding: 0 var(--s6); position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 17px; font-weight: 640; letter-spacing: .2px; }
.topbar .spacer { flex: 1; }

.content { padding: var(--s6); max-width: 1320px; width: 100%; margin: 0 auto; }
.content-wide { max-width: none; }

/* ==========================================================================
   按钮
   ========================================================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: var(--r-sm);
  border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text); font-size: 13px; font-weight: 550; font-family: inherit;
  cursor: pointer; transition: all .12s; white-space: nowrap; line-height: 1;
}
.btn:hover { background: var(--surface-2); border-color: #c9ced6; }
.btn:active { transform: translateY(.5px); }
.btn:disabled { opacity: .5; 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-danger { color: var(--danger); border-color: var(--danger-line); background: #fff; }
.btn-danger:hover { background: var(--danger-bg); border-color: #e6b3ac; }

.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-sm { height: 28px; padding: 0 10px; font-size: 12.5px; border-radius: var(--r-sm); }
.btn-icon { width: 34px; padding: 0; }
.btn-icon.btn-sm { width: 28px; }

/* ==========================================================================
   卡片
   ========================================================================== */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); box-shadow: var(--sh-1);
}
.card-pad { padding: var(--s5); }
.card-head {
  padding: var(--s4) var(--s5); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: var(--s3);
}
.card-title { font-size: 14.5px; font-weight: 620; }
.card-sub { font-size: 12.5px; color: var(--text-3); margin-top: 2px; }

.grid { display: grid; gap: var(--s4); }

/* ==========================================================================
   语义色胶囊（状态）
   ========================================================================== */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  height: 22px; padding: 0 9px; border-radius: var(--r-pill);
  font-size: 12px; font-weight: 600; line-height: 1; white-space: nowrap;
  border: 1px solid transparent;
}
.pill .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .9; }

/* 进度框状态 */
.pill-todo    { background: var(--todo-bg);    color: var(--todo-fg); }
.pill-doing   { background: var(--doing-bg);   color: var(--doing-fg); }
.pill-done    { background: var(--done-bg);    color: var(--done-fg); }
.pill-blocked { background: var(--blocked-bg); color: var(--blocked-fg); }

/* 项目状态 */
.pill-active  { background: var(--st-active-bg);  color: var(--st-active); }
.pill-serving { background: var(--st-serving-bg); color: var(--st-serving); }
.pill-expired { background: var(--st-expired-bg); color: var(--st-expired); }
.pill-done-st { background: var(--st-done-bg);    color: var(--st-done); }
.pill-paused  { background: var(--st-paused-bg);  color: var(--st-paused); }

.tag {
  display: inline-flex; align-items: center; height: 20px; padding: 0 8px;
  border-radius: var(--r-sm); font-size: 11.5px; font-weight: 550;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-2);
}

/* ==========================================================================
   提示条（逾期一行提示，可点击展开）
   ========================================================================== */
.notice {
  display: flex; align-items: center; gap: 10px;
  padding: 10px var(--s4); border-radius: var(--r);
  font-size: 13px; margin-bottom: var(--s4);
  border: 1px solid var(--danger-line); background: var(--danger-bg); color: #8f2b20;
}
.notice.warn { border-color: #f0d9bf; background: var(--st-expired-bg); color: #8a5324; }
.notice.info { border-color: var(--primary-line); background: var(--primary-soft); color: var(--primary-hover); }
.notice .bar { width: 3px; align-self: stretch; border-radius: 2px; background: currentColor; opacity: .5; }
.notice b { font-weight: 650; }
.notice-link { margin-left: auto; cursor: pointer; font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }
.notice-x { cursor: pointer; opacity: .55; font-size: 13px; line-height: 1; padding: 2px 4px; margin-left: var(--s2); }
.notice-x:hover { opacity: 1; }

/* 「（自建）」小字标记：仅管理员可见 */
.sub-tag { margin-left: 4px; font-size: 11px; color: var(--text-3); font-weight: 400; white-space: nowrap; }

/* 部门项目负责人：列表内可直接点击填写，整列水平+垂直居中、无下划线；填与不填占位一致 */
.owner-cell { display: inline-block; box-sizing: border-box; min-width: 64px; height: 26px; line-height: 18px; font-size: 13px; text-align: center; cursor: pointer; border-radius: var(--r-sm); padding: 4px 6px; }
.owner-cell:hover { color: var(--primary); background: var(--primary-soft); }
.owner-cell.owner-empty { color: var(--text-3); }
.table .col-owner { text-align: center; vertical-align: middle; }

/* ==========================================================================
   工具条（搜索 + 筛选 + 操作）
   ========================================================================== */
.toolbar { display: flex; align-items: center; gap: var(--s3); margin-bottom: var(--s4); flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }

.search {
  position: relative; display: flex; align-items: center;
}
.search input {
  height: 34px; width: 260px; padding: 0 12px 0 32px;
  border: 1px solid var(--border-strong); border-radius: var(--r-sm);
  font-size: 13px; font-family: inherit; background: var(--surface); color: var(--text);
  transition: border-color .12s, box-shadow .12s;
}
.search input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.search .ico { position: absolute; left: 10px; color: var(--text-3); pointer-events: none; }

.select, .input, .textarea {
  height: 34px; padding: 0 10px; border: 1px solid var(--border-strong);
  border-radius: var(--r-sm); font-size: 13px; font-family: inherit;
  background: var(--surface); color: var(--text); transition: border-color .12s, box-shadow .12s;
}
.textarea { height: auto; padding: 8px 10px; line-height: 1.5; resize: vertical; min-height: 68px; }
.select:focus, .input:focus, .textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft);
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.field .hint { font-size: 11.5px; color: var(--text-3); }
.input.full, .select.full, .textarea.full { width: 100%; }

/* ==========================================================================
   项目列表（表格式排版，数据密集但不拥挤）
   ========================================================================== */
.table { width: 100%; border-collapse: separate; border-spacing: 0; }
.table th, .table td { text-align: left; padding: 12px var(--s4); border-bottom: 1px solid var(--border); }
.table th {
  font-size: 11.5px; font-weight: 650; color: var(--text-3); letter-spacing: .3px;
  background: var(--surface-2); position: sticky; top: 60px; z-index: 5;
  border-bottom: 1px solid var(--border-strong);
}
.table tbody tr { transition: background .1s; cursor: pointer; }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: none; }
.table .col-name { font-weight: 600; color: var(--text); }
.table .col-client { color: var(--text-2); }
.table .col-note {
  color: var(--text-2); max-width: 320px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; font-size: 13px;
}
.table .col-date { color: var(--text-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .col-actions { text-align: right; white-space: nowrap; }
.table .row-overdue .col-name { color: var(--danger); }
.rowflag { display: inline-block; width: 3px; height: 15px; border-radius: 2px; margin-right: 8px; vertical-align: -2px; }

.muted { color: var(--text-3); }
.num { font-variant-numeric: tabular-nums; }
.overdue-txt { color: var(--danger); font-weight: 600; }

/* 全部项目按模板分类的分组抬头 */
.group-head {
  display: flex; align-items: center; gap: 10px;
  margin: var(--s5) 0 var(--s2);
}
.group-head:first-child { margin-top: 0; }
.gh-bar { width: 3px; height: 16px; border-radius: 2px; background: var(--primary); flex: 0 0 auto; }
.gh-name { font-size: 14px; font-weight: 650; color: var(--text); letter-spacing: .2px; }
.gh-count { font-size: 12px; color: var(--text-3); font-variant-numeric: tabular-nums; }

/* 部门进度点 ●●●○○ */
.dots { display: inline-flex; gap: 3px; align-items: center; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--border-strong); display: inline-block; }
.dots i.on { background: var(--dept-color, var(--primary)); }
.dots i.doing { background: var(--doing-dot); }
.dots i.blocked { background: var(--blocked-dot); }
.progress-txt { font-size: 12.5px; color: var(--text-2); font-variant-numeric: tabular-nums; margin-right: 8px; }

/* ==========================================================================
   项目详情：头部 + 六部门卡片网格
   ========================================================================== */
.detail-head {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--sh-1);
  padding: var(--s5) var(--s6); margin-bottom: var(--s5);
}
.detail-title-row { display: flex; align-items: flex-start; gap: var(--s4); }
.detail-title { font-size: 21px; font-weight: 680; letter-spacing: .2px; display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.title-edit {
  font-family: inherit; font-size: 12px; font-weight: 500; color: var(--text-3);
  background: transparent; border: 1px solid var(--border); border-radius: 999px;
  padding: 3px 10px; cursor: pointer; transition: all .12s; line-height: 1.4;
}
.title-edit:hover { color: var(--primary); border-color: var(--primary-line); background: var(--primary-soft); }
.head-actions { flex-wrap: wrap; }
.detail-client { color: var(--text-2); font-size: 14px; font-weight: 500; }
.detail-note {
  color: var(--text-2); font-size: 13.5px; margin-top: 10px;
  padding: 10px var(--s4); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--r-sm);
  display: flex; align-items: flex-start; gap: var(--s3);
}
.detail-note .txt { flex: 1; white-space: pre-wrap; word-break: break-word; }
.detail-meta {
  display: flex; flex-wrap: wrap; gap: var(--s2) var(--s5); margin-top: var(--s4);
  padding-top: var(--s4); border-top: 1px dashed var(--border);
}
.meta-item { display: flex; flex-direction: column; gap: 2px; }
.meta-k { font-size: 11.5px; color: var(--text-3); }
.meta-v { font-size: 13.5px; font-weight: 550; color: var(--text); font-variant-numeric: tabular-nums; }
.meta-v a { font-weight: 550; }

.dept-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s4);
}
@media (max-width: 1180px) { .dept-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 720px)  { .dept-grid { grid-template-columns: 1fr; } }

.dept-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); box-shadow: var(--sh-1); overflow: hidden;
  display: flex; flex-direction: column;
  border-top: 3px solid var(--dept-color, var(--primary));
}
.dept-card-head {
  padding: var(--s3) var(--s4); display: flex; align-items: center; gap: var(--s2);
  border-bottom: 1px solid var(--border); background: var(--surface-2);
}
.dept-card-name { font-size: 13.5px; font-weight: 640; color: var(--text); }
.dept-card-count { margin-left: auto; font-size: 12px; color: var(--text-3); font-variant-numeric: tabular-nums; }

/* 部门视角进入：非本部门只读（能看进度，不能勾） */
.dept-card-lock {
  font-size: 11px; color: var(--text-3); border: 1px solid var(--border);
  border-radius: 999px; padding: 1px 7px; flex: 0 0 auto;
}
.dept-locked { background: var(--surface-2); }
.dept-locked .dept-card-head { background: #f4f6f8; }
.dept-locked .stage { opacity: .78; }
.dept-locked .stage-name { color: var(--text-2); }
.stage-check.locked { cursor: not-allowed; background: #eef0f3; border-color: #dfe3e8; }
.stage.s-done .stage-check.locked { background: #b9c6cf; border-color: #b9c6cf; }
.stage-check.locked:hover { border-color: #dfe3e8; }

.stage-list { padding: var(--s2); display: flex; flex-direction: column; gap: 2px; }
.stage {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--r-sm);
  border: 1px solid transparent; transition: background .1s, border-color .1s;
}
.stage:hover { background: var(--surface-2); border-color: var(--border); }
.stage-check {
  width: 18px; height: 18px; flex: 0 0 auto; border-radius: 5px;
  border: 1.5px solid var(--border-strong); background: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: all .12s;
  position: relative;
}
.stage-check:hover { border-color: var(--primary); }
.stage.s-done .stage-check { background: var(--done-dot); border-color: var(--done-dot); }
.stage.s-done .stage-check::after {
  content: ""; width: 9px; height: 5px; border-left: 2px solid #fff; border-bottom: 2px solid #fff;
  transform: rotate(-45deg) translate(1px, -1px);
}
.stage.s-doing .stage-check { border-color: var(--doing-dot); box-shadow: inset 0 0 0 3px var(--doing-bg); }
.stage.s-blocked .stage-check { background: var(--blocked-dot); border-color: var(--blocked-dot); }
.stage.s-blocked .stage-check::after { content: "!"; color: #fff; font-size: 12px; font-weight: 700; line-height: 1; }

.stage-main { flex: 1; min-width: 0; }
.stage-name { font-size: 13.5px; font-weight: 550; color: var(--text); }
.stage.s-done .stage-name { color: var(--text-2); }
.stage-sub { font-size: 11.5px; color: var(--text-3); margin-top: 2px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.stage-service { font-size: 11.5px; font-weight: 600; color: var(--st-serving); }
.stage-actions { display: flex; gap: 2px; opacity: 0; transition: opacity .12s; }
.stage:hover .stage-actions { opacity: 1; }

.stage-add {
  margin: var(--s1) var(--s2) var(--s2); padding: 7px 10px; border-radius: var(--r-sm);
  border: 1px dashed var(--border-strong); color: var(--text-3); font-size: 12.5px;
  cursor: pointer; text-align: center; transition: all .12s; background: transparent; width: calc(100% - 16px);
}
.stage-add:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }

/* 网格内的「添加部门」虚线卡片（唤出 0 任务部门） */
.dept-add {
  border: 1px dashed var(--border-strong); border-radius: var(--r); background: transparent;
  color: var(--text-3); cursor: pointer; font-family: inherit; font-size: 13px; font-weight: 550;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 120px; transition: all .12s; padding: var(--s4);
}
.dept-add:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }

.icon-btn {
  width: 26px; height: 26px; border-radius: var(--r-sm); border: 1px solid transparent;
  background: transparent; color: var(--text-3); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; transition: all .1s;
}
.icon-btn:hover { background: var(--surface); border-color: var(--border); color: var(--text); }
.icon-btn.danger:hover { color: var(--danger); border-color: var(--danger-line); background: var(--danger-bg); }

/* ==========================================================================
   沟通时间线
   ========================================================================== */
.tl-input-row { display: flex; gap: var(--s3); align-items: flex-start; margin-bottom: var(--s4); }
.tl-input-row textarea {
  flex: 1; min-height: 44px; padding: 9px 12px; border: 1px solid var(--border-strong);
  border-radius: var(--r-sm); font-size: 13px; font-family: inherit; line-height: 1.5;
  resize: vertical; color: var(--text); background: var(--surface);
  transition: border-color .12s, box-shadow .12s;
}
.tl-input-row textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

.timeline { display: flex; flex-direction: column; }
.tl-item { display: flex; gap: var(--s3); padding: var(--s3) 0; border-bottom: 1px solid var(--border); }
.tl-item:last-child { border-bottom: none; }
.tl-rail { display: flex; flex-direction: column; align-items: center; flex: 0 0 auto; }
.tl-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--primary); margin-top: 5px; flex: 0 0 auto; }
.tl-line { width: 1px; flex: 1; background: var(--border); margin-top: 4px; }
.tl-body { flex: 1; min-width: 0; }
.tl-date { font-size: 11.5px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.tl-content { font-size: 13.5px; color: var(--text); margin-top: 2px; white-space: pre-wrap; word-break: break-word; }

/* ==========================================================================
   弹窗
   ========================================================================== */
.modal-mask {
  position: fixed; inset: 0; background: rgba(20, 26, 34, .38);
  backdrop-filter: blur(2px); display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: var(--s4); animation: fade .14s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--sh-3);
  width: 100%; max-width: 460px; max-height: 90vh; overflow: hidden;
  display: flex; flex-direction: column; animation: pop .16s cubic-bezier(.2,.8,.3,1);
}
.modal.wide { max-width: 620px; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.985); } to { opacity: 1; transform: none; } }
.modal-head { padding: var(--s5) var(--s5) var(--s3); }
.modal-title { font-size: 16px; font-weight: 650; }
.modal-desc { font-size: 12.5px; color: var(--text-3); margin-top: 4px; }
.modal-body { padding: var(--s3) var(--s5) var(--s5); overflow-y: auto; display: flex; flex-direction: column; gap: var(--s4); }
.modal-foot { padding: var(--s4) var(--s5); border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: var(--s3); background: var(--surface-2); }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s4); }
.form-grid .span2 { grid-column: span 2; }
.input-group { display: flex; gap: var(--s2); }
.input-group .input { flex: 1; }
.computed {
  padding: 10px var(--s4); background: var(--primary-soft); border: 1px solid var(--primary-line);
  border-radius: var(--r-sm); font-size: 13px; color: var(--primary-hover); display: flex; gap: var(--s2); align-items: center;
}
.computed b { font-variant-numeric: tabular-nums; }
.req { color: var(--danger); }

/* ==========================================================================
   空状态 / 加载
   ========================================================================== */
.empty { text-align: center; padding: var(--s7) var(--s4); color: var(--text-3); }
.empty-ico { width: 44px; height: 44px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border); margin: 0 auto var(--s4); display: flex; align-items: center; justify-content: center; color: var(--text-3); }
.empty-title { font-size: 14.5px; font-weight: 600; color: var(--text-2); margin-bottom: 4px; }
.empty-desc { font-size: 13px; }

.skeleton { background: linear-gradient(90deg, #eef0f3 25%, #f6f7f9 37%, #eef0f3 63%); background-size: 400% 100%; animation: shimmer 1.3s ease infinite; border-radius: var(--r-sm); }
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ==========================================================================
   通用工具类
   ========================================================================== */
.row { display: flex; align-items: center; gap: var(--s3); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); }
.col { display: flex; flex-direction: column; }
.wrap { flex-wrap: wrap; }
.gap1 { gap: var(--s1); } .gap2 { gap: var(--s2); } .gap3 { gap: var(--s3); } .gap4 { gap: var(--s4); }
.mt2 { margin-top: var(--s2); } .mt3 { margin-top: var(--s3); } .mt4 { margin-top: var(--s4); } .mt5 { margin-top: var(--s5); }
.mb2 { margin-bottom: var(--s2); } .mb3 { margin-bottom: var(--s3); } .mb4 { margin-bottom: var(--s4); } .mb5 { margin-bottom: var(--s5); }
.ml-auto { margin-left: auto; }
.hidden { display: none !important; }
.center { text-align: center; }
.right { text-align: right; }
.strong { font-weight: 620; }
.fs12 { font-size: 12px; } .fs13 { font-size: 13px; } .fs15 { font-size: 15px; }
.divider { height: 1px; background: var(--border); margin: var(--s4) 0; }
.clickable { cursor: pointer; }

.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 2px; gap: 2px; }
.seg button { border: none; background: transparent; padding: 5px 12px; border-radius: 5px; font-size: 12.5px; font-weight: 550; color: var(--text-2); cursor: pointer; font-family: inherit; transition: all .12s; }
.seg button.active { background: var(--surface); color: var(--primary); box-shadow: var(--sh-1); }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: var(--s3); }
.stat { padding: var(--s4); border: 1px solid var(--border); border-radius: var(--r); background: var(--surface); }
.stat-v { font-size: 24px; font-weight: 680; letter-spacing: -.5px; font-variant-numeric: tabular-nums; }
.stat-k { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.stat.alert .stat-v { color: var(--danger); }
.stat.warn .stat-v { color: var(--warn); }

/* 单选卡片（模板/导入模式选择） */
.choice { border: 1px solid var(--border-strong); border-radius: var(--r-sm); padding: var(--s3) var(--s4); cursor: pointer; transition: all .12s; }
.choice:hover { border-color: var(--primary); }
.choice.selected { border-color: var(--primary); background: var(--primary-soft); box-shadow: 0 0 0 1px var(--primary) inset; }
.choice-t { font-size: 13.5px; font-weight: 600; }
.choice-d { font-size: 12px; color: var(--text-3); margin-top: 2px; }

/* toast */
.toast-wrap { position: fixed; right: var(--s5); bottom: var(--s5); z-index: 200; display: flex; flex-direction: column; gap: var(--s2); }
.toast {
  background: #232a33; color: #fff; padding: 11px var(--s4); border-radius: var(--r-sm);
  box-shadow: var(--sh-3); font-size: 13px; max-width: 360px; animation: slidein .18s ease;
  display: flex; align-items: center; gap: var(--s2);
}
.toast.ok { background: #1f7a4d; } .toast.err { background: #b23b2e; }
@keyframes slidein { from { opacity: 0; transform: translateX(12px); } to { opacity: 1; transform: none; } }

/* 表格横向滚动容器（窄屏时表格可左右滑） */
.table-wrap { overflow-x: auto; }

/* 纵向滚动容器：默认露出约 10 行，其余下滑查看；不折叠、不隐藏任何行 */
.scroll-y { overflow-y: auto; max-height: 486px; }
.scroll-y .table th { position: sticky; top: 0; z-index: 6; }

/* 最近回款流水：只露出 5 行，其余下滑查看 */
.scroll-5 { overflow-y: auto; max-height: 298px; }
.scroll-5 .table th { position: sticky; top: 0; z-index: 6; }

/* 财务部表头：合同 / 运营 / 区域总 固定三字宽，不换行 */
.table th.w3, .table td.w3 { white-space: nowrap; }
.table th.w3 { width: 72px; min-width: 72px; }
/* 项目名：前 8 字一行，超出部分折到第二行 */
.table th.fin-name { width: 152px; }
.table td.fin-name { max-width: 152px; white-space: normal; word-break: break-word; line-height: 1.45; }
/* 财务表：按钮/数字不换行，整表给足宽度，保证每行一行高（10 行=486px 名副其实） */
.fin-table { min-width: 1180px; }
.fin-scroll { max-height: 560px; }   /* 财务表行高约 52px，正好露出 10 行 */
.fin-table td, .fin-table th { white-space: nowrap; }
.fin-table td.fin-name { white-space: normal; }
.fin-table .col-actions { white-space: nowrap; }

/* 弹窗内表格：单元格不换行，项与数字同行对齐 */
.modal .table td, .modal .table th { white-space: nowrap; }
.modal .table { min-width: 520px; }

/* 提成已发放：绿色文字按钮（默认态与核销按钮同色） */
.btn.cm-paid { color: var(--st-serving); border-color: #bfe3cf; background: var(--st-serving-bg); font-weight: 600; }
.btn.cm-paid:hover { background: #dcf0e4; border-color: #a5d8bb; }

/* 待办红点：回款收齐但未登记提成 */
.rdot { width: 7px; height: 7px; border-radius: 50%; background: var(--danger); display: inline-block; margin-left: 5px; vertical-align: 2px; }

/* ==========================================================================
   移动端 / 窄屏自适应
   ========================================================================== */
@media (max-width: 900px) {
  :root { --sidebar-w: 100%; }
  html { -webkit-text-size-adjust: 100%; }
  body { -webkit-tap-highlight-color: transparent; }
  .layout { flex-direction: column; }
  .sidebar {
    width: 100%; flex: 0 0 auto; height: auto; position: static;
    border-right: none; border-bottom: 1px solid var(--border);
  }
  .brand { padding: 12px 14px 6px; border-bottom: none; }
  .sidebar-foot { display: none; }
  .nav { padding: 0 8px 10px; display: flex; flex-direction: column; gap: 6px; }
  .nav-group {
    display: flex; gap: 6px; overflow-x: auto; margin: 0; padding-bottom: 4px;
    -webkit-overflow-scrolling: touch; scrollbar-width: none;
  }
  .nav-group::-webkit-scrollbar { display: none; }
  .nav-label, .nav-sep { display: none; }
  .nav-item { white-space: nowrap; flex: 0 0 auto; padding: 9px 14px; font-size: 13.5px; }
  .nav-count { margin-left: 6px; }

  /* 顶栏吸顶：一行排满即横滑，不堆成两三行 */
  .topbar {
    height: auto; flex: 0 0 auto; flex-wrap: nowrap; overflow-x: auto;
    -webkit-overflow-scrolling: touch; scrollbar-width: none;
    padding: 10px 12px; gap: 8px;
    position: sticky; top: 0; z-index: 40; background: rgba(255,255,255,.95);
    backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
  }
  .topbar::-webkit-scrollbar { display: none; }
  .topbar h1 { font-size: 16px; width: auto; flex: 0 0 auto; order: -1; }
  .topbar .spacer { display: none; }
  .topbar .btn, .topbar .select { min-height: 36px; flex: 0 0 auto; }
  .topbar #userChip { margin-left: auto; flex: 0 0 auto; }

  .content { padding: 12px 12px calc(20px + env(safe-area-inset-bottom)); }
  .toolbar { gap: 8px; }
  .toolbar .select { min-height: 42px; flex: 1 1 auto; }
  .search { flex: 1 1 100%; }
  .search input { width: 100%; min-height: 42px; font-size: 16px; }

  /* 控件加大：16px 字号避免 iOS 聚焦自动放大整页；点击区域 ≥38px */
  .input, .select, .textarea { font-size: 16px; min-height: 42px; }
  .textarea { min-height: 64px; }
  .btn { min-height: 38px; }
  .btn-sm { min-height: 34px; padding: 6px 12px; }
  .icon-btn { width: 34px; height: 34px; }
  .seg button { padding: 8px 14px; }
  .choice { padding: var(--s4); }

  .dept-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span2 { grid-column: span 1; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stat { padding: 12px; }
  .stat-v { font-size: 20px; letter-spacing: -.2px; }
  .stat-k { font-size: 11.5px; }
  .detail-head { padding: 14px; }
  .detail-title { font-size: 18px; }
  .detail-meta { gap: 10px 18px; }

  /* 详情页操作：横滑一排，不折成一堆 */
  .head-actions { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 4px; }
  .head-actions > * { flex: 0 0 auto; }
  .head-actions .muted { font-size: 11.5px; padding-right: 4px; }

  /* 表格：去掉内层双滚动条改为整页下滑；横向仍可滑且首列钉住不迷路 */
  .card { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .scroll-y, .scroll-5 { max-height: none; overflow-y: visible; }
  .table { min-width: 620px; font-size: 13px; }
  .table th { position: static; }
  .table th, .table td { padding: 11px 10px; }
  .table th:first-child, .table td:first-child {
    position: sticky; left: 0; z-index: 3; background: var(--surface);
    box-shadow: inset -1px 0 0 var(--border);
    min-width: 126px; max-width: 162px; white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis;
  }
  .table td:first-child .rowflag { margin-right: 4px; }
  .table thead th:first-child { z-index: 5; background: var(--surface-2); }
  .table tbody tr.row-overdue td:first-child { background: var(--danger-bg); }
  .owner-cell { height: 32px; line-height: 24px; }
  .progress-txt { font-size: 12.5px; }
  .group-head { margin-top: 18px; flex-wrap: wrap; gap: 4px 8px; }
  .gh-count { font-size: 12px; }

  /* 进度框：手机上操作按钮常显（没有 hover），勾选框加大 */
  .stage { padding: 10px; }
  .stage-check { width: 22px; height: 22px; }
  .stage-actions { opacity: 1; }
  .stage-sub { font-size: 12px; }
  .tl-content { font-size: 14px; }

  /* 弹窗改底部抽屉：单手够得着，按钮整宽 */
  .modal-mask { padding: 0; align-items: flex-end; }
  .modal, .modal.wide {
    max-width: 100%; border-radius: 16px 16px 0 0; max-height: 90vh;
    padding-bottom: env(safe-area-inset-bottom); animation: sheetup .2s cubic-bezier(.2,.8,.3,1);
  }
  @keyframes sheetup { from { transform: translateY(18px); opacity: .7; } to { transform: none; opacity: 1; } }
  .modal-head { padding: 16px 16px 8px; }
  .modal-body { padding: 8px 16px 16px; }
  .modal-foot {
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    position: sticky; bottom: 0;
  }
  .modal-foot .btn { flex: 1; min-height: 44px; }
  .modal .table { min-width: 520px; }

  .notice { font-size: 12.5px; padding: 10px 12px; }
  .notice-x { min-width: 34px; min-height: 32px; display: inline-flex; align-items: center; justify-content: center; }
  .toast-wrap { right: 10px; left: 10px; bottom: calc(10px + env(safe-area-inset-bottom)); }
  .toast { max-width: none; }
}
