/* Chat page — scoped styles, paired with styles.css */

html, body.chat-body {
  height: 100%;
}

body.chat-body {
  background: var(--surface-alt);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.chat-shell {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
}

.chat-col {
  flex: 1;
  max-width: 820px;
  margin-inline: auto;
  width: 100%;
  padding-inline: 1.5rem;
  padding-block: 2rem 7rem;
  display: flex;
  flex-direction: column;
}

/* Intro */
.chat-intro {
  text-align: center;
  padding-block: 2.5rem 2rem;
  display: grid;
  gap: 1rem;
  justify-items: center;
}

.chat-intro h1 {
  font-size: clamp(1.5rem, 3vw, 2.15rem);
  line-height: 1.3;
  color: var(--dga-green-dark);
  font-weight: 700;
  max-width: 640px;
}

.chat-intro p {
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.7;
  max-width: 620px;
}

.chat-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  background: var(--dga-green-soft);
  color: var(--dga-green-dark);
  padding: 0.4rem 0.9rem;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 500;
}

.chat-badge svg {
  color: var(--accent);
}

.suggested-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  max-width: 720px;
  width: 100%;
  margin-block-start: 1rem;
}

.suggested {
  display: flex;
  align-items: flex-start;
  gap: 0.7rem;
  text-align: start;
  padding: 0.9rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
  color: var(--ink);
  cursor: pointer;
  transition: border-color 150ms ease, transform 150ms ease, box-shadow 150ms ease;
  line-height: 1.45;
}

.suggested:hover {
  border-color: var(--dga-green);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.suggested-emoji {
  font-size: 1.15rem;
  line-height: 1;
  flex-shrink: 0;
  padding-block-start: 0.1rem;
}

.suggested-text {
  font-size: 0.92rem;
  color: var(--ink);
}

@media (max-width: 640px) {
  .suggested-grid { grid-template-columns: 1fr; }
}

/* Conversation log */
.chat-log {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.chat-log:empty { display: none; }

.msg {
  display: flex;
  gap: 0.75rem;
  animation: fadeUp 240ms ease-out;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  color: white;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.msg-avatar.user {
  background: var(--dga-green-dark);
}

.msg-avatar.assistant {
  background: linear-gradient(135deg, var(--dga-green) 0%, var(--accent) 100%);
}

.msg-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.msg-role {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 600;
}

.msg-bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.85rem 1rem;
  color: var(--ink);
  line-height: 1.65;
  font-size: 0.97rem;
  overflow-wrap: break-word;
}

.msg.user .msg-bubble {
  background: var(--dga-green);
  color: white;
  border-color: var(--dga-green-dark);
}

.msg.assistant .msg-bubble a { color: var(--dga-green-dark); text-decoration: underline; }

.msg-bubble p { margin-block: 0.35rem; }
.msg-bubble p:first-child { margin-block-start: 0; }
.msg-bubble p:last-child { margin-block-end: 0; }

.msg-bubble h1,
.msg-bubble h2,
.msg-bubble h3 {
  margin-block: 0.7rem 0.35rem;
  color: var(--dga-green-dark);
  line-height: 1.3;
}

.msg.user .msg-bubble h1,
.msg.user .msg-bubble h2,
.msg.user .msg-bubble h3 {
  color: white;
}

.msg-bubble code {
  background: rgba(0, 0, 0, 0.06);
  padding: 0.12rem 0.35rem;
  border-radius: 4px;
  font-size: 0.9em;
}

.msg.user .msg-bubble code {
  background: rgba(255, 255, 255, 0.16);
}

.msg-bubble ul, .msg-bubble ol {
  padding-inline-start: 1.3rem;
  margin-block: 0.35rem;
}

.msg-bubble li { margin-block: 0.15rem; }

.msg-bubble blockquote {
  border-inline-start: 3px solid var(--dga-green);
  padding-inline-start: 0.8rem;
  color: var(--muted);
  margin-block: 0.5rem;
}

/* Streaming cursor */
.msg.streaming .msg-bubble::after {
  content: "▍";
  display: inline-block;
  color: var(--dga-green);
  margin-inline-start: 0.15rem;
  animation: blink 1s steps(2) infinite;
}

@keyframes blink { 50% { opacity: 0; } }

/* Tool chips */
.tool-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-block-end: 0.2rem;
}

.tool-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--dga-green-soft);
  color: var(--dga-green-dark);
  border: 1px solid rgba(0, 108, 53, 0.22);
  border-radius: 999px;
  padding: 0.25rem 0.7rem;
  font-size: 0.78rem;
  font-weight: 500;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tool-chip.running {
  background: var(--surface);
  border-color: var(--border);
  color: var(--muted);
}

.tool-chip.error {
  background: #fdecec;
  border-color: #f5c2c2;
  color: #9b1c1c;
}

.tool-chip svg { flex-shrink: 0; }

/* Thinking indicator */
.thinking {
  display: inline-flex;
  gap: 3px;
  padding: 0.25rem 0;
}

.thinking span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--dga-green);
  opacity: 0.5;
  animation: bounce 1.2s infinite ease-in-out;
}

.thinking span:nth-child(2) { animation-delay: 0.15s; }
.thinking span:nth-child(3) { animation-delay: 0.3s; }

@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.45; }
  40% { transform: translateY(-4px); opacity: 1; }
}

/* Composer */
.chat-composer {
  position: sticky;
  bottom: 0;
  inset-inline: 0;
  background: linear-gradient(to top, var(--surface-alt) 70%, rgba(245, 247, 245, 0));
  padding-block: 1rem 1.2rem;
  padding-inline: 1.5rem;
  z-index: 5;
}

.composer-inner {
  max-width: 820px;
  margin-inline: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.06);
  padding: 0.55rem 0.7rem 0.55rem 1rem;
  display: flex;
  align-items: end;
  gap: 0.6rem;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

html[dir="rtl"] .composer-inner {
  padding: 0.55rem 1rem 0.55rem 0.7rem;
}

.composer-inner:focus-within {
  border-color: var(--dga-green);
  box-shadow: 0 8px 28px rgba(0, 108, 53, 0.14);
}

#chat-input {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  font: inherit;
  font-size: 1rem;
  line-height: 1.5;
  padding: 0.6rem 0;
  max-height: 220px;
  color: var(--ink);
  background: transparent;
}

#chat-input::placeholder { color: var(--muted); }

.composer-send {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--dga-green);
  color: white;
  border: none;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 120ms ease, transform 120ms ease;
  flex-shrink: 0;
}

.composer-send:hover:not(:disabled) {
  background: var(--dga-green-dark);
  transform: scale(1.04);
}

.composer-send:disabled {
  background: var(--border);
  cursor: not-allowed;
}

html[dir="rtl"] .composer-send svg { transform: scaleX(-1); }

.composer-hint {
  max-width: 820px;
  margin-inline: auto;
  text-align: center;
  margin-block-start: 0.5rem;
  font-size: 0.76rem;
  color: var(--muted);
}

/* Citations */
.sources-row {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-block-start: 0.2rem;
}

.sources-heading {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.sources-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.source-pill {
  display: inline-flex;
  align-items: start;
  gap: 0.55rem;
  padding: 0.55rem 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--ink);
  font-size: 0.85rem;
  text-decoration: none;
  transition: border-color 120ms ease, transform 120ms ease, box-shadow 120ms ease;
  line-height: 1.4;
}

a.source-pill:hover {
  border-color: var(--dga-green);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.source-idx {
  flex-shrink: 0;
  min-width: 1.3rem;
  height: 1.3rem;
  padding: 0 0.35rem;
  border-radius: 4px;
  background: var(--dga-green-soft);
  color: var(--dga-green-dark);
  font-size: 0.75rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.source-pill svg {
  color: var(--dga-green);
  margin-block-start: 0.18rem;
  flex-shrink: 0;
}

.source-label {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: baseline;
  color: var(--ink);
  font-weight: 500;
  overflow-wrap: anywhere;
}

a.source-pill:hover .source-label {
  color: var(--dga-green-dark);
}

.source-meta {
  color: var(--muted);
  font-weight: 400;
  font-size: 0.8rem;
}

/* Error banner */
.chat-error {
  background: #fdecec;
  border: 1px solid #f5c2c2;
  color: #9b1c1c;
  padding: 0.7rem 1rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  margin-block: 0.5rem;
}

/* Hide the rest of the body footer on chat page */
.chat-body .site-footer { display: none; }
