/* ============================================================
   CRM 响应式样式表
   适配：桌面 / 平板 / 手机 / 小窗口
   ============================================================ */

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

:root {
  --p: #409eff; --pl: #66b1ff;
  --d: #1f2d3d; --d2: #18222f; --d3: #2a3a4d;
  --b: #e4e7ed; --m: #909399; --bg: #f0f2f5;
  --g: #67c23a; --o: #e6a23c; --r: #f56c6c;
  --sidebar-w: 200px;
  --header-h: 56px;
}

html { -webkit-text-size-adjust: 100%; }

body {
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg); color: #303133;
  min-height: 100vh;
  overflow-x: hidden;
}

a { color: var(--p); text-decoration: none; }
a:hover { opacity: .85; }
ul { list-style: none; }
img { max-width: 100%; height: auto; }

/* ============================================================
   登录页
   ============================================================ */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #1f2d3d, #2c3e50); padding: 16px;
}
.login-box {
  width: 100%; max-width: 380px;
  background: #fff; border-radius: 10px;
  padding: 32px 28px;
  box-shadow: 0 14px 50px rgba(0,0,0,.28);
}
.login-box h2 { text-align: center; font-size: 20px; color: var(--d); margin-bottom: 6px; }
.login-box .sub { text-align: center; font-size: 12px; color: var(--m); margin-bottom: 22px; }
.role-tabs {
  display: flex; border: 1px solid var(--b); border-radius: 6px;
  overflow: hidden; margin-bottom: 18px;
}
.role-tabs label { flex: 1; cursor: pointer; }
.role-tabs input { display: none; }
.role-tabs span {
  display: block; text-align: center; padding: 9px 0;
  font-size: 13px; color: #606266;
}
.role-tabs input:checked + span { background: var(--p); color: #fff; }

/* ============================================================
   主布局
   ============================================================ */
.app { display: flex; min-height: 100vh; position: relative; }

/* ----- 侧边栏 ----- */
.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--d);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 1000;
  transform: translateX(0);
  transition: transform .25s ease;
}
.sidebar .logo {
  height: var(--header-h); line-height: var(--header-h);
  text-align: center; color: #fff; font-weight: 600; font-size: 15px;
  background: var(--d2); letter-spacing: 1px;
}
.sidebar a {
  display: block; padding: 12px 20px;
  color: #bfcbd9; font-size: 14px;
  transition: background .18s, color .18s;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar a:hover { background: var(--d3); color: #fff; }
.sidebar a.active { background: var(--p); color: #fff; }
.sidebar .nav-group {
  padding: 12px 20px 5px; font-size: 11px; color: #5b6b7c;
  letter-spacing: 1px; text-transform: uppercase;
}

/* 遮罩 */
.sidebar-mask {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 999;
  opacity: 0;
  transition: opacity .25s;
  pointer-events: none;
}
.sidebar-mask.show { opacity: 1; pointer-events: auto; }

/* ----- 主区域 ----- */
.main {
  flex: 1; min-width: 0;
  margin-left: var(--sidebar-w);
  display: flex; flex-direction: column;
}

/* 顶部栏 */
.topbar {
  height: var(--header-h); flex: 0 0 var(--header-h);
  background: #fff; display: flex; align-items: center;
  padding: 0 16px;
  box-shadow: 0 1px 5px rgba(0,0,0,.06);
  position: sticky; top: 0; z-index: 100;
  gap: 10px;
}
.menu-btn {
  display: none;
  width: 36px; height: 36px;
  background: transparent; border: none; cursor: pointer;
  padding: 8px; border-radius: 6px;
  flex-direction: column; justify-content: space-between;
  flex-shrink: 0;
}
.menu-btn span {
  display: block; height: 2px; background: #303133; border-radius: 2px;
}
.menu-btn:active { background: #f5f7fa; }
.topbar .title {
  font-size: 16px; font-weight: 600; color: var(--d);
  flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar .right {
  display: flex; align-items: center; gap: 10px;
  font-size: 13px; color: #606266;
  flex-shrink: 0;
}
.topbar .right .who { color: var(--d); font-weight: 500; }

.content { padding: 16px; flex: 1; min-width: 0; }

/* ============================================================
   卡片 / 统计
   ============================================================ */
.card {
  background: #fff; border-radius: 8px;
  padding: 16px; margin-bottom: 16px;
  box-shadow: 0 1px 5px rgba(0,0,0,.05);
}
.card h3 {
  margin: 0 0 14px; font-size: 15px; font-weight: 600; color: var(--d);
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 8px;
}
.card h3 .extra { font-size: 13px; font-weight: 400; color: var(--m); }

.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }

.stat {
  background: #fff; border-radius: 8px;
  padding: 16px 18px;
  box-shadow: 0 1px 5px rgba(0,0,0,.05);
  border-left: 3px solid var(--p);
  min-width: 0;
}
.stat.g { border-left-color: var(--g); }
.stat.o { border-left-color: var(--o); }
.stat.r { border-left-color: var(--r); }
.stat .label {
  font-size: 12.5px; color: var(--m); margin-bottom: 6px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.stat .value {
  font-size: 24px; font-weight: 600; color: var(--d);
  line-height: 1.2; word-break: break-all;
}
.stat .value small { font-size: 12px; font-weight: 400; color: var(--m); margin-left: 3px; }

/* ============================================================
   表格
   ============================================================ */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -16px;
  padding: 0 16px;
}
table {
  width: 100%; border-collapse: collapse;
  font-size: 13px; min-width: 600px;
}
th, td {
  padding: 10px; border-bottom: 1px solid var(--b);
  text-align: left; white-space: nowrap;
}
th { background: #fafafa; color: #606266; font-weight: 600; font-size: 12.5px; }
tbody tr:hover { background: #f5f7fa; }
tbody tr:last-child td { border-bottom: none; }
td.wrap { white-space: normal; max-width: 240px; word-break: break-all; }

/* ============================================================
   按钮
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 6px 14px; border-radius: 4px;
  border: 1px solid var(--b); background: #fff; color: #606266;
  cursor: pointer; font-size: 13px; line-height: 1.5;
  text-decoration: none; transition: .18s; white-space: nowrap;
  -webkit-appearance: none; appearance: none;
  font-family: inherit;
}
.btn:hover { border-color: var(--p); color: var(--p); }
.btn-primary { background: var(--p); border-color: var(--p); color: #fff; }
.btn-primary:hover { background: var(--pl); border-color: var(--pl); color: #fff; }
.btn-success { background: var(--g); border-color: var(--g); color: #fff; }
.btn-success:hover { opacity: .88; color: #fff; }
.btn-danger { color: var(--r); border-color: #fbc4c4; }
.btn-danger:hover { background: var(--r); border-color: var(--r); color: #fff; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ============================================================
   表单
   ============================================================ */
input[type=text], input[type=password], input[type=number], input[type=date],
input[type=tel], input[type=file], select, textarea {
  width: 100%; padding: 8px 10px;
  border: 1px solid #dcdfe6; border-radius: 4px;
  font-size: 14px; outline: none; font-family: inherit;
  background: #fff; transition: border-color .18s;
  -webkit-appearance: none; appearance: none;
}
input[type=text]:focus, input[type=password]:focus, input[type=number]:focus,
input[type=date]:focus, input[type=tel]:focus, select:focus, textarea:focus {
  border-color: var(--p);
}
input[readonly] { background: #f5f7fa !important; color: #606266; cursor: not-allowed; }
textarea { resize: vertical; min-height: 72px; }
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M6 8L2 4h8z' fill='%23909399'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 12px;
  padding-right: 30px;
}
.form-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 12px; }
.form-item { display: flex; flex-direction: column; gap: 5px; min-width: 150px; flex: 1; }
.form-item.fixed { flex: 0 0 auto; min-width: 0; }
.form-item label { font-size: 12px; color: var(--m); }
.form-actions { display: flex; gap: 10px; padding-top: 6px; flex-wrap: wrap; }

/* ============================================================
   标签
   ============================================================ */
.tag {
  display: inline-block; padding: 1px 9px;
  border-radius: 10px; font-size: 12px; line-height: 18px;
  background: #ecf5ff; color: var(--p); white-space: nowrap;
}
.tag-green { background: #f0f9eb; color: var(--g); }
.tag-orange { background: #fdf6ec; color: var(--o); }
.tag-gray { background: #f4f4f5; color: var(--m); }
.tag-red { background: #fef0f0; color: var(--r); }
.tag-purple { background: #f5f0ff; color: #8b5cf6; }

/* ============================================================
   分页
   ============================================================ */
.pager { margin-top: 16px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.pager a, .pager span {
  padding: 4px 11px; border: 1px solid var(--b); border-radius: 4px;
  font-size: 13px; color: #606266; background: #fff;
}
.pager a:hover { border-color: var(--p); color: var(--p); }
.pager .cur { background: var(--p); border-color: var(--p); color: #fff; }
.pager .info { font-size: 12px; color: var(--m); border: none; background: none; margin-left: 6px; }

/* ============================================================
   时间轴
   ============================================================ */
.timeline { position: relative; padding-left: 18px; }
.timeline::before {
  content: ''; position: absolute; left: 4px; top: 6px; bottom: 6px;
  width: 2px; background: #ebeef5;
}
.tl-item { position: relative; padding: 0 0 18px 12px; }
.tl-item::before {
  content: ''; position: absolute; left: -18px; top: 6px;
  width: 8px; height: 8px; border-radius: 50%; background: var(--p);
}
.tl-item.g::before { background: var(--g); }
.tl-item.o::before { background: var(--o); }
.tl-item.r::before { background: var(--r); }
.tl-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.tl-time { color: var(--m); font-size: 12px; }
.tl-op { font-size: 12px; color: #606266; }
.tl-body {
  background: #f8f9fb; border-radius: 5px;
  padding: 9px 12px; margin-top: 6px;
  font-size: 13px; white-space: pre-wrap; word-break: break-word;
  color: #4a5568; border-left: 3px solid #dcdfe6;
}
.tl-body.follow { border-left-color: var(--g); background: #f6fbf2; }
.tl-body.log { border-left-color: var(--o); background: #fdfaf4; }
.diff-up { color: var(--g); font-weight: 600; }
.diff-down { color: var(--r); font-weight: 600; }

/* ============================================================
   提示
   ============================================================ */
.alert {
  padding: 10px 14px; border-radius: 5px;
  font-size: 13px; margin-bottom: 14px;
  border-left: 4px solid var(--p); background: #ecf5ff; color: #3a6fa8;
  word-break: break-word;
}
.alert-error { background: #fef0f0; border-color: var(--r); color: #c45656; }
.alert-success { background: #f0f9eb; border-color: var(--g); color: #529b2e; }
.alert-warn { background: #fdf6ec; border-color: var(--o); color: #b88230; }
.empty { text-align: center; padding: 50px 0; color: var(--m); font-size: 13px; }
.empty::before { content: '📭'; display: block; font-size: 36px; margin-bottom: 10px; }

/* ============================================================
   弹窗
   ============================================================ */
.modal-mask {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: none; align-items: center; justify-content: center;
  z-index: 2000; padding: 16px;
  overflow-y: auto;
}
.modal-mask.show { display: flex; }
.modal {
  background: #fff; border-radius: 8px;
  padding: 22px;
  width: 460px; max-width: 100%;
  max-height: 90vh; overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
  margin: auto;
}
.modal h4 { margin: 0 0 16px; font-size: 16px; color: var(--d); }
.modal .form-actions { margin-top: 18px; justify-content: flex-end; }

/* ============================================================
   拨号
   ============================================================ */
.call-btn {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 2px 9px; border-radius: 12px; font-size: 12px;
  background: #f0f9eb; color: var(--g); border: 1px solid #c2e7b0;
  white-space: nowrap;
}
.call-btn:hover { background: var(--g); color: #fff; }

.chk { width: 16px; height: 16px; cursor: pointer; accent-color: var(--p); }

/* ============================================================
   标签页
   ============================================================ */
.tabs {
  display: flex; gap: 4px;
  border-bottom: 1px solid var(--b);
  margin-bottom: 16px; flex-wrap: wrap;
}
.tabs a {
  padding: 8px 16px; font-size: 14px; color: #606266;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs a.on { color: var(--p); border-bottom-color: var(--p); font-weight: 600; }

/* ============================================================
   响应式：大平板横屏 992 - 1199
   ============================================================ */
@media (max-width: 1199px) {
  .grid-5 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ============================================================
   响应式：平板竖屏 / 小窗口 768 - 991
   ============================================================ */
@media (max-width: 991px) {
  /* 侧边栏变抽屉 */
  .sidebar {
    transform: translateX(-100%);
    box-shadow: 2px 0 12px rgba(0,0,0,.15);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-mask { display: block; }
  .main { margin-left: 0; }
  .menu-btn { display: flex; }
  .topbar .title { font-size: 15px; }

  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: 1fr; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-5 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  .form-item { min-width: 0; flex: 1 1 calc(50% - 6px); }
  .form-item.fixed { flex: 0 0 auto; }
}

/* ============================================================
   响应式：手机 <= 767
   ============================================================ */
@media (max-width: 767px) {
  :root { --header-h: 52px; }

  .content { padding: 10px; }
  .card { padding: 12px; margin-bottom: 12px; border-radius: 6px; }
  .card h3 { font-size: 14px; margin-bottom: 12px; }
  .card h3 .extra { font-size: 12px; width: 100%; }

  .grid { gap: 10px; }
  .grid-2, .grid-3, .grid-4, .grid-5 { grid-template-columns: 1fr; }

  .stat { padding: 12px 14px; }
  .stat .value { font-size: 20px; }

  /* 顶部栏精简 */
  .topbar { padding: 0 10px; gap: 6px; }
  .topbar .title { font-size: 14px; }
  .topbar .right .who { display: none; }
  .topbar .right .tag { font-size: 11px; padding: 1px 7px; }
  .topbar .right .btn { padding: 4px 10px; font-size: 12px; }
  .menu-btn { width: 32px; height: 32px; padding: 7px; }

  /* 表单单列 */
  .form-row { flex-direction: column; gap: 10px; align-items: stretch; }
  .form-item, .form-item.fixed { flex: 1 1 100%; min-width: 0; }
  .form-actions { flex-direction: column; }
  .form-actions .btn { width: 100%; justify-content: center; }

  /* 按钮 */
  .btn-group { gap: 6px; }
  .btn-group .btn-sm { padding: 5px 10px; font-size: 12px; }
  .btn { padding: 7px 12px; }

  /* 表格横向滚动 */
  .table-wrap {
    margin: 0 -12px;
    padding: 0 12px;
    border-radius: 6px;
  }
  table { font-size: 12.5px; min-width: 540px; }
  th, td { padding: 8px; }
  td.wrap { max-width: 160px; }

  /* 弹窗底部弹出 */
  .modal-mask { padding: 10px; align-items: flex-end; }
  .modal {
    width: 100%; max-width: 100%;
    border-radius: 12px 12px 0 0;
    padding: 20px 16px;
    max-height: 92vh;
  }
  .modal .form-actions { flex-direction: row; }
  .modal .form-actions .btn { flex: 1; justify-content: center; }

  /* 标签页横向滚动 */
  .tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
    flex-wrap: nowrap;
    margin: 0 -10px 12px;
    padding: 0 10px;
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs a { padding: 8px 14px; font-size: 13px; flex-shrink: 0; }

  /* 时间轴 */
  .tl-body { font-size: 12.5px; padding: 8px 10px; }
  .timeline { padding-left: 14px; }
}

/* ============================================================
   响应式：极小屏 <= 380
   ============================================================ */
@media (max-width: 380px) {
  .topbar .right .tag { display: none; }
  .stat .value { font-size: 18px; }
  table { min-width: 480px; }
}

/* ============================================================
   横屏手机 / 小窗口高度过矮
   ============================================================ */
@media (max-height: 500px) and (orientation: landscape) {
  .modal { max-height: 95vh; }
  .sidebar .logo { height: 40px; line-height: 40px; font-size: 13px; }
  :root { --header-h: 44px; }
}