/* 聊天面板：沿用 Claude 风格的纸面与陶土色 */

.chat-fab {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 55;
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  padding: 0;
  border: 0;
  border-radius: 26px;
  background: var(--accent);
  color: #fdfbf7;
  cursor: pointer;
  overflow: hidden;
  box-shadow: 0 8px 24px -8px rgba(189, 93, 58, .55);
  transition: width .34s cubic-bezier(.2, .7, .3, 1), gap .34s cubic-bezier(.2, .7, .3, 1),
              box-shadow .18s ease, opacity .18s ease, transform .18s ease;
}
.chat-fab:hover { transform: translateY(-2px); box-shadow: 0 12px 28px -8px rgba(189, 93, 58, .65); }
.chat-fab svg { width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.chat-fab-label {
  max-width: 0;
  opacity: 0;
  overflow: hidden;
  white-space: nowrap;
  font-size: 13px;
  letter-spacing: .01em;
  transition: max-width .34s cubic-bezier(.2, .7, .3, 1), opacity .22s ease .04s;
}
.chat-fab.is-open { opacity: 0; pointer-events: none; }

/* 鼠标设备上悬停展开成“和 Friend 聊天” */
@media (hover: hover) and (pointer: fine) {
  .chat-fab:hover { width: var(--fab-w, 178px); gap: 8px; }
  .chat-fab:hover .chat-fab-label { max-width: 160px; opacity: 1; }
  .chat-fab:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
}

.chat-panel {
  position: fixed;
  right: 22px;
  bottom: 86px;
  z-index: 60;
  width: 366px;
  max-width: calc(100vw - 32px);
  height: min(552px, calc(100vh - 130px));
  display: flex;
  flex-direction: column;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 24px 60px -24px rgba(30, 24, 16, .5), 0 2px 8px rgba(30, 24, 16, .06);
  overflow: hidden;
  animation: chat-in .22s cubic-bezier(.2, .7, .3, 1);
}
.chat-panel[hidden] { display: none; }
@keyframes chat-in {
  from { opacity: 0; transform: translateY(10px) scale(.98); }
  to { opacity: 1; transform: none; }
}

.chat-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 16px 13px;
  border-bottom: 1px solid var(--line);
  background: var(--side);
}
.chat-head strong {
  display: block;
  font-family: var(--serif);
  font-size: 15px;
  font-weight: 500;
  letter-spacing: .01em;
}
.chat-sub { display: block; margin-top: 2px; font-size: 11.5px; color: var(--muted); }

.chat-close {
  width: 26px; height: 26px;
  display: grid; place-items: center;
  border: 1px solid transparent;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  transition: color .16s ease, border-color .16s ease;
}
.chat-close:hover { color: var(--accent); border-color: var(--line); }

.chat-log {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
.chat-log::-webkit-scrollbar { width: 8px; }
.chat-log::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }

.chat-empty {
  margin: auto 4px;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.8;
  text-align: center;
}

.msg { display: flex; flex-direction: column; gap: 3px; max-width: 86%; }
.msg.me { align-self: flex-end; align-items: flex-end; }
.msg.friend { align-self: flex-start; align-items: flex-start; }
.msg-body {
  padding: 9px 12px;
  border-radius: 12px;
  font-size: 13.2px;
  line-height: 1.72;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg.me .msg-body { background: var(--accent); color: #fdfbf7; border-bottom-right-radius: 4px; }
.msg.friend .msg-body { background: var(--chip); color: var(--text-2); border-bottom-left-radius: 4px; }
.msg-time { font-size: 10.5px; color: var(--muted); font-family: var(--mono); }
.msg.pending .msg-body { opacity: .72; }

.chat-typing { display: flex; gap: 4px; padding: 4px 2px; }
.chat-typing i {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--muted);
  animation: chat-dot 1.1s infinite;
}
.chat-typing i:nth-child(2) { animation-delay: .15s; }
.chat-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes chat-dot {
  0%, 60%, 100% { opacity: .3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-2px); }
}

.chat-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px 12px;
  border-top: 1px solid var(--line);
  background: var(--paper);
}
.chat-form textarea {
  flex: 1;
  min-height: 38px;
  max-height: 108px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--side);
  color: var(--text);
  font-family: var(--sans);
  font-size: 13.2px;
  line-height: 1.5;
  resize: none;
  outline: none;
  transition: border-color .16s ease;
}
.chat-form textarea:focus { border-color: var(--accent); }
.chat-form button {
  flex: none;
  height: 38px;
  padding: 0 14px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: #fdfbf7;
  font-family: var(--sans);
  font-size: 13px;
  cursor: pointer;
  transition: opacity .16s ease, transform .16s ease;
}
.chat-form button:hover { transform: translateY(-1px); }
.chat-form button:disabled { opacity: .5; cursor: default; transform: none; }

.chat-hint { padding: 0 12px 10px; font-size: 11px; color: var(--muted); }
.chat-hint.is-error { color: #c0492b; }

@media (max-width: 560px) {
  .chat-fab { right: 16px; bottom: 16px; width: 48px; height: 48px; }
  .chat-panel {
    right: 10px; left: 10px; bottom: 72px;
    width: auto;
    height: min(560px, calc(100vh - 96px));
  }
}

@media print {
  .chat-fab, .chat-panel { display: none !important; }
}
