:root {
  /* Adjust this once to match your top navbar height */
  --app-header-offset: 90px;
}

.chat-page {
  max-width: 900px;
  margin: 0 auto;
  padding: 16px;
  overflow-x: hidden;

  /* IMPORTANT: take navbar into account */
  height: calc(100dvh - var(--app-header-offset));
  box-sizing: border-box;

  display: flex;
  flex-direction: column;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.chat-title {
  font-size: 18px;
  font-weight: 700;
  margin: 0;
}

.chat-mode {
  font-size: 14px;
  color: #555;
}

.mode-tabs {
  display: flex;
  gap: 8px;
  margin: 12px 0 16px;
}

.mode-tab {
  border: 1px solid #ddd;
  background: #fff;
  padding: 6px 10px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
}

.mode-tab.is-active {
  border-color: #111;
  font-weight: 700;
}

.chat-shell {
  border: 1px solid #e6e6e6;
  border-radius: 14px;
  overflow: hidden;
  background: #fff;

  /* Make the shell behave like a real chat container */
  display: flex;
  flex-direction: column;

  /* Fill remaining space; scrolling happens inside `.chat-messages`. */
  flex: 1 1 auto;
  min-height: 0;
}

.chat-messages {
  /* Fill available space in the shell (and allow overflow scrolling) */
  flex: 1 1 auto;

  /* Scroll only inside the messages area */
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-gutter: stable;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
  min-height: 0;

  padding: 14px;
  background: #fafafa;

  /* Chat behavior: messages sit at the bottom when there are few */
  display: block;
  flex-direction: column;
  justify-content: flex-end;
  gap: 10px;
}

.msg-row {
  display: flex;
  /* Prevent vertical stretching (fixes the tall black pill bubble) */
  align-items: flex-end;
  margin: 10px 0;
}

.msg-row.is-user {
  justify-content: flex-end;
}

.msg-row.is-assistant {
  justify-content: flex-start;
}

.bubble {
  display: inline-block;
  height: auto;
  max-width: min(78%, 640px);
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid #e6e6e6;
  background: #fff;
  line-height: 1.35;
  white-space: normal;
  word-break: break-word;
}

.msg-row.is-user .bubble {
  background: #111;
  color: #fff;
  border-color: #111;
}

.msg-row.is-assistant .bubble {
  background: #fff;
  color: #111;
}

.bubble-meta {
  font-size: 12px;
  opacity: 0.7;
  margin-top: 6px;
}

/* Reset default margins created by Rails `simple_format` (<p> tags). */
.bubble-content p {
  margin: 0;
}

.bubble-content p + p {
  margin-top: 8px;
}

.chat-input {
  border-top: 1px solid #e6e6e6;
  padding: 12px;
  background: #fff;
}

.chat-form {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.chat-textarea {
  flex: 1;
  min-height: 56px;
  max-height: 140px;
  resize: vertical;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid #ddd;
  font-size: 14px;
}

.chat-send {
  border: 1px solid #111;
  background: #111;
  color: #fff;
  padding: 10px 14px;
  border-radius: 12px;
  cursor: pointer;
  font-size: 14px;
}