/* ============================================================
   客户信息管理系统 - 响应式样式（PC / 手机 适配）
   ============================================================ */
:root {
  --primary: #2f6fed;
  --primary-dark: #1e54c7;
  --bg: #f4f6fa;
  --card: #ffffff;
  --text: #243044;
  --text-light: #7a8699;
  --border: #e3e8f0;
  --danger: #e5484d;
  --success: #30a46c;
  --warning: #f5a623;
  --radius: 10px;
  --shadow: 0 2px 12px rgba(36, 48, 68, .08);
}

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

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC",
    "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
}

.hidden { display: none !important; }
.required { color: var(--danger); font-style: normal; }

/* ---------------- 按钮 ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 4px; padding: 9px 18px; border: none; border-radius: 8px;
  font-size: 14px; cursor: pointer; transition: all .18s;
  white-space: nowrap; user-select: none;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline {
  background: #fff; color: var(--primary);
  border: 1px solid var(--primary);
}
.btn-outline:hover { background: #eef4ff; }
.btn-ghost { background: transparent; color: var(--text-light); }
.btn-ghost:hover { color: var(--danger); }
.btn-danger { background: #fdebec; color: var(--danger); }
.btn-sm { padding: 5px 12px; font-size: 13px; }
.btn-block { width: 100%; padding: 12px; font-size: 16px; }
.btn[disabled] { opacity: .6; cursor: not-allowed; }

/* ---------------- 登录页 ---------------- */
.login-wrap {
  position: relative;
  min-height: 100vh; min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #2f6fed 0%, #6a9bff 60%, #8fb7ff 100%);
  padding: 20px;
}
.login-copyright {
  position: absolute; left: 0; right: 0; bottom: 14px;
  text-align: center; font-size: 12px;
  color: rgba(255, 255, 255, .75);
}
.login-card {
  width: 100%; max-width: 400px; background: var(--card);
  border-radius: 16px; box-shadow: 0 16px 48px rgba(0,0,0,.18);
  padding: 40px 32px 28px;
}
.login-logo { text-align: center; margin-bottom: 28px; }
.logo-icon {
  width: 64px; height: 40px; margin: 0 auto 14px;
  background: var(--primary); color: #fff; font-weight: 700;
  border-radius: 10px; display: flex; align-items: center; justify-content: center;
  font-size: 15px; letter-spacing: 1px;
}
.login-card h1 { font-size: 20px; font-weight: 600; }
.login-sub { font-size: 12px; color: var(--text-light); margin-top: 4px; }

/* ---------------- 表单 ---------------- */
.form-field, .form-group { margin-bottom: 16px; }
.form-field label, .form-group label {
  display: block; font-size: 14px; margin-bottom: 6px; font-weight: 500;
}
.form-field input, .form-field select, .form-field textarea,
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 15px; font-family: inherit;
  background: #fff; transition: border .18s, box-shadow .18s;
}
.form-field input:focus, .form-field select:focus, .form-field textarea:focus,
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(47, 111, 237, .15);
}
.error-box, .form-error {
  background: #fdebec; color: var(--danger);
  border-radius: 8px; padding: 9px 12px;
  font-size: 13px; margin-bottom: 14px;
  word-break: break-all;
}
.attr-hint {
  margin-top: 6px; font-size: 12px; color: var(--text-light);
  background: #f6f8fc; border-radius: 6px; padding: 6px 10px;
}
.attr-hint b { color: var(--warning); font-weight: 600; }

/* ---------------- 顶部导航 ---------------- */
.navbar {
  background: var(--card); box-shadow: var(--shadow);
  position: sticky; top: 0; z-index: 50;
}
.navbar-inner {
  max-width: 1200px; margin: 0 auto; padding: 0 20px;
  height: 56px; display: flex; align-items: center; gap: 24px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-badge {
  background: var(--primary); color: #fff; font-size: 12px; font-weight: 700;
  border-radius: 6px; padding: 3px 7px;
}
.brand-text { font-weight: 600; font-size: 16px; }
.nav-links { display: flex; gap: 6px; flex: 1; }
.nav-link {
  text-decoration: none; color: var(--text-light);
  padding: 6px 14px; border-radius: 8px; font-size: 14px;
}
.nav-link.active, .nav-link:hover { color: var(--primary); background: #eef4ff; }
.nav-right { display: flex; align-items: center; gap: 12px; }
.user-name { font-size: 13px; color: var(--text); }

/* 右上角用户信息下拉菜单 */
.user-menu { position: relative; }
.user-menu-btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border); background: #fff;
  border-radius: 20px; padding: 5px 12px; cursor: pointer;
  font-size: 13px; color: var(--text); font-family: inherit;
  max-width: 160px;
}
.user-menu-btn:hover { border-color: var(--primary); }
.user-menu-btn .user-name {
  max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-weight: 500;
}
.user-menu-btn .caret {
  font-size: 10px; color: var(--text-light); transition: transform .18s;
}
.user-menu.open .caret { transform: rotate(180deg); }
.user-dropdown {
  position: absolute; right: 0; top: calc(100% + 6px);
  background: #fff; border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 8px 24px rgba(36, 48, 68, .14);
  min-width: 140px; padding: 6px; z-index: 200;
  animation: pop .15s ease;
}
.user-dropdown button {
  display: block; width: 100%; text-align: left;
  border: none; background: none; cursor: pointer;
  padding: 9px 12px; border-radius: 7px;
  font-size: 14px; color: var(--text); font-family: inherit;
}
.user-dropdown button:hover { background: #f2f6ff; color: var(--primary); }

/* ---------------- 主体 ---------------- */
.main { max-width: 1200px; margin: 0 auto; padding: 20px; }
.page-title { font-size: 20px; margin-bottom: 4px; }
.report-meta { font-size: 13px; color: var(--text-light); margin-bottom: 16px; }

/* 工具栏 */
.toolbar {
  background: var(--card); border-radius: var(--radius);
  padding: 16px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.toolbar-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.search-box { flex: 1; min-width: 200px; }
.search-box input {
  width: 100%; padding: 9px 14px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 14px; background: #fafbfd;
}
.search-box input:focus { outline: none; border-color: var(--primary); background: #fff; }
.select {
  padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; background: #fff; cursor: pointer; max-width: 180px;
}
.toolbar-actions { display: flex; gap: 10px; }
.toolbar-actions .btn.hidden + .btn { flex: 1; }
.toolbar-meta {
  margin-top: 10px; font-size: 13px; color: var(--text-light);
  display: flex; align-items: center; flex-wrap: wrap; gap: 6px;
}
.toolbar-meta b { color: var(--primary); }
.deleted-toggle {
  display: inline-flex; align-items: center; gap: 5px;
  margin-left: 12px; font-size: 13px; color: var(--text-light);
  cursor: pointer; user-select: none;
}
.deleted-toggle input { cursor: pointer; accent-color: var(--primary); }
.page-head { flex: 1; }
.page-head .page-title { margin-bottom: 2px; }
.page-sub { font-size: 13px; color: var(--text-light); }

/* 日志筛选栏 */
.filter-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border);
}
.input-sm {
  padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 13px; background: #fff; font-family: inherit;
}
.input-sm:focus { outline: none; border-color: var(--primary); }
.filter-sep { font-size: 13px; color: var(--text-light); }
.select-sm {
  padding: 7px 10px; font-size: 13px; max-width: none;
  border: 1px solid var(--border); border-radius: 8px;
  background: #fff; cursor: pointer; font-family: inherit;
}

/* ---------------- 表格 ---------------- */
.table-card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.table-scroll {
  overflow-x: auto;
  /* PC 端列表区域高度约束：每页 10/20/50 条时在视口内滚动，不撑高页面 */
  max-height: calc(100vh - 340px);
  min-height: 220px;
  overflow-y: auto;
}
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table thead th {
  position: sticky; top: 0; z-index: 2; background: #f7f9fc;
}
.data-table th, .data-table td {
  padding: 12px 14px; text-align: left;
  border-bottom: 1px solid var(--border);
}
.data-table th {
  background: #f7f9fc; color: var(--text-light); font-weight: 600;
  font-size: 13px; white-space: nowrap;
}
.data-table td { vertical-align: top; }
.td-remark { max-width: 220px; }
.td-remark p { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.row-ops { display: flex; gap: 8px; white-space: nowrap; }
.td-seq { color: var(--text-light); }
.td-time { white-space: nowrap; color: var(--text-light); font-size: 13px; }
.td-ip { white-space: nowrap; color: var(--text-light); font-size: 13px; }
.td-self { font-size: 12px; color: var(--text-light); }
.row-self { background: #f8faff; }
.row-deleted td { opacity: .55; }
.row-deleted td:nth-child(2) { text-decoration: line-through; }
.tag-deleted {
  background: #f1f3f5; color: #868e96; padding: 2px 8px;
  border-radius: 12px; font-size: 12px; white-space: nowrap;
}

/* 角色 / 状态 / 操作类型标签 */
.role-tag, .status-tag, .action-tag {
  display: inline-block; padding: 2px 10px; border-radius: 20px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.role-admin { background: #fff3e0; color: #b25e09; }
.role-user { background: #e7f5ff; color: #1971c2; }
.status-on { background: #e9f7ef; color: #2b8a3e; }
.status-off { background: #fdebec; color: #c92a2a; }
.action-tag { background: #eef1f7; color: #4a5568; }

/* 客户属性标签 */
.attr-tag {
  display: inline-block; padding: 2px 10px; border-radius: 20px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.attr-1 { background: #fdecec; color: #c92a2a; }
.attr-2 { background: #fff3e0; color: #b25e09; }
.attr-3 { background: #fff8db; color: #996c00; }
.attr-4 { background: #e9f7ef; color: #2b8a3e; }
.attr-5 { background: #e7f5ff; color: #1971c2; }
.attr-6 { background: #f3f0ff; color: #6741d9; }
.freq-text { color: var(--warning); font-size: 13px; white-space: nowrap; }

.empty-tip { text-align: center; padding: 60px 20px; color: var(--text-light); }
.empty-icon { font-size: 40px; margin-bottom: 8px; }

/* 移动端卡片（默认隐藏，媒体查询切换） */
.card-list { display: none; }

/* 分页 */
.pagination {
  display: flex; align-items: center; justify-content: space-between;
  gap: 6px; padding: 12px 16px; font-size: 13px; flex-wrap: wrap;
}
.page-meta { color: var(--text-light); }
.page-controls { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.page-size-label {
  display: inline-flex; align-items: center; gap: 4px;
  color: var(--text-light); margin-right: 8px; font-size: 13px;
}
.page-btn {
  min-width: 32px; height: 32px; padding: 0 8px;
  border: 1px solid var(--border); background: #fff;
  border-radius: 6px; cursor: pointer; font-size: 13px;
}
.page-btn:hover:not([disabled]) { border-color: var(--primary); color: var(--primary); }
.page-btn.active, .page-btn.current { background: var(--primary); color: #fff; border-color: var(--primary); }
.page-btn[disabled] { opacity: .5; cursor: default; }
.page-info { color: var(--text-light); margin: 0 6px; }
.load-more-tip {
  text-align: center; padding: 12px; color: var(--text-light); font-size: 13px;
}

/* ---------------- 弹窗 ---------------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(20, 28, 44, .5);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 16px;
}
.modal {
  background: #fff; border-radius: 14px; width: 100%; max-width: 520px;
  max-height: 92vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.25);
  animation: pop .18s ease;
}
.modal-sm { max-width: 400px; }
@keyframes pop { from { transform: scale(.94); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: #fff; border-radius: 14px 14px 0 0;
}
.modal-header h3 { font-size: 16px; }
.modal-close {
  border: none; background: none; font-size: 24px; line-height: 1;
  color: var(--text-light); cursor: pointer; padding: 2px 6px;
}
.modal form { padding: 20px; }
/* 弹窗标题：与窗口边缘保持合理间距 */
.modal-title {
  padding: 18px 20px 4px;
  font-size: 16px;
  font-weight: 600;
}
.modal-title + form { padding-top: 12px; }

/* ---------------- 客户详情查看弹窗 ---------------- */
.detail-list { padding: 6px 20px 4px; }
.detail-row {
  display: flex; gap: 12px; padding: 10px 0;
  border-bottom: 1px dashed var(--border); font-size: 14px;
}
.detail-row:last-child { border-bottom: none; }
.detail-label {
  flex-shrink: 0; width: 96px; color: var(--text-light); font-size: 13px;
  padding-top: 1px;
}
.detail-val { flex: 1; word-break: break-all; }

/* ---------------- 页面水印 ---------------- */
.watermark {
  position: fixed; inset: 0; z-index: 999;
  pointer-events: none; background-repeat: repeat;
}
.modal-footer {
  display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px;
}

/* ---------------- 统计页 ---------------- */
.stat-cards {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 14px; margin-bottom: 16px;
}
.stat-card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px; text-align: center;
}
.stat-num { font-size: 30px; font-weight: 700; color: var(--primary); }
.stat-label { font-size: 13px; color: var(--text-light); margin-top: 4px; }

.chart-card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px; margin-bottom: 16px;
}
.card-title { font-size: 15px; margin-bottom: 16px; }
.chart-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px;
}
.chart-grid .chart-card { margin-bottom: 0; }

/* 条形图（纯CSS实现，无外部依赖） */
.bar-item { margin-bottom: 14px; }
.bar-head {
  display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 5px;
}
.bar-head b { font-weight: 600; }
.bar-track { background: #eef1f7; border-radius: 6px; height: 14px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 6px; background: var(--primary); min-width: 2px; transition: width .4s; }
.freq-table { font-size: 14px; }
.freq-table td { padding: 10px 12px; }

/* 提示气泡 */
.toast {
  position: fixed; top: 70px; left: 50%; transform: translateX(-50%);
  background: rgba(36, 48, 68, .92); color: #fff;
  padding: 10px 22px; border-radius: 8px; font-size: 14px;
  z-index: 200; animation: pop .2s ease; max-width: 86vw; text-align: center;
}
.toast-success { background: rgba(25, 108, 68, .95); }
.toast-error { background: rgba(200, 40, 45, .95); }

/* ---------------- 关于页 ---------------- */
.about-card { padding: 36px 28px; }
.about-logo { text-align: center; margin-bottom: 28px; }
.about-badge {
  display: inline-block; background: var(--primary); color: #fff;
  font-weight: 700; font-size: 16px; letter-spacing: 1px;
  border-radius: 12px; padding: 10px 20px; margin-bottom: 14px;
}
.about-logo h2 { font-size: 20px; }
.about-company { color: var(--text-light); font-size: 14px; margin-top: 6px; }
.about-section { margin-bottom: 24px; }
.about-section .data-table td:first-child { color: var(--text-light); }
.about-text { font-size: 14px; color: var(--text); margin-bottom: 10px; }

/* ---------------- 页脚版权 ---------------- */
.page-footer {
  text-align: center; padding: 20px 16px 28px;
  font-size: 12px; color: var(--text-light);
}

/* ============================================================
   响应式断点：移动端（<=768px）
   ============================================================ */
@media (max-width: 768px) {
  body { font-size: 14px; }

  .navbar-inner { padding: 0 12px; gap: 10px; height: 52px; }
  .brand-text { display: none; }
  .nav-links { gap: 0; overflow-x: auto; }
  .nav-link { padding: 6px 10px; font-size: 13px; white-space: nowrap; }
  /* 移动端同样显示右上角用户名（点击弹出退出菜单） */
  .user-menu-btn { max-width: 120px; padding: 4px 10px; }
  .user-menu-btn .user-name { max-width: 72px; }

  .main { padding: 12px; }

  .toolbar { padding: 12px; }
  .toolbar-row { flex-direction: column; align-items: stretch; }
  .search-box input { padding: 11px 14px; }
  .select { width: 100%; max-width: none; }
  /* 新增 / 导出按钮同一行（符合移动端操作规范），单个按钮时自动占满整行 */
  .toolbar-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .toolbar-actions .btn { padding: 11px; }
  .toolbar-actions .btn:only-child { grid-column: 1 / -1; }
  .deleted-toggle { margin-left: 0; }

  /* 表格切换为卡片 + 左滑操作 */
  .table-scroll { display: none; }
  .card-list { display: block; padding: 12px; }
  .mobile-card {
    position: relative; overflow: hidden;
    border: 1px solid var(--border); border-radius: 10px;
    margin-bottom: 10px; background: #e9edf3;
  }
  /* 左滑露出的操作按钮区（编辑/删除），固定在卡片右侧 */
  .mc-actions {
    position: absolute; right: 0; top: 0; bottom: 0;
    width: 132px; display: flex;
  }
  .mc-btn {
    flex: 1; border: none; color: #fff; font-size: 14px;
    cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent;
  }
  .mc-edit { background: var(--primary); }
  .mc-del { background: var(--danger); }
  /* 卡片内容层（跟随手指左滑）：
     touch-action: pan-y 让浏览器只处理纵向滚动，横向手势完全由脚本接管，
     避免滑动时页面整体跟随移动 */
  .mc-content {
    position: relative; z-index: 1; background: #fff;
    padding: 14px; will-change: transform;
    touch-action: pan-y;
    box-shadow: 2px 0 8px rgba(36, 48, 68, .08);
  }
  .mc-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
  .mc-seq {
    display: inline-flex; min-width: 24px; height: 24px;
    align-items: center; justify-content: center;
    background: #eef4ff; color: var(--primary);
    border-radius: 6px; font-size: 12px; font-weight: 600;
  }
  .mc-name { font-size: 16px; font-weight: 600; }
  .mc-row { display: flex; gap: 8px; margin-top: 6px; font-size: 13px; }
  .mc-label { color: var(--text-light); flex-shrink: 0; }
  .mc-val { word-break: break-all; }

  /* 移动端不显示分页（改为滚动加载） */
  .pagination { display: none; }

  .stat-cards { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-card { padding: 14px; }
  .stat-num { font-size: 24px; }
  .chart-grid { grid-template-columns: 1fr; }

  .modal form { padding: 14px; }
  .modal-footer .btn { flex: 1; padding: 11px; }
  .login-card { padding: 32px 22px 22px; }

  .filter-bar .input-sm, .filter-bar .select-sm { flex: 1; min-width: 120px; }
}

/* 超小屏 */
@media (max-width: 400px) {
  .stat-cards { grid-template-columns: 1fr 1fr; }
}
