.chat-page {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Header */
.chat-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  padding: 0 12px;
  padding-top: env(safe-area-inset-top, 0px);
  background: var(--glass-bg);
  backdrop-filter: blur(15px);
  -webkit-backdrop-filter: blur(15px);
  border-bottom: 1px solid var(--glass-border);
  z-index: 10;
  height: 60px;
}

.chat-header .back-btn {
  color: var(--text-main);
  text-decoration: none;
  font-size: 20px;
  padding: 4px 8px;
  z-index: 20;
  flex-shrink: 0;
}


.header-info {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  max-width: 50%;
  padding-top: env(safe-area-inset-top, 0px);
}

.header-info h3 {
  color: var(--text-main);
  font-weight: 500;
  font-size: 16px;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.typing-status {
  font-size: 11px;
  color: var(--text-muted);
  height: 14px;
  opacity: 0;
  transition: opacity 0.3s;
}

.typing-status.active {
  opacity: 0.6;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 2px;
  z-index: 20;
  margin-left: auto;
  flex-shrink: 0;
}

.header-icon {
  padding: 4px 6px;
  cursor: pointer;
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: center;
}

.header-icon svg {
  width: 19px;
  height: 19px;
}

/* Chat Container */
.chat-container {
  flex: 1;
  padding: 15px 12px;
  padding-top: 70px;
  padding-bottom: 70px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Message Animation */
@keyframes msgFadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.msg-row {
  display: flex;
  margin-bottom: 10px;
  align-items: flex-start;
  animation: msgFadeIn 0.25s ease-out;
}

.msg-row.no-animate {
  animation: none;
}

.msg-row.ai {
  justify-content: flex-start;
}

.msg-row.user {
  justify-content: flex-end;
}

/* Send Feedback */
.msg-row.msg-sending .bubble {
  opacity: 0.5;
  transition: opacity 0.3s;
}

.msg-row.msg-sent .bubble {
  opacity: 1;
  transition: opacity 0.3s;
}

.msg-failed-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}

.msg-failed-icon {
  color: #cc4444;
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
}

/* Avatar */
.avatar {
  width: 36px;
  height: 36px;
  min-width: 36px;
  border-radius: 50%;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 11px;
  font-weight: 600;
  color: #555;
  flex-shrink: 0;
}

.ai-avatar {
  background: rgba(255, 255, 255, 0.5);
  margin-right: 8px;
}

.user-avatar {
  background: rgba(200, 200, 210, 0.5);
  margin-left: 8px;
}

/* Message Content */
.msg-content {
  max-width: 72%;
}

.bubble {
  padding: 10px 14px;
  font-size: 15px;
  line-height: 1.5;
  word-wrap: break-word;
  word-break: break-word;
  color: var(--text-main);
}

.msg-row.ai .bubble {
  background: var(--glass-bg);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--glass-border);
  border-radius: 4px 18px 18px 18px;
}

.msg-row.user .bubble {
  background: rgba(255, 255, 255, 0.55);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid var(--glass-border);
  border-radius: 18px 4px 18px 18px;
}

.timestamp {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 3px;
  padding: 0 4px;
  opacity: 0.5;
}

.timestamp.hidden {
  display: none;
}

.msg-row.ai .timestamp { text-align: right; }
.msg-row.user .timestamp { text-align: right; }

/* Typing Dots */
.typing-bubble {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 18px;
}

.typing-bubble .dot {
  width: 7px;
  height: 7px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typing 1.4s infinite;
}

.typing-bubble .dot:nth-child(2) { animation-delay: 0.2s; }
.typing-bubble .dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
  0%, 60%, 100% { opacity: 0.3; transform: scale(0.8); }
  30% { opacity: 1; transform: scale(1); }
}

/* Input Area */
.input-area {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--glass-bg);
  backdrop-filter: blur(25px);
  -webkit-backdrop-filter: blur(25px);
  padding: 8px 10px;
  padding-bottom: 12px;
  display: flex;
  align-items: flex-end;
  border-top: 1px solid var(--glass-border);
  z-index: 10;
}

.input-left-btns {
  display: flex;
  align-items: center;
  gap: 0;
  margin-right: 4px;
  flex-shrink: 0;
}

.input-icon-btn {
  background: none;
  border: none;
  color: var(--text-main);
  padding: 6px 5px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.45;
  transition: opacity 0.2s, transform 0.25s;
}

.input-icon-btn:active {
  opacity: 0.8;
}

.input-icon-btn.active {
  opacity: 0.8;
  transform: rotate(45deg);
}

.input-icon-btn svg {
  width: 22px;
  height: 22px;
}

.input-area textarea {
  flex: 1;
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  padding: 9px 14px;
  color: var(--text-main);
  font-size: 15px;
  resize: none;
  max-height: 100px;
  min-height: 38px;
  height: 38px;
  outline: none;
  font-family: inherit;
  line-height: 1.4;
  overflow-y: hidden;
}

.input-area textarea.scrollable {
  overflow-y: auto;
}

.send-btn {
  background: transparent;
  border: none;
  color: var(--text-main);
  font-size: 20px;
  margin-left: 6px;
  margin-bottom: 4px;
  cursor: pointer;
  transition: opacity 0.2s;
  flex-shrink: 0;
  padding: 4px 6px;
}

.send-btn.dim {
  opacity: 0.2;
  pointer-events: none;
}

.send-btn.stop-mode {
  color: #cc4444;
  opacity: 1;
  pointer-events: auto;
  font-size: 16px;
}

/* Plus Panel */
.plus-panel {
  position: fixed;
  bottom: -300px;
  left: 0;
  right: 0;
  background: rgba(245, 245, 245, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid rgba(0,0,0,0.06);
  padding: 18px 15px 20px 15px;
  z-index: 9;
  transition: bottom 0.3s ease;
}

.plus-panel.show {
  bottom: 58px;
}

.plus-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px 8px;
}

.plus-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  transition: transform 0.1s;
}

.plus-item:active {
  transform: scale(0.9);
}

.plus-icon {
  width: 50px;
  height: 50px;
  background: rgba(255,255,255,0.8);
  border-radius: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.plus-label {
  font-size: 10px;
  color: #888;
}

/* Emoji Panel */
.emoji-panel {
  position: fixed;
  bottom: -300px;
  left: 0;
  right: 0;
  background: rgba(245, 245, 245, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid rgba(0,0,0,0.06);
  padding: 10px 15px 20px 15px;
  z-index: 9;
  transition: bottom 0.3s ease;
  min-height: 160px;
}

.emoji-panel.show {
  bottom: 58px;
}

.emoji-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-size: 13px;
  color: #888;
}

.emoji-add-btn {
  width: 26px;
  height: 26px;
  background: rgba(0,0,0,0.05);
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: #888;
  cursor: pointer;
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.emoji-empty {
  grid-column: 1 / -1;
  text-align: center;
  color: #bbb;
  font-size: 12px;
  padding: 25px 0;
}

/* Time Separator */
.time-separator {
  text-align: center;
  padding: 8px 0;
  animation: msgFadeIn 0.25s ease-out;
}

.time-separator-text {
  display: inline-block;
  font-size: 10px;
  color: var(--text-muted);
  background: rgba(0,0,0,0.03);
  padding: 2px 10px;
  border-radius: 8px;
  opacity: 0.6;
}

/* Pat Pat */
.pat-message {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  padding: 6px 0;
  opacity: 0.6;
  animation: msgFadeIn 0.25s ease-out;
}

@keyframes avatarShake {
  0%, 100% { transform: rotate(0deg); }
  20% { transform: rotate(-10deg); }
  40% { transform: rotate(8deg); }
  60% { transform: rotate(-6deg); }
  80% { transform: rotate(4deg); }
}

.avatar-shaking {
  animation: avatarShake 0.4s ease;
}

/* Long Press Menu */
.msg-menu-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.25);
  z-index: 100;
  display: none;
}

.msg-menu-overlay.show { display: block; }

.msg-menu {
  position: fixed;
  z-index: 101;
  background: rgba(255,255,255,0.88);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(0,0,0,0.06);
  border-radius: 12px;
  min-width: 150px;
  padding: 4px 0;
  box-shadow: 0 6px 24px rgba(0,0,0,0.12);
  display: none;
}

.msg-menu.show {
  display: block;
  animation: menuFadeIn 0.12s ease-out;
}

@keyframes menuFadeIn {
  from { opacity: 0; transform: scale(0.92); }
  to { opacity: 1; transform: scale(1); }
}

.msg-menu-item {
  display: flex;
  align-items: center;
  padding: 10px 14px;
  cursor: pointer;
  gap: 8px;
}

.msg-menu-item:active {
  background: rgba(0,0,0,0.04);
}

.msg-menu-item-icon {
  font-size: 15px;
  width: 20px;
  text-align: center;
}

.msg-menu-item-text {
  font-size: 14px;
  color: #333;
}

.msg-menu-item.disabled {
  opacity: 0.3;
  pointer-events: none;
}

.msg-menu-item.danger .msg-menu-item-text {
  color: #cc4444;
}

.msg-menu-divider {
  height: 1px;
  background: rgba(0,0,0,0.06);
  margin: 3px 10px;
}

.msg-row.msg-selected .bubble {
  box-shadow: 0 0 0 2px rgba(100,150,255,0.35);
}

/* Edit Bar */
.edit-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(25px);
  -webkit-backdrop-filter: blur(25px);
  padding: 8px 12px 12px 12px;
  display: none;
  align-items: center;
  border-top: 1px solid rgba(0,0,0,0.06);
  z-index: 50;
  gap: 8px;
}

.edit-bar.show { display: flex; }

.edit-bar textarea {
  flex: 1;
  background: rgba(0,0,0,0.03);
  border: 1px solid rgba(0,0,0,0.08);
  border-radius: 16px;
  padding: 9px 14px;
  color: #333;
  font-size: 15px;
  resize: none;
  max-height: 100px;
  min-height: 38px;
  outline: none;
  font-family: inherit;
  line-height: 1.4;
}

.edit-bar-cancel {
  padding: 6px 12px;
  background: none;
  border: none;
  color: #999;
  font-size: 13px;
  cursor: pointer;
}

.edit-bar-save {
  padding: 6px 12px;
  background: rgba(0,0,0,0.06);
  border: none;
  border-radius: 14px;
  color: #333;
  font-size: 13px;
  cursor: pointer;
}

/* Recall */
.msg-recall {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  padding: 6px 0;
  opacity: 0.6;
  animation: msgFadeIn 0.25s ease-out;
}

/* Quote Bar */
.quote-bar {
  position: fixed;
  bottom: 58px;
  left: 0;
  right: 0;
  background: rgba(245,245,245,0.95);
  backdrop-filter: blur(15px);
  -webkit-backdrop-filter: blur(15px);
  padding: 6px 12px;
  display: none;
  align-items: center;
  border-top: 1px solid rgba(0,0,0,0.06);
  z-index: 11;
  gap: 8px;
}

.quote-bar.show { display: flex; }

.quote-bar-content {
  flex: 1;
  font-size: 12px;
  color: #999;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  border-left: 2px solid rgba(0,0,0,0.12);
  padding-left: 8px;
}

.quote-bar-name {
  font-size: 11px;
  color: #777;
  font-weight: 500;
}

.quote-bar-close {
  background: none;
  border: none;
  font-size: 16px;
  color: #bbb;
  cursor: pointer;
  padding: 2px 6px;
}

/* Quote in bubble */
.bubble-quote {
  background: rgba(0,0,0,0.03);
  border-left: 2px solid rgba(0,0,0,0.12);
  padding: 4px 8px;
  margin-bottom: 6px;
  border-radius: 3px;
  font-size: 12px;
  color: #999;
  max-height: 50px;
  overflow: hidden;
}

.bubble-quote-name {
  font-size: 10px;
  color: #aaa;
  margin-bottom: 1px;
}

/* Load More */
.load-more-wrap {
  text-align: center;
  padding: 12px 0;
}

.load-more-spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(0,0,0,0.08);
  border-top-color: rgba(0,0,0,0.3);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.load-more-end {
  text-align: center;
  padding: 10px 0;
  font-size: 11px;
  color: var(--text-muted);
  opacity: 0.5;
}
/* ===== 搜索面板 ===== */
.search-panel {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-primary, #f5f7fa);
  z-index: 500;
  flex-direction: column;
}
.search-panel.active {
  display: flex;
}
.search-panel-bar {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  gap: 10px;
  border-bottom: 1px solid var(--border-color, #e0e0e0);
  background: var(--bg-secondary, #fff);
}
.search-panel-icon {
  flex-shrink: 0;
}
.search-panel .search-input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--border-color, #e0e0e0);
  border-radius: 10px;
  background: var(--bg-primary, #f5f7fa);
  color: var(--text-primary, #333);
  font-size: 15px;
  outline: none;
}
.search-panel .search-input:focus {
  border-color: var(--accent-color, #6ea8d7);
}
.search-count {
  font-size: 12px;
  color: var(--text-secondary, #999);
  white-space: nowrap;
}
.search-close-btn {
  background: none;
  border: none;
  font-size: 20px;
  color: var(--text-secondary, #999);
  cursor: pointer;
  padding: 4px 8px;
}
.search-nav {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 8px;
  border-bottom: 1px solid var(--border-color, #e0e0e0);
  background: var(--bg-secondary, #fff);
  font-size: 13px;
  color: var(--text-secondary, #999);
}
.search-nav.active {
  display: flex;
}
.search-nav-btn {
  background: var(--bg-primary, #f5f7fa);
  border: 1px solid var(--border-color, #e0e0e0);
  border-radius: 50%;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-primary, #333);
}
.search-results {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}
.search-result-item {
  display: flex;
  flex-direction: column;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color, #e0e0e0);
  cursor: pointer;
  gap: 4px;
}
.search-result-item:active {
  background: var(--bg-primary, #f5f7fa);
}
.search-result-role {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-color, #6ea8d7);
}
.search-result-content {
  font-size: 14px;
  color: var(--text-primary, #333);
  line-height: 1.5;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.search-result-content mark {
  background: #fff3a8;
  color: inherit;
  padding: 0 2px;
  border-radius: 2px;
}
.search-result-time {
  font-size: 11px;
  color: var(--text-secondary, #999);
}
.search-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-secondary, #999);
  font-size: 14px;
}
.msg-highlight {
  animation: highlightFade 2s ease;
}
@keyframes highlightFade {
  0% { background: rgba(110, 168, 215, 0.3); }
  100% { background: transparent; }
}
