/* Codehakai AI assistant — chat surface.
   Loads after style.css and reuses its tokens, buttons, and card styles. */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---- Hero ---- */
.ai-hero {
  position: relative;
  padding-top: calc(var(--header-h) + clamp(44px, 7vw, 80px));
  padding-bottom: clamp(40px, 6vw, 72px);
  overflow: hidden;
}

.ai-hero-inner {
  position: relative;
  text-align: center;
}

.ai-title {
  font-family: var(--font-display);
  font-size: clamp(32px, 4.6vw, 54px);
  font-weight: 700;
  line-height: 1.07;
  letter-spacing: -0.028em;
  max-width: 18ch;
  margin: 0 auto;
}

.ai-title em {
  font-style: normal;
  color: var(--accent);
}

.ai-lede {
  color: var(--muted);
  font-size: clamp(15.5px, 1.5vw, 17.5px);
  max-width: 60ch;
  margin: 18px auto 0;
}

/* ---- Chat shell ---- */
.chat-shell {
  max-width: 860px;
  margin: clamp(32px, 5vw, 52px) auto 0;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: 0 34px 90px -34px rgba(0, 0, 0, 0.8);
}

.chat-head {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

.chat-head code {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--muted);
}

.chat-status {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--faint);
  white-space: nowrap;
}

.chat-status i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.chat-status.is-live {
  color: var(--accent);
  border-color: rgba(200, 245, 96, 0.4);
  background: var(--accent-soft);
}

/* ---- Messages ---- */
.chat-log {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 26px 24px;
  min-height: 260px;
  max-height: 460px;
  overflow-y: auto;
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

.msg {
  display: flex;
  flex-direction: column;
  gap: 7px;
  max-width: 86%;
}

.msg-who {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--faint);
}

.msg-body {
  padding: 14px 18px;
  border-radius: 14px;
  font-size: 15px;
  line-height: 1.68;
}

.msg-body p + p {
  margin-top: 11px;
}

.msg.bot .msg-body {
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-top-left-radius: 4px;
  color: var(--text);
}

.msg.user {
  align-self: flex-end;
  align-items: flex-end;
}

.msg.user .msg-body {
  background: var(--accent-soft);
  border: 1px solid rgba(200, 245, 96, 0.28);
  border-top-right-radius: 4px;
  color: var(--text);
}

.msg.is-error .msg-body {
  background: rgba(255, 92, 92, 0.08);
  border-color: rgba(255, 132, 132, 0.34);
  color: #ffb4b4;
}

.typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 0;
}

.typing i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--faint);
  animation: typing-bounce 1.2s ease-in-out infinite;
}

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

@keyframes typing-bounce {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-4px); }
}

/* ---- Suggestions ---- */
.chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  padding: 0 24px;
}

.chat-suggestions button {
  padding: 8px 15px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  font-size: 13.5px;
  color: var(--muted);
  transition: border-color 0.25s, color 0.25s, background 0.25s, transform 0.25s var(--ease-out);
}

.chat-suggestions button:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
  transform: translateY(-2px);
}

.chat-suggestions.is-hidden {
  display: none;
}

/* ---- Composer ---- */
.chat-composer {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  padding: 18px 24px 14px;
}

.chat-composer textarea {
  flex: 1;
  font: inherit;
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  padding: 13px 16px;
  resize: none;
  max-height: 160px;
  transition: border-color 0.25s, box-shadow 0.25s;
}

.chat-composer textarea::placeholder {
  color: var(--faint);
}

.chat-composer textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(200, 245, 96, 0.14);
}

.chat-composer textarea:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.chat-send {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-ink);
  transition: background 0.25s, transform 0.25s var(--ease-out), opacity 0.25s;
}

.chat-send svg {
  width: 17px;
  height: 17px;
}

.chat-send:hover:not(:disabled) {
  background: var(--accent-strong);
  transform: translateY(-2px);
}

.chat-send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.chat-meta {
  padding: 0 24px 20px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--faint);
}

/* ---- Responsive ---- */
@media (max-width: 620px) {
  .chat-log {
    padding: 20px 16px;
    max-height: 400px;
  }

  .msg {
    max-width: 94%;
  }

  .chat-suggestions,
  .chat-composer,
  .chat-meta {
    padding-inline: 16px;
  }

  .chat-head {
    padding-inline: 14px;
  }

  .chat-head code {
    font-size: 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat-log {
    scroll-behavior: auto;
  }

  .typing i {
    animation: none;
  }
}
