/* ── Chat page layout ────────────────────────────────────────────────────── */
.chat-page {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

/* Compact header for chat page */
.chat-page .site-header { flex-shrink: 0; }

.chat-layout {
  display: grid;
  grid-template-columns: 22rem 1fr;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* ── Reasoning sidebar ───────────────────────────────────────────────────── */
.reasoning-panel {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--color-border);
  background: var(--color-surface);
  min-height: 0;
  overflow: hidden;
}

.reasoning-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.1rem;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.reasoning-panel__title {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-muted);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.reasoning-panel__title .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-muted);
  transition: background 0.3s;
}

.reasoning-panel__title .dot.active { background: var(--color-accent); animation: pulse 1.2s ease-in-out infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(1.3); }
}

.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-muted);
  padding: 0.25rem;
  border-radius: 0.4rem;
  font-size: 1rem;
  line-height: 1;
  transition: color var(--transition), background var(--transition);
}
.btn-icon:hover { color: var(--color-text); background: var(--color-border); }

.reasoning-panel__body {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.reasoning-panel__empty {
  color: var(--color-muted);
  font-size: 0.8rem;
  text-align: center;
  margin-top: 2rem;
  line-height: 1.6;
}

/* Reasoning step */
.r-step {
  display: flex;
  gap: 0.6rem;
  align-items: flex-start;
  font-size: 0.8rem;
  color: var(--color-muted);
  animation: fadeSlideIn 0.25s ease;
}

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

.r-step__icon { flex-shrink: 0; font-size: 0.9rem; line-height: 1.5; }

.r-step__text { flex: 1; line-height: 1.5; }

.r-step--active .r-step__text { color: var(--color-text); }
.r-step--done .r-step__icon { filter: brightness(1.2); }
.r-step--tool .r-step__text { color: var(--color-primary-h); font-family: var(--font-mono); font-size: 0.76rem; }

/* ── Main chat area ──────────────────────────────────────────────────────── */
.chat-main {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* Message bubbles */
.message {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  animation: fadeSlideIn 0.2s ease;
  max-width: 52rem;
}

.message--user { align-self: flex-end; flex-direction: row-reverse; }
.message--assistant { align-self: flex-start; }
.message--system { align-self: center; }

.message__avatar {
  flex-shrink: 0;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  font-weight: 700;
}

.message--user .message__avatar {
  background: var(--color-primary);
  color: #fff;
}

.message--assistant .message__avatar {
  background: color-mix(in srgb, var(--color-accent) 20%, transparent);
  border: 1px solid color-mix(in srgb, var(--color-accent) 40%, transparent);
  color: var(--color-accent);
}

.message__bubble {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  font-size: 0.925rem;
  line-height: 1.65;
  max-width: 38rem;
}

.message--user .message__bubble {
  background: var(--color-primary);
  color: #fff;
  border-bottom-right-radius: 0.25rem;
}

.message--assistant .message__bubble {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-bottom-left-radius: 0.25rem;
  color: var(--color-text);
}

.message--system .message__bubble {
  background: transparent;
  border: 1px dashed var(--color-border);
  color: var(--color-muted);
  font-size: 0.8rem;
  text-align: center;
}

/* Tool call block inside assistant bubble */
.tool-call-block {
  margin-top: 0.75rem;
  border: 1px solid color-mix(in srgb, var(--color-primary) 40%, transparent);
  border-radius: 0.5rem;
  overflow: hidden;
  font-size: 0.8rem;
}

.tool-call-block__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: color-mix(in srgb, var(--color-primary) 12%, transparent);
  padding: 0.4rem 0.75rem;
  cursor: pointer;
  user-select: none;
}

.tool-call-block__label {
  font-family: var(--font-mono);
  color: var(--color-primary-h);
  font-size: 0.78rem;
  font-weight: 600;
}

.tool-call-block__chevron {
  color: var(--color-muted);
  transition: transform var(--transition);
  font-style: normal;
}

.tool-call-block.is-open .tool-call-block__chevron { transform: rotate(90deg); }

.tool-call-block__body {
  display: none;
  padding: 0.75rem;
  background: color-mix(in srgb, var(--color-bg) 80%, transparent);
  overflow-x: auto;
}

.tool-call-block.is-open .tool-call-block__body { display: block; }

.tool-call-block__body pre {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--color-text);
  white-space: pre-wrap;
  word-break: break-all;
}

/* JSON syntax highlight (minimal) */
.json-key   { color: #9b8fff; }
.json-str   { color: #80e0a0; }
.json-num   { color: #f0c060; }
.json-bool  { color: #60c0f0; }
.json-null  { color: var(--color-muted); }

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 0.3rem;
  align-items: center;
  padding: 0.5rem 0;
}
.typing-indicator span {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--color-muted);
  animation: bounce 1.2s ease-in-out infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-6px); }
}

/* ── Chat input bar ──────────────────────────────────────────────────────── */
.chat-input-bar {
  flex-shrink: 0;
  border-top: 1px solid var(--color-border);
  padding: 1rem 1.5rem;
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
  background: var(--color-bg);
}

.chat-input-wrap {
  flex: 1;
  display: flex;
  align-items: flex-end;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.6rem 1rem;
  transition: border-color var(--transition);
  gap: 0.5rem;
}

.chat-input-wrap:focus-within { border-color: var(--color-primary); }

.chat-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: 0.95rem;
  resize: none;
  line-height: 1.5;
  max-height: 8rem;
  min-height: 1.5rem;
}

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

.chat-input-char {
  font-size: 0.75rem;
  color: var(--color-muted);
  align-self: flex-end;
  white-space: nowrap;
}

.btn-send {
  flex-shrink: 0;
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  width: 2.5rem;
  height: 2.5rem;
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), box-shadow var(--transition);
}
.btn-send:hover { background: var(--color-primary-h); box-shadow: 0 0 12px color-mix(in srgb, var(--color-primary) 60%, transparent); }
.btn-send:disabled { opacity: 0.4; cursor: not-allowed; box-shadow: none; }

/* Suggestions row */
.chat-suggestions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  padding: 0 1.5rem 0.75rem;
}

.suggestion-chip {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  padding: 0.3rem 0.85rem;
  font-size: 0.78rem;
  color: var(--color-muted);
  cursor: pointer;
  transition: border-color var(--transition), color var(--transition);
  white-space: nowrap;
}
.suggestion-chip:hover { border-color: var(--color-primary); color: var(--color-primary-h); }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .chat-layout { grid-template-columns: 1fr; }

  .reasoning-panel {
    display: none;
    position: fixed;
    inset: 4rem 0 0 0;
    z-index: 200;
    border-right: none;
    border-bottom: 1px solid var(--color-border);
    max-height: 45dvh;
  }

  .reasoning-panel.is-visible { display: flex; }

  .chat-suggestions { padding: 0 1rem 0.75rem; }
  .chat-input-bar    { padding: 0.75rem 1rem; }
  .chat-messages     { padding: 1rem; }
}
