:root {
  --bg: #FFF8F4;
  --bg-panel: rgba(255, 253, 250, 0.93);
  --bg-panel-strong: #FFEEE8;
  --text: #2D1740;
  --text-muted: #9B82B2;
  --accent: #FF8577;
  --accent-2: #E55C6C;
  --border: rgba(229, 170, 160, 0.28);
  --danger: #D94F62;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(ellipse 1000px 600px at 10% 0%, rgba(255, 210, 198, 0.55) 0%, transparent 60%),
    radial-gradient(ellipse 800px 700px at 90% 95%, rgba(214, 190, 255, 0.45) 0%, transparent 60%),
    linear-gradient(180deg, #FFF8F4 0%, #FFFAF8 100%);
  font-family: "Plus Jakarta Sans", sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
}

.bg-glow {
  position: fixed;
  z-index: -1;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.45;
  pointer-events: none;
}

.bg-glow-a {
  width: 420px;
  height: 420px;
  top: -100px;
  right: -90px;
  background: #FFCCC0;
}

.bg-glow-b {
  width: 360px;
  height: 360px;
  left: -80px;
  bottom: -110px;
  background: #D4BCFF;
}

.page {
  width: min(1200px, 92vw);
  margin: 42px auto 56px;
}

.topbar {
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 20px;
}

.topbar-eyebrow {
  font-size: 0.65rem;
  margin-bottom: 3px;
}

.user-email {
  margin: 0;
  font-family: "IBM Plex Mono", "Menlo", monospace;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.hero {
  animation: rise 500ms ease;
}

.eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--accent);
  font-size: 0.77rem;
  font-family: "IBM Plex Mono", "Menlo", monospace;
}

h1, h2, h3 {
  font-family: "Epilogue", sans-serif;
}

h1 {
  margin: 8px 0 12px;
  font-size: clamp(2.2rem, 3.6vw, 3.2rem);
  line-height: 1.05;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.subtitle {
  margin: 0;
  max-width: 760px;
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1.5;
}

.grid {
  margin-top: 30px;
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  gap: 20px;
  align-items: start;
}

.card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  backdrop-filter: blur(12px);
  box-shadow: 0 16px 34px rgba(126, 100, 190, 0.17);
}

.form-card {
  padding: 20px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  animation: rise 650ms ease;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field.full {
  grid-column: 1 / -1;
}

.thread-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
}

.thread-row .secondary-btn {
  height: 42px;
  padding: 0 14px;
}

label {
  font-size: 0.88rem;
  color: var(--text-muted);
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  color: var(--text);
  background: var(--bg-panel-strong);
  font-family: inherit;
  font-size: 0.95rem;
}

textarea {
  resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(141, 107, 232, 0.2);
}

.primary-btn {
  border: none;
  border-radius: 999px;
  padding: 13px 16px;
  background: linear-gradient(135deg, #FF8577 0%, #FFB5A0 100%);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  transition: transform 140ms ease, opacity 140ms ease, box-shadow 140ms ease;
  box-shadow: 0 4px 16px rgba(255, 133, 119, 0.3);
}

.primary-btn:hover {
  transform: translateY(-1px);
}

.primary-btn:disabled {
  opacity: 0.75;
  cursor: wait;
}

.form-card .primary-btn {
  grid-column: 1 / -1;
  margin-top: 4px;
}

.secondary-btn {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 999px;
  padding: 10px 14px;
  font-weight: 600;
  cursor: pointer;
}

.secondary-btn:hover {
  background: #f8f2ff;
}

.secondary-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Icon Buttons */
.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  min-width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 150ms ease;
  font-size: 1.1rem;
}

.icon-btn:hover:not(:disabled) {
  background: var(--surface);
  border-color: #a496b8;
}

.icon-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.answer-card {
  padding: 20px;
  animation: rise 800ms ease;
}

.answer-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

h2 {
  margin: 0;
  font-size: 1.25rem;
}

#status {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.82rem;
  font-family: "IBM Plex Mono", "Menlo", monospace;
}

#status.error {
  color: var(--danger);
}

.chat-container {
  margin: 0;
  min-height: 480px;
  max-height: 74vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding-right: 8px;
  /* For scrollbar breathing room */
}

/* Custom Scrollbar for Chat */
.chat-container::-webkit-scrollbar {
  width: 6px;
}

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

.chat-container::-webkit-scrollbar-thumb {
  background-color: rgba(183, 148, 255, 0.3);
  border-radius: 10px;
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  margin-top: 40px;
  font-family: "IBM Plex Mono", "Menlo", monospace;
  font-size: 0.9rem;
}

.empty-state.error {
  color: var(--danger);
  background: rgba(185, 65, 102, 0.08);
  padding: 12px;
  border-radius: 8px;
}

/* Chat Input Bar */
.chat-form {
  display: flex;
  gap: 12px;
  margin-top: 0;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  animation: rise 300ms ease;
}

.chat-form input,
.chat-form textarea {
  flex-grow: 1;
  border-radius: 16px;
  padding: 14px 20px;
  font-size: 1rem;
  resize: none;
  overflow: hidden;
  min-height: 52px;
  max-height: 220px;
  line-height: 1.5;
  overflow-y: auto;
}

.chat-form button {
  padding: 0 24px;
}

.hidden {
  display: none !important;
}

/* Header link profile */
.profile-link {
  text-decoration: none;
  font-weight: 500;
  transition: color 150ms ease;
}

.profile-link:hover {
  color: var(--accent-2);
}

/* Chat Bubbles Base */
.msg-wrapper {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  animation: rise 300ms ease;
}

.msg-label {
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 6px;
  font-family: "IBM Plex Mono", "Menlo", monospace;
}

.msg-bubble {
  padding: 16px 20px;
  border-radius: 16px;
  font-size: 0.96rem;
  line-height: 1.6;
  color: var(--text);
  word-wrap: break-word;
}

/* User Message Styles */
.msg-user {
  align-self: flex-end;
}

.msg-user .msg-label {
  text-align: right;
}

.msg-user .msg-bubble {
  background: linear-gradient(135deg, #FF8577, #FFB5A0);
  color: #fff;
  border-end-end-radius: 4px;
  box-shadow: 0 4px 14px rgba(255, 133, 119, 0.28);
  font-weight: 600;
}

/* Assistant Message Styles */
.msg-assistant {
  align-self: flex-start;
}

.msg-assistant .msg-bubble {
  background: #FFFAF7;
  border: 1px solid rgba(229, 170, 160, 0.22);
  border-end-start-radius: 4px;
  box-shadow: 0 4px 18px rgba(210, 150, 140, 0.09);
}

/* Markdown Scoped Typography */
.msg-assistant .msg-bubble h1,
.msg-assistant .msg-bubble h2,
.msg-assistant .msg-bubble h3 {
  margin-top: 0;
  margin-bottom: 12px;
  color: var(--text);
  line-height: 1.3;
}

.msg-assistant .msg-bubble h1 {
  font-size: 1.6rem;
}

.msg-assistant .msg-bubble h2 {
  font-size: 1.4rem;
  border-bottom: 1px solid rgba(122, 95, 196, 0.1);
  padding-bottom: 6px;
  margin-top: 24px;
}

.msg-assistant .msg-bubble h2:first-child {
  margin-top: 0;
}

.msg-assistant .msg-bubble h3 {
  font-size: 1.15rem;
  color: var(--accent-2);
  margin-top: 20px;
}

.msg-assistant .msg-bubble p {
  margin-top: 0;
  margin-bottom: 16px;
}

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

.msg-assistant .msg-bubble ul,
.msg-assistant .msg-bubble ol {
  margin-top: 0;
  margin-bottom: 16px;
  padding-left: 24px;
}

.msg-assistant .msg-bubble li {
  margin-bottom: 6px;
}

.msg-assistant .msg-bubble strong {
  font-weight: 700;
  color: #1a102b;
}

.msg-assistant .msg-bubble code {
  font-family: "IBM Plex Mono", "SF Mono", "Menlo", monospace;
  background: rgba(183, 148, 255, 0.15);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.85em;
  color: var(--accent-2);
}

.msg-assistant .msg-bubble pre {
  background: #1a102b;
  border-radius: 10px;
  padding: 16px;
  overflow-x: auto;
  margin-bottom: 16px;
}

.msg-assistant .msg-bubble pre code {
  color: #e7d7ff;
  background: transparent;
  padding: 0;
  font-size: 0.85rem;
}

.auth-body {
  display: grid;
  place-items: center;
  min-height: 100vh;
}

.auth-page {
  width: min(980px, 94vw);
  margin: 32px auto;
}

.auth-card {
  padding: 24px;
}

.auth-status {
  margin: 14px 0 6px;
  font-size: 0.88rem;
  color: var(--text-muted);
  min-height: 1.2em;
}

.auth-status.error {
  color: var(--danger);
}

.auth-toggle-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 10px;
  margin-bottom: 12px;
}

.auth-toggle {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  color: var(--text);
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
}

.auth-toggle.active {
  background: linear-gradient(90deg, var(--accent), #d9c5ff);
  border-color: rgba(141, 107, 232, 0.45);
  color: #2a1b47;
}

.auth-toggle:disabled {
  opacity: 0.72;
  cursor: not-allowed;
}

.auth-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 10px;
}

.auth-form {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.75);
  display: grid;
  gap: 8px;
  align-content: start;
}

.auth-panel.hidden {
  display: none;
}

.auth-form h2 {
  margin: 0 0 6px;
}

.auth-form .primary-btn {
  margin-top: 8px;
}

.auth-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 18px 0 12px;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.auth-divider span {
  padding: 0 10px;
  position: relative;
}

.auth-divider span::before,
.auth-divider span::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 80px;
  height: 1px;
  background: var(--border);
}

.auth-divider span::before {
  right: 100%;
}

.auth-divider span::after {
  left: 100%;
}

.google-btn {
  appearance: none;
  display: block;
  width: 100%;
  text-align: center;
  text-decoration: none;
  border-radius: 999px;
  padding: 12px 16px;
  background: #fff;
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 700;
}

.google-btn:hover {
  background: #f8f2ff;
}

.google-btn.disabled {
  pointer-events: none;
  opacity: 0.62;
}

.hint {
  margin: 10px 0 0;
  color: var(--text-muted);
  font-size: 0.82rem;
}

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

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

@media (max-width: 980px) {
  .grid {
    grid-template-columns: 1fr;
  }

  #answer {
    min-height: 320px;
  }

  .auth-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .page {
    width: min(1200px, 94vw);
    margin: 26px auto 40px;
  }

  .form-card {
    grid-template-columns: 1fr;
  }

  .thread-row {
    grid-template-columns: 1fr;
  }
}

/* ─── Projects Grid ─────────────────────────────────────── */

.projects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-top: 32px;
}

.project-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 24px 20px;
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease;
  display: flex;
  flex-direction: column;
  gap: 8px;
  backdrop-filter: blur(12px);
  box-shadow: 0 8px 24px rgba(210, 150, 140, 0.08);
  animation: rise 400ms ease;
}

.project-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 18px 38px rgba(255, 133, 119, 0.18);
}

.project-card-new {
  border: 2px dashed rgba(255, 133, 119, 0.35);
  background: rgba(255, 140, 127, 0.05);
  color: var(--accent);
}

.project-card-new:hover {
  border-color: var(--accent);
  background: rgba(255, 140, 127, 0.1);
}

.project-card-icon {
  font-size: 1.8rem;
  line-height: 1;
}

.project-card-name {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
  line-height: 1.3;
}

.project-card-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-family: "IBM Plex Mono", monospace;
}

.project-card-empty {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.92rem;
  padding: 24px;
}

.new-project-form {
  max-width: 560px;
  margin-top: 32px;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: rise 350ms ease;
}

/* ─── Chat Page Layout ───────────────────────────────────── */

.chat-page {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

.conversations-sidebar {
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow: hidden;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-top {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.back-link {
  font-size: 0.82rem;
  color: var(--text-muted);
  text-decoration: none;
  font-family: "IBM Plex Mono", monospace;
  transition: color 140ms ease;
}

.back-link:hover {
  color: var(--accent-2);
}

.project-title {
  margin: 0;
  font-size: 1.1rem;
  font-family: "Fraunces", Georgia, serif;
  font-style: italic;
  color: var(--text);
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.new-conv-btn {
  border: none;
  border-radius: 999px;
  padding: 10px 14px;
  background: linear-gradient(135deg, #FF8577 0%, #FFB5A0 100%);
  color: #fff;
  font-weight: 700;
  font-size: 0.88rem;
  cursor: pointer;
  font-family: inherit;
  transition: transform 140ms ease, box-shadow 140ms ease;
  box-shadow: 0 4px 14px rgba(255, 133, 119, 0.28);
  text-align: center;
}

.new-conv-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(255, 133, 119, 0.38);
}

.conversations-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
  flex: 1;
}

.conversations-list::-webkit-scrollbar {
  width: 4px;
}

.conversations-list::-webkit-scrollbar-thumb {
  background-color: rgba(255, 133, 119, 0.2);
  border-radius: 10px;
}

.conv-item {
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 12px;
  cursor: pointer;
  font-size: 0.86rem;
  color: var(--text);
  font-family: inherit;
  transition: all 150ms ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
}

.conv-item:hover {
  background: var(--bg-panel-strong);
  border-color: var(--border);
}

.conv-item.active {
  background: linear-gradient(135deg, rgba(255, 133, 119, 0.13), rgba(255, 181, 160, 0.08));
  border-color: rgba(255, 133, 119, 0.28);
  font-weight: 700;
  color: var(--accent-2);
}

.conv-empty {
  font-size: 0.84rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: 16px;
  font-family: "IBM Plex Mono", monospace;
}

.sidebar-footer {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.sidebar-user {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-family: "IBM Plex Mono", monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.logout-link {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.78rem;
  cursor: pointer;
  text-align: left;
  padding: 0;
  font-family: inherit;
  transition: color 140ms ease;
}

.logout-link:hover {
  color: var(--danger);
}

.chat-main {
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 28px 32px 24px;
  background:
    radial-gradient(ellipse 800px 500px at 80% 10%, rgba(255, 210, 198, 0.3) 0%, transparent 60%),
    #FFF9F6;
}

.chat-main .chat-container {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.chat-main .chat-form {
  margin-top: 0;
}

@media (max-width: 768px) {
  .chat-page {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .conversations-sidebar {
    position: static;
    height: auto;
    max-height: 220px;
    overflow-y: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .chat-main {
    height: calc(100vh - 220px);
  }
}

/* ─── Chat Welcome Screen ───────────────────────────────── */

.chat-main.welcome-mode {
  background:
    radial-gradient(ellipse 900px 500px at 60% 30%, rgba(255, 210, 198, 0.25) 0%, transparent 60%),
    #FFF9F6;
}

.chat-main.welcome-mode .chat-container {
  overflow: visible;
  justify-content: center;
}

.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  min-height: 100%;
  width: 100%;
  text-align: center;
  padding: 0;
  gap: 0;
}

.welcome-cloud {
  width: calc(100% + 80px);
  margin: 0 -40px;
  height: 80px;
  background: rgba(236, 224, 205, 0.65);
  flex-shrink: 0;
}

.welcome-cloud-top {
  border-radius: 0 0 50% 50% / 0 0 40px 40px;
}

.welcome-cloud-bottom {
  border-radius: 50% 50% 0 0 / 40px 40px 0 0;
}

.welcome-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 40px 24px 24px;
  flex: 1;
  justify-content: center;
}

.welcome-heading {
  font-family: "Nunito", sans-serif;
  font-weight: 900;
  font-style: normal;
  font-size: clamp(3.5rem, 8vw, 6rem);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #C084FC;
  margin: 0;
  line-height: 1;
}

.welcome-tagline {
  font-family: "Fraunces", Georgia, serif;
  font-style: italic;
  font-size: clamp(1.1rem, 2.5vw, 1.5rem);
  color: #F59E0B;
  margin: 0;
  font-weight: 400;
}

.welcome-prompts {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  padding: 0 24px 40px;
}

.prompt-pill {
  background: rgba(255, 255, 255, 0.75);
  border: 1.5px solid rgba(192, 132, 252, 0.28);
  border-radius: 999px;
  padding: 10px 20px;
  font-size: 0.88rem;
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  transition: all 160ms ease;
  backdrop-filter: blur(4px);
  box-shadow: 0 2px 12px rgba(192, 132, 252, 0.1);
}

.prompt-pill:hover {
  background: rgba(192, 132, 252, 0.12);
  border-color: rgba(192, 132, 252, 0.5);
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(192, 132, 252, 0.18);
}

