/* ============================================================
   AI CHAT PAGE — Premium 2026 "AI Copilot" Interface
   Preserves all layout logic, chat mechanics, JS compatibility
   ============================================================ */

/* ── Body: fill screen, lock overflow ── */
body {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  margin: 0;
  max-width: 100vw;
}

/* ── Navbar shrinks to fit ── */
.navbar {
  flex-shrink: 0;
}

/* ── chat-page: fills remaining height ── */
.chat-page {
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  justify-content: center;
  background-color: var(--bg-color);
  padding: 0;
  position: relative;
}

/* Subtle radial glow behind chat */
.chat-page::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 70% 50% at 50% 80%, rgba(155,28,49,0.08) 0%, transparent 65%);
  pointer-events: none;
  z-index: 0;
}

/* ── chat-container: main frame ── */
.chat-container {
  width: 100%;
  max-width: 800px;
  display: flex;
  flex-direction: column;
  background-color: transparent;
  position: relative;
  z-index: 1;
}

/* ============================================================
   MESSAGES AREA
   ============================================================ */
.chat-messages {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1.5rem 1rem 6rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  scroll-behavior: smooth;

  scrollbar-width: thin;
  scrollbar-color: rgba(155,28,49,0.25) transparent;
}

.chat-messages::-webkit-scrollbar {
  width: 4px;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: rgba(155,28,49,0.3);
  border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

/* ============================================================
   MESSAGE BUBBLES — Premium 2026
   ============================================================ */
.message {
  display: flex;
  width: 100%;
  animation: fadeSlideUp 0.28s cubic-bezier(0.16, 1, 0.3, 1) both;
}

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

.message.user {
  justify-content: flex-end;
}

.message.ai {
  justify-content: flex-start;
}

.bubble {
  max-width: 75%;
  padding: 0.9rem 1.15rem;
  border-radius: 20px;
  line-height: 1.65;
  word-wrap: break-word;
  white-space: pre-wrap;
  font-size: 0.95rem;
}

/* ── User bubble ── */
.user .bubble {
  background: linear-gradient(135deg, #9B1C31 0%, #c0394e 100%);
  color: #fff;
  border-bottom-right-radius: 5px;
  box-shadow:
    0 4px 14px rgba(155,28,49,0.35),
    0 1px 0 rgba(255,255,255,0.08) inset;
}

/* ── AI bubble ── */
.ai .bubble {
  background: rgba(18, 22, 30, 0.9);
  color: var(--text-color);
  border: 1px solid rgba(255,255,255,0.07);
  border-bottom-left-radius: 5px;
  box-shadow:
    0 4px 16px rgba(0,0,0,0.3),
    0 0 0 1px rgba(155,28,49,0.08);
  backdrop-filter: blur(8px);
}

/* Light theme AI bubble */
.light-theme .ai .bubble {
  background: rgba(255,255,255,0.92);
  border-color: rgba(0,0,0,0.07);
  color: var(--text-color);
}

/* ── Loading bubble with animated dots ── */
.loading {
  align-items: center;
}

.loading .bubble {
  background: rgba(18, 22, 30, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 999px;
  color: #b8bcc8;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  min-height: 44px;
  padding: 0.7rem 1rem;
}

.loading-text {
  color: #b8bcc8;
  font-size: 0.92rem;
  line-height: 1;
}

.dots {
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
}

.dots span {
  display: block;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: rgba(155, 28, 49, 0.9);
  animation: dotPulse 1.1s ease-in-out infinite;
}

.dots span:nth-child(1) { animation-delay: 0s; }
.dots span:nth-child(2) { animation-delay: 0.16s; }
.dots span:nth-child(3) { animation-delay: 0.32s; }

@keyframes dotPulse {
  0%, 80%, 100% { opacity: 0.35; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

/* ── Error bubble ── */
.message.error .bubble {
  background: rgba(45,15,15,0.9);
  border: 1px solid rgba(185,28,28,0.4);
  color: #fca5a5;
}

/* ============================================================
   INPUT AREA — Pinned at bottom
   ============================================================ */
.chat-input-area {
  flex-shrink: 0;
  padding: 0.75rem 1rem 1.2rem;
  background: rgba(7, 9, 13, 0.85);
  border-top: 1px solid rgba(255,255,255,0.06);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.light-theme .chat-input-area {
  background: rgba(240,242,248,0.85);
  border-top-color: rgba(0,0,0,0.06);
}

/* ── Quick action chips ── */
.quick-actions {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  gap: 0.5rem;
  margin-bottom: 0.8rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 2px;
}

.quick-actions::-webkit-scrollbar {
  display: none;
}

.quick-btn {
  flex-shrink: 0;
  background: rgba(155,28,49,0.12);
  border: 1px solid rgba(155,28,49,0.35);
  color: #f87171;
  padding: 7px 15px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 34px;
  letter-spacing: 0.01em;
  font-family: inherit;
  transition:
    background var(--transition-fast),
    border-color var(--transition-fast),
    transform var(--transition-fast),
    box-shadow var(--transition-fast);
}

.quick-btn:hover {
  background: rgba(155,28,49,0.25);
  border-color: rgba(192,57,78,0.6);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(155,28,49,0.25);
  color: #fca5a5;
}

.quick-btn:active {
  transform: scale(0.96);
  box-shadow: none;
}

/* ── Input wrapper — premium pill ── */
.input-wrapper {
  display: flex;
  align-items: center;
  background: rgba(18,22,30,0.9);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 60px;
  padding: 0.3rem 0.3rem 0.3rem 1.3rem;
  transition:
    border-color var(--transition-fast),
    box-shadow var(--transition-fast),
    background var(--transition-fast);
  backdrop-filter: blur(8px);
}

.input-wrapper:focus-within {
  border-color: rgba(155,28,49,0.6);
  box-shadow:
    0 0 0 3px rgba(155,28,49,0.12),
    0 4px 16px rgba(155,28,49,0.15);
  background: rgba(18,22,30,0.98);
}

.light-theme .input-wrapper {
  background: rgba(255,255,255,0.92);
  border-color: rgba(0,0,0,0.08);
}

.light-theme .input-wrapper:focus-within {
  border-color: rgba(155,28,49,0.5);
  background: #ffffff;
}

#messageInput {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  color: var(--text-color);
  font-size: 0.95rem;
  font-family: inherit;
  padding: 0.75rem 0;
  outline: none;
  box-shadow: none;
  width: auto;
}

#messageInput::placeholder {
  color: var(--text-muted);
  opacity: 1;
}

.send-btn {
  flex-shrink: 0;
  background: linear-gradient(135deg, #9B1C31, #c0394e);
  border: none;
  border-radius: 50%;
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(155,28,49,0.4);
  transition:
    background var(--transition-fast),
    transform var(--transition-fast),
    box-shadow var(--transition-fast);
}

.send-btn:hover {
  background: linear-gradient(135deg, #b22b40, #cc4257);
  transform: scale(1.07);
  box-shadow: 0 4px 16px rgba(155,28,49,0.55);
}

.send-btn:active {
  transform: scale(0.94);
  box-shadow: none;
}

/* ============================================================
   MOBILE OVERRIDES ≤ 768px
   ============================================================ */
@media (max-width: 768px) {
  .chat-page {
    padding: 0;
  }

  .chat-messages {
    padding: 1rem 0.85rem 7rem;
    gap: 0.8rem;
    scroll-padding-top: 1rem;
  }

  .bubble {
    max-width: 88%;
    font-size: 0.92rem;
    padding: 0.8rem 1rem;
  }

  .chat-input-area {
    padding: 0.6rem 0.75rem env(safe-area-inset-bottom, 0.9rem);
  }

  .quick-btn {
    font-size: 0.78rem;
    padding: 6px 13px;
    min-height: 34px;
  }

  .input-wrapper {
    padding-left: 1rem;
    padding-right: 0.3rem;
  }

  #messageInput {
    font-size: max(0.93rem, 16px);
    padding: 0.7rem 0;
  }

  .send-btn {
    width: 40px;
    height: 40px;
    font-size: 0.95rem;
  }
}

/* ── Extra-small screens ── */
@media (max-width: 400px) {
  .bubble {
    max-width: 94%;
    font-size: 0.88rem;
  }

  .quick-btn {
    font-size: 0.74rem;
    padding: 5px 11px;
    min-height: 32px;
  }
}


@media (max-width: 600px) {
  .loading .bubble {
    min-height: 40px;
    padding: 0.62rem 0.9rem;
    gap: 0.45rem;
  }

  .loading-text {
    font-size: 0.88rem;
  }

  .dots span {
    width: 4px;
    height: 4px;
  }
}
