:root {
  color-scheme: light;
  font-family: "Inter", "SF Pro Display", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --chat-bg: #0f172a;
  --chat-panel: #ffffff;
  --chat-border: #e5e7eb;
  --chat-muted: #6b7280;
  --chat-accent: #3F8CFF;
  --chat-accent-soft: rgba(63, 140, 255, 0.1);
  --chat-user: #111827;
  --chat-assistant: #0f172a;
  --chat-assistant-bg: #eef2ff;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: #f3f4f6;
  color: var(--chat-user);
  display: flex;
  justify-content: center;
  padding: 16px;
  height: 100vh;
}

.chat-shell {
  width: 100%;
  max-width: 720px;
  min-height: 100%;
  background: #fff;
  border-radius: 12px;
  border: 1px solid #e5e7eb;
  display: flex;
  flex-direction: column;
  height: 100%;
  max-height: 100%;
}


.chat-log {
  flex: 1;
  padding: 20px 20px 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: 0;
}

/* Thin scrollbar — applied globally inside this iframe document so the chat
   feels consistent with the parent app. */
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(15, 23, 42, 0.2) transparent;
}
*::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
*::-webkit-scrollbar-track {
  background: transparent;
}
*::-webkit-scrollbar-thumb {
  background-color: rgba(15, 23, 42, 0.18);
  border-radius: 3px;
}
*::-webkit-scrollbar-thumb:hover {
  background-color: rgba(15, 23, 42, 0.32);
}

.chat-message {
  display: flex;
  gap: 12px;
}

.chat-message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: #374151;
  color: white;
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: 12px;
  flex-shrink: 0;
}

.chat-message-body {
  background: #ffffff;
  border-radius: 16px;
  padding: 10px 14px;
  max-width: 90%;
  min-width: 0;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: break-word;
}

.chat-message-timestamp {
  margin-top: 6px;
  font-size: 11px;
  color: #c6d4f0;
  text-align: right;
}

.chat-message-actions {
  margin-top: 10px;
  display: flex;
  justify-content: flex-end;
}

.chat-inline-btn {
  border: none;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  background: var(--chat-accent);
  color: white;
}

.chat-inline-btn:hover {
  opacity: 0.9;
}

.chat-message-user {
  flex-direction: row-reverse;
}

.chat-message-user .chat-message-avatar {
  background: var(--chat-accent);
}

.chat-message-user .chat-message-body {
  background: linear-gradient(180deg, #4F97FF 0%, #3578E5 100%);
  color: #ffffff;
  border-bottom-right-radius: 6px;
  box-shadow:
    inset 0 0 0 1px rgba(0, 0, 0, 0.08),
    0 1px 2px rgba(53, 120, 229, 0.18),
    0 4px 12px rgba(53, 120, 229, 0.22);
}

.chat-message-assistant .chat-message-body {
  background: #ffffff;
  color: var(--chat-assistant);
  border-bottom-left-radius: 6px;
  box-shadow:
    0 0 0 1px rgba(15, 23, 42, 0.04),
    0 2px 4px rgba(15, 23, 42, 0.04),
    0 8px 16px -4px rgba(15, 23, 42, 0.10),
    0 20px 32px -12px rgba(15, 23, 42, 0.06);
}

/* Inline markdown styles */
.chat-inline-code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.9em;
  background: #1e293b;
  color: #e2e8f0;
  padding: 2px 6px;
  border-radius: 4px;
}

.chat-message-body strong {
  font-weight: 700;
}

.chat-message-body em {
  font-style: italic;
}

/* Headings in chat */
.chat-heading {
  font-weight: 700;
  margin: 12px 0 4px;
  line-height: 1.3;
}

.chat-heading:first-child {
  margin-top: 0;
}

.chat-h1 {
  font-size: 1.25em;
}

.chat-h2 {
  font-size: 1.1em;
}

.chat-h3 {
  font-size: 1em;
  color: var(--chat-accent);
}

/* Bullet lists in chat */
.chat-list {
  margin: 6px 0;
  padding-left: 20px;
  list-style: disc;
}

.chat-list li {
  margin: 4px 0;
  line-height: 1.5;
}

.chat-code-block {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 13px;
  line-height: 1.4;
  background: #0f172a;
  color: #f8fafc;
  border-radius: 10px;
  border: 1px solid #1e293b;
  padding: 12px;
  margin-top: 12px;
  white-space: pre;
  width: 100%;
  max-width: 100%;
  overflow: auto;
}

.chat-hint {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--chat-muted);
}

footer {
  padding: 16px 20px;
  border-top: 1px solid var(--chat-border);
  background: #fff;
}

.chat-composer {
  display: flex;
  gap: 12px;
  align-items: center;
}

#chatInput {
  flex: 1;
  border-radius: 10px;
  border: 1px solid var(--chat-border);
  padding: 12px 16px;
  font-family: inherit;
  resize: none;
  min-height: 48px;
}

.chat-primary-btn,
.chat-secondary-btn {
  border: none;
  border-radius: 999px;
  padding: 10px 20px;
  font-weight: 600;
  cursor: pointer;
  font-size: 14px;
}

.chat-primary-btn {
  background: var(--chat-accent);
  color: white;
}

.chat-primary-btn:disabled {
  opacity: 0.5;
  cursor: wait;
}

.chat-primary-btn.generating {
  animation: generating-bg 3s ease infinite;
  color: white;
}

@keyframes generating-bg {
  0%   { background-color: #4f46e5; }
  25%  { background-color: #7c3aed; }
  50%  { background-color: #2563eb; }
  75%  { background-color: #0891b2; }
  100% { background-color: #4f46e5; }
}

.chat-secondary-btn {
  background: var(--chat-accent-soft);
  color: var(--chat-accent);
}

/* Tool Progress Display */
.tool-progress {
  background: #f8fafc !important;
  border: 1px solid #e2e8f0;
}

.tool-progress-label {
  font-weight: 600;
  color: var(--chat-accent);
  margin-bottom: 8px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.tool-progress-label::before {
  content: '';
  width: 14px;
  height: 14px;
  border: 2px solid var(--chat-accent);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.tool-progress-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tool-progress-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  padding: 4px 0;
}

.tool-icon {
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 11px;
  flex-shrink: 0;
}

.tool-icon.pending {
  background: #fef3c7;
  color: #92400e;
}

.tool-icon.success {
  background: #d1fae5;
  color: #065f46;
}

.tool-icon.error {
  background: #fee2e2;
  color: #991b1b;
}

.tool-text {
  color: #374151;
}

@media (max-width: 768px) {
  body {
    padding: 8px;
  }

  .chat-shell {
    border-radius: 0;
    border-left: none;
    border-right: none;
    height: 100vh;
  }
}
