/* Chat View */
.sg-chat-view {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

/* Custom element wrappers — participate in parent flex layout */
sg-message-list {
  flex: 1;
  min-height: 0;
}

sg-message-bubble {
  display: contents;
}

/* Message List */
.sg-message-list {
  height: 100%;
  overflow-y: auto;
  padding: 16px max(24px, calc((100% - 800px) / 2));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.sg-message-list__empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-secondary);
  font-size: 16px;
}

/* Message Bubble */
.sg-message-bubble {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: 12px;
  line-height: 1.5;
  word-wrap: break-word;
}

.sg-message-bubble--user {
  align-self: flex-end;
  background-color: var(--color-bg-secondary);
  color: var(--color-text);
  border-bottom-right-radius: 4px;
}

.sg-message-bubble--assistant {
  align-self: flex-start;
  background-color: transparent;
  max-width: 100%;
}

.sg-message-bubble__content p:first-child {
  margin-top: 0;
}

.sg-message-bubble__content p:last-child {
  margin-bottom: 0;
}

.sg-message-bubble__content pre {
  background-color: var(--color-bg-tertiary);
  padding: 12px;
  border-radius: 6px;
  overflow-x: auto;
}

.sg-message-bubble__content code {
  background-color: var(--color-bg-tertiary);
  padding: 2px 4px;
  border-radius: 3px;
  font-size: 0.9em;
}

.sg-message-bubble__content pre code {
  background: none;
  padding: 0;
}

.sg-message-bubble__content a {
  color: inherit;
  text-decoration: underline;
}

/* Playlist Cards */
.sg-message-bubble__playlists {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 0 0;
}

.sg-message-bubble__playlist-card {
  flex-shrink: 0;
  width: 60px;
  height: 60px;
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
}

.sg-message-bubble__playlist-image {
  width: 60px;
  height: 60px;
  object-fit: cover;
  display: block;
}

.sg-message-bubble__playlist-image--placeholder {
  background-color: var(--color-bg-tertiary);
}

.sg-message-bubble__playlists-label {
  width: 100%;
  font-size: 12px;
  color: var(--color-text-secondary);
}

/* Create Playlist Action Button */
.sg-message-bubble__create-action-wrapper {
  padding: 12px 0 4px;
}

.sg-message-bubble__create-action {
  display: inline-flex;
  align-items: center;
  padding: 10px 20px;
  border: none;
  border-radius: 20px;
  background-color: var(--color-primary);
  color: #fff;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s;
}

.sg-message-bubble__create-action:hover:not(:disabled) {
  background-color: var(--color-primary-hover);
}

.sg-message-bubble__create-action:disabled {
  background-color: var(--color-text-secondary);
  opacity: 0.5;
  cursor: not-allowed;
}

/* SoundCloud Match Card */
.sg-message-bubble__match-card {
  margin-top: 12px;
  background-color: var(--color-bg-secondary);
  border-radius: 12px;
  padding: 16px;
  cursor: pointer;
  transition: background-color 0.15s;
  max-width: 480px;
  text-decoration: none;
  color: var(--color-text);
  display: block;
}

.sg-message-bubble__match-card:hover {
  background-color: var(--color-bg-tertiary);
}

.sg-message-bubble__match-card-header {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

.sg-message-bubble__match-card-art {
  width: 80px;
  height: 80px;
  border-radius: 8px;
  flex-shrink: 0;
  overflow: hidden;
}

.sg-message-bubble__match-card-art-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.sg-message-bubble__match-card-info {
  flex: 1;
  min-width: 0;
}

.sg-message-bubble__match-card-title {
  font-size: 15px;
  font-weight: 600;
  margin-top: 4px;
}

.sg-message-bubble__match-card-description {
  font-size: 12px;
  color: var(--color-text-secondary);
  margin-top: 2px;
}

.sg-message-bubble__match-card-count {
  font-size: 12px;
  color: var(--color-text-secondary);
  margin-top: 6px;
}

.sg-message-bubble__match-card-tracks {
  margin-top: 12px;
  border-top: 1px solid var(--color-border);
  padding-top: 8px;
}

.sg-message-bubble__match-card-track {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 3px 0;
  font-size: 13px;
}

.sg-message-bubble__match-card-track-num {
  color: var(--color-text-secondary);
  font-size: 12px;
  width: 20px;
  text-align: right;
  flex-shrink: 0;
}

.sg-message-bubble__match-card-track-title {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sg-message-bubble__match-card-track-artist {
  color: var(--color-text-secondary);
  font-size: 12px;
  white-space: nowrap;
  flex-shrink: 0;
}

/* Thinking Animation */
.sg-message-bubble__thinking {
  display: flex;
  gap: 4px;
  padding: 4px 0;
}

.sg-message-bubble__thinking-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--color-text-secondary);
  animation: sg-thinking 1.4s infinite;
}

.sg-message-bubble__thinking-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.sg-message-bubble__thinking-dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes sg-thinking {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}

/* Matched Songs List */
.sg-message-bubble__matched-songs {
  max-width: 500px;
  margin-top: 12px;
}

.sg-message-bubble__matched-songs-header {
  font-size: 12px;
  color: var(--color-text-secondary);
  margin-bottom: 8px;
}

.sg-message-bubble__matched-song {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--color-border);
}

.sg-message-bubble__matched-song:last-of-type {
  border-bottom: none;
}

.sg-message-bubble__matched-song-num {
  width: 24px;
  text-align: right;
  font-size: 12px;
  color: var(--color-text-secondary);
  flex-shrink: 0;
}

.sg-message-bubble__matched-song-info {
  flex: 1;
  min-width: 0;
}

.sg-message-bubble__matched-song-title {
  font-weight: 500;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: block;
}

.sg-message-bubble__matched-song-artist {
  font-size: 12px;
  color: var(--color-text-secondary);
}

.sg-message-bubble__matched-song-add {
  opacity: 0;
  transition: opacity 0.15s;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 8px;
  color: var(--color-primary);
  font-size: 16px;
  flex-shrink: 0;
  border-radius: 4px;
}

.sg-message-bubble__matched-song:hover .sg-message-bubble__matched-song-add {
  opacity: 1;
}

/* Hide individual add buttons unless draft state */
.sg-message-bubble__matched-songs:not(.sg-message-bubble__matched-songs--draft) .sg-message-bubble__matched-song-add {
  display: none;
}

.sg-message-bubble__matched-song--added .sg-message-bubble__matched-song-add {
  color: var(--color-success);
  opacity: 1;
}

.go-plus-badge {
  display: inline-block;
  vertical-align: middle;
  margin-left: 4px;
  flex-shrink: 0;
}

.sg-message-bubble__matched-songs-action {
  margin-top: 12px;
}

.sg-message-bubble__matched-songs-btn {
  display: inline-flex;
  align-items: center;
  padding: 8px 20px;
  background: var(--color-primary);
  color: white;
  border: none;
  border-radius: 20px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s;
}

.sg-message-bubble__matched-songs-btn:hover {
  background: var(--color-primary-hover);
}

.sg-message-bubble__matched-songs-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

/* Streaming Tool Status */
.sg-message-bubble__streaming-status {
  padding: 8px 0;
}

.sg-message-bubble__tool-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--color-text-secondary);
}

.sg-message-bubble__tool-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  border-radius: 3px;
}

.sg-message-bubble__tool-icon-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-text-secondary);
  flex-shrink: 0;
  margin: 0 5px;
}

.sg-message-bubble__tool-dots {
  display: inline-flex;
  gap: 2px;
  margin-left: 4px;
}

.sg-message-bubble__tool-dots .sg-message-bubble__thinking-dot {
  width: 4px;
  height: 4px;
}

/* Chat Input */
.sg-chat-input {
  padding: 16px max(24px, calc((100% - 800px) / 2));
}

.sg-chat-input__wrapper {
  display: flex;
  align-items: center;
  border: 1px solid var(--color-border);
  border-radius: 24px;
  padding: 4px 4px 4px 16px;
  width: 100%;
}

.sg-chat-input__textarea {
  flex: 1;
  resize: none;
  border: none;
  padding: 8px 0;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
  background: transparent;
  color: var(--color-text);
  min-height: 24px;
  max-height: 200px;
  outline: none;
}

.sg-chat-input__textarea::placeholder {
  color: var(--color-text-secondary);
}

.sg-chat-input__send {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--color-text);
  color: #fff;
  border: none;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
}

.sg-chat-input__send:disabled {
  background: var(--color-text-secondary);
  opacity: 0.5;
  cursor: not-allowed;
}

/* Conversation Item */
.sg-conversation-item {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--color-text);
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sg-conversation-item:hover {
  background-color: var(--color-sidebar-hover);
}

.sg-conversation-item--active {
  background-color: var(--color-sidebar-hover);
  font-weight: 600;
}

/* Sidebar New Chat Button */
.sg-sidebar__new-chat {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 8px;
  border: none;
  border-radius: 6px;
  background: none;
  color: var(--color-text);
  cursor: pointer;
  font-size: 14px;
}

.sg-sidebar__new-chat:hover {
  background-color: var(--color-sidebar-hover);
}

.sg-sidebar__conversations {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 8px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  border-top: 1px solid transparent;
  margin-left: -8px;
  margin-right: -8px;
  padding-left: 8px;
  padding-right: 8px;
}

.sg-sidebar__conversations--scrolled {
  border-top-color: var(--color-border);
}

/* Mobile: tighter side padding on chat content */
@media (max-width: 768px) {
  .sg-message-list {
    padding: 16px 12px;
  }

  .sg-chat-input {
    padding: 16px 12px;
  }
}
