/* ============================================================
   Inbox — Odoo Discuss look
   Conversation list on the left, thread and composer on the
   right: author + time above each run of messages, round
   bubbles, a boxed composer. Scoped to #inboxView.
   ============================================================ */

/* Layout */
html body #inboxView .inbox-container { background: var(--odoo-surface); border-top: 0; }
html body #inboxView .conversation-list {
  flex-basis: 320px;
  width: 320px;
  background: var(--odoo-surface);
  border-right: 1px solid var(--odoo-border);
}
html body #inboxView .chat-panel { background: var(--odoo-surface); }

/* Conversation list */
html body #inboxView .conversation-toolbar { padding: var(--odoo-space-3); gap: var(--odoo-space-2); border-bottom: 1px solid var(--odoo-border); }
html body #inboxView .conversation-item {
  position: relative;
  gap: var(--odoo-space-3);
  padding: var(--odoo-space-3);
  border: 0;
  border-bottom: 1px solid var(--odoo-surface-muted);
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  animation: none;
}
html body #inboxView .conversation-item:hover { background: var(--odoo-surface-muted); }
html body #inboxView .conversation-item.active { background: var(--odoo-primary-subtle); box-shadow: inset 3px 0 0 var(--odoo-primary); }
html body #inboxView .conversation-item.unread .conversation-name { font-weight: 700; }
html body #inboxView .conversation-name { font-size: var(--odoo-font-size-base); color: var(--odoo-text); }
html body #inboxView .conversation-time { font-size: var(--odoo-font-size-xs); color: var(--odoo-text-muted); }
html body #inboxView .conversation-preview { font-size: var(--odoo-font-size-sm); color: var(--odoo-text-muted); }
html body #inboxView .conversation-avatar { width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0; }
html body #inboxView .unread-badge {
  min-width: 20px;
  padding: 2px 6px;
  border-radius: 10px;
  background: var(--odoo-primary);
  color: #fff;
  font-size: var(--odoo-font-size-xs);
  font-weight: 700;
  line-height: 16px;
  text-align: center;
}

/* Thread header */
html body #inboxView .chat-header {
  gap: var(--odoo-space-3);
  padding: var(--odoo-space-2) var(--odoo-space-4);
  min-height: 56px;
  background: var(--odoo-surface);
  border-bottom: 1px solid var(--odoo-border);
}
html body #inboxView .chat-customer-info { display: flex; align-items: center; gap: var(--odoo-space-3); min-width: 0; flex: 1; }
html body #inboxView .chat-customer-text { display: flex; flex-direction: column; min-width: 0; }
html body #inboxView .chat-customer-info h3 {
  margin: 0;
  overflow: hidden;
  font-size: var(--odoo-font-size-md);
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}
html body #inboxView .chat-customer-info .customer-id {
  display: flex;
  align-items: center;
  gap: 4px;
  overflow: hidden;
  color: var(--odoo-text-muted);
  font-size: var(--odoo-font-size-xs);
  text-overflow: ellipsis;
  white-space: nowrap;
}
html body #inboxView .chat-customer-info .customer-channel { display: inline-flex; width: 14px; height: 14px; }
html body #inboxView .chat-customer-info .customer-channel svg { width: 14px; height: 14px; }
.chat-avatar,
.message-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--odoo-primary);
  color: #fff;
  font-weight: 700;
}
.chat-avatar { width: 36px; height: 36px; font-size: var(--odoo-font-size-sm); }

/* Messages */
.chat-thread { position: relative; display: flex; flex: 1 1 0; min-height: 0; }
html body #inboxView .chat-messages {
  flex: 1;
  padding: var(--odoo-space-4) var(--odoo-space-5);
  background: var(--odoo-surface);
  gap: 2px;
}
html body #inboxView .message {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: var(--odoo-space-2);
  max-width: min(78%, 640px);
  margin-top: 0;
}
html body #inboxView .message.first-in-group { margin-top: var(--odoo-space-3); }
html body #inboxView .message.outbound { flex-direction: row-reverse; }
html body #inboxView .message-avatar { width: 32px; height: 32px; font-size: var(--odoo-font-size-xs); }
html body #inboxView .message.inbound:not(.first-in-group) .message-avatar { visibility: hidden; }
html body #inboxView .message-body { display: flex; flex-direction: column; min-width: 0; }
html body #inboxView .message.outbound .message-body { align-items: flex-end; }
.message-author {
  display: flex;
  align-items: baseline;
  gap: var(--odoo-space-2);
  margin-bottom: 2px;
  font-size: var(--odoo-font-size-xs);
  color: var(--odoo-text-muted);
}
.message-author strong { color: var(--odoo-text); font-size: var(--odoo-font-size-sm); }
html body #inboxView .message.outbound .message-author { flex-direction: row-reverse; }

html body #inboxView .message .message-bubble {
  padding: var(--odoo-space-2) var(--odoo-space-3);
  border: 0;
  border-radius: 18px;
  box-shadow: none;
  font-size: var(--odoo-font-size-base);
  line-height: 1.55;
}
html body #inboxView .message.inbound .message-bubble {
  background: var(--odoo-surface-muted);
  color: var(--odoo-text);
}
html body #inboxView .message.outbound .message-bubble {
  background: var(--odoo-primary);
  color: #fff;
}
html body #inboxView .message.outbound.manual .message-bubble { background: var(--odoo-primary-active); }
html body #inboxView .message.outbound .message-bubble a { color: #fff; }
html body #inboxView .message-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
  color: var(--odoo-text-muted);
  font-size: var(--odoo-font-size-xs);
}
html body #inboxView .message-meta .ai-badge {
  padding: 0 6px;
  border-radius: 8px;
  background: var(--odoo-primary-subtle);
  color: var(--odoo-primary);
  font-weight: 700;
}
html body #inboxView .date-separator { margin: var(--odoo-space-4) 0 var(--odoo-space-2); }
html body #inboxView .date-separator span {
  padding: 2px var(--odoo-space-3);
  border: 1px solid var(--odoo-border);
  border-radius: 12px;
  background: var(--odoo-surface);
  color: var(--odoo-text-muted);
  font-size: var(--odoo-font-size-xs);
}

.chat-jump {
  position: absolute;
  right: var(--odoo-space-5);
  bottom: var(--odoo-space-3);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--odoo-border-strong);
  border-radius: 50%;
  background: var(--odoo-surface);
  box-shadow: var(--odoo-shadow-menu);
  color: var(--odoo-text);
  cursor: pointer;
}
.chat-jump:hover { background: var(--odoo-surface-muted); }

/* Composer */
html body #inboxView .chat-input {
  display: block;
  padding: var(--odoo-space-3) var(--odoo-space-4) var(--odoo-space-4);
  background: var(--odoo-surface);
  border-top: 0;
}
.composer {
  border: 1px solid var(--odoo-border-strong);
  border-radius: 18px;
  background: var(--odoo-surface);
}
.composer:focus-within { border-color: var(--odoo-primary); box-shadow: var(--odoo-focus-ring); }
html body #inboxView .composer textarea {
  display: block;
  width: 100%;
  min-height: 24px;
  max-height: 140px;
  padding: var(--odoo-space-3) var(--odoo-space-4) var(--odoo-space-1);
  border: 0;
  background: transparent;
  box-shadow: none;
  resize: none;
  outline: none;
  font-size: var(--odoo-font-size-base);
  line-height: 1.5;
}
.composer-tools {
  display: flex;
  align-items: center;
  gap: var(--odoo-space-1);
  padding: var(--odoo-space-1) var(--odoo-space-2) var(--odoo-space-2) var(--odoo-space-3);
}
html body #inboxView .composer-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--odoo-text-muted);
  cursor: pointer;
}
html body #inboxView .composer-btn:hover:not(:disabled) { background: var(--odoo-surface-muted); color: var(--odoo-primary); }
html body #inboxView .composer-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.composer-hint { flex: 1; padding-left: var(--odoo-space-2); color: var(--odoo-text-disabled); font-size: var(--odoo-font-size-xs); }
html body #inboxView .composer .send-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 var(--odoo-space-4);
  border: 0;
  border-radius: 16px;
  background: var(--odoo-primary);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}
html body #inboxView .composer .send-btn:hover:not(:disabled) { background: var(--odoo-primary-hover); }
html body #inboxView .composer .send-btn:disabled { background: var(--odoo-border-strong); cursor: not-allowed; }
.composer-emoji { position: relative; }
.emoji-popover {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  z-index: var(--odoo-z-dropdown);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 2px;
  padding: var(--odoo-space-2);
  border: 1px solid var(--odoo-border);
  border-radius: var(--odoo-radius-lg);
  background: var(--odoo-surface);
  box-shadow: var(--odoo-shadow-menu);
}
.emoji-popover button {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: var(--odoo-radius-md);
  background: transparent;
  font-size: 20px;
  cursor: pointer;
}
.emoji-popover button:hover { background: var(--odoo-surface-muted); }

@media (max-width: 768px) {
  html body #inboxView .conversation-list { width: 100%; flex-basis: auto; }
  html body #inboxView .message { max-width: 90%; }
  html body #inboxView .chat-messages { padding: var(--odoo-space-3); }
  .composer-hint { display: none; }
  .composer-tools { justify-content: flex-start; }
  html body #inboxView .composer .send-btn { margin-left: auto; }
}

@media (prefers-color-scheme: dark) {
  /* The thread sits on the page colour, a step darker than the panels, so
     the customer's bubble (a step lighter) stands apart from it. */
  html body #inboxView .chat-messages { background: var(--odoo-bg); }
  .message-reaction { border-color: var(--odoo-bg); background: #4a4f58; }
  html body #inboxView .message.inbound .message-bubble { background: #3d424a; color: var(--odoo-text); }
  html body #inboxView .message.outbound .message-bubble { background: #7d5673; }
  html body #inboxView .message.outbound.manual .message-bubble { background: #6b4862; }
  html body #inboxView .date-separator span { background: var(--odoo-surface); }
  .message-quote { background: rgb(255 255 255 / 8%); }
}

/* Customer profile pictures */
.chat-avatar.has-photo,
.message-avatar.has-photo { background: var(--odoo-surface-muted); overflow: hidden; }
.chat-avatar img,
.message-avatar img { width: 100%; height: 100%; object-fit: cover; }
html body #inboxView .conversation-avatar { position: relative; overflow: hidden; }
html body #inboxView .conversation-avatar .conversation-photo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

/* Delivery state under the last message you sent, as Messenger shows it */
.message-receipt {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 2px;
  color: var(--odoo-text-muted);
  font-size: var(--odoo-font-size-xs);
}
.receipt-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border: 1.5px solid var(--odoo-text-disabled);
  border-radius: 50%;
  color: var(--odoo-text-disabled);
}
.message-receipt.delivered .receipt-icon { background: var(--odoo-text-muted); border-color: var(--odoo-text-muted); color: #fff; }
.message-receipt.sending .receipt-icon { border-style: dashed; }
.receipt-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  overflow: hidden;
  border-radius: 50%;
  background: var(--odoo-primary);
  color: #fff;
  font-size: 7px;
  font-weight: 700;
}
.receipt-avatar img { width: 100%; height: 100%; object-fit: cover; }

/* Image waiting in the composer */
.composer-attachment {
  display: flex;
  align-items: center;
  gap: var(--odoo-space-3);
  margin: var(--odoo-space-2) var(--odoo-space-2) 0;
  padding: var(--odoo-space-2);
  border: 1px solid var(--odoo-border);
  border-radius: var(--odoo-radius-lg);
  background: var(--odoo-surface-muted);
}
.composer-attachment img {
  width: 64px;
  height: 64px;
  flex-shrink: 0;
  border-radius: var(--odoo-radius-md);
  object-fit: cover;
}
.composer-attachment-info { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.composer-attachment-name {
  overflow: hidden;
  font-size: var(--odoo-font-size-sm);
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.composer-attachment-hint { color: var(--odoo-text-muted); font-size: var(--odoo-font-size-xs); }

/* Replying to a specific message */
html body #inboxView .message { position: relative; }
.message-reply-btn {
  align-self: center;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--odoo-text-muted);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s;
}
.message:hover .message-reply-btn,
.message-reply-btn:focus-visible { opacity: 1; }
.message-reply-btn:hover { background: var(--odoo-surface-muted); color: var(--odoo-primary); }
@media (hover: none) { .message-reply-btn { opacity: 0.7; } }

.message-quote {
  display: flex;
  flex-direction: column;
  max-width: 100%;
  margin-bottom: -10px;
  padding: var(--odoo-space-2) var(--odoo-space-3) calc(var(--odoo-space-2) + 10px);
  border: 0;
  border-left: 3px solid var(--odoo-primary);
  border-radius: 14px;
  background: var(--odoo-surface-muted);
  color: var(--odoo-text-muted);
  font-size: var(--odoo-font-size-xs);
  text-align: left;
  cursor: pointer;
}
.message-quote:disabled { cursor: default; }
/* A message the customer took back. */
html body #inboxView .message-unsent { font-style: italic; color: var(--odoo-text-muted); }
.message-quote strong { color: var(--odoo-text); font-size: var(--odoo-font-size-xs); }
.message-quote span {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  white-space: pre-wrap;
  word-break: break-word;
}
html body #inboxView .message.outbound .message-quote { border-left: 0; border-right: 3px solid var(--odoo-primary); }
html body #inboxView .message .message-bubble { position: relative; }
.message.flash .message-bubble { animation: msg-flash 1.4s ease-out; }
@keyframes msg-flash {
  0%, 40% { box-shadow: 0 0 0 4px var(--odoo-primary-subtle), 0 0 0 6px var(--odoo-primary); }
  100% { box-shadow: none; }
}

.composer-reply {
  display: flex;
  align-items: center;
  gap: var(--odoo-space-2);
  margin: var(--odoo-space-2) var(--odoo-space-2) 0;
  padding: var(--odoo-space-1) var(--odoo-space-1) var(--odoo-space-1) var(--odoo-space-3);
  border-left: 3px solid var(--odoo-primary);
  border-radius: var(--odoo-radius-md);
  background: var(--odoo-surface-muted);
  color: var(--odoo-text-muted);
}
.composer-reply-text { display: flex; flex-direction: column; flex: 1; min-width: 0; font-size: var(--odoo-font-size-xs); }
.composer-reply-text strong { color: var(--odoo-text); }
.composer-reply-text span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Emoji reactions */
.message-react { position: relative; align-self: center; }
.message:hover .message-react .message-reply-btn,
.message-react:focus-within .message-reply-btn { opacity: 1; }
.reaction-picker {
  position: absolute;
  bottom: calc(100% + 4px);
  left: 0;
  z-index: var(--odoo-z-dropdown);
  display: flex;
  gap: 2px;
  padding: 4px;
  border: 1px solid var(--odoo-border);
  border-radius: 20px;
  background: var(--odoo-surface);
  box-shadow: var(--odoo-shadow-menu);
}
.reaction-picker button {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  transition: transform 0.1s;
}
.reaction-picker button:hover { background: var(--odoo-surface-muted); transform: scale(1.2); }
.reaction-picker button.active { background: var(--odoo-primary-subtle); }
.message-reaction {
  align-self: flex-start;
  margin: -8px 0 0 10px;
  padding: 0 5px;
  border: 2px solid var(--odoo-surface);
  border-radius: 12px;
  background: var(--odoo-surface-muted);
  font-size: 13px;
  line-height: 20px;
  z-index: 1;
}

/* ============================================================
   Phone: the open chat takes the whole screen, Messenger-style.
   The app navbar steps aside (the chat header
   has its own back arrow), the composer is a single line, and
   per-message buttons appear on tap instead of eating width.
   ============================================================ */
@media (max-width: 768px) {
  html body:has(.inbox-container.chat-open) .app-navbar { display: none; }
  html body:has(.inbox-container.chat-open) #inboxView {
    height: calc(100dvh - var(--trial-banner-height, 0px));
  }
  html body:has(.inbox-container.chat-open) .main-content { padding-bottom: 0; overflow: hidden; }

  html body #inboxView .chat-header {
    min-height: 52px;
    padding: var(--odoo-space-1) var(--odoo-space-2);
    gap: var(--odoo-space-1);
  }
  html body #inboxView .chat-back-btn { width: 36px; height: 36px; flex-shrink: 0; }
  .chat-avatar { width: 34px; height: 34px; }
  html body #inboxView .chat-actions { gap: var(--odoo-space-2); flex-shrink: 0; }

  /* Thread */
  html body #inboxView .chat-messages { padding: var(--odoo-space-2) var(--odoo-space-3); }
  html body #inboxView .message { max-width: 88%; gap: var(--odoo-space-1); }
  html body #inboxView .message-avatar { display: none; }
  html body #inboxView .message .message-bubble { font-size: var(--odoo-font-size-base); padding: 7px 12px; }
  html body #inboxView .message-image { max-width: 100%; }
  .message-quote { font-size: 11px; }

  /* Reply / react buttons: hidden until the message is tapped */
  html body #inboxView .message .message-reply-btn,
  html body #inboxView .message .message-react { display: none; }
  html body #inboxView .message.actions-open .message-reply-btn,
  html body #inboxView .message.actions-open .message-react { display: inline-flex; opacity: 1; }
  .reaction-picker { left: auto; right: 0; }

  /* Composer: [emoji][attach][ message ][send] on one line */
  html body #inboxView .chat-input { padding: var(--odoo-space-2) var(--odoo-space-2) calc(var(--odoo-space-2) + env(safe-area-inset-bottom, 0px)); }
  .composer {
    display: grid;
    grid-template-columns: auto auto 1fr auto;
    align-items: end;
    gap: 0 2px;
    padding: 4px 6px;
    border-radius: 22px;
  }
  .composer-tools { display: contents; }
  .composer-reply,
  .composer-attachment { grid-column: 1 / -1; grid-row: 1; margin: 2px 0 4px; }
  .composer-emoji { grid-row: 2; grid-column: 1; }
  .composer .attach-btn { grid-row: 2; grid-column: 2; }
  html body #inboxView .composer textarea {
    grid-row: 2;
    grid-column: 3;
    padding: 7px 6px;
    min-height: 20px;
  }
  html body #inboxView .composer .send-btn {
    grid-row: 2;
    grid-column: 4;
    width: 36px;
    height: 36px;
    padding: 0;
    justify-content: center;
    border-radius: 50%;
  }
  html body #inboxView .composer .send-btn span { display: none; }
  .emoji-popover { grid-template-columns: repeat(5, 1fr); bottom: calc(100% + 10px); }
}

html body .snippet-media { display: inline-flex; align-items: center; gap: 4px; }
html body .snippet-media svg { flex-shrink: 0; opacity: .75; }
