/* ==========================================================================
   DevPilot-AI - AI Chat Assistant CSS
   ========================================================================== */

/* Full Viewport App Containment for Chat */
html.chat-page,
body.chat-page {
  height: 100%;
  height: 100dvh;
  overflow: hidden;
}

#main-content.chat-main {
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-sizing: border-box;
}

/* Chat Container Card */
.chat-container {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  height: 100%;
  background: var(--color-surface);
  border: 1px solid var(--color-outline-variant);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-card);
  position: relative;
}

/* Messages Scroll Container */
.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.875rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background: var(--color-surface-container-low);
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

@media (min-width: 640px) {
  .chat-messages {
    padding: 1.25rem 1.5rem;
    gap: 1.25rem;
  }
}

/* Message Rows */
.message-row {
  display: flex;
  gap: 0.625rem;
  max-width: 94%;
  width: fit-content;
  transition: opacity 0.2s ease;
}

@media (min-width: 640px) {
  .message-row {
    max-width: 86%;
    gap: 0.875rem;
  }
}

@media (min-width: 1024px) {
  .message-row {
    max-width: 80%;
  }
}

.message-row.user {
  align-self: flex-end;
  flex-direction: row-reverse;
  margin-left: auto;
}

.message-row.ai {
  align-self: flex-start;
  margin-right: auto;
}

/* Avatars */
.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: var(--shadow-subtle);
}

@media (min-width: 640px) {
  .message-avatar {
    width: 36px;
    height: 36px;
  }
}

.user-avatar {
  background: var(--color-primary-light);
  color: var(--color-primary);
}

.ai-avatar {
  background: var(--color-primary);
  color: #ffffff;
}

/* Bubbles */
.message-bubble {
  padding: 0.75rem 0.875rem;
  border-radius: var(--radius-lg);
  font-size: 0.875rem;
  line-height: 1.55;
  position: relative;
  word-break: break-word;
  overflow-wrap: anywhere;
  min-width: 60px;
}

.message-text {
  color: inherit;
  font-family: inherit;
  font-size: inherit;
  font-weight: inherit;
  line-height: inherit;
  letter-spacing: inherit;
}

.chat-markdown-paragraph {
  margin: 0 0 0.75rem;
}

.chat-markdown-paragraph:last-child,
.chat-markdown-list:last-child,
.chat-code-block:last-child,
.message-text > :last-child {
  margin-bottom: 0;
}

.chat-markdown-heading {
  margin: 1rem 0 0.5rem;
  color: inherit;
  font-family: inherit;
  font-weight: 600;
  line-height: 1.35;
}

.chat-markdown-heading:first-child {
  margin-top: 0;
}

.chat-markdown-heading:is(h1, h2) {
  font-size: 1.1em;
}

.chat-markdown-heading:is(h3, h4) {
  font-size: 1.03em;
}

.chat-markdown-list {
  margin: 0 0 0.75rem;
  padding-left: 1.4rem;
}

.chat-markdown-list li + li {
  margin-top: 0.25rem;
}

.chat-markdown-list ul,
.chat-markdown-list ol {
  margin-top: 0.25rem;
  padding-left: 1.2rem;
}

.chat-markdown-list:is(ul) {
  list-style: disc;
}

.chat-markdown-list:is(ol) {
  list-style: decimal;
}

.chat-inline-code {
  padding: 0.1em 0.35em;
  border: 1px solid var(--color-outline-variant);
  border-radius: 0.3rem;
  background: var(--color-surface-container);
  color: var(--color-on-surface);
  font-family: 'Fira Code', 'Cascadia Code', 'Source Code Pro', Consolas, Monaco, monospace;
  font-size: 0.88em;
  white-space: break-spaces;
}

.chat-code-block {
  max-width: 100%;
  margin: 0 0 0.875rem;
  overflow: hidden;
  border: 1px solid var(--color-outline-variant);
  border-radius: var(--radius-md);
  background: var(--color-surface-container-low);
}

.chat-code-block-header {
  padding: 0.35rem 0.75rem;
  border-bottom: 1px solid var(--color-outline-variant);
  color: var(--color-on-surface-variant);
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 1.4;
  text-transform: lowercase;
}

.chat-code-block pre {
  max-width: 100%;
  margin: 0;
  padding: 0.75rem 0.875rem;
  overflow-x: auto;
  color: var(--color-on-surface);
  font-family: 'Fira Code', 'Cascadia Code', 'Source Code Pro', Consolas, Monaco, monospace;
  font-size: 0.82em;
  line-height: 1.55;
  tab-size: 2;
  white-space: pre;
  -webkit-overflow-scrolling: touch;
}

.chat-code-block code {
  color: inherit;
  font: inherit;
  white-space: inherit;
}

@media (min-width: 640px) {
  .message-bubble {
    padding: 0.875rem 1.125rem;
    font-size: 0.9375rem;
    line-height: 1.6;
  }
}

.message-row.user .message-bubble {
  background: var(--color-primary);
  color: #ffffff;
  border-bottom-right-radius: 4px;
}

.message-row.ai .message-bubble {
  background: #ffffff;
  color: var(--color-on-surface);
  border: 1px solid var(--color-outline-variant);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow-subtle);
}

/* Visual cue for target / exit message highlight */
.message-row.highlight-exit-target .message-bubble {
  outline: 2px solid var(--color-primary);
  outline-offset: 3px;
  animation: exitTargetPulse 1.8s ease-out forwards;
}

@keyframes exitTargetPulse {
  0% {
    outline-color: var(--color-primary);
    box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.25);
  }
  70% {
    outline-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.1);
  }
  100% {
    outline-color: transparent;
    box-shadow: none;
  }
}

/* Code Snippets within Messages */
.chat-messages .code-block-wrapper {
  max-width: 100%;
  overflow: hidden;
  margin-top: 0.625rem;
  border-radius: var(--radius-md);
}

.chat-messages .code-content {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  white-space: pre;
  max-width: 100%;
  font-size: 0.78rem;
}

@media (min-width: 640px) {
  .chat-messages .code-content {
    font-size: 0.8125rem;
  }
}

/* Floating Jump to Last Chat Button */
.chat-scroll-bottom-btn {
  position: absolute;
  bottom: 112px;
  right: 18px;
  background: #ffffff;
  color: var(--color-primary);
  border: 1px solid var(--color-outline-variant);
  border-radius: var(--radius-full);
  padding: 0.375rem 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.375rem;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.12);
  cursor: pointer;
  transition: opacity 0.2s cubic-bezier(0.4, 0, 0.2, 1), transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  z-index: 30;
}

@media (min-width: 640px) {
  .chat-scroll-bottom-btn {
    bottom: 120px;
    right: 28px;
  }
}

.chat-scroll-bottom-btn.visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

.chat-scroll-bottom-btn:hover {
  background: var(--color-primary-light);
  border-color: var(--color-primary);
  box-shadow: 0 6px 18px rgba(79, 70, 229, 0.2);
}

/* Chat Input Bar */
.chat-input-container {
  padding: 0.625rem 0.75rem;
  background: var(--color-surface);
  border-top: 1px solid var(--color-outline-variant);
  flex-shrink: 0;
  box-sizing: border-box;
}

@media (min-width: 640px) {
  .chat-input-container {
    padding: 0.875rem 1.25rem;
  }
}

.chat-input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  background: var(--color-surface-container-low);
  border: 1px solid var(--color-outline-variant);
  border-radius: var(--radius-lg);
  padding: 0.5rem 0.625rem;
  transition: all var(--transition-fast);
}

@media (min-width: 640px) {
  .chat-input-wrapper {
    gap: 0.75rem;
    padding: 0.625rem 0.875rem;
  }
}

.chat-input-wrapper:focus-within {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
  background: #ffffff;
}

.chat-textarea {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  font-size: 16px; /* 16px prevents automatic zoom-in on iOS Safari upon focus */
  color: var(--color-on-surface);
  resize: none;
  max-height: 120px;
  min-height: 24px;
  line-height: 1.4;
  font-family: inherit;
  padding: 0;
}

@media (min-width: 640px) {
  .chat-textarea {
    font-size: 0.9375rem;
    line-height: 1.5;
  }
}

/* Quick prompt suggestions */
.chat-suggestions {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 0.5rem;
  margin-bottom: 0.5rem;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.chat-suggestions::-webkit-scrollbar {
  display: none;
}

.suggestion-chip {
  padding: 0.35rem 0.75rem;
  background: var(--color-surface-container);
  color: var(--color-on-surface-variant);
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 500;
  white-space: nowrap;
  flex-shrink: 0;
  cursor: pointer;
  border: 1px solid var(--color-outline-variant);
  transition: all var(--transition-fast);
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  user-select: none;
}

@media (min-width: 640px) {
  .suggestion-chip {
    padding: 0.375rem 0.875rem;
    font-size: 0.8125rem;
  }
}

.suggestion-chip:hover {
  background: var(--color-primary-light);
  color: var(--color-primary);
  border-color: var(--color-primary);
}
