/* ============================================
   ThamaTek AI Chat — page-specific styles
   Brand tokens, base reset, and light/dark theme
   come from ../styles.css. This file only adds the
   chat app shell + message/composer components.
   ============================================ */

.chat-body {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background:
    radial-gradient(60% 50% at 50% 0%, rgba(124, 58, 237, 0.10), transparent 70%),
    var(--color-bg);
}

/* ---------- Header ---------- */
.chat-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--color-border);
  background: color-mix(in srgb, var(--color-bg-elevated) 80%, transparent);
  backdrop-filter: blur(10px);
}

.chat-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--color-text);
}
.chat-brand:hover { color: var(--color-text); }
.chat-brand-text { font-weight: 600; font-size: var(--font-size-lg); letter-spacing: -0.01em; }
.chat-brand-text strong {
  background: var(--gradient-brand);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.chat-brand-sub {
  font-weight: 600;
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  padding: 0.05rem 0.5rem;
  margin-left: 0.15rem;
}

.chat-header-actions { display: flex; align-items: center; gap: 0.5rem; }

.chat-btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.85rem;
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--color-text-secondary);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
}
.chat-btn-ghost:hover {
  color: var(--color-text);
  background: var(--color-bg-card-hover);
  border-color: var(--color-border-hover);
}

/* ---------- Messages area ---------- */
.chat-main {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
}
.chat-thread {
  max-width: 820px;
  margin: 0 auto;
  padding: 1.75rem 1.25rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* Welcome / empty state */
.chat-welcome { text-align: center; padding: clamp(2rem, 8vh, 5rem) 0 1rem; }
.chat-welcome-badge {
  display: inline-block;
  font-size: var(--font-size-xs);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-accent-soft);
  background: rgba(124, 58, 237, 0.12);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  padding: 0.35rem 0.85rem;
  margin-bottom: 1.25rem;
}
.chat-welcome-title {
  font-size: var(--font-size-3xl);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 0.75rem;
  background: var(--gradient-brand);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.chat-welcome-sub {
  max-width: 560px;
  margin: 0 auto 1.75rem;
  color: var(--color-text-secondary);
  font-size: var(--font-size-base);
}
.chat-suggestions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  max-width: 620px;
  margin: 0 auto;
}
.chat-suggestion {
  text-align: left;
  padding: 0.9rem 1.1rem;
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--color-text);
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition-fast), border-color var(--transition-fast), transform var(--transition-fast);
}
.chat-suggestion:hover {
  background: var(--color-bg-card-hover);
  border-color: var(--color-border-hover);
  transform: translateY(-2px);
}

/* Message rows */
.msg { display: flex; gap: 0.85rem; align-items: flex-start; }
.msg-avatar {
  flex: 0 0 auto;
  width: 32px; height: 32px;
  border-radius: var(--radius-full);
  display: grid; place-items: center;
  font-size: var(--font-size-xs);
  font-weight: 700;
}
.msg-user .msg-avatar { background: var(--color-surface-alt); color: var(--color-text-secondary); }
.msg-assistant .msg-avatar { background: var(--gradient-btn); color: #fff; }

.msg-body { min-width: 0; flex: 1 1 auto; }
.msg-role {
  font-size: var(--font-size-xs);
  font-weight: 600;
  color: var(--color-text-muted);
  margin-bottom: 0.25rem;
}
.msg-content {
  color: var(--color-text);
  font-size: var(--font-size-base);
  line-height: 1.7;
  overflow-wrap: anywhere;
}
.msg-user .msg-content {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
}

/* Markdown styling inside assistant messages */
.msg-content p { margin: 0 0 0.85rem; }
.msg-content p:last-child { margin-bottom: 0; }
.msg-content ul, .msg-content ol { margin: 0 0 0.85rem 1.4rem; }
.msg-content li { margin: 0.2rem 0; }
.msg-content h1, .msg-content h2, .msg-content h3 { margin: 1.1rem 0 0.6rem; line-height: 1.3; }
.msg-content h1 { font-size: var(--font-size-xl); }
.msg-content h2 { font-size: var(--font-size-lg); }
.msg-content h3 { font-size: var(--font-size-base); }
.msg-content a { color: var(--color-primary-soft); text-decoration: underline; }
.msg-content code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.875em;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 0.1rem 0.35rem;
}
.msg-content pre {
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0.9rem 1rem;
  overflow-x: auto;
  margin: 0 0 0.85rem;
}
.msg-content pre code { background: none; border: 0; padding: 0; font-size: 0.85rem; }
.msg-content blockquote {
  border-left: 3px solid var(--color-border-hover);
  padding-left: 0.9rem;
  color: var(--color-text-secondary);
  margin: 0 0 0.85rem;
}
.msg-content table { border-collapse: collapse; margin: 0 0 0.85rem; display: block; overflow-x: auto; }
.msg-content th, .msg-content td { border: 1px solid var(--color-border); padding: 0.4rem 0.7rem; text-align: left; }

/* Image thumbnails attached to a user message */
.msg-files { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.5rem; }
.msg-file-img { max-width: 220px; max-height: 220px; border-radius: var(--radius-sm); border: 1px solid var(--color-border); }
.msg-file-doc {
  display: inline-flex; align-items: center; gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
}

/* Typing indicator */
.msg-typing { display: inline-flex; gap: 4px; padding: 0.4rem 0; }
.msg-typing span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--color-text-muted);
  animation: chatBlink 1.2s infinite ease-in-out both;
}
.msg-typing span:nth-child(2) { animation-delay: 0.15s; }
.msg-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes chatBlink { 0%, 80%, 100% { opacity: 0.25; } 40% { opacity: 1; } }

.msg-error {
  color: #fca5a5;
  background: rgba(220, 38, 38, 0.08);
  border: 1px solid rgba(220, 38, 38, 0.3);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.85rem;
  font-size: var(--font-size-sm);
}

/* ---------- Composer ---------- */
.chat-composer-wrap {
  flex: 0 0 auto;
  padding: 0.75rem 1.25rem 1.1rem;
  background: linear-gradient(to top, var(--color-bg) 60%, transparent);
}
.chat-composer {
  max-width: 820px;
  margin: 0 auto;
}
.chat-attachments { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.6rem; }
.chat-chip {
  display: inline-flex; align-items: center; gap: 0.45rem;
  padding: 0.35rem 0.4rem 0.35rem 0.6rem;
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  max-width: 220px;
}
.chat-chip img { width: 28px; height: 28px; border-radius: 6px; object-fit: cover; }
.chat-chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-chip-remove {
  display: grid; place-items: center;
  width: 20px; height: 20px;
  border-radius: 50%;
  color: var(--color-text-muted);
  background: transparent;
  border: 0; cursor: pointer;
}
.chat-chip-remove:hover { color: var(--color-text); background: var(--color-bg-card-hover); }

.chat-composer-row {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.5rem 0.5rem 0.5rem 0.65rem;
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.chat-composer-row:focus-within {
  border-color: var(--color-border-hover);
  box-shadow: var(--glow-card-hover);
}
.chat-input {
  flex: 1 1 auto;
  resize: none;
  max-height: 200px;
  border: 0;
  background: transparent;
  color: var(--color-text);
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  line-height: 1.5;
  padding: 0.5rem 0.25rem;
}
.chat-input:focus { outline: none; }
.chat-input::placeholder { color: var(--color-text-muted); }

.chat-attach-btn, .chat-send-btn {
  flex: 0 0 auto;
  display: grid; place-items: center;
  width: 40px; height: 40px;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast), opacity var(--transition-fast);
}
.chat-attach-btn {
  color: var(--color-text-secondary);
  background: transparent;
  border: 1px solid transparent;
}
.chat-attach-btn:hover { color: var(--color-text); background: var(--color-surface); }
.chat-send-btn {
  color: #fff;
  background: var(--gradient-btn);
  border: 0;
}
.chat-send-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.chat-send-btn:not(:disabled):hover { filter: brightness(1.08); }

.chat-disclaimer {
  text-align: center;
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
  margin-top: 0.6rem;
}

/* Stop button shown while streaming */
.chat-send-btn.is-streaming {
  background: var(--color-surface-alt);
  color: var(--color-text);
}

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
  .chat-suggestions { grid-template-columns: 1fr; }
  .chat-back span, .chat-btn-ghost span { display: none; }
  .chat-welcome-title { font-size: var(--font-size-2xl); }
}
