/* ========== 主题色（改配色只动这里） ========== */
:root {
  --bg: #f3f5f9;
  --card: #ffffff;
  --line: #e6e9ef;
  --line-soft: #f0f2f6;
  --text: #1d2433;
  --text-2: #4b5468;
  --muted: #8b93a7;
  --primary: #4f6ef7;
  --primary-dark: #3d5ae6;
  --primary-soft: #eef1ff;
  --success: #12a150;
  --success-soft: #e8f7ee;
  --warning: #e8710a;
  --warning-soft: #fff3e6;
  --danger: #e5484d;
  --danger-soft: #fdecec;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 4px 16px rgba(16, 24, 40, .06);
  --ring: 0 0 0 3px rgba(79, 110, 247, .18);
  --control-h: 38px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); margin: 0; }
.error { color: var(--danger); min-height: 1.5em; margin: 0; font-size: 13px; }
h1 { font-size: 18px; margin: 0; font-weight: 700; letter-spacing: .5px; }
h2 { font-size: 17px; margin: 0; font-weight: 600; }

/* ========== 按钮 ========== */
button, input, textarea { font: inherit; color: inherit; }
button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: var(--control-h); padding: 0 16px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--card); color: var(--text-2);
  cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s, box-shadow .15s;
}
button:hover { border-color: #c9d1e3; background: #f8f9fc; color: var(--text); }
button:focus-visible { outline: none; box-shadow: var(--ring); }
button.primary { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 2px 6px rgba(79, 110, 247, .3); }
button.primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); color: #fff; }
button.ghost { border-color: transparent; background: transparent; color: var(--muted); }
button.ghost:hover { background: var(--line-soft); color: var(--text); }
button.block { width: 100%; height: 42px; font-size: 15px; }
.icon { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }

/* ========== 输入框 ========== */
input, textarea {
  height: var(--control-h); padding: 0 12px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--card); outline: none;
  transition: border-color .15s, box-shadow .15s;
}
textarea { height: auto; padding: 10px 12px; resize: vertical; line-height: 1.6; }
input:hover, textarea:hover { border-color: #c9d1e3; }
input:focus, textarea:focus { border-color: var(--primary); box-shadow: var(--ring); }
input::placeholder, textarea::placeholder { color: #b3b9c8; }

/* ========== 自绘下拉框（dropdown.js） ========== */
.dropdown { position: relative; }
.dd-trigger {
  min-width: 160px; justify-content: space-between; gap: 12px; padding: 0 12px 0 14px;
  color: var(--text-2); font-weight: normal;
}
.dropdown.has-value .dd-trigger { color: var(--primary); border-color: #c5d0ff; background: var(--primary-soft); }
/* 选中某个录入人时，按钮用这个人的颜色 */
.dropdown.tag .dd-trigger { color: var(--tag-fg); background: var(--tag-bg); border-color: transparent; }
.dropdown.tag.open .dd-trigger { background: var(--card); border-color: var(--tag-dot); }
.dropdown.tag .dd-label::before, .dd-item.tag span:first-child::before {
  content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 8px; border-radius: 50%;
  background: var(--tag-dot); vertical-align: 1px;
}
.dd-item.tag.selected { color: var(--tag-fg); }
.dd-item.tag.selected.active { background: var(--tag-bg); }
.dropdown.open .dd-trigger { border-color: var(--primary); box-shadow: var(--ring); background: var(--card); }
.dd-arrow { display: flex; width: 16px; height: 16px; color: var(--muted); transition: transform .2s; }
.dd-arrow svg, .dd-check svg { width: 100%; height: 100%; }
.dropdown.open .dd-arrow { transform: rotate(180deg); color: var(--primary); }

.dd-menu {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 20;
  min-width: 100%; max-height: 280px; overflow-y: auto;
  margin: 0; padding: 6px; list-style: none;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 12px 32px rgba(16, 24, 40, .14);
  /* 展开动画：淡入 + 轻微下滑 */
  opacity: 0; transform: translateY(-4px); pointer-events: none; visibility: hidden;
  transition: opacity .15s, transform .15s, visibility .15s;
}
.dropdown.open .dd-menu { opacity: 1; transform: translateY(0); pointer-events: auto; visibility: visible; }
.dd-item {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  height: 36px; padding: 0 10px 0 12px; border-radius: 7px;
  color: var(--text-2); cursor: pointer; white-space: nowrap;
}
.dd-item.active { background: #f3f5fa; color: var(--text); }
.dd-item.selected { color: var(--primary); font-weight: 600; }
.dd-item.selected.active { background: var(--primary-soft); }
.dd-check { display: flex; width: 16px; height: 16px; visibility: hidden; }
.dd-item.selected .dd-check { visibility: visible; }
/* 第一项「全部」和具体人之间加一条分隔线 */
.dd-item:first-child { margin-bottom: 4px; position: relative; }
.dd-item:first-child::after { content: ""; position: absolute; left: 8px; right: 8px; bottom: -3px; height: 1px; background: var(--line-soft); }

input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--primary); margin: 0; }

/* ========== 登录页 ========== */
.login {
  display: flex; justify-content: center; align-items: center; height: 100vh;
  background: radial-gradient(circle at 20% 20%, #e3e9ff 0, transparent 45%),
              radial-gradient(circle at 80% 80%, #e6f4ff 0, transparent 45%), var(--bg);
}
.login-card {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  width: 360px; padding: 40px 36px 28px;
  background: var(--card); border-radius: 16px; box-shadow: 0 12px 40px rgba(16, 24, 40, .1);
}
.login-card h1 { font-size: 22px; }
.login-card .muted { margin-bottom: 12px; }
.login-card input { width: 100%; height: 42px; }

.login-logo { width: 72px; height: 72px; margin-bottom: 4px; }

/* ========== 主界面布局：表格占满剩余高度，不靠写死的 calc ========== */
#main-view { display: flex; flex-direction: column; height: 100vh; }
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  height: 64px; padding: 0 28px; flex-shrink: 0;
  background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo { width: 38px; height: 38px; flex-shrink: 0; }
.subtitle { margin: 0; font-size: 12px; color: var(--muted); }
.actions { display: flex; gap: 10px; align-items: center; }
/* 顶栏当前登录账号：用自己的录入人颜色 */
.me { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px 0 10px; margin-left: 4px; border-radius: 15px; font-size: 13px; font-weight: 600; background: var(--tag-bg, var(--line-soft)); color: var(--tag-fg, var(--text-2)); }
.me::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--tag-dot, var(--muted)); }
.content { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 20px 28px 14px; }

/* ========== 汇总卡片 ========== */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 18px; flex-shrink: 0; }
.stat {
  position: relative; overflow: hidden;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px 20px 16px 24px; display: flex; flex-direction: column; gap: 4px;
}
.stat::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--accent, var(--primary)); }
.stat span { color: var(--muted); font-size: 13px; }
.stat b { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--accent-text, var(--text)); }
.stat.v-count    { --accent: #8b93a7; }
.stat.v-total    { --accent: var(--primary); }
.stat.v-received { --accent: var(--success); --accent-text: var(--success); }
.stat.v-pending  { --accent: var(--warning); --accent-text: var(--warning); }

/* ========== 导航页签 + 筛选 ========== */
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 14px; flex-shrink: 0; }
.nav { display: inline-flex; gap: 4px; padding: 4px; background: #e9ecf3; border-radius: 10px; }
.tab {
  height: 34px; padding: 0 16px; border: none; border-radius: 8px;
  background: transparent; color: var(--text-2); font-weight: 500;
}
.tab:hover { background: rgba(255, 255, 255, .6); color: var(--text); }
.tab.active { background: var(--card); color: var(--primary); font-weight: 600; box-shadow: 0 1px 3px rgba(16, 24, 40, .12); }
.tab .count {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; background: rgba(139, 147, 167, .16); color: var(--muted);
}
.tab.active .count { background: var(--primary-soft); color: var(--primary); }

/* 状态页签容器不占布局，页签直接排进 .nav */
.status-tabs { display: contents; }

/* 第一个页签：带下拉的「全部订单 / 我的订单」，外观和普通页签一致 */
.tab-dropdown .dd-trigger {
  min-width: 0; height: 34px; padding: 0 10px 0 16px; gap: 6px;
  border: none; border-radius: 8px; background: transparent; color: var(--text-2); font-weight: 500;
}
.tab-dropdown .dd-trigger:hover { background: rgba(255, 255, 255, .6); color: var(--text); }
.tab-dropdown.active .dd-trigger { background: var(--card); color: var(--primary); font-weight: 600; box-shadow: 0 1px 3px rgba(16, 24, 40, .12); }
.tab-dropdown.has-value .dd-trigger { border: none; }
.tab-dropdown:not(.active).has-value .dd-trigger { background: transparent; color: var(--text-2); }
.tab-dropdown.open .dd-trigger { box-shadow: var(--ring); }
.tab-dropdown .dd-arrow { width: 14px; height: 14px; }
.tab-dropdown .dd-menu { left: 0; right: auto; min-width: 150px; }
.tab-dropdown .count {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 500; background: rgba(139, 147, 167, .16); color: var(--muted);
}
.tab-dropdown.active .count { background: var(--primary-soft); color: var(--primary); }

.filters { display: flex; gap: 10px; align-items: center; }
.search { position: relative; }
.search .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search input { width: 300px; padding-left: 36px; }

/* ========== 表格 ========== */
.table-wrap {
  flex: 1; min-height: 0; overflow: auto;
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
}
table { border-collapse: separate; border-spacing: 0; width: 100%; min-width: 1200px; }
th, td { text-align: center; white-space: nowrap; padding: 0; border-bottom: 1px solid var(--line-soft); }
th {
  position: sticky; top: 0; z-index: 1;
  height: 46px; padding: 0 10px;
  background: #f7f8fb; color: var(--text-2); font-size: 13px; font-weight: 600;
  border-bottom: 1px solid var(--line);
}
tbody tr { transition: background .12s; }
tbody tr:nth-child(even) td { background: #fbfcfd; }
tbody tr:hover td { background: #f4f7ff; }
tbody tr:last-child td { border-bottom: none; }

td .cell { padding: 12px 10px; min-height: 46px; outline: none; border-radius: 6px; }
td .cell[contenteditable="true"] { cursor: text; }
td .cell[contenteditable="true"]:hover { background: rgba(79, 110, 247, .05); }
td .cell[contenteditable="true"]:focus { background: #fff; box-shadow: inset 0 0 0 2px var(--primary); }
td.wide .cell { white-space: normal; min-width: 150px; max-width: 300px; margin: 0 auto; }
td.readonly .cell { color: var(--muted); font-size: 13px; }
td[data-field="name"] .cell { font-weight: 600; }
td[data-field="phone"] .cell { font-variant-numeric: tabular-nums; letter-spacing: .3px; }
/* 录入人标签：颜色由 colors.js 按名字写进 --tag-* 变量 */
td[data-field="recorder"] .cell.tag {
  display: inline-flex; align-items: center; gap: 6px; min-height: 0; margin: 8px; padding: 2px 10px 2px 8px;
  background: var(--tag-bg); color: var(--tag-fg); border-radius: 12px; font-size: 13px; font-weight: 500;
}
td[data-field="recorder"] .cell.tag::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--tag-dot); flex-shrink: 0; }
td[data-field="recorder"] .cell.tag:focus { background: #fff; }

/* 金额：等宽数字，上下对比不跳 */
td.money .cell { font-variant-numeric: tabular-nums; min-width: 90px; }
[data-field="balance"] .cell { color: var(--warning); font-weight: 700; }
/* 写手那三列用紫色系，和客户的钱一眼区分开 */
[data-field="writer_balance"] .cell { color: #8b46e8; font-weight: 700; }
[data-field="balance"] .cell.negative, [data-field="writer_balance"] .cell.negative { color: var(--danger); background: var(--danger-soft); }

/* 金额分组格：一格三行，左小标签、右金额。
   两组各一套颜色（改颜色只动这里）：客户收款 = 橙，写手付款 = 紫；表头、底色、小标签、手机卡片都用它 */
[data-group="customer_money"] { --grp: #d9620a; --grp-bg: #fff7ef; --grp-line: #fde3c8; }
[data-group="writer_money"]   { --grp: #8b46e8; --grp-bg: #f7f2ff; --grp-line: #e6d8fb; }
th.money-group { color: var(--grp); }
th.money-group::after { content: ""; display: block; width: 28px; height: 3px; margin: 4px auto 0; border-radius: 2px; background: var(--grp); opacity: .6; }
tbody tr td.money-group, tbody tr:nth-child(even) td.money-group, tbody tr:hover td.money-group { background: var(--grp-bg); }
.money-group .mlabel { color: var(--grp); opacity: .75; }
.money-group .mrow + .mrow { border-top-color: var(--grp-line); }
th.money-group, td.money-group { min-width: 135px; }
td.money-group { padding: 6px 10px; }
.mrow { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 26px; }
.mrow + .mrow { border-top: 1px dashed var(--line-soft); }
.mlabel { flex-shrink: 0; font-size: 12px; color: var(--muted); }
.mrow .cell { flex: 1; min-height: 26px; padding: 3px 6px; text-align: right; font-variant-numeric: tabular-nums; }
/* 写手付款格整体淡紫底，和客户收款区分 */

/* 已结算：尾款已收，变灰划掉；结算时间做成绿色标签 */
tr.settled [data-field="balance"] .cell { color: var(--muted); font-weight: normal; text-decoration: line-through; }
tr.settled td[data-field="settled_at"] .cell { color: var(--success); }

/* 操作列 */
.actions-cell { padding: 0 6px; }
/* 操作列钉在右侧：列多了表格要横向滚动时，「结算 / 删除」也一直看得到。
   底色必须不透明，否则滚动时下面的内容会透出来；隔行色 / 悬停色由 tbody 规则覆盖 */
.orders th:last-child { position: sticky; right: 0; z-index: 2; }
td.actions-cell { position: sticky; right: 0; z-index: 1; background: var(--card); box-shadow: -8px 0 10px -8px rgba(16, 24, 40, .14); }
.orders th:last-child { box-shadow: -8px 0 10px -8px rgba(16, 24, 40, .14); }
/* 操作按钮做小：一排三个（结算 / 加急 / 删除）也不占太宽 */
.actions-cell button { height: 24px; padding: 0 7px; font-size: 12px; border-radius: 12px; margin-right: 3px; }
.actions-cell button:last-child { margin-right: 0; }
/* 「结算」和「撤销结算」等宽，后面的「删除」上下对齐 */
/* 「结算 / 撤销结算」「加急 / 取消加急」各自等宽，上下行对齐 */
.actions-cell button.settle, .actions-cell button.link, .actions-cell button.urgent-btn { min-width: 62px; }
button.settle { color: var(--success); border-color: #bfe8cf; background: var(--success-soft); }
button.settle:hover { background: var(--success); border-color: var(--success); color: #fff; }
button.settle:disabled { color: #c0c6d4; border-color: var(--line); background: #f7f8fa; cursor: not-allowed; }
button.link { border-color: transparent; background: transparent; color: var(--muted); }
button.link:hover { background: var(--line-soft); color: var(--text); }
button.danger { border-color: transparent; background: transparent; color: var(--danger); }
/* 加急：按钮红色描边；加急的行左边一条红线 + 淡红底，一眼看出 */
button.urgent-btn { color: var(--danger); border-color: #f6c4c6; background: #fff; }
button.urgent-btn:hover { background: var(--danger); border-color: var(--danger); color: #fff; }
button.urgent-btn.on { background: var(--danger-soft); border-color: #f6c4c6; }
tbody tr.urgent td, tbody tr.urgent:nth-child(even) td { background: #fff6f6; }
tbody tr.urgent td:first-child { box-shadow: inset 4px 0 0 var(--danger); }
/* 「急」标签放在添加时间下面单独一行，不和日期抢宽度 */
tbody tr.urgent td[data-field="created_at"] .cell::after { content: "加急"; display: block; width: fit-content; margin: 3px auto 0; padding: 0 6px; border-radius: 4px; background: var(--danger); color: #fff; font-size: 12px; font-weight: 600; line-height: 18px; }

/* 时间：日期 / 时分上下两行 */
/* pre：只在日期和时分之间换行，日期本身不许再断开（不然列窄时会断成「2026-11-」「21」） */
td[data-field="created_at"] .cell, td[data-field="settled_at"] .cell { white-space: pre; line-height: 1.45; }

/* 时期筛选的自定义日期框 */
.period-custom { display: inline-flex; align-items: center; gap: 6px; padding: 0 6px; flex-shrink: 0; }
.period-custom input { height: 30px; padding: 0 8px; font-size: 13px; }
button.danger:hover { background: var(--danger-soft); color: var(--danger); }

.empty { padding: 60px 0; text-align: center; color: var(--muted); }
.table-foot { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-top: 12px; flex-shrink: 0; }
.tip { margin: 0 2px; font-size: 12px; color: var(--muted); }

/* ========== 分页条（pager.js） ========== */
.pager { display: flex; align-items: center; gap: 6px; }
.pg-info { margin-right: 6px; font-size: 13px; color: var(--muted); }
.pg-btn {
  min-width: 32px; height: 32px; padding: 0 8px; border-radius: 8px;
  font-variant-numeric: tabular-nums; color: var(--text-2);
}
.pg-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; cursor: default; box-shadow: 0 2px 6px rgba(79, 110, 247, .3); }
.pg-btn:disabled { color: #c0c6d4; background: var(--card); border-color: var(--line); cursor: not-allowed; }
.pg-ellipsis { min-width: 20px; text-align: center; color: var(--muted); letter-spacing: 1px; }
.pg-jump { display: flex; align-items: center; gap: 6px; margin-left: 8px; font-size: 13px; color: var(--muted); }
.pg-jump input { width: 56px; height: 32px; padding: 0 8px; text-align: center; -moz-appearance: textfield; }
.pg-jump input::-webkit-inner-spin-button, .pg-jump input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.pager.single .pg-btn, .pager.single .pg-ellipsis, .pager.single .pg-jump { display: none; }

/* ========== 电话小眼睛 / 查看密码弹窗 ========== */
.eye-btn {
  width: 26px; height: 26px; padding: 0; margin-left: 6px; vertical-align: middle;
  border: none; border-radius: 6px; background: transparent; color: var(--muted);
}
.eye-btn svg { width: 16px; height: 16px; }
.eye-btn:hover { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.eye-btn.on { color: var(--primary); }
.mobile-only { display: none; }
td[data-field="phone"] .cell.masked { color: var(--text-2); letter-spacing: 1px; cursor: default; }

dialog { border: none; padding: 0; background: transparent; }
dialog::backdrop { background: rgba(16, 24, 40, .45); }
.modal {
  width: min(400px, calc(100vw - 32px)); padding: 22px 24px; display: flex; flex-direction: column; gap: 14px;
  background: var(--card); border-radius: 16px; box-shadow: 0 20px 50px rgba(16, 24, 40, .2);
}
.modal-head { display: flex; justify-content: space-between; align-items: center; }
.modal .hint { margin: 0; font-size: 13px; color: var(--muted); line-height: 1.6; }
.modal .hint b { color: var(--danger); font-weight: 600; }
.modal input { width: 100%; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; }
/* ========== 新增订单 ========== */
/* 顶栏按钮：渐变 + 加号小方块 */
.add-btn {
  height: 32px; padding: 0 12px 0 6px; gap: 6px; border: none; border-radius: 8px; font-size: 13px; font-weight: 500;
  background: linear-gradient(135deg, #6f8bff 0%, #4f6ef7 55%, #3f5de8 100%);
  box-shadow: 0 2px 8px rgba(79, 110, 247, .28), inset 0 1px 0 rgba(255, 255, 255, .22);
  transition: transform .15s, box-shadow .15s, filter .15s;
}
.add-btn:hover { transform: translateY(-1px); filter: brightness(1.05); box-shadow: 0 4px 12px rgba(79, 110, 247, .36), inset 0 1px 0 rgba(255, 255, 255, .22); background: linear-gradient(135deg, #6f8bff 0%, #4f6ef7 55%, #3f5de8 100%); }
.add-btn:active { transform: translateY(0); }
.add-btn-plus { width: 20px; height: 20px; border-radius: 6px; display: flex; align-items: center; justify-content: center; background: rgba(255, 255, 255, .22); }
.add-btn-plus .icon { width: 13px; height: 13px; stroke-width: 2.8; }

/* 弹窗 */
.add-dialog .modal { width: min(440px, calc(100vw - 32px)); padding: 22px 22px 20px; gap: 18px; }
.add-dialog[open] .modal { animation: pop-in .18s ease-out; }
.add-title { display: flex; align-items: center; gap: 12px; }
.add-title-icon {
  width: 40px; height: 40px; border-radius: 11px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; background: var(--primary-soft); color: var(--primary);
}
.add-title-icon svg, .icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.modal-sub { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.modal-sub b { color: var(--text-2); font-weight: 600; white-space: nowrap; }
.icon-btn { display: flex; align-items: center; justify-content: center; }
.icon-btn svg { width: 18px; height: 18px; }

/* 两张选项卡片：渐变图标块 + 标题（带可见范围小标签）+ 说明 + 快捷键 + 箭头。
   注意按钮默认 white-space: nowrap，这里必须放开，否则说明文字会把弹窗撑出屏幕 */
.kind-choices { display: flex; flex-direction: column; gap: 10px; }
.kind-btn {
  --kc: var(--primary); --kc-soft: var(--primary-soft); --kc-grad: linear-gradient(135deg, #7d96ff, #4f6ef7);
  position: relative; width: 100%; height: auto; padding: 16px 16px 16px 14px; gap: 14px; justify-content: flex-start;
  white-space: normal; text-align: left; border: 1.5px solid var(--line); border-radius: 14px; background: var(--card);
  transition: border-color .15s, background .15s, box-shadow .15s, transform .15s;
}
.kind-btn.personal { --kc: var(--success); --kc-soft: var(--success-soft); --kc-grad: linear-gradient(135deg, #3ccf7f, #12a150); }
.kind-btn:hover, .kind-btn:focus-visible {
  border-color: var(--kc); background: var(--kc-soft); color: inherit;
  box-shadow: 0 8px 22px rgba(16, 24, 40, .08); transform: translateY(-1px);
}
.kind-icon {
  flex-shrink: 0; width: 48px; height: 48px; border-radius: 14px;
  display: flex; align-items: center; justify-content: center; color: #fff; background: var(--kc-grad);
  box-shadow: 0 6px 14px color-mix(in srgb, var(--kc) 30%, transparent);
}
.kind-icon svg, .kind-arrow { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.kind-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.kind-title { display: flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 600; color: var(--text); }
.kind-chip { padding: 1px 8px; border-radius: 10px; font-size: 11px; font-style: normal; font-weight: 500; color: var(--kc); background: var(--kc-soft); }
.kind-btn:hover .kind-chip { background: var(--card); }
.kind-desc { font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.kind-key {
  flex-shrink: 0; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 6px;
  display: inline-flex; align-items: center; justify-content: center;
  font: 600 12px/1 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted);
  background: var(--line-soft); border: 1px solid var(--line); border-bottom-width: 2px;
}
.kind-arrow { width: 18px; height: 18px; color: #c0c6d4; flex-shrink: 0; transition: transform .15s, color .15s; }
.kind-btn:hover .kind-arrow { color: var(--kc); transform: translateX(3px); }
.icon-btn { width: 32px; height: 32px; padding: 0; border: none; background: transparent; color: var(--muted); border-radius: 8px; flex-shrink: 0; }
.icon-btn:hover { background: var(--line-soft); }

/* ========== 月度统计 ========== */
.stats-btn { gap: 5px; color: var(--primary); }
.stats-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.stats-dialog .modal { width: min(880px, calc(100vw - 32px)); max-height: calc(100vh - 48px); overflow: auto; }
.stats-dialog[open] .modal { animation: pop-in .18s ease-out; }
.stats-head-right { display: flex; align-items: center; gap: 10px; }
.seg { display: inline-flex; padding: 3px; border-radius: 9px; background: #e9ecf3; }
.seg button { height: 28px; padding: 0 12px; border: none; border-radius: 7px; background: transparent; font-size: 13px; color: var(--text-2); }
.seg button.active { background: var(--card); color: var(--primary); font-weight: 600; box-shadow: 0 1px 3px rgba(16, 24, 40, .12); }
.stats-section + .stats-section { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line-soft); }
.stats-section h3 { margin: 0 0 6px; font-size: 14px; font-weight: 600; color: var(--text-2); }

/* 图表：网格 / 坐标轴弱化，线 2px，点带白圈 */
.chart { position: relative; }
.chart-plot { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-grid { stroke: #eef0f4; stroke-width: 1; }
.chart-axis { stroke: #d9dde5; stroke-width: 1; }
.chart-tick { font-size: 11px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.chart-line { fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.chart-point { stroke: #fff; stroke-width: 2; }
.chart-end-label { font-size: 12px; fill: var(--text-2); }
.chart-cross { stroke: #c9d1e3; stroke-width: 1; stroke-dasharray: 3 3; }
.chart-hit { fill: transparent; cursor: crosshair; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 4px; font-size: 12px; color: var(--text-2); }
.chart-legend-item { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend i, .chart-tip i { display: inline-block; width: 12px; height: 3px; border-radius: 2px; background: var(--c); }
.chart-tip {
  position: absolute; top: 6px; z-index: 2; min-width: 150px; padding: 8px 10px; pointer-events: none;
  background: var(--card); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 6px 18px rgba(16, 24, 40, .12);
  font-size: 12px; color: var(--text-2);
}
.chart-tip b { display: block; margin-bottom: 4px; color: var(--text); font-size: 12.5px; }
.chart-tip div { display: flex; align-items: center; gap: 6px; line-height: 1.7; }
.chart-tip span { margin-left: auto; padding-left: 12px; color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }

/* 统计表格：表头带图表同色小色条；全款下有量条；收款率进度条；本月高亮；底部合计 */
.stats-table-wrap { overflow: auto; max-height: 62vh; border: 1px solid var(--line); border-radius: 12px; }
#stats-table { width: 100%; min-width: 560px; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }
#stats-table th, #stats-table td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--line-soft); white-space: nowrap; box-shadow: none; }
#stats-table .num { text-align: right; font-variant-numeric: tabular-nums; }
#stats-table thead th {
  position: sticky; top: 0; z-index: 1; height: auto; background: #f7f8fb; color: var(--text-2);
  font-size: 12.5px; font-weight: 600; border-bottom: 1px solid var(--line);
}
#stats-table .swatch { display: inline-block; width: 10px; height: 3px; margin-right: 6px; border-radius: 2px; vertical-align: 3px; background: var(--c); }
#stats-table tbody tr:nth-child(even) td { background: #fbfcfd; }
#stats-table tbody tr:hover td { background: #f4f7ff; }
#stats-table td.month { font-weight: 500; color: var(--text); }
#stats-table .zero { color: #c0c6d4; }
#stats-table tr.current td { background: var(--primary-soft); }
#stats-table tr.current td.month { color: var(--primary); font-weight: 600; }
.now-tag { margin-left: 8px; padding: 1px 7px; border-radius: 9px; font-size: 11px; font-style: normal; font-weight: 600; color: #fff; background: var(--primary); vertical-align: 1px; }
/* 全款量条：数字下面一条细线，长短 = 当月全款 / 12 个月里最多的那个月 */
#stats-table td .amount-bar { display: block; height: 3px; margin: 5px 0 0 auto; border-radius: 2px; background: var(--c); opacity: .55; }
/* 收款率 */
#stats-table td.rate { min-width: 110px; }
.rate-text { display: inline-block; min-width: 38px; font-weight: 600; color: var(--text); }
.rate-bar { display: inline-block; width: 56px; height: 6px; margin-left: 8px; border-radius: 3px; background: #e9ecf3; vertical-align: 1px; overflow: hidden; }
.rate-fill { display: block; height: 100%; border-radius: 3px; background: var(--success); }
#stats-table tfoot th, #stats-table tfoot td {
  position: sticky; bottom: 0; background: #f7f8fb; font-weight: 700; color: var(--text);
  border-top: 1px solid var(--line); border-bottom: none;
}
#stats-table tfoot th { font-size: 13px; }

/* ========== 提示 ========== */
.toast {
  position: fixed; top: 24px; left: 50%; transform: translate(-50%, -8px);
  padding: 10px 18px; border-radius: 10px; background: #1d2433; color: #fff;
  box-shadow: 0 8px 24px rgba(16, 24, 40, .2);
  opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; z-index: 10;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ========== 手机端（窄屏）：表格每行变成一张卡片，字段名在左、内容在右 ========== */
@media (max-width: 768px) {
  /* 页面整体正常滚动，不再固定一屏高 */
  #main-view { height: auto; min-height: 100vh; }
  .content { flex: none; padding: 12px 12px 20px; }

  .topbar { height: auto; padding: 10px 14px; gap: 8px; position: sticky; top: 0; z-index: 5; }
  .topbar h1 { font-size: 17px; }
  .brand { gap: 8px; }
  .brand-logo { width: 30px; height: 30px; }
  .subtitle { display: none; }
  .actions { gap: 6px; }
  .actions button { height: 34px; padding: 0 12px; }
  #btn-logout { padding: 0 8px; }
  .me { height: 28px; padding: 0 10px 0 8px; margin-left: 0; }

  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 12px; }
  .stat { padding: 12px 14px 12px 18px; }
  .stat b { font-size: 19px; }

  .toolbar { flex-direction: column; align-items: stretch; gap: 10px; }
  /* 页签放不下就左右滑 */
  .nav { overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .nav::-webkit-scrollbar { display: none; }
  .tab, .tab-dropdown .dd-trigger { flex-shrink: 0; padding: 0 12px; }
  /* 下拉菜单放在可横滑的容器里会被裁掉，展开时改成固定定位 */
  .tab-dropdown .dd-menu { position: fixed; top: auto; left: 12px; margin-top: 6px; }
  /* 搜索框单独一行，录入人下拉和「显示电话」放第二行，不然三个挤一行搜索框只剩几个字 */
  .filters { width: 100%; flex-wrap: wrap; }
  .search { flex: 1 1 100%; }
  .filters .dropdown:not(.tab-dropdown) { flex: 1; }
  .filters .dropdown:not(.tab-dropdown) .dd-trigger { width: 100%; }
  .search input { width: 100%; }
  .dropdown:not(.tab-dropdown) .dd-trigger { min-width: 120px; }

  /* iOS 上输入框字号小于 16px 会自动放大页面 */
  input, textarea, td .cell { font-size: 16px; }

  /* 表格 → 卡片 */
  .table-wrap { overflow: visible; background: transparent; box-shadow: none; border-radius: 0; }
  table.orders, .orders tbody, .orders tr, .orders td { display: block; width: 100%; min-width: 0; }
  .orders thead { display: none; }
  .orders tbody tr {
    margin-bottom: 12px; padding: 4px 14px;
    background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  }
  .orders tbody tr:nth-child(even) td, .orders tbody tr:hover td { background: transparent; }
  .orders td {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    text-align: right; white-space: normal; border-bottom: 1px dashed var(--line-soft);
  }
  .orders tbody tr td:last-child { border-bottom: none; }
  .orders td::before { content: attr(data-label); flex-shrink: 0; color: var(--muted); font-size: 13px; }
  .orders td .cell { flex: 1; min-height: 40px; padding: 9px 0; text-align: right; word-break: break-all; }
  .orders td.wide .cell { min-width: 0; max-width: none; margin: 0; }
  .orders td.money .cell { min-width: 0; }
  .orders td[data-field="recorder"] .cell.tag { flex: none; margin: 8px 0; }
  /* 每组一块带颜色的圆角小卡片，组名当小标题 */
  .orders tbody tr td.money-group, .orders tbody tr:nth-child(even) td.money-group, .orders tbody tr:hover td.money-group {
    display: block; margin: 8px 0; padding: 8px 12px; border: 1px solid var(--grp-line); border-bottom: 1px solid var(--grp-line);
    border-radius: 10px; background: var(--grp-bg);
  }
  .orders td.money-group::before { display: block; margin-bottom: 2px; text-align: left; font-weight: 600; color: var(--grp); }
  .mrow .cell { min-height: 36px; padding: 7px 0; }
  .orders td .mrow .cell[contenteditable="true"]:focus { padding: 7px 8px; }
  /* 空着的格子给个提示，不然不知道能点 */
  .orders td .cell[contenteditable="true"]:empty::before { content: "点击填写"; color: #c0c6d4; }
  .orders td.readonly .cell:empty::before { content: "—"; color: #c0c6d4; }
  .orders td .cell[contenteditable="true"]:focus { padding: 9px 8px; }

  /* 操作区：不再钉在右边，按钮放大好点 */
  .orders td.actions-cell, .orders th:last-child { position: static; box-shadow: none; }
  .orders td.actions-cell { justify-content: flex-end; gap: 10px; padding: 10px 0; }
  .orders td.actions-cell::before { margin-right: auto; }
  /* 手机上按钮保持大一点，好点 */
  .actions-cell button { height: 34px; padding: 0 14px; font-size: 14px; border-radius: 17px; margin-right: 0; }
  /* 手机卡片：加急的单整张卡片红框 */
  .orders tbody tr.urgent { box-shadow: 0 0 0 2px var(--danger), var(--shadow); }
  .orders tbody tr.urgent td, .orders tbody tr.urgent:nth-child(even) td { background: transparent; }
  .orders tbody tr.urgent td:first-child { box-shadow: none; }
  /* 时间在卡片里一行显示就够宽 */
  .orders td[data-field="created_at"] .cell, .orders td[data-field="settled_at"] .cell { white-space: normal; }
  .orders tbody tr.urgent td[data-field="created_at"] .cell::after { display: inline-block; margin: 0 0 0 6px; vertical-align: 1px; }
  .period-custom input { font-size: 16px; }

  .empty { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }
  .table-foot { flex-direction: column; align-items: center; gap: 10px; }
  .tip { display: none; }
  .pager { flex-wrap: wrap; justify-content: center; }
  .pg-jump { display: none; }

  .mobile-only { display: inline-flex; }
  #btn-phone-mobile { width: auto; height: var(--control-h); padding: 0 12px; margin: 0; gap: 4px; font-size: 13px; border: 1px solid var(--line); background: var(--card); flex-shrink: 0; }
  #btn-phone-mobile.on { border-color: #c5d0ff; background: var(--primary-soft); }

  .login-card { width: calc(100vw - 32px); padding: 32px 22px 22px; }

  /* 弹窗在手机上从底部滑出，占满宽度 */
  dialog.sheet { margin: auto 0 0; width: 100%; max-width: 100%; }
  dialog.sheet .modal {
    width: 100%; border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
    animation: sheet-up .22s ease-out;
  }
  .kind-btn { padding: 16px 14px 16px 12px; }
  .kind-key { display: none; }
  .stats-dialog .modal { width: 100%; max-height: 88vh; padding: 16px 12px calc(16px + env(safe-area-inset-bottom)); }
  .stats-dialog[open] .modal { animation: sheet-up .22s ease-out; }
  .add-dialog .modal { width: 100%; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); }
  .add-dialog[open] .modal { animation: sheet-up .22s ease-out; }
  .actions .add-btn { height: 30px; padding: 0 10px 0 5px; font-size: 13px; }
  .add-btn-plus { width: 19px; height: 19px; }
}

@keyframes sheet-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes pop-in { from { opacity: 0; transform: translateY(6px) scale(.98); } to { opacity: 1; transform: none; } }
