/* ============================================
   Chat Page — Full-page mobile chat
   Apple iMessage / Telegram style
   ============================================ */

/* Tailwind utilities (not loaded on chat layout) — scoped to avoid leaking into engineer panel */
.chat-page-body .hidden { display: none !important; }
.chat-page-body .w-4 { width: 16px; }
.chat-page-body .h-4 { height: 16px; }
.chat-page-body .w-5 { width: 20px; }
.chat-page-body .h-5 { height: 20px; }

/* Body — no scroll, full viewport */
.chat-page-body {
  margin: 0;
  padding: 0;
  overflow: hidden;
  height: 100dvh;
  background: #f5f5f5;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.dark .chat-page-body {
  background: #0a0a0a;
}

/* Page container — flex column, full viewport */
.chat-page {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 100vw;
  overflow: hidden;
  position: relative;
}

/* Desktop: constrain width, center, add shadow */
@media (min-width: 768px) {
  .chat-page-body {
    display: flex;
    justify-content: center;
    background: #e5e5e5;
  }

  .dark .chat-page-body {
    background: #000;
  }

  .chat-page {
    max-width: 480px;
    width: 100%;
    border-left: 1px solid rgba(0, 0, 0, 0.1);
    border-right: 1px solid rgba(0, 0, 0, 0.1);
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.08);
  }

  .dark .chat-page {
    border-color: rgba(255, 255, 255, 0.06);
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.4);
  }
}

/* ============================================
   Header — frosted glass
   ============================================ */
.chat-page-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid rgba(0, 0, 0, 0.1);
  flex-shrink: 0;
  z-index: 10;
}

.dark .chat-page-header {
  background: rgba(20, 20, 20, 0.85);
  border-bottom-color: rgba(255, 255, 255, 0.08);
}

.chat-page-back {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  background: none;
  color: #f97316;
  cursor: pointer;
  border-radius: 50%;
  padding: 0;
  flex-shrink: 0;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.chat-page-back:active {
  background: rgba(249, 115, 22, 0.1);
}

.chat-page-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.chat-page-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #f97316, #ea580c);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  flex-shrink: 0;
}

.chat-page-title {
  font-size: 16px;
  font-weight: 600;
  color: #111;
  margin: 0;
  line-height: 1.2;
}

.dark .chat-page-title {
  color: #f7f7f7;
}

.chat-page-status {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: #888;
  margin: 0;
  line-height: 1;
}

.dark .chat-page-status {
  color: #777;
}

.chat-page-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #22c55e;
  flex-shrink: 0;
}

.chat-page-status-dot.offline {
  background: #9ca3af;
}

.chat-page-status-dot.reconnecting {
  background: #f59e0b;
  animation: pulse-dot 1.5s infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ============================================
   Contact CTA Banner
   ============================================ */
.chat-page-contact-cta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 12px;
  padding: 10px 14px;
  background: rgba(249, 115, 22, 0.08);
  border: 1px solid rgba(249, 115, 22, 0.15);
  border-radius: 12px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
  position: relative;
}

.chat-page-contact-cta:active {
  background: rgba(249, 115, 22, 0.15);
}

.dark .chat-page-contact-cta {
  background: rgba(249, 115, 22, 0.1);
  border-color: rgba(249, 115, 22, 0.2);
}

.dark .chat-page-contact-cta:active {
  background: rgba(249, 115, 22, 0.18);
}

.chat-page-contact-cta-close {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 20px;
  height: 20px;
  border: none;
  background: none;
  color: #9ca3af;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 14px;
  line-height: 1;
  -webkit-tap-highlight-color: transparent;
}

.chat-page-contact-cta-close:active {
  background: rgba(0, 0, 0, 0.05);
}

.dark .chat-page-contact-cta-close {
  color: #6b7280;
}

.dark .chat-page-contact-cta-close:active {
  background: rgba(255, 255, 255, 0.1);
}

.chat-page-contact-cta-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, #f97316, #ea580c);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  flex-shrink: 0;
}

.chat-page-contact-cta-text {
  flex: 1;
  font-size: 13px;
  color: #92400e;
  font-weight: 500;
}

.dark .chat-page-contact-cta-text {
  color: #fb923c;
}

.chat-page-contact-cta-chevron {
  color: #d97706;
  flex-shrink: 0;
}

.dark .chat-page-contact-cta-chevron {
  color: #f97316;
}

/* ============================================
   Connection Banner
   ============================================ */
.chat-page-connection-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 8px 16px;
  background: #fef3c7;
  color: #92400e;
  font-size: 13px;
  text-align: center;
  flex-shrink: 0;
  transition: background 0.2s;
}

.chat-page-connection-btn {
  padding: 4px 12px;
  border-radius: 12px;
  border: 1px solid currentColor;
  background: transparent;
  color: inherit;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}

.chat-page-connection-btn:active {
  background: rgba(0, 0, 0, 0.08);
}

.chat-page-connection-banner.is-offline {
  background: #fee2e2;
  color: #991b1b;
}

.dark .chat-page-connection-banner {
  background: #422006;
  color: #fde68a;
}

.dark .chat-page-connection-banner.is-offline {
  background: #450a0a;
  color: #fecaca;
}

.dark .chat-page-connection-btn:active {
  background: rgba(255, 255, 255, 0.1);
}

/* ============================================
   Messages Area — scrollable
   ============================================ */
.chat-page-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 16px;
  scroll-behavior: smooth;
}

.chat-page-messages-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 100%;
  justify-content: flex-end;
}

/* Grouped messages (same sender, <5 min apart) */
.chat-page-msg.grouped {
  margin-top: -8px; /* reduce gap: 10px - 8px = 2px effective */
}

/* Avatar spacer for grouped messages (keeps alignment) */
.chat-page-msg-avatar-spacer {
  width: 28px;
  flex-shrink: 0;
}

/* Time separator between message groups */
.chat-page-time-separator {
  text-align: center;
  padding: 8px 0;
}

.chat-page-time-separator span {
  font-size: 11px;
  color: #9ca3af;
  background: rgba(156, 163, 175, 0.1);
  padding: 2px 10px;
  border-radius: 10px;
}

.dark .chat-page-time-separator span {
  color: #6b7280;
  background: rgba(107, 114, 128, 0.15);
}

/* Loading */
.chat-page-loading {
  display: flex;
  justify-content: center;
  padding: 40px 0;
}

.chat-page-typing-dots {
  display: flex;
  gap: 4px;
  align-items: center;
}

.chat-page-typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #d1d5db;
  animation: chat-page-bounce 1.4s infinite ease-in-out both;
}

.dark .chat-page-typing-dots span {
  background: #4b5563;
}

.chat-page-typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.chat-page-typing-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes chat-page-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* ============================================
   Messages — Bubbles
   ============================================ */
.chat-page-msg {
  display: flex;
  gap: 8px;
  max-width: 80%;
  animation: msg-appear 0.25s ease-out;
}

.chat-page-msg.from-client {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.chat-page-msg-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.chat-page-msg.from-client .chat-page-msg-content {
  align-items: flex-end;
}

.chat-page-msg.from-assistant .chat-page-msg-content,
.chat-page-msg.from-engineer .chat-page-msg-content {
  align-items: flex-start;
}

.chat-page-msg.from-assistant,
.chat-page-msg.from-engineer {
  align-self: flex-start;
}

/* Avatar (assistant/engineer only) */
.chat-page-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, #f97316, #ea580c);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  flex-shrink: 0;
  align-self: flex-end;
}

.chat-page-msg-avatar svg {
  width: 14px;
  height: 14px;
}

.chat-page-msg.from-engineer .chat-page-msg-avatar {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
}

/* Bubble */
.chat-page-bubble {
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.45;
  word-break: break-word;
  position: relative;
  width: fit-content;
  max-width: 100%;
}

.chat-page-msg.from-client .chat-page-bubble {
  background: #f97316;
  color: white;
  border-bottom-right-radius: 6px;
}

.chat-page-msg.from-assistant .chat-page-bubble,
.chat-page-msg.from-engineer .chat-page-bubble {
  background: #e8e8ed;
  color: #1a1a1a;
  border-bottom-left-radius: 6px;
}

.dark .chat-page-msg.from-assistant .chat-page-bubble,
.dark .chat-page-msg.from-engineer .chat-page-bubble {
  background: #262626;
  color: #e5e5e5;
}

/* Bubble links */
.chat-page-bubble a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.chat-page-msg.from-assistant .chat-page-bubble a {
  color: #f97316;
}

.dark .chat-page-msg.from-assistant .chat-page-bubble a {
  color: #fb923c;
}

/* Markdown in bubbles */
.chat-page-bubble p { margin: 0 0 8px; }
.chat-page-bubble p:last-child { margin-bottom: 0; }
.chat-page-bubble strong { font-weight: 600; }
.chat-page-bubble ul, .chat-page-bubble ol { margin: 4px 0; padding-left: 20px; }
.chat-page-bubble li { margin-bottom: 2px; }
.chat-page-bubble code {
  padding: 2px 5px;
  border-radius: 4px;
  font-size: 0.9em;
  background: rgba(0,0,0,0.06);
}
.dark .chat-page-bubble code {
  background: rgba(255,255,255,0.1);
}

/* Engineer badge */
.chat-page-engineer-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 500;
  color: #3b82f6;
  margin-left: 8px;
}

/* Time */
.chat-page-msg-time {
  font-size: 11px;
  color: #9ca3af;
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.chat-page-msg.from-client .chat-page-msg-time {
  justify-content: flex-end;
}

.dark .chat-page-msg-time {
  color: #6b7280;
}

/* Message animation */
@keyframes msg-appear {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chat-page-msg.animate-in {
  opacity: 0;
  transform: translateY(8px);
}

.chat-page-msg.is-animating {
  animation: msg-appear 0.25s ease-out forwards;
}

.chat-page-msg.animate-complete {
  opacity: 1;
  transform: none;
}

/* Message sending/error states */
.chat-page-msg--sending .chat-page-bubble {
  opacity: 0.7;
}

.chat-page-msg--error .chat-page-bubble {
  opacity: 0.5;
}

.chat-page-message-retry {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  font-size: 12px;
}

.chat-page-message-retry .retry-text {
  color: #ef4444;
}

.chat-page-message-retry .retry-btn {
  background: none;
  border: none;
  color: #f97316;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  font-size: 12px;
}

/* Attachments */
.chat-page-msg-attachments {
  margin-bottom: 6px;
}

.chat-page-msg-attachments img {
  max-width: 240px;
  max-height: 200px;
  border-radius: 14px;
  display: block;
}

.chat-page-msg-attachments video {
  max-width: 240px;
  border-radius: 14px;
}

.chat-page-msg-attachments .chat-attachment-file {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(0,0,0,0.05);
  font-size: 13px;
  color: #555;
  text-decoration: none;
}

.dark .chat-page-msg-attachments .chat-attachment-file {
  background: rgba(255,255,255,0.08);
  color: #aaa;
}

/* ============================================
   Inline Buttons (order confirm, etc.)
   ============================================ */
.chat-page-msg .chat-order-confirm-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.chat-page-msg .chat-confirm-btn {
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.chat-page-msg .chat-confirm-btn:active {
  transform: scale(0.96);
}

.chat-page-msg .chat-confirm-btn-yes,
.chat-page-msg .chat-confirm-btn-primary {
  background: #f97316;
  color: white;
}

.chat-page-msg .chat-confirm-btn-no,
.chat-page-msg .chat-confirm-btn-edit {
  background: transparent;
  color: #6b7280;
  border: 1px solid #d1d5db;
}

.dark .chat-page-msg .chat-confirm-btn-no,
.dark .chat-page-msg .chat-confirm-btn-edit {
  background: transparent;
  color: rgba(255, 255, 255, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.chat-page-msg .chat-confirm-btn.disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chat-page-msg .chat-confirm-btn.selected {
  background: #22c55e;
  color: white;
  animation: confirmPulse 0.3s ease-out;
}

@media (prefers-reduced-motion: reduce) {
  .chat-page-msg .chat-confirm-btn { transition: none !important; animation: none !important; }
}

/* Payment options */
.chat-page-msg .chat-payment-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.chat-page-msg .chat-payment-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid #e5e7eb;
  background: white;
  cursor: pointer;
  font-size: 14px;
  color: #374151;
  transition: background 0.15s, border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.dark .chat-page-msg .chat-payment-btn {
  background: #1f1f1f;
  border-color: #333;
  color: #e5e5e5;
}

.chat-page-msg .chat-payment-btn:active {
  background: #f9fafb;
}

/* Quick actions (inline) — works in both widget and chat page */
.chat-inline-quick-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 12px;
}

.chat-inline-qa-btn {
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid #e5e7eb;
  background: #fff;
  color: #374151;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
  text-align: left;
  line-height: 1.3;
}

.chat-inline-qa-btn:hover {
  background: #f9fafb;
}

.chat-inline-qa-btn:active {
  transform: scale(0.97);
  background: #f3f4f6;
}

.dark .chat-inline-qa-btn {
  background: #2a2a2a;
  color: #e5e5e5;
  border-color: #444;
}

.dark .chat-inline-qa-btn:hover {
  background: #333;
}


/* Order summary card */
.chat-page-msg .chat-order-summary {
  margin-top: 10px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid #e5e7eb;
}

.dark .chat-page-msg .chat-order-summary {
  border-color: #333;
}

.chat-page-msg .chat-order-summary-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: #f0fdf4;
  color: #166534;
  font-weight: 500;
  font-size: 14px;
}

.dark .chat-page-msg .chat-order-summary-header {
  background: #052e16;
  color: #86efac;
}

.chat-page-msg .chat-order-summary-header svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.chat-page-msg .chat-order-summary-body {
  padding: 12px 14px;
  background: white;
}

.dark .chat-page-msg .chat-order-summary-body {
  background: #1a1a1a;
}

.chat-page-msg .chat-order-summary-product {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid #f3f4f6;
}

.dark .chat-page-msg .chat-order-summary-product {
  border-bottom-color: #262626;
}

.chat-page-msg .chat-order-summary-product-name {
  font-weight: 500;
  color: #111;
  font-size: 14px;
}

.dark .chat-page-msg .chat-order-summary-product-name {
  color: #e5e5e5;
}

.chat-page-msg .chat-order-summary-product-price {
  font-weight: 700;
  color: #111;
  white-space: nowrap;
  font-size: 15px;
}

.dark .chat-page-msg .chat-order-summary-product-price {
  color: #f97316;
}

.chat-page-msg .chat-order-summary-delivery-title {
  font-size: 12px;
  color: #9ca3af;
  margin-bottom: 6px;
}

.chat-page-msg .chat-order-summary-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: #555;
  margin-bottom: 4px;
}

.dark .chat-page-msg .chat-order-summary-row {
  color: #999;
}

.chat-page-msg .chat-order-summary-row svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
  color: #9ca3af;
}

/* Delivery form button (inline) */
.chat-page-msg .chat-inline-delivery-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  margin-top: 10px;
  border-radius: 12px;
  border: 1px solid #e5e7eb;
  background: white;
  cursor: pointer;
  font-size: 14px;
  color: #374151;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.dark .chat-page-msg .chat-inline-delivery-btn {
  background: #1f1f1f;
  border-color: #333;
  color: #e5e5e5;
}

/* Typing indicator (in messages list) */
#typing-indicator-page {
  animation: msg-appear 0.2s ease-out;
}

#typing-indicator-page .chat-page-typing-dots {
  padding: 4px 0;
}

/* Inline typing bubble (appears at bottom of messages, like WhatsApp) */
.chat-page-typing-bubble {
  padding: 4px 16px 8px;
  max-height: 60px;
  overflow: hidden;
  opacity: 1;
  transition: opacity 0.2s ease, max-height 0.2s ease, padding 0.2s ease;
}

.chat-page-typing-bubble.hidden {
  opacity: 0;
  max-height: 0;
  padding: 0 16px;
}

.chat-page-typing-bubble-content {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #f3f4f6;
  padding: 10px 14px;
  border-radius: 18px;
  border-bottom-left-radius: 6px;
}

.dark .chat-page-typing-bubble-content {
  background: #252525;
}

.chat-page-typing-label {
  font-size: 13px;
  color: #888;
  white-space: nowrap;
}

.dark .chat-page-typing-label {
  color: #999;
}

.chat-page-typing-label:empty {
  display: none;
}

.chat-page-typing-bubble .chat-page-typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #aaa;
  animation: chat-page-bounce 1.4s infinite ease-in-out both;
}

.dark .chat-page-typing-bubble .chat-page-typing-dots span {
  background: #666;
}

.chat-page-typing-bubble .chat-page-typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.chat-page-typing-bubble .chat-page-typing-dots span:nth-child(2) { animation-delay: -0.16s; }

/* ============================================
   Jump to Latest Button
   ============================================ */
.chat-page-jump {
  position: absolute;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 0.5px solid rgba(0,0,0,0.1);
  border-radius: 20px;
  padding: 6px 14px;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  color: #666;
  font-size: 13px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  z-index: 5;
  transition: transform 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.dark .chat-page-jump {
  background: rgba(30, 30, 30, 0.9);
  border-color: rgba(255,255,255,0.08);
  color: #aaa;
}

.chat-page-jump:active {
  transform: translateX(-50%) scale(0.96);
}

.chat-page-jump-badge {
  background: #f97316;
  color: white;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}

/* ============================================
   Input Area — frosted glass, safe areas
   ============================================ */
.chat-page-input-area {
  flex-shrink: 0;
  padding: 8px 12px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid rgba(0, 0, 0, 0.1);
  z-index: 10;
}

.dark .chat-page-input-area {
  background: rgba(20, 20, 20, 0.85);
  border-top-color: rgba(255, 255, 255, 0.08);
}

.chat-page-form {
  margin: 0;
}

.chat-page-input-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f3f4f6;
  border-radius: 24px;
  padding: 5px 5px 5px 12px;
  min-height: 44px;
  box-sizing: border-box;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.2s;
}

.dark .chat-page-input-wrapper {
  background: #1f1f1f;
}

.chat-page-input-wrapper:focus-within {
  background: #e8e8ed;
  border-color: #f97316;
}

.dark .chat-page-input-wrapper:focus-within {
  background: #262626;
  border-color: #f97316;
}

.chat-page-attach-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: none;
  background: none;
  color: #9ca3af;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  border-radius: 50%;
  -webkit-tap-highlight-color: transparent;
}

.chat-page-attach-btn:active {
  background: rgba(0,0,0,0.08);
  transform: scale(0.95);
}

.dark .chat-page-attach-btn {
  color: #6b7280;
}

.chat-page-textarea {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  font-size: 16px; /* Prevents iOS zoom on focus */
  line-height: 1.4;
  max-height: 120px;
  padding: 7px 0;
  color: #111;
  outline: none;
  font-family: inherit;
}

.dark .chat-page-textarea {
  color: #f7f7f7;
}

.chat-page-textarea::placeholder {
  color: #9ca3af;
}

.dark .chat-page-textarea::placeholder {
  color: #6b7280;
}

.chat-page-send-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: #f97316;
  color: white;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  transition: opacity 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.chat-page-send-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.chat-page-send-btn:not(:disabled):active {
  transform: scale(0.92);
}

/* Attachment preview */
.chat-page-attachment-preview {
  padding: 8px 0 4px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chat-page-attachment-preview .attachment-preview-item {
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  background: #f3f4f6;
}

.dark .chat-page-attachment-preview .attachment-preview-item {
  background: #262626;
}

.chat-page-attachment-preview img {
  width: 56px;
  height: 56px;
  object-fit: cover;
  display: block;
}

.chat-page-attachment-preview .attachment-remove-btn {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(0,0,0,0.5);
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  line-height: 1;
}

/* ============================================
   Inline delivery form (in chat)
   ============================================ */
.chat-page-msg .chat-inline-form {
  margin-top: 10px;
  border-radius: 14px;
  border: 1px solid #e5e7eb;
  background: white;
  overflow: hidden;
}

.dark .chat-page-msg .chat-inline-form {
  background: #1a1a1a;
  border-color: #333;
}

.chat-page-msg .chat-inline-form-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: #f9fafb;
  border-bottom: 1px solid #f3f4f6;
  font-size: 14px;
  font-weight: 500;
  color: #374151;
}

.dark .chat-page-msg .chat-inline-form-header {
  background: #1f1f1f;
  border-bottom-color: #262626;
  color: #e5e5e5;
}

.chat-page-msg .chat-inline-form-close {
  margin-left: auto;
  background: none;
  border: none;
  color: #9ca3af;
  cursor: pointer;
  padding: 4px;
}

.chat-page-msg .chat-inline-form-body {
  padding: 12px 14px;
}

.chat-page-msg .chat-inline-form-field {
  margin-bottom: 10px;
}

.chat-page-msg .chat-inline-form-field label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: #6b7280;
  margin-bottom: 4px;
}

.chat-page-msg .chat-inline-form-field input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 15px;
  color: #111;
  background: white;
}

.dark .chat-page-msg .chat-inline-form-field input {
  background: #262626;
  border-color: #404040;
  color: #e5e5e5;
}

.chat-page-msg .chat-inline-form-row {
  display: flex;
  gap: 10px;
}

.chat-page-msg .chat-inline-form-row .chat-inline-form-field {
  flex: 1;
}

.chat-page-msg .chat-inline-form-error {
  font-size: 12px;
  color: #ef4444;
  margin-top: 4px;
}

.chat-page-msg .chat-inline-form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 10px 14px;
  border-top: 1px solid #f3f4f6;
}

.dark .chat-page-msg .chat-inline-form-actions {
  border-top-color: #262626;
}

.chat-page-msg .chat-inline-form-cancel {
  padding: 8px 14px;
  border: none;
  background: #f3f4f6;
  border-radius: 8px;
  font-size: 14px;
  color: #6b7280;
  cursor: pointer;
}

.dark .chat-page-msg .chat-inline-form-cancel {
  background: #333;
  color: #aaa;
}

.chat-page-msg .chat-inline-form-submit {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: none;
  background: #f97316;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  color: white;
  cursor: pointer;
}

/* ============================================
   Audio player (reuse widget styles)
   ============================================ */
.chat-page-msg .audio-player {
  margin: 4px 0;
}
