/* 微信式聊天编辑器：消息区独立滚动，编辑器始终是聊天容器的底部区域。 */

.app-main,
.chat-container {
  min-width: 0;
  min-height: 0;
}

.chat-container {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.message-list {
  scroll-behavior: auto;
}

.input-container {
  position: relative;
  z-index: 20;
  display: flex;
  width: auto;
  min-height: 0;
  flex: 0 0 auto;
  flex-direction: column;
  align-items: stretch;
  margin: 0;
  padding: 8px 22px calc(9px + var(--wx-safe-bottom));
  border-top: 1px solid #dcdcdc;
  background: #f7f7f7;
  overflow: visible;
  overflow-anchor: none;
  isolation: isolate;
  -webkit-transform: none;
  transform: none;
  transition: none;
}

/* 保留真实文件控件的可唤起能力，避免 iOS 12 对 display:none 的限制。 */
.file-input-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  border: 0;
  opacity: 0;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.message-input {
  display: block;
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
}

.input-wrapper {
  display: flex;
  width: 100%;
  min-width: 0;
  align-items: flex-end;
  gap: 4px;
}

.file-button,
.emoji-button {
  display: grid;
  width: 38px;
  height: 42px;
  flex: 0 0 38px;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: #666;
  cursor: pointer;
  touch-action: manipulation;
}

.file-button:hover,
.file-button:active,
.emoji-button:hover,
.emoji-button:active {
  background: #e9e9e9;
  color: #333;
}

.input-field-container {
  display: flex;
  min-width: 0;
  min-height: 42px;
  flex: 1 1 auto;
  align-items: flex-end;
  gap: 4px;
  padding: 3px 5px 3px 10px;
  border: 1px solid #d7d7d7;
  border-radius: 4px;
  background: #fff;
}

.input-field-container:focus-within {
  border-color: #9bd8ab;
}

.input-field-container textarea {
  display: block;
  min-width: 0;
  min-height: 34px;
  max-height: 120px;
  flex: 1 1 auto;
  padding: 7px 2px;
  border: 0;
  border-radius: 0;
  outline: 0;
  background: transparent;
  color: #222;
  font-size: 15px;
  line-height: 20px;
  resize: none;
  -webkit-appearance: none;
}

.input-field-container textarea::placeholder {
  color: #a0a0a0;
}

.function-button,
.function-button.show {
  display: grid;
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  place-items: center;
  margin: 0;
  padding: 0;
  border: 1.5px solid #626262;
  border-radius: 50%;
  outline: 0;
  background: transparent;
  color: #595959;
  cursor: pointer;
  opacity: 1;
  transform: none;
  box-shadow: none;
  transition: none;
  touch-action: manipulation;
}

.function-button.hide {
  display: none;
}

/* 加号是工具按钮，不在 hover 时旋转、变色或放大。 */
.function-button:hover,
.function-button:active,
.function-button:focus,
.function-button:focus-visible {
  border-color: #626262;
  outline: 0;
  background: transparent !important;
  color: #595959 !important;
  transform: none;
  box-shadow: none !important;
  filter: none;
}

.function-button:hover:not(:disabled),
.function-button:active:not(:disabled) {
  background: transparent !important;
  color: #595959 !important;
  transform: none !important;
  box-shadow: none !important;
}

.function-button .function-icon {
  display: block;
  width: 19px;
  height: 19px;
  color: currentColor;
  fill: none;
  transform: none;
  transition: none;
}

.function-button .function-icon path {
  stroke: currentColor;
  stroke-width: 2.2;
}

.function-button:hover .function-icon,
.function-button:active .function-icon,
.function-button:focus .function-icon,
.function-button:focus-visible .function-icon {
  transform: none !important;
  transition: none !important;
}

.send-button,
.send-button.show {
  display: none;
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: var(--wx-green);
  color: #fff;
  cursor: pointer;
  opacity: 1;
  transform: none;
  box-shadow: none;
  transition: none;
}

.send-button.show {
  display: grid;
}

.send-button:hover:not(:disabled),
.send-button:active:not(:disabled) {
  background: var(--wx-green-dark);
}

.send-button:disabled {
  cursor: default;
  opacity: 0.55;
}

.send-button.loading .send-icon {
  opacity: 0;
}

.upload-status {
  position: absolute;
  right: 22px;
  bottom: calc(100% + 8px);
  left: 22px;
  z-index: 3;
  display: flex;
  min-height: 34px;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border: 1px solid #dedede;
  border-radius: 4px;
  background: #fff;
  color: #666;
  font-size: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
}

.upload-progress {
  min-width: 80px;
  flex: 1;
  height: 4px;
  overflow: hidden;
  border-radius: 2px;
  background: #ededed;
}

.progress-bar {
  width: 0;
  height: 100%;
  background: var(--wx-green);
}

/* 桌面端辅助面板从编辑器上方展开，背景沿用微信面板灰。 */
.function-menu,
.emoji-picker-overlay {
  position: absolute;
  right: 0;
  bottom: 100%;
  left: 0;
  z-index: 12000;
  display: none;
  height: 0;
  min-width: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  opacity: 1;
  pointer-events: none;
  transform: none;
}

.function-menu.show,
.emoji-picker-overlay {
  display: block;
  pointer-events: auto;
}

.function-menu-overlay {
  position: fixed;
  z-index: 0;
  inset: 0;
  background: transparent;
}

.function-menu-content,
.emoji-picker-modal {
  position: absolute;
  right: 22px;
  bottom: 0;
  left: auto;
  z-index: 1;
  width: min(430px, calc(100vw - 44px));
  max-width: none;
  max-height: min(430px, calc(var(--wx-viewport-height) - 150px));
  overflow: hidden auto;
  border: 1px solid #d9d9d9;
  border-radius: 8px;
  background: #f7f7f7;
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.16);
}

.function-menu-header,
.emoji-picker-header {
  display: flex;
  min-height: 46px;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  border-bottom: 1px solid #e4e4e4;
  background: #f7f7f7;
}

.function-menu-header::before {
  display: none;
}

.function-menu-header h3,
.emoji-picker-title {
  margin: 0;
  color: #444;
  font-size: 14px;
  font-weight: 500;
}

.function-menu-close,
.emoji-picker-close {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: #777;
  cursor: pointer;
}

.function-menu-close:hover,
.emoji-picker-close:hover {
  background: #e9e9e9;
  color: #333;
}

.function-menu-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px 6px;
  padding: 14px;
}

.function-menu-item {
  display: flex;
  min-width: 0;
  min-height: 78px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 6px 3px;
  border-radius: 5px;
  cursor: pointer;
}

.function-menu-item:hover,
.function-menu-item:active {
  background: #e9e9e9;
}

.function-menu-item-icon {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  margin-bottom: 6px;
  border: 1px solid #e1e1e1;
  border-radius: 6px;
  background: #fff;
  font-size: 23px;
}

.function-menu-item-content {
  min-width: 0;
  width: 100%;
  text-align: center;
}

.function-menu-item-title {
  overflow: hidden;
  color: #555;
  font-size: 11px;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.emoji-picker-modal {
  width: min(480px, calc(100vw - 44px));
}

.emoji-picker-content {
  max-height: calc(min(430px, var(--wx-viewport-height) - 150px) - 46px);
  padding: 13px 14px 15px;
  overflow: auto;
}

.emoji-category-title {
  margin-bottom: 8px;
  color: #999;
  font-size: 11px;
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 3px;
}

.emoji-item {
  display: grid;
  min-width: 0;
  min-height: 40px;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  font-size: 24px;
  cursor: pointer;
}

.emoji-item:hover,
.emoji-item:focus-visible {
  outline: 0;
  background: #e9e9e9;
}

body.aux-panel-open .input-container {
  z-index: 12001;
}

/* 桌面端：工具栏、文本区、发送按钮符合 PC 微信的垂直分区。 */
@media (min-width: 721px) {
  .input-container {
    height: 184px;
    min-height: 184px;
    padding: 0 24px 14px;
  }

  .message-input {
    height: 100%;
    max-width: none;
  }

  .input-wrapper {
    position: relative;
    display: block;
    height: 100%;
  }

  .file-button,
  .emoji-button,
  .function-button,
  .send-button {
    position: absolute !important;
    z-index: 2;
  }

  .file-button,
  .emoji-button,
  .function-button {
    top: 9px;
    width: 34px;
    height: 34px;
  }

  .file-button {
    left: 0;
  }

  .emoji-button {
    left: 40px;
  }

  .input-field-container {
    position: static;
    display: block;
    height: 100%;
    min-height: 0;
    overflow: visible;
    padding: 40px 0 38px;
    border: 0;
    background: transparent;
  }

  .input-field-container:focus-within {
    border-color: transparent;
  }

  .input-field-container textarea {
    width: 100%;
    height: 100% !important;
    min-height: 0;
    max-height: none;
    padding: 2px 0;
    background: transparent;
    font-size: 15px;
    line-height: 22px;
    overflow-y: auto;
  }

  .function-button,
  .function-button.show {
    left: 80px;
    border: 0;
    border-radius: 4px;
  }

  .send-button,
  .send-button.show {
    right: 0;
    top: auto;
    bottom: 0;
    display: none;
    width: 80px;
    height: 32px;
    border-radius: 4px;
  }

  .send-button:not(.show) {
    display: grid;
    background: #e5e5e5;
    color: #999;
    cursor: default;
    pointer-events: none;
  }

  .send-button.show {
    display: grid;
  }

  .send-button .send-icon {
    display: none;
  }

  .send-button::after {
    content: "发送";
    font-size: 13px;
  }

  .send-button,
  .send-button.show,
  .send-button:hover:not(:disabled),
  .send-button:active:not(:disabled),
  .send-button:focus,
  .send-button:focus-visible,
  .send-button.loading {
    transform: none !important;
    transition: none !important;
    box-shadow: none !important;
  }

  .send-button.loading .send-icon {
    animation: none !important;
  }

  .send-button:hover:not(:disabled),
  .send-button:active:not(:disabled) {
    background: var(--wx-green) !important;
  }

  .function-menu-content,
  .emoji-picker-modal {
    right: auto;
    left: 24px;
    width: min(520px, calc(100vw - 48px), calc(100% - 48px));
    max-height: min(420px, calc(var(--wx-viewport-height) - 220px));
  }

  .emoji-picker-modal {
    width: min(560px, calc(100vw - 48px), calc(100% - 48px));
  }

  .emoji-picker-content {
    max-height: calc(min(420px, var(--wx-viewport-height) - 220px) - 46px);
  }
}

/* 移动端：编辑器随视觉视口落在键盘上方，消息列表仍是唯一滚动区。 */
@media (max-width: 720px) {
  html,
  body {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    min-height: 0;
    overflow: hidden;
    overscroll-behavior: none;
  }

  .app {
    position: fixed;
    top: 0;
    right: 0;
    left: 0;
    width: 100%;
    height: calc(
      100% - var(--wx-keyboard-inset, 0px) -
        var(--wx-viewport-offset-top, 0px)
    );
    max-height: calc(
      100% - var(--wx-keyboard-inset, 0px) -
        var(--wx-viewport-offset-top, 0px)
    );
    overflow: hidden;
    transform: translate3d(0, var(--wx-app-top-correction, 0px), 0);
  }

  .app-main,
  .chat-container {
    height: 100%;
    max-height: 100%;
  }

  .chat-container {
    grid-template-rows: 56px minmax(0, 1fr) auto;
  }

  .input-container {
    position: relative;
    right: auto;
    bottom: auto;
    left: auto;
    grid-row: 3;
    width: 100%;
    padding: 4px max(6px, env(safe-area-inset-right))
      calc(4px + var(--wx-safe-bottom))
      max(6px, env(safe-area-inset-left));
    background: #f7f7f7;
  }

  :root.wx-keyboard-open .input-container,
  body.aux-panel-open .input-container {
    padding-bottom: 2px;
  }

  .message-input {
    width: 100%;
    padding: 0;
  }

  .message-list {
    padding-bottom: 14px;
    scroll-padding-bottom: 14px;
  }

  .input-wrapper {
    align-items: center;
    gap: 1px;
  }

  .file-button,
  .emoji-button {
    width: 36px;
    height: 40px;
    flex-basis: 36px;
  }

  .input-field-container {
    align-items: center;
    min-height: 40px;
    gap: 4px;
    padding: 0;
    border: 0;
    background: transparent;
  }

  .input-field-container:focus-within {
    border-color: transparent;
  }

  .input-field-container textarea {
    min-height: 40px;
    max-height: 104px;
    padding: 8px 12px;
    border: 1px solid #d9d9d9;
    border-radius: 20px;
    background: #fff;
    font-size: 16px;
    line-height: 22px;
    overflow-y: auto !important;
  }

  .function-button,
  .function-button.show,
  .send-button,
  .send-button.show {
    position: static;
    width: 34px;
    height: 34px;
    flex-basis: 34px;
    align-self: center;
    transform: none !important;
  }

  .file-button,
  .emoji-button,
  .function-button,
  .send-button {
    align-self: center !important;
  }

  .function-button,
  .function-button.show {
    border: 1.5px solid #626262;
    border-radius: 50%;
  }

  .send-button,
  .send-button.show {
    border-radius: 4px;
  }

  .function-menu,
  .emoji-picker-overlay {
    position: relative;
    inset: auto;
    order: 2;
    display: block;
    width: 100%;
    height: auto;
    flex: 0 0 auto;
    pointer-events: auto;
  }

  .function-menu:not(.show) {
    display: none;
  }

  .function-menu-overlay {
    position: fixed;
    z-index: 0;
    inset: 0;
    background: transparent;
    pointer-events: none;
  }

  .function-menu-content,
  .emoji-picker-modal {
    position: relative;
    inset: auto;
    z-index: 1;
    width: 100%;
    max-height: min(390px, 45vh);
    max-height: min(390px, 45dvh);
    border-right: 0;
    border-left: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .function-menu-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 7px 4px;
    padding: 12px 9px 14px;
  }

  .function-menu-item {
    min-height: 72px;
  }

  .emoji-picker-content {
    max-height: min(390px, 45vh);
    max-height: min(390px, 45dvh);
    padding: 12px 9px calc(14px + var(--wx-safe-bottom));
  }

  .emoji-grid {
    grid-template-columns: repeat(8, minmax(0, 1fr));
  }

  .emoji-item {
    min-height: 42px;
    font-size: 25px;
  }
}

@media (max-width: 380px) {
  .file-button,
  .emoji-button {
    width: 33px;
    flex-basis: 33px;
  }

  .function-menu-item-icon {
    width: 40px;
    height: 40px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .function-button,
  .function-button .function-icon {
    transition: none !important;
  }
}
