/* Message Bubbles — Chat conversation styles */

.msg {
  padding: 2px 0;
  min-width: 0;
}

/* User message — right aligned pill */
.msg--user {
  display: flex;
  justify-content: flex-end;
}

.msg__pill {
  background: var(--chat-user-bg, rgba(255, 255, 255, 0.12));
  border: 1px solid rgba(var(--island-accent-rgb, 123, 120, 255), 0.15);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--island-text);
  max-width: 85%;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.msg__user-content {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.msg__user-content > span {
  min-width: 0;
}

.msg__sender-logo {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  border-radius: 5px;
  object-fit: cover;
}

.msg__prefix {
  color: var(--island-text-muted);
  font-size: 9px;
}

.msg__images {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 6px;
}

.msg__image {
  display: block;
  max-width: 100%;
  max-height: 200px;
  border: 1px solid var(--island-border);
  border-radius: 6px;
  cursor: pointer;
  object-fit: contain;
}

/* Assistant message — left aligned */
.msg--assistant {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 4px 0;
}

.msg__avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  flex: 0 0 24px;
  margin-top: 1px;
}

.msg__avatar .platform-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}

.msg__avatar .platform-icon--image {
  border-radius: 7px;
  object-fit: cover;
}

.msg__avatar .platform-icon--glyph {
  border-radius: 7px;
  background: rgba(var(--island-accent-rgb, 123, 120, 255), 0.14);
  border: 1px solid rgba(var(--island-accent-rgb, 123, 120, 255), 0.25);
  color: var(--island-accent, #7b78ff);
}

.msg__assistant-body {
  min-width: 0;
  flex: 1;
  max-width: 100%;
}

.msg__content {
  min-width: 0;
  max-width: 100%;
  font-size: 12px;
  color: var(--island-text);
  line-height: 1.6;
  opacity: 0.9;
  overflow-wrap: anywhere;
}

.msg__process {
  margin-bottom: 6px;
  overflow: hidden;
  border: 1px solid var(--island-border);
  border-radius: 8px;
  background: var(--island-subtle);
}

.msg__process-summary {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 6px;
  border: 0;
  background: transparent;
  color: var(--island-text-secondary);
  cursor: pointer;
  font: inherit;
  font-size: 11px;
  padding: 6px 8px;
  text-align: left;
}

.msg__process-summary:hover {
  background: var(--island-card-hover);
  color: var(--island-text);
}

.msg__process-chevron {
  width: 12px;
  color: var(--island-text-muted);
  font-size: 9px;
}

.msg__process-detail {
  border-top: 1px solid var(--island-border);
  padding: 7px 8px;
}

.msg__process-section {
  max-height: 180px;
  overflow-x: hidden;
  overflow-y: auto;
  color: var(--island-text-secondary);
  font-size: 11px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.msg__process-section + .msg__process-section,
.msg__process-section + .msg__process-tools,
.msg__process-tools + .msg__process-section {
  margin-top: 8px;
}

.msg__process-section--thinking {
  opacity: 0.8;
}

.msg__process-label {
  margin-bottom: 3px;
  color: var(--island-text-muted);
  font-size: 10px;
  font-style: italic;
}

.msg__process-tools {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.msg__process-tool {
  border-radius: 6px;
  background: var(--island-subtle);
  padding: 6px;
}

.msg__process-pre {
  max-height: 160px;
  overflow-x: hidden;
  overflow-y: auto;
  margin: 6px 0 0;
  padding: 7px 8px;
  border: 1px solid var(--island-border);
  border-radius: 6px;
  background: var(--island-code-block-bg, var(--island-code-bg));
  color: var(--island-code-muted);
  font-family: var(--font-mono, 'SF Mono', 'Fira Code', monospace);
  font-size: 10px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ── Markdown body styling ── */
.msg__content.markdown-body h1,
.msg__content.markdown-body h2,
.msg__content.markdown-body h3,
.msg__content.markdown-body h4,
.msg__content.markdown-body h5,
.msg__content.markdown-body h6,
.msg__process-section.markdown-body h1,
.msg__process-section.markdown-body h2,
.msg__process-section.markdown-body h3,
.msg__process-section.markdown-body h4,
.msg__process-section.markdown-body h5,
.msg__process-section.markdown-body h6 {
  margin: 8px 0 4px;
  font-weight: 600;
  line-height: 1.4;
  color: var(--island-text);
}

.msg__content.markdown-body h1 { font-size: 16px; }
.msg__content.markdown-body h2 { font-size: 14px; }
.msg__content.markdown-body h3 { font-size: 13px; }
.msg__content.markdown-body h4,
.msg__content.markdown-body h5,
.msg__content.markdown-body h6,
.msg__process-section.markdown-body h1,
.msg__process-section.markdown-body h2,
.msg__process-section.markdown-body h3,
.msg__process-section.markdown-body h4,
.msg__process-section.markdown-body h5,
.msg__process-section.markdown-body h6 { font-size: 12px; }

.msg__content.markdown-body p,
.msg__process-section.markdown-body p {
  margin: 4px 0;
}

.msg__content.markdown-body ul,
.msg__content.markdown-body ol,
.msg__process-section.markdown-body ul,
.msg__process-section.markdown-body ol {
  margin: 4px 0;
  padding-left: 18px;
}

.msg__content.markdown-body li,
.msg__process-section.markdown-body li {
  margin: 2px 0;
}

.msg__content.markdown-body code,
.msg__process-section.markdown-body code {
  background: var(--island-inline-code-bg);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: var(--font-mono, 'SF Mono', 'Fira Code', monospace);
  font-size: 11px;
  color: var(--island-inline-code-text);
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.msg__content.markdown-body pre,
.msg__process-section.markdown-body pre {
  margin: 6px 0;
  padding: 10px 12px;
  background: var(--island-code-block-bg, var(--island-code-bg));
  border-radius: 6px;
  overflow-x: hidden;
  border: 1px solid var(--island-code-border);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg__content.markdown-body pre code,
.msg__process-section.markdown-body pre code {
  background: none;
  padding: 0;
  border-radius: 0;
  font-size: 11px;
  line-height: 1.5;
  color: var(--island-code-text);
  white-space: pre-wrap;
  word-break: break-word;
}

.msg__content.markdown-body blockquote,
.msg__process-section.markdown-body blockquote {
  margin: 6px 0;
  padding: 4px 12px;
  border-left: 3px solid var(--island-accent, #7b78ff);
  color: var(--island-markdown-muted);
  font-style: italic;
}

.msg__content.markdown-body table,
.msg__process-section.markdown-body table {
  margin: 6px 0;
  border-collapse: collapse;
  width: 100%;
  font-size: 11px;
}

.msg__content.markdown-body th,
.msg__content.markdown-body td,
.msg__process-section.markdown-body th,
.msg__process-section.markdown-body td {
  border: 1px solid var(--island-border);
  padding: 4px 8px;
  text-align: left;
}

.msg__content.markdown-body th,
.msg__process-section.markdown-body th {
  background: var(--island-card-hover);
  font-weight: 600;
}

.msg__content.markdown-body hr,
.msg__process-section.markdown-body hr {
  border: none;
  border-top: 1px solid var(--island-border);
  margin: 8px 0;
}

.msg__content.markdown-body a,
.msg__process-section.markdown-body a {
  color: var(--island-link, var(--island-accent));
  text-decoration: none;
}

.msg__content.markdown-body a:hover,
.msg__process-section.markdown-body a:hover {
  text-decoration: underline;
}

.msg__content.markdown-body strong,
.msg__process-section.markdown-body strong {
  font-weight: 600;
  color: var(--island-text);
}

.msg__content.markdown-body img,
.msg__process-section.markdown-body img {
  max-width: 100%;
  border-radius: 6px;
  margin: 4px 0;
}

/* Tool use — compact with status dot */
.msg--tool {
  padding: 3px 0;
  cursor: pointer;
}

.msg__tool-header {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--island-text-secondary);
}

.msg__tool-name {
  font-family: var(--font-mono, 'SF Mono', monospace);
  font-size: 10px;
}

.msg__mcp-badge {
  font-size: 9px;
  padding: 1px 4px;
  border-radius: 3px;
  background: var(--island-info-bg);
  color: var(--island-info-text);
  font-weight: 600;
}

.msg__tool-spinner {
  width: 8px;
  height: 8px;
  border: 1.5px solid var(--island-text-muted);
  border-top-color: var(--island-text);
  border-radius: 50%;
  animation: msg-spin 0.8s linear infinite;
}

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

.msg__tool-check {
  color: var(--island-success-text);
  font-size: 10px;
}

.msg__tool-x {
  color: var(--island-danger-text);
  font-size: 10px;
}

.msg__tool-detail {
  margin-top: 4px;
  background: var(--island-code-block-bg, var(--island-code-bg));
  border-radius: 4px;
  padding: 6px 8px;
  font-family: var(--font-mono, 'SF Mono', monospace);
  font-size: 10px;
  color: var(--island-code-muted);
  max-height: 120px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

.msg__tool-detail pre {
  margin: 0;
  font-size: inherit;
  white-space: pre-wrap;
}

/* Permission request — amber highlight */
.msg--permission {
  background: var(--island-warning-bg);
  border-left: 2px solid var(--island-warning);
  border-radius: 0 6px 6px 0;
  padding: 8px 12px;
  margin: 4px 0;
}

.msg__perm-header {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 500;
}

.msg__perm-icon {
  font-size: 13px;
}

.msg__perm-tool {
  color: var(--island-warning-text);
  font-family: var(--font-mono, 'SF Mono', monospace);
}

.msg__perm-input {
  margin-top: 4px;
  font-family: var(--font-mono, 'SF Mono', monospace);
  font-size: 10px;
  color: var(--island-text-muted);
  max-height: 60px;
  overflow: hidden;
}

.msg__perm-input pre {
  margin: 0;
  white-space: pre-wrap;
}

/* Thinking — gray italic */
.msg--thinking {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  padding: 2px 0;
  cursor: pointer;
}

.msg__thinking-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--island-text-muted);
  margin-top: 6px;
  flex-shrink: 0;
}

.msg__thinking-text {
  font-size: 11px;
  color: var(--island-text-muted);
  font-style: italic;
  line-height: 1.4;
}

/* Error message */
.msg--error {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 0;
  font-size: 11px;
  color: var(--island-danger-text);
}

.msg__error-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--island-danger-text);
  flex-shrink: 0;
}
