/* ==========================================================================
   Ask NASA — Chat UI Styles
   Matches portfolio light theme (Inter + Space Grotesk, #2563eb accent)
   ========================================================================== */

:root {
  --accent: #2563eb;
  --accent-light: rgba(37, 99, 235, 0.08);
  --bg-primary: #ffffff;
  --bg-secondary: #f8f9fc;
  --text-primary: #111827;
  --text-secondary: #6b7280;
  --border: rgba(0, 0, 0, 0.08);
  --font-body: 'Inter', sans-serif;
  --font-heading: 'Space Grotesk', sans-serif;
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg-secondary);
  -webkit-font-smoothing: antialiased;
}

/* ==========================================================================
   Layout
   ========================================================================== */

.chat-app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 800px;
  margin: 0 auto;
  background: var(--bg-primary);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

/* ==========================================================================
   Header
   ========================================================================== */

.chat-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-primary);
  flex-shrink: 0;
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-title {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.header-icon {
  flex-shrink: 0;
}

.header-title h1 {
  font-family: var(--font-heading);
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0;
  color: var(--text-primary);
}

.header-subtitle {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin: 0;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 8px;
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
  text-decoration: none;
  transition: background 150ms ease, color 150ms ease;
}

.icon-btn:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.how-it-works-btn {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.75rem;
  font-family: var(--font-body);
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--accent);
  background: var(--accent-light);
  border: 1px solid rgba(37, 99, 235, 0.15);
  border-radius: 20px;
  cursor: pointer;
  transition: background 150ms ease, transform 150ms ease;
}

.how-it-works-btn:hover {
  background: rgba(37, 99, 235, 0.14);
  transform: translateY(-1px);
}

.how-it-works-btn.active {
  color: #ffffff;
  background: var(--accent);
  border-color: var(--accent);
}

/* ==========================================================================
   Info Panel (How It Works)
   ========================================================================== */

.info-panel {
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  overflow-y: auto;
  max-height: 60vh;
  flex-shrink: 0;
  animation: slideDown 0.25s ease;
}

@keyframes slideDown {
  from { opacity: 0; max-height: 0; }
  to { opacity: 1; max-height: 60vh; }
}

.info-content {
  padding: 1.25rem 1.5rem;
  max-width: 600px;
  margin: 0 auto;
}

.info-content h3 {
  font-family: var(--font-heading);
  font-size: 1.1rem;
  font-weight: 700;
  margin: 0 0 0.5rem;
  color: var(--text-primary);
}

.info-content > p {
  font-size: 0.88rem;
  color: var(--text-secondary);
  margin: 0 0 1.25rem;
  line-height: 1.6;
}

/* Pipeline Diagram */
.pipeline {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin-bottom: 1.25rem;
}

.pipeline-step {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.step-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--accent-light);
  color: var(--accent);
  flex-shrink: 0;
}

.step-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.step-text strong {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
}

.step-text span {
  font-size: 0.78rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

.step-text a {
  color: var(--accent);
  text-decoration: none;
}

.step-text a:hover {
  text-decoration: underline;
}

.step-text code {
  font-size: 0.75rem;
  background: rgba(0, 0, 0, 0.06);
  padding: 0.05rem 0.3rem;
  border-radius: 3px;
}

.pipeline-arrow {
  display: flex;
  justify-content: center;
  padding: 0.15rem 0;
  color: var(--text-secondary);
  opacity: 0.5;
}

/* Info Note */
.info-note {
  font-size: 0.82rem;
  color: var(--text-secondary);
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  padding: 0.75rem 1rem;
  line-height: 1.55;
}

.info-note strong {
  color: var(--text-primary);
}

.info-note code {
  font-size: 0.75rem;
  background: rgba(0, 0, 0, 0.06);
  padding: 0.05rem 0.3rem;
  border-radius: 3px;
}

.info-note a {
  color: var(--accent);
  text-decoration: none;
}

.info-note a:hover {
  text-decoration: underline;
}

/* ==========================================================================
   Messages Area
   ========================================================================== */

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* Message Bubbles */
.message {
  max-width: 85%;
  padding: 0.875rem 1.125rem;
  border-radius: 16px;
  font-size: 0.95rem;
  line-height: 1.65;
  animation: fadeIn 0.3s ease;
}

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

.message-user {
  align-self: flex-end;
  background: var(--accent);
  color: #ffffff;
  border-bottom-right-radius: 4px;
}

.message-assistant {
  align-self: flex-start;
  background: var(--bg-secondary);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

/* Markdown inside assistant messages */
.message-assistant p {
  margin: 0 0 0.5rem;
}

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

.message-assistant ul,
.message-assistant ol {
  margin: 0.5rem 0;
  padding-left: 1.25rem;
}

.message-assistant li {
  margin-bottom: 0.25rem;
}

.message-assistant strong {
  font-weight: 600;
}

.message-assistant code {
  background: rgba(0, 0, 0, 0.06);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-size: 0.85em;
}

/* Thinking indicator */
.thinking {
  display: flex;
  gap: 4px;
  padding: 0.875rem 1.125rem;
}

.thinking-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-secondary);
  animation: bounce 1.4s ease-in-out infinite;
}

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

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* ==========================================================================
   Empty State
   ========================================================================== */

.empty-state {
  text-align: center;
  margin: auto;
  padding: 2rem 1rem;
  max-width: 480px;
}

.empty-icon {
  margin-bottom: 1.25rem;
}

.empty-state h2 {
  font-family: var(--font-heading);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 0.5rem;
}

.empty-state p {
  color: var(--text-secondary);
  font-size: 0.95rem;
  margin: 0 0 1.5rem;
}

.suggested-questions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
}

.suggestion {
  display: inline-block;
  padding: 0.5rem 1rem;
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--accent);
  background: var(--accent-light);
  border: 1px solid rgba(37, 99, 235, 0.15);
  border-radius: 20px;
  cursor: pointer;
  transition: background 150ms ease, transform 150ms ease;
}

.suggestion:hover {
  background: rgba(37, 99, 235, 0.14);
  transform: translateY(-1px);
}

/* ==========================================================================
   Input Bar
   ========================================================================== */

.chat-input-bar {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  background: var(--bg-primary);
  flex-shrink: 0;
}

.input-form {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.input-form input {
  flex: 1;
  padding: 0.75rem 1rem;
  font-family: var(--font-body);
  font-size: 0.95rem;
  color: var(--text-primary);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  outline: none;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.input-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.input-form input::placeholder {
  color: var(--text-secondary);
}

.input-form button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  background: var(--accent);
  color: #ffffff;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 150ms ease, box-shadow 150ms ease;
}

.input-form button:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.25);
}

.input-form button:active {
  transform: translateY(0);
}

.input-form button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.input-disclaimer {
  font-size: 0.7rem;
  color: var(--text-secondary);
  text-align: center;
  margin: 0.5rem 0 0;
}

/* ==========================================================================
   Source References
   ========================================================================== */

.message-sources {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  align-items: center;
}

.sources-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-right: 0.25rem;
}

.source-link {
  display: inline-block;
  font-size: 0.78rem;
  color: var(--accent);
  background: var(--accent-light);
  padding: 0.25rem 0.625rem;
  border-radius: 12px;
  text-decoration: none;
  border: 1px solid rgba(37, 99, 235, 0.12);
  transition: background 150ms ease, transform 150ms ease;
  line-height: 1.4;
}

.source-link:hover {
  background: rgba(37, 99, 235, 0.14);
  transform: translateY(-1px);
}

/* ==========================================================================
   Error Message
   ========================================================================== */

.message-error {
  align-self: flex-start;
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  padding: 0.875rem 1.125rem;
  font-size: 0.95rem;
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 840px) {
  .chat-app {
    border-left: none;
    border-right: none;
  }
}

@media (max-width: 480px) {
  .chat-header {
    padding: 0.75rem 1rem;
  }

  .chat-messages {
    padding: 1rem;
  }

  .chat-input-bar {
    padding: 0.75rem 1rem;
  }

  .message {
    max-width: 92%;
  }

  .header-title h1 {
    font-size: 1.1rem;
  }

  .empty-state h2 {
    font-size: 1.25rem;
  }

  .suggestion {
    font-size: 0.8rem;
    padding: 0.4rem 0.75rem;
  }

  .info-content {
    padding: 1rem;
  }

  .pipeline-step {
    padding: 0.5rem 0.6rem;
    gap: 0.5rem;
  }
}
