.chat-container {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
  border-radius: 0;
  border: none;
  border-left: 1px solid rgb(var(--color-border-200));
  background: rgb(var(--color-border-50));
  overflow: hidden;
}

.chats {
  position: relative;
  flex: 1;
  overflow-y: auto;
  padding: 1.75rem 1.75rem 1.25rem;
  display: flex;
  flex-direction: column;
}

.chats::after {
  content: '';
  position: sticky;
  bottom: 0;
  left: 0;
  right: 0;
  height: 2rem;
  pointer-events: none;
  background: linear-gradient(180deg, transparent 0%, rgb(var(--color-border-50)) 100%);
}

.chats > div {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  width: min(100%, 760px);
  margin: 0 auto;
}

.chats::-webkit-scrollbar {
  width: 8px;
}

.chats::-webkit-scrollbar-track {
  background: rgba(var(--color-border-100), 0.6);
  border-radius: 999px;
}

.chats::-webkit-scrollbar-thumb {
  background: rgb(var(--color-border-300));
  border-radius: 999px;
}

.chats::-webkit-scrollbar-thumb:hover {
  background: rgb(var(--color-border-400));
}

.initial-alga {
  text-align: center;
  color: rgb(var(--color-text-800));
  max-width: 480px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
  border-radius: 0.75rem;
  border: 1px solid rgb(var(--color-border-200));
  background: rgb(var(--color-card));
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.initial-alga img {
  margin: 0 auto 1rem;
}

.initial-alga h1 {
  font-size: 1.125rem;
  font-weight: 600;
  margin: 0;
  line-height: 1.4;
}

.chat-footer {
  padding: 1rem 1.5rem;
  background: rgb(var(--color-card));
  border-top: 1px solid rgb(var(--color-border-200));
}

.chat-footer__inner {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
}

.chat-footer__input {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.chat-input-wrapper {
  position: relative;
  display: flex;
  flex-direction: column;
}

.chat-input {
  width: 100%;
  min-height: 3.25rem;
  max-height: 18rem;
  resize: vertical;
  border-radius: 0.5rem;
  border: 1px solid rgb(var(--color-border-300));
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  line-height: 1.5;
  color: rgb(var(--color-text-900));
  background: rgb(var(--color-border-50));
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.chat-input:focus {
  outline: none;
  border-color: rgb(var(--color-primary-400));
  box-shadow: 0 0 0 3px rgba(var(--color-primary-400), 0.1);
}

.chat-input:disabled {
  background: rgb(var(--color-border-100));
  color: rgb(var(--color-text-500));
  cursor: not-allowed;
  opacity: 0.6;
}

.chat-input__hint {
  font-size: 0.75rem;
  line-height: 1.3;
  color: rgb(var(--color-text-500));
  margin: 0;
}

.chat-input__hint--editing {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.35rem;
  color: rgb(var(--color-primary-700));
}

.chat-input__cancel-edit {
  border: none;
  background: transparent;
  color: rgb(var(--color-primary-600));
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}

.chat-input__cancel-edit:hover {
  text-decoration: underline;
}

.chat-action {
  border: none;
  border-radius: 0.5rem;
  padding: 0.625rem 1.5rem;
  font-size: 0.875rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.15s ease, opacity 0.15s ease;
}

.chat-action-group {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.chat-action:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chat-action--send {
  color: white;
  background: rgb(var(--color-primary-500));
}

.chat-action--send:hover:not(:disabled) {
  background: rgb(var(--color-primary-600));
}

.chat-action--stop {
  color: white;
  background: rgb(var(--color-secondary-600));
}

.chat-action--stop:hover:not(:disabled) {
  background: rgb(var(--color-secondary-700));
}

.function-approval-wrapper {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  width: 100%;
  margin: 0;
  padding: 1rem;
  border-radius: 0.5rem;
  border: 1px solid rgb(var(--color-border-200));
  background: rgb(var(--color-secondary-50));
}

.function-approval-wrapper .chat-img {
  border-radius: 0.5rem;
  padding: 0.5rem;
  background: rgb(var(--color-card));
  border: 1px solid rgb(var(--color-border-200));
}

.function-approval-bubble {
  flex: 1;
  background: rgb(var(--color-card));
  border: 1px solid rgb(var(--color-border-200));
  border-radius: 0.5rem;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
}

.function-approval-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.function-approval-badge {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background-color: rgb(var(--color-secondary-100));
  color: rgb(var(--color-secondary-800));
  padding: 0.25rem 0.5rem;
  border-radius: 0.25rem;
}

.function-approval-endpoint {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.78rem;
  color: rgb(var(--color-text-600));
}

.function-approval-title {
  font-size: 1rem;
  font-weight: 600;
  color: rgb(var(--color-text-900));
  margin: 0;
  line-height: 1.4;
}

.function-approval-description {
  color: rgb(var(--color-text-700));
  margin: 0;
  line-height: 1.5;
  font-size: 0.875rem;
}

.function-approval-preview {
  color: rgb(var(--color-text-800));
  margin: 0;
  line-height: 1.5;
  font-size: 0.875rem;
}

.function-approval-reasoning {
  margin: 0;
  font-size: 0.8125rem;
  color: rgb(var(--color-text-700));
}

.function-approval-reasoning summary {
  cursor: pointer;
  color: rgb(var(--color-primary-500));
  font-weight: 600;
  list-style: none;
}

.function-approval-reasoning summary::marker {
  display: none;
}

.function-approval-plan {
  margin-top: 0.5rem;
  padding-left: 1.25rem;
  display: grid;
  gap: 0.375rem;
  list-style: decimal;
  color: rgb(var(--color-text-700));
  font-size: 0.875rem;
}

.function-approval-playbooks,
.function-approval-arguments,
.function-approval-preferences,
.function-approval-status {
  color: rgb(var(--color-text-700));
  font-size: 0.875rem;
  line-height: 1.5;
  margin: 0;
}

.function-approval-error {
  margin: 0;
  font-size: 0.8125rem;
  color: rgb(var(--color-accent-600));
  background-color: rgb(var(--color-accent-50));
  border-left: 3px solid rgb(var(--color-accent-400));
  padding: 0.75rem;
  border-radius: 0.375rem;
}

.function-approval-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin: 0;
}

.function-arg-list {
  list-style: none;
  padding: 0;
  margin: 0.5rem 0 0;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
}

.function-arg-item {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0.625rem;
  background: rgb(var(--color-border-50));
  border-radius: 0.375rem;
  border: 1px solid rgb(var(--color-border-200));
}

.function-arg-key {
  font-weight: 600;
  font-size: 0.8125rem;
  color: rgb(var(--color-text-700));
}

.function-arg-value {
  font-size: 0.875rem;
  color: rgb(var(--color-text-800));
  word-break: break-word;
}

.function-arg-value-collapsible {
  margin-top: 0.25rem;
}

.function-arg-value-collapsible summary {
  cursor: pointer;
  color: rgb(var(--color-primary-500));
  font-size: 0.8125rem;
  font-weight: 500;
}

.function-arg-value-full {
  margin-top: 0.5rem;
  padding: 0.75rem;
  background: rgb(var(--color-border-100));
  border-radius: 0.375rem;
  font-size: 0.8125rem;
  overflow-x: auto;
}

.function-approval-details {
  margin: 0;
  font-size: 0.8125rem;
  color: rgb(var(--color-text-700));
}

.function-approval-details summary {
  cursor: pointer;
  color: rgb(var(--color-primary-500));
  font-weight: 600;
  font-size: 0.8125rem;
  list-style: none;
}

.function-approval-details summary::marker {
  display: none;
}

.function-approval-details[open] summary {
  margin-bottom: 0.5rem;
}

.function-approval-details .function-approval-description {
  margin-top: 0;
}

.function-approval-preferences {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.function-approval-preference-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.function-approval-preference-toggle > div {
  align-items: center;
}

.function-approval-preference-toggle label {
  font-size: 0.8125rem;
}

/* ---------- Mention chips ---------- */

.chat-mention-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  padding-bottom: 0.375rem;
}

.chat-mention-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  line-height: 1.3;
  font-weight: 500;
  color: rgb(var(--color-text-700));
  background: rgb(var(--color-border-100));
  border: 1px solid rgb(var(--color-border-200));
}

.chat-mention-chip--ticket { background: rgba(var(--color-primary-100), 0.6); border-color: rgb(var(--color-primary-200)); }
.chat-mention-chip--client { background: rgba(var(--color-secondary-100), 0.6); border-color: rgb(var(--color-secondary-200)); }
.chat-mention-chip--contact { background: rgba(var(--color-accent-100), 0.5); border-color: rgb(var(--color-accent-200)); }
.chat-mention-chip--project { background: rgba(99, 102, 241, 0.1); border-color: rgba(99, 102, 241, 0.25); }
.chat-mention-chip--asset { background: rgba(16, 185, 129, 0.1); border-color: rgba(16, 185, 129, 0.25); }
.chat-mention-chip--user { background: rgba(245, 158, 11, 0.1); border-color: rgba(245, 158, 11, 0.25); }

.chat-mention-chip__text {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-mention-chip__remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 0;
  color: rgb(var(--color-text-500));
  border-radius: 50%;
  transition: color 0.1s;
}

.chat-mention-chip__remove:hover {
  color: rgb(var(--color-text-900));
}

/* ---------- Mention popup ---------- */

.chat-mention-popup {
  position: absolute;
  left: 0;
  width: 100%;
  max-width: 400px;
  z-index: 10;
  max-height: 320px;
  overflow-y: auto;
  background: rgb(var(--color-card));
  border: 1px solid rgb(var(--color-border-200));
  border-radius: 0.5rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  padding: 0.25rem 0;
}

.chat-mention-popup--above {
  bottom: calc(100% + 4px);
}

.chat-mention-popup--below {
  top: calc(100% + 4px);
}

.chat-mention-popup__loading,
.chat-mention-popup__empty {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  font-size: 0.8125rem;
  color: rgb(var(--color-text-500));
}

.chat-mention-popup__spinner {
  animation: mention-spin 0.8s linear infinite;
}

@keyframes mention-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.chat-mention-popup__category-header {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.75rem;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: rgb(var(--color-text-500));
}

.chat-mention-popup__item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.4rem 0.75rem;
  border: none;
  background: transparent;
  font-size: 0.8125rem;
  color: rgb(var(--color-text-800));
  cursor: pointer;
  text-align: left;
}

.chat-mention-popup__item:hover,
.chat-mention-popup__item--selected {
  background: rgb(var(--color-border-100));
}

.chat-mention-popup__item-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-mention-popup__item-secondary {
  flex-shrink: 0;
  font-size: 0.75rem;
  color: rgb(var(--color-text-500));
}

@media (max-width: 960px) {
  .chat-container {
    border-radius: 0.5rem;
  }

  .chats {
    padding: 1rem;
  }

  .chats > div {
    width: 100%;
  }

  .chat-footer {
    padding: 0.875rem 1rem;
  }

  .function-approval-wrapper {
    margin: 0.875rem 1rem;
    flex-direction: column;
    align-items: stretch;
  }

  .function-approval-wrapper .chat-img {
    width: 2rem;
    height: 2rem;
  }
}

@media (max-width: 640px) {
  .chat-container {
    border-radius: 0.5rem;
  }

  .chat-footer__inner {
    flex-direction: column;
    align-items: stretch;
  }

  .chat-action {
    width: 100%;
  }

  .function-approval-wrapper {
    margin: 0.75rem 0.875rem;
    padding: 0.75rem;
  }

  .function-approval-bubble {
    padding: 0.875rem 1rem;
  }
}
