/* Enterprise messaging — soft product chat UI */

.ff-messages {
  --ff-msg-accent: var(--primary-color, #0056b3);
  --ff-msg-accent-soft: color-mix(in srgb, var(--ff-msg-accent) 12%, transparent);
  --ff-msg-accent-mid: color-mix(in srgb, var(--ff-msg-accent) 22%, transparent);
  --ff-msg-surface: var(--bs-body-bg, #fff);
  --ff-msg-sidebar: var(--bs-tertiary-bg, #f8fafc);
  --ff-msg-border: color-mix(in srgb, var(--bs-border-color, #dee2e6) 85%, transparent);
  --ff-msg-text: var(--bs-body-color, #212529);
  --ff-msg-muted: var(--bs-secondary-color, #6c757d);
  --ff-msg-mine-bg: var(--ff-msg-accent);
  --ff-msg-mine-fg: #f8fafc;
  --ff-msg-theirs-bg: #ffffff;
  --ff-msg-theirs-fg: var(--ff-msg-text);
  --ff-msg-thread-top: #f3f7fc;
  --ff-msg-thread-bottom: #e8eef6;
  --ff-msg-radius: 16px;
  --ff-msg-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
  --ff-msg-avatar-from: color-mix(in srgb, var(--ff-msg-accent) 78%, #0b1120);
  --ff-msg-avatar-to: var(--ff-msg-accent);

  display: grid;
  grid-template-columns: minmax(260px, 340px) 1fr;
  gap: 0;
  min-height: min(78vh, 820px);
  height: min(78vh, 820px);
  border: 1px solid var(--ff-msg-border);
  border-radius: var(--ff-msg-radius);
  overflow: hidden;
  background: var(--ff-msg-surface);
  box-shadow: var(--ff-msg-shadow);
  color: var(--ff-msg-text);
}

[data-bs-theme="dark"] .ff-messages {
  --ff-msg-surface: var(--bs-body-bg, #1a1d21);
  --ff-msg-sidebar: color-mix(in srgb, var(--bs-body-bg, #1a1d21) 88%, #000);
  --ff-msg-border: rgba(255, 255, 255, 0.1);
  --ff-msg-muted: var(--bs-secondary-color, #adb5bd);
  --ff-msg-mine-bg: color-mix(in srgb, var(--ff-msg-accent) 82%, #fff);
  --ff-msg-theirs-bg: color-mix(in srgb, var(--bs-body-bg, #1a1d21) 70%, #2a2f36);
  --ff-msg-theirs-fg: var(--bs-body-color, #e9ecef);
  --ff-msg-thread-top: #151820;
  --ff-msg-thread-bottom: #12151b;
  --ff-msg-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  --ff-msg-accent-soft: color-mix(in srgb, var(--ff-msg-accent) 22%, transparent);
  --ff-msg-accent-mid: color-mix(in srgb, var(--ff-msg-accent) 32%, transparent);
}

/* —— Sidebar —— */

.ff-messages-sidebar {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--ff-msg-border);
  background: var(--ff-msg-sidebar);
  min-height: 0;
}

.ff-messages-sidebar-header {
  padding: 1rem 1rem 0.85rem;
  border-bottom: 1px solid var(--ff-msg-border);
  flex-shrink: 0;
}

.ff-messages-sidebar-header .ff-msg-sidebar-title {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0;
}

.ff-messages-sidebar-header .btn {
  border-radius: 10px;
  font-weight: 500;
}

.ff-messages-sidebar-header #ff-msg-read-all {
  border: 0;
  color: var(--ff-msg-muted);
  padding: 0.2rem 0.45rem;
  font-size: 0.78rem;
}

.ff-messages-sidebar-header #ff-msg-read-all:hover {
  color: var(--ff-msg-accent);
  background: var(--ff-msg-accent-soft);
}

.ff-messages-list {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  padding: 0.35rem 0;
}

.ff-messages-list #ff-msg-list-empty {
  padding: 1.25rem 1rem;
  text-align: center;
  color: var(--ff-msg-muted);
}

.ff-msg-item {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  width: 100%;
  text-align: left;
  border: 0;
  border-left: 3px solid transparent;
  background: transparent;
  padding: 0.8rem 1rem;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
  color: inherit;
}

.ff-msg-item:hover {
  background: var(--ff-msg-accent-soft);
}

.ff-msg-item.is-active {
  background: var(--ff-msg-accent-mid);
  border-left-color: var(--ff-msg-accent);
}

.ff-msg-item--unread .ff-msg-item-title {
  font-weight: 700;
}

.ff-msg-item--unread .ff-msg-item-preview {
  color: var(--ff-msg-text);
  opacity: 0.85;
}

.ff-msg-item-avatar {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--ff-msg-avatar-from), var(--ff-msg-avatar-to));
  color: #f8fafc;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-weight: 650;
  flex-shrink: 0;
  letter-spacing: 0.02em;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
}

.ff-msg-item-body {
  min-width: 0;
  flex: 1;
}

.ff-msg-item-top {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  align-items: baseline;
}

.ff-msg-item-title {
  font-weight: 600;
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.01em;
}

.ff-msg-item-time {
  font-size: 0.7rem;
  color: var(--ff-msg-muted);
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.ff-msg-item-preview {
  font-size: 0.8rem;
  color: var(--ff-msg-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 0.2rem;
  line-height: 1.35;
}

.ff-msg-item-unread {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.15rem;
  height: 1.15rem;
  padding: 0 0.35rem;
  margin-top: 0.35rem;
  font-size: 0.65rem;
  font-weight: 700;
  line-height: 1;
  border-radius: 999px;
  background: #dc3545;
  color: #fff;
}

/* —— Thread —— */

.ff-messages-thread {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: linear-gradient(180deg, var(--ff-msg-thread-top) 0%, var(--ff-msg-thread-bottom) 100%);
}

.ff-messages-thread-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2.5rem 1.5rem;
  text-align: center;
  gap: 0.75rem;
}

.ff-messages-thread-empty .ff-msg-empty-icon {
  width: 4.25rem;
  height: 4.25rem;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--ff-msg-accent-soft);
  color: var(--ff-msg-accent);
  font-size: 1.75rem;
}

.ff-messages-thread-empty p {
  max-width: 22rem;
  margin: 0;
  color: var(--ff-msg-muted);
  font-size: 0.95rem;
  line-height: 1.45;
}

.ff-messages-thread-active {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.ff-messages-thread-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1.1rem;
  background: color-mix(in srgb, var(--ff-msg-surface) 92%, transparent);
  border-bottom: 1px solid var(--ff-msg-border);
  flex-shrink: 0;
  backdrop-filter: blur(6px);
}

.ff-msg-thread-heading {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.ff-msg-thread-avatar {
  width: 2.35rem;
  height: 2.35rem;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--ff-msg-avatar-from), var(--ff-msg-avatar-to));
  color: #f8fafc;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 650;
  flex-shrink: 0;
}

.ff-msg-thread-heading-text {
  min-width: 0;
}

.ff-messages-thread-header #ff-msg-thread-title {
  font-size: 0.98rem;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ff-messages-thread-header #ff-msg-thread-sub {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--ff-msg-muted);
}

.ff-messages-thread-header #ff-msg-add-people {
  border-radius: 10px;
  flex-shrink: 0;
}

.ff-messages-thread-body {
  flex: 1;
  overflow-y: auto;
  padding: 1.15rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  min-height: 0;
}

.ff-msg-day {
  align-self: center;
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--ff-msg-muted);
  background: color-mix(in srgb, var(--ff-msg-surface) 72%, transparent);
  border: 1px solid var(--ff-msg-border);
  border-radius: 999px;
  padding: 0.2rem 0.7rem;
  margin: 0.45rem 0;
  backdrop-filter: blur(4px);
}

.ff-msg-bubble-row {
  display: flex;
  margin-bottom: 0.1rem;
  animation: ff-msg-bubble-in 0.16s ease-out;
}

.ff-msg-bubble-row--mine {
  justify-content: flex-end;
}

.ff-msg-bubble-row--theirs {
  justify-content: flex-start;
}

.ff-msg-bubble {
  max-width: min(78%, 34rem);
  padding: 0.6rem 0.85rem 0.45rem;
  border-radius: 16px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
  word-wrap: break-word;
  white-space: pre-wrap;
  font-size: 0.92rem;
  line-height: 1.45;
}

.ff-msg-bubble-row--mine .ff-msg-bubble {
  background: var(--ff-msg-mine-bg);
  color: var(--ff-msg-mine-fg);
  border-bottom-right-radius: 5px;
}

.ff-msg-bubble-row--theirs .ff-msg-bubble {
  background: var(--ff-msg-theirs-bg);
  color: var(--ff-msg-theirs-fg);
  border: 1px solid var(--ff-msg-border);
  border-bottom-left-radius: 5px;
}

.ff-msg-bubble-sender {
  font-size: 0.7rem;
  font-weight: 650;
  margin-bottom: 0.2rem;
  color: var(--ff-msg-accent);
}

.ff-msg-bubble-meta {
  display: block;
  font-size: 0.65rem;
  opacity: 0.65;
  text-align: right;
  margin-top: 0.3rem;
  font-variant-numeric: tabular-nums;
}

@keyframes ff-msg-bubble-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .ff-msg-bubble-row {
    animation: none;
  }
}

/* —— Composer —— */

.ff-messages-composer {
  display: flex;
  gap: 0.65rem;
  align-items: flex-end;
  padding: 0.85rem 1.1rem 1rem;
  background: var(--ff-msg-surface);
  border-top: 1px solid var(--ff-msg-border);
  flex-shrink: 0;
}

.ff-msg-composer-well {
  flex: 1;
  display: flex;
  align-items: flex-end;
  border: 1px solid var(--ff-msg-border);
  border-radius: 14px;
  background: var(--ff-msg-sidebar);
  padding: 0.35rem 0.55rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.ff-msg-composer-well:focus-within {
  border-color: var(--ff-msg-accent);
  box-shadow: 0 0 0 3px var(--ff-msg-accent-soft);
  background: var(--ff-msg-surface);
}

.ff-messages-composer textarea {
  resize: none;
  max-height: 8rem;
  min-height: 2.4rem;
  border: 0;
  background: transparent;
  box-shadow: none;
  padding: 0.45rem 0.35rem;
  font-size: 0.92rem;
  line-height: 1.4;
  color: var(--ff-msg-text);
}

.ff-messages-composer textarea:focus {
  border: 0;
  box-shadow: none;
  outline: none;
  background: transparent;
}

.ff-messages-composer #ff-msg-send {
  width: 2.55rem;
  height: 2.55rem;
  border-radius: 50%;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: var(--ff-msg-accent);
  border-color: var(--ff-msg-accent);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.12);
}

.ff-messages-composer #ff-msg-send:hover {
  filter: brightness(1.06);
}

.ff-msg-member-picker {
  max-height: 280px;
  overflow-y: auto;
}

.ff-msg-member-option {
  cursor: pointer;
}

.ff-msg-member-option .form-check-input {
  margin-top: 0.35rem;
}

@media (max-width: 767.98px) {
  .ff-messages {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 72vh;
    border-radius: 12px;
  }

  .ff-messages-sidebar {
    max-height: 42vh;
    border-right: 0;
    border-bottom: 1px solid var(--ff-msg-border);
  }

  .ff-messages-thread {
    min-height: 52vh;
  }

  .ff-msg-item {
    padding: 0.9rem 1rem;
    min-height: 3.5rem;
  }

  .ff-messages-composer {
    padding: 0.75rem 0.85rem calc(0.85rem + env(safe-area-inset-bottom, 0));
  }

  .ff-messages-composer #ff-msg-send {
    width: 2.75rem;
    height: 2.75rem;
  }
}
