/* ==========================================================================
   MatSpell Google-Backed Chat Shell Styles (/chat)
   ========================================================================== */

.chat-page-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--top-strip-height, 60px) - 32px);
  min-height: 500px;
  background: var(--color-bg, #ffffff);
  border-radius: var(--radius-lg, 12px);
  border: 1px solid var(--color-border, #e2e8f0);
  box-shadow: var(--shadow-sm, 0 1px 2px rgba(0,0,0,0.05));
  overflow: hidden;
}

.chat-shell {
  display: flex;
  flex: 1;
  height: 100%;
  overflow: hidden;
}

/* --- Left Pane: Conversations Navigation --- */
.chat-sidebar-pane {
  width: 320px;
  min-width: 280px;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--color-border, #e2e8f0);
  background: var(--color-bg-subtle, #f8fafc);
}

.chat-nav-header {
  padding: 16px;
  border-bottom: 1px solid var(--color-border, #e2e8f0);
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--color-bg, #ffffff);
}

.chat-nav-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-nav-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0;
  color: var(--color-text, #0f172a);
}

.chat-search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.chat-search-icon {
  position: absolute;
  left: 10px;
  width: 16px;
  height: 16px;
  color: var(--color-text-muted, #64748b);
  pointer-events: none;
}

.chat-search-input {
  width: 100%;
  padding: 8px 12px 8px 34px;
  border-radius: var(--radius-md, 8px);
  border: 1px solid var(--color-border, #e2e8f0);
  background: var(--color-bg, #ffffff);
  font-size: 0.875rem;
  color: var(--color-text, #0f172a);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.chat-search-input:focus {
  border-color: var(--color-primary, #6366f1);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.chat-conversations-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.chat-section-group {
  margin-bottom: 16px;
}

.chat-section-header {
  padding: 8px 16px 4px 16px;
}

.chat-section-label {
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--color-text-muted, #64748b);
}

.chat-items-list {
  display: flex;
  flex-direction: column;
}

.chat-dm-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  cursor: pointer;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  transition: background-color 0.15s ease;
  user-select: none;
}

.chat-dm-item:hover {
  background: var(--color-bg-hover, #f1f5f9);
}

.chat-dm-item.active {
  background: var(--color-primary-subtle, #e0e7ff);
  border-left: 3px solid var(--color-primary, #6366f1);
}

.chat-dm-item .avatar {
  flex-shrink: 0;
}

.chat-dm-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.chat-dm-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.chat-dm-name {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-text, #0f172a);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-unread-badge {
  background: var(--color-red, #ef4444);
  color: #ffffff;
  font-size: 0.6875rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 9999px;
  min-width: 16px;
  text-align: center;
  line-height: 1.2;
}

.chat-dm-item.has-unread .chat-dm-name {
  font-weight: 700;
}

.chat-dm-sub {
  font-size: 0.75rem;
  color: var(--color-text-muted, #64748b);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-spaces-empty {
  font-size: 0.75rem;
  padding: 8px 16px;
  margin: 0;
  font-style: italic;
}

/* --- Right Pane: Active Conversation & Stream --- */
.chat-main-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--color-bg, #ffffff);
  position: relative;
  overflow: hidden;
}

/* Empty State */
.chat-empty-state {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  padding: 32px;
  text-align: center;
}

.chat-empty-state[hidden],
.chat-empty-state.hidden {
  display: none !important;
}

.chat-empty-content {
  max-width: 380px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.chat-empty-icon-wrap {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--color-primary-subtle, #e0e7ff);
  color: var(--color-primary, #6366f1);
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-empty-icon {
  width: 32px;
  height: 32px;
}

.chat-empty-content h2 {
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0;
}

.chat-empty-content p {
  margin: 0;
  font-size: 0.875rem;
}

/* Active View */
.chat-active-view {
  display: flex;
  flex-direction: column;
  flex: 1;
  height: 100%;
  overflow: hidden;
}

.chat-active-view[hidden],
.chat-active-view.hidden {
  display: none !important;
}

.chat-conversation-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--color-border, #e2e8f0);
  background: var(--color-bg, #ffffff);
  z-index: 2;
}

.chat-header-user {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-header-info {
  display: flex;
  flex-direction: column;
}

.chat-header-title {
  font-size: 1rem;
  font-weight: 700;
  margin: 0;
  color: var(--color-text, #0f172a);
}

.chat-header-subtitle {
  font-size: 0.75rem;
}

.chat-stream-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  background: var(--color-bg, #ffffff);
}

.chat-messages-stream {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: auto; /* Push messages to bottom when few */
}

/* Message Bubble Styles */
.chat-msg-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  max-width: 78%;
}

.chat-msg-row.sent {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.chat-msg-row.received {
  align-self: flex-start;
}

.chat-msg-avatar {
  flex-shrink: 0;
  margin-top: 2px;
}

.chat-msg-content {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 100%;
}

.chat-msg-row.sent .chat-msg-content {
  align-items: flex-end;
}

.chat-msg-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 0.75rem;
}

.chat-msg-author {
  font-weight: 600;
  color: var(--color-text, #0f172a);
}

.chat-msg-time {
  color: var(--color-text-muted, #64748b);
}

.chat-msg-bubble {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.9rem;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
}

.chat-msg-row.received .chat-msg-bubble {
  background: var(--color-bg-subtle, #f1f5f9);
  color: var(--color-text, #0f172a);
  border-top-left-radius: 2px;
  border: 1px solid var(--color-border, #e2e8f0);
}

.chat-msg-row.sent .chat-msg-bubble {
  background: var(--color-primary, #6366f1);
  color: #ffffff;
  border-top-right-radius: 2px;
}

/* Date Divider */
.chat-date-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 16px 0 8px;
  position: relative;
}

.chat-date-divider::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 1px;
  background: var(--color-border, #e2e8f0);
  z-index: 1;
}

.chat-date-divider span {
  position: relative;
  z-index: 2;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-text-muted, #64748b);
  background: var(--color-bg, #ffffff);
  padding: 3px 12px;
  border-radius: 12px;
  border: 1px solid var(--color-border, #e2e8f0);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

/* Image Attachment Card */
.chat-attachment-img-wrap {
  margin-top: 6px;
  max-width: 380px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--color-border, #e2e8f0);
  background: #f8fafc;
}

.chat-attachment-img {
  display: block;
  max-width: 100%;
  max-height: 360px;
  object-fit: contain;
  border-radius: 8px;
  cursor: pointer;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.chat-attachment-img:hover {
  opacity: 0.92;
  transform: scale(1.01);
}

/* Attachment Chip */
.chat-attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: var(--radius-md, 8px);
  background: var(--color-bg-subtle, #f1f5f9);
  border: 1px solid var(--color-border, #e2e8f0);
  color: var(--color-text, #0f172a);
  text-decoration: none;
  font-size: 0.8125rem;
  margin-top: 6px;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.chat-attachment-chip:hover {
  background: var(--color-bg-hover, #e2e8f0);
  border-color: var(--color-border-hover, #cbd5e1);
}

.chat-msg-row.sent .chat-attachment-chip {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.35);
  color: #ffffff;
}

.chat-attachment-name {
  font-weight: 500;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-attachment-action {
  font-weight: 600;
  font-size: 0.75rem;
  opacity: 0.8;
}

/* Composer Footer */
.chat-composer-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--color-border, #e2e8f0);
  background: var(--color-bg, #ffffff);
}

.chat-composer-form {
  display: flex;
  flex-direction: column;
}

.chat-composer-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 6px 10px;
  border-radius: var(--radius-lg, 12px);
  border: 1px solid var(--color-border, #cbd5e1);
  background: var(--color-bg, #ffffff);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.chat-composer-input-row:focus-within {
  border-color: var(--color-primary, #6366f1);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.chat-textarea {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  font-family: inherit;
  font-size: 0.9375rem;
  line-height: 1.4;
  padding: 6px 4px;
  max-height: 120px;
  background: transparent;
  color: var(--color-text, #0f172a);
}

.chat-composer-buttons {
  display: flex;
  align-items: center;
  gap: 4px;
}

.chat-attach-btn {
  color: var(--color-text-muted, #64748b);
}

.chat-send-btn {
  padding: 6px 14px;
  height: 36px;
}

/* --- Staff Picker Modal (New Chat) --- */
.chat-staff-picker-modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.chat-staff-picker-dialog {
  background: var(--color-bg, #ffffff);
  border-radius: var(--radius-lg, 12px);
  width: 90%;
  max-width: 440px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-xl, 0 20px 25px -5px rgba(0,0,0,0.1));
  border: 1px solid var(--color-border, #e2e8f0);
  overflow: hidden;
}

.chat-staff-picker-header {
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--color-border, #e2e8f0);
}

.chat-staff-picker-header h3 {
  margin: 0;
  font-size: 1.125rem;
}

.chat-staff-search-wrap {
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border, #e2e8f0);
}

.chat-staff-list {
  flex: 1;
  overflow-y: auto;
  max-height: 350px;
}

.chat-staff-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  width: 100%;
  border: none;
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.chat-staff-item:hover {
  background: var(--color-bg-hover, #f1f5f9);
}

.chat-staff-item-info {
  display: flex;
  flex-direction: column;
}

.chat-staff-item-name {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-text, #0f172a);
}

.chat-staff-item-role {
  font-size: 0.75rem;
  color: var(--color-text-muted, #64748b);
}

/* --- Attachment Chips & File Display (CHAT-G3-E) --- */
.chat-msg-attachments {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 6px;
}

.chat-attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: var(--radius-md, 8px);
  background: var(--color-bg-subtle, #f1f5f9);
  border: 1px solid var(--color-border, #e2e8f0);
  color: var(--color-text, #0f172a);
  text-decoration: none;
  font-size: 0.8125rem;
  font-weight: 500;
  transition: background-color 0.15s ease, border-color 0.15s ease;
  max-width: 320px;
}

.chat-msg-row.sent .chat-attachment-chip {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.25);
  color: #ffffff;
}

.chat-attachment-chip:hover {
  background: var(--color-bg-hover, #e2e8f0);
  text-decoration: none;
}

.chat-msg-row.sent .chat-attachment-chip:hover {
  background: rgba(255, 255, 255, 0.25);
}

.chat-attachment-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.chat-attachment-action {
  font-size: 0.75rem;
  opacity: 0.75;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.chat-composer-file-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  background: var(--color-bg-subtle, #f8fafc);
  border-bottom: 1px solid var(--color-border, #e2e8f0);
  font-size: 0.8125rem;
}

.chat-composer-file-remove {
  border: none;
  background: transparent;
  color: var(--color-text-muted, #64748b);
  cursor: pointer;
  padding: 2px;
  font-size: 1rem;
}