.carnival-chat {
  display: grid;
  grid-template-columns: minmax(12rem, 15rem) minmax(0, 1fr);
  gap: 1rem;
  align-items: stretch;
  min-height: 60vh;
  max-width: 100%;
}

.carnival-chat__sidebar {
  border-right: 1px solid var(--pico-muted-border-color);
  padding-right: 0.75rem;
  min-width: 0;
}

.carnival-chat__sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

/* Pico estica form/button — manter o + compacto no header */
.carnival-chat__sidebar-header form.button_to {
  display: inline-flex;
  margin: 0;
  width: auto;
}

.carnival-chat__sidebar-header form.button_to button {
  width: auto;
  margin: 0;
}

.carnival-chat__conversations {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.carnival-chat__conversations li {
  margin: 0;
  padding: 0;
}

.carnival-chat__conversations a {
  display: block;
  padding: 0.4rem 0.55rem;
  border-radius: var(--pico-border-radius);
  color: var(--pico-color);
  font-size: 0.9rem;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.carnival-chat__conversations a:hover {
  background: color-mix(in srgb, var(--pico-primary) 12%, transparent);
}

.carnival-chat__conversations li.is-active a {
  background: var(--pico-primary-background);
  color: var(--pico-primary-inverse);
}

.carnival-chat__main {
  display: flex;
  flex-direction: column;
  min-height: 60vh;
  min-width: 0;
}

.carnival-chat__bubble {
  max-width: min(28rem, 75%);
  width: fit-content;
  padding: 0.45rem 0.75rem;
  border-radius: 0.85rem;
  font-size: 0.95rem;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.carnival-chat__text {
  white-space: pre-wrap;
}

.carnival-chat__bubble p {
  margin: 0;
}

.carnival-chat__bubble p + p {
  margin-top: 0.55rem;
}

.carnival-chat__bubble ul,
.carnival-chat__bubble ol {
  margin: 0.45rem 0 0.2rem;
  padding-left: 1.25rem;
}

.carnival-chat__bubble li {
  margin: 0.15rem 0;
}

.carnival-chat__bubble li p {
  margin: 0;
}

.carnival-chat__bubble strong,
.carnival-chat__bubble b {
  font-weight: 700;
}

.carnival-chat__bubble a {
  text-decoration: underline !important;
  word-break: break-word;
}

.carnival-chat__bubble--assistant a {
  color: var(--pico-primary);
}

.carnival-chat__bubble--user a {
  color: #fff;
}

.carnival-chat__bubble h1,
.carnival-chat__bubble h2,
.carnival-chat__bubble h3,
.carnival-chat__bubble h4 {
  margin: 0.55rem 0 0.25rem;
  font-size: 1em;
  line-height: 1.3;
}

.carnival-chat__bubble h1:first-child,
.carnival-chat__bubble h2:first-child,
.carnival-chat__bubble h3:first-child,
.carnival-chat__bubble h4:first-child,
.carnival-chat__bubble p:first-child,
.carnival-chat__bubble ul:first-child,
.carnival-chat__bubble ol:first-child {
  margin-top: 0;
}

.carnival-chat__bubble code {
  font-size: 0.88em;
  padding: 0.05rem 0.3rem;
  border-radius: 0.3rem;
  background: color-mix(in srgb, var(--pico-color) 8%, transparent);
}

.carnival-chat__bubble--user code {
  background: rgb(255 255 255 / 18%);
}

.carnival-chat__bubble pre {
  margin: 0.45rem 0;
  padding: 0.55rem 0.65rem;
  overflow-x: auto;
  border-radius: 0.5rem;
  background: color-mix(in srgb, var(--pico-color) 8%, transparent);
}

.carnival-chat__bubble pre code {
  padding: 0;
  background: transparent;
}

.carnival-chat__bubble blockquote {
  margin: 0.45rem 0;
  padding-left: 0.65rem;
  border-left: 3px solid color-mix(in srgb, var(--pico-primary) 45%, transparent);
  opacity: 0.92;
}

.carnival-chat__media {
  margin: 0.35rem 0;
  max-width: 100%;
}

.carnival-chat__media:first-child {
  margin-top: 0;
}

.carnival-chat__media:last-child {
  margin-bottom: 0;
}

.carnival-chat__image {
  display: block;
  max-width: min(22rem, 100%);
  width: auto;
  height: auto;
  border-radius: 0.65rem;
}

.carnival-chat__messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding: 0.5rem 0.25rem;
  scrollbar-color: color-mix(in srgb, var(--pico-primary) 35%, transparent)
    transparent;
}

.carnival-chat__bubble--user {
  align-self: flex-end;
  background: var(--pico-primary-background);
  color: #fff;
}

.carnival-chat__bubble--user p,
.carnival-chat__bubble--user a,
.carnival-chat__bubble--user .carnival-chat__text {
  color: #fff;
}


.carnival-chat__bubble--assistant {
  align-self: flex-start;
  background: color-mix(in srgb, var(--pico-muted-border-color) 55%, transparent);
}

.carnival-chat__bubble.is-typing {
  padding: 0.6rem 0.85rem;
}

.carnival-chat__typing {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.carnival-chat__typing span {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: color-mix(in srgb, var(--pico-primary) 70%, transparent);
  animation: carnival-chat-typing 1.2s ease-in-out infinite;
}

.carnival-chat__typing span:nth-child(2) {
  animation-delay: 0.18s;
}

.carnival-chat__typing span:nth-child(3) {
  animation-delay: 0.36s;
}

@keyframes carnival-chat-typing {
  0%,
  60%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }

  30% {
    opacity: 1;
    transform: translateY(-0.22rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  .carnival-chat__typing span {
    animation: carnival-chat-typing-fade 1.4s ease-in-out infinite;
    transform: none;
  }

  @keyframes carnival-chat-typing-fade {
    0%,
    100% {
      opacity: 0.35;
    }

    50% {
      opacity: 1;
    }
  }
}

.carnival-chat__error {
  display: none;
}

.carnival-chat__form {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  margin-top: 0.5rem;
}

.carnival-chat__form textarea {
  flex: 1;
  margin: 0;
  resize: vertical;
  min-height: 2.75rem;
}

.carnival-chat__form button {
  width: auto;
  margin: 0;
}

.carnival-chat__empty {
  margin: auto;
  text-align: center;
  max-width: 24rem;
}

@media (max-width: 40rem) {
  .carnival-chat {
    grid-template-columns: 1fr;
  }

  .carnival-chat__sidebar {
    border-right: none;
    border-bottom: 1px solid var(--pico-muted-border-color);
    padding-right: 0;
    padding-bottom: 0.75rem;
  }

  .carnival-chat__bubble {
    max-width: 90%;
  }
}
