/* ==========================================================================
   Chat Styling: Apple Liquid Glass & High-Performance Fluid Viewport
   ========================================================================== */

.chat-viewport {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: auto;
  height: 100%;
  min-height: 0;
}

.chat-content-container {
  width: 100%;
  max-width: var(--max-content-width);
  margin: 0 auto;
  padding: 28px 20px 0;
  display: flex;
  flex-direction: column;
  gap: 24px;
  min-height: 100%;
  box-sizing: border-box;
}

/* Dedicated Safari-proof bottom clearance spacer */
.chat-bottom-spacer {
  height: var(--composer-spacing, 160px);
  min-height: var(--composer-spacing, 160px);
  width: 100%;
  flex-shrink: 0;
  pointer-events: none;
  display: block;
}

/* ==========================================
   Apple Native Empty State (Lovable Spec)
   ========================================== */
.empty-state {
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: left;
  margin: auto 0;
  padding: 40px 0 20px;
  animation: appleSpringIn var(--duration-normal) var(--ease-apple);
  width: 100%;
}

.empty-icon-wrap {
  margin-bottom: 20px;
  display: inline-flex;
}

.empty-icon {
  width: 60px;
  height: 60px;
  border-radius: 18px;
  object-fit: cover;
  display: block;
  background: #FFFFFF;
  border: 1px solid var(--border-glass);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
}

.empty-greeting {
  font-family: var(--font-apple-display);
  font-size: 34px;
  font-weight: 590;
  letter-spacing: -0.025em;
  color: var(--text-primary);
  margin-bottom: 6px;
  line-height: 1.2;
}

.empty-subtext {
  font-size: 18px;
  color: var(--text-secondary);
  line-height: 1.45;
  font-weight: 400;
}

/* Lovable 2x2 Grid Prompt Suggestion Cards */
.empty-suggestions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-top: 32px;
  width: 100%;
}

.suggestion-chip {
  padding: 18px 20px;
  border-radius: 20px;
  background: var(--card);
  backdrop-filter: var(--blur-card);
  -webkit-backdrop-filter: var(--blur-card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  text-align: left;
  min-height: 80px;
  display: flex;
  align-items: center;
  transition: filter 180ms var(--ease-spring), transform 220ms var(--ease-spring), border-color 180ms;
  cursor: pointer;
  line-height: 1.4;
}

.suggestion-chip:hover {
  filter: brightness(1.04);
  border-color: rgba(10, 132, 255, 0.35);
  transform: translateY(-2px);
}

.suggestion-chip:active {
  transform: scale(0.98);
}

/* ==========================================
   Message Rows & Bubbles (Lovable Spec)
   ========================================== */
.message-row {
  display: flex;
  flex-direction: column;
  width: 100%;
  scroll-margin-top: 24px;
  scroll-margin-bottom: 24px;
  animation: appleSpringIn var(--duration-fast) var(--ease-apple);
}

.message-row.user {
  align-items: flex-end;
}

.message-row.assistant {
  align-items: flex-start;
}

/* User Message Bubble — Sleek, compact standard chat style */
.user-bubble {
  max-width: 70%;
  width: fit-content;
  background: var(--primary);
  color: var(--primary-foreground);
  border-radius: 18px 18px 4px 18px;
  padding: 8px 14px;
  font-size: 14px;
  line-height: 1.4;
  box-shadow: 0 2px 8px -2px rgba(10, 132, 255, 0.35);
  word-break: break-word;
  border: none;
  display: inline-block;
}

.user-bubble-text {
  white-space: pre-wrap;
  margin: 0;
  padding: 0;
}

/* User Bubble Attachments */
.user-bubble-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.user-bubble-image {
  max-width: 240px;
  max-height: 200px;
  border-radius: 12px;
  object-fit: cover;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  cursor: pointer;
  background: rgba(255, 255, 255, 0.1);
  transition: transform var(--duration-fast) var(--ease-apple);
}

.user-bubble-image:hover {
  transform: scale(1.02);
}

.user-bubble-file {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.18);
  font-size: 12px;
  color: #FFFFFF;
}

/* Assistant Message Container */
.assistant-container {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.assistant-meta-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2px;
}

.tier-badge-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 11px;
  border-radius: var(--radius-pill);
  font-size: 11.5px;
  font-weight: 550;
  border: 1px solid var(--border-subtle);
  background: var(--glass-surface);
  backdrop-filter: var(--blur-subtle);
  box-shadow: var(--shadow-subtle);
}

.tier-badge-pill.lite {
  color: var(--tier-lite-color);
  background-color: var(--tier-lite-bg);
}

.tier-badge-pill.flash {
  color: var(--tier-flash-color);
  background-color: var(--tier-flash-bg);
}

.tier-badge-pill.pro {
  color: var(--tier-pro-color);
  background-color: var(--tier-pro-bg);
}

.stream-status-text {
  font-size: 12px;
  color: var(--text-tertiary);
  font-style: italic;
}

/* ==========================================
   Thinking Accordion (Apple Native Collapsible)
   ========================================== */
.thinking-wrapper {
  margin: 6px 0 10px;
  animation: appleSpringIn var(--duration-fast) var(--ease-apple);
}

/* ChatGPT-style streaming "Thinking…" pill shown during generation */
.thinking-status-pill {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 7px 14px;
  border-radius: var(--radius-pill);
  background: var(--glass-surface);
  border: 1px solid var(--border-glass);
  box-shadow: var(--shadow-subtle);
  backdrop-filter: var(--blur-subtle);
  -webkit-backdrop-filter: var(--blur-subtle);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  user-select: none;
  animation: appleSpringIn var(--duration-fast) var(--ease-apple);
}

/* 3-dot thinking bounce animation */
.thinking-dots {
  display: flex;
  align-items: center;
  gap: 4px;
}

.thinking-dots span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background-color: var(--accent-apple);
  animation: thinkingBounce 1.2s infinite ease-in-out;
}

.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes thinkingBounce {
  0%, 80%, 100% { transform: scale(0.7); opacity: 0.5; }
  40% { transform: scale(1); opacity: 1; }
}

.thinking-accordion {
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  background: var(--glass-surface);
  backdrop-filter: var(--blur-card);
  -webkit-backdrop-filter: var(--blur-card);
  overflow: hidden;
  box-shadow: var(--shadow-subtle);
}

.thinking-summary {
  list-style: none;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-secondary);
  transition: background-color var(--duration-fast);
}

.thinking-summary::-webkit-details-marker {
  display: none;
}

.thinking-summary:hover {
  background: var(--glass-hover);
  color: var(--text-primary);
}

.thinking-pulse-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: var(--accent-apple);
  animation: cursorBlink 1.2s infinite ease-in-out;
}

.thinking-title {
  flex: 1;
}

.thinking-chevron {
  font-size: 11px;
  color: var(--text-tertiary);
  transition: transform var(--duration-fast) var(--ease-apple);
}

.thinking-accordion[open] .thinking-chevron {
  transform: rotate(180deg);
}

.thinking-body {
  padding: 12px 14px 14px;
  border-top: 1px solid var(--border-subtle);
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  background: var(--glass-code);
  white-space: pre-wrap;
  max-height: 260px;
  overflow-y: auto;
}

/* ==========================================
   Assistant Prose & Rich Markdown Typography
   ========================================== */
.assistant-prose {
  font-size: 15px;
  line-height: 1.65;
  color: var(--text-primary);
  word-break: break-word;
}

.assistant-prose p {
  margin-bottom: 14px;
}

.assistant-prose p:last-child {
  margin-bottom: 0;
}

.assistant-prose h1,
.assistant-prose h2,
.assistant-prose h3,
.assistant-prose h4 {
  color: var(--text-primary);
  font-weight: 600;
  letter-spacing: -0.02em;
  margin: 20px 0 8px;
}

.assistant-prose h1 { font-size: 22px; }
.assistant-prose h2 { font-size: 18px; }
.assistant-prose h3 { font-size: 16px; }

.assistant-prose ul,
.assistant-prose ol {
  margin: 10px 0 14px 22px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.assistant-prose li {
  line-height: 1.6;
}

.assistant-prose blockquote {
  border-left: 3px solid var(--accent-apple);
  padding: 4px 14px;
  margin: 14px 0;
  color: var(--text-secondary);
  background: var(--glass-input);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.assistant-prose .inline-code {
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--glass-code);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
}

.assistant-prose a {
  color: var(--accent-apple);
  text-decoration: none;
}

.assistant-prose a:hover {
  text-decoration: underline;
}

/* Typing Cursor */
.typing-cursor {
  display: inline-block;
  width: 7px;
  height: 15px;
  background-color: var(--accent-apple);
  margin-left: 3px;
  vertical-align: -2px;
  border-radius: 2px;
  animation: cursorBlink 0.9s infinite;
}

/* ==========================================
   Apple Native Code Block Surfaces
   ========================================== */
.code-block-wrapper {
  margin: 16px 0;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border-glass);
  background: #14151A;
  box-shadow: var(--shadow-card);
}

.code-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: rgba(255, 255, 255, 0.05);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.code-lang-tag {
  font-size: 11.5px;
  font-family: var(--font-mono);
  color: #A1A1A6;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.btn-copy-code {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 11.5px;
  color: #A1A1A6;
  background: rgba(255, 255, 255, 0.08);
  transition: all var(--duration-fast);
}

.btn-copy-code:hover {
  color: #FFFFFF;
  background: rgba(255, 255, 255, 0.16);
}

.code-block-content {
  padding: 14px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.55;
  color: #E2E4E9;
  background: transparent;
}

/* Responsive Table */
.prose-table-wrap {
  width: 100%;
  overflow-x: auto;
  margin: 16px 0;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-glass);
  background: var(--glass-surface);
  box-shadow: var(--shadow-subtle);
}

.prose-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  text-align: left;
}

.prose-table th,
.prose-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-subtle);
}

.prose-table th {
  font-weight: 600;
  background: var(--glass-input);
  color: var(--text-primary);
}

.prose-table tr:last-child td {
  border-bottom: none;
}

/* ==========================================
   Apple Floating Scroll-to-Bottom Pill
   ========================================== */
.btn-scroll-bottom {
  position: absolute;
  bottom: calc(var(--composer-spacing, 160px) - 14px);
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  border-radius: var(--radius-pill);
  background: var(--glass-surface-elevated);
  backdrop-filter: var(--blur-ultra);
  -webkit-backdrop-filter: var(--blur-ultra);
  border: 1px solid var(--border-glass);
  box-shadow: var(--shadow-modal), 0 4px 16px rgba(0, 0, 0, 0.12);
  font-size: 12.5px;
  font-weight: 550;
  color: var(--text-primary);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s var(--ease-apple), transform 0.22s var(--ease-apple), background-color 0.15s ease;
  z-index: 30;
  cursor: pointer;
  user-select: none;
}

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

.btn-scroll-bottom:hover {
  background: var(--glass-hover);
  transform: translateX(-50%) translateY(-2px);
  box-shadow: var(--shadow-modal), 0 6px 20px rgba(0, 0, 0, 0.16);
}

.btn-scroll-bottom:active {
  transform: translateX(-50%) scale(0.96);
}

/* ==========================================
   Mobile Responsive Adjustments
   ========================================== */
@media (max-width: 768px) {
  .chat-content-container {
    padding: 18px 14px 0;
    gap: 18px;
  }

  .empty-suggestions {
    grid-template-columns: 1fr;
  }

  .user-bubble {
    max-width: 85%;
    padding: 8px 12px;
    font-size: 13.5px;
  }

  .empty-greeting {
    font-size: 28px;
  }

  .btn-scroll-bottom {
    bottom: calc(var(--composer-spacing, 160px) - 10px);
  }
}
