/* ========== 全局 ========== */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  font-size: 13px; color: #333; background: #f5f6f8;
}
a { text-decoration: none; color: inherit; }

/* ========== 顶部栏 ========== */
.topbar {
  display: flex; align-items: center; height: 50px;
  background: #1f2a44; color: #e0e6f2; padding: 0 20px;
  box-shadow: 0 2px 4px rgba(0,0,0,.08);
  position: sticky; top: 0; z-index: 100;
}
.topbar .logo { font-size: 16px; font-weight: 600; margin-right: 28px; }
.nav-tabs { display: flex; gap: 4px; flex: 1; }
.nav-tab {
  padding: 8px 18px; border-radius: 4px; font-size: 13px;
  color: #b0b8cc; transition: all .2s;
}
.nav-tab:hover { color: #fff; background: rgba(255,255,255,.06); }
.nav-tab.active {
  background: #4a6cf7; color: #fff;
}
.user-info { display: flex; align-items: center; gap: 14px; font-size: 13px; }
.user-info .role-tag {
  display: inline-block; padding: 1px 8px; border-radius: 10px;
  font-size: 11px; background: #3d4b68; color: #cfd7e7;
  margin-left: 6px;
}
.user-info .role-tag.admin { background: #f5a623; color: #1f2a44; }
.btn-link { color: #aab3c8; font-size: 13px; }
.btn-link:hover { color: #fff; }

/* ========== 工具栏 ========== */
.toolbar {
  display: flex; align-items: center; justify-content: space-between;
  height: 44px; padding: 0 20px; background: #fff;
  border-bottom: 1px solid #e8eaf0; box-shadow: 0 1px 2px rgba(0,0,0,.03);
  position: sticky; top: 50px; z-index: 90;
}
.toolbar-left { display: flex; align-items: center; gap: 10px; }
.toolbar-right { display: flex; align-items: center; gap: 14px; }
.btn {
  padding: 6px 16px; border: 1px solid transparent; border-radius: 4px;
  font-size: 13px; cursor: pointer; transition: all .15s;
  background: #fff; line-height: 1.5;
}
.btn-primary { background: #4a6cf7; color: #fff; border-color: #4a6cf7; }
.btn-primary:hover { background: #3a5ce7; }
.btn-danger { background: #f53f3f; color: #fff; border-color: #f53f3f; }
.btn-danger:hover { background: #d93636; }
.btn-ghost { border-color: #d0d5dd; color: #555; }
.btn-ghost:hover { border-color: #4a6cf7; color: #4a6cf7; }
.btn-sm { padding: 3px 10px; font-size: 12px; }
.search {
  padding: 6px 12px; border: 1px solid #d0d5dd; border-radius: 4px;
  font-size: 13px; width: 240px; outline: none;
}
.search:focus { border-color: #4a6cf7; }
.filter { font-size: 13px; color: #555; cursor: pointer; user-select: none; }
.filter input { margin-right: 4px; vertical-align: 2px; }
.sub-title { font-size: 12px; }
.tip-info { font-size: 12px; color: #888; }

/* ========== 表格容器 ========== */
.table-wrap {
  padding: 12px 20px; overflow: auto; height: calc(100vh - 50px - 44px - 24px);
}

/* ========== Excel 风格表格 ========== */
.excel-table {
  border-collapse: collapse; width: max-content; min-width: 100%;
  background: #fff; font-size: 13px;
}
.excel-table thead {
  position: sticky; top: 0; z-index: 20;
}
.excel-table th {
  background: #f0f2f5; color: #444; font-weight: 600; text-align: left;
  border: 1px solid #dfe2e8; padding: 8px 10px; white-space: nowrap;
}
.excel-table td {
  border: 1px solid #e8ebf0; padding: 0; vertical-align: middle;
  position: relative;
}
.excel-table tbody tr:hover td { background: #fafbff; }

/* ID 列 + 操作列 */
.col-rowno { width: 60px; background: #f7f8fa; text-align: center;
  border-right: 2px solid #d0d5dd !important; color: #666; font-size: 12px; }
.col-action { text-align: center; background: #fafbff; }

/* 单元格 */
.cell {
  min-height: 30px; padding: 5px 20px 5px 10px; outline: none;
  word-break: break-all; cursor: text; position: relative;
}
.cell[contenteditable="true"]:focus {
  background: #eaf2ff; box-shadow: inset 0 0 0 2px #4a6cf7;
}
.cell[contenteditable="true"]:hover { background: #f0f5ff; }
.cell[contenteditable="false"] {
  color: #aaa; background: #fafafa; cursor: not-allowed;
}
.cell.readonly-by-owner {
  color: #777; background: #fff8e6 !important;
}
.cell.readonly-by-owner[contenteditable="false"] {
  color: #888;
}
/* 业务员字段高亮行归属 */
.cell.sales-owner {
  background: #e6f7ff; color: #1890ff; font-weight: 500;
}
.cell.sales-owner.readonly-by-owner {
  background: #fff8e6 !important; color: #d48806;
}
.cell.date-input { padding: 0; }
.cell.date-input input {
  border: none; outline: none; width: 100%; height: 30px;
  padding: 5px 18px 5px 10px; font-size: 13px; background: transparent;
}
.cell.date-input input:disabled { color: #aaa; background: #fafafa; cursor: not-allowed; }

/* 数字列（自定义列类型） */
.cell.num-input { padding: 0; background: #fff; }
.cell.num-input input {
  border: none; outline: none; width: 100%; height: 30px;
  padding: 5px 10px; font-size: 13px; background: transparent;
}
.cell.num-input input:disabled { color: #aaa; background: #fafafa; cursor: not-allowed; }

/* 单元格历史小圆点：蓝=有未读修改，灰=已读；从未修改不显示 */
.history-dot {
  position: absolute; top: 3px; right: 4px;
  width: 7px; height: 7px; border-radius: 50%;
  background: #4a6cf7; cursor: pointer; z-index: 3;
  box-shadow: 0 0 0 2px #fff;
  transition: transform .12s, background .12s;
}
.history-dot:hover {
  background: #f5222d; transform: scale(1.4);
  box-shadow: 0 0 0 2px #fff;
}
.history-dot.is-read { background: #c2c6cc; }
.history-dot.is-read:hover { background: #4a6cf7; transform: scale(1.4); }
.history-dot.is-hidden { display: none; }

/* 超期天数颜色 + 单元格底色 */
.cell.overdue-0 { color: #52c41a; }
.cell.overdue-warn { color: #fa8c16; font-weight: 600; background: #fff7e6; }
.cell.overdue-danger { color: #f5222d; font-weight: 700; background: #fff1f0; }
/* 可点击处理跟进的超期格 */
.cell.overdue-cell-act { cursor: pointer; }
.cell.overdue-cell-act:hover { outline: 2px solid #ffa39e; outline-offset: -2px; }

/* 整行超期提醒：整条浅红底（暂缓期内不加此 class） */
.excel-table tbody tr.row-alert td { background: #fff1f0; }
.excel-table tbody tr.row-alert:hover td { background: #ffe7e6; }
.excel-table tbody tr.row-alert td .cell,
.excel-table tbody tr.row-alert td .cell[contenteditable="false"],
.excel-table tbody tr.row-alert td .cell.select-cell,
.excel-table tbody tr.row-alert td .cell.date-input,
.excel-table tbody tr.row-alert td .cell.num-input { background: transparent; }
.excel-table tbody tr.row-alert td .cell.readonly-by-owner { background: transparent !important; }
/* 整行标色时仍保留：业务员归属列配色、超期格高亮 */
.excel-table tbody tr.row-alert .cell.sales-owner { background: #e6f7ff !important; }
.excel-table tbody tr.row-alert .cell.sales-owner.readonly-by-owner { background: #fff8e6 !important; }
.excel-table tbody tr.row-alert .cell.overdue-warn { background: #ffe7ba !important; }
.excel-table tbody tr.row-alert .cell.overdue-danger { background: #ffccc7 !important; }

/* 操作按钮：按钮文字绝不拆行（避免小屏“历史”变两行把整行撑高） */
.col-action { width: 1%; min-width: 150px; white-space: nowrap; text-align: center; background: #fafbff; }
.row-actions { display: flex; flex-wrap: nowrap; gap: 4px; justify-content: center; align-items: center; padding: 4px 8px; }
.row-actions button {
  padding: 3px 8px; border: 1px solid #d0d5dd; background: #fff;
  border-radius: 3px; font-size: 12px; cursor: pointer; color: #555;
  white-space: nowrap; flex: 0 0 auto;
}
.row-actions button:hover { border-color: #4a6cf7; color: #4a6cf7; }
.row-actions button.delete:hover { border-color: #f53f3f; color: #f53f3f; }
.row-actions button.complete { color: #389e0d; }
.row-actions button.complete:hover { border-color: #52c41a; color: #389e0d; background: #f6ffed; }
.row-actions button:disabled { opacity: .4; cursor: not-allowed; }
.row-actions button:disabled:hover { border-color: #d0d5dd; color: #555; }

/* 完结确认按钮 */
.btn-complete { background: #52c41a; border-color: #52c41a; color: #fff; }
.btn-complete:hover { background: #49b016; border-color: #49b016; color: #fff; }
/* 弹窗确认文案支持换行 */
#confirm-text { white-space: pre-line; line-height: 1.7; }

/* 空数据提示 */
.empty-hint {
  text-align: center; padding: 60px 0; color: #999; font-size: 14px;
}

/* ========== 弹窗 ========== */
.modal {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
}
.modal-mask { position: absolute; inset: 0; background: rgba(0,0,0,.4); }
.modal-box {
  position: relative; background: #fff; border-radius: 8px;
  width: 720px; max-width: 90vw; max-height: 80vh;
  display: flex; flex-direction: column; box-shadow: 0 12px 40px rgba(0,0,0,.2);
}
.modal-box.confirm-box { width: 360px; }
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 20px; border-bottom: 1px solid #eee; font-weight: 600;
}
.modal-close {
  cursor: pointer; font-size: 22px; color: #999; line-height: 1;
}
.modal-close:hover { color: #333; }
.modal-body { padding: 16px 20px; overflow: auto; }
.modal-body p { line-height: 1.7; color: #555; font-size: 14px; }
.confirm-btns { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* 历史表格 */
.history-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.history-table th, .history-table td {
  border: 1px solid #e8ebf0; padding: 8px 10px; text-align: left; vertical-align: top;
}
.history-table th { background: #f7f8fa; font-weight: 600; color: #555; }
.history-table td.old-val { color: #f5222d; text-decoration: line-through; }
.history-table td.new-val { color: #52c41a; font-weight: 500; }
.history-empty { text-align: center; padding: 30px; color: #aaa; }

/* ========== Toast ========== */
.toast {
  position: fixed; top: 70px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,.82); color: #fff; padding: 10px 22px;
  border-radius: 6px; font-size: 13px; z-index: 2000;
  opacity: 0; transition: opacity .2s; pointer-events: none;
}
.toast.show { opacity: 1; }
.toast.success { background: rgba(82,196,26,.92); }
.toast.error { background: rgba(245,63,63,.92); }
.toast.warn { background: rgba(250,140,22,.92); }

/* ========== 回收站表格 ========== */
.recycle-table { width: 100%; }
.cell.deleted-owner { background: #fff1f0; color: #f5222d; }
.btn-restore { color: #52c41a !important; }
.btn-restore:hover { border-color: #52c41a !important; color: #52c41a !important; }
.btn-perm-del { color: #f5222d !important; }
.btn-perm-del:hover { border-color: #f5222d !important; color: #f5222d !important; }

/* 响应式：小屏幕 */
@media (max-width: 768px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 10px 12px; gap: 8px; }
  .toolbar { flex-direction: column; height: auto; padding: 10px 12px; gap: 8px; }
  .search { width: 160px; }
  .nav-tab { padding: 6px 12px; font-size: 12px; }
  .table-wrap { height: auto; padding: 8px; }
  /* 操作按钮更紧凑，但仍保持一行 */
  .row-actions { gap: 3px; padding: 3px 4px; }
  .row-actions button { padding: 3px 6px; font-size: 11px; }
  .col-action { min-width: 132px; }
  .excel-table { font-size: 12px; }
  .cell { min-height: 28px; }
  /* 列管理页排序按钮 */
  .field-row { gap: 6px; }
  .field-row .f-flabel { width: 140px; }
}

/* ============================================================
   v2 扩展样式
   ============================================================ */

/* 下拉单元格（形状） */
.cell.select-cell { padding: 0; background: #fff; }
.cell.select-cell select {
  width: 100%; height: 30px; border: none; outline: none;
  background: transparent; font-size: 13px; padding: 0 16px 0 10px;
  cursor: pointer; color: #333;
}
.cell.select-cell select:disabled { color: #999; background: #fafafa; cursor: not-allowed; }
.cell.date-input { background: #fff; }

/* 角色标签 */
.role-tag.role-sales { background: #e6f7ff; color: #1890ff; }
.role-tag.role-production { background: #f6ffed; color: #389e0d; }

/* 历史字段标签 */
.field-tag {
  display: inline-block; padding: 1px 8px; border-radius: 3px;
  background: #eef2ff; color: #4a6cf7; font-size: 11px; white-space: nowrap;
}

/* 变动提示条 */
.change-banner {
  position: fixed; top: 100px; left: 50%; transform: translateX(-50%);
  z-index: 1500; background: #fff7e6; border: 1px solid #ffd591;
  color: #d46b08; padding: 8px 18px; border-radius: 20px; font-size: 13px;
  box-shadow: 0 4px 14px rgba(0,0,0,.12);
}
.change-banner a { color: #4a6cf7; font-weight: 600; }

.btn-block { width: 100%; padding: 10px; font-size: 14px; }
.center { text-align: center; }

/* ========== 登录页 ========== */
.login-body {
  background: linear-gradient(135deg, #1f2a44 0%, #3a4f80 100%);
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
}
.login-wrap { width: 380px; max-width: 92vw; }
.login-card {
  background: #fff; border-radius: 12px; padding: 36px 32px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3); text-align: center;
}
.login-logo { font-size: 44px; }
.login-card h1 { font-size: 19px; margin: 10px 0 6px; color: #1f2a44; line-height: 1.4; }
.login-sub { color: #888; font-size: 12px; margin-bottom: 22px; }
.login-error {
  background: #fff1f0; border: 1px solid #ffa39e; color: #cf1322;
  padding: 8px 12px; border-radius: 6px; font-size: 13px; margin-bottom: 16px;
}
.login-form { text-align: left; }
.login-form label {
  display: block; font-size: 13px; color: #555; margin-bottom: 14px;
}
.login-form input {
  width: 100%; margin-top: 5px; padding: 9px 12px;
  border: 1px solid #d0d5dd; border-radius: 6px; font-size: 14px; outline: none;
}
.login-form input:focus { border-color: #4a6cf7; }
/* 记住密码：复选框不撑满整行 */
.login-form label.remember-line {
  display: flex; align-items: center; font-size: 13px; color: #666; margin-bottom: 16px;
}
.login-form label.remember-line input {
  width: auto; margin: 0 7px 0 0; padding: 0; }

/* ========== 统计概览 ========== */
.dashboard { padding: 22px; max-width: 1200px; margin: 0 auto; }
.page-title { font-size: 20px; color: #1f2a44; margin-bottom: 18px; }
.stat-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 16px; margin-bottom: 22px;
}
.stat-card {
  background: #fff; border-radius: 10px; padding: 22px 24px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06); border-left: 5px solid #4a6cf7;
  transition: transform .15s, box-shadow .15s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(0,0,0,.1); }
.stat-num { font-size: 34px; font-weight: 700; line-height: 1.2; color: #1f2a44; }
.stat-label { color: #888; font-size: 13px; margin-top: 6px; }
.stat-blue { border-left-color: #4a6cf7; }
.stat-red { border-left-color: #f5222d; }
.stat-red .stat-num { color: #f5222d; }
.stat-green { border-left-color: #52c41a; }
.stat-green .stat-num { color: #389e0d; }
.stat-orange { border-left-color: #fa8c16; }
.stat-orange .stat-num { color: #d46b08; }

.dash-panels { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 860px) { .dash-panels { grid-template-columns: 1fr; } }
.dash-panel {
  background: #fff; border-radius: 10px; padding: 18px 20px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.dash-panel h3 { font-size: 15px; margin-bottom: 12px; color: #1f2a44; }
.link-btn { color: #4a6cf7; font-size: 12px; }

/* ========== 通用小表格 / 设置页 ========== */
.mini-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.mini-table th, .mini-table td { border: 1px solid #e8ebf0; padding: 8px 10px; text-align: left; }
.mini-table th { background: #f7f8fa; font-weight: 600; color: #555; white-space: nowrap; }
.mini-table input, .mini-table select {
  width: 100%; padding: 5px 8px; border: 1px solid #d0d5dd;
  border-radius: 4px; font-size: 13px;
}

.settings-wrap { padding: 22px; max-width: 1100px; margin: 0 auto; }
.settings-card {
  background: #fff; border-radius: 10px; padding: 20px 24px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06); margin-bottom: 18px;
}
.settings-card h3 { font-size: 15px; margin-bottom: 8px; color: #1f2a44; }
.settings-hint { color: #999; font-size: 12px; line-height: 1.7; margin-bottom: 14px; }
.add-form {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
  margin-top: 14px; padding-top: 14px; border-top: 1px dashed #e8ebf0;
}
.add-form input, .add-form select {
  padding: 7px 10px; border: 1px solid #d0d5dd; border-radius: 4px; font-size: 13px;
}
.inline-form { display: inline-flex; gap: 4px; margin-right: 6px; }
.msg-bar {
  background: #e6fffb; border: 1px solid #87e8de; color: #08979c;
  padding: 9px 14px; border-radius: 6px; margin-bottom: 16px; font-size: 13px;
}

/* ========== 修改密码页 ========== */
.pwd-wrap { display: flex; justify-content: center; padding: 50px 20px; }
.pwd-card {
  background: #fff; border-radius: 10px; padding: 28px 30px;
  width: 400px; max-width: 94vw; box-shadow: 0 2px 12px rgba(0,0,0,.08);
}
.pwd-card h2 { font-size: 18px; margin-bottom: 8px; color: #1f2a44; }
.pwd-hint { color: #888; font-size: 13px; margin-bottom: 18px; }
.pwd-card label { display: block; font-size: 13px; color: #555; margin-bottom: 14px; }
.pwd-card input {
  width: 100%; margin-top: 5px; padding: 9px 12px;
  border: 1px solid #d0d5dd; border-radius: 6px; font-size: 14px; outline: none;
}
.pwd-card input:focus { border-color: #4a6cf7; }
.pwd-result { margin-top: 12px; font-size: 13px; }

/* ========== 系统设置：保存状态条 + 形状规则卡片 ========== */
.save-status {
  display: none; margin-bottom: 14px; padding: 9px 14px;
  border: 1px solid; border-radius: 6px; font-size: 13px;
}
.rule-cards { display: flex; flex-direction: column; gap: 10px; }
.rule-card {
  display: flex; align-items: center; gap: 16px;
  border: 1px solid #e8ebf0; border-radius: 8px; padding: 12px 16px;
  background: #fcfcfd; flex-wrap: wrap;
}
.rule-shape-name { width: 160px; }
.rule-shape-name input {
  width: 100%; padding: 7px 10px; border: 1px solid #d0d5dd;
  border-radius: 6px; font-size: 14px; font-weight: 600;
}
.rule-desc { flex: 1; min-width: 280px; color: #666; font-size: 13px; }
.rule-desc input[type=number] {
  width: 70px; padding: 5px 8px; border: 1px solid #d0d5dd;
  border-radius: 6px; font-size: 14px; text-align: center; margin: 0 4px;
}
.rule-desc b { color: #f5222d; font-size: 15px; }
.rule-ops { display: flex; gap: 8px; }
.type-rule-block {
  border: 1px solid #eef0f4; border-radius: 10px; padding: 14px 16px;
  margin-bottom: 14px; background: #fff;
}
.type-rule-title {
  font-size: 14px; color: #1f2a44; margin-bottom: 10px;
  display: flex; align-items: center; gap: 10px;
}
.type-rule-date { font-size: 12px; color: #999; font-weight: 400; }

/* ========== 表格列管理 ========== */
.field-block .field-list { display: flex; flex-direction: column; gap: 8px; }
.field-row {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.field-row .f-flabel {
  width: 170px; padding: 6px 10px; border: 1px solid #d0d5dd;
  border-radius: 6px; font-size: 13px; font-weight: 600;
}
.field-row .f-ftype, .add-form .new-ftype {
  padding: 6px 8px; border: 1px solid #d0d5dd; border-radius: 6px; font-size: 13px;
}
.field-row .f-fopts {
  flex: 1; min-width: 220px; padding: 6px 10px;
  border: 1px solid #d0d5dd; border-radius: 6px; font-size: 13px;
}
.field-row .ftype-tag {
  display: inline-block; min-width: 108px; text-align: center;
  font-size: 12px; color: #888; background: #f5f6f8;
  border: 1px solid #e8ebf0; border-radius: 4px; padding: 4px 10px;
}
.field-off-hint { font-size: 12px; color: #fa8c16; }
.field-ops { display: flex; gap: 8px; margin-left: auto; }

/* 列排序按钮组 */
.f-order { display: flex; gap: 2px; flex: 0 0 auto; }
.f-order .btn { min-width: 32px; padding: 4px 0; font-weight: 700; }
.f-order .btn:disabled { opacity: .35; cursor: not-allowed; }

/* 超期跟进弹窗 */
.followup-text { line-height: 1.9; font-size: 14px; }
.followup-label { display: block; font-size: 13px; color: #666; line-height: 1.7; margin: 6px 0 10px; }
.followup-label input {
  display: block; width: 100%; margin-top: 8px; padding: 8px 10px;
  border: 1px solid #d0d5dd; border-radius: 6px; font-size: 14px;
}
.followup-label input:focus { border-color: #4a6cf7; outline: none; }
.followup-quick { display: flex; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }

/* 类型表操作列按钮组 */
.mini-table td.row-ops { white-space: nowrap; }
.mini-table td.row-ops .btn { margin: 2px 2px; }

/* 列管理页返回链接 */
.page-head-row { margin-bottom: 6px; }
.back-link { color: #4a6cf7; font-size: 13px; text-decoration: none; }
.back-link:hover { text-decoration: underline; }
