/* 客服（访客页 + 工作台）共用：与 vv09.cc 同一套样式——浅灰底、白卡片、单一蓝色点缀。
   数值照抄 vv09.cc 的 assets/css/site.css，改之前先对照它。 */
:root {
  --ink: #354052;
  --sub: #4f5b6c;
  --muted: #7d8795;
  --line: #e4e8ee;
  --field: #d9dfe8;
  --ground: #f7f8fa;
  --paper: #fff;
  --blue: #5879f5;
  --blue-deep: #4769e6;
  --blue-soft: #edf2ff;
  --danger: #d24c56;
  --ok: #2f8a5b;
  --font: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
  --bar-h: 64px;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--ground); color: var(--ink); font: 15px/1.7 var(--font); }
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
code { font: 12px var(--mono); }

/* ---------- vv09.cc 页面框架 ---------- */
.wrap { width: min(1040px, calc(100% - 40px)); margin: auto; }
.topbar { height: 72px; display: flex; align-items: center; justify-content: space-between; }
.brand-image { display: block; width: 62px; height: 62px; object-fit: contain; }
.back { color: var(--muted); font-size: 14px; }
.back:hover { color: var(--blue); }
.page-head { padding: 52px 0 36px; background: var(--paper); border-bottom: 1px solid var(--line); }
.eyebrow { color: var(--blue); font-size: 13px; font-weight: 700; letter-spacing: .08em; margin: 0 0 8px; }
.page-head h1 { font-size: clamp(32px, 5vw, 46px); margin: 0; line-height: 1.25; letter-spacing: .03em; }
.page-head p { color: var(--muted); margin: 12px 0 0; }
.content { padding: 26px 0 80px; }
.footer { border-top: 1px solid var(--line); padding: 24px 0; color: #9099a6; font-size: 13px; background: var(--paper); }
.card { background: var(--paper); border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 10px 28px rgba(37, 49, 67, .05); }

/* ---------- controls ---------- */
.field { display: grid; gap: 6px; }
.field > span { font-size: 14px; font-weight: 700; }
.field small { margin-left: 4px; font-size: 12px; font-weight: 400; color: var(--muted); }
.field .req { margin-left: 4px; font-style: normal; font-size: 12px; font-weight: 700; color: var(--danger); }
.field input, .field textarea, .composer textarea {
  width: 100%; padding: 12px 14px;
  border: 1px solid var(--field); border-radius: 11px; background: #fbfcfe;
  outline: none; transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field textarea:focus, .composer textarea:focus { border-color: #86a0ff; box-shadow: 0 0 0 3px rgba(88, 121, 245, .1); }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 11px 18px; border: 1px solid #d7def0; border-radius: 10px; background: var(--paper);
  color: #46546a; font-size: 14px; font-weight: 650; cursor: pointer;
  transition: border-color .15s, background .15s;
}
.btn:hover { border-color: var(--blue); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-ink { border-color: var(--blue); background: var(--blue); color: #fff; }
.btn-ink:hover { border-color: var(--blue-deep); background: var(--blue-deep); }
.btn:focus-visible, .link:focus-visible, .tab:focus-visible, .conv:focus-visible, .bar-out:focus-visible, .chip:focus-visible, .bot-option:focus-visible {
  outline: 2px solid var(--blue); outline-offset: 2px;
}

.link { padding: 0; border: 0; background: none; cursor: pointer; color: var(--blue); font-size: 13px; font-weight: 650; }
.link:hover { text-decoration: underline; }

.status { min-height: 1.4em; margin: 0; font-size: 13px; color: var(--muted); }
.status.is-error { color: var(--danger); }
.status.is-ok { color: var(--ok); }

/* ---------- 消息流（访客页和工作台共用） ---------- */
.stream {
  flex: 1; overflow-y: auto; margin: 0; padding: 26px; list-style: none;
  display: flex; flex-direction: column; gap: 18px;
  background: linear-gradient(180deg, #fbfcff, #f7f9fc);
}
.stream-empty { margin: auto; color: var(--muted); font-size: 14px; text-align: center; }
.msg { display: flex; flex-direction: column; align-items: flex-start; max-width: min(78%, 680px); }
.msg-meta { margin: 0 6px 5px; color: #9099a6; font-size: 12px; }
.msg-bubble {
  padding: 12px 15px; background: var(--paper); border: 1px solid #e1e6ee;
  border-radius: 15px 15px 15px 4px; box-shadow: 0 5px 12px rgba(37, 49, 67, .04);
}
.msg-bubble p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-bubble img { display: block; max-width: min(100%, 420px); max-height: 420px; margin-top: 9px; border-radius: 10px; object-fit: contain; background: #eef1f7; cursor: zoom-in; }
.msg-bubble img:first-child { margin-top: 0; }
.msg.is-mine { align-self: flex-end; align-items: flex-end; }
.msg.is-mine .msg-bubble { color: #fff; background: #6683ee; border-color: #6683ee; border-radius: 15px 15px 4px 15px; }
.msg.is-pending { opacity: .55; }

.composer { padding: 20px 22px; border-top: 1px solid var(--line); background: var(--paper); }
.composer textarea { display: block; min-height: 84px; max-height: 40vh; resize: vertical; }
.composer-row { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.composer-row input[type=file] { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.composer-row label.link { padding: 8px 12px; border: 1px solid var(--field); border-radius: 9px; color: #4c5a70; font-weight: 400; }
.composer-row label.link:hover { border-color: var(--blue); text-decoration: none; }
.file-name { max-width: 30%; overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.composer-row .status { flex: 1; min-width: 0; min-height: 0; }
.composer-row .btn { margin-left: auto; }

/* 自动回复问题按钮（访客页，输入框上方） */
.bot-menu { padding: 14px 22px 0; border-top: 1px solid var(--line); background: var(--paper); }
.bot-menu:not([hidden]) + .composer { border-top: 0; }
.bot-menu p { margin: 0 0 8px; color: var(--muted); font-size: 12px; }
.bot-options { display: flex; flex-wrap: wrap; gap: 8px; }
.bot-option { padding: 7px 13px; border: 1px solid #cdd8ff; border-radius: 999px; background: var(--blue-soft); color: var(--blue); font-size: 13px; font-weight: 650; cursor: pointer; }
.bot-option:hover { border-color: var(--blue); }
.bot-option.is-human { border-color: var(--field); background: var(--paper); color: var(--sub); }

/* ---------- 访客页（vv09.cc 在线客服页布局） ---------- */
.room { display: grid; gap: 16px; }
.room-who {
  display: flex; align-items: center; flex-wrap: wrap; gap: 4px 14px;
  padding: 15px 18px; background: var(--paper); border: 1px solid var(--line); border-radius: 14px;
  color: var(--muted); font-size: 14px;
}
.room-who b { color: var(--blue); font-size: 14px; }
.room-who .link { margin-left: auto; }
.room-panel { display: flex; flex-direction: column; overflow: hidden; }
.room-panel .stream { min-height: 390px; max-height: 58vh; }

.room-gate, .stream-welcome { margin: auto; width: 100%; max-width: 440px; padding: 40px 24px; }
.room-gate { display: grid; gap: 16px; }
.room-gate h2, .stream-welcome h3 { margin: 0; font-size: 24px; line-height: 1.3; }
.room-gate > p { margin: -6px 0 4px; color: var(--muted); }
.room-gate > p.must { color: #40506a; font-weight: 650; }
.room-gate .btn { margin-top: 4px; }
.stream-welcome { list-style: none; }
.stream-welcome p { margin: 10px 0 0; color: var(--muted); font-size: 14px; }
.stream-welcome .aside { padding-top: 12px; border-top: 1px solid var(--line); font-size: 13px; }
.stream-welcome .aside b { color: var(--ink); }

/* 嵌在 iframe 里（发卡站、主站）：去掉页头页脚，聊天区铺满 */
.is-embedded .chrome { display: none; }
.is-embedded body { background: var(--paper); }
.is-embedded .content { padding: 0; }
.is-embedded .room { width: 100%; height: 100vh; height: 100dvh; display: flex; flex-direction: column; gap: 0; }
.is-embedded .room-who { border-width: 0 0 1px; border-radius: 0; }
.is-embedded .room-panel { flex: 1; min-height: 0; border: 0; border-radius: 0; box-shadow: none; }
.is-embedded .room-panel .stream { min-height: 0; max-height: none; }

/* ---------- 工作台登录 ---------- */
.gate-card { max-width: 480px; margin: 18px auto; padding: 26px; display: grid; gap: 14px; }
.gate-card h2 { margin: 0; font-size: 22px; }
.gate-card > p { margin: -6px 0 6px; color: var(--muted); }
.gate-card .btn { justify-self: start; margin-top: 4px; }

/* ---------- 工作台 ---------- */
.desk { height: 100vh; height: 100dvh; display: grid; grid-template-rows: var(--bar-h) minmax(0, 1fr); }
.bar {
  display: flex; align-items: center; gap: clamp(16px, 3vw, 40px);
  padding: 0 clamp(14px, 2.4vw, 28px); background: var(--paper); border-bottom: 1px solid var(--line);
}
.bar-brand { display: flex; align-items: center; gap: 10px; }
.bar-brand img { width: 40px; height: 40px; object-fit: contain; }
.bar-brand span { font-size: 17px; font-weight: 700; letter-spacing: .04em; }
.tabs { display: flex; height: 100%; gap: 4px; }
.tab {
  position: relative; display: flex; align-items: center; gap: 7px;
  padding: 0 14px; border: 0; background: none; cursor: pointer;
  color: var(--muted); font-weight: 650;
}
.tab:hover, .tab.is-active { color: var(--blue); }
.tab.is-active::after { content: ""; position: absolute; left: 14px; right: 14px; bottom: -1px; height: 2px; background: var(--blue); }
.tab i, .conv-unread {
  min-width: 20px; height: 18px; padding: 0 5px; border-radius: 10px;
  display: inline-grid; place-items: center;
  background: var(--blue); color: #fff; font: 700 10px/1 var(--font); font-style: normal;
}
.bar-out { margin-left: auto; padding: 6px 2px; border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 14px; }
.bar-out:hover { color: var(--blue); }
.view { min-height: 0; }

/* 会话 */
.view-chat { display: grid; grid-template-columns: clamp(280px, 26vw, 340px) minmax(0, 1fr); }
.rail { display: flex; flex-direction: column; min-height: 0; background: #fafbfe; border-right: 1px solid var(--line); }
.rail-head { display: flex; align-items: baseline; gap: 10px; padding: 18px; border-bottom: 1px solid var(--line); }
.rail-head h2 { margin: 0; font-size: 18px; }
.rail-head > span { color: var(--muted); font-size: 12px; }
.rail-head .link { margin-left: auto; }
.batch-actions { display: flex; align-items: center; gap: 12px; padding: 10px 18px; font-size: 13px; }
.batch-actions label { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.conv-row { display: flex; align-items: center; }
.conv-row > input { flex-shrink: 0; margin: 0 0 0 14px; }
.conv-row .conv { min-width: 0; flex: 1; }
.rail-list { flex: 1; overflow-y: auto; }
.conversation-pager { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 18px; border-top: 1px solid var(--line); font-size: 12px; }
.conversation-pager select { padding: 4px; border: 1px solid var(--line); border-radius: 4px; background: var(--paper); }
.conversation-pager .status { flex-basis: 100%; margin: 0; }
.conversation-pager .status:empty { display: none; }
.link:disabled { opacity: .45; cursor: not-allowed; }
.delete-conversation { margin-left: auto; flex-shrink: 0; color: #b42318; }
.rail-empty { padding: 25px; color: var(--muted); font-size: 13px; text-align: center; }
.conv {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px;
  width: 100%; padding: 15px 17px; border: 0; border-bottom: 1px solid #ebeff4;
  background: transparent; text-align: left; cursor: pointer;
}
.conv:hover, .conv.is-active { background: #eef3ff; }
.conv-name { overflow: hidden; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.conv-time { color: #9aa2ae; font-size: 11px; line-height: 1.9; }
.conv-preview { overflow: hidden; color: #667386; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.conv-unread { justify-self: end; }
.conv.has-unread .conv-preview { color: var(--ink); }

.thread { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--paper); }
.thread-head { display: flex; align-items: center; gap: 12px; padding: 17px 22px; border-bottom: 1px solid var(--line); }
.thread-back { display: none; }
.thread-who { display: grid; gap: 6px; min-width: 0; }
.thread-who strong { font-size: 17px; line-height: 1.3; overflow-wrap: anywhere; }
.thread-ids { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: baseline; gap: 6px; max-width: 100%;
  padding: 2px 9px; border: 1px solid #e4e9f2; border-radius: 8px; background: #fafbfc;
  font: 12px/1.6 var(--mono); color: var(--ink); cursor: copy; overflow-wrap: anywhere; text-align: left;
}
.chip span { font-family: var(--font); color: var(--muted); }
.chip:hover { border-color: #9eb1ff; background: #f4f6ff; }
.thread-empty { margin: auto; padding: 32px clamp(20px, 6vw, 80px); max-width: 520px; }
.thread-empty h3 { margin: 0 0 10px; font-size: 22px; }
.thread-empty p { margin: 0 0 8px; color: var(--muted); }

/* 设置 / 客户 */
.view-settings, .view-customers { overflow-y: auto; }
.sheet { max-width: 760px; margin: 0 auto; padding: 32px clamp(16px, 4vw, 40px) 48px; display: grid; gap: 18px; }
.sheet-wide { max-width: 1040px; }
.block { display: grid; gap: 16px; padding: 26px; background: var(--paper); border: 1px solid var(--line); border-radius: 16px; }
.block-head { display: flex; align-items: center; flex-wrap: wrap; gap: 12px 24px; }
.block-head h2 { margin: 0; font-size: 20px; }
.hint { margin: -4px 0 0; max-width: 60ch; color: var(--muted); font-size: 13px; }
.sheet-wide .hint, .sheet-wide .status { margin: 0; }
.who { color: var(--muted); font-size: 13px; }
.who code { color: var(--ink); font-size: 13px; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.actions { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; }
.field textarea { min-height: 96px; resize: vertical; }
.faq { display: grid; gap: 12px; counter-reset: faq; }
.faq-item { display: grid; gap: 12px; margin: 0; padding: 16px; border: 1px solid var(--line); border-radius: 12px; background: #fafbfe; counter-increment: faq; }
.faq-head { display: flex; align-items: center; justify-content: space-between; font-size: 14px; }
.faq-head b::after { content: " " counter(faq); }

.switch { display: inline-flex; align-items: center; gap: 10px; margin-left: auto; cursor: pointer; }
.switch input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.switch span { position: relative; width: 40px; height: 22px; border-radius: 11px; background: #cfd6e2; transition: background .2s; }
.switch span::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(37, 49, 67, .3); transition: transform .2s;
}
.switch input:checked + span { background: var(--blue); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 2px solid var(--blue); outline-offset: 2px; }
.switch em { color: var(--sub); font-size: 13px; font-style: normal; font-weight: 650; }

.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.stat { display: grid; gap: 2px; padding: 20px 22px; background: var(--paper); border: 1px solid var(--line); border-radius: 16px; }
.stat b { font-size: clamp(28px, 4vw, 38px); line-height: 1.15; }
.stat span { color: var(--muted); font-size: 13px; }
.stat.is-key { background: var(--blue-soft); border-color: #cdd8ff; }
.stat.is-key b { color: var(--blue); }
.table-wrap { overflow-x: auto; background: var(--paper); border: 1px solid var(--line); border-radius: 16px; }
.roster { width: 100%; min-width: 560px; border-collapse: collapse; font-size: 14px; }
.roster th { padding: 11px 16px; background: #fafbfc; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 12px; font-weight: 650; text-align: left; }
.roster td { padding: 10px 16px; border-bottom: 1px solid #ebeff4; overflow-wrap: anywhere; }
.roster tr:last-child td { border-bottom: 0; }
.roster td:nth-child(4), .roster td:nth-child(5) { color: var(--sub); font-size: 13px; white-space: nowrap; }
.roster tr.is-paid td { background: #f4f6ff; }
.roster tr.is-paid td:nth-child(5) { color: var(--blue); font-weight: 700; }
.roster .roster-empty { padding: 28px 16px; color: var(--muted); text-align: center; }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; } }

/* ---------- phone ---------- */
@media (max-width: 760px) {
  :root { --bar-h: 56px; }
  .wrap { width: min(100% - 32px, 1040px); }
  .brand-image { width: 52px; height: 52px; }
  .page-head { padding: 35px 0 27px; }
  .room-panel .stream { min-height: 340px; max-height: 55vh; }
  .stream { padding: 17px; }
  .msg { max-width: 90%; }
  .composer { padding: 14px 16px calc(14px + env(safe-area-inset-bottom)); }
  .bot-menu { padding: 12px 16px 0; }
  .file-name { max-width: 40%; }

  .desk .bar-brand span { display: none; }
  .tabs { gap: 0; }
  .tab { padding: 0 11px; }
  .view-chat { grid-template-columns: 1fr; }
  .rail { border-right: 0; }
  .thread { display: none; }
  .view-chat.is-reading .rail { display: none; }
  .view-chat.is-reading .thread { display: flex; }
  .thread-back {
    display: grid; place-items: center; width: 36px; height: 36px; margin-left: -8px;
    border: 0; background: none; color: var(--ink); font-size: 28px; line-height: 1; cursor: pointer;
  }
  .pair { grid-template-columns: 1fr; }
  .stats { gap: 10px; }
  .stat { padding: 14px; }
  .switch { margin-left: 0; }
}
