/* ==========================================================================
   客服工作台样式（无构建，直接由 base.html 引入）
   设计约束：
   - 单文件、纯 CSS、不依赖任何框架，便于离线部署；
   - 关键区域用 CSS 变量统一配色，租户主题色只在浮窗里用（避免后台串色）。
   ========================================================================== */

:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --border: #e4e7ec;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-soft: #eef4ff;
  --success: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.6 -apple-system, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------------- 布局 ---------------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 208px;
  flex: 0 0 208px;
  background: #fff;
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
}

.brand { font-weight: 700; font-size: 16px; padding: 4px 8px 14px; }
.brand small { display: block; color: var(--muted); font-weight: 400; font-size: 12px; }

.nav a {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 10px;
  border-radius: 8px;
  color: var(--text);
  margin-bottom: 2px;
}
.nav a:hover { background: #f3f4f6; text-decoration: none; }
.nav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav .badge {
  background: var(--danger);
  color: #fff;
  border-radius: 999px;
  font-size: 11px;
  padding: 1px 7px;
  min-width: 20px;
  text-align: center;
}
.nav .badge.zero { display: none; }

/* 侧栏分组：会话（我的 / 排队中 / 全部）、工单（我的 / 全部）。
   父项是分组标题（当前分组时变主色加粗，仍可点击回默认视图），
   子项缩进并带一条左侧竖线；选中态沿用 `.nav a.active` 的浅主色药丸。 */
.nav-group { margin-bottom: 8px; }
.nav-group > .nav-parent { font-weight: 500; }
.nav-group.is-active > .nav-parent { color: var(--primary); font-weight: 600; }
.nav-sub { margin: 2px 0 4px; padding-left: 10px; border-left: 1px solid var(--border); }
.nav-sub a { padding: 6px 10px; font-size: 13px; margin-bottom: 1px; }
.nav-sub a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav-sub .badge { font-size: 10px; padding: 0 6px; min-width: 18px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar h1 { font-size: 16px; margin: 0; flex: 1; }
.content { padding: 20px; }

/* 顶栏的在线状态下拉：在线 / 忙碌 / 离开 / 离线 */
.status-picker { position: relative; display: inline-flex; }

.status-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  color: var(--text);
  font: inherit;
  font-size: 12px;
  line-height: 1.4;
  cursor: pointer;
  white-space: nowrap;
}
.status-btn:hover { background: #f7f8fa; }
.status-btn .dot {
  width: 7px; height: 7px; flex: 0 0 auto;
  border-radius: 50%;
  background: var(--muted);
}
.status-btn::after { content: "▾"; margin-left: 2px; font-size: 9px; color: var(--muted); }

/* 每个状态一套颜色：绿=在线、红=忙碌（勿扰）、黄=离开、灰=离线 */
.status-btn[data-status="online"] { color: #15803d; background: #f0fdf4; border-color: #bbf7d0; }
.status-btn[data-status="online"] .dot { background: var(--success); }
.status-btn[data-status="busy"] { color: #b91c1c; background: #fef2f2; border-color: #fecaca; }
.status-btn[data-status="busy"] .dot { background: #dc2626; }
.status-btn[data-status="away"] { color: #a16207; background: #fefce8; border-color: #fde68a; }
.status-btn[data-status="away"] .dot { background: #ca8a04; }

.status-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 40;
  min-width: 180px;
  padding: 6px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 26px -14px rgba(17, 24, 39, .35), 0 2px 6px rgba(17, 24, 39, .06);
}
.status-menu[hidden] { display: none; }
.status-menu button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 7px;
  background: none;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}
.status-menu button:hover { background: #f4f6f9; }
.status-menu button.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.status-menu button::before {
  content: "";
  width: 7px; height: 7px; flex: 0 0 auto;
  border-radius: 50%;
  background: var(--muted);
}
.status-menu [data-status="online"]::before { background: var(--success); }
.status-menu [data-status="busy"]::before { background: #dc2626; }
.status-menu [data-status="away"]::before { background: #ca8a04; }
.status-menu em {
  margin-left: auto;
  font-style: normal;
  font-size: 11px;
  font-weight: 400;
  color: var(--muted);
}

/* ---------------- 组件 ---------------- */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 16px;
}
.card h2 { font-size: 15px; margin: 0 0 12px; }

.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1100px) {
  .grid.cols-4, .grid.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .layout { flex-direction: column; }
  .sidebar { width: auto; height: auto; position: static; }
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; }
}

.stat { display: flex; flex-direction: column; gap: 4px; }
.stat .num { font-size: 26px; font-weight: 700; }
.stat .label { color: var(--muted); font-size: 12px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 13px;
  cursor: pointer;
  /* 文案不折行：否则在窄容器里“保存状态”会被压成两行 */
  white-space: nowrap;
}
.btn:hover { background: #f9fafb; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { border-color: #fecaca; color: var(--danger); }
.btn.small { padding: 4px 8px; font-size: 12px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* 退出登录用 POST 表单（Django 5 的 LogoutView 不接受 GET），
   这里把表单压成和旁边的标签同一行、不占额外高度。 */
.logout-form { display: inline-flex; margin: 0; }

.input, textarea.input, select.input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  background: #fff;
  color: var(--text);
}
textarea.input { resize: vertical; min-height: 76px; }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
label.check { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }

table.list { width: 100%; border-collapse: collapse; }
table.list th, table.list td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
table.list th { color: var(--muted); font-weight: 500; font-size: 12px; background: #fafbfc; }
table.list tr:hover td { background: #fbfcff; }

.tag {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 12px;
  background: #f3f4f6;
  color: var(--muted);
}
.tag.blue { background: var(--primary-soft); color: var(--primary); }
.tag.green { background: #ecfdf5; color: var(--success); }
.tag.orange { background: #fff7ed; color: var(--warn); }
.tag.red { background: #fef2f2; color: var(--danger); }
.tag.yellow { background: #fefce8; color: #a16207; }
/* 会话列表里的“待办”徽标：未读 / 客服未回复用实心色块，比上面这些浅色 tag 显著得多 */
.tag.unread { background: var(--danger); color: #fff; font-weight: 600; }
.tag.unreplied { background: #c2410c; color: #fff; font-weight: 600; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.empty { color: var(--muted); text-align: center; padding: 28px 12px; }

/* ---------------- 双栏页（会话 / 工单共用：左列表 + 右面板） ---------------- */
.split-layout {
  display: grid;
  grid-template-columns: 316px minmax(0, 1fr);
  gap: 14px;
  /* 撑满顶栏以下的一屏，让列表与消息区各自内部滚动 */
  height: calc(100vh - 106px);
  min-height: 480px;
}
/* 面板：卡片外观，内部区域各自滚动（本身不滚） */
.pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.pane-placeholder { align-items: center; justify-content: center; text-align: center; color: var(--muted); }
/* 按钮用 .btn（display:inline-flex）会盖掉浏览器默认的 [hidden]{display:none}，必须显式补一条 */
[hidden] { display: none !important; }

/* --- 左栏：列表 --- */
.list-head {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--border);
}
/* 搜索框与按钮一行放下（.input 默认 width:100% 会把按钮挤到下一行） */
.list-head form .input { flex: 1; width: auto; min-width: 0; }
.list-views { display: flex; flex-wrap: wrap; gap: 6px; }
.list-views a {
  font-size: 12px;
  padding: 3px 9px;
  border-radius: 999px;
  background: #f3f4f6;
  color: var(--text);
}
.list-views a:hover { background: #e9ecf1; text-decoration: none; }
.list-views a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.list-rows { flex: 1; overflow-y: auto; }
.list-item {
  display: block;
  padding: 10px 12px;
  color: inherit;
  border-bottom: 1px solid var(--border);
}
/* 客服未读的会话整行也做标记（淡红底 + 左侧红条）；下面的 :hover / .active 会盖掉它 */
.list-item.is-unread { background: #fff7f6; box-shadow: inset 3px 0 0 var(--danger); }
.list-item:hover { background: #fafbfc; text-decoration: none; }
.list-item.active { background: var(--primary-soft); box-shadow: inset 3px 0 0 var(--primary); }
.list-item .top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.list-item .name { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .time { color: var(--muted); font-size: 11px; white-space: nowrap; }
.list-item .preview {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.list-item .tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 5px; }

/* --- 右栏：面板 --- */
.pane-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}
.pane-title { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.pane-body {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 292px;
}
.pane-main { display: flex; flex-direction: column; min-height: 0; }
/* 消息区、侧栏各自滚动；消息区不再受 60vh 限制（面板里高度由 flex 决定） */
.pane-main .msg-list { flex: 1; max-height: none; padding: 14px; }
/* 消息少时贴底（像微信），消息多时自动边距归零、不影响滚动（比 justify-content:flex-end 安全） */
.pane-main .msg-list > *:first-child { margin-top: auto; }
.pane-main .composer { margin-top: 0; padding: 10px 14px 12px; }
.pane-side {
  border-left: 1px solid var(--border);
  background: #fcfcfd;
  padding: 14px;
  overflow-y: auto;
}
.pane-side h3 { font-size: 13px; margin: 0 0 8px; }
.pane-side section + section { margin-top: 16px; padding-top: 14px; border-top: 1px dashed var(--border); }

.pane-title .ticket-subject { font-weight: 600; }

/* ---------------- 工单面板（工单式，不做聊天气泡） ---------------- */
/* 属性条：状态 / 优先级 / 处理人 + 保存 */
.ticket-props {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px;
  padding: 10px 14px;
  background: #fcfcfd;
  border-bottom: 1px solid var(--border);
}
.ticket-props .prop { display: flex; flex-direction: column; gap: 3px; }
.ticket-props .prop > span { font-size: 11px; color: var(--muted); }
.ticket-props .input { width: auto; min-width: 108px; padding: 4px 8px; font-size: 12px; }

/* 问题描述：单独成块（引用式），不是一条聊天消息 */
.ticket-desc { margin: 12px 14px 0; border: 1px solid var(--border); border-radius: 10px; background: #f9fafb; }
.ticket-desc > header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
}
.ticket-desc .desc-body { padding: 10px 12px; white-space: pre-wrap; }

/* 处理记录：卡片式条目，全部左对齐（作者/时间/类型在头部） */
.ticket-scroll { flex: 1; min-height: 0; overflow-y: auto; padding-bottom: 4px; }
.note-list { padding: 12px 14px; }
.note-list-title { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.note {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  margin-bottom: 10px;
  overflow: hidden;
}
.note > header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  background: #fcfcfd;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.note > header .avatar { flex: 0 0 22px; width: 22px; height: 22px; font-size: 12px; }
.note .note-author { font-weight: 600; }
.note .note-body { padding: 10px 12px; white-space: pre-wrap; }
/* 内部备注：琥珀色卡片 + 标签，一眼看出“这行客户看不到” */
.note.note-internal { border-color: #fcd34d; }
.note.note-internal > header { background: #fffbeb; border-bottom-color: #fde68a; }
.note.note-internal .note-body { background: #fffdf5; }

/* 回复表单：回复客户 / 内部备注 两个页签 + 提交 */
.reply-box { border-top: 1px solid var(--border); background: #fcfcfd; padding: 10px 14px 12px; }
.reply-tabs { display: flex; gap: 6px; margin-bottom: 8px; }
.reply-tabs .tab {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 999px;
  padding: 3px 12px;
  font-size: 12px;
  cursor: pointer;
}
.reply-tabs .tab.active {
  background: var(--primary-soft);
  border-color: #c7d7fe;
  color: var(--primary);
  font-weight: 600;
}
.reply-box textarea { min-height: 62px; }
.reply-box .row { margin-top: 8px; align-items: center; }

/* 接待上限设置条：标签 + 数字框 + 单位 + 保存按钮。
   `.input`（约 40px 高）与 `.btn.small`（约 29px 高）默认高度差很多，
   这里统一给 38px 高度，四者才能在同一条基线上对齐。 */
.cap-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cap-bar .cap-label { font-size: 13px; color: var(--muted); margin-right: 2px; }
.cap-bar .cap-input {
  width: 72px;
  height: 38px;
  padding: 0 6px;
  text-align: center;
  font-size: 15px;
  font-weight: 600;
  /* 去掉数字输入框的上下箭头占位，数字居中才好看（仍可用键盘上下键调整） */
  -moz-appearance: textfield;
  appearance: textfield;
}
.cap-bar .cap-input::-webkit-outer-spin-button,
.cap-bar .cap-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.cap-bar .cap-unit { font-size: 13px; color: var(--muted); }
.cap-bar .cap-save { height: 38px; padding: 0 16px; font-size: 13px; }
.cap-hint { margin: 10px 0 0; }

/* ---------------- 客服管理：账号卡片 ---------------- */
/* 每个客服一张卡片：头像 + 名称/账号 + 角色/状态标签 + 接待量进度条 + 最近活跃与操作。
   卡片宽度自适应（auto-fill），窄屏自动变成一列，不用另写媒体查询。 */
.agent-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(266px, 1fr));
  gap: 12px;
  margin-top: 12px;
}
.agent-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
.agent-card:hover { border-color: #d3d8e0; box-shadow: var(--shadow); }
/* 已停用的账号：整体压暗（但操作按钮仍保持可读） */
.agent-card.is-off { background: #fafafa; }
.agent-card.is-off .agent-card-head,
.agent-card.is-off .agent-card-tags,
.agent-card.is-off .agent-load { opacity: .55; }
.agent-card-head { display: flex; align-items: center; gap: 10px; min-width: 0; }
.agent-card-head .avatar { flex: 0 0 40px; width: 40px; height: 40px; font-size: 18px; }
.agent-card-id { display: flex; flex-direction: column; min-width: 0; line-height: 1.35; }
.agent-card-id strong,
.agent-card-id .small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* 在线状态圆点：颜色与 .tag 的几档一致 */
.agent-dot { flex: 0 0 9px; width: 9px; height: 9px; border-radius: 50%; background: #cbd5e1; }
.agent-dot.online { background: var(--success); }
.agent-dot.busy { background: var(--warn); }
.agent-dot.away { background: #ca8a04; }
.agent-card-tags { display: flex; flex-wrap: wrap; gap: 6px; }
/* 接待量：进度条 + “接待中 / 上限”，满员变红（提醒不会再自动分配） */
.agent-load { display: flex; align-items: center; gap: 8px; }
.agent-load-bar { flex: 1; height: 6px; border-radius: 999px; background: #eef1f5; overflow: hidden; }
.agent-load-bar > i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--primary);
  transition: width .2s;
}
.agent-load.full .agent-load-bar > i { background: var(--danger); }
.agent-card-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
}

/* 窄屏：侧栏落到消息下面；再窄则列表在上、面板在下 */
@media (max-width: 1240px) {
  .pane-body { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
  .pane-side { border-left: none; border-top: 1px solid var(--border); max-height: 44%; }
}
@media (max-width: 900px) {
  .split-layout { grid-template-columns: 1fr; height: auto; }
  .list-rows { max-height: 40vh; }
  .pane-main .msg-list { max-height: 62vh; }
  .pane-placeholder { display: none; }
}

.msg-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 60vh;
  overflow: auto;
  padding: 8px 4px;
}
/* 微信式布局：头像在气泡外侧。
   注意：宽度上限必须放在 `.msg > div` 上（它是一个「收缩到内容」的 flex 子项），
   写在 `.bubble` 上的百分比会以这个自动宽度为基准 → 短消息被压成「一个字一行」、
   长消息被无谓压窄（与浮窗踩的是同一个坑，见 README 7.1）。 */
.msg { display: flex; gap: 8px; align-items: flex-start; }
.msg.visitor { justify-content: flex-start; }
/* 客服/机器人的消息靠右，并且头像排到最外侧
   ⚠️ 别写成 `flex-direction: row-reverse; justify-content: flex-end`：
   反向主轴下 flex-end 是**左端**，整条消息会被推回左边（只留下头像在气泡右侧的假象）。 */
.msg.bot, .msg.agent { justify-content: flex-end; }
.msg.bot .avatar, .msg.agent .avatar { order: 2; }
.msg.system { justify-content: center; }
/* 内容列：自己不撑满，内部气泡按文字宽度收缩 */
.msg > div {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  max-width: 72%;
  min-width: 0;
}
.msg.bot > div, .msg.agent > div { align-items: flex-end; }
.msg.system > div { align-items: center; }

.avatar {
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  overflow: hidden;
  background: #eef1f5;
  color: #4b5563;
  font-size: 17px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  user-select: none;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar.bot { background: #e6f4ea; }
.avatar.agent { background: #e8f0fe; }
/* 浮窗首页品牌区头像（没配时预览的就是租户名称首字） */
.avatar.brand { background: #eef2ff; }

/* 头像编辑控件 */
.avatar-field { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.avatar-field .avatar { flex: 0 0 44px; width: 44px; height: 44px; font-size: 22px; }
.avatar-field .fields { flex: 1; min-width: 0; }
.avatar-field .row { margin-bottom: 6px; }
.msg .bubble {
  max-width: 100%;
  padding: 8px 12px;
  border-radius: 12px;
  background: #f3f4f6;
  white-space: pre-wrap;
  /* anywhere：分子级的断行能力，长 URL/订单号也能在气泡内折行 */
  overflow-wrap: anywhere;
}
.msg.agent .bubble { background: var(--primary); color: #fff; }
.msg.bot .bubble { background: #eef7ee; }
.msg.system .bubble { background: #f9fafb; color: var(--muted); font-size: 12px; }
.msg .meta { font-size: 11px; color: var(--muted); margin-top: 3px; }
.msg .meta .row { flex-wrap: wrap; }
.msg.draft .bubble { border: 1px dashed var(--warn); background: #fffaf0; }
.msg.failed .bubble { border: 1px solid #fecaca; background: #fff5f5; }

.composer { border-top: 1px solid var(--border); padding-top: 10px; margin-top: 10px; }
.composer textarea { min-height: 68px; }

/* ---------------- 附件与表情（会话 / 工单输入区共用，另见 console/attachments.js） ---------------- */
/* 表情面板用 absolute 定位贴在输入区上方，所以这三个容器要充当定位参考 */
.composer, .reply-box, .field { position: relative; }

/* 待发送的附件条：选完文件先上传，发送前可以逐个删掉 */
.attach-bar { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 220px;
  padding: 3px 6px 3px 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fafbfc;
  font-size: 12px;
}
.attach-chip img { width: 26px; height: 26px; object-fit: cover; border-radius: 6px; display: block; }
.attach-chip .chip-ico { font-size: 15px; }
.attach-chip .chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-chip .chip-x {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 11px;
  padding: 0 2px;
}
.attach-chip .chip-x:hover { color: var(--danger); }

/* 气泡 / 工单卡片里的附件：图片用缩略图（点开原图），其他文件用下载卡片 */
.attach-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.attach-thumb {
  display: block;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  line-height: 0;
}
.attach-thumb img { display: block; max-width: 220px; max-height: 180px; }
.attach-file {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 260px;
  padding: 6px 9px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-size: 12px;
}
.attach-file:hover { border-color: var(--primary); text-decoration: none; }
.attach-file .attach-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-file .attach-size { color: var(--muted); font-size: 11px; }
.msg.out .attach-list { justify-content: flex-end; }

/* 表情面板 */
.emoji-panel {
  position: absolute;
  bottom: 100%;
  left: 0;
  margin-bottom: 6px;
  z-index: 40;
  width: 244px;
  max-height: 168px;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  padding: 6px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
}
.emoji-panel button {
  border: 0;
  background: transparent;
  cursor: pointer;
  font-size: 17px;
  line-height: 1;
  padding: 4px;
  border-radius: 6px;
}
.emoji-panel button:hover { background: #f1f3f6; }

.kv { display: grid; grid-template-columns: 90px minmax(0, 1fr); gap: 6px 10px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }

.timeline { list-style: none; margin: 0; padding: 0; font-size: 12px; color: var(--muted); }
.timeline li { padding: 4px 0; border-bottom: 1px dashed var(--border); }

/* ---------------- 提示 ---------------- */
#toasts {
  position: fixed;
  right: 18px;
  bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
}
.toast {
  background: #111827;
  color: #fff;
  padding: 9px 14px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  font-size: 13px;
  max-width: 320px;
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

/* ---------------- 一次性提示条（Django messages） ----------------
   例如「自助注册成功」的欢迎语：进入页面时显示在内容区顶部，刷新后即消失。 */
.flash-stack { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.flash {
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  background: var(--primary-soft);
  color: var(--primary);
  border: 1px solid #cddffd;
  transition: opacity .4s ease;
}
.flash.success { background: #ecfdf5; color: #047857; border-color: #a7f3d0; }
.flash.warning { background: #fffbeb; color: #b45309; border-color: #fde68a; }
.flash.error { background: #fef2f2; color: var(--danger); border-color: #fecaca; }

/* ---------------- 登录页 ---------------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #eef4ff, #f7f8fb);
}
.login-card {
  width: 360px;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 10px 30px rgba(16, 24, 40, .12);
  padding: 28px;
}
.login-card h1 { margin: 0 0 4px; font-size: 20px; }
.login-card .sub { color: var(--muted); font-size: 13px; margin-bottom: 20px; }
.login-links {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 13px;
}
.errorlist { list-style: none; padding: 0; margin: 0 0 10px; color: var(--danger); font-size: 12px; }

/* 选择租户（同一邮箱属于多个租户时的第二步） */
.tenant-choice {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 8px;
  cursor: pointer;
}
.tenant-choice:hover { border-color: #c7d7f5; background: #f8faff; }
.tenant-choice input { margin: 0; }
.tenant-choice-main { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0; }
.tenant-choice-main strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tenant-choice-user { white-space: nowrap; }

/* ---------------- 弹层 ---------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9998;
}
.modal {
  background: #fff;
  border-radius: 12px;
  width: min(680px, 92vw);
  max-height: 86vh;
  overflow: auto;
  padding: 20px;
  box-shadow: 0 20px 50px rgba(16, 24, 40, .25);
}
.modal h3 { margin: 0 0 12px; font-size: 16px; }
