/* The Bot tab (communitiesBot.js): configuration, threads and conversation. */

.communities-bot {
  display: grid;
  gap: 18px;
  min-width: 0;
}

.communities-bot > .communities-back {
  justify-self: start;
}

.communities-bot-notice {
  display: grid;
  justify-items: start;
  gap: 14px;
}

/* Title bar */

.communities-bot-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.communities-bot-title {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-width: 0;
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.communities-bot-title svg {
  flex: none;
  margin-top: 2px;
  color: var(--theme-color-primary);
}

.communities-bot-bar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.communities-bot-bar-actions:empty {
  display: none;
}

.communities-bot-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: var(--theme-radius-full, 9999px);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.communities-bot-badge.is-active {
  background: color-mix(in srgb, #16a34a 15%, transparent);
  color: #15803d;
}

.communities-bot-badge.is-paused {
  background: color-mix(in srgb, #d97706 16%, transparent);
  color: #b45309;
}

:root[data-theme="dark"] .communities-bot-badge.is-active {
  color: #4ade80;
}

:root[data-theme="dark"] .communities-bot-badge.is-paused {
  color: #fbbf24;
}

.communities-bot-intro {
  margin: 0;
  color: var(--theme-text-secondary);
  font-size: 15px;
}

/* Remove buttons (files, threads) turn red on hover */

.communities-bot-remove:hover:not(:disabled) {
  background: color-mix(in srgb, #dc2626 12%, transparent);
  color: #dc2626;
}

/* Configuration */

.communities-bot-instructions {
  min-height: 200px;
  line-height: 1.5;
}

.communities-bot-files {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.communities-bot-files-empty {
  padding: 12px 14px;
  border: 1px dashed var(--theme-border-default);
  border-radius: var(--theme-radius-md);
  color: var(--theme-text-secondary);
  font-size: 15px;
}

.communities-bot-file {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-block: 8px;
  padding-inline: 14px 8px;
  border: 1px solid var(--theme-border-subtle);
  border-radius: var(--theme-radius-md);
  background: var(--theme-surface-raised);
}

.communities-bot-file-icon {
  display: inline-flex;
  flex: none;
  color: var(--theme-color-primary);
}

.communities-bot-file-meta {
  display: grid;
  flex: 1;
  min-width: 0;
}

.communities-bot-file-name {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.communities-bot-file-size {
  color: var(--theme-text-secondary);
  font-size: 13px;
}

.communities-bot-upload {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin-top: 4px;
}

.communities-bot-config-actions {
  display: flex;
  justify-content: flex-end;
  padding-top: 16px;
  border-top: 1px solid var(--theme-border-subtle);
}

/* Threads */

.communities-bot-threads {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr));
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.communities-bot-thread {
  display: flex;
  align-items: flex-start;
  gap: 4px;
  padding: 6px;
  border: 1px solid var(--theme-border-subtle);
  border-radius: var(--theme-radius-lg);
  background: var(--theme-surface-raised);
  box-shadow: var(--theme-shadow-sm);
  transition: box-shadow 120ms ease, border-color 120ms ease;
}

.communities-bot-thread:hover {
  border-color: var(--theme-border-default);
  box-shadow: var(--theme-shadow-md);
}

.communities-bot-thread-open {
  display: flex;
  flex: 1;
  align-items: flex-start;
  gap: 12px;
  min-width: 0;
  padding: 8px;
  border: 0;
  border-radius: var(--theme-radius-md);
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: start;
  cursor: pointer;
}

.communities-bot-thread-open:focus-visible {
  outline: 2px solid var(--theme-color-primary);
  outline-offset: 2px;
}

.communities-bot-thread-icon,
.communities-bot-avatar {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--site-primary-soft);
  color: var(--theme-color-primary);
}

.communities-bot-avatar {
  width: 32px;
  height: 32px;
}

.communities-bot-thread-text {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.communities-bot-thread-title {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.communities-bot-thread-meta {
  color: var(--theme-text-secondary);
  font-size: 13px;
}

/* Conversation */

.communities-bot-chat {
  display: grid;
  overflow: hidden;
  border: 1px solid var(--theme-border-subtle);
  border-radius: var(--theme-radius-lg);
  background: var(--theme-surface-raised);
}

.communities-bot-messages {
  display: flex;
  flex-direction: column;
  gap: 16px;
  height: clamp(320px, 62vh, 900px);
  margin: 0;
  padding: 20px;
  overflow-y: auto;
  overscroll-behavior: contain;
  list-style: none;
  background: var(--theme-bg-secondary);
}

.communities-bot-messages-empty {
  margin: auto;
  color: var(--theme-text-secondary);
  text-align: center;
}

.communities-bot-message {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-width: 0;
}

.communities-bot-message.is-user {
  flex-direction: row-reverse;
}

.communities-bot-bubble {
  display: grid;
  gap: 6px;
  min-width: 0;
  max-width: min(100%, 78ch);
  padding: 10px 14px;
  border: 1px solid var(--theme-border-subtle);
  border-radius: var(--theme-radius-lg);
  background: var(--theme-surface-raised);
  box-shadow: var(--theme-shadow-sm);
}

.communities-bot-message.is-bot .communities-bot-bubble {
  flex: 1;
}

.communities-bot-message.is-user .communities-bot-bubble {
  border-color: transparent;
  background: var(--site-primary-soft);
  box-shadow: none;
}

.communities-bot-message-text {
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.communities-bot-message.is-user .communities-bot-message-text {
  white-space: pre-wrap;
}

.communities-bot-message-text .site-loader.is-compact {
  justify-content: flex-start;
  padding: 0;
}

.communities-bot-message-time {
  color: var(--theme-text-secondary);
  font-size: 12px;
}

.communities-bot-message.is-user .communities-bot-message-time {
  text-align: end;
}

.communities-bot-cursor {
  display: inline-block;
  width: 7px;
  height: 1em;
  margin-inline-start: 2px;
  vertical-align: text-bottom;
  background: var(--theme-color-primary);
  animation: communities-bot-blink 0.9s steps(1) infinite;
}

/* The Markdown puts the cursor after the last block; keep it on the last line. */
.communities-bot-message.is-streaming .communities-bot-message-text > p:nth-last-child(2) {
  display: inline;
}

@keyframes communities-bot-blink {
  50% { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .communities-bot-cursor {
    animation: none;
  }
}

/* Composer */

.communities-bot-composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  margin: 12px 12px 0;
  padding-block: 6px;
  padding-inline: 16px 6px;
  border: 1px solid var(--theme-border-default);
  border-radius: 24px;
  background: var(--theme-bg-primary);
}

.communities-bot-composer:focus-within {
  border-color: var(--theme-color-primary);
  box-shadow: 0 0 0 3px var(--site-primary-soft);
}

.communities-bot-composer-input {
  flex: 1;
  min-width: 0;
  min-height: 24px;
  max-height: 180px;
  padding: 8px 0;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--theme-text-primary);
  font: inherit;
  font-size: 16px;
  line-height: 1.4;
  resize: none;
}

.communities-bot-composer-input:disabled {
  opacity: 0.6;
}

.communities-bot-send {
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--theme-color-primary);
  color: #ffffff;
  cursor: pointer;
  transition: filter 120ms ease;
}

.communities-bot-send:hover:not(:disabled) {
  filter: brightness(1.08);
}

.communities-bot-send:focus-visible {
  outline: 2px solid var(--theme-color-primary);
  outline-offset: 2px;
}

.communities-bot-send:disabled {
  opacity: 0.5;
  cursor: default;
}

/* The send arrow points along the reading direction. */
:root[dir="rtl"] .communities-bot-send svg {
  transform: scaleX(-1);
}

.communities-bot-composer-help {
  margin: 6px 16px 10px;
  color: var(--theme-text-secondary);
  font-size: 12px;
}

.communities-bot-paused {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 0;
  padding: 14px 16px;
  color: var(--theme-text-secondary);
  font-size: 15px;
}

.communities-bot-paused svg {
  flex: none;
  margin-top: 3px;
}

@media (max-width: 600px) {
  .communities-bot-messages {
    height: clamp(300px, 60vh, 640px);
    padding: 14px 10px;
  }

  .communities-bot-message .communities-avatar,
  .communities-bot-message .communities-bot-avatar {
    display: none;
  }

  .communities-bot-bubble {
    max-width: 100%;
  }

  .communities-bot-message.is-user .communities-bot-bubble {
    margin-inline-start: 24px;
  }

  .communities-bot-composer {
    margin-inline: 8px;
  }

  .communities-bot-config-actions .communities-button {
    width: 100%;
  }
}
