body {
  font-family: "Inter", "Segoe UI", sans-serif;
}

p {
    margin-block-start: 0em;
    margin-block-end: 0em;
    text-align: left;
}

.chat {
  display: grid;
  grid-template-columns: minmax(280px, 320px) 1fr;
  gap: clamp(1.5rem, 4vw, 2.5rem);
  padding: clamp(1.5rem, 4vw, 3rem);
  max-width: 1200px;
  margin: 0 auto;
  color: var(--text-primary);
}

.chat__sidebar {
  background: var(--surface-card);
  border-radius: 20px;
  border: 1px solid var(--border-light);
  box-shadow: 0 24px 40px -32px var(--shadow-primary);
  max-height: 50vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat__sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem 1rem;
}

.chat__sidebar-header h1 {
  margin: 0;
  font-size: 1.35rem;
}

.chat__refresh,
.chat__thread-refresh {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0.35rem;
  border-radius: 10px;
  transition: background 0.18s ease, color 0.18s ease;
}

.chat__refresh:hover,
.chat__thread-refresh:hover {
  color: var(--text-primary);
  background: rgba(63, 183, 180, 0.12);
}

.chat__search {
  padding: 0 1.5rem 1rem;
}

.chat__search input {
  width: 100%;
  border: 1px solid var(--border-light);
  border-radius: 12px;
  padding: 0.55rem 0.75rem;
  font-size: 0.95rem;
  background: var(--surface-ghost);
  color: var(--text-primary);
}

.chat__conversation-list {
  overflow-y: auto;
  padding: 0.75rem 0;
  display: grid;
  gap: 0.15rem;
}

.chat__conversation {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.75rem;
  padding: 0.75rem 1.5rem;
  max-height: 80px;
  cursor: pointer;
  align-content: space-around;
  background: var(--surface-card);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  transition: background 0.18s ease;
}

/* Delete button placed in the top-right corner of each conversation item. */
.chat__conversation {
  position: relative;
  padding-right: 3.25rem; /* space for the delete control */
}

.chat__delete {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  font-size: 0.95rem;
  cursor: pointer;
  padding: 0;
  border-radius: 8px;
  transition: background 0.12s ease, color 0.12s ease, transform 0.08s ease;
}

.chat__delete:focus {
  outline: none;
  box-shadow: 0 0 0 4px rgba(63,183,180,0.12);
  border-color: rgba(63,183,180,0.18);
}

.chat__delete:hover {
  background: rgba(0,0,0,0.04);
  color: var(--text-primary);
  transform: translateY(-1px);
}

/* When conversation item is active, make delete control more subtle */
.chat__conversation.is-active .chat__delete {
  color: var(--text-secondary);
}

@media (max-width: 640px) {
  .chat__conversation {
    padding-right: 2.5rem;
  }
  .chat__delete {
    top: 6px;
    right: 6px;
    width: 30px;
    height: 30px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat__delete {
    transition: none;
  }
}

.chat__conversation:hover,
.chat__conversation:focus-visible,
.chat__conversation.is-active {
  background: rgba(63, 183, 180, 0.12);
}

.chat__conversation img {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  box-shadow: 0 12px 24px -20px var(--shadow-secondary);
}

.chat__conversation-info {
  display: grid;
  gap: 0.25rem;
  min-width: 0;
}

.chat__conversation-name {
  margin: 0;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  justify-content: space-between;
  gap: 0.4rem;
}

.chat__conversation-preview {
  margin: 0;
  color: var(--text-secondary);
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat__conversation-meta {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.chat__badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  padding: 0 0.4rem;
  border-radius: 999px;
  background: var(--accent-primary);
  color: #fff;
  font-weight: 600;
  font-size: 0.75rem;
}

.chat__empty {
  margin: 1.5rem;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.chat__loading {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1.5rem;
  color: var(--text-secondary);
}

.chat__spinner {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid rgba(63, 183, 180, 0.2);
  border-top-color: var(--accent-primary);
  animation: chat-spin 0.8s linear infinite;
}

@keyframes chat-spin {
  to {
    transform: rotate(360deg);
  }
}

.chat__thread {
  background: var(--surface-card);
  border-radius: 20px;
  border: 1px solid var(--border-light);
  box-shadow: 0 24px 40px -32px var(--shadow-primary);
  display: flex;
  flex-direction: column;
  min-height: 480px;
}

.chat__thread-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 1.75rem 1rem;
  border-bottom: 1px solid var(--border-light);
}

.chat__thread-user {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.chat__thread-user img {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  object-fit: cover;
  box-shadow: 0 14px 24px -20px var(--shadow-secondary);
}

.chat__thread-user h2 {
  margin: 0;
  font-size: 1.1rem;
}

.chat__thread-user a {
  color: var(--accent-primary);
  font-size: 0.85rem;
  text-decoration: none;
}

.chat__thread-user a:hover,
.chat__thread-user a:focus-visible {
  text-decoration: underline;
}

.chat__thread-empty {
  flex: 1;
  display: grid;
  place-items: center;
  gap: 0.6rem;
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.chat__thread-empty i {
  width: 40px;
  height: 40px;
  color: var(--accent-primary);
}

.chat__messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1.2rem 1.6rem;
  display: grid;
  max-height: 50vh;
  row-gap: 0.65rem;
}


.chat__message {
  max-width: min(70%, 480px);
  padding: 0.6rem 0.85rem 0.55rem;
  border-radius: 16px;
  line-height: 1.45;
  display: inline-flex;
  flex-direction: column;
  gap: 0.3rem;
  background: var(--surface-ghost);
  color: var(--text-primary);
  box-shadow: 0 16px 30px -26px var(--shadow-secondary);
  word-wrap: break-word;
}

.chat__message--outgoing {
  margin-left: auto;
  align-self: flex-end;
  overflow-wrap: anywhere;
  background: var(--accent-primary);
  color: #fff;
  text-align: right;
}

.chat__message--ongoing {
  margin-right: auto;
  text-align: left;
}

.chat__message-meta {
  font-size: 0.7rem;
  color: var(--text-secondary);
}

.chat__message--outgoing .chat__message-meta {
  color: rgba(255, 255, 255, 0.75);
}

.chat__composer {
  border-top: 1px solid var(--border-light);
  padding: 1rem 1.75rem 1.5rem;
  display: grid;
  gap: 0.75rem;
}

.chat__composer textarea {
  width: 100%;
  border: 1px solid var(--border-light);
  border-radius: 14px;
  padding: 0.75rem 1rem;
  font-family: "Inter", "Segoe UI", sans-serif;
  font-size: 0.95rem;
  background: var(--surface-card);
  color: var(--text-primary);
  resize: vertical;
}

.chat__composer textarea:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px rgba(63, 183, 180, 0.18);
}

.chat__composer.is-loading {
  opacity: 0.65;
  pointer-events: none;
}

.chat__send {
  place-self: end;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  border: none;
  border-radius: 999px;
  padding: 0.55rem 1.4rem;
  background: var(--accent-primary);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.chat__send:hover,
.chat__send:focus-visible {
  transform: translateY(-1px);
  box-shadow: 0 18px 36px -24px var(--shadow-secondary);
}

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

  .chat__sidebar {
    max-height: 320px;
  }

  .chat__thread {
    min-height: 420px;
  }
}

.chat__conversation.is-active .chat__conversation-name {
  color: var(--accent-primary);
}

.chat__conversation.is-active .chat__conversation-preview {
  color: var(--text-primary);
}
