/* ============================================================
   约签签 CRM v3 — AI 驾驶舱
   Tailwind CSS palette: Emerald 600 (brand) + Slate (neutral)
   Light theme — Clean, professional dashboard
   ============================================================ */

:root {
  /* ── Surfaces (Slate) ── */
  --page:          #f1f5f9;   /* Slate 100 */
  --surface:       #ffffff;   /* White */
  --surface-alt:   #f8fafc;   /* Slate 50 */
  --surface-hover: #e2e8f0;   /* Slate 200 */
  --overlay:       rgba(15,23,42,0.40);

  /* ── Borders (Slate) ── */
  --border:        #e2e8f0;   /* Slate 200 */
  --border-strong: #cbd5e1;   /* Slate 300 */
  --border-focus:  #94a3b8;   /* Slate 400 */

  /* ── Ink (Slate) ── */
  --ink-primary:   #0f172a;   /* Slate 900 */
  --ink-secondary: #475569;   /* Slate 600 */
  --ink-muted:     #94a3b8;   /* Slate 400 */

  /* ── Brand: Emerald ── */
  --brand:         #059669;   /* Emerald 600 */
  --brand-light:   #10b981;   /* Emerald 500 */
  --brand-dark:    #047857;   /* Emerald 700 */
  --brand-bg:      rgba(5,150,105,0.08);
  --brand-bg-strong: rgba(5,150,105,0.14);

  /* ── Accent colors (Tailwind 500/600 series) ── */
  --blue:          #2563eb;   /* Blue 600 — AI */
  --blue-bg:       rgba(37,99,235,0.08);
  --amber:         #d97706;   /* Amber 600 — handoff / warning */
  --amber-bg:      rgba(217,119,6,0.08);
  --rose:          #e11d48;   /* Rose 600 — critical / redline */
  --rose-bg:       rgba(225,29,72,0.08);
  --sky:           #0284c7;   /* Sky 600 — info */
  --sky-bg:        rgba(2,132,199,0.08);
  --violet:        #7c3aed;   /* Violet 600 — accent */
  --violet-bg:     rgba(124,58,237,0.08);
  --orange:        #ea580c;   /* Orange 600 — attention */
  --orange-bg:     rgba(234,88,12,0.08);
  --cyan:          #0891b2;   /* Cyan 600 — teal */
  --cyan-bg:       rgba(8,145,178,0.08);
  --gold:          #b45309;   /* Amber 700 — ranking/accent */

  /* ── Chart categorical (Tailwind 500s, ordered for CVD safety) ── */
  --cat-1: #3b82f6;   /* blue */
  --cat-2: #f59e0b;   /* amber */
  --cat-3: #10b981;   /* emerald (brand) */
  --cat-4: #8b5cf6;   /* violet */
  --cat-5: #f97316;   /* orange */
  --cat-6: #06b6d4;   /* cyan */
  --cat-7: #ec4899;   /* pink */
  --cat-8: #e11d48;   /* rose */

  /* ── Status (fixed) ── */
  --status-good:     #059669;   /* Emerald 600 */
  --status-warning:  #d97706;   /* Amber 600 */
  --status-serious:  #ea580c;   /* Orange 600 */
  --status-critical: #e11d48;   /* Rose 600 */

  /* ── Chart chrome ── */
  --chart-gridline:  #e2e8f0;   /* Slate 200 */
  --chart-baseline:  #cbd5e1;   /* Slate 300 */

  /* ── Geometry ── */
  --sidebar-w: 232px;
  --radius-sm: 6px;
  --radius:    10px;
  --radius-lg: 14px;
  --gap:       16px;
  --gap-sm:    10px;
  --gap-xs:    6px;
  --transition: 180ms ease;

  /* ── Shadows ── */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.06);
  --shadow:    0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);

  /* ── Typography ── */
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', system-ui, sans-serif;
  --font-mono: 'SF Mono', 'Cascadia Code', 'Fira Code', monospace;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; }
body {
  font-family: var(--font);
  background: var(--page);
  color: var(--ink-primary);
  min-height: 100vh;
  display: flex;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  width: var(--sidebar-w); min-width: var(--sidebar-w);
  height: 100vh; position: fixed; left: 0; top: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  z-index: 100; overflow-y: auto;
}
.sidebar-brand {
  padding: 22px 20px 18px;
  font-size: 1.15rem; font-weight: 700;
  color: var(--brand);
  letter-spacing: 0.01em;
  display: flex; align-items: center; gap: 8px;
  border-bottom: 1px solid var(--border);
}
.sidebar-brand span {
  color: var(--ink-muted); font-weight: 400;
  font-size: 0.72rem; letter-spacing: 0.04em;
  text-transform: uppercase;
}

.sidebar-nav { flex: 1; padding: 10px 12px; }
.sidebar-nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--radius);
  color: var(--ink-secondary); text-decoration: none;
  font-size: 0.875rem; font-weight: 500;
  transition: all var(--transition);
  margin-bottom: 2px; position: relative;
}
.sidebar-nav a:hover { background: var(--surface-hover); color: var(--ink-primary); }
.sidebar-nav a.active { background: var(--brand-bg); color: var(--brand); }
.sidebar-nav a.active::before {
  content: ''; position: absolute; left: 0; top: 8px; bottom: 8px;
  width: 3px; border-radius: 0 2px 2px 0; background: var(--brand);
}
.sidebar-nav a .icon { font-size: 1.05rem; width: 22px; text-align: center; }
.sidebar-nav a .badge-count {
  margin-left: auto;
  background: var(--surface-hover);
  padding: 2px 8px; border-radius: 10px;
  font-size: 0.68rem; font-weight: 600;
  color: var(--ink-muted); min-width: 22px; text-align: center;
  font-variant-numeric: tabular-nums;
}
.sidebar-nav a.active .badge-count {
  background: var(--brand-bg-strong); color: var(--brand);
}

.sidebar-divider { height: 1px; background: var(--border); margin: 12px 8px; }

.sidebar-footer {
  padding: 14px 16px 18px; border-top: 1px solid var(--border);
  font-size: 0.73rem; color: var(--ink-muted);
}

/* Pulse */
.pulse {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--status-good); display: inline-block;
  animation: pulse-ring 2s ease-out infinite; margin-right: 6px;
}
@keyframes pulse-ring {
  0%   { box-shadow: 0 0 0 0 rgba(16,185,129,0.5); }
  70%  { box-shadow: 0 0 0 6px rgba(16,185,129,0); }
  100% { box-shadow: 0 0 0 0 rgba(16,185,129,0); }
}

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.main { margin-left: var(--sidebar-w); flex: 1; min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 50;
  background: rgba(255,255,255,0.85); backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 13px 28px;
  display: flex; align-items: center; gap: 12px;
}
.topbar h2 { font-size: 1.05rem; font-weight: 600; color: var(--ink-primary); }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }

.content { flex: 1; padding: 24px 28px; overflow-y: auto; }

/* ============================================================
   KPI CARDS
   ============================================================ */
.kpi-grid {
  display: grid; grid-template-columns: repeat(5, 1fr);
  gap: var(--gap); margin-bottom: 24px;
}
.kpi-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 20px 22px;
  transition: all var(--transition); position: relative; overflow: hidden;
}
.kpi-card::after {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 1px;
  background: linear-gradient(90deg, transparent, rgba(0,0,0,0.04), transparent);
}
.kpi-card:hover {
  border-color: var(--border-strong); box-shadow: var(--shadow);
  transform: translateY(-1px);
}
.kpi-card .kpi-label {
  font-size: 0.7rem; color: var(--ink-muted);
  text-transform: uppercase; letter-spacing: 0.08em; font-weight: 500;
  margin-bottom: 10px;
}
.kpi-card .kpi-value {
  font-size: 2rem; font-weight: 700; color: var(--ink-primary);
  line-height: 1; font-variant-numeric: tabular-nums;
}
.kpi-card .kpi-sub {
  font-size: 0.73rem; color: var(--ink-secondary); margin-top: 8px;
  display: flex; align-items: center; gap: 4px;
}
.kpi-card .kpi-sub::before {
  content: ''; display: inline-block;
  width: 6px; height: 6px; border-radius: 50%; background: currentColor;
}

/* KPI accent left-border strips */
.kpi-card.accent-1 { border-left: 3px solid var(--blue); }     /* AI */
.kpi-card.accent-2 { border-left: 3px solid var(--amber); }    /* handoff */
.kpi-card.accent-3 { border-left: 3px solid var(--brand); }    /* growth */
.kpi-card.accent-4 { border-left: 3px solid var(--violet); }   /* attention */
.kpi-card.accent-5 { border-left: 3px solid var(--sky); }      /* info */

/* ============================================================
   CHART CARDS
   ============================================================ */
.chart-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 22px; margin-bottom: var(--gap);
}
.chart-card h3 {
  font-size: 0.85rem; font-weight: 600; color: var(--ink-secondary);
  margin-bottom: 18px; display: flex; align-items: center; gap: 8px;
  letter-spacing: 0.02em;
}
.chart-card h3 .dot {
  width: 8px; height: 8px; border-radius: 2px; background: var(--brand);
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--gap); }

/* ============================================================
   FILTERS & INPUTS
   ============================================================ */
.filter-bar {
  display: flex; flex-wrap: wrap; gap: var(--gap-xs);
  margin-bottom: 14px; align-items: center;
}
.filter-bar input, .filter-bar select {
  background: var(--surface); color: var(--ink-primary);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 8px 12px; font-size: 0.82rem; font-family: var(--font);
  outline: none; transition: border var(--transition), box-shadow var(--transition);
}
.filter-bar input:focus, .filter-bar select:focus {
  border-color: var(--brand); box-shadow: 0 0 0 3px rgba(16,185,129,0.15);
}
.filter-bar input { min-width: 220px; }
.filter-bar input::placeholder { color: var(--ink-muted); }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface);
  color: var(--ink-secondary); cursor: pointer;
  font-size: 0.8rem; font-weight: 500; font-family: var(--font);
  transition: all var(--transition); white-space: nowrap; text-align: center;
}
.btn:hover { background: var(--surface-hover); color: var(--ink-primary); border-color: var(--border-strong); }
.btn-primary { background: var(--brand); color: #fff; border-color: var(--brand); font-weight: 600; }
.btn-primary:hover { background: var(--brand-light); border-color: var(--brand-light); box-shadow: 0 0 0 3px rgba(16,185,129,0.2); }

/* ============================================================
   TABLE
   ============================================================ */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left; padding: 10px 14px; font-size: 0.7rem; font-weight: 600;
  color: var(--ink-muted); text-transform: uppercase; letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border); white-space: nowrap;
  background: var(--surface); position: sticky; top: 0;
}
tbody td {
  padding: 10px 14px; font-size: 0.84rem;
  border-bottom: 1px solid var(--border); color: var(--ink-secondary);
}
tbody tr { transition: background var(--transition); cursor: pointer; }
tbody tr:hover td { background: var(--surface-hover); }
tbody tr.selected td { background: var(--brand-bg); }
td.name-cell { color: var(--ink-primary); font-weight: 500; }

/* ============================================================
   BADGES
   ============================================================ */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 3px;
  font-size: 0.68rem; font-weight: 600; letter-spacing: 0.02em; line-height: 1.5;
}
.badge-A { background: var(--sky-bg);    color: var(--sky); }
.badge-B { background: var(--blue-bg);   color: var(--blue); }
.badge-C { background: var(--surface-hover); color: var(--ink-muted); }
.badge-D { background: var(--rose-bg);   color: var(--rose); }
.badge-ai { background: var(--blue-bg);  color: var(--blue); }
.badge-human { background: var(--amber-bg); color: var(--amber); }

/* ============================================================
   CRM SPLIT (customers)
   ============================================================ */
.crm-split {
  display: grid; grid-template-columns: var(--split-width,380px) 6px 1fr;
  gap: 0; height: calc(100vh - 130px);
}
.crm-split-handle {
  width: 6px; cursor: col-resize; background: transparent;
  transition: background 0.2s; z-index: 10; user-select: none;
}
.crm-split-handle:hover,.crm-split-handle.dragging{background:var(--brand)}
.crm-list-panel{margin-right:6px}
.crm-detail-panel{margin-left:6px}
.crm-list-panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); display: flex; flex-direction: column; overflow: hidden;
}
.crm-list-header {
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  font-weight: 600; font-size: 0.82rem; color: var(--ink-secondary);
  display: flex; justify-content: space-between; align-items: center;
}
.crm-list-scroll { flex: 1; overflow-y: auto; }
.crm-list-item {
  padding: 13px 18px; border-bottom: 1px solid var(--border);
  cursor: pointer; transition: all var(--transition);
}
.crm-list-item:hover { background: var(--surface-hover); }
.crm-list-item.selected {
  background: var(--brand-bg); border-left: 3px solid var(--brand);
  padding-left: 15px;
}
.crm-list-item { display: flex; gap: 10px; align-items: flex-start; }
.crm-list-item .li-avatar {
  width: 34px; height: 34px; flex: 0 0 34px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 0.85rem; font-weight: 700; user-select: none;
}
.crm-list-item .li-body { flex: 1; min-width: 0; }
.crm-list-item .li-name { font-weight: 600; color: var(--ink-primary); font-size: 0.88rem; }
.crm-list-item .li-phone {
  font-family: var(--font-mono); font-size: 0.74rem; color: var(--ink-secondary);
  margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.crm-list-item .li-company { font-size: 0.78rem; color: var(--ink-secondary); margin-top: 2px; }
.crm-list-item .li-meta {
  font-size: 0.72rem; color: var(--ink-muted); margin-top: 4px;
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
}

.crm-detail-panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); overflow: hidden; display: flex; flex-direction: column;
  min-height: 0;
}
.crm-split > * { min-height: 0; overflow: hidden; }
.crm-detail-header { padding: 18px 22px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.crm-detail-header h2 { font-size: 1.1rem; font-weight: 600; }
.crm-detail-header .subtitle {
  font-size: 0.78rem; color: var(--ink-muted); margin-top: 4px;
  font-family: var(--font-mono);
}
.crm-detail-info { flex-shrink: 0; overflow-y: auto; }
.crm-detail-vsplit {
  height: 8px; flex-shrink: 0; cursor: row-resize;
  background: var(--border); border-radius: 2px;
  transition: background 0.2s, box-shadow 0.2s; z-index: 10; user-select: none;
  margin: 0;
}
.crm-detail-vsplit:hover, .crm-detail-vsplit.dragging {
  background: var(--brand); box-shadow: 0 0 0 4px rgba(5,150,105,0.2);
}
.crm-detail-chat { flex: 1 0 var(--chat-h, 200px); overflow-y: auto; min-height: 120px; padding: 0 22px 18px; }
.crm-detail-body { flex: 1; overflow-y: auto; display: flex; flex-direction: column; min-height: 0; }

.tab-bar {
  display: flex; gap: 0; border-bottom: 1px solid var(--border);
  padding: 0 22px; background: var(--surface);
}
.tab-item {
  padding: 10px 16px; cursor: pointer; font-size: 0.82rem; font-weight: 500;
  color: var(--ink-muted); border-bottom: 2px solid transparent;
  transition: all var(--transition); margin-bottom: -1px;
}
.tab-item:hover { color: var(--ink-secondary); }
.tab-item.active { color: var(--brand); border-bottom-color: var(--brand); }

.field-row {
  display: grid; grid-template-columns: 100px 1fr;
  gap: 8px; margin-bottom: 10px; align-items: center;
}
.field-row label {
  font-size: 0.73rem; color: var(--ink-muted);
  font-weight: 500; letter-spacing: 0.02em;
}
.field-row select, .field-row input, .field-row textarea {
  background: var(--page); color: var(--ink-primary);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 7px 10px; font-size: 0.84rem; outline: none;
  font-family: var(--font); width: 100%;
  transition: border var(--transition), box-shadow var(--transition);
}
.field-row select:focus, .field-row input:focus, .field-row textarea:focus {
  border-color: var(--brand); box-shadow: 0 0 0 3px rgba(16,185,129,0.12);
}
.field-row textarea { min-height: 50px; resize: vertical; }

/* ============================================================
   TIMELINE / MESSAGE ROWS
   ============================================================ */
.timeline-section { margin-top: 22px; border-top: 1px solid var(--border); padding-top: 18px; }
.timeline-section h3 { font-size: 0.85rem; font-weight: 600; color: var(--ink-secondary); margin-bottom: 14px; }

/* Message row — flex container, full width */
.message-row {
  display: flex; width: 100%; margin: 12px 0; align-items: flex-start;
}
.message-row.customer { justify-content: flex-start; flex-direction: row; }
.message-row.ours     { justify-content: flex-end;   flex-direction: row; }

/* Avatar */
.avatar {
  width: 28px; height: 28px; flex: 0 0 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.66rem; font-weight: 700;
}
.customer .avatar { margin-right: 8px; background: var(--violet-bg); color: var(--violet); }
.ours .avatar     { margin-left: 8px;  background: var(--brand-bg);  color: var(--brand); }

/* Message content wrapper */
.message-content { max-width: 75%; }
.ours .message-content { display: flex; flex-direction: column; align-items: flex-end; }
.message-bubble {
  padding: 10px 14px; border-radius: 10px;
  font-size: 0.81rem; line-height: 1.55; word-break: break-word; white-space: pre-wrap;
}
.customer .message-bubble {
  background: #f3f6fb; color: var(--ink-primary); border-bottom-left-radius: 3px;
}
.ours .message-bubble {
  background: #e8f8f0; color: var(--ink-primary); border-bottom-right-radius: 3px;
}

/* Meta: time + translate button */
.message-meta { font-size: 0.66rem; color: var(--ink-muted); margin-top: 3px; font-variant-numeric: tabular-nums; }
.customer .message-meta { text-align: left; }
.ours .message-meta     { text-align: right; }

/* Translation text — click to toggle */
.tl-text { cursor: pointer; user-select: none; }
.tl-text:hover { opacity: 0.7; }

/* 时间线图片：按需加载，点击看大图 */
.tl-image {
  display: block; max-width: 240px; max-height: 240px;
  border-radius: 6px; border: 1px solid var(--border);
  background: var(--page); object-fit: contain;
}
@media (max-width: 768px) {
  .tl-image { max-width: 180px; max-height: 180px; }
}

.timeline-handoff {
  text-align: center; padding: 8px; margin: 12px 0;
  background: var(--rose-bg); border: 1px dashed var(--rose);
  border-radius: var(--radius-sm); color: var(--rose);
  font-size: 0.76rem; font-weight: 500;
}

/* ============================================================
   FEED / MONITOR
   ============================================================ */
.feed-container { display: flex; flex-direction: column; max-height: 480px; overflow-y: auto; }
.feed-item {
  padding: 10px 14px; display: flex; gap: 10px; align-items: flex-start;
  border-bottom: 1px solid var(--border); transition: background var(--transition); cursor: pointer;
}
.feed-item:hover { background: var(--surface-hover); }
.feed-item .feed-icon {
  width: 24px; height: 24px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem; flex-shrink: 0; margin-top: 2px;
}
.feed-item .feed-body { flex: 1; min-width: 0; }
.feed-item .feed-name { font-weight: 600; font-size: 0.8rem; color: var(--ink-primary); }
.feed-item .feed-text {
  font-size: 0.78rem; color: var(--ink-secondary); margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.feed-item .feed-meta {
  font-size: 0.66rem; color: var(--ink-muted); margin-top: 3px;
  display: flex; gap: 6px; align-items: center;
}

/* ============================================================
   KANBAN
   ============================================================ */
.kanban-wrap { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 12px; }
.kanban-col {
  flex: 1; min-width: 185px; max-width: 260px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); display: flex; flex-direction: column;
  max-height: calc(100vh - 200px);
}
.kanban-col-header {
  padding: 11px 14px; font-size: 0.8rem; font-weight: 600;
  border-bottom: 2px solid var(--border); display: flex; justify-content: space-between;
  background: var(--surface-alt); border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.kanban-col-body { flex: 1; padding: 8px; overflow-y: auto; min-height: 80px; }
.kanban-card {
  background: var(--page); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 12px; margin-bottom: 6px;
  cursor: grab; transition: all var(--transition);
}
.kanban-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.kanban-card:active { cursor: grabbing; }
.kanban-card.dragging { opacity: 0.35; }
.kanban-card .kc-name { font-weight: 600; font-size: 0.81rem; color: var(--ink-primary); }
.kanban-card .kc-company { font-size: 0.72rem; color: var(--ink-muted); margin-top: 2px; }
.kanban-card.A { border-left: 3px solid var(--sky); }
.kanban-card.B { border-left: 3px solid var(--blue); }
.kanban-card.C { border-left: 3px solid var(--ink-muted); }
.kanban-card.D { border-left: 3px solid var(--rose); }
.kanban-col-body.drag-over { background: var(--brand-bg); }

/* ============================================================
   PAGINATION
   ============================================================ */
.pagination {
  display: flex; align-items: center; justify-content: center;
  gap: 6px; padding: 16px 0;
}
.pagination button {
  background: var(--surface); color: var(--ink-secondary);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 6px 12px; cursor: pointer; font-size: 0.78rem; font-family: var(--font);
  transition: all var(--transition);
}
.pagination button:hover:not(:disabled) { background: var(--surface-hover); color: var(--ink-primary); border-color: var(--border-strong); }
.pagination button:disabled { opacity: 0.3; cursor: default; }
.pagination span { color: var(--ink-muted); font-size: 0.78rem; }

/* ============================================================
   STATES
   ============================================================ */
.empty-state { text-align: center; padding: 60px 20px; color: var(--ink-muted); }
.empty-state .icon { font-size: 2.5rem; margin-bottom: 12px; opacity: 0.4; }
.empty-state p { font-size: 0.84rem; }

.loading-box { text-align: center; padding: 40px; color: var(--ink-muted); }
.spinner {
  width: 28px; height: 28px; border: 2.5px solid var(--border);
  border-top-color: var(--brand); border-radius: 50%;
  animation: spin 0.65s linear infinite; margin: 0 auto 10px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton {
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-hover) 50%, var(--surface) 75%);
  background-size: 200% 100%; animation: shimmer 1.5s infinite; border-radius: var(--radius-sm);
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ============================================================
   TOAST
   ============================================================ */
.toast {
  position: fixed; bottom: 20px; right: 20px; z-index: 9999;
  padding: 11px 18px; border-radius: var(--radius);
  font-size: 0.81rem; font-weight: 500; color: var(--ink-primary);
  background: var(--surface); border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-lg); display: flex; align-items: center; gap: 10px;
  animation: slideUp 0.2s ease;
}
.toast-ok { border-left: 3px solid var(--status-good); }
.toast-err { border-left: 3px solid var(--status-critical); }
.toast-close { background: none; border: none; color: var(--ink-muted); cursor: pointer; font-size: 1rem; line-height: 1; padding: 0 2px; }
.toast-close:hover { color: var(--ink-primary); }
@keyframes slideUp { from { transform: translateY(12px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ============================================================
   MISC
   ============================================================ */
.field-empty { color: var(--ink-muted); font-style: italic; cursor: pointer; font-size: 0.8rem; }
.field-empty:hover { color: var(--brand); font-style: normal; }

.silence-bar { display: flex; gap: 3px; height: 22px; border-radius: 4px; overflow: hidden; margin-top: 4px; }
.silence-segment {
  display: flex; align-items: center; justify-content: center;
  font-size: 0.62rem; font-weight: 600; color: #fff;
  transition: all var(--transition); cursor: pointer;
}
.silence-segment:hover { filter: brightness(1.2); }

.profile-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.profile-section { margin-bottom: 14px; }
.profile-section h4 { font-size: 0.76rem; color: var(--ink-muted); margin-bottom: 6px; letter-spacing: 0.04em; text-transform: uppercase; }
.memory-item { padding: 5px 0 5px 10px; font-size: 0.82rem; border-left: 2px solid var(--brand); margin-bottom: 4px; color: var(--ink-secondary); }

.reason-tag { display: inline-block; padding: 2px 8px; border-radius: 3px; font-size: 0.68rem; font-weight: 600; }
.reason-customer  { background: var(--blue-bg);   color: var(--blue); }
.reason-price     { background: var(--rose-bg);   color: var(--rose); }
.reason-file      { background: var(--amber-bg);  color: var(--amber); }
.reason-redline   { background: var(--rose-bg);   color: var(--rose); }
.reason-system    { background: var(--surface-hover); color: var(--ink-muted); }

.sidebar-nav .icon { display: inline-flex; align-items: center; width: 20px; height: 20px; }
.sidebar-nav .icon svg { width: 18px; height: 18px; }
.sidebar-nav a.active .icon svg { stroke: var(--brand); }

.chart-card canvas { max-width: 100%; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1200px) { .kpi-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 1024px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .crm-split { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
  .kanban-col { min-width: 150px; }
}
@media (max-width: 768px) {
  .sidebar { width: 56px; min-width: 56px; }
  .sidebar .sidebar-brand span, .sidebar .sidebar-nav a span:not(.icon),
  .sidebar .sidebar-footer, .sidebar .badge-count { display: none; }
  .main { margin-left: 56px; }
  :root { --sidebar-w: 56px; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .kpi-card { padding: 14px 16px; }
  .kpi-card .kpi-value { font-size: 1.5rem; }
}

/* ============================================================
   NEW: Orders — status timeline
   ============================================================ */
.order-timeline { display: flex; justify-content: space-between; align-items: flex-start; padding: 12px 0; position: relative; }
.order-timeline::before { content: ''; position: absolute; top: 24px; left: 10%; right: 10%; height: 2px; background: var(--border); z-index: 0; }
.ot-step { display: flex; flex-direction: column; align-items: center; gap: 6px; position: relative; z-index: 1; flex: 1; }
.ot-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--border); border: 2px solid #fff; }
.ot-step.active .ot-dot { background: var(--brand); box-shadow: 0 0 0 3px var(--brand-bg); }
.ot-step.current .ot-dot { background: var(--brand); box-shadow: 0 0 0 5px var(--brand-bg-strong); }
.ot-step span { font-size: 0.68rem; color: var(--ink-muted); white-space: nowrap; }
.ot-step.active span { color: var(--brand); font-weight: 600; }

/* ============================================================
   NEW: Follow-up cards
   ============================================================ */
.fu-card { transition: box-shadow var(--transition); }
.fu-card:hover { box-shadow: var(--shadow-sm); }

/* ============================================================
   NEW: Completeness bar (customer enrichment)
   ============================================================ */
.completeness-bar { height: 6px; border-radius: 3px; background: var(--border); overflow: hidden; margin: 4px 0; }
.completeness-bar-fill { height: 100%; border-radius: 3px; transition: width 0.6s ease; }
.completeness-low .completeness-bar-fill { background: var(--rose); }
.completeness-medium .completeness-bar-fill { background: var(--amber); }
.completeness-high .completeness-bar-fill { background: var(--brand); }

/* 客户名后面的 WhatsApp 号：仅手机端显示（桌面端已有副标题） */
.cust-name-wa { display: none; }
/* 手机端号码行右侧的返回按钮（桌面端用不到） */
.mobile-back-btn-right { display: none; }

/* ============================================================
   NEW: Enrichment review modal
   ============================================================ */
.enrich-review-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.enrich-review-row:last-child { border-bottom: none; }
.enrich-field-label { width: 70px; font-size: 0.8rem; color: var(--ink-secondary); flex-shrink: 0; }
.enrich-old-val { font-size: 0.8rem; color: var(--ink-muted); text-decoration: line-through; flex: 1; }
.enrich-new-val { font-size: 0.85rem; color: var(--brand); font-weight: 500; flex: 1; }
.enrich-arrow { color: var(--ink-muted); font-size: 0.8rem; }
.enrich-conf-badge { font-size: 0.7rem; padding: 2px 6px; border-radius: 4px; flex-shrink: 0; }
.enrich-conf-high { background: var(--brand-bg); color: var(--brand); }
.enrich-conf-medium { background: var(--amber-bg); color: var(--amber); }
.enrich-conf-low { background: var(--rose-bg); color: var(--rose); }

/* ============================================================
   NEW: Pager buttons
   ============================================================ */
.pager { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 10px; justify-content: center; }

/* ============================================================
   NEW: 发送栏 4 个控件（语言 / 翻译 / 原文 / 发送）等宽等高
   PC 端一行显示；手机端在 @media 里改成等分一行
   ============================================================ */
.msgbar-ctrl {
  flex: 0 0 96px;
  width: 96px;
  height: 36px;
  min-height: 36px;
  box-sizing: border-box;
  padding: 0 6px;
  border-radius: 18px;
  font-size: 0.78rem;
  line-height: 1;
  white-space: nowrap;
  text-align: center;
}
select.msgbar-ctrl { padding: 0 4px; }

/* ============================================================
   MOBILE ADAPTATION (max-width: 767px)
   Complete single-page navigation for CRM on phones.
   PC端不受任何影响 — 所有规则严格锁在 @media 内。
   ============================================================ */

@media (max-width: 767px) {

  /* ── 1. 隐藏 PC 侧边栏，主区全宽 ── */
  .sidebar { display: none !important; }
  .main { margin-left: 0 !important; }
  .content { padding-bottom: 70px !important; } /* 给底部导航留空间 */

  /* ── 2. crm-split 取消 grid 改 flex ── */
  .crm-split {
    display: flex !important;
    flex-direction: column !important;
    height: auto !important;
    min-height: calc(100vh - 110px);
  }
  .crm-split-handle { display: none !important; }
  .crm-detail-panel { margin-left: 0 !important; }
  .crm-list-panel { margin-right: 0 !important; }

  /* ── 3. 单页导航模式 ── */
  .crm-split.mobile-list-only .crm-detail-panel { display: none !important; }
  .crm-split.mobile-detail-only .crm-list-panel { display: none !important; }
  .crm-split.mobile-detail-only .crm-detail-panel {
    display: flex !important;
    flex-direction: column;
    height: calc(100vh - 110px);
    overflow: hidden;
  }
  .crm-split.mobile-detail-only .crm-detail-header { flex-shrink: 0; }
  .crm-split.mobile-detail-only .crm-detail-body {
    flex: 1 !important;
    overflow-y: auto !important;
    display: block !important;
  }
  .crm-split.mobile-detail-only .crm-detail-info {
    overflow-y: visible !important;
  }
  .crm-split.mobile-detail-only .crm-detail-vsplit { display: none !important; }

  /* ── 4. 列表视图优化 ── */
  .crm-list-item {
    padding: 14px 16px !important;
    border-bottom: 1px solid var(--border) !important;
  }
  .crm-list-item .li-name { font-size: 0.92rem !important; }
  .crm-list-item .li-meta { font-size: 0.7rem !important; }

  /* ── 5. 详情视图滚动 ── */
  .crm-detail-chat {
    overflow-y: visible !important;
    min-height: auto !important;
    flex: none !important;
    /* 底部发送区是 fixed 的（输入框最高 100px + 按钮行 34px + 底部导航 56px），
       这里必须留够高度，否则「一键翻译全部对话」按钮会被盖住 */
    padding: 0 16px 220px !important;
  }

  /* ── 6. 发送区域：固定在底部（两行布局） ── */
  .crm-detail-chat > div:last-child {
    position: fixed !important;
    bottom: 56px !important; /* 在底部导航之上 */
    left: 0 !important;
    right: 0 !important;
    background: var(--surface) !important;
    border-top: 1px solid var(--border) !important;
    padding: 8px 12px !important;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0)) !important;
    z-index: 150 !important;
  }
  .crm-detail-chat > div:last-child > div:first-child {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
    align-items: center !important;
  }
  .crm-detail-chat textarea {
    flex: 0 0 100% !important; /* 占一整行 */
    font-size: 16px !important; /* 防止 iOS 自动缩放 */
    min-height: 44px !important;
    max-height: 100px !important;
    border-radius: 18px !important;
    background: var(--page) !important;
    border: 1px solid var(--border) !important;
    padding: 10px 14px !important;
    resize: none !important;
  }
  .crm-detail-chat .msgbar-ctrl {
    flex: 1 1 0 !important;      /* 4 个控件等分一行 */
    width: auto !important;
    min-width: 0 !important;
    height: 34px !important;
    min-height: 34px !important;
    font-size: 14px !important;
    padding: 0 4px !important;
    border-radius: 17px !important;
    white-space: nowrap !important;
  }
  .crm-detail-chat select[id^='targetLang'] {
    display: block !important; /* 手机端显示语言选择器 */
    border: 1px solid var(--border) !important;
    background: var(--surface) !important;
    margin-left: 0 !important;
  }
  /* ── 7. 客户信息字段：单列显示 ── */
  .crm-split.mobile-detail-only .cust-info-grid {
    grid-template-columns: 1fr !important;
  }
  .field-row {
    grid-template-columns: 80px 1fr !important;
    gap: 6px !important;
    margin-bottom: 8px !important;
  }
  .field-row label { font-size: 0.7rem !important; }
  .field-row input, .field-row select, .field-row textarea {
    font-size: 16px !important; /* 防止 iOS 自动缩放 */
    padding: 8px 10px !important;
  }

  /* ── 8. 详情头部优化 ── */
  .crm-detail-header {
    padding: 12px 16px !important;
    display: flex !important;
    align-items: center !important;
    gap: 10px !important;
    flex-wrap: wrap !important;
  }
  .crm-detail-actions { flex-basis: 100% !important; }
  .crm-ai-summary, .crm-ai-score { flex-basis: 100% !important; }
  .crm-detail-header h2 {
    font-size: 1rem !important;
    flex: 1 !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
  }
  .crm-detail-header .subtitle {
    display: none !important; /* 手机端隐藏副信息 */
  }
  .crm-detail-header button[onclick^='enrichCustomer'] {
    font-size: 0.68rem !important;
    padding: 4px 8px !important;
  }
  .crm-detail-header #completeness {
    display: none !important;
  }

  /* ── 9. 返回按钮 ── */
  .mobile-back-btn {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--surface-hover);
    border: 1px solid var(--border);
    font-size: 1rem;
    cursor: pointer;
    flex-shrink: 0;
  }
  /* 号码行右侧的返回按钮：手机系统返回键会退出整个网站，这里给一个稳妥入口 */
  .mobile-back-btn-right {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    margin-left: auto;
    padding: 4px 10px;
    border-radius: 16px;
    background: var(--surface-hover);
    border: 1px solid var(--border);
    color: var(--ink-secondary);
    font-size: 0.72rem;
    line-height: 1.2;
    white-space: nowrap;
    cursor: pointer;
    flex-shrink: 0;
  }

  /* ── 10. 底部导航栏 ── */
  .mobile-nav {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    height: 56px !important;
    height: calc(56px + env(safe-area-inset-bottom, 0)) !important;
    background: var(--surface) !important;
    border-top: 1px solid var(--border) !important;
    display: flex !important;
    justify-content: space-around !important;
    align-items: center !important;
    z-index: 200 !important;
    padding-bottom: env(safe-area-inset-bottom, 0) !important;
  }
  .mobile-nav-item {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 2px !important;
    flex: 1 !important;
    height: 100% !important;
    color: var(--ink-muted) !important;
    text-decoration: none !important;
    font-size: 0.62rem !important;
    font-weight: 500 !important;
    cursor: pointer !important;
  }
  .mobile-nav-item .icon {
    font-size: 1.2rem !important;
    line-height: 1 !important;
  }
  .mobile-nav-item.active {
    color: var(--brand) !important;
  }
  .mobile-nav-item.active-touch {
    background: var(--surface-hover) !important;
  }

  /* ── 11. 筛选栏手机端适配 ── */
  .filter-bar {
    padding: 10px 12px !important;
    gap: 6px !important;
  }
  .filter-bar .btn { padding: 6px 12px !important; }

  /* ── 12. KPI 手机端 ── */
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
  }
  .kpi-card { padding: 12px !important; }
  .kpi-card .kpi-value { font-size: 1.3rem !important; }

  /* ── 13. 触摸反馈 ── */
  .btn, .crm-list-item, .sidebar-nav a {
    -webkit-tap-highlight-color: transparent !important;
    touch-action: manipulation !important;
  }

  /* ── 14. 仪表盘视图手机端 ── */
  .dashboard-grid {
    grid-template-columns: 1fr !important;
  }
  .dashboard-col { gap: 12px !important; }

  /* ── 15. 客户详情全屏：隐藏顶栏和筛选栏，把高度让给对话记录 ── */
  body.mobile-cust-detail .topbar { display: none !important; }
  body.mobile-cust-detail .content { padding: 0 !important; }
  body.mobile-cust-detail .filter-bar { display: none !important; }
  body.mobile-cust-detail .crm-split.mobile-detail-only .crm-detail-panel {
    height: 100vh !important;
    height: 100dvh !important;
  }

  /* ── 16. 手机端详情头部：完整度条缩短、按钮更紧凑、隐藏快捷回复行 ── */
  .crm-detail-actions { gap: 6px !important; }
  .crm-detail-actions .btn {
    font-size: 0.66rem !important;
    padding: 4px 8px !important;
    white-space: nowrap !important;
  }
  .crm-detail-actions [id^='completeness'] {
    flex: 0 1 70px !important;
    max-width: 70px !important;
    min-width: 40px !important;
  }
  .crm-detail-actions [id^='completeness'] span {
    display: inline !important;
    font-size: 0.5rem !important;
    line-height: 1.1 !important;
    color: var(--ink-muted);
  }
  .crm-detail-header h2 .cust-name-wa {
    display: inline !important;
    margin-left: 6px;
    font-size: 0.8rem !important;
    font-weight: 400;
    color: var(--ink-muted);
    white-space: nowrap;
  }
  #templateBar { display: none !important; }

  /* ── 17. 手机端自适应宽度：页面不再左右滑动 ── */
  html, body { overflow-x: hidden !important; max-width: 100vw !important; }
  .main, .content, .crm-split, .crm-list-panel, .crm-detail-panel {
    min-width: 0 !important;
    max-width: 100% !important;
  }
  .topbar {
    flex-wrap: wrap !important;
    padding: 8px 12px !important;
    gap: 6px !important;
  }
  .topbar h2 { font-size: 0.95rem !important; white-space: nowrap !important; }
  .topbar-actions {
    width: 100% !important;
    margin-left: 0 !important;
    flex-wrap: wrap !important;
    gap: 4px !important;
  }
  .topbar-actions .btn {
    font-size: 0.72rem !important;
    padding: 4px 10px !important;
  }
  .content { padding: 12px 12px 70px !important; }
  .filter-bar input {
    min-width: 0 !important;
    flex: 1 1 100% !important;
  }
  .filter-bar select {
    min-width: 0 !important;
    flex: 1 1 45% !important;
  }
  .message-bubble { overflow-wrap: anywhere !important; word-break: break-word !important; }
  .crm-detail-header, .crm-detail-body, .crm-detail-chat {
    max-width: 100% !important;
    box-sizing: border-box !important;
  }

} /* END @media (max-width: 767px) */

/* PC端隐藏手机端导航（手机端媒体查询内 display:flex !important 覆盖此规则） */
.mobile-nav { display: none; }
.mobile-back-btn { display: none !important; }
