:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --green: #16a34a;
  --blue: #0891b2;
  --danger: #dc2626;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: "Microsoft YaHei", "PingFang SC", -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
.hidden { display: none !important; }

/* ---------- 登录页 ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 60%, #38bdf8 100%);
}
.login-card {
  background: var(--card);
  padding: 40px 36px;
  border-radius: 16px;
  width: 380px;
  box-shadow: 0 25px 60px rgba(0,0,0,.3);
  text-align: center;
}
.login-logo {
  width: 64px; height: 64px;
  margin: 0 auto 12px;
  background: var(--primary);
  color: #fff;
  border-radius: 16px;
  font-size: 26px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.login-card h1 { font-size: 22px; margin-bottom: 4px; }
.login-sub { color: var(--muted); margin-bottom: 24px; font-size: 12px; letter-spacing: 2px; }
.login-card input {
  width: 100%;
  padding: 12px 14px;
  margin-bottom: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  outline: none;
}
.login-card input:focus { border-color: var(--primary); }
.login-error { color: var(--danger); font-size: 13px; min-height: 18px; margin: 6px 0; }
.login-tip { margin-top: 16px; color: var(--muted); font-size: 12px; line-height: 1.8; background: #f8fafc; border-radius: 8px; padding: 8px; }

/* ---------- 布局 ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px;
  background: #0f172a;
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; bottom: 0; left: 0;
}
.side-logo { padding: 22px 20px; font-size: 17px; font-weight: 700; color: #fff; border-bottom: 1px solid #1e293b; }
.sidebar nav { flex: 1; padding: 12px 0; }
.sidebar nav a {
  display: block;
  padding: 13px 22px;
  cursor: pointer;
  color: #94a3b8;
  transition: .15s;
  font-size: 14px;
}
.sidebar nav a:hover { color: #fff; background: #1e293b; }
.sidebar nav a.active { color: #fff; background: var(--primary); border-radius: 0 24px 24px 0; }
.side-user { padding: 16px 20px; border-top: 1px solid #1e293b; }
.side-user p { margin-bottom: 10px; color: #e2e8f0; font-weight: 600; }

.main { flex: 1; margin-left: 220px; padding: 24px 20px 40px; min-width: 0; }
.main h2 { margin-bottom: 18px; font-size: 20px; }
.page-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; flex-wrap: wrap; gap: 10px; }
.page-head h2 { margin-bottom: 0; }

/* ---------- 组件 ---------- */
.card {
  background: var(--card);
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
  margin-bottom: 20px;
}
.card h3 { margin-bottom: 14px; font-size: 15px; }
.btn {
  border: none;
  border-radius: 8px;
  padding: 9px 18px;
  cursor: pointer;
  font-size: 14px;
  transition: .15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: transparent; color: #94a3b8; border: 1px solid #334155; }
.btn-ghost:hover { color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; }
.btn-link { background: none; border: none; color: var(--primary); cursor: pointer; padding: 2px 6px; font-size: 13px; }
.btn-link.danger { color: var(--danger); }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat-card {
  background: var(--card);
  border-radius: 12px;
  padding: 22px;
  display: flex; flex-direction: column;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.stat-num { font-size: 32px; font-weight: 700; color: var(--primary); }
.stat-num.green { color: var(--green); }
.stat-num.blue { color: var(--blue); }

.bar-row { display: flex; align-items: center; margin-bottom: 10px; gap: 10px; }
.bar-name { width: 70px; color: var(--muted); }
.bar-track { flex: 1; background: #eef2f7; border-radius: 6px; height: 18px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--primary), #38bdf8); border-radius: 6px; }
.bar-cnt { width: 40px; text-align: right; font-weight: 600; }

/* ---------- 表格（自适应全宽，长内容换行不出现横向滚动条） ---------- */
.table-card { padding: 0; overflow-x: hidden; }
table { width: 100%; border-collapse: collapse; table-layout: fixed; }
th, td {
  padding: 10px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: normal;
  word-break: break-word;
  overflow-wrap: anywhere;
  vertical-align: top;
  line-height: 1.5;
}
th { background: #f8fafc; color: var(--muted); font-weight: 600; font-size: 13px; }
tbody tr:hover { background: #f8fafc; }
/* 客户列表列宽分配 */
#page-customers table { font-size: 13px; }
#page-customers table th:nth-child(1) { width: 4%; }
#page-customers table th:nth-child(2) { width: 16%; }
#page-customers table th:nth-child(3) { width: 6%; }
#page-customers table th:nth-child(4) { width: 8%; }
#page-customers table th:nth-child(5) { width: 7%; }
#page-customers table th:nth-child(6) { width: 10%; }
#page-customers table th:nth-child(7) { width: 7%; }
#page-customers table th:nth-child(8) { width: 14%; }
#page-customers table th:nth-child(9) { width: 7%; }
#page-customers table th:nth-child(10) { width: 6%; }
#page-customers table th:nth-child(11) { width: 15%; }
#customer-tbody td:nth-child(1) { text-align: center; color: var(--muted); }
#customer-tbody td:last-child { white-space: nowrap; text-align: center; }
#customer-tbody .btn-link { padding: 0 3px; font-size: 12.5px; }
.btn-link { white-space: nowrap; }
.date-cell { white-space: normal; word-break: keep-all; font-variant-numeric: tabular-nums; }
.summary-cell { white-space: normal; word-break: break-word; }
.contact-cell { white-space: normal; word-break: break-all; }
.tag { padding: 3px 10px; border-radius: 20px; font-size: 12px; white-space: nowrap; }
/* 投标流程节点配色 */
.tag.s1 { background: #dbeafe; color: #1d4ed8; }  /* 预告中 */
.tag.s2 { background: #cffafe; color: #0e7490; }  /* 获取文件中 */
.tag.s3 { background: #fef3c7; color: #b45309; }  /* 投标准备中 */
.tag.s4 { background: #ede9fe; color: #6d28d9; }  /* 已投标待公示结果中 */
.tag.s5 { background: #dcfce7; color: #15803d; }  /* 中标（未中标） */
.tag.s6 { background: #e2e8f0; color: #475569; }  /* 结束 */

/* ---------- 客户跟踪表 ---------- */
.track-tip { color: var(--muted); font-size: 12.5px; margin-bottom: 12px; }
.track-select, .track-date {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12.5px;
  outline: none;
  background: #fff;
  width: 100%;
  max-width: 160px;
}
.track-progress {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12.5px;
  outline: none;
  width: 100%;
}
.track-progress:focus, .track-select:focus, .track-date:focus { border-color: var(--primary); }

.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filters select, .filters input {
  padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; outline: none;
}

/* ---------- 表单 ---------- */
.form-card { max-width: 760px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 20px; }
#customer-form label, #edit-form label, #user-form label {
  display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); margin-bottom: 12px;
}
#customer-form label.full, #edit-form label.full { grid-column: 1 / -1; }
#customer-form input, #customer-form select, #customer-form textarea,
#edit-form input, #edit-form select, #edit-form textarea, #user-form input, #user-form select {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; outline: none; font-family: inherit;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }

/* ---------- 弹窗 ---------- */
.modal {
  position: fixed; inset: 0;
  background: rgba(15,23,42,.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 20px;
}
.modal-box {
  background: #fff; border-radius: 14px; padding: 24px;
  width: 560px; max-width: 100%; max-height: 88vh; overflow-y: auto;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.btn-close { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--muted); }
.detail-info { background: #f8fafc; border-radius: 10px; padding: 14px 16px; margin-bottom: 16px; line-height: 2; }
.followup-list { max-height: 220px; overflow-y: auto; margin-bottom: 14px; }
.followup-item { padding: 10px 12px; border-left: 3px solid var(--primary); background: #f8fafc; border-radius: 0 8px 8px 0; margin-bottom: 8px; }
.followup-item p { margin-bottom: 4px; }
.followup-item span { color: var(--muted); font-size: 12px; }
.followup-input { display: flex; gap: 8px; }
.followup-input input { flex: 1; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; outline: none; }

/* ---------- 备案页脚 ---------- */
.icp-footer {
  text-align: center;
  padding: 14px;
  font-size: 12px;
  color: rgba(255,255,255,.85);
}
.icp-footer a { color: inherit; text-decoration: none; }
.icp-footer a:hover { text-decoration: underline; }
.app-footer {
  position: fixed;
  bottom: 0; left: 220px; right: 0;
  color: var(--muted);
  padding: 8px;
  background: transparent;
  pointer-events: auto;
}
@media (min-width: 769px) and (max-width: 1024px) { .app-footer { left: 64px; } }

/* ---------- 提示 ---------- */
.toast {
  position: fixed; top: 24px; left: 50%; transform: translateX(-50%);
  background: #0f172a; color: #fff; padding: 11px 22px; border-radius: 10px;
  z-index: 200; box-shadow: 0 10px 30px rgba(0,0,0,.25); font-size: 14px;
}
.toast.success { background: var(--green); }
.toast.error { background: var(--danger); }

/* ---------- 平板（769~1024px）：窄侧栏 ---------- */
@media (min-width: 769px) and (max-width: 1024px) {
  .sidebar { width: 64px; }
  .side-logo { font-size: 0; padding: 18px 0; text-align: center; }
  .side-logo::before { content: "CRM"; font-size: 15px; color: #fff; }
  .side-user p { display: none; }
  .side-user .btn { font-size: 12px; padding: 6px 4px; }
  .sidebar nav a { font-size: 12px; padding: 13px 4px; text-align: center; }
  .main { margin-left: 64px; padding: 16px; }
  .form-grid { grid-template-columns: 1fr; }
}

/* ---------- 手机端适配（放最后，确保优先级最高；与PC同一账号、同一数据） ---------- */
@media (max-width: 768px) {
  html, body { max-width: 100%; overflow-x: hidden; }
  .app { display: block; min-height: 100vh; }

  /* 侧边栏改为顶部固定导航条（不用 bottom:fixed，避免被手机浏览器工具栏遮挡、点不到） */
  .sidebar {
    position: sticky;
    top: 0; left: auto; right: auto; bottom: auto;
    width: 100%; height: auto;
    flex-direction: row; align-items: center;
    z-index: 1000;
    box-shadow: 0 2px 8px rgba(15,23,42,.18);
  }
  .side-logo { display: none; }
  .sidebar nav {
    flex: 1; display: flex; width: auto; padding: 0;
    overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none;
  }
  .sidebar nav::-webkit-scrollbar { display: none; }
  .sidebar nav a {
    flex: 1 0 auto; min-width: 88px;
    padding: 12px 6px;
    font-size: 12px; text-align: center;
    white-space: nowrap; border-radius: 0;
    touch-action: manipulation;
  }
  .sidebar nav a.active { border-radius: 0; }
  .side-user { display: block; padding: 8px 10px; border: 0; flex-shrink: 0; }
  .side-user p { display: none; }
  .side-user .btn { font-size: 12px; padding: 6px 8px; }

  /* 内容区占满整屏并居中，清除 PC 侧栏留下的左边距 */
  .main {
    margin-left: 0 !important;
    width: 100%; max-width: 100%;
    padding: 14px 12px 30px;
    min-width: 0;
  }
  .main h2 { font-size: 17px; }
  .page-head { flex-direction: column; align-items: stretch; }
  .filters { width: 100%; }
  .filters select, .filters input { flex: 1; min-width: 0; }
  .form-grid { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-card { padding: 14px; }
  .stat-num { font-size: 24px; }
  .card { padding: 14px; }
  .modal { padding: 12px; }
  .modal-box { width: 100%; max-height: 84vh; padding: 16px; }
  .login-card { width: 100%; max-width: calc(100% - 32px); padding: 28px 20px; }
  .app-footer.app-footer {
    position: static !important;
    left: 0 !important; right: 0 !important;
    text-align: center; padding: 10px;
  }

  /* 表格转卡片式布局 */
  .table-card { background: transparent; box-shadow: none; overflow-x: visible; }
  table { table-layout: auto; }
  #page-customers thead, #page-track thead, #page-users thead { display: none; }
  #page-customers tr, #page-track tr, #page-users tr {
    display: block;
    background: #fff;
    border-radius: 10px;
    margin-bottom: 10px;
    padding: 6px 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
  }
  #page-customers td, #page-track td, #page-users td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 7px 4px;
    border-bottom: 1px dashed var(--border);
    white-space: normal;
  }
  #page-customers td:last-child, #page-track td:last-child, #page-users td:last-child {
    border-bottom: none;
    justify-content: flex-end;
  }
  #page-customers td::before, #page-track td::before, #page-users td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    flex-shrink: 0;
  }
  #page-customers td:last-child::before, #page-track td:last-child::before, #page-users td:last-child::before { content: ''; }
  .track-progress { min-width: 140px; }
}
