/* ============================================
   Chat page layout - make chat fill available space
   ============================================ */
body:has(.chat) {
  height: 100dvh;
}

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;
}

@media (max-width: 767.98px) {
  body:has(.chat) footer {
    padding: 2px 0 !important;
    background: var(--color-bg) !important;
    border-top: 1px solid var(--color-border);
  }

  body:has(.chat) footer .order-2 { display: none; }

  body:has(.chat) footer a {
    color: var(--color-muted) !important;
    font-size: 10px !important;
  }
}

/* ============================================
   .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: linear-gradient(180deg, #eef1f5 0%, #f5f3f0 100%);
}

.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;
  border-radius: 20px;
  padding: 8px 14px;
  border-color: var(--color-border);
  background-color: var(--color-light);
  flex: 1;
  min-width: 0;
}

.chat__composer-textarea:focus {
  background-color: var(--color-bg);
}

.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 10px 8px;
  position: relative;
  display: inline-block;
  max-width: 85%;
  word-wrap: break-word;
  border-radius: 12px;
}

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

.message--user .message__bubble {
  background-color: #dce4f0;
  color: var(--color-ink);
  box-shadow: var(--shadow);
  border-radius: 8px 8px 0 8px;
}

.message--user .message__bubble::before {
  content: "";
  position: absolute;
  bottom: 0;
  right: -8px;
  width: 20px;
  height: 20px;
  background-color: #dce4f0;
  border-bottom-left-radius: 15px;
}

.message--user .message__bubble::after {
  content: "";
  position: absolute;
  bottom: 0;
  right: -10px;
  width: 10px;
  height: 20px;
  background: linear-gradient(180deg, #eef1f5 0%, #f5f3f0 100%);
  border-bottom-left-radius: 10px;
}

.message--ai .message__bubble {
  background-color: #ffffff;
  color: var(--color-ink);
  box-shadow: var(--shadow);
  border-radius: 8px 8px 8px 0;
}

.message--ai .message__bubble::before {
  content: "";
  position: absolute;
  bottom: 0;
  left: -8px;
  width: 20px;
  height: 20px;
  background-color: #ffffff;
  border-bottom-right-radius: 15px;
}

.message--ai .message__bubble::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: -10px;
  width: 10px;
  height: 20px;
  background: linear-gradient(180deg, #eef1f5 0%, #f5f3f0 100%);
  border-bottom-right-radius: 10px;
}

/* Highlighted message (linked from external page) */
.message--highlighted .message__bubble {
  animation: message-highlight 2s ease-out;
}

@keyframes message-highlight {
  0%, 30% { background-color: #fff3cd; }
  100% { background-color: inherit; }
}

/* 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: var(--color-muted);
  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;
  overflow: hidden;
}

.message__files .document-item,
.message__files .document-name {
  overflow: hidden;
  text-overflow: ellipsis;
}

.message__files .document-name a {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}

/* 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 icon (staff only) */
.message__debug-icon {
  align-self: center;
  font-size: 12px;
  opacity: 0;
  transition: opacity 0.15s;
}

.message:hover .message__debug-icon {
  opacity: 0.4;
}

.message__debug-icon:hover {
  opacity: 0.8;
}

/* ============================================
   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: var(--color-primary);
}

.message--user .read-receipt-pending,
.message--user .read-receipt-sent,
.message--user .read-receipt-delivered {
  color: var(--color-muted);
}

.message--user .read-receipt-read {
  color: var(--color-primary);
}

.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;
}

/* ============================================
   Day separators
   ============================================ */
.day-separator {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 20px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--color-muted);
}

.day-separator::before,
.day-separator::after {
  content: "";
  flex: 1;
  height: 1px;
  background-color: var(--color-border);
  opacity: 0.5;
}

/* ============================================
   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: 12px;
  box-shadow: var(--shadow);
  margin: 4px 0;
}

.typing-dot {
  width: 7px;
  height: 7px;
  background-color: var(--color-muted);
  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); }
}
