/* ==========================================
   CHAT INTERFACE
   ========================================== */

.chat-container {
  max-width: 900px;
  margin: 0 auto;
}

/* Header uses global .page-header from style.css */

/* ==========================================
   SESSION ROW (quota + new conversation)
   ========================================== */

/* Was a full-width centred banner on --violet-wash with a 4px violet left bar,
   57px tall, to say one number. It outweighed the send button, which is the
   only action of the page. Metadata reads as metadata: a mono line, right of
   the row, next to the only control that acts on the session. */
.chat-session-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-sm);
  margin-bottom: var(--space-xs);
}

.quota-info {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.quota-info strong {
  font-weight: var(--font-weight-medium);
  color: var(--text-secondary);
}

.btn-clear-chat {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  background: transparent;
  color: var(--text-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: color var(--transition-fast), border-color var(--transition-fast);
}

.btn-clear-chat:hover {
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.btn-clear-chat:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-clear-chat.loading svg {
  animation: spin 0.8s linear infinite;
}

.btn-clear-chat svg {
  width: 16px;
  height: 16px;
}

/* ==========================================
   CONVERSATION
   ========================================== */

/* The height was a hardcoded 600px, which cost twice: the same box on a 13"
   laptop and on a 27" display, and 400px of void under the welcome message on
   the anonymous page, which is the first thing a visitor sees. It grows with
   the conversation and stops at what the viewport can hold; the offset is what
   sits above it (sticky header + page header + session row), measured. */
.chat-box {
  display: flex;
  flex-direction: column;
  min-height: 300px;
  max-height: clamp(420px, calc(100vh - 300px), 900px);
  background: var(--card-bg);
  /* --card-bg and --bg-primary are one step apart and the shadow is black on a
     near-black canvas, so the box had no visible edge at all. The hairline is
     what draws it, not the elevation. */
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: var(--space-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.chat-message {
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-md);
  max-width: 80%;
  animation: messageSlide var(--transition-base);
}

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

/* The speaker is carried by the tint and by the side of the box, not by weight:
   this border was 2px --violet-primary, which made the visitor's own message
   the loudest element of a page whose only action is the send button. */
.chat-message.user {
  background-color: var(--violet-wash);
  border: 1px solid var(--violet-dark);
  align-self: flex-end;
  border-bottom-right-radius: var(--radius-sm);
  color: var(--text-primary);
}

.chat-message.assistant {
  background-color: var(--surface-raised);
  border: 1px solid var(--border-color);
  align-self: flex-start;
  border-bottom-left-radius: var(--radius-sm);
}

/* Same tokens as the global .eyebrow. Not the class itself: this label is also
   built by the three template literals of the page script, and a class added
   in one place and not the other is exactly how two renderings drift. */
.chat-message-role {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: var(--font-weight-medium);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  margin-bottom: 0.35rem;
}

.chat-message.user .chat-message-role {
  color: var(--violet-primary);
}

.chat-message.assistant .chat-message-role {
  color: var(--text-secondary);
}

.chat-message-content {
  color: var(--text-primary);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  white-space: pre-wrap;
}

.empty-state {
  margin: auto;
  text-align: center;
  color: var(--text-secondary);
  font-size: var(--text-base);
}

/* ==========================================
   COMPOSER
   ========================================== */

/* --bg-secondary is exactly --card-bg, already carried by the box, so this
   band was the same colour as its host and only the hairline separated them.
   Transparent says the same thing without the collision. */
.chat-input-container {
  padding: var(--space-sm);
  background: transparent;
  border-top: 1px solid var(--border-color);
}

.chat-form {
  display: flex;
  gap: var(--space-xs);
}

.chat-input {
  flex: 1;
  padding: 0.6rem 0.75rem;
  background: var(--input-bg);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: var(--text-base);
  font-family: inherit;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.chat-input:focus {
  outline: none;
  border-color: var(--violet-primary);
  box-shadow: 0 0 0 3px rgba(var(--violet-primary-rgb), 0.18);
}

/* A <button> inherits neither font-family nor font-size, and this rule set
   neither: the label rendered in the user-agent font at 13.33px next to a 15px
   input. Yellow stays, it is the single action of the screen. */
.chat-submit {
  padding: 0.6rem var(--space-sm);
  background: var(--yellow-primary);
  color: var(--dark-primary);
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: var(--text-base);
  font-weight: var(--font-weight-bold);
  cursor: pointer;
  transition: background var(--transition-fast), opacity var(--transition-fast);
}

.chat-submit:hover {
  background: var(--yellow-dark);
}

.chat-submit:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.loading-indicator {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  padding-top: var(--space-xs);
  color: var(--text-secondary);
  font-size: var(--text-sm);
}

.login-prompt {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: var(--space-xs) 0;
}

.login-prompt p {
  margin: 0;
  color: var(--text-secondary);
  font-size: var(--text-base);
}

.btn-login {
  padding: var(--space-xs) var(--space-sm);
  background: var(--yellow-primary);
  color: var(--dark-primary);
  text-decoration: none;
  border-radius: var(--radius-sm);
  font-size: var(--text-base);
  font-weight: var(--font-weight-bold);
  transition: background var(--transition-fast);
}

.btn-login:hover {
  background: var(--yellow-dark);
}

/* ==========================================
   ANIMATIONS & LOADING STATES
   ========================================== */

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

/* The track was --violet-light, a near-white pastel the design system declares
   ink-only: a 3px bright ring was the lightest thing on the page while waiting. */
.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--violet-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ==========================================
   RESPONSIVE - MOBILE
   ========================================== */

@media (max-width: 768px) {
  .chat-box {
    max-height: clamp(360px, calc(100vh - 260px), 640px);
  }

  .chat-messages {
    padding: var(--space-sm);
  }

  .chat-message {
    max-width: 90%;
  }
}

/* Responsive for page header is handled in global style.css */
