/* ============================================
   Chat page layout - make chat fill available space
   ============================================ */
body:has(.chat) main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

body:has(.chat) main > .container {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* ============================================
   .chat (main chat container)
   ============================================ */
.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat__messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: var(--space);
  background-color: #f0f2f5;
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="60" height="60" viewBox="0 0 60 60"><defs><pattern id="chat-pattern" x="0" y="0" width="60" height="60" patternUnits="userSpaceOnUse"><circle cx="15" cy="15" r="0.5" fill="%23e9edef" opacity="0.6"/><circle cx="45" cy="45" r="0.5" fill="%23e9edef" opacity="0.4"/><circle cx="30" cy="5" r="0.3" fill="%23e9edef" opacity="0.5"/><circle cx="5" cy="35" r="0.4" fill="%23e9edef" opacity="0.3"/><circle cx="50" cy="20" r="0.3" fill="%23e9edef" opacity="0.7"/></pattern></defs><rect width="60" height="60" fill="url(%23chat-pattern)"/></svg>');
  background-size: 60px 60px;
}

.chat__empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--color-muted);
  padding: var(--space-double);
}

.chat__composer {
  padding: var(--space-half);
  background-color: var(--color-bg, #fff);
  border-top: 1px solid var(--color-border, #dee2e6);
}

.chat__composer-row {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
}

.chat__composer-textarea {
  resize: none;
  min-height: 38px;
}

.chat__composer-buttons {
  display: flex;
  gap: 0.25rem;
}

.chat__composer-submit {
  white-space: nowrap;
}

/* Quota alerts */
.quota-alert {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  padding: 0.75rem 1rem;
  border-radius: 0.375rem;
}

.quota-alert--warning {
  background-color: var(--bs-warning-bg-subtle, #fff3cd);
  border: 1px solid var(--bs-warning-border-subtle, #ffe69c);
  color: var(--bs-warning-text-emphasis, #664d03);
}

.quota-alert--info {
  background-color: var(--bs-info-bg-subtle, #cff4fc);
  border: 1px solid var(--bs-info-border-subtle, #9eeaf9);
  color: var(--bs-info-text-emphasis, #055160);
}

.quota-alert__content {
  flex-grow: 1;
}

/* ============================================
   .message (individual message block)
   ============================================ */
.message {
  padding: 0 1px;
  margin-bottom: 0.75rem;
}

@media (min-width: 768px) {
  .message {
    padding: 0 20px;
  }
}

/* Message body - flex container */
.message__body {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 8px;
}

.message--user .message__body {
  justify-content: flex-end;
}

.message--ai .message__body {
  justify-content: flex-start;
}

/* Message bubble */
.message__bubble {
  padding: 6px 7px 8px 7px;
  position: relative;
  display: inline-block;
  max-width: 85%;
  word-wrap: break-word;
}

@media (min-width: 768px) {
  .message__bubble {
    max-width: 65%;
  }
}

.message--user .message__bubble {
  background-color: #d1f4cc;
  color: #111b21;
  border-radius: 7.5px 7.5px 0 7.5px;
  box-shadow: 0 1px 0.5px rgba(11, 20, 26, 0.13);
}

.message--ai .message__bubble {
  background-color: #ffffff;
  color: #111b21;
  border-radius: 7.5px 7.5px 7.5px 0;
  box-shadow: 0 1px 0.5px rgba(11, 20, 26, 0.13);
}

/* Message content */
.message__content {
  line-height: 1.4;
  font-size: 15px;
  display: inline;
  word-break: break-word;
  overflow-wrap: break-word;
}

.message__content p {
  margin-bottom: 0;
  display: inline;
  word-break: break-word;
}

/* Message author name (for hubs) */
.message__author {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--bs-secondary-color);
  margin-bottom: 0.25rem;
}

/* Message time */
.message__meta {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  white-space: nowrap;
  margin-left: 4px;
  vertical-align: bottom;
}

.message__time {
  display: inline;
  color: rgba(102, 119, 129, 0.8);
  font-size: 11px;
  white-space: nowrap;
  line-height: 1;
}

[dir="rtl"] .message__time {
  margin-left: 0;
  margin-right: 4px;
}

/* Message files */
.message__files {
  margin-top: 0.5rem;
}

/* Message delete button (staff only) */
.message__delete-button {
  font-size: 0.7rem;
  line-height: 1;
  margin-top: 2px;
  background: none;
  border: none;
  color: var(--bs-secondary-color);
  padding: 0.25rem;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.message:hover .message__delete-button {
  opacity: 1;
}

/* Message reactions */
.message__reactions {
  display: flex;
  align-items: center;
  position: relative;
  min-width: 32px;
  margin: 0 6px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
}

.message:hover .message__reactions {
  opacity: 1;
  pointer-events: auto;
}

.message__reactions-toggle {
  font-size: 1rem;
  text-decoration: none;
  background: none;
  border: none;
  color: var(--bs-secondary-color);
  padding: 0.25rem;
  cursor: pointer;
}

.message__reactions-popover {
  display: flex;
  gap: 0.25rem;
  font-size: 1.1rem;
  position: absolute;
  top: 50%;
  left: 100%;
  transform: translateY(-50%);
  background: #ffffff;
  border-radius: 20px;
  padding: 4px 8px;
  margin-left: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  z-index: 10;
}

.message__reactions-button {
  line-height: 1;
  text-decoration: none;
  background: none;
  border: none;
  padding: 0.25rem;
  cursor: pointer;
}

/* Message debug info (staff only) */
.message__debug {
  margin-top: 2px;
  font-size: 10px;
  opacity: 0.7;
  clear: both;
}

.message--user .message__debug {
  text-align: right;
}

.message--ai .message__debug {
  text-align: left;
}

/* ============================================
   Read receipts
   ============================================ */
.message__receipt {
  display: inline-flex;
  align-items: center;
  margin-left: 3px;
  vertical-align: bottom;
}

.message__receipt svg {
  width: 12px;
  height: 9px;
  display: block;
}

.read-receipt-pending {
  color: #9ca3af;
  opacity: 0.7;
}

.read-receipt-sent,
.read-receipt-delivered {
  color: #9ca3af;
}

.read-receipt-read {
  color: #4fc3f7;
}

.message--user .read-receipt-pending,
.message--user .read-receipt-sent,
.message--user .read-receipt-delivered {
  color: #666666;
}

.message--user .read-receipt-read {
  color: #4fc3f7;
}

.message__receipt span {
  transition: color 0.3s ease;
}

/* ============================================
   Message author badges
   ============================================ */
.message-author-badge {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 500;
  padding: 2px 6px;
  border-radius: 4px;
}

.message-author-badge.me,
.message-author-badge.member,
.message-author-badge.assistant {
  color: #6c757d;
  background-color: rgba(108, 117, 125, 0.08);
}

.parent-message__header .message-author-badge {
  font-size: 10px;
  padding: 1px 4px;
}

/* ============================================
   Typing indicator
   ============================================ */
#typing-indicator {
  padding: 0 20px;
}

.typing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
  background-color: #ffffff;
  border-radius: 7.5px 7.5px 7.5px 0;
  box-shadow: 0 1px 0.5px rgba(11, 20, 26, 0.13);
  margin: 4px 0;
}

.typing-dot {
  width: 8px;
  height: 8px;
  background-color: #90949c;
  border-radius: 50%;
  animation: typing-bounce 1.4s ease-in-out infinite;
}

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

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-4px); }
}
