/* ============================================================================
 * ui-crm.css — 三后台（总部 /admin、代理商 /agent、交付中心 /jiaofu）公共 CRM 组件样式
 *
 * 设计基线：提炼自总部后台「客户 CRM」页，统一表格、分页器、工具栏、按钮、
 *   弹窗、空状态、统计卡、状态标签的视觉规范。
 *
 * 约束（务必遵守，改动前先读）：
 *   1. 所有色值/圆角/间距一律使用 admin.css 已定义的 CSS 变量，严禁硬编码色值，
 *      否则深色模式（html[data-theme=dark]）不会跟随。
 *   2. 本文件必须在 admin.css 之后引入，用于覆盖历史重复规则。
 *   3. 桌面端优先；窄屏下由表格自身横向滚动（.ui-table-wrap），
 *      绝不允许整页横向滚动。
 * ========================================================================== */

/* ---------------------------------------------------------------------------
 * 1. 纵向堆叠容器
 * 用途：页面级区块自上而下排列。修复「容器被误挂网格类导致子块横向铺开」类问题
 *      （如代理商「我的报表」原挂 .report-cards 网格）。
 * 职责分离：容器只管纵向堆叠，内部卡片区自行决定是否网格。
 * ------------------------------------------------------------------------ */
.ui-stack { display: flex; flex-direction: column; gap: 14px; width: 100%; min-width: 0; }
.ui-stack > * { min-width: 0; }
.ui-stack-sm { gap: 10px; }

/* ---------------------------------------------------------------------------
 * 2. 工具栏 .ui-pane-head
 * 左：标题（可带 Material 图标）；右：操作区（按钮组 + 搜索框）
 * ------------------------------------------------------------------------ */
.ui-pane-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 12px; min-width: 0;
}
.ui-pane-title {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 16px; font-weight: 700; color: var(--brand); margin: 0;
  white-space: nowrap;
}
.ui-pane-title .msr {
  font-size: 17px; line-height: 1;
  background: #17a07f;  /* 亮青绿圆底 + 微投影 */
  color: #fff; border-radius: 8px; width: 28px; height: 28px;
  display: inline-flex; align-items: center; justify-content: center;
  box-shadow: 0 1px 3px rgba(0,0,0,.18);
}
.ui-pane-title .msr:hover { filter: brightness(1.12); }
.ui-pane-tools {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-left: auto; min-width: 0;
}
.ui-search {
  padding: 9px 13px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 13px; width: 250px; max-width: 44vw; outline: none;
  background: var(--card); color: var(--ink); transition: .15s;
  box-sizing: border-box;
}
.ui-search:focus { border-color: var(--brand-accent); box-shadow: 0 0 0 3px rgba(22,160,133,.15); }
.ui-search::placeholder { color: var(--muted); }
.ui-search-block { width: 100%; max-width: 100%; }

@media (max-width: 720px) {
  .ui-pane-head { flex-direction: column; align-items: stretch; }
  .ui-pane-tools { margin-left: 0; }
  .ui-search { width: 100%; max-width: 100%; }
}

/* ---------------------------------------------------------------------------
 * 3. 数据表格 .ui-table
 * 表头品牌绿底白字 + 吸顶；单元格细线分隔；行悬停浅绿底；支持列宽拖拽手柄。
 * ------------------------------------------------------------------------ */
.ui-table-wrap {
  width: 100%; min-width: 0; overflow-x: auto; overflow-y: visible;
  border: 1px solid var(--line); border-radius: 12px; background: var(--card);
  -webkit-overflow-scrolling: touch;
}
/* 需要固定高度滚动区（长列表）时叠加此类，配合 --ui-table-maxh */
.ui-table-wrap.scroll-y { overflow-y: auto; max-height: var(--ui-table-maxh, 560px); }

.ui-table {
  width: 100%; border-collapse: separate; border-spacing: 0;
  font-size: 13px; color: var(--ink); table-layout: auto;
}
.ui-table.fixed { table-layout: fixed; }

.ui-table thead th {
  background: var(--brand); color: #fff; font-weight: 700; font-size: 12.5px;
  padding: 9px 12px; text-align: left; white-space: nowrap;
  position: relative; user-select: none; border-bottom: 1px solid var(--brand-dark);
}
/* 表头吸顶：滚动时保持可见 */
.ui-table.sticky-head thead th { position: sticky; top: 0; z-index: 5; }
.ui-table thead th:first-child { border-top-left-radius: 11px; }
.ui-table thead th:last-child { border-top-right-radius: 11px; }

.ui-table tbody td {
  padding: 9px 12px; border-bottom: 1px solid var(--line);
  vertical-align: middle; word-break: break-word;
}
.ui-table tbody tr:last-child td { border-bottom: 0; }
.ui-table tbody tr:hover td { background: var(--brand-soft); }
.ui-table td.num, .ui-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.ui-table td.ctr, .ui-table th.ctr { text-align: center; }
.ui-table td.nowrap, .ui-table th.nowrap { white-space: nowrap; }
.ui-table td.muted, .ui-table .muted { color: var(--muted); }
/* 操作列：按钮不换行、间距统一 */
.ui-table td .ui-ops { display: inline-flex; gap: 6px; flex-wrap: wrap; }

/* 列宽拖拽手柄：位于表头右边缘 */
.ui-col-resizer {
  position: absolute; top: 0; right: 0; width: 6px; height: 100%;
  cursor: col-resize; user-select: none; touch-action: none;
  background: transparent; transition: background .15s;
}
.ui-col-resizer:hover, .ui-col-resizer.dragging { background: rgba(255,255,255,.35); }
body.ui-col-resizing { cursor: col-resize !important; user-select: none !important; }

/* ---------------------------------------------------------------------------
 * 4. 统一分页器 .ui-pager
 * 单行三栏：左统计文案 / 中页码翻页（居中）/ 右每页条数（靠右）
 * 关键：中间区 flex:1 1 auto + min-width:0，防止页码过多把整页撑出横向滚动条。
 * ------------------------------------------------------------------------ */
.ui-pager {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: center;
  margin: 12px auto 0; padding: 9px 12px; max-width: 100%;
  width: fit-content; min-width: 0;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
}
.ui-pager-info {
  font-size: 13px; color: var(--muted); white-space: nowrap; flex: 0 0 auto;
}
.ui-pager-pages {
  flex: 0 1 auto; min-width: 0;
  display: flex; align-items: center; justify-content: center;
  gap: 5px; flex-wrap: wrap;
}
.ui-pager-size {
  margin-left: auto; flex-shrink: 0;
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px; color: var(--muted); white-space: nowrap;
}
.ui-pager-size select {
  border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px;
  background: var(--card); color: var(--ink); font-size: 12.5px; cursor: pointer;
}
.ui-pg-btn {
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 8px; padding: 5px 10px; min-width: 32px;
  font-size: 12.5px; cursor: pointer; transition: .15s;
}
.ui-pg-btn:hover:not(:disabled):not(.on) {
  background: var(--brand-soft); border-color: var(--brand-accent); color: var(--brand);
}
.ui-pg-btn.on {
  background: var(--brand); color: #fff; border-color: var(--brand); font-weight: 700;
}
.ui-pg-btn:disabled { opacity: .4; cursor: not-allowed; }
.ui-pg-gap { color: var(--muted); padding: 0 2px; font-size: 12.5px; }

@media (max-width: 720px) {
  .ui-pager { flex-wrap: wrap; }
  .ui-pager-pages { order: 3; width: 100%; justify-content: flex-start; }
  .ui-pager-size { order: 2; }
}

/* ---------------------------------------------------------------------------
 * 5. 按钮 .ui-btn（与 admin.css 的 .btn 保持一致口径，供新页面直接使用）
 * ------------------------------------------------------------------------ */
.ui-btn {
  background: var(--brand-accent); color: #fff; border: 0; border-radius: 10px;
  padding: 11px 16px; font-size: 14px; cursor: pointer; transition: .16s;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  white-space: nowrap; line-height: 1.2;
}
.ui-btn:hover { background: var(--ok); box-shadow: 0 2px 8px rgba(22,160,133,.28); }
.ui-btn:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }
.ui-btn.pri { background: var(--brand); }
.ui-btn.pri:hover { background: var(--brand-accent); }
.ui-btn.ghost { background: var(--card); color: var(--ink); border: 1px solid var(--line); }
.ui-btn.ghost:hover { background: var(--brand-soft); border-color: var(--brand-accent); color: var(--brand); }
.ui-btn.danger { background: var(--danger); }
.ui-btn.danger:hover { background: #dc2626; }
.ui-btn.sm { padding: 7px 12px; font-size: 13px; border-radius: 9px; }
.ui-btn.block { width: 100%; }

/* ---------------------------------------------------------------------------
 * 6. 弹窗 .ui-modal-mask / .ui-modal-box
 * ------------------------------------------------------------------------ */
.ui-modal-mask {
  position: fixed; inset: 0; z-index: 9000;
  background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center; padding: 16px;
  animation: uiFadeIn .16s ease;
}
@keyframes uiFadeIn { from { opacity: 0; } to { opacity: 1; } }
.ui-modal-box {
  background: var(--card); color: var(--ink);
  border-radius: 16px; padding: 22px; width: 440px;
  max-width: 92vw; max-height: 90vh; overflow: auto;
  box-shadow: 0 18px 48px rgba(0,0,0,.22);
  animation: uiPopIn .18s cubic-bezier(.22,1,.36,1);
  box-sizing: border-box;
}
@keyframes uiPopIn { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }
.ui-modal-box h3 { margin: 0 0 14px; font-size: 16px; font-weight: 700; color: var(--brand); }
.ui-modal-body { min-width: 0; }
.ui-modal-foot {
  display: flex; justify-content: flex-end; gap: 8px;
  margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line);
}

/* 弹窗内表单字段 */
.ui-field { margin-bottom: 12px; }
.ui-field > label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.ui-field input, .ui-field select, .ui-field textarea {
  width: 100%; box-sizing: border-box;
  padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px;
  font-size: 14px; background: var(--card); color: var(--ink);
  font-family: inherit;
}
.ui-field textarea { resize: vertical; min-height: 84px; }
.ui-field input:focus, .ui-field select:focus, .ui-field textarea:focus {
  outline: none; border-color: var(--brand-accent); box-shadow: 0 0 0 3px rgba(22,160,133,.12);
}
.ui-field input:disabled, .ui-field select:disabled {
  background: var(--surface-2); color: var(--muted); cursor: not-allowed;
}

/* ---------------------------------------------------------------------------
 * 7. 空状态 .ui-empty
 * ------------------------------------------------------------------------ */
.ui-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; padding: 40px 20px; text-align: center; color: var(--muted);
}
.ui-empty .ui-empty-icon { font-size: 40px; line-height: 1; opacity: .45; }
.ui-empty .ui-empty-text { font-size: 14px; }
.ui-empty .ui-empty-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-top: 2px; }

/* ---------------------------------------------------------------------------
 * 8. 统计卡 .ui-stat-grid
 * ------------------------------------------------------------------------ */
.ui-stat-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px; width: 100%; min-width: 0;
}
.ui-stat-card {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px 12px; text-align: center; min-width: 0; transition: .16s;
}
.ui-stat-card:hover { border-color: var(--brand-accent); box-shadow: 0 2px 10px rgba(16,24,40,.06); }
.ui-stat-card b {
  display: block; font-size: 21px; font-weight: 800; color: var(--brand);
  line-height: 1.25; word-break: break-all;
}
.ui-stat-card span { display: block; font-size: 11.5px; color: var(--muted); margin-top: 3px; }

/* ---------------------------------------------------------------------------
 * 9. 状态标签 .ui-tag
 * ------------------------------------------------------------------------ */
.ui-tag {
  display: inline-block; padding: 2px 8px; border-radius: 6px;
  font-size: 11.5px; font-weight: 500; white-space: nowrap;
  background: var(--brand-soft); color: var(--brand);
}
.ui-tag.success { background: rgba(22,163,74,.12); color: var(--ok); }
.ui-tag.warn    { background: rgba(245,158,11,.14); color: #b45309; }
.ui-tag.danger  { background: rgba(239,68,68,.12); color: var(--danger); }
.ui-tag.info    { background: rgba(47,111,237,.12); color: #2f6fed; }
.ui-tag.muted   { background: rgba(156,163,175,.16); color: var(--muted); }

/* ---------------------------------------------------------------------------
 * 10. 卡片 .ui-card / 分节标题
 * ------------------------------------------------------------------------ */
.ui-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 16px; min-width: 0;
}
.ui-card-title {
  display: flex; align-items: center; gap: 6px;
  font-weight: 700; font-size: 14px; color: var(--brand); margin-bottom: 10px;
}
/* 单行文字摘要条（如 VIP 新增汇总） */
.ui-summary-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 11px 14px; background: var(--brand-soft); border: 1px solid var(--line);
  border-radius: 12px; font-size: 13px; color: var(--ink);
}
.ui-summary-bar b { color: var(--brand); font-weight: 700; }

/* ---------------------------------------------------------------------------
 * 11. 子 Tab 切换条 .ui-subtabs（代理商「客户消息」会话列表 / 发消息）
 * ------------------------------------------------------------------------ */
.ui-subtabs {
  display: flex; align-items: center; gap: 4px;
  border-bottom: 1px solid var(--line); margin-bottom: 14px; min-width: 0;
  overflow-x: auto;
}
.ui-subtab {
  position: relative; border: 0; background: transparent; cursor: pointer;
  padding: 10px 16px; font-size: 14px; font-weight: 600; color: var(--muted);
  white-space: nowrap; transition: color .16s;
}
.ui-subtab::after {
  content: ""; position: absolute; left: 12px; right: 12px; bottom: -1px;
  height: 2px; border-radius: 2px; background: var(--brand-accent);
  transform: scaleX(0); transition: transform .16s ease;
}
.ui-subtab:hover { color: var(--brand); }
.ui-subtab.on { color: var(--brand); }
.ui-subtab.on::after { transform: scaleX(1); }
.ui-subtab .ui-badge {
  display: inline-block; margin-left: 5px; min-width: 16px; padding: 0 5px;
  border-radius: 9px; background: var(--danger); color: #fff;
  font-size: 11px; font-weight: 700; line-height: 16px; text-align: center;
}
.ui-subpane[hidden] { display: none !important; }

/* ---------------------------------------------------------------------------
 * 12. Toast 轻提示
 * ------------------------------------------------------------------------ */
.ui-toast-wrap {
  position: fixed; left: 50%; top: 22px; transform: translateX(-50%);
  z-index: 9500; display: flex; flex-direction: column; gap: 8px;
  align-items: center; pointer-events: none;
}
.ui-toast {
  background: rgba(31,42,55,.94); color: #fff; border-radius: 10px;
  padding: 10px 18px; font-size: 13.5px; max-width: 82vw;
  box-shadow: 0 8px 24px rgba(0,0,0,.22);
  animation: uiToastIn .18s ease;
}
.ui-toast.err { background: rgba(239,68,68,.95); }
.ui-toast.ok  { background: rgba(22,163,74,.95); }
.ui-toast.hide { opacity: 0; transform: translateY(-8px); transition: .22s ease; }
@keyframes uiToastIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: none; } }
