:root {
  color-scheme: light;
  --wechat-green: #95ec69;
  --wechat-green-hover: #86df5d;
  --page-bg: #ededed;
  --panel-bg: #f7f7f7;
  --sidebar-bg: #e9e9e9;
  --rail-bg: #2e2e2e;
  --text-main: #191919;
  --text-subtle: #999999;
  --line: #e5e5e5;
  --white: #ffffff;
  --danger: #c7463d;
  --radius: 8px;
  font-family: "Microsoft YaHei UI", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

* { box-sizing: border-box; }
html { height: 100%; background: var(--page-bg); }
body {
  width: 100%;
  height: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  color: var(--text-main);
  background: var(--page-bg);
}
button, input, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

/* A desktop-like app window around the WeChat-inspired chat surface. */
.app-window {
  position: fixed;
  z-index: 10;
  left: 50%;
  top: 50%;
  display: flex;
  flex-direction: column;
  width: min(1240px, calc(100vw - 72px));
  height: min(850px, calc(100dvh - 86px));
  min-width: 620px;
  min-height: 500px;
  overflow: hidden;
  transform: translate(-50%, -50%);
  background: var(--panel-bg);
  border: 1px solid rgb(0 0 0 / 10%);
  border-radius: 10px;
  box-shadow: 0 18px 60px rgb(0 0 0 / 18%), 0 2px 8px rgb(0 0 0 / 7%);
}
.app-window.is-positioned { transform: none; }
.app-window.is-maximized {
  inset: 0 !important;
  width: 100vw !important;
  height: 100dvh !important;
  min-width: 0;
  min-height: 0;
  max-width: none;
  border: 0;
  border-radius: 0;
  transform: none !important;
  box-shadow: none;
}
.app-window[hidden] { display: none !important; }
.window-titlebar {
  position: relative;
  z-index: 20;
  flex: 0 0 36px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
  color: #383838;
  background: #f5f5f5;
  border-bottom: 1px solid #e6e6e6;
  user-select: none;
  cursor: grab;
  touch-action: none;
}
.window-titlebar:active { cursor: grabbing; }
.window-title-drag-area { display: flex; align-items: center; gap: 9px; min-width: 0; height: 100%; padding: 0 12px; pointer-events: none; }
.window-title-icon { display: block; width: 19px; height: 19px; border-radius: 4px; object-fit: cover; }
.window-title-text { overflow: hidden; font-size: 12px; font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }
.window-controls { align-self: stretch; display: flex; flex: 0 0 auto; }
.window-control { width: 44px; height: 35px; display: grid; place-items: center; padding: 0; color: #555; border: 0; border-radius: 0; background: transparent; cursor: pointer; }
.window-control:hover { background: #e6e6e6; }
.window-control svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 1.15; stroke-linecap: round; stroke-linejoin: round; }
.window-control .icon-restore { display: none; }
.app-window.is-maximized #window-maximize .icon-maximize { display: none; }
.app-window.is-maximized #window-maximize .icon-restore { display: block; }
.window-control.close-control:hover { color: #fff; background: #e81123; }
.desktop-taskbar {
  position: fixed;
  z-index: 5;
  left: 50%;
  bottom: 10px;
  display: flex;
  align-items: center;
  min-height: 40px;
  padding: 4px;
  transform: translateX(-50%);
  background: rgb(248 248 248 / 92%);
  border: 1px solid rgb(0 0 0 / 9%);
  border-radius: 9px;
  box-shadow: 0 4px 20px rgb(0 0 0 / 9%);
  backdrop-filter: blur(14px);
}
.taskbar-app { display: flex; align-items: center; gap: 8px; min-height: 31px; padding: 4px 11px; color: #333; background: transparent; border: 0; border-radius: 5px; cursor: pointer; font-size: 12px; }
.taskbar-app:hover, .taskbar-app.is-active { background: #e9e9e9; }
.taskbar-app img { width: 21px; height: 21px; border-radius: 4px; object-fit: cover; }

.wechat-app {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: flex;
  width: 100%;
  height: auto;
  overflow: hidden;
  background: var(--white);
}

/* Narrow dark strip inspired by WeChat Desktop. */
.tool-rail {
  flex: 0 0 62px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  padding: 20px 0 20px;
  color: #b8b8b8;
  background: var(--rail-bg);
}
.rail-top, .rail-bottom { display: flex; flex-direction: column; align-items: center; gap: 25px; }
.brand-icon { display: block; width: 31px; height: 31px; border-radius: 7px; object-fit: cover; }
.rail-icon {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  padding: 8px;
  color: #b7b7b7;
  background: transparent;
  border: 0;
  border-radius: 5px;
}
.rail-icon.active { color: #9be879; }
.rail-icon svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.rail-user-avatar { width: 28px; height: 28px; border-radius: 4px; object-fit: cover; }

.conversation-sidebar {
  flex: 0 0 258px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--sidebar-bg);
  border-right: 1px solid #dedede;
}
.sidebar-profile {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px 0 18px;
}
.profile-copy { min-width: 0; }
.profile-name { overflow: hidden; color: #202020; font-size: 15px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.profile-status { display: flex; align-items: center; gap: 6px; margin-top: 6px; color: #858585; font-size: 12px; }
.online-dot, .contact-online-dot { width: 6px; height: 6px; border-radius: 50%; background: #63bd51; }
.profile-avatar { width: 35px; height: 35px; border-radius: 4px; object-fit: cover; }
.search-box {
  height: 31px;
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 12px 16px;
  padding: 0 9px;
  color: #888;
  background: #dedede;
  border-radius: 4px;
}
.search-box svg { width: 14px; height: 14px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; }
.search-box input { width: 100%; min-width: 0; padding: 0; border: 0; outline: 0; color: #333; background: transparent; font-size: 13px; }
.search-box input::placeholder { color: #929292; }
.search-box:focus-within { box-shadow: inset 0 0 0 1px #c8c8c8; }
.section-caption { padding: 0 17px 9px; color: #9a9a9a; font-size: 12px; letter-spacing: .4px; }
.contact-item {
  width: 100%;
  min-height: 70px;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px 13px;
  text-align: left;
  border: 0;
  background: transparent;
  cursor: pointer;
}
.contact-item[hidden] { display: none; }
.contact-item:hover { background: #dedede; }
.contact-item.selected, .contact-item.selected:hover { background: #cfcfcf; }
.contact-avatar-wrap { position: relative; flex: 0 0 43px; width: 43px; height: 43px; }
.contact-avatar { width: 43px; height: 43px; display: block; border-radius: 4px; object-fit: cover; }
.contact-online-dot { position: absolute; right: -2px; bottom: -2px; width: 9px; height: 9px; border: 2px solid #cfcfcf; }
.contact-copy { display: block; flex: 1; min-width: 0; }
.contact-topline { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.contact-name { overflow: hidden; font-size: 14px; font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }
.contact-time { flex: 0 0 auto; color: #999; font-size: 10px; }
.contact-preview { display: block; overflow: hidden; margin-top: 7px; color: #929292; font-size: 12px; line-height: 1.3; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-footnote { margin: auto 13px 13px; color: #a1a1a1; font-size: 10px; text-align: center; }

.chat-pane {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--page-bg);
}
.chat-header {
  position: relative;
  z-index: 1;
  flex: 0 0 62px;
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) 46px;
  align-items: center;
  padding: 0 17px;
  background: #f7f7f7;
  border-bottom: 1px solid #e4e4e4;
}
.chat-title-wrap { min-width: 0; text-align: center; }
.chat-title { margin: 0; overflow: hidden; color: #222; font-size: 17px; font-weight: 500; line-height: 1.35; text-overflow: ellipsis; white-space: nowrap; transition: color .16s ease; }
.chat-title.is-typing { color: #777; font-size: 13px; font-weight: 400; }
.chat-subtitle { display: block; min-height: 3px; margin-top: 2px; color: #aaa; font-size: 10px; line-height: 1.1; }
.header-spacer { display: block; }
.header-end-mark { display: flex; align-items: center; justify-content: flex-end; color: #777; }
.header-end-mark svg { width: 22px; height: 22px; fill: currentColor; }

.messages {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 20px;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 24px clamp(18px, 4vw, 54px) 22px;
  overscroll-behavior: contain;
  scrollbar-color: #c8c8c8 transparent;
  scrollbar-width: thin;
}
.conversation-start { display: flex; flex-direction: column; align-items: center; gap: 12px; margin: 0 auto 8px; color: #b4b4b4; font-size: 11px; text-align: center; }
.conversation-start p { margin: 0; }
.date-pill { padding: 5px 10px; border-radius: 4px; color: #f8f8f8; background: #d3d3d3; font-size: 10px; }
.message-row { width: 100%; display: flex; align-items: flex-start; gap: 10px; animation: message-in .16s ease-out; }
.message-row.user { flex-direction: row-reverse; }
.message-avatar { flex: 0 0 39px; width: 39px; height: 39px; display: block; border-radius: 4px; object-fit: cover; background: #ddd; }
.message-content { display: flex; flex-direction: column; align-items: flex-start; max-width: min(76%, 620px); min-width: 0; }
.message-row.user .message-content { align-items: flex-end; }
.message-name { margin: 0 0 5px; color: #a1a1a1; font-size: 10px; line-height: 1.2; }
.message-bubble {
  position: relative;
  max-width: 100%;
  padding: 10px 12px;
  color: #1f1f1f;
  background: var(--white);
  border-radius: 4px;
  box-shadow: 0 1px 1px rgb(0 0 0 / 2%);
  font-size: 16px;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: normal;
}
.message-row.user .message-bubble { background: var(--wechat-green); }
.message-bubble.error { color: #9b3b34; background: #fff4f2; border: 1px solid #f2d1cc; }
.time-divider { align-self: center; display: flex; justify-content: center; width: 100%; margin: -3px 0; pointer-events: none; }
.time-divider-label { display: inline-block; padding: 4px 9px; color: #fafafa; background: #d2d2d2; border-radius: 4px; font-size: 12px; font-weight: 400; line-height: 1.2; font-variant-numeric: tabular-nums; }
.system-notice-error { color: #a53c35; background: #fff0ee; border: 1px solid #f3d0cc; }
.system-notice { align-self: center; max-width: min(90%, 440px); padding: 7px 11px; color: #8d8d8d; background: rgb(211 211 211 / 55%); border-radius: 4px; font-size: 11px; line-height: 1.5; text-align: center; }
.error-banner { flex: 0 0 auto; margin: 0 24px 8px; padding: 9px 12px; color: #a53c35; background: #fff0ee; border: 1px solid #f3d0cc; border-radius: 4px; font-size: 12px; line-height: 1.5; }
.error-banner[hidden] { display: none; }

.composer {
  flex: 0 0 auto;
  min-height: 174px;
  display: flex;
  flex-direction: column;
  padding: 12px clamp(18px, 3vw, 31px) max(13px, env(safe-area-inset-bottom));
  background: #f7f7f7;
  border-top: 1px solid #e2e2e2;
}
.composer-topline { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.composer-hint { color: #a2a2a2; font-size: 11px; }
.char-count { color: #aaa; font-size: 11px; font-variant-numeric: tabular-nums; }
.char-count.near-limit { color: #c34d45; }
#message-input {
  width: 100%;
  min-height: 62px;
  max-height: 120px;
  flex: 1 1 auto;
  resize: none;
  overflow-y: auto;
  padding: 2px 0 7px;
  border: 0;
  outline: 0;
  color: #222;
  background: transparent;
  font-size: 15px;
  line-height: 1.65;
}
#message-input::placeholder { color: #b5b5b5; }
.composer-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 8px; }
.composer-privacy { color: #b0b0b0; font-size: 10px; letter-spacing: .1px; }
.send-button {
  min-width: 78px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 13px;
  color: #1b1b1b;
  background: var(--wechat-green);
  border: 0;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  transition: background .15s ease, opacity .15s ease;
}
.send-button:hover:not(:disabled) { background: var(--wechat-green-hover); }
.send-button:disabled { cursor: wait; opacity: .65; }
.send-button svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; clip-path: inset(50%); }

@keyframes message-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 900px) {
  .app-window { width: calc(100vw - 32px); height: calc(100dvh - 78px); min-width: 580px; min-height: 480px; }
  .conversation-sidebar { flex-basis: 225px; }
  .tool-rail { flex-basis: 54px; }
  .messages { padding-right: 22px; padding-left: 22px; }
}

@media (max-width: 680px) {
  html, body { width: 100%; height: 100%; min-height: 100%; }
  body { background: var(--page-bg); }
  .app-window, .app-window.is-maximized {
    inset: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    min-width: 0;
    min-height: 0;
    transform: none;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }
  .window-titlebar, .desktop-taskbar { display: none; }
  .wechat-app {
    width: 100%;
    height: 100%;
    min-height: 0;
    border-radius: 0;
    box-shadow: none;
  }
  .tool-rail, .conversation-sidebar { display: none; }
  .chat-pane { width: 100%; }
  .chat-header {
    flex-basis: calc(54px + env(safe-area-inset-top));
    padding-top: env(safe-area-inset-top);
    padding-right: 14px;
    padding-left: 14px;
    grid-template-columns: 30px minmax(0, 1fr) 30px;
  }
  .header-end-mark { justify-content: center; }
  .chat-title { font-size: 16px; }
  .chat-title.is-typing { font-size: 13px; }
  .messages {
    gap: 17px;
    padding: 18px 13px 16px;
  }
  .message-row { gap: 8px; }
  .message-avatar { width: 36px; height: 36px; flex-basis: 36px; }
  .message-content { max-width: calc(100% - 48px); }
  .message-bubble { padding: 10px 12px; font-size: 16px; }
  .composer {
    min-height: 148px;
    padding: 9px 12px max(10px, env(safe-area-inset-bottom));
  }
  .composer-hint { font-size: 10px; }
  #message-input { min-height: 50px; max-height: 112px; font-size: 16px; }
  .composer-privacy { font-size: 9px; }
  .error-banner { margin-right: 12px; margin-left: 12px; }
}

@media (max-height: 620px) and (min-width: 681px) {
  .app-window { height: calc(100dvh - 58px); min-height: 0; }
  .desktop-taskbar { bottom: 5px; min-height: 34px; }
  .window-titlebar { flex-basis: 32px; }
  .window-control { height: 31px; }
}

@media (max-width: 360px) {
  .chat-header { grid-template-columns: 18px minmax(0, 1fr) 22px; padding-right: 10px; padding-left: 10px; }
  .messages { padding-right: 9px; padding-left: 9px; }
  .message-avatar { width: 32px; height: 32px; flex-basis: 32px; }
  .message-content { max-width: calc(100% - 41px); }
  .composer { padding-right: 9px; padding-left: 9px; }
  .send-button { min-width: 68px; padding: 0 9px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
