/* ABOUTME: Styles for multi-user chatrooms — intentionally distinct from AI chat */

/* ABOUTME: Uses blue accent and flat message list (not bubbles) to prevent confusion with private AI chat */

/* ========== Index Page ========== */
.chatrooms-index {
  max-width: 640px;
  margin: 0 auto;
  padding: var(--space-4);
}

.chatrooms-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: var(--space-4);
}

.chatrooms-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.chatroom-card {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.chatroom-card:hover {
  border-color: var(--blue);
  box-shadow: 0 2px 8px rgb(66 133 244 / 10%);
}

.chatroom-card-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  background: var(--blue-light);
  color: var(--blue);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.125rem;
  flex-shrink: 0;
}

.chatroom-card-body {
  flex: 1;
  min-width: 0;
}

.chatroom-card-name-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.125rem;
}

.chatroom-card-name {
  font-weight: 600;
  font-size: 1rem;
}

.chatroom-card-unread {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 0.375rem;
  border-radius: 999px;
  background: var(--red);
  color: white;
  font-size: 0.6875rem;
  font-weight: 700;
}

.chatroom-card-time {
  color: var(--gray-400);
}

.chatroom-card-description {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  line-height: 1.4;
  margin-bottom: 0.25rem;
}

.chatroom-card-meta {
  font-size: 0.75rem;
  color: var(--gray-500);
}

.chatroom-card-meta i {
  margin-right: 0.25rem;
}

.chatroom-card-arrow {
  color: var(--gray-400);
  font-size: 0.75rem;
  flex-shrink: 0;
}

/* ========== Room View ========== */
.chatroom-container {
  display: flex;
  flex-direction: column;
  height: calc(100dvh - 56px); /* viewport minus nav */
  max-width: 800px;
  margin: 0 auto;
  background: var(--surface);
}

.chatroom-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.chatroom-back-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--text-secondary);
  text-decoration: none;
  transition: background 0.2s;
}

.chatroom-back-btn:hover {
  background: var(--gray-100);
}

.chatroom-header-info {
  flex: 1;
}

.chatroom-title {
  font-size: 1.0625rem;
  font-weight: 700;
  line-height: 1.2;
  margin: 0;
}

.chatroom-member-count {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

/* Public room warning banner */
.chatroom-banner {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0.5rem var(--space-4);
  background: var(--blue-light);
  color: var(--blue);
  font-size: 0.75rem;
  font-weight: 500;
  flex-shrink: 0;
}

.chatroom-banner i {
  font-size: 0.6875rem;
}

/* ========== Message List (flat style, not bubbles) ========== */
.chatroom-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-2) 0;
  visibility: hidden;
}

.chatroom-messages.loaded {
  visibility: visible;
}

.chatroom-scroll-anchor {
  height: 1px;
}

.chatroom-message {
  display: flex;
  gap: var(--space-3);
  padding: 0.375rem var(--space-4);
  transition: background 0.15s;
}

.chatroom-message:hover {
  background: var(--gray-50);
}

.chatroom-message-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 0.75rem;
  font-weight: 600;
  flex-shrink: 0;
  margin-top: 0.125rem;
}

.chatroom-message-body {
  flex: 1;
  min-width: 0;
}

.chatroom-message-header {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  margin-bottom: 0.125rem;
}

.chatroom-message-author {
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--text);
}

.chatroom-message--own .chatroom-message-author {
  color: var(--blue);
}

.chatroom-message-time {
  font-size: 0.6875rem;
  color: var(--gray-400);
}

.chatroom-message-edited {
  font-size: 0.6875rem;
  color: var(--gray-400);
  font-style: italic;
}

.chatroom-message-content {
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--text);
  overflow-wrap: break-word;
}

.chatroom-message-content span {
  white-space: pre-wrap;
}

.chatroom-message-deleted {
  color: var(--gray-400);
}

/* Optimistic message (pending server confirmation) */
.chatroom-message--optimistic {
  opacity: 0.6;
}

/* ========== Day Divider ========== */
.chatroom-day-divider {
  display: flex;
  align-items: center;
  padding: var(--space-3) var(--space-4);
}

.chatroom-day-divider::before,
.chatroom-day-divider::after {
  content: "";
  flex: 1;
  border-bottom: 1px solid var(--border);
}

.chatroom-day-divider-label {
  padding: 0 var(--space-3);
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ========== Input Area ========== */
.chatroom-input-area {
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.chatroom-input-row {
  display: flex;
  gap: var(--space-2);
  align-items: center;
}

.chatroom-input {
  flex: 1;
  padding: 0.625rem 0.875rem;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 0.875rem;
  background: white;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.chatroom-input:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgb(66 133 244 / 15%);
}

.chatroom-send-btn {
  padding: 0.625rem 1.25rem;
  background: var(--blue);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  white-space: nowrap;
}

.chatroom-send-btn:hover {
  background: #3b78e7;
}

.chatroom-send-btn:active {
  background: #2d6ae0;
}

/* ========== Load More ========== */
.chatroom-load-more {
  display: block;
  width: 100%;
  padding: var(--space-2);
  background: none;
  border: none;
  color: var(--blue);
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
}

.chatroom-load-more:hover {
  text-decoration: underline;
}

/* ========== Header Actions ========== */
.chatrooms-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chatroom-new-btn {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  background: var(--blue) !important;
  border-color: var(--blue) !important;
  font-size: 0.8125rem;
  padding: 0.5rem 1rem;
}

.chatroom-header-actions {
  display: flex;
  gap: 0.25rem;
  margin-left: auto;
}

.chatroom-header-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: none;
  background: var(--gray-100);
  color: var(--gray-600);
  cursor: pointer;
  text-decoration: none;
  transition: background 0.2s;
}

.chatroom-header-btn:hover {
  background: var(--gray-200);
  color: var(--gray-800);
}

.chatroom-header-btn--leave {
  color: var(--red);
}

.chatroom-header-btn--leave:hover {
  background: var(--red-light);
}

/* ========== Card Badges ========== */
.chatroom-card-badge {
  display: inline-block;
  font-size: 0.6875rem;
  font-weight: 600;
  padding: 0.125rem 0.5rem;
  border-radius: 999px;
  margin-left: 0.5rem;
}

.chatroom-card-badge--joined {
  background: var(--blue-light);
  color: var(--blue);
}

/* ========== Join Button ========== */
.chatroom-join-btn {
  width: 100%;
  padding: 0.75rem;
  background: var(--blue);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.chatroom-join-btn:hover {
  background: #3b78e7;
}

/* ========== Muted Notice ========== */
.chatroom-muted-notice {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: 0.75rem;
  color: var(--text-secondary);
  font-size: 0.8125rem;
  text-align: center;
}

/* ========== Message Action Buttons (edit, delete) ========== */

/* Action buttons group (edit + delete) */
.chatroom-message-actions {
  display: none;
  align-items: center;
  gap: 0.25rem;
  margin-left: auto;
}

.chatroom-message:hover .chatroom-message-actions {
  display: inline-flex;
}

/* Edit button form wrapper — button_to generates a <form>, flatten it */
.chatroom-message-action-form {
  display: inline-flex;
  margin: 0;
  padding: 0;
}

.chatroom-message-action {
  background: none;
  border: none;
  color: var(--gray-400);
  cursor: pointer;
  padding: 0.125rem 0.25rem;
  font-size: 0.6875rem;
  border-radius: var(--radius-sm);
  transition: color 0.15s, background 0.15s;
  text-decoration: none;
}

.chatroom-message-action:hover {
  color: var(--blue);
  background: var(--blue-light);
}

.chatroom-message-action:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 1px;
}

/* ========== Edit Form ========== */
.chatroom-message--editing {
  background: var(--blue-light);
  border-radius: var(--radius);
}

.chatroom-message-editing-label {
  font-size: 0.6875rem;
  color: var(--blue);
  font-weight: 600;
}

.chatroom-edit-form {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.chatroom-edit-input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--blue);
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-family: inherit;
  resize: vertical;
  min-height: 2.5rem;
}

.chatroom-edit-input:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgb(66 133 244 / 15%);
}

.chatroom-edit-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.chatroom-edit-hint {
  font-size: 0.6875rem;
  color: var(--gray-400);
  margin-right: auto;
}

.chatroom-edit-save {
  background: var(--blue) !important;
  border-color: var(--blue) !important;
}

/* ========== Message Delete Button ========== */
.chatroom-message-delete {
  display: none;
  background: none;
  border: none;
  color: var(--gray-400);
  cursor: pointer;
  padding: 0.125rem 0.25rem;
  font-size: 0.6875rem;
  border-radius: var(--radius-sm);
  transition: color 0.15s, background 0.15s;
  margin-left: auto;
}

.chatroom-message:hover .chatroom-message-delete {
  display: inline-flex;
}

.chatroom-message-delete:hover {
  color: var(--red);
  background: var(--red-light);
}

.chatroom-message-delete:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 1px;
}

/* ========== Deleted Message ========== */
.chatroom-message--deleted .chatroom-message-avatar {
  opacity: 0.4;
}

.chatroom-message-deleted-text {
  color: var(--gray-400);
  font-size: 0.8125rem;
}

/* ========== Members List (Modal) ========== */
.chatroom-members-list {
  display: flex;
  flex-direction: column;
}

.chatroom-member-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.625rem 0;
  border-bottom: 1px solid var(--gray-100);
}

.chatroom-member-row:last-child {
  border-bottom: none;
}

.chatroom-member-info {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.chatroom-member-name {
  font-weight: 500;
  font-size: 0.875rem;
}

.chatroom-member-role {
  display: inline-block;
  font-size: 0.625rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.0625rem 0.375rem;
  border-radius: 999px;
  margin-left: 0.375rem;
}

.chatroom-member-role--admin {
  background: var(--blue-light);
  color: var(--blue);
}

.chatroom-member-role--moderator {
  background: var(--purple-light);
  color: var(--purple);
}

.chatroom-member-role--muted {
  background: var(--gray-100);
  color: var(--gray-500);
}

.chatroom-member-actions {
  position: relative;
}

.chatroom-member-actions-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: none;
  background: none;
  color: var(--gray-500);
  cursor: pointer;
  transition: background 0.15s;
}

.chatroom-member-actions-btn:hover {
  background: var(--gray-100);
}

.chatroom-member-actions-menu {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 0.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 12px rgb(0 0 0 / 15%);
  min-width: 160px;
  display: none;
  z-index: 100;
}

.chatroom-member-actions-menu .dropdown-action-item {
  display: block;
  width: 100%;
  padding: 0.5rem 0.75rem;
  background: none;
  border: none;
  text-align: left;
  font-size: 0.8125rem;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s;
}

.chatroom-member-actions-menu .dropdown-action-item:hover {
  background: var(--gray-50);
}

.chatroom-member-actions-menu .dropdown-action-item--danger {
  color: var(--red);
}

.chatroom-member-actions-menu .dropdown-action-item--danger:hover {
  background: var(--red-light);
}

/* ========== Image Attachments ========== */
.chatroom-message-images {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  margin-top: 0.375rem;
}

.chatroom-message-image-link {
  display: block;
  max-width: 300px;
  min-height: 100px;
  background: var(--gray-100);
  border-radius: var(--radius);
  overflow: hidden;
}

.chatroom-message-image {
  display: block;
  max-width: 100%;
  max-height: 240px;
  border-radius: var(--radius);
  object-fit: cover;
  cursor: pointer;
  transition: opacity 0.15s;
}

.chatroom-message-image:hover {
  opacity: 0.9;
}


/* Attach button and file input */
.chatroom-attach-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  color: var(--gray-500);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}

.chatroom-attach-btn:hover {
  background: var(--gray-100);
  color: var(--blue);
}

.chatroom-file-input {
  display: none;
}

/* Image preview strip above input */
.chatroom-image-preview {
  display: flex;
  gap: 0.375rem;
  padding: 0.375rem 0;
  align-items: center;
  flex-wrap: wrap;
}

.chatroom-image-thumb {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.chatroom-image-clear {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: none;
  background: var(--gray-200);
  color: var(--gray-600);
  font-size: 0.875rem;
  cursor: pointer;
  transition: background 0.15s;
}

.chatroom-image-clear:hover {
  background: var(--gray-300);
}

/* ========== Emoji Reactions ========== */
.chatroom-reactions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  margin-top: 0.25rem;
  flex-wrap: wrap;
  position: relative;
}

.chatroom-reaction-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.125rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--gray-50);
  font-size: 0.8125rem;
  cursor: pointer;
  transition: all 0.15s;
  line-height: 1.4;
}

.chatroom-reaction-btn:hover {
  background: var(--gray-100);
  border-color: var(--gray-300);
}

.chatroom-reaction-btn--active {
  background: var(--blue-light);
  border-color: var(--blue);
}

.chatroom-reaction-btn--active:hover {
  background: #d0e1fd;
}

.chatroom-reaction-emoji {
  font-size: 0.875rem;
}

.chatroom-reaction-count {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.chatroom-reaction-btn--active .chatroom-reaction-count {
  color: var(--blue);
}

.chatroom-reaction-add {
  display: inline-flex;
  width: 26px;
  height: 26px;
  align-items: center;
  justify-content: center;
  border: 1px dashed var(--gray-300);
  border-radius: 999px;
  background: none;
  color: var(--gray-400);
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.15s;
}

.chatroom-reaction-add:hover {
  border-color: var(--blue);
  color: var(--blue);
  background: var(--blue-light);
}

/* Emoji picker popup */
.chatroom-emoji-picker {
  position: absolute;
  bottom: 100%;
  left: 0;
  margin-bottom: 0.25rem;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.125rem;
  padding: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 12px rgb(0 0 0 / 15%);
  z-index: 50;
}

.chatroom-emoji-option {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  border-radius: var(--radius-sm);
  font-size: 1.25rem;
  cursor: pointer;
  transition: background 0.1s;
}

.chatroom-emoji-option:hover {
  background: var(--gray-100);
}

/* ========== Image Lightbox ========== */
.chatroom-lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgb(0 0 0 / 85%);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
  padding: var(--space-4);
}

.chatroom-lightbox-image {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: var(--radius);
}

/* ========== Empty State ========== */
.chatrooms-empty {
  text-align: center;
  padding: var(--space-8) var(--space-4);
  color: var(--text-secondary);
  font-size: 0.875rem;
}

/* ========== Mobile ========== */
@media (width <= 768px) {
  .chatroom-container {
    height: calc(100dvh - 50px);
  }

  .chatroom-message-avatar {
    width: 32px;
    height: 32px;
    font-size: 0.6875rem;
  }

  .chatroom-message {
    padding: 0.25rem var(--space-3);
    gap: var(--space-2);
  }

  .chatroom-input {
    font-size: 1rem; /* prevent iOS zoom */
  }
}
