/* AP Services — mobile Message module (reference UI) */
:root {
  --ap-msg-bg: #fff9f0;
  --ap-msg-accent: #e6a23c;
  --ap-msg-accent-dark: #c9852a;
  --ap-msg-pill: #f5ebe0;
  --ap-msg-pill-text: #8b6914;
  --ap-msg-badge: #f56c6c;
  --ap-msg-text: #1f2937;
  --ap-msg-muted: #9ca3af;
  --ap-msg-line: #ece5dc;
  --ap-msg-bubble-out: #fff3cd;
  --ap-msg-bubble-in: #ffffff;
}

html.ap-expo-app .navbar,
html.ap-expo-app .footer,
html.ap-expo-app body:has(.chat-page) > .navbar,
html.ap-expo-app body:has(.chat-page) > .footer {
  display: none !important;
}

html.ap-expo-app .chat-page {
  padding: 0;
  min-height: 0;
  background: var(--ap-msg-bg);
}

html.ap-expo-app:not(.social-bridge-mode) .chat-page:not(.chat-active-page) {
  min-height: calc(100dvh - var(--social-bottom-nav-h, 62px) - var(--social-safe-bottom, env(safe-area-inset-bottom, 0px)));
}

html.ap-expo-app body.chat-active .chat-page {
  min-height: 0 !important;
}

html.ap-expo-app .chat-layout {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - var(--social-bottom-nav-h, 62px) - var(--social-safe-bottom, env(safe-area-inset-bottom, 0px)));
  min-height: 0;
  border: none;
  box-shadow: none;
  border-radius: 0;
  background: var(--ap-msg-bg);
}

html.ap-expo-app .chat-sidebar {
  background: var(--ap-msg-bg);
}

/* List header */
.ap-msg-top {
  padding: 10px 16px 8px;
  background: linear-gradient(180deg, #fdf5e6 0%, var(--ap-msg-bg) 100%);
}

html.ap-expo-app .ap-msg-top {
  padding-top: 8px;
}

.ap-msg-empty {
  text-align: center;
  padding: 48px 24px;
  color: var(--ap-msg-muted);
}

.ap-msg-empty i {
  font-size: 42px;
  opacity: 0.35;
  margin-bottom: 12px;
}

.ap-msg-empty p {
  margin: 0 0 6px;
  font-weight: 600;
  color: var(--ap-msg-text);
}

.ap-chat-skeleton-row {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px 16px;
}

.ap-chat-skeleton-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.08);
  animation: ap-chat-skeleton-pulse 1.1s ease-in-out infinite;
  flex-shrink: 0;
}

.ap-chat-skeleton-lines {
  flex: 1;
  min-width: 0;
}

.ap-chat-skeleton-line {
  height: 10px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.07);
  animation: ap-chat-skeleton-pulse 1.1s ease-in-out infinite;
}

.ap-chat-skeleton-line--short {
  width: 42%;
  height: 12px;
  margin-bottom: 8px;
}

@keyframes ap-chat-skeleton-pulse {
  0% { opacity: 0.55; }
  50% { opacity: 1; }
  100% { opacity: 0.55; }
}

.ap-msg-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.ap-msg-top h1 {
  font-size: 26px;
  font-weight: 800;
  color: var(--ap-msg-text);
  margin: 0;
  letter-spacing: -0.02em;
}

.ap-msg-top-actions {
  display: flex;
  gap: 14px;
  color: #a67c2e;
  font-size: 18px;
}

.ap-msg-top-actions button {
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(201, 162, 39, 0.25);
  color: #8b6914;
  padding: 8px 10px;
  border-radius: 12px;
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(107, 79, 16, 0.08);
}

.ap-chat-action-sheet {
  position: fixed;
  inset: 0;
  z-index: 12000;
  display: none;
  align-items: flex-end;
  justify-content: center;
}

.ap-chat-action-sheet.open {
  display: flex;
}

.ap-chat-action-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 10, 5, 0.45);
}

.ap-chat-action-panel {
  position: relative;
  width: min(100%, 420px);
  background: #fff;
  border-radius: 20px 20px 0 0;
  padding: 12px 12px max(16px, env(safe-area-inset-bottom));
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.15);
  animation: apSheetUp 0.22s ease;
}

.ap-chat-action-panel button {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  border: none;
  background: #faf6ee;
  color: #5c4a1a;
  font-size: 15px;
  font-weight: 600;
  padding: 14px 16px;
  border-radius: 14px;
  margin-bottom: 8px;
}

.ap-chat-action-panel button.is-cancel {
  background: #f3f4f6;
  color: #6b7280;
  justify-content: center;
}

@keyframes apSheetUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.ap-msg-notify {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f8e8c8;
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 12px;
  font-size: 12px;
  color: #6b4f1d;
}

.ap-msg-notify i {
  color: #a67c2e;
}

.ap-msg-notify span {
  flex: 1;
  min-width: 0;
}

.ap-msg-notify .open-btn {
  background: var(--ap-msg-accent);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 600;
}

.ap-msg-notify .close-btn {
  background: none;
  border: none;
  color: #9ca3af;
  font-size: 16px;
  padding: 0 4px;
}

.ap-msg-filters {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}

.ap-msg-filters::-webkit-scrollbar {
  display: none;
}

.ap-msg-filter {
  flex: 0 0 auto;
  border: 1px solid #ead9c3;
  background: var(--ap-msg-pill);
  color: var(--ap-msg-pill-text);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}

.ap-msg-filter.active {
  background: var(--ap-msg-accent);
  border-color: var(--ap-msg-accent);
  color: #fff;
}

.ap-msg-filter .pill-badge {
  display: none;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  margin-left: 4px;
  border-radius: 999px;
  background: var(--ap-msg-badge);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
}

.ap-msg-filter .pill-badge.is-visible {
  display: inline-flex;
}

.ap-msg-filter.active .pill-badge {
  background: #fff;
  color: var(--ap-msg-badge);
}

/* Conversation rows */
html.ap-expo-app .chat-list {
  padding: 0;
  background: var(--ap-msg-bg);
  flex: 1 1 auto;
  min-height: 220px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

html.ap-expo-app .chat-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--ap-msg-line);
  background: transparent;
  cursor: pointer;
}

html.ap-expo-app .chat-item.has-unread {
  background: rgba(91, 103, 246, 0.08);
}

html.ap-expo-app .chat-item.has-unread:not(.active) {
  box-shadow: inset 3px 0 0 #5b67f6;
}

html.ap-expo-app .chat-item.has-unread .chat-info h4 {
  font-weight: 800;
  color: #1f2937;
}

html.ap-expo-app .chat-item.has-unread .chat-info p {
  color: #374151;
  font-weight: 600;
}

html.ap-expo-app .chat-item.has-unread .chat-time {
  color: #5b67f6;
  font-weight: 700;
}

html.ap-expo-app .chat-item .chat-unread-dot {
  position: absolute;
  top: -1px;
  right: -1px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #ef4444;
  border: 2px solid var(--ap-msg-bg, #fff);
  z-index: 2;
}

html.ap-expo-app .chat-item.has-unread .unread-badge {
  background: #ef4444;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  font-size: 11px;
  box-shadow: 0 2px 6px rgba(239, 68, 68, 0.35);
}

html.ap-expo-app .chat-item.active {
  background: rgba(230, 162, 60, 0.08);
}

html.ap-expo-app .chat-item .chat-avatar {
  position: relative;
  flex-shrink: 0;
}

html.ap-expo-app .chat-item .avatar-placeholder {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, #e8c56a, #c9a227);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
}

html.ap-expo-app .chat-item .status-dot {
  display: none;
}

html.ap-expo-app .chat-item .chat-info {
  flex: 1;
  min-width: 0;
}

html.ap-expo-app .chat-item .chat-info h4 {
  font-size: 15px;
  font-weight: 700;
  color: var(--ap-msg-text);
  margin: 0 0 4px;
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
}

html.ap-expo-app .chat-item .chat-info h4 .chat-name-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

html.ap-expo-app .chat-item .chat-info h4 .ap-role-badge,
html.ap-expo-app .chat-item .chat-info h4 .ap-msg-official {
  flex-shrink: 0;
  font-size: 9px;
  padding: 1px 6px;
}

html.ap-expo-app .chat-item .chat-info p {
  font-size: 13px;
  color: var(--ap-msg-muted);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

html.ap-expo-app .chat-item .chat-meta {
  flex-shrink: 0;
  text-align: right;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

html.ap-expo-app .chat-item .chat-time {
  font-size: 11px;
  color: var(--ap-msg-muted);
}

html.ap-expo-app .chat-item .unread-badge {
  background: var(--ap-msg-badge);
  color: #fff;
  border-radius: 999px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.ap-msg-official {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  color: #3b82f6;
  background: #dbeafe;
  border-radius: 4px;
  padding: 1px 6px;
  margin-left: 6px;
  vertical-align: middle;
}

/* Thread open — grid layout in document flow (no fixed compose bar) */
html.ap-expo-app body.chat-active,
html.social-bridge-mode body.chat-active,
html.social-app body.chat-active {
  overflow: hidden;
  height: 100dvh;
  width: 100%;
  padding: 0 !important;
  margin: 0 !important;
}

body.chat-active .chat-page,
body.chat-active .chat-container {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0 !important;
  width: 100% !important;
  max-width: none !important;
  margin: 0 !important;
  padding: 0 !important;
  height: calc(100dvh - var(--social-bottom-nav-h, 62px) - var(--ap-chat-bottom-pad, env(safe-area-inset-bottom, 0px))) !important;
  max-height: calc(100dvh - var(--social-bottom-nav-h, 62px) - var(--ap-chat-bottom-pad, env(safe-area-inset-bottom, 0px))) !important;
  overflow: hidden;
  background: #fff;
}

body.chat-active .chat-layout {
  display: flex !important;
  flex-direction: column;
  flex: 1 1 0;
  min-height: 0;
  width: 100% !important;
  max-width: none !important;
  height: 100% !important;
  max-height: 100% !important;
  margin: 0 !important;
  padding: 0 !important;
  overflow: hidden;
  grid-template-columns: unset !important;
  gap: 0 !important;
  border-radius: 0 !important;
  border: none !important;
  box-shadow: none !important;
  background: #fff;
}

body.chat-active .chat-sidebar {
  display: none !important;
}

body.chat-active .chat-main {
  display: flex !important;
  flex: 1 1 0;
  min-height: 0;
  width: 100%;
  flex-direction: column;
  overflow: hidden;
  background: #fff;
}

body.chat-active .chat-thread-pane,
body.chat-active #activeChat {
  display: grid !important;
  grid-template-rows: auto auto minmax(0, 1fr) auto auto;
  flex: 1 1 0;
  min-height: 0;
  width: 100%;
  overflow: hidden;
  background: #fff;
}

body.chat-active .chat-header {
  grid-row: 1;
  flex-shrink: 0;
  width: 100%;
  box-sizing: border-box;
  background: #fff;
  overflow: visible;
}

body.chat-active .ap-msg-quota-banner {
  grid-row: 2;
  margin: 0 12px 6px;
}

body.chat-active .ap-msg-quota-banner:not(.is-limit) {
  display: none !important;
}

body.chat-active .messages-container {
  grid-row: 3;
  min-height: 0;
  width: 100%;
  box-sizing: border-box;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 6px 12px 8px;
  background: #eef0f3;
  display: flex;
  flex-direction: column;
}

body.chat-active .messages-stack {
  display: flex;
  flex-direction: column;
  margin-top: auto;
  width: 100%;
  gap: 0;
}

body.chat-active .ap-msg-quick-row {
  display: none !important;
}

body.chat-active .chat-typing-indicator {
  grid-row: 4;
  margin: 0;
  padding: 4px 12px 6px;
  background: #eef0f3;
}

body.chat-active .chat-input-container {
  grid-row: 5;
  flex-shrink: 0;
  width: 100%;
  box-sizing: border-box;
  position: relative;
  z-index: 10;
  background: #fff;
  border-top: 1px solid #e5e7eb;
  padding: 8px 12px calc(8px + var(--ap-chat-bottom-pad, env(safe-area-inset-bottom, 0px)));
}

html.ap-expo-app body.chat-active .chat-header {
  padding: 8px 12px;
  padding-top: max(6px, env(safe-area-inset-top, 0px));
}

html.ap-expo-app body.chat-active .chat-page,
html.social-bridge-mode body.chat-active .chat-page {
  padding-bottom: 0 !important;
  background: #fff !important;
}

body.chat-active #social-bottom-nav-mount,
body.chat-active .social-bottom-nav {
  display: flex !important;
  z-index: 300;
  bottom: var(--ap-chat-bottom-pad, env(safe-area-inset-bottom, 0px));
}

body.chat-overlay-open #social-bottom-nav-mount,
body.chat-overlay-open .social-bottom-nav {
  display: none !important;
}

html.ap-expo-app body.chat-active .chat-layout,
html.social-bridge-mode body.chat-active .chat-layout {
  border-radius: 0 !important;
  min-height: 0 !important;
  background: #fff !important;
}

@media (max-width: 768px) {
  html.ap-expo-app .chat-layout {
    display: flex;
    flex-direction: column;
    min-height: 0;
  }

  html.ap-expo-app .chat-sidebar {
    flex: 1;
    min-height: 0;
    width: 100%;
  }

  html.ap-expo-app .chat-main {
    display: none;
    flex-direction: column;
    min-height: 0;
    width: 100%;
  }
}

body.chat-active #activeChat {
  margin-bottom: 0;
}

/* Keyboard open — fit thread to visible viewport (fixes blank gap + input jumping) */
body.chat-keyboard-open.chat-active .chat-page,
body.chat-keyboard-open.chat-active .chat-container {
  position: fixed !important;
  top: var(--chat-vv-offset-top, 0px) !important;
  left: 0;
  right: 0;
  width: 100% !important;
  height: var(--chat-vv-height, 100dvh) !important;
  max-height: var(--chat-vv-height, 100dvh) !important;
  z-index: 200;
  transform: none;
}

body.chat-keyboard-open.chat-active #social-bottom-nav-mount,
body.chat-keyboard-open.chat-active .social-bottom-nav {
  display: none !important;
}

body.chat-active #emptyChat {
  display: none !important;
}

.chat-thread-empty {
  margin: 24px auto;
  text-align: center;
  color: var(--ap-msg-muted, #9ca3af);
  padding: 32px 20px;
}

.chat-thread-empty i {
  font-size: 40px;
  opacity: 0.35;
  margin-bottom: 12px;
  display: block;
}

.chat-thread-empty p {
  margin: 0 0 6px;
  font-weight: 600;
  color: var(--ap-msg-text, #1f2937);
}

.chat-thread-empty small {
  display: block;
  font-size: 12px;
  color: var(--ap-msg-muted, #9ca3af);
}

.chat-thread-empty .btn-open {
  margin-top: 14px;
  border: none;
  border-radius: 999px;
  padding: 10px 18px;
  background: linear-gradient(135deg, #d4a84b, #9a7218);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

html.ap-expo-app .message-content {
  white-space: pre-wrap !important;
  overflow-wrap: anywhere !important;
  word-wrap: break-word;
  word-break: break-word !important;
  font-size: 15px;
  line-height: 1.45;
  -webkit-text-fill-color: currentColor;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

html.ap-expo-app .message-wrapper.received .message-content {
  background: #ffffff !important;
  color: #1f2937 !important;
  -webkit-text-fill-color: #1f2937 !important;
  border: 1px solid #e5e7eb;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

html.ap-expo-app .message-wrapper.sent .message-content {
  background: #d9fdd3 !important;
  color: #111b21 !important;
  -webkit-text-fill-color: #111b21 !important;
  border: none;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.06);
}

html.ap-expo-app .message-wrapper.received .message-time {
  color: #9ca3af !important;
}

html.ap-expo-app .message-wrapper.sent .message-time {
  color: #667781 !important;
}

.msg-empty-placeholder {
  font-style: italic;
  opacity: 0.65;
  font-size: 13px;
}

html.ap-expo-app .message-bubble.sent .message-content,
html.ap-expo-app .message-bubble.received .message-content {
  border-radius: 16px;
}

html.ap-expo-app .message-image {
  display: block;
  max-width: min(240px, 72vw);
  border-radius: 12px;
  margin-top: 4px;
}

html.ap-expo-app .chat-header {
  background: #fff;
  border-bottom: 1px solid var(--ap-msg-line);
  padding: calc(8px + env(safe-area-inset-top, 0px)) 12px 10px;
}

html.ap-expo-app .chat-back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  font-size: 18px;
  color: var(--ap-msg-text);
}

html.ap-expo-app .chat-user-details h3 {
  font-size: 15px;
  font-weight: 700;
  max-width: min(58vw, 220px);
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
}

html.ap-expo-app .chat-user-details h3 .chat-name-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

html.ap-expo-app .chat-user-details h3 .ap-role-badge {
  flex-shrink: 0;
  font-size: 9px;
  padding: 1px 6px;
}

html.ap-expo-app .chat-user-status {
  display: none;
}

html.ap-expo-app .chat-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 0 0 auto;
  flex-shrink: 0;
  max-width: none;
  overflow: visible;
  position: relative;
  z-index: 30;
}

html.ap-expo-app #chatHeaderSellBtn:not([hidden]) {
  color: #ea580c;
}

html.ap-expo-app .chat-action-btn {
  width: 40px;
  height: 40px;
  min-width: 40px;
  min-height: 40px;
  border: none;
  background: transparent;
  color: var(--ap-msg-text);
  font-size: 17px;
  pointer-events: auto !important;
  touch-action: manipulation;
  position: relative;
  z-index: 2;
}

html.ap-expo-app .chat-header-more-wrap {
  position: relative;
  z-index: 40;
  overflow: visible;
}

html.ap-expo-app .chat-header-more-menu {
  z-index: 6000;
}

html.ap-expo-app .chat-header-more-menu.open {
  display: block;
}

html.ap-expo-app .message-more-btn {
  pointer-events: auto !important;
  touch-action: manipulation;
}

html.ap-expo-app .chat-action-btn:active {
  opacity: 0.65;
}

html.ap-expo-app .chat-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

html.ap-expo-app .chat-user-info {
  flex: 1;
  min-width: 0;
}

html.ap-expo-app .messages-container {
  background: #f3f4f6;
  padding: 12px;
  display: block;
  overflow-x: hidden !important;
  max-width: 100%;
  box-sizing: border-box;
}

html.ap-expo-app .message-bubble {
  box-sizing: border-box;
  flex: 0 1 auto;
  width: auto !important;
  max-width: min(72vw, 280px) !important;
  min-width: 0 !important;
  overflow: hidden;
}

html.ap-expo-app .message-wrapper {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  display: flex;
  margin-bottom: 10px;
  box-sizing: border-box;
  overflow: hidden;
}

html.ap-expo-app .message-bubble.sent,
html.ap-expo-app .message-wrapper.sent .message-bubble {
  background: transparent;
  color: inherit;
  border: none;
}

html.ap-expo-app .message-bubble.received,
html.ap-expo-app .message-wrapper.received .message-bubble {
  background: transparent;
  border: none;
}

/* Force long DM text to wrap inside the bubble (not stretch the thread).
   Use vw — NOT % — so a long line cannot expand the parent and break max-width. */
body.chat-active .messages-container,
body.chat-active .messages-stack,
html.ap-expo-app .messages-stack,
html.ap-expo-app .messages-container {
  width: 100% !important;
  max-width: 100% !important;
  min-width: 0 !important;
  overflow-x: hidden !important;
  box-sizing: border-box !important;
}

body.chat-active .message-wrapper,
html.ap-expo-app .message-wrapper,
.message-wrapper {
  width: 100% !important;
  max-width: 100% !important;
  min-width: 0 !important;
  box-sizing: border-box !important;
  overflow: hidden !important;
}

body.chat-active .message-bubble,
html.ap-expo-app .message-bubble,
.message-bubble,
.message-bubble.sent,
.message-bubble.received {
  box-sizing: border-box !important;
  flex: 0 1 auto !important;
  width: auto !important;
  max-width: min(72vw, 280px) !important;
  min-width: 0 !important;
  overflow: hidden !important;
}

body.chat-active .message-content,
html.ap-expo-app .message-content,
.message-content {
  display: block !important;
  width: 100% !important;
  max-width: 100% !important;
  min-width: 0 !important;
  box-sizing: border-box !important;
  overflow-wrap: anywhere !important;
  word-break: break-word !important;
  white-space: pre-wrap !important;
  hyphens: auto;
}

/* Keep header Gift / ⋮ / Profile on-screen even with long names */
html.ap-expo-app .chat-header,
body.chat-active .chat-header {
  display: flex !important;
  align-items: center;
  gap: 8px;
  min-width: 0;
  overflow: visible;
}

html.ap-expo-app .chat-user-info,
body.chat-active .chat-user-info {
  flex: 1 1 auto !important;
  min-width: 0 !important;
  overflow: hidden !important;
}

html.ap-expo-app .chat-user-details h3 {
  max-width: 100% !important;
}

html.ap-expo-app .chat-actions,
body.chat-active .chat-actions {
  display: flex !important;
  align-items: center;
  gap: 2px;
  flex: 0 0 auto !important;
  flex-shrink: 0 !important;
  max-width: none !important;
  overflow: visible !important;
  position: relative;
  z-index: 30;
}

.ap-msg-quick-row {
  display: flex;
  gap: 8px;
  padding: 8px 12px 4px;
  overflow-x: auto;
  background: #fff;
  border-top: 1px solid var(--ap-msg-line);
}

.ap-msg-quick {
  flex: 0 0 auto;
  border: 1px solid #dbeafe;
  background: #f8fafc;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  color: #2563eb;
}

.ap-msg-quick.gift {
  background: linear-gradient(135deg, #ec4899, #f43f5e);
  border: none;
  color: #fff;
}

html.ap-expo-app .chat-input-container {
  background: #fff;
  border-top: 1px solid #e5e7eb;
  padding: 8px 12px calc(8px + var(--ap-chat-bottom-pad, env(safe-area-inset-bottom, 0px)));
}

html.ap-expo-app .chat-input-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f3f4f6;
  border-radius: 999px;
  padding: 6px 10px;
}

html.ap-expo-app .chat-input-wrapper textarea {
  border: none;
  background: transparent;
  flex: 1;
  resize: none;
  font-size: 14px;
  min-height: 24px;
  max-height: 80px;
}

html.ap-expo-app .chat-input-actions .attach-btn {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

html.ap-expo-app .chat-input-actions .attach-btn .fa-image,
html.ap-expo-app .chat-input-actions .attach-btn .fa-video {
  font-size: 1rem;
}

html.ap-expo-app .sidebar-header--legacy {
  display: none;
}

.ap-msg-search {
  margin: 0 0 10px;
  padding: 0 2px;
}

.ap-msg-search input {
  width: 100%;
  padding: 10px 12px 10px 2.5rem;
  border: 1px solid rgba(201, 162, 39, 0.28);
  border-radius: 12px;
  font-size: 14px;
  background: #fff;
  color: #5c4210;
}

.ap-msg-search i {
  left: 14px;
}

.chat-typing-indicator[hidden] {
  display: none !important;
}

.chat-typing-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 16px 8px;
  font-size: 12px;
  color: var(--gray-500);
}

.typing-dots i {
  display: inline-block;
  width: 5px;
  height: 5px;
  margin: 0 1px;
  border-radius: 50%;
  background: var(--gray-400);
  animation: chatTypingBounce 1.2s infinite ease-in-out;
}

.typing-dots i:nth-child(2) { animation-delay: 0.15s; }
.typing-dots i:nth-child(3) { animation-delay: 0.3s; }

@keyframes chatTypingBounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.5; }
  40% { transform: translateY(-4px); opacity: 1; }
}

.message-status .sending { color: var(--gray-400); }
.message-status .failed { color: #ef4444; }
.message-status .delivered { color: var(--gray-500); }
.message-status .read { color: #3b82f6; }

.chat-gift-sheet {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 100050;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}

.chat-gift-sheet[hidden] {
  display: none !important;
}

.chat-gift-panel {
  width: 100%;
  max-width: 100%;
  background: #fff;
  border-radius: 20px 20px 0 0;
  padding: 16px 16px calc(16px + var(--ap-chat-bottom-pad, env(safe-area-inset-bottom, 0px)));
  max-height: min(72vh, calc(100dvh - 48px - var(--ap-chat-bottom-pad, env(safe-area-inset-bottom, 0px))));
  overflow-y: auto;
  box-sizing: border-box;
}

html.ap-expo-app .chat-gift-send,
html.social-app .chat-gift-send {
  margin-bottom: 4px;
}

.chat-gift-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.chat-gift-head button {
  border: none;
  background: #f3f4f6;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
}

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

.chat-gift-item {
  border: 1px solid #eee;
  border-radius: 12px;
  padding: 8px 4px;
  background: #fff;
  cursor: pointer;
  font-size: 11px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-height: 90px;
}

.chat-gift-item.is-selected {
  border-color: #f5b800;
  background: #fff8e1;
}

.chat-gift-item .g {
  font-size: 24px;
  display: block;
  line-height: 1;
}

.chat-gift-item .gift-name {
  display: block;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #333;
}

.chat-gift-item .gift-coin-cost,
.chat-gift-item small {
  display: block;
  width: 100%;
  margin-top: 2px;
  color: #b45309;
  font-weight: 800;
  font-size: 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-gift-balance {
  font-size: 13px;
  margin: 12px 0 8px;
  color: #666;
}

.chat-gift-send {
  width: 100%;
  border: none;
  border-radius: 999px;
  padding: 12px;
  background: linear-gradient(90deg, #ffb300, #ff8f00);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
}

.chat-gift-send:disabled {
  opacity: 0.65;
  cursor: wait;
}

.chat-coin-meta {
  font-size: 13px;
  color: #555;
  margin: 0 0 8px;
}

.chat-coin-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: #444;
  margin: 12px 0 6px;
}

.chat-coin-input {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 12px;
  font-size: 16px;
  margin-bottom: 12px;
}

.chat-item--search {
  width: 100%;
  text-align: left;
  border: none;
  background: #fff8e1;
  cursor: pointer;
  font: inherit;
}

.ap-msg-notify[hidden] {
  display: none !important;
}

.room-invite-card {
  min-width: 200px;
  max-width: 280px;
  padding: 4px 0;
}
.room-invite-card strong {
  display: block;
  margin-bottom: 4px;
  font-size: 14px;
}
.room-invite-card-sub {
  font-size: 12px;
  opacity: 0.85;
  margin-bottom: 10px;
  line-height: 1.35;
  word-break: break-word;
}
.room-invite-join-btn {
  border: none;
  border-radius: 999px;
  padding: 8px 16px;
  font-weight: 800;
  font-size: 13px;
  background: linear-gradient(135deg, #f59e0b, #ea580c);
  color: #fff;
  cursor: pointer;
  touch-action: manipulation;
}

@media (min-width: 769px) {
  html:not(.ap-expo-app):not(.social-app) .ap-msg-quick-row {
    display: none;
  }
}
