:root {
  color-scheme: light;
  --wechat-green: #07c160;
  --wechat-green-dark: #06ad56;
  --chat-green: #95ec69;
  --chrome: #ededed;
  --line: #dedede;
  --muted: #8a8a8a;
  --text: #191919;
  --sidebar-width: 360px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC",
    "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #d8d8d8;
  color: var(--text);
}

button, input, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.app-shell {
  width: min(1180px, 100%);
  height: 100%;
  margin: auto;
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  background: white;
  box-shadow: 0 0 35px rgba(0, 0, 0, .1);
}

.sidebar {
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: white;
  border-right: 1px solid var(--line);
}

.topbar,
.chat-header {
  min-height: 74px;
  display: flex;
  align-items: center;
  padding: 12px 18px;
  background: var(--chrome);
  border-bottom: 1px solid #d5d5d5;
}

.topbar { justify-content: space-between; }
.topbar h1, .chat-header h2 { margin: 0; font-size: 19px; }
.topbar p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.topbar-actions { display: flex; gap: 9px; }

.icon-button,
.back-button {
  border: 0;
  background: rgba(255, 255, 255, .72);
  color: #333;
  border-radius: 7px;
  height: 38px;
  min-width: 38px;
  cursor: pointer;
  font-size: 22px;
}

.icon-button:hover { background: white; }
.icon-button.primary { background: var(--wechat-green); color: white; }

.search-wrap { padding: 10px 12px; background: #f7f7f7; }
.search-box {
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: 5px;
  color: #8a8a8a;
  background: white;
  font-size: 14px;
}

.conversation-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.conversation-row {
  width: 100%;
  height: 76px;
  border: 0;
  border-bottom: 1px solid #f0f0f0;
  padding: 10px 13px;
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  background: white;
  cursor: pointer;
}

.conversation-row:hover { background: #f5f5f5; }
.conversation-row.active { background: #dedede; }

.avatar {
  width: 48px;
  height: 48px;
  flex: 0 0 48px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  color: transparent;
  background: center / cover no-repeat url("/chatdelia-logo.jpg");
  font-size: 0;
  font-weight: 650;
}

.conversation-copy { min-width: 0; flex: 1; }
.conversation-line {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 7px;
}
.conversation-title {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 16px;
  font-weight: 500;
}
.conversation-line time { flex: 0 0 auto; color: #b1b1b1; font-size: 11px; }
.conversation-preview {
  display: block;
  overflow: hidden;
  color: #999;
  font-size: 13px;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.sidebar-footer {
  height: 38px;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 14px;
  color: #999;
  background: #f7f7f7;
  border-top: 1px solid #eee;
  font-size: 11px;
}
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #bbb; }
.status-dot.ok { background: var(--wechat-green); }
.status-dot.error { background: #fa5151; }

.chat-panel {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--chrome);
}

.chat-header { justify-content: space-between; }
.chat-title-wrap { text-align: center; }
.chat-title-wrap span { color: #888; font-size: 11px; }
.back-button { display: none; font-size: 33px; line-height: 1; background: transparent; }

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 24px clamp(16px, 4vw, 52px);
}

.empty-chat {
  height: 100%;
  display: grid;
  place-items: center;
  color: #aaa;
  text-align: center;
}
.empty-chat .empty-icon {
  width: 70px;
  height: 70px;
  margin: 0 auto 14px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  color: transparent;
  background: center / cover no-repeat url("/chatdelia-logo.jpg");
  font-size: 0;
}

.message-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 0 0 22px;
}
.message-row.user { flex-direction: row-reverse; }

.message-avatar {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  display: grid;
  place-items: center;
  border-radius: 5px;
  color: transparent;
  background: center / cover no-repeat url("/chatdelia-logo.jpg");
  font-size: 0;
  font-weight: 650;
}
.message-row.user .message-avatar {
  color: white;
  background: #5b7fbd;
  font-size: 14px;
}

.bubble-wrap {
  max-width: min(72%, 620px);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}
.message-row.user .bubble-wrap { align-items: flex-end; }

.bubble {
  position: relative;
  padding: 10px 13px;
  border: 1px solid #dedede;
  border-radius: 5px;
  background: white;
  font-size: 15px;
  line-height: 1.58;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.message-row.user .bubble {
  border-color: #8bd765;
  background: var(--chat-green);
}

.bubble-meta {
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: #9b9b9b;
  font-size: 11px;
}
.play-button {
  border: 0;
  padding: 3px 7px;
  border-radius: 4px;
  color: #666;
  background: rgba(255, 255, 255, .7);
  cursor: pointer;
}
.voice-label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 7px;
  font-weight: 600;
}
.voice-bars { letter-spacing: -2px; transform: rotate(180deg); }
.voice-transcript {
  padding-top: 7px;
  border-top: 1px solid rgba(0, 0, 0, .1);
  font-size: 13px;
  color: #3d3d3d;
}

.thinking .bubble { min-width: 58px; color: #999; letter-spacing: 3px; }

.composer {
  min-height: 76px;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 18px calc(12px + env(safe-area-inset-bottom));
  background: #f7f7f7;
  border-top: 1px solid #d4d4d4;
}

.composer textarea {
  flex: 1;
  min-height: 44px;
  max-height: 130px;
  resize: none;
  border: 0;
  border-radius: 5px;
  outline: 0;
  padding: 11px 12px;
  background: white;
  line-height: 1.4;
}
.composer textarea:focus { box-shadow: 0 0 0 1px #cfcfcf; }

.send-button,
.save-button,
.secondary-button {
  height: 42px;
  border: 0;
  border-radius: 5px;
  padding: 0 17px;
  cursor: pointer;
}
.send-button, .save-button { color: white; background: var(--wechat-green); }
.send-button:hover, .save-button:hover { background: var(--wechat-green-dark); }
.send-button:disabled { opacity: .45; cursor: default; }
.secondary-button { color: #333; background: #eee; }

.error-toast {
  margin: 0 18px 10px;
  padding: 10px 12px;
  border-radius: 5px;
  color: #c33;
  background: #fff0f0;
  font-size: 13px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, .38);
}
.modal-backdrop[hidden] { display: none; }
.settings-card {
  width: min(430px, 100%);
  padding: 22px;
  border-radius: 12px;
  background: white;
  box-shadow: 0 24px 70px rgba(0, 0, 0, .25);
}
.settings-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
}
.settings-title h2 { margin: 0; font-size: 20px; }
.settings-card label { display: block; margin: 0 0 8px; font-size: 14px; }
.settings-card input[type="url"],
.settings-card input[type="password"] {
  width: 100%;
  height: 44px;
  margin-top: 8px;
  padding: 0 11px;
  border: 1px solid #d2d2d2;
  border-radius: 6px;
  outline: 0;
}
.field-help { margin: -2px 0 18px; color: #999; font-size: 11px; }
.switch-row {
  display: flex !important;
  align-items: center;
  justify-content: space-between;
  margin: 20px 0 !important;
}
.switch-row small { display: block; margin-top: 4px; color: #999; }
.switch-row input { width: 20px; height: 20px; accent-color: var(--wechat-green); }
.settings-actions { display: flex; justify-content: flex-end; gap: 10px; }

@media (max-width: 720px) {
  .app-shell { display: block; }
  .sidebar, .chat-panel { position: absolute; inset: 0; }
  .chat-panel { transform: translateX(100%); transition: transform .22s ease; }
  body.chat-open .chat-panel { transform: translateX(0); }
  .sidebar { border-right: 0; }
  .back-button { display: block; }
  .chat-header .icon-button { background: transparent; }
  .bubble-wrap { max-width: 78%; }
  .messages { padding: 20px 13px; }
  .composer { padding-inline: 10px; }
}
