/* Messages page: the conversations and the open one. Layout, tokens, header and
   footer come from shared/site.css; buttons, avatars, Markdown, dialogs and toasts
   are the same as the Communities page's (communities.css), kept here so neither
   page depends on the other. */

.messages-page {
  padding-block: 40px 72px;
}

.messages-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 24px;
}

.messages-title {
  font-size: clamp(1.75rem, 3.6vw, 2.5rem);
  font-weight: 800;
}

.messages-status,
.messages-empty {
  padding: 32px 16px;
  color: var(--theme-text-secondary);
  text-align: center;
}

/* Signed out */

.messages-signed-out {
  display: grid;
  justify-items: center;
  gap: 16px;
  padding: 48px 16px;
  border: 1px solid var(--theme-border-subtle);
  border-radius: var(--theme-radius-lg);
  background: var(--theme-bg-secondary);
  color: var(--theme-text-secondary);
  font-size: 17px;
  text-align: center;
}

.messages-signed-out-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: var(--theme-radius-md);
  background: var(--site-primary-soft);
  color: var(--theme-color-primary);
}

/* Layout: the list beside the conversation on wide screens, one at a time on small ones */

.messages-layout {
  display: grid;
  grid-template-columns: minmax(280px, 380px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.messages-threads,
.messages-conversation {
  min-width: 0;
  border: 1px solid var(--theme-border-subtle);
  border-radius: var(--theme-radius-lg);
  background: var(--theme-surface-raised);
}

.messages-threads {
  max-height: min(78vh, 900px);
  overflow-y: auto;
}

.messages-pick {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 72px 16px;
  color: var(--theme-text-secondary);
  text-align: center;
}

.messages-pick svg {
  color: var(--theme-text-tertiary);
}

.messages-icon-button.messages-back {
  display: none;
}

@media (max-width: 1023px) {
  .messages-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .messages-layout.has-peer .messages-threads,
  .messages-layout:not(.has-peer) .messages-conversation {
    display: none;
  }

  .messages-icon-button.messages-back {
    display: inline-flex;
  }
}

[dir='rtl'] .messages-back svg {
  transform: scaleX(-1);
}

/* Threads */

.messages-thread-list {
  margin: 0;
  padding: 6px;
  list-style: none;
}

.messages-thread {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: var(--theme-radius-md);
  color: inherit;
  text-decoration: none;
  transition: background 120ms ease;
}

.messages-thread:hover {
  background: var(--theme-bg-secondary);
}

.messages-thread.is-active {
  background: var(--site-primary-soft);
}

.messages-thread-text {
  display: grid;
  flex: 1;
  gap: 2px;
  min-width: 0;
}

.messages-thread-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.messages-thread-name {
  font-weight: 700;
  overflow-wrap: anywhere;
}

.messages-thread-time {
  flex: none;
  color: var(--theme-text-tertiary);
  font-size: 12px;
}

.messages-thread-preview {
  display: -webkit-box;
  overflow: hidden;
  color: var(--theme-text-secondary);
  font-size: 14px;
  overflow-wrap: anywhere;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.messages-thread.has-unread .messages-thread-preview {
  color: var(--theme-text-primary);
  font-weight: 600;
}

.messages-helper {
  justify-self: start;
  padding: 1px 8px;
  border-radius: var(--theme-radius-full);
  background: color-mix(in srgb, #16a34a 14%, transparent);
  color: #15803d;
  font-size: 12px;
  font-weight: 600;
}

[data-theme='dark'] .messages-helper {
  color: #4ade80;
}

.messages-unread {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding-inline: 6px;
  border-radius: var(--theme-radius-full);
  background: var(--theme-color-primary);
  color: #ffffff;
  font-size: 12px;
  font-weight: 700;
}

/* Conversation */

.messages-conversation-inner {
  display: flex;
  flex-direction: column;
}

.messages-conversation-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--theme-border-subtle);
}

.messages-conversation-person {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.messages-conversation-name {
  font-size: 18px;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.messages-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-block-size: 320px;
  max-block-size: min(62vh, 720px);
  margin: 0;
  padding: 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--theme-bg-secondary);
  list-style: none;
}

.messages-list .messages-empty {
  margin-block: auto;
}

.messages-older {
  display: flex;
  justify-content: center;
}

.messages-message {
  display: flex;
}

.messages-message.is-mine {
  justify-content: flex-end;
}

.messages-bubble {
  display: grid;
  gap: 6px;
  min-inline-size: 0;
  max-inline-size: min(78%, 760px);
  padding: 10px 14px;
  border: 1px solid var(--theme-border-subtle);
  border-radius: var(--theme-radius-lg);
  border-end-start-radius: var(--theme-radius-sm);
  background: var(--theme-surface-raised);
  box-shadow: var(--theme-shadow-sm);
}

.messages-message.is-mine .messages-bubble {
  border-color: transparent;
  border-end-start-radius: var(--theme-radius-lg);
  border-end-end-radius: var(--theme-radius-sm);
  background: var(--site-primary-soft);
}

.messages-message.is-editing .messages-bubble {
  outline: 2px solid var(--theme-color-primary);
  outline-offset: 2px;
}

.messages-body {
  font-size: 15px;
}

.messages-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
  color: var(--theme-text-tertiary);
  font-size: 12px;
}

.messages-edited {
  font-style: italic;
}

.messages-read {
  display: inline-flex;
}

.messages-read.is-read {
  color: var(--theme-color-primary);
}

.messages-reactions,
.messages-message-actions {
  display: inline-flex;
  gap: 2px;
}

.messages-message-actions {
  margin-inline-start: auto;
}

.messages-message-action {
  width: 28px;
  height: 28px;
}

.messages-reaction {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 26px;
  padding: 2px 8px;
  border: 1px solid var(--theme-border-subtle);
  border-radius: var(--theme-radius-full);
  background: transparent;
  color: var(--theme-text-secondary);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.messages-reaction:hover:not(:disabled) {
  border-color: var(--theme-color-primary);
  color: var(--theme-color-primary);
}

.messages-reaction.is-active {
  border-color: var(--theme-color-primary);
  background: var(--site-primary-soft);
  color: var(--theme-color-primary);
}

.messages-reaction:disabled {
  cursor: default;
}

/* Composer */

.messages-composer {
  display: grid;
  gap: 6px;
  padding: 12px;
  border-top: 1px solid var(--theme-border-subtle);
}

.messages-editing {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--theme-color-primary);
  font-size: 13px;
  font-weight: 600;
}

.messages-editing[hidden] {
  display: none;
}

.messages-editing-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.messages-composer-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.messages-composer-input {
  flex: 1;
  min-height: 44px;
  resize: none;
}

.messages-send {
  width: 44px;
  min-height: 44px;
  padding: 0;
}

.messages-help {
  color: var(--theme-text-tertiary);
  font-size: 12px;
}

/* Buttons */

.messages-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 8px 16px;
  border: 1px solid transparent;
  border-radius: var(--theme-radius-md);
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, box-shadow 120ms ease, color 120ms ease;
}

.messages-button:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.messages-button-primary {
  background: var(--theme-color-primary);
  color: #ffffff;
  box-shadow: var(--theme-shadow-sm);
}

.messages-button-primary:hover:not(:disabled) {
  box-shadow: var(--theme-shadow-md);
}

.messages-button-outline {
  border-color: var(--theme-border-default);
  color: var(--theme-text-primary);
}

.messages-button-outline:hover:not(:disabled) {
  border-color: var(--theme-color-primary);
}

.messages-button-danger {
  background: #dc2626;
  color: #ffffff;
}

.messages-button-danger:hover:not(:disabled) {
  background: #b91c1c;
}

.messages-button-ghost {
  color: var(--theme-text-secondary);
}

.messages-button-ghost:hover:not(:disabled) {
  background: var(--theme-bg-tertiary);
  color: var(--theme-text-primary);
}

.messages-button .site-loader.is-compact,
.messages-icon-button .site-loader.is-compact {
  padding: 0;
}

.messages-icon-button {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: var(--theme-radius-md);
  background: transparent;
  color: var(--theme-text-secondary);
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}

.messages-icon-button:hover:not(:disabled) {
  background: var(--theme-bg-tertiary);
  color: var(--theme-text-primary);
}

.messages-icon-button.is-active {
  color: var(--theme-color-primary);
}

.messages-icon-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Avatars */

.messages-avatar {
  --messages-avatar-size: 32px;
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: var(--messages-avatar-size);
  height: var(--messages-avatar-size);
  overflow: hidden;
  border-radius: var(--theme-radius-full);
  background: var(--theme-bg-tertiary);
  color: var(--theme-text-secondary);
  font-size: calc(var(--messages-avatar-size) * 0.42);
  font-weight: 700;
}

.messages-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.messages-avatar.is-placeholder {
  background: var(--site-primary-soft);
  color: var(--theme-color-primary);
}

/* Markdown written by members */

.messages-markdown {
  overflow-wrap: anywhere;
}

.messages-markdown > * + * {
  margin-top: 0.75em;
}

.messages-markdown h1,
.messages-markdown h2,
.messages-markdown h3,
.messages-markdown h4 {
  margin-top: 1.2em;
  font-size: 1.15em;
  font-weight: 700;
}

.messages-markdown ul,
.messages-markdown ol {
  padding-inline-start: 1.4em;
}

.messages-markdown a {
  color: var(--theme-color-primary);
}

.messages-markdown code {
  padding: 1px 6px;
  border-radius: var(--theme-radius-sm);
  background: var(--theme-bg-tertiary);
  font-size: 0.9em;
}

.messages-markdown pre {
  overflow-x: auto;
  padding: 12px 14px;
  border-radius: var(--theme-radius-md);
  background: var(--theme-bg-tertiary);
}

.messages-markdown pre code {
  padding: 0;
  background: transparent;
}

.messages-markdown blockquote {
  padding-inline-start: 14px;
  border-inline-start: 3px solid var(--theme-color-primary);
  color: var(--theme-text-secondary);
}

.messages-markdown img {
  max-width: 100%;
  height: auto;
  border-radius: var(--theme-radius-md);
}

.messages-markdown-table {
  overflow-x: auto;
}

.messages-markdown table {
  border-collapse: collapse;
}

.messages-markdown th,
.messages-markdown td {
  padding: 6px 10px;
  border: 1px solid var(--theme-border-subtle);
  text-align: start;
}

/* Dialogs */

.messages-dialog {
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100dvh - 48px);
  padding: 0;
  border: 1px solid var(--theme-border-subtle);
  border-radius: var(--theme-radius-lg);
  background: var(--theme-surface-raised);
  color: var(--theme-text-primary);
  box-shadow: var(--theme-shadow-md);
}

.messages-dialog[open] {
  display: flex;
  flex-direction: column;
}

.messages-dialog-lg {
  width: min(820px, calc(100vw - 32px));
}

.messages-dialog::backdrop {
  background: rgba(0, 0, 0, 0.45);
}

.messages-dialog-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-block: 12px;
  padding-inline: 24px 12px;
  border-bottom: 1px solid var(--theme-border-subtle);
}

.messages-dialog-title {
  font-size: 18px;
  font-weight: 700;
}

.messages-dialog-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 20px 24px;
}

.messages-dialog-message {
  font-size: 16px;
}

.messages-dialog-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 24px 20px;
  border-top: 1px solid var(--theme-border-subtle);
}

.messages-input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--theme-border-default);
  border-radius: var(--theme-radius-md);
  background: var(--theme-bg-primary);
  color: var(--theme-text-primary);
  font: inherit;
  font-size: 15px;
  resize: vertical;
}

.messages-input:focus {
  border-color: var(--theme-color-primary);
  outline: none;
  box-shadow: 0 0 0 3px var(--site-primary-soft);
}

/* Toasts */

.messages-toasts {
  position: fixed;
  inset-block-end: calc(16px + env(safe-area-inset-bottom, 0px));
  inset-inline-end: 16px;
  z-index: 100;
  display: grid;
  gap: 8px;
  max-width: min(420px, calc(100vw - 32px));
}

.messages-toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 16px;
  border: 1px solid var(--theme-border-subtle);
  border-inline-start: 4px solid var(--theme-color-primary);
  border-radius: var(--theme-radius-md);
  background: var(--theme-surface-raised);
  box-shadow: var(--theme-shadow-md);
  font-size: 15px;
  animation: messages-toast-in 200ms ease;
}

.messages-toast svg {
  flex: none;
  margin-top: 2px;
  color: var(--theme-color-primary);
}

.messages-toast.is-success {
  border-inline-start-color: #16a34a;
}

.messages-toast.is-success svg {
  color: #16a34a;
}

.messages-toast.is-error {
  border-inline-start-color: #dc2626;
}

.messages-toast.is-error svg {
  color: #dc2626;
}

@keyframes messages-toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .messages-toast {
    animation: none;
  }
}

@media (max-width: 560px) {
  .messages-page {
    padding-block: 24px 48px;
  }

  .messages-bubble {
    max-inline-size: 88%;
  }

  .messages-help {
    display: none;
  }
}
