/* Reset and Base Styles */
*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  /* Gray scale palette */
  --bg-primary: #f7f7f8;
  --bg-secondary: #fafafa;
  --bg-tertiary: #ededef;
  
  /* Purple accent colors */
  --accent-primary: #9b87f5;
  --accent-secondary: #7c66dc;
  --accent-light: #c4b5fd;
  --accent-dark: #6366f1;
  --accent-text: #8b7fd1;
  
  /* Text colors - cool grays */
  --text-primary: #2d2d32;
  --text-secondary: #5a5a64;
  --text-muted: #9090a0;
  
  /* UI colors */
  --border: rgba(139, 139, 160, 0.15);
  --shadow: rgba(45, 45, 50, 0.08);
  --subtle-shadow: rgba(45, 45, 50, 0.05);
  
  /* Message colors */
  --message-user-bg: linear-gradient(135deg, #e9e3ff 0%, #ddd6fe 100%);
  --message-assistant-bg: #ffffff;
  
  --font-sans: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-display: 'Space Grotesk', var(--font-sans);
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  padding: 0;
  font-family: var(--font-sans);
  color: var(--text-secondary);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-y: auto;
  position: relative;
  background: linear-gradient(135deg, #f4f4f9 0%, #f8f7fb 45%, #f3f4f9 100%);
  isolation: isolate;
}

body::before {
  content: "";
  position: fixed;
  inset: -25%;
  background:
    radial-gradient(circle at var(--bg-x1, 18%) var(--bg-y1, 26%), rgba(107, 91, 209, 0.35) 0%, transparent 62%),
    radial-gradient(circle at var(--bg-x2, 84%) var(--bg-y2, 18%), rgba(167, 139, 250, 0.3) 0%, transparent 68%),
    radial-gradient(circle at var(--bg-x3, 42%) var(--bg-y3, 82%), rgba(71, 63, 145, 0.32) 0%, transparent 60%);
  filter: blur(80px);
  animation: bgDriftA 12s ease-in-out infinite alternate;
  z-index: -1;
  pointer-events: none;
  opacity: 0.92;
}

body::after {
  content: "";
  position: fixed;
  inset: -30%;
  background:
    radial-gradient(circle at var(--bg2-x1, 20%) var(--bg2-y1, 72%), rgba(55, 48, 107, 0.24) 0%, transparent 58%),
    radial-gradient(circle at var(--bg2-x2, 68%) var(--bg2-y2, 34%), rgba(141, 129, 209, 0.22) 0%, transparent 60%),
    radial-gradient(circle at var(--bg2-x3, 82%) var(--bg2-y3, 82%), rgba(196, 181, 253, 0.2) 0%, transparent 62%);
  filter: blur(110px);
  animation: bgDriftB 16s ease-in-out infinite alternate;
  mix-blend-mode: soft-light;
  z-index: -2;
  pointer-events: none;
  opacity: 0.82;
}

/* Main container */
.chat-container {
  max-width: 900px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 0 32px;
}

/* Header */
.chat-header {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  padding: 24px 0 20px;
  border-bottom: none;
  flex-shrink: 0;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  pointer-events: none;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  padding: 0 32px;
  justify-content: flex-end;
  pointer-events: auto;
}

.icon-button {
  width: 40px;
  height: 40px;
  background: transparent;
  border: none;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.3s ease;
  text-decoration: none;
  box-shadow: none;
}

.icon-button:hover {
  background: rgba(155, 135, 245, 0.12);
  color: var(--accent-primary);
  border-color: transparent;
  transform: scale(1.1);
  box-shadow: none;
}

.icon-button:active {
  transform: scale(1);
}

.icon-button svg {
  width: 20px;
  height: 20px;
}

.header-left,
.logo-icon,
.header-title,
.back-link {
  display: none;
}

/* Main chat area */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 80px 0 0;
  position: relative;
  min-height: calc(100vh - 64px);
}

.chat-messages {
  flex: 1;
  padding: 0 0 200px 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chat-messages:has(.message) {
  padding: 0 0 24px 0;
}

.chat-messages:has(.message) ~ .chat-input-container {
  position: static;
  transform: none;
}

/* Custom scrollbar - minimal for body */
body::-webkit-scrollbar {
  width: 6px;
}

body::-webkit-scrollbar-track {
  background: transparent;
}

body::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

body::-webkit-scrollbar-thumb:hover {
  background: var(--accent-primary);
}

@keyframes bgDriftA {
  0% {
    --bg-x1: 10%; --bg-y1: 20%;
    --bg-x2: 88%; --bg-y2: 14%;
    --bg-x3: 46%; --bg-y3: 68%;
    transform: translate(-4%, -3%) scale(1.03);
    opacity: 0.75;
  }
  50% {
    --bg-x1: 22%; --bg-y1: 30%;
    --bg-x2: 76%; --bg-y2: 20%;
    --bg-x3: 58%; --bg-y3: 80%;
    transform: translate(3%, 2%) scale(1.08);
    opacity: 0.92;
  }
  100% {
    --bg-x1: 16%; --bg-y1: 34%;
    --bg-x2: 84%; --bg-y2: 26%;
    --bg-x3: 52%; --bg-y3: 86%;
    transform: translate(-2%, 4%) scale(1.04);
    opacity: 0.8;
  }
}

@keyframes bgDriftB {
  0% {
    --bg2-x1: 30%; --bg2-y1: 70%;
    --bg2-x2: 62%; --bg2-y2: 28%;
    --bg2-x3: 78%; --bg2-y3: 86%;
    transform: translate(3%, -2%) scale(1.02) rotate(0deg);
    opacity: 0.68;
  }
  50% {
    --bg2-x1: 18%; --bg2-y1: 78%;
    --bg2-x2: 70%; --bg2-y2: 36%;
    --bg2-x3: 88%; --bg2-y3: 90%;
    transform: translate(-4%, 3%) scale(1.1) rotate(5deg);
    opacity: 0.82;
  }
  100% {
    --bg2-x1: 26%; --bg2-y1: 82%;
    --bg2-x2: 64%; --bg2-y2: 32%;
    --bg2-x3: 74%; --bg2-y3: 84%;
    transform: translate(2%, -1%) scale(1.05) rotate(-4deg);
    opacity: 0.7;
  }
}

/* Welcome message */
.welcome-message {
  background: transparent;
  border: none;
  padding: 0 0 200px 0;
  max-width: 500px;
  margin: 0 auto;
  animation: fadeInUp 0.5s ease;
  text-align: center;
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  padding-bottom: 240px;
}

.welcome-heading {
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 20px 0;
  letter-spacing: -0.02em;
}

.welcome-text {
  color: var(--text-secondary);
  font-size: 16px;
  line-height: 1.7;
  margin: 0 0 16px 0;
}

.welcome-subheading {
  display: none;
}

.welcome-list {
  display: none;
}

.welcome-list li {
  display: none;
}

.welcome-list li::before {
  display: none;
}

.example-text {
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.7;
  margin: 0;
  font-style: italic;
  font-weight: 400;
  padding: 0;
  background: transparent;
  border-radius: 0;
  border-left: none;
}

/* Chat messages */
.message {
  display: flex;
  flex-direction: column;
  gap: 4px;
  animation: fadeInUp 0.3s ease;
  max-width: 72%;
}

.message--user {
  align-self: flex-end;
}

.message--assistant {
  align-self: flex-start;
}

.message-bubble {
  background: var(--message-assistant-bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 16px 20px;
  color: var(--text-secondary);
  font-size: 15px;
  line-height: 1.7;
  word-wrap: break-word;
  overflow-wrap: break-word;
  box-shadow: 0 2px 8px var(--subtle-shadow);
}

.message--user .message-bubble {
  background: linear-gradient(135deg, rgba(80, 70, 150, 0.92) 0%, rgba(124, 102, 220, 0.88) 100%);
  border: 1px solid rgba(80, 70, 150, 0.45);
  color: var(--text-primary);
  font-weight: 500;
  color: #f6f5ff;
  box-shadow: 0 8px 24px rgba(55, 48, 107, 0.25);
}

.message--error .message-bubble {
  border-color: rgba(220, 100, 80, 0.3);
  background: rgba(220, 100, 80, 0.08);
  color: #d06450;
}

/* Loading state */
.message--loading .message-bubble {
  position: relative;
  border-color: var(--accent-primary);
  background: var(--bg-secondary);
}

.message--loading .message-bubble::after {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-left: 6px;
  border-radius: 50%;
  background: var(--accent-primary);
  animation: pulse 1.4s ease-in-out infinite;
}

/* Input container */
.chat-input-container {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: center;
  padding: 0 32px 60px 32px;
  flex-shrink: 0;
  position: absolute;
  bottom: 35%;
  left: 50%;
  transform: translate(-50%, 50%);
  background: transparent;
  width: 100%;
  max-width: 700px;
  transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1),
              bottom 0.5s cubic-bezier(0.4, 0, 0.2, 1),
              padding 0.5s cubic-bezier(0.4, 0, 0.2, 1),
              max-width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 10;
}

.chat-input-container.is-focused {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translate(-50%, 0);
  padding: 0;
  max-width: 900px;
  width: calc(100% - 48px);
  background: transparent;
}

.chat-input {
  flex: 1;
  background: white;
  border: 2px solid var(--border);
  border-radius: 30px;
  padding: 14px 20px;
  color: var(--text-primary);
  font-size: 15px;
  font-family: var(--font-sans);
  outline: none;
  transition: padding 0.4s cubic-bezier(0.4, 0, 0.2, 1),
              border-color 0.3s ease,
              box-shadow 0.3s ease;
  line-height: 1.5;
  box-shadow: 0 2px 8px var(--subtle-shadow);
}

.chat-input-container.is-focused .chat-input {
  padding: 16px 22px;
}

.chat-input::placeholder {
  color: var(--text-muted);
}

.chat-input:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 4px 16px rgba(155, 135, 245, 0.2), 0 0 0 4px rgba(155, 135, 245, 0.1);
}

.chat-submit {
  width: 44px;
  height: 44px;
  background: var(--accent-primary);
  border: none;
  border-radius: 22px;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1),
              height 0.4s cubic-bezier(0.4, 0, 0.2, 1),
              border-radius 0.4s cubic-bezier(0.4, 0, 0.2, 1),
              transform 0.3s ease,
              background 0.3s ease,
              opacity 0.3s ease;
  flex-shrink: 0;
  opacity: 0.9;
}

.chat-input-container.is-focused .chat-submit {
  width: 48px;
  height: 48px;
  border-radius: 24px;
}

.chat-submit:hover:not(:disabled) {
  transform: scale(1.05);
  opacity: 1;
  background: var(--accent-secondary);
}

.chat-submit:active:not(:disabled) {
  transform: scale(0.95);
}

.chat-submit:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.chat-submit svg {
  width: 20px;
  height: 20px;
}

/* Screen reader only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* Animations */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {
  0%, 100% {
    opacity: 0.4;
    transform: scale(1);
  }
  50% {
    opacity: 1;
    transform: scale(1.2);
  }
}

/* Markdown Styling in Message Bubbles */
.message-bubble h1,
.message-bubble h2,
.message-bubble h3,
.message-bubble h4,
.message-bubble h5,
.message-bubble h6 {
  margin: 1em 0 0.6em 0;
  font-weight: 600;
  line-height: 1.3;
  color: var(--text-primary);
}

.message-bubble h1 { font-size: 1.4em; }
.message-bubble h2 { font-size: 1.25em; }
.message-bubble h3 { font-size: 1.1em; }

.message-bubble h1:first-child,
.message-bubble h2:first-child,
.message-bubble h3:first-child {
  margin-top: 0;
}

.message-bubble p {
  margin: 0.8em 0;
  line-height: 1.7;
}

.message-bubble p:first-child {
  margin-top: 0;
}

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

.message-bubble strong {
  font-weight: 600;
  color: var(--text-primary);
}

.message-bubble em {
  font-style: italic;
  color: var(--text-secondary);
}

.message-bubble code {
  background: rgba(155, 135, 245, 0.1);
  border: 1px solid rgba(155, 135, 245, 0.2);
  padding: 3px 6px;
  border-radius: 6px;
  font-family: 'SF Mono', 'Menlo', 'Monaco', 'Courier New', monospace;
  font-size: 0.9em;
  color: var(--accent-text);
}

.message-bubble pre {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin: 1em 0;
  overflow-x: auto;
}

.message-bubble pre code {
  background: none;
  border: none;
  padding: 0;
  color: var(--text-secondary);
  display: block;
}

.message-bubble ul,
.message-bubble ol {
  margin: 0.8em 0;
  padding-left: 1.5em;
}

.message-bubble li {
  margin: 0.5em 0;
  line-height: 1.7;
}

.message-bubble ul li::marker {
  color: var(--accent-primary);
}

.message-bubble ol li::marker {
  color: var(--accent-primary);
  font-weight: 600;
}

.message-bubble blockquote {
  margin: 1em 0;
  padding: 12px 16px;
  border-left: 3px solid var(--accent-primary);
  background: rgba(155, 135, 245, 0.08);
  border-radius: 0 8px 8px 0;
  font-style: italic;
}

.message-bubble blockquote p {
  margin: 0.5em 0;
}

.message-bubble a {
  color: var(--accent-text);
  text-decoration: none;
  border-bottom: 1px solid rgba(139, 115, 85, 0.3);
  transition: all 0.2s ease;
}

.message-bubble a:hover {
  color: var(--accent-primary);
  border-bottom-color: var(--accent-primary);
}

.message-bubble hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.2em 0;
}

.message-bubble table {
  width: 100%;
  border-collapse: collapse;
  margin: 1em 0;
  font-size: 0.95em;
}

.message-bubble table th,
.message-bubble table td {
  padding: 10px 14px;
  border: 1px solid var(--border);
  text-align: left;
}

.message-bubble table th {
  background: rgba(155, 135, 245, 0.12);
  font-weight: 600;
  color: var(--text-primary);
}

.message-bubble table tr:nth-child(even) {
  background: rgba(106, 93, 82, 0.03);
}

.message-bubble img {
  max-width: 100%;
  height: auto;
  border-radius: 12px;
  margin: 0.6em 0;
}

/* User messages should not render markdown (plain text only) */
.message--user .message-bubble code,
.message--user .message-bubble pre {
  background: rgba(58, 51, 48, 0.08);
  border-color: rgba(58, 51, 48, 0.15);
}

/* Responsive design */
@media (max-width: 768px) {
  .chat-container {
    padding: 0 24px;
  }

  .chat-header {
    padding: 20px 0 18px;
  }

  .header-actions {
    padding: 0 24px;
  }

  .icon-button {
    width: 38px;
    height: 38px;
  }

  .icon-button svg {
    width: 18px;
    height: 18px;
  }

  .welcome-message {
    padding: 0;
    margin-top: 40px;
  }

  .welcome-heading {
    font-size: 28px;
  }

  .message {
    max-width: 82%;
  }

  .message-bubble {
    padding: 14px 18px;
    font-size: 14px;
  }

  .chat-input-container {
    gap: 10px;
    padding: 20px 0 28px;
    margin: 0 -24px;
    padding-left: 24px;
    padding-right: 24px;
  }

  .chat-submit {
    width: 48px;
    height: 48px;
  }
}

@media (max-width: 480px) {
  .chat-container {
    padding: 0 20px;
  }

  .header-actions {
    gap: 10px;
    padding: 0 20px;
  }

  .icon-button {
    width: 36px;
    height: 36px;
  }

  .icon-button svg {
    width: 17px;
    height: 17px;
  }

  .welcome-message {
    padding: 0;
  }

  .welcome-heading {
    font-size: 24px;
  }

  .message {
    max-width: 88%;
  }

  .chat-input-container {
    margin: 0 -20px;
    padding-left: 20px;
    padding-right: 20px;
  }
}
