:root {
  --primary-color: #4f46e5;
  --primary-gradient: linear-gradient(135deg, #4f46e5, #7c3aed);
  --bg-gradient: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
  --glass-bg: rgba(255, 255, 255, 0.85);
  --glass-border: rgba(255, 255, 255, 0.5);
  --text-main: #1f2937;
  --text-muted: #6b7280;
  --shadow-lg: 0 10px 30px -5px rgba(0, 0, 0, 0.1);
  --radius-xl: 24px;
  --radius-lg: 16px;
  --radius-md: 12px;
  font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  line-height: 1.6;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 2rem;
  background: var(--bg-gradient);
  color: var(--text-main);
}

.app-shell {
  width: min(1000px, 100%);
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-xl);
  padding: 2.5rem;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 2rem;
  height: 90vh;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

header h1 {
  margin: 0;
  font-size: 1.8rem;
  background: var(--primary-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  font-weight: 800;
}

header p {
  margin: 0.5rem 0 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

#clear-history {
  border: 1px solid #e5e7eb;
  border-radius: 999px;
  padding: 0.6rem 1.25rem;
  background: white;
  color: var(--text-muted);
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s ease;
  font-size: 0.9rem;
}

#clear-history:hover {
  border-color: var(--primary-color);
  color: var(--primary-color);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  overflow: hidden;
  /* Contain scroll within chat window */
}

#chat-window {
  flex: 1;
  overflow-y: auto;
  padding-right: 1rem;
  /* Space for scrollbar */
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  scroll-behavior: smooth;
}

/* Custom Scrollbar */
#chat-window::-webkit-scrollbar {
  width: 6px;
}

#chat-window::-webkit-scrollbar-track {
  background: transparent;
}

#chat-window::-webkit-scrollbar-thumb {
  background-color: rgba(0, 0, 0, 0.1);
  border-radius: 10px;
}

.chat-bubble {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 1.25rem;
  border-radius: var(--radius-lg);
  max-width: 85%;
  animation: fadeIn 0.3s ease-out forwards;
  position: relative;
  line-height: 1.6;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chat-bubble .role {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.25rem;
}

/* User Bubble */
.chat-bubble.user {
  align-self: flex-end;
  background: white;
  border: 1px solid #e5e7eb;
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.03);
}

.chat-bubble.user .role {
  color: var(--text-muted);
  text-align: right;
}

/* AI Bubble */
.chat-bubble.ai {
  align-self: flex-start;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-bottom-left-radius: 4px;
}

.chat-bubble.ai .role {
  color: var(--primary-color);
}

.message-content {
  white-space: pre-wrap;
  /* Fix markdown newlines */
  font-size: 1rem;
}

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

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

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

/* Recommendations inside bubble */
.recommendations-container {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(0, 0, 0, 0.05);
}

.recommendations-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
  font-weight: 500;
  display: block;
}

.recommendation-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.recommendation-chip {
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 999px;
  padding: 0.5rem 1rem;
  font-size: 0.9rem;
  color: var(--primary-color);
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.02);
}

.recommendation-chip:hover {
  background: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.2);
}

/* Input Area */
form {
  position: relative;
  margin-top: auto;
}

textarea {
  width: 100%;
  resize: none;
  border-radius: var(--radius-lg);
  border: 2px solid #e5e7eb;
  padding: 1rem 4rem 1rem 1.25rem;
  /* Space for button */
  font-size: 1rem;
  font-family: inherit;
  transition: border-color 0.2s;
  background: #f9fafb;
  min-height: 60px;
}

textarea:focus {
  outline: none;
  border-color: var(--primary-color);
  background: white;
}

button[type="submit"] {
  position: absolute;
  right: 10px;
  bottom: 10px;
  border: none;
  border-radius: 999px;
  padding: 0.6rem 1.2rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: white;
  background: var(--primary-gradient);
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
  z-index: 10;
}

button[type="submit"]:hover {
  opacity: 0.95;
}

button[type="submit"]:active {
  transform: scale(0.98);
}

button[disabled] {
  opacity: 0.6;
  cursor: not-allowed;
  background: #9ca3af;
  box-shadow: none;
}

/* Side Panel Recommendations (if used) */
#recommendation-panel {
  display: none;
  /* Hiding the old panel as we moved recs to bubbles */
}

@media (max-width: 640px) {
  body {
    padding: 0;
  }

  .app-shell {
    height: 100vh;
    border-radius: 0;
    padding: 1rem;
  }

  .chat-bubble {
    max-width: 95%;
  }
}