:root {
  color-scheme: light;
  font-family: "Microsoft YaHei UI", "Segoe UI", sans-serif;
  font-size: 14px;
  letter-spacing: 0;
  --accent: #0b766d;
  --accent-dark: #075c55;
  --amber: #b26a00;
  --canvas: #f3f5f6;
  --danger: #b42318;
  --ink: #18222a;
  --muted: #63717b;
  --panel: #ffffff;
  --rule: #dce3e7;
  --soft: #eef3f4;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  background: var(--canvas);
  color: var(--ink);
  margin: 0;
  min-width: 320px;
  overflow: hidden;
}

button, input, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }

.chat-shell {
  display: grid;
  grid-template-rows: 58px minmax(0, 1fr);
  height: 100vh;
  overflow: hidden;
}

.appbar {
  align-items: center;
  background: var(--panel);
  border-bottom: 1px solid var(--rule);
  display: flex;
  height: 58px;
  justify-content: space-between;
  padding: 0 22px;
}

.brand, .appbar-actions, .person-heading, .chat-header-status { align-items: center; display: flex; }
.brand { gap: 10px; }
.appbar-actions, .chat-header-status { gap: 8px; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 15px; line-height: 20px; }
.brand small { color: var(--muted); font-size: 12px; line-height: 16px; }

.brand-mark { display: grid; gap: 2px; grid-template-columns: repeat(2, 8px); grid-template-rows: repeat(2, 8px); height: 18px; width: 18px; }
.brand-mark i { background: var(--ink); display: block; }
.brand-mark i:nth-child(2) { background: var(--accent); }
.brand-mark i:nth-child(3) { background: var(--amber); }

.mode-badge, .count, .stage-badge, .conversation-status, .summary-chip, .conversion-status {
  align-items: center;
  border: 1px solid var(--rule);
  border-radius: 5px;
  color: var(--muted);
  display: inline-flex;
  font-size: 12px;
  font-weight: 700;
  min-height: 26px;
  padding: 0 8px;
  white-space: nowrap;
}

.mode-badge[data-mode="mock"] { background: #fff5da; border-color: #f2d68e; color: #875500; }
.mode-badge[data-mode="live"] { background: #e8f6f0; border-color: #a9d8ca; color: var(--accent-dark); }
.connection-button {
  align-items: center;
  background: #fff;
  border: 1px solid var(--rule);
  border-radius: 5px;
  color: var(--ink);
  display: inline-flex;
  font-size: 12px;
  font-weight: 700;
  gap: 7px;
  min-height: 30px;
  padding: 0 9px;
}
.connection-button:hover { border-color: var(--accent); }
.connection-button[data-status="connected"] { background: #e8f6f0; border-color: #a9d8ca; color: var(--accent-dark); }
.connection-dot { background: #9aa6ad; border-radius: 50%; height: 8px; width: 8px; }
.connection-button[data-status="connected"] .connection-dot { background: var(--accent); }
.stage-badge[data-stage="qualified"] { background: #e8f6f0; border-color: #a9d8ca; color: var(--accent-dark); }
.stage-badge[data-stage="handoff_pending"] { background: #fff0ed; border-color: #f2c2b9; color: #9b3e2c; }
.conversion-status[data-state="sent"] { background: #e8f6f0; border-color: #a9d8ca; color: var(--accent-dark); }
.conversion-status[data-state="added"] { background: #edf1ff; border-color: #bdc8f5; color: #3b4f9b; }
.conversion-status[data-state="waiting"] { background: #f4f6f7; }

.icon-button {
  align-items: center;
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: 5px;
  color: var(--ink);
  display: inline-flex;
  font-size: 18px;
  height: 28px;
  justify-content: center;
  line-height: 1;
  padding: 0;
  width: 28px;
}
.icon-button:hover, .text-button:hover { border-color: var(--accent); color: var(--accent); }

.chat-layout {
  display: grid;
  grid-template-columns: 304px minmax(420px, 1fr) 334px;
  min-height: 0;
  overflow: hidden;
}
.conversation-sidebar, .info-sidebar { background: var(--panel); min-width: 0; overflow: auto; }
.conversation-sidebar { border-right: 1px solid var(--rule); padding: 18px 14px; }
.info-sidebar { border-left: 1px solid var(--rule); }

.sidebar-heading, .section-header { align-items: flex-start; display: flex; justify-content: space-between; }
.sidebar-heading { margin: 0 4px 16px; }
.sidebar-heading h1, .section-header h3, .chat-header h2, .empty-state h2 { margin: 0; }
.sidebar-heading h1 { font-size: 18px; line-height: 25px; }
.eyebrow { color: var(--muted); font-size: 12px; font-weight: 700; margin: 0 0 3px; }
.subtle { color: var(--muted); margin: 3px 0 0; }

.new-lead-form, .handoff-form { display: grid; gap: 10px; }
.new-lead-form { border-bottom: 1px solid var(--rule); padding: 0 4px 16px; }
.new-lead-form label, .handoff-form label { display: grid; gap: 5px; }
.new-lead-form label span, .handoff-form label span, .field-label { color: var(--muted); font-size: 12px; font-weight: 700; }

input, textarea {
  background: #fff;
  border: 1px solid #cbd6dc;
  border-radius: 5px;
  color: var(--ink);
  outline: none;
  padding: 8px 9px;
  resize: vertical;
  width: 100%;
}
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgb(11 118 109 / 12%); }
input:disabled, textarea:disabled { background: #f0f3f4; color: #89959c; cursor: default; }
textarea[readonly] { background: #f5f7f8; color: #46535c; }

.primary-button, .secondary-button, .text-button {
  border-radius: 5px;
  font-weight: 700;
  min-height: 34px;
  padding: 0 11px;
}
.primary-button { background: var(--accent); border: 1px solid var(--accent); color: #fff; }
.primary-button:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.secondary-button { background: #fff; border: 1px solid #b6c2c8; color: var(--ink); }
.secondary-button:hover { border-color: var(--accent); color: var(--accent); }
.primary-button:disabled, .secondary-button:disabled { background: #f0f3f4; border-color: #dce3e7; color: #99a4aa; cursor: default; }
.text-button { background: transparent; border: 1px solid transparent; color: var(--accent-dark); min-height: 27px; padding: 0 5px; }
.text-button:disabled { color: #99a4aa; cursor: default; }
.full-width { width: 100%; }

.lead-list { display: grid; gap: 3px; margin-top: 14px; padding-bottom: 8px; }
.lead-row { align-items: center; background: transparent; border: 1px solid transparent; border-radius: 5px; color: var(--ink); display: grid; gap: 9px; grid-template-columns: 28px minmax(0, 1fr) 8px; min-height: 54px; padding: 7px 8px; text-align: left; width: 100%; }
.lead-row:hover { background: var(--soft); }
.lead-row.selected { background: #e5f4f0; border-color: #b7ddd3; }
.lead-avatar, .avatar { align-items: center; background: #dbe8e5; border-radius: 50%; color: var(--accent-dark); display: inline-flex; font-weight: 800; justify-content: center; }
.lead-avatar { font-size: 12px; height: 28px; width: 28px; }
.lead-row-main { display: grid; gap: 2px; min-width: 0; }
.lead-row strong, .lead-row small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lead-row small { color: var(--muted); }
.stage-dot { background: #9aa6ad; border-radius: 50%; height: 8px; width: 8px; }
.stage-qualified { background: var(--accent); }
.stage-handoff_pending, .stage-handed_off { background: #c24f3d; }
.stage-waiting_for_click { background: var(--amber); }

.conversation-main { background: #f6f8f9; display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.conversation-view { display: flex; flex: 1; flex-direction: column; min-height: 0; }
.chat-header { align-items: center; background: var(--panel); border-bottom: 1px solid var(--rule); display: flex; justify-content: space-between; min-height: 72px; padding: 12px 20px; }
.person-heading { gap: 10px; min-width: 0; }
.avatar { flex: 0 0 auto; height: 36px; width: 36px; }
.chat-header h2 { font-size: 17px; line-height: 23px; }

.message-list { display: flex; flex: 1; flex-direction: column; gap: 14px; overflow: auto; padding: 24px clamp(18px, 4vw, 54px); }
.message { display: grid; gap: 4px; max-width: min(78%, 560px); }
.message.outbound { align-self: flex-end; justify-items: end; }
.message-meta { align-items: center; color: var(--muted); display: flex; font-size: 12px; gap: 7px; }
.message p { background: #ffffff; border: 1px solid #dce3e7; border-radius: 6px; line-height: 1.55; margin: 0; padding: 9px 11px; white-space: pre-wrap; }
.message.outbound p { background: #dff3ec; border-color: #b8ded2; }
.message-empty { align-items: center; color: var(--muted); display: flex; flex: 1; justify-content: center; }

.composer { background: var(--panel); border-top: 1px solid var(--rule); display: grid; gap: 9px; grid-template-columns: minmax(0, 1fr) auto; padding: 12px 20px; }
.composer textarea { min-height: 48px; resize: none; }
.composer .primary-button { align-self: end; }

.info-section { border-bottom: 1px solid var(--rule); padding: 16px; }
.section-header { gap: 10px; margin-bottom: 11px; }
.section-header h3 { font-size: 15px; line-height: 21px; }
.summary-chip { background: var(--soft); color: var(--accent-dark); }

.qualification-list { display: grid; gap: 7px; list-style: none; margin: 0; padding: 0; }
.qualification-list li { align-items: center; display: grid; gap: 7px; grid-template-columns: 18px minmax(0, 1fr) auto; min-height: 25px; }
.qualification-list small { color: var(--muted); font-size: 12px; }
.qualification-check { align-items: center; border: 1px solid #bac6cc; border-radius: 50%; color: #fff; display: inline-flex; font-size: 11px; font-weight: 800; height: 17px; justify-content: center; width: 17px; }
.qualification-list .complete .qualification-check { background: var(--accent); border-color: var(--accent); }
.qualification-list .complete small { color: var(--accent-dark); }

.service-link { color: var(--accent-dark); display: block; font-family: Consolas, monospace; font-size: 12px; line-height: 1.5; margin-bottom: 10px; overflow-wrap: anywhere; }
.acquisition-link[hidden] { display: none; }
.field-label { display: block; margin: 0 0 5px; }
.info-section textarea { margin-bottom: 9px; }
.conversion-actions { display: grid; gap: 8px; grid-template-columns: 1fr 1fr; }
.activity-list { display: grid; gap: 10px; list-style: none; margin: 0; padding: 0; }
.activity-list li { display: grid; gap: 8px; grid-template-columns: 7px minmax(0, 1fr); }
.activity-marker { background: var(--amber); border-radius: 50%; height: 7px; margin-top: 5px; width: 7px; }
.activity-list p { line-height: 1.4; margin: 0 0 2px; }
.activity-list time { color: var(--muted); font-size: 12px; }

.empty-state { align-items: center; color: var(--muted); display: flex; flex: 1; flex-direction: column; justify-content: center; text-align: center; }
.empty-state[hidden], .conversation-view[hidden] { display: none; }
.empty-mark { align-items: center; background: var(--panel); border: 1px solid var(--rule); border-radius: 50%; color: var(--accent); display: inline-flex; font-size: 26px; height: 46px; justify-content: center; margin-bottom: 10px; width: 46px; }
.empty-state h2 { color: var(--ink); font-size: 17px; }

.connection-dialog {
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: 6px;
  box-shadow: 0 18px 48px rgb(24 34 42 / 22%);
  color: var(--ink);
  max-height: min(720px, calc(100vh - 32px));
  max-width: calc(100vw - 28px);
  padding: 0;
  width: 460px;
}
.connection-dialog::backdrop { background: rgb(24 34 42 / 38%); }
.dialog-header { align-items: center; border-bottom: 1px solid var(--rule); display: flex; justify-content: space-between; padding: 16px 18px; }
.dialog-header h2 { font-size: 18px; margin: 0; }
.connection-view { padding: 18px; }
.connection-view[hidden] { display: none; }
.connection-identity { align-items: center; display: grid; gap: 10px; grid-template-columns: 38px minmax(0, 1fr) auto; }
.connection-identity strong, .connection-identity small { display: block; }
.connection-identity small { color: var(--muted); margin-top: 2px; }
.wecom-mark { align-items: center; background: var(--accent); border-radius: 5px; color: #fff; display: inline-flex; font-size: 18px; font-weight: 800; height: 38px; justify-content: center; width: 38px; }
.connection-state { border: 1px solid var(--rule); border-radius: 5px; color: var(--muted); font-size: 12px; font-weight: 700; padding: 5px 8px; }
.connection-state[data-status="connected"] { background: #e8f6f0; border-color: #a9d8ca; color: var(--accent-dark); }
.connection-form { border-top: 1px solid var(--rule); display: grid; gap: 12px; margin-top: 18px; padding-top: 18px; }
.connection-form label { display: grid; gap: 5px; }
.connection-form label span { color: var(--muted); font-size: 12px; font-weight: 700; }
.connection-details { border-bottom: 1px solid var(--rule); border-top: 1px solid var(--rule); display: grid; gap: 0; margin: 18px 0 0; }
.connection-details div { align-items: center; border-bottom: 1px solid var(--rule); display: grid; gap: 12px; grid-template-columns: 118px minmax(0, 1fr); min-height: 42px; }
.connection-details div:last-child { border-bottom: 0; }
.connection-details dt { color: var(--muted); font-size: 12px; font-weight: 700; }
.connection-details dd { font-family: Consolas, monospace; font-size: 12px; margin: 0; overflow-wrap: anywhere; text-align: right; }
.permission-list { display: grid; gap: 0; list-style: none; margin: 12px 0 18px; padding: 0; }
.permission-list li { align-items: center; display: flex; justify-content: space-between; min-height: 34px; }
.permission-list strong { color: var(--accent-dark); font-size: 12px; }

.toast { background: var(--ink); border-radius: 5px; bottom: 20px; color: #fff; left: 50%; opacity: 0; padding: 9px 12px; pointer-events: none; position: fixed; transform: translate(-50%, 12px); transition: opacity .18s ease, transform .18s ease; z-index: 10; }
.toast.visible { opacity: 1; transform: translate(-50%, 0); }
.toast[data-tone="error"] { background: var(--danger); }
.toast[data-tone="success"] { background: var(--accent-dark); }
.visually-hidden { clip: rect(1px, 1px, 1px, 1px); height: 1px; overflow: hidden; position: absolute; width: 1px; }

@media (max-width: 1180px) {
  .chat-layout { grid-template-columns: 270px minmax(360px, 1fr) 300px; }
  .conversation-sidebar { padding: 16px 10px; }
  .info-section { padding: 14px; }
  .conversion-actions { grid-template-columns: 1fr; }
}

@media (max-width: 880px) {
  .chat-layout { grid-template-columns: 260px minmax(0, 1fr); }
  .info-sidebar { border-left: 0; border-top: 1px solid var(--rule); grid-column: 1 / -1; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .info-section { border-right: 1px solid var(--rule); }
  .activity-section { grid-column: 1 / -1; }
}

@media (max-width: 640px) {
  body { overflow: auto; }
  .chat-shell { display: block; height: auto; min-height: 100vh; overflow: visible; }
  .chat-layout { min-height: 0; overflow: visible; }
  .appbar { padding: 0 14px; }
  .brand small { display: none; }
  .mode-badge { display: none; }
  .connection-button { max-width: 150px; overflow: hidden; }
  .connection-button span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .chat-layout { display: block; }
  .conversation-sidebar { border-bottom: 1px solid var(--rule); border-right: 0; max-height: 340px; }
  .lead-list { max-height: 155px; overflow: auto; }
  .conversation-view { min-height: 560px; }
  .chat-header { padding: 12px 14px; }
  .chat-header-status { align-items: flex-end; flex-direction: column; }
  .message-list { min-height: 340px; padding: 18px 14px; }
  .message { max-width: 88%; }
  .composer { grid-template-columns: 1fr; padding: 10px 14px; }
  .composer .primary-button { width: 100%; }
  .info-sidebar { display: block; }
  .info-section { border-right: 0; }
}
