.chat-header {
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.95);
  border-bottom: 0.5px solid rgba(0, 0, 0, 0.1);
  position: relative;
  z-index: 100;
}

.chat-header-actions {
  width: 60px;
  justify-content: flex-end;
}

.chat-home-btn {
  display: flex;
  color: #4e6fae;
}

.chat-home-btn .chat-home-icon {
  opacity: 0.95;
  transform: translateY(-0.2px);
}

.chat-back-btn,
.chat-menu-btn {
  display: none;
}

.chat-back-btn {
  color: #345d96;
  justify-content: center;
  padding: 0 !important;
}

.chat-back-btn svg {
  width: 18px;
  height: 18px;
  transform: translateX(-0.5px);
}

.chat-sort-btn,
.chat-add-btn {
  display: flex;
}

.chat-list-page {
  padding-top: 0;
}

.group-chat-toggle {
  display: none;
  padding: 8px 16px;
  background: rgba(255, 255, 255, 0.95);
  border-bottom: 0.5px solid rgba(0, 0, 0, 0.1);
  align-items: center;
  justify-content: space-between;
}

.group-chat-toggle.is-visible {
  display: flex;
}

.group-chat-toggle-label {
  font-size: 14px;
  color: #666;
}

.group-members-section {
  margin-top: 16px;
  padding: 0 20px;
}

.group-members-title {
  font-size: 13px;
  color: #999;
  margin-bottom: 8px;
}

.group-members-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.group-chat-settings.is-hidden {
  display: none;
}

.group-chat-settings-card {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
}

.group-chat-settings-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.group-chat-settings-icon {
  width: 40px;
  height: 40px;
}

.group-chat-settings-text {
  text-align: left;
}

.group-chat-settings-title {
  font-size: 15px;
  font-weight: 500;
  color: #333;
}

.group-chat-settings-subtitle {
  font-size: 12px;
  color: #999;
}

.group-chat-frequency-card {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 16px 20px;
  gap: 12px;
}

.group-chat-frequency-range {
  width: 100%;
  -webkit-appearance: none;
  height: 4px;
  background: #e9e9ea;
  border-radius: 2px;
  outline: none;
}

.group-chat-frequency-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  background: #FF2442;
  border-radius: 50%;
  cursor: pointer;
}

.archive-view,
.diary-view {
  background: #F2F2F7;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.archive-header,
.diary-header {
  background: white;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.archive-back-btn,
.diary-back-btn {
  color: #007AFF;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 2px;
  width: 100px;
}

.archive-settings-btn,
.diary-add-btn {
  width: 100px;
  justify-content: flex-end;
}

.diary-list {
  flex: 1;
  overflow-y: auto;
  padding: 20px 0;
}

/* ============================================
   Stitch UI Overrides - Chat Flow + Related Views
   ============================================ */
[data-project="chat"]#chatView {
  background: var(--app-gradient);
  --chat-header-h: 48px;
  --chat-header-offset: 8px;
  --chat-composer-h: 82px;
}

[data-project="chat"]#chatView #chatListPage,
[data-project="chat"]#chatView #chatConversationPage,
[data-project="chat"]#chatView #friendDetailPage {
  background: transparent !important;
}

[data-project="chat"]#chatView .chat-subview {
  background: transparent !important;
}

[data-project="chat"]#chatView #chatConversationPage {
  padding-top: 0;
  height: 100%;
  min-height: 100%;
}

[data-project="chat"]#chatView .chat-header {
  background: transparent !important;
  border-bottom: none !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  position: absolute;
  top: calc(var(--chat-header-offset) + var(--safe-top));
  left: 0;
  right: 0;
  height: var(--chat-header-h);
  padding: 0 16px;
  z-index: 110;
  pointer-events: auto;
}

[data-project="chat"]#chatView .chat-header .nav-title {
  pointer-events: none;
}

[data-project="chat"]#chatView .chat-header .nav-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}

[data-project="chat"]#chatView .chat-header .nav-action-btn,
[data-project="chat"]#chatView .chat-header .shell-menu-btn {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.7);
  box-shadow: var(--shadow-sm);
}

[data-project="chat"]#chatView .chat-header-actions {
  width: auto;
  gap: 10px;
}

/* Chat list layout */
[data-project="chat"]#chatView .chat-list-container {
  background: transparent;
  padding-top: calc(var(--chat-header-h) + var(--chat-header-offset) + var(--safe-top));
}

[data-project="chat"]#chatView .chat-search-box {
  background: transparent;
  padding: 12px 20px 10px;
}

[data-project="chat"]#chatView .search-inner {
  background: rgba(255, 255, 255, 0.9);
  border-radius: 999px;
  padding: 14px 18px;
  box-shadow: var(--shadow-soft);
  border: 1px solid rgba(255, 255, 255, 0.7);
  color: var(--text-tertiary);
  justify-content: flex-start;
}

[data-project="chat"]#chatView .search-inner svg {
  opacity: 0.6;
}

.chat-quick-row {
  display: flex;
  gap: 16px;
  padding: 4px 20px 14px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.chat-quick-row::-webkit-scrollbar {
  display: none;
}

.chat-quick-item {
  width: 72px;
  flex: 0 0 auto;
  text-align: center;
}

.chat-quick-avatar {
  width: 64px;
  height: 64px;
  margin: 0 auto 8px;
  border-radius: var(--radius-full);
  background: var(--glass-bg);
  border: 2px solid rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.chat-quick-avatar > * {
  width: 100%;
  height: 100%;
}

.chat-quick-avatar img {
  object-fit: cover;
}

.chat-quick-avatar .avatar-text,
.chat-quick-avatar .avatar-emoji {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
}

.chat-quick-avatar-add {
  background: rgba(255, 255, 255, 0.94);
  color: #ff7ba7;
  border: 1.5px solid rgba(255, 153, 194, 0.55);
  box-shadow: 0 8px 18px rgba(255, 143, 180, 0.18);
}

.chat-quick-avatar-add svg {
  width: 20px;
  height: 20px;
  stroke-width: 1.65;
  opacity: 0.92;
}

.chat-quick-name {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

[data-project="chat"]#chatView .chat-sort-label {
  background: transparent;
  padding: 6px 20px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: none;
  letter-spacing: 0.2px;
}

[data-project="chat"]#chatView .chat-list {
  background: transparent;
  padding: 0 16px 120px;
}

[data-project="chat"]#chatView #chatMessages.chat-viewport,
[data-project="chat"]#chatView .chat-viewport {
  flex: 1;
  min-height: 0;
  padding: calc(var(--chat-header-h) + var(--chat-header-offset) + var(--safe-top)) 16px calc(var(--chat-composer-h) + var(--shell-nav-h) + var(--shell-nav-offset) + var(--safe-bottom)) !important;
  background: transparent !important;
}

[data-project="chat"]#chatView .chat-list-item {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow-soft);
  border-radius: 26px;
  padding: 16px 18px;
}

[data-project="chat"]#chatView .chat-item-avatar {
  width: 56px;
  height: 56px;
  border: 3px solid rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow-sm);
}

[data-project="chat"]#chatView .chat-item-name {
  font-size: 16px;
}

[data-project="chat"]#chatView .chat-item-preview {
  color: var(--text-secondary);
}

/* Composer (floating elements) */
.chat-composer {
  position: absolute !important;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100% !important;
  min-height: var(--chat-composer-h);
  background: transparent !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  border-top: none !important;
  margin: 0 !important;
  padding: 12px 16px calc(24px + var(--safe-bottom)) !important;
  gap: 10px;
  z-index: 120;
  pointer-events: none;
}

.chat-composer > * {
  pointer-events: auto;
}

.chat-input-pill {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.92);
  border-radius: 999px;
  padding: 8px 16px;
  box-shadow: var(--shadow-soft);
  border: 1px solid rgba(255, 255, 255, 0.7);
}

.chat-input-pill textarea {
  flex: 1 1 auto !important;
  min-width: 0 !important;
  width: 100% !important;
  max-width: 100% !important;
  background: transparent !important;
  border: none !important;
  display: block;
  box-sizing: border-box;
  height: 38px !important;
  min-height: 38px !important;
  line-height: 22px !important;
  padding: 6px 0 !important;
  box-shadow: none !important;
}

#chatPlusBtn {
  font-size: 24px !important;
  font-weight: 300 !important;
  line-height: 1;
}

#chatPlusBtn,
#chatEmojiBtn,
#chatVoiceBtn,
#sendButton {
  width: 46px;
  height: 46px;
  border-radius: var(--radius-full);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border: 1px solid rgba(255, 255, 255, 0.72) !important;
  box-shadow: var(--shadow-sm);
}

#chatPlusBtn,
#chatEmojiBtn,
#chatVoiceBtn {
  background: rgba(255, 255, 255, 0.92) !important;
  color: #56617a !important;
}

#sendButton {
  background: linear-gradient(135deg, var(--accent-pink) 0%, var(--accent-pink-dark) 100%);
  box-shadow: var(--fab-shadow);
  border-color: rgba(255, 112, 154, 0.5) !important;
  color: #fff !important;
}

#chatEmojiBtn svg,
#chatVoiceBtn svg {
  width: 18px;
  height: 18px;
  display: block;
}

#chatPlusBtn:disabled,
#chatEmojiBtn:disabled,
#chatVoiceBtn:disabled,
#sendButton:disabled {
  opacity: 0.48;
  cursor: not-allowed;
  box-shadow: none !important;
}

[data-project="chat"]#chatView .message-content.voice_fake {
  padding: 10px 14px;
  border-radius: 18px;
  min-width: 156px;
  max-width: 240px;
}

[data-project="chat"]#chatView .fake-voice-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  cursor: pointer;
  user-select: none;
}

[data-project="chat"]#chatView .voice-play-icon {
  width: 24px;
  height: 24px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.32);
  color: currentColor;
  flex-shrink: 0;
}

[data-project="chat"]#chatView .message.assistant .voice-play-icon {
  background: rgba(0, 0, 0, 0.08);
}

[data-project="chat"]#chatView .voice-play-icon svg {
  width: 13px;
  height: 13px;
}

[data-project="chat"]#chatView .voice-wave {
  display: grid;
  grid-template-columns: repeat(14, minmax(2px, 1fr));
  align-items: center;
  gap: 2px;
  height: 18px;
  flex: 1;
}

[data-project="chat"]#chatView .voice-wave-bar {
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: currentColor;
  opacity: 0.28;
  transform-origin: center;
}

[data-project="chat"]#chatView .message-content.voice_fake.is-playing .voice-wave-bar,
[data-project="chat"]#chatView .fake-voice-bar.is-playing .voice-wave-bar {
  animation: fakeVoiceWave 0.95s ease-in-out infinite;
  animation-delay: calc(var(--bar-index) * 0.04s);
  opacity: 0.64;
}

[data-project="chat"]#chatView .message-content.voice_fake.is-playing .voice-play-icon,
[data-project="chat"]#chatView .fake-voice-bar.is-playing .voice-play-icon {
  transform: scale(1.05);
}

[data-project="chat"]#chatView .voice-duration {
  font-size: 12px;
  font-weight: 600;
  opacity: 0.8;
  min-width: 34px;
  text-align: right;
}

@keyframes fakeVoiceWave {
  0%,
  100% {
    transform: scaleY(0.55);
  }
  50% {
    transform: scaleY(1.45);
  }
}

@media (max-width: 420px) {
  .chat-composer {
    gap: 8px;
    padding: 10px 12px calc(20px + var(--safe-bottom)) !important;
  }

  #chatPlusBtn,
  #chatEmojiBtn,
  #chatVoiceBtn,
  #sendButton {
    width: 42px;
    height: 42px;
  }

  .chat-input-pill {
    padding: 7px 12px;
  }

  .chat-input-pill textarea {
    height: 34px !important;
    min-height: 34px !important;
    line-height: 20px !important;
    padding: 5px 0 !important;
  }
}

/* Friend detail page */
[data-project="chat"]#chatView #friendDetailPage .friend-profile-container {
  background: transparent;
  padding-top: calc(var(--chat-header-h) + var(--chat-header-offset) + var(--safe-top) - 6px);
  padding-bottom: calc(12px + var(--safe-bottom));
}

[data-project="chat"]#chatView #friendDetailPage .friend-profile-hero {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 24px;
  margin: 10px 12px 8px;
  padding: 18px 16px 14px;
  box-shadow: var(--shadow-soft);
}

[data-project="chat"]#chatView #friendDetailPage .friend-avatar-wrapper {
  width: 84px;
  height: 84px;
}

[data-project="chat"]#chatView #friendDetailPage .friend-name {
  margin-top: 10px;
  margin-bottom: 2px;
  font-size: 28px;
  line-height: 1.1;
}

[data-project="chat"]#chatView #friendDetailPage .friend-bio {
  margin-top: 0;
  margin-bottom: 2px;
  font-size: 13px;
  line-height: 1.25;
}

[data-project="chat"]#chatView #friendDetailPage .friend-status-indicator {
  margin-top: 8px;
  padding: 4px 12px;
}

[data-project="chat"]#chatView #friendDetailPage .friend-block-actions {
  padding: 0 12px;
  margin-top: 10px;
}

[data-project="chat"]#chatView #friendDetailPage .block-btn {
  min-height: 44px;
  padding: 10px 14px;
  border-radius: 14px;
}

[data-project="chat"]#chatView #friendDetailPage .friend-block-card {
  margin: 10px 12px;
  padding: 14px;
  border-radius: 14px;
}

[data-project="chat"]#chatView #friendDetailPage #singleChatActions {
  margin-top: 6px;
  padding: 0 12px 12px;
  gap: 10px;
}

[data-project="chat"]#chatView #friendDetailPage #singleChatActions .friend-action-card {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow-sm);
  border-radius: 18px;
  padding: 14px 8px;
  gap: 8px;
  min-height: 108px;
}

[data-project="chat"]#chatView #friendDetailPage #singleChatActions .friend-action-card .action-icon {
  width: 40px;
  height: 40px;
}

[data-project="chat"]#chatView #friendDetailPage #singleChatActions .friend-action-card .action-label {
  font-size: 12px;
}

[data-project="chat"]#chatView #friendDetailPage .friend-danger-zone {
  margin-top: 10px;
  padding: 0 12px 8px;
  gap: 10px;
}

[data-project="chat"]#chatView #friendDetailPage .danger-btn {
  min-height: 44px;
  padding: 11px 16px;
  border-radius: 14px;
}

/* Personas list */
#userPersonasView {
  background: var(--app-gradient) !important;
  display: flex;
  flex-direction: column;
  height: 100%;
}

#userPersonasView .settings-viewport {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-left: 16px;
  padding-right: 16px;
  padding-bottom: calc(66px + 18px + var(--safe-bottom));
}

#userPersonasView .app-navbar {
  background: transparent;
  border-bottom: none;
}

#userPersonaEditorView .app-navbar {
  background: transparent;
  border-bottom: none;
}

#userPersonasView .ios-list-group {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 24px;
  box-shadow: var(--shadow-soft);
  padding: 8px;
}

/* Persona editor */
#userPersonaEditorView {
  background: var(--app-gradient) !important;
}

#userPersonaEditorView .ios-modal {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
  border-radius: 28px;
}

/* Add friend modal */
#friendModal {
  background: rgba(18, 16, 26, 0.24);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

#friendModal .add-friend-modal {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 28px;
  box-shadow: var(--glass-shadow);
}

#friendModal .add-friend-header {
  border-bottom: none;
  padding: 16px 20px;
}

#friendModal .add-friend-avatar {
  background: rgba(255, 255, 255, 0.8);
  border: 2px dashed rgba(255, 143, 180, 0.35);
  box-shadow: var(--shadow-soft);
}

#friendModal .add-friend-save {
  background: linear-gradient(135deg, var(--accent-pink) 0%, var(--accent-pink-dark) 100%);
  color: #fff;
  border-radius: var(--radius-full);
  padding: 8px 18px;
  box-shadow: var(--fab-shadow);
}

/* Wallet */
#walletView {
  background: var(--app-gradient) !important;
}

#walletView .app-navbar {
  background: transparent !important;
  border-bottom: none;
}

#walletView .wallet-content-wechat {
  background: transparent;
}

#walletView .wallet-actions-wechat button {
  border-radius: 999px;
  box-shadow: var(--shadow-soft);
}
