:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --warn: #d97706;
  --warn-soft: #fffbeb;
  --success: #059669;
  --success-soft: #ecfdf5;
  --radius: 10px;
  --shadow: 0 4px 16px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

.hidden { display: none !important; }

/* 按钮与表单 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s ease;
  background: var(--surface);
  color: var(--text);
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { background: #047857; }
.btn-outline { border-color: var(--border); background: #fff; }
.btn-outline:hover:not(:disabled) { background: var(--surface-alt); border-color: #cbd5e1; }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover:not(:disabled) { background: #e2e8f066; color: var(--text); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-xs { padding: 3px 8px; font-size: 12px; }
.btn-block { width: 100%; padding: 10px; font-size: 14px; }
.btn-close {
  border: none;
  background: transparent;
  font-size: 20px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 6px;
}

input[type="text"], input[type="password"], input[type="search"], input[type="number"], select, textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 7px 10px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  outline: none;
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
.input-sm { padding: 5px 8px; font-size: 12.5px; }

/* 登录页 */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #eff6ff 0%, #f8fafc 50%, #ecfdf5 100%);
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.login-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.login-logo h1 { margin: 0; font-size: 20px; }
.login-logo p { margin: 2px 0 0; font-size: 12.5px; color: var(--text-muted); }
.logo-badge {
  width: 42px; height: 42px; border-radius: 10px;
  background: linear-gradient(135deg, #2563eb, #059669);
  color: #fff; font-weight: 700; font-size: 20px;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.logo-badge.sm { width: 28px; height: 28px; font-size: 14px; border-radius: 7px; }
.form-stack { display: flex; flex-direction: column; gap: 14px; }
.form-stack label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 500; }
.form-error {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid #fecaca;
  border-radius: 7px;
  padding: 8px 10px;
  font-size: 12.5px;
}
.login-tips {
  margin-top: 16px;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--surface-alt);
  padding: 10px;
  border-radius: 8px;
}

/* 主应用框架 */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}
.topbar {
  height: 54px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 10px; }
.brand { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.stats-bar { display: flex; align-items: center; gap: 8px; margin-left: 8px; }
.stat-pill {
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 999px;
  background: #eff6ff;
  color: #1e40af;
}
.stat-pill.muted { background: var(--surface-alt); color: var(--text-muted); }
.stat-pill.danger { background: var(--danger-soft); color: var(--danger); font-weight: 600; }
.agent-status-box {
  display: flex; align-items: center; gap: 6px;
  padding-left: 8px; border-left: 1px solid var(--border);
}
.me-name { font-weight: 600; font-size: 13px; white-space: nowrap; }
.status-select { width: auto; padding: 4px 8px; font-size: 12.5px; }

/* 三栏布局 */
.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 310px minmax(420px, 1fr) 390px;
  min-height: 0;
  overflow: hidden;
}

/* 左栏：会话列表 */
.col-left {
  background: #fff;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.filter-bar { padding: 10px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.scope-tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; background: var(--surface-alt); padding: 3px; border-radius: 8px; }
.scope-tabs .tab {
  border: none; background: transparent; padding: 5px 4px; border-radius: 6px;
  font-size: 12px; cursor: pointer; color: var(--text-muted); font-weight: 500;
}
.scope-tabs .tab.active { background: #fff; color: var(--primary); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.filter-inputs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.conv-list { flex: 1; overflow-y: auto; }
.conv-item {
  padding: 11px 12px;
  border-bottom: 1px solid #f1f5f9;
  cursor: pointer;
  transition: background .12s;
  position: relative;
}
.conv-item:hover { background: #f8fafc; }
.conv-item.active { background: #eff6ff; border-left: 3px solid var(--primary); padding-left: 9px; }
.conv-top { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-bottom: 4px; }
.shop-badge {
  display: inline-flex;
  align-items: center;
  padding: 1px 7px;
  border-radius: 4px;
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sla-badge {
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 4px;
  font-weight: 600;
  white-space: nowrap;
}
.sla-ok { background: #f1f5f9; color: #475569; }
.sla-warn { background: var(--warn-soft); color: var(--warn); }
.sla-danger { background: var(--danger); color: #fff; animation: pulse 1.4s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .7; } }
.conv-mid { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.conv-buyer { font-weight: 600; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-agent { font-size: 11.5px; color: var(--text-muted); white-space: nowrap; }
.conv-bottom { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 4px; }
.conv-preview { font-size: 12.5px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.unread-dot {
  min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 999px; background: var(--danger); color: #fff;
  font-size: 11px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

/* 中栏：聊天区 */
.col-center {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg);
  position: relative;
}
.chat-empty {
  flex: 1; display: flex; align-items: center; justify-content: center; text-align: center; color: var(--text-muted);
}
.empty-icon { font-size: 42px; margin-bottom: 8px; }
.chat-pane { flex: 1; display: flex; flex-direction: column; min-height: 0; position: relative; }
.chat-header {
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.chat-header-info { display: flex; align-items: center; gap: 10px; min-width: 0; }
.chat-buyer-row { display: flex; align-items: center; gap: 6px; }
.chat-sub { font-size: 11.5px; color: var(--text-muted); }
.mini-tag { font-size: 11px; padding: 1px 6px; border-radius: 4px; background: #fef3c7; color: #92400e; }
.chat-header-actions { display: flex; align-items: center; gap: 8px; }
.inline-label { display: inline-flex; align-items: center; gap: 4px; font-size: 12.5px; color: var(--text-muted); white-space: nowrap; }
.inline-label select { width: auto; }

.msg-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.msg-row { display: flex; flex-direction: column; max-width: 76%; }
.msg-row.buyer { align-self: flex-start; align-items: flex-start; }
.msg-row.agent { align-self: flex-end; align-items: flex-end; }
.msg-row.system { align-self: center; align-items: center; max-width: 90%; }
.msg-meta { font-size: 11px; color: var(--text-muted); margin-bottom: 3px; }
.msg-bubble {
  padding: 9px 12px;
  border-radius: 10px;
  word-break: break-word;
  white-space: pre-wrap;
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
.msg-row.buyer .msg-bubble { background: #fff; border: 1px solid var(--border); border-top-left-radius: 3px; }
.msg-row.agent .msg-bubble { background: #2563eb; color: #fff; border-top-right-radius: 3px; }
.msg-row.agent .msg-bubble.failed { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.msg-system-pill {
  font-size: 11.5px;
  color: var(--text-muted);
  background: #e2e8f0aa;
  padding: 3px 10px;
  border-radius: 999px;
}
.msg-img { max-width: 220px; max-height: 220px; border-radius: 8px; cursor: zoom-in; display: block; }
.rich-card {
  background: #fff; color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 10px; min-width: 240px; max-width: 300px;
}
.rich-card-tag { font-size: 11px; color: var(--primary); font-weight: 600; margin-bottom: 4px; }
.rich-card-title { font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.rich-card-sub { font-size: 12px; color: var(--text-muted); }

/* 快捷话术浮层 */
.qr-popover {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 162px;
  max-height: 260px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  z-index: 20;
}
.qr-popover-head {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
  font-size: 12.5px;
}
.qr-popover-list { overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.qr-item {
  border: 1px solid #f1f5f9; border-radius: 7px; padding: 8px 10px;
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  background: var(--surface-alt);
}
.qr-item:hover { border-color: #bfdbfe; background: #eff6ff; }
.qr-item-title { font-weight: 600; font-size: 12.5px; }
.qr-item-text { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.qr-item-actions { display: flex; gap: 4px; flex-shrink: 0; }

/* 输入区 */
.composer {
  background: #fff;
  border-top: 1px solid var(--border);
  padding: 8px 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.composer-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.composer-tools { display: flex; align-items: center; gap: 6px; }
.file-btn { cursor: pointer; }
.quota-indicator { font-size: 12px; font-weight: 500; }
.quota-ok { color: var(--success); }
.quota-warn { color: var(--warn); }
.quota-block { color: var(--danger); }
#msg-input { resize: none; border-radius: 8px; }
.composer-footer { display: flex; align-items: center; justify-content: space-between; }
.hint { font-size: 11.5px; color: var(--text-muted); }

/* 右栏：订单与售后 */
.col-right {
  background: #fff;
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.panel-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.orders-container {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.order-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  background: var(--surface-alt);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.order-head { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.order-id { font-family: ui-monospace, Consolas, monospace; font-size: 12px; color: var(--text-muted); cursor: pointer; }
.order-id:hover { color: var(--primary); }
.status-chip { font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: #e0f2fe; color: #0369a1; }
.order-prod { background: #fff; border: 1px solid #eef2f7; border-radius: 7px; padding: 8px; font-size: 12.5px; }
.order-meta { font-size: 12px; color: var(--text-muted); display: flex; flex-direction: column; gap: 3px; }
.order-meta b { color: var(--text); }
.note-box {
  background: #fefce8; border: 1px solid #fde68a; border-radius: 6px;
  padding: 6px 8px; font-size: 12px; color: #854d0e;
}
.order-actions { display: flex; flex-wrap: wrap; gap: 6px; }

.aftersale-box {
  background: #fff1f2;
  border: 1px solid #fecdd3;
  border-radius: 8px;
  padding: 9px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.aftersale-head { display: flex; justify-content: space-between; align-items: center; font-size: 12.5px; font-weight: 600; color: #9f1239; }
.aftersale-meta { font-size: 12px; color: #881337; }
.aftersale-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 36px 18px;
  font-size: 13px;
}

/* 弹窗 */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .45);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 16px;
}
.modal-dialog {
  width: 100%; max-width: 760px; max-height: 88vh;
  background: #fff; border-radius: 12px; box-shadow: 0 20px 50px rgba(0,0,0,.22);
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-head {
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-body { padding: 16px 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.data-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.data-table th, .data-table td { border-bottom: 1px solid var(--border); padding: 8px 6px; text-align: left; }
.data-table th { color: var(--text-muted); font-weight: 600; background: var(--surface-alt); }
.code-pill {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 11.5px; background: #f1f5f9; padding: 2px 6px; border-radius: 4px;
  word-break: break-all;
}

/* 灯箱 & Toast */
.lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,.78);
  display: flex; align-items: center; justify-content: center; z-index: 200; cursor: zoom-out;
}
.lightbox img { max-width: 90vw; max-height: 90vh; border-radius: 8px; }
.toast-container {
  position: fixed; right: 18px; bottom: 18px; z-index: 300;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: #0f172a; color: #fff; padding: 10px 14px; border-radius: 8px;
  font-size: 13px; box-shadow: var(--shadow); max-width: 340px;
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

@media (max-width: 1100px) {
  .workspace { grid-template-columns: 260px 1fr 320px; }
}
