* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; }
body {
  margin: 0;
  color: #1f2937;
  background: #f3f6fa;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  font-size: 14px;
  display: grid;
  place-items: center;
  padding: 24px;
}
button, textarea, input { font: inherit; }
button { cursor: pointer; }
.client {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: min(900px, 100%);
  height: min(680px, calc(100vh - 48px));
  height: min(680px, calc(100dvh - 48px));
  min-height: 600px;
  overflow: hidden;
  background: #f7f9fc;
  border: 1px solid #d9e1ec;
  border-radius: 4px;
  box-shadow: 0 12px 36px rgba(15, 23, 42, .14);
}
.client-head {
  min-height: 86px;
  padding: 16px 16px 14px;
  border-bottom: 1px solid #dce8f5;
  background: #f7fbff;
}
.head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 12px;
}
.brand-img {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #e8f3ff;
  box-shadow: inset 0 0 0 1px #cfe5ff;
}
.brand-copy { min-width: 0; }
.brand-title {
  overflow: hidden;
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.brand-sub {
  margin-top: 5px;
  overflow: hidden;
  color: #6b7280;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.status-pill {
  display: inline-flex;
  height: 28px;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  border-radius: 14px;
  background: #edf7ff;
  color: #2563eb;
  white-space: nowrap;
  font-size: 12px;
}
.status-pill::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #fbbf24;
}
.status-pill.online::before { background: #34d399; }
.notice-bar {
  display: none;
  margin-top: 14px;
  padding: 9px 10px;
  border-radius: 8px;
  background: #eef6ff;
  color: #2563eb;
  line-height: 1.45;
  font-size: 12px;
}
.notice-bar.show { display: block; }
.notice-bar.dark {
  background: #111827;
  color: #fff;
  box-shadow: 0 8px 22px rgba(15,23,42,.22);
}
.message-area {
  overflow: auto;
  padding: 16px 14px 18px;
  background: linear-gradient(180deg, rgba(22,119,255,.05), transparent 92px), #f7f9fc;
}
.time-chip {
  width: fit-content;
  margin: 0 auto 16px;
  padding: 4px 10px;
  border-radius: 11px;
  background: #dbe3ee;
  color: #667085;
  font-size: 12px;
}
.msg {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  margin-bottom: 14px;
}
.msg.me { justify-content: flex-end; }
.avatar {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border-radius: 10px;
  background: #1677ff;
  overflow: hidden;
}
.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.msg.me .avatar { display: none; }
.bubble-wrap {
  max-width: min(72%, 520px);
  min-width: 0;
}
.name {
  margin: 0 0 5px;
  color: #667085;
  font-size: 12px;
}
.bubble {
  padding: 10px 12px;
  border-radius: 4px 12px 12px 12px;
  background: #fff;
  box-shadow: 0 5px 18px rgba(15,23,42,.06);
  color: #253044;
  line-height: 1.6;
  word-break: break-word;
}
.msg.me .bubble {
  border-radius: 12px 4px 12px 12px;
  background: #1677ff;
  color: #fff;
  box-shadow: 0 6px 18px rgba(22,119,255,.18);
}
.msg.recalled .bubble {
  border-color: #e5e7eb;
  background: #f3f4f6;
  color: #6b7280;
  box-shadow: none;
  font-style: italic;
}
.recalled-text { color: #6b7280; }
.chat-img {
  display: block;
  max-width: min(360px, 100%);
  max-height: 260px;
  border-radius: 4px;
  object-fit: contain;
}
.meta {
  margin-top: 5px;
  color: #98a2b3;
  font-size: 11px;
}
.welcome-card {
  margin: 2px 0 14px 43px;
  max-width: min(72%, 520px);
  padding: 12px;
  border: 1px solid #e6edf5;
  border-radius: 4px;
  background: #fff;
  box-shadow: 0 5px 18px rgba(15,23,42,.06);
}
.welcome-title {
  margin: 0 0 10px;
  color: #344054;
  font-weight: 700;
}
.quick-list {
  display: grid;
  gap: 8px;
}
.quick-btn {
  width: 100%;
  min-height: 34px;
  padding: 7px 10px;
  border: 1px solid #dbeafe;
  border-radius: 4px;
  background: #f8fbff;
  color: #2563eb;
  text-align: left;
}
.composer {
  border-top: 1px solid #d9e1ec;
  background: #fff;
}
.tool-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  padding: 7px 10px 0;
}
.tool-btn {
  display: inline-flex;
  width: 32px;
  height: 32px;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #667085;
  font-size: 18px;
}
.tool-btn:hover { background: #f2f4f7; }
.tool-btn:disabled {
  opacity: .45;
  cursor: not-allowed;
}
.tool-btn img {
  display: block;
  width: 18px;
  height: 18px;
  pointer-events: none;
}
.emoji-panel {
  display: none;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 10px;
  border-top: 1px solid #f0f2f5;
}
.emoji-panel.open { display: flex; }
.emoji-panel button {
  width: 32px;
  height: 32px;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  background: #fff;
  font-size: 18px;
}
.input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
  padding: 8px 10px 10px;
}
.input {
  width: 100%;
  min-height: 64px;
  max-height: 120px;
  padding: 9px 0;
  border: 0;
  outline: none;
  resize: none;
  color: #1f2937;
  line-height: 1.5;
}
.send {
  min-width: 70px;
  height: 36px;
  border: 0;
  border-radius: 6px;
  background: #1677ff;
  color: #fff;
  font-weight: 600;
}
.send:disabled {
  background: #cbd5e1;
  cursor: default;
}
.offline-drawer {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 5;
  display: none;
  padding: 14px;
  border-top: 1px solid #d9e1ec;
  background: #fff;
  box-shadow: 0 -14px 34px rgba(15,23,42,.12);
}
.offline-drawer.open { display: block; }
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.drawer-title {
  margin: 0;
  font-size: 16px;
}
.close-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 8px;
  background: #f3f6fa;
  transition: background .16s ease, box-shadow .16s ease, transform .16s ease;
}
.close-btn:hover {
  background: #e8eef7;
  box-shadow: 0 4px 12px rgba(15, 23, 42, .1);
}
.close-btn:active { transform: scale(.96); }
.close-btn:focus-visible {
  outline: 2px solid rgba(22, 119, 255, .35);
  outline-offset: 2px;
}
.close-btn img {
  width: 20px;
  height: 20px;
  display: block;
}
.field {
  width: 100%;
  height: 38px;
  margin-bottom: 9px;
  padding: 0 10px;
  border: 1px solid #d0d5dd;
  border-radius: 6px;
  outline: none;
}
.field.textarea {
  height: 88px;
  padding: 9px 10px;
  resize: vertical;
  line-height: 1.5;
}
.drawer-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.ghost,
.primary {
  height: 36px;
  padding: 0 14px;
  border-radius: 6px;
}
.ghost {
  border: 1px solid #d0d5dd;
  background: #fff;
  color: #344054;
}
.primary {
  border: 0;
  background: #1677ff;
  color: #fff;
}
.kf-msg-menu {
  position: fixed;
  z-index: 20;
  display: none;
  min-width: 96px;
  padding: 6px;
  border: 1px solid #dbe3ee;
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 12px 28px rgba(15, 23, 42, .18);
}
.kf-msg-menu.open { display: block; }
.kf-msg-menu button {
  display: block;
  width: 100%;
  height: 34px;
  padding: 0 10px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: #1f2937;
  text-align: left;
}
.kf-msg-menu button:hover { background: #f1f5f9; }
@media (max-width: 780px) {
  body {
    padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  }
  .client {
    width: 100%;
    height: calc(100vh - 20px);
    height: calc(100dvh - 20px);
    min-height: 0;
  }
  .bubble-wrap, .welcome-card { max-width: 84%; }
}
@media (max-width: 520px) {
  body { padding: 0; }
  .client {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }
  .client-head {
    min-height: 76px;
    padding: 12px 12px 10px;
  }
  .head-row { align-items: flex-start; }
  .brand {
    gap: 9px;
    max-width: calc(100% - 92px);
  }
  .brand-img {
    width: 34px;
    height: 34px;
  }
  .status-pill {
    height: 26px;
    padding: 0 8px;
  }
  .notice-bar { margin-top: 10px; }
  .message-area { padding: 12px 10px 14px; }
  .bubble-wrap, .welcome-card { max-width: 88%; }
  .welcome-card { margin-left: 39px; }
  .chat-img {
    max-width: min(260px, 100%);
    max-height: 220px;
  }
  .tool-row {
    min-height: 34px;
    padding: 5px 8px 0;
  }
  .input-row {
    grid-template-columns: minmax(0, 1fr) 64px;
    gap: 8px;
    padding: 6px 8px 8px;
  }
  .input {
    min-height: 54px;
    max-height: 86px;
  }
  .send {
    min-width: 64px;
    height: 34px;
  }
  .offline-drawer { padding: 12px; }
  .drawer-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
  .ghost, .primary { width: 100%; }
}
@media (max-width: 360px) {
  .brand { max-width: 100%; }
  .head-row { flex-wrap: wrap; }
  .status-pill { margin-left: 43px; }
  .input-row { grid-template-columns: 1fr; }
  .send { width: 100%; }
}
@media (max-height: 620px) and (max-width: 780px) {
  .client-head {
    min-height: 64px;
    padding-top: 10px;
    padding-bottom: 8px;
  }
  .brand-sub { display: none; }
  .notice-bar {
    margin-top: 8px;
    padding: 7px 8px;
  }
  .input { min-height: 46px; }
}
