:root {
  --cath-hero-gradient: linear-gradient(135deg, rgba(130,106,237,0.24), rgba(244,198,255,0.52));
  --cath-card-bg: color-mix(in oklab, var(--surface), var(--surface-2) 35%);
  --cath-card-border: color-mix(in oklab, var(--border), var(--primary) 18%);
  --cath-chat-bg: color-mix(in oklab, var(--surface), white 6%);
  --cath-shadow: 0 20px 35px rgba(130, 106, 237, 0.14);
}

body.cath-ai-page {
  background: var(--surface);
  color: var(--text);
  --cath-header-offset: 96px;
}

.cath-ai-page main {
  display: grid;
  gap: clamp(4rem, 7vw, 5.5rem);
  padding-top: var(--cath-header-offset, 96px);
}

.cath-ai-hero {
  position: relative;
  overflow: hidden;
  padding: clamp(6rem, 9vw, 8rem) clamp(1.5rem, 5vw, 5rem);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  align-items: center;
  background: var(--cath-hero-gradient);
  border-bottom-left-radius: 48px;
  border-bottom-right-radius: 48px;
  box-shadow: var(--cath-shadow);
}

.hero-glow {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at top left, rgba(130,106,237,0.32), transparent 60%),
              radial-gradient(circle at 80% 20%, rgba(255,180,212,0.28), transparent 60%);
  opacity: 0.8;
  pointer-events: none;
}

.hero-content {
  position: relative;
  display: grid;
  gap: 1.2rem;
  z-index: 1;
}

.hero-content .eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.3em;
  font-size: 0.78rem;
  font-weight: 600;
  color: color-mix(in oklab, var(--primary), var(--text) 50%);
}

.hero-content h1 {
  font-size: clamp(2.8rem, 6vw, 4.6rem);
  font-family: 'Poppins', 'Inter', sans-serif;
  margin: 0;
}

.hero-content .intro {
  font-size: clamp(1rem, 3vw, 1.2rem);
  max-width: 540px;
  color: color-mix(in oklab, var(--muted), var(--text) 45%);
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.9rem;
  align-items: center;
}

.hero-illustration {
  position: relative;
  width: 100%;
  height: clamp(260px, 30vw, 420px);
}

.orb {
  position: absolute;
  border-radius: 999px;
  filter: blur(0);
}

.orb-1 {
  width: clamp(180px, 25vw, 280px);
  height: clamp(180px, 25vw, 280px);
  background: radial-gradient(circle, rgba(255,196,231,0.8) 0%, rgba(130,106,237,0.2) 70%, transparent 100%);
  top: 12%;
  left: 15%;
}

.orb-2 {
  width: clamp(140px, 22vw, 220px);
  height: clamp(140px, 22vw, 220px);
  background: radial-gradient(circle, rgba(130,106,237,0.75) 0%, rgba(255,255,255,0) 70%);
  bottom: 6%;
  right: 10%;
}

.sparkles::before,
.sparkles::after {
  content: '';
  position: absolute;
  inset: 20% 30%;
  background: radial-gradient(circle, rgba(255,255,255,0.8) 0%, transparent 60%);
  opacity: 0.6;
}

.section.how-it-works {
  padding-top: 0;
}

.section.how-it-works h2 {
  text-align: center;
  margin-bottom: clamp(2rem, 4vw, 3rem);
}

.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: clamp(1.2rem, 3vw, 2rem);
}

.feature-card {
  padding: clamp(1.6rem, 3vw, 2rem);
  border-radius: 20px;
  background: var(--cath-card-bg);
  border: 1px solid var(--cath-card-border);
  box-shadow: var(--shadow-sm);
  display: grid;
  gap: 0.6rem;
}

.feature-card h3 {
  font-size: 1.12rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  color: color-mix(in oklab, var(--primary) 60%, var(--text));
}

.cath-ai-chat {
  padding: 0 clamp(1rem, 4vw, 4rem);
}

.chat-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 0.9fr);
  gap: clamp(2rem, 5vw, 3rem);
  align-items: start;
}

.chat-panel {
  background: var(--cath-chat-bg);
  border-radius: 28px;
  padding: clamp(1.6rem, 3vw, 2.2rem);
  border: 1px solid color-mix(in oklab, var(--border), var(--primary) 12%);
  box-shadow: var(--cath-shadow);
  display: grid;
  gap: 1.4rem;
  max-height: 100%;
}

.chat-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.chat-panel-heading {
  display: grid;
  gap: 0.25rem;
}

.chat-panel-header h2 {
  margin: 0;
  font-size: 1.8rem;
}

.chat-subtitle {
  margin: 0;
  color: color-mix(in oklab, var(--muted), var(--text) 40%);
}

.chat-status {
  min-height: 1.4rem;
  font-size: 0.88rem;
  color: color-mix(in oklab, var(--muted), var(--text) 30%);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.chat-status.has-message {
  opacity: 1;
}

.chat-status[data-tone="success"] {
  color: color-mix(in oklab, #34d399, var(--text) 20%);
}

.chat-status[data-tone="error"] {
  color: color-mix(in oklab, #f43f5e, var(--text) 15%);
}

.chat-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
}

/* Normalize control alignment and heights in toolbar */
.chat-toolbar > * {
  align-self: center;
}

/* On wider screens, place 'Model' label inline with the select for baseline alignment */
@media (min-width: 600px) {
  .chat-toolbar .input-select {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
  }
  .chat-toolbar .input-select span {
    margin: 0;
    line-height: 1;
  }
}

.input-select {
  display: grid;
  gap: 0.3rem;
  font-size: 0.8rem;
  color: color-mix(in oklab, var(--muted), var(--text) 40%);
}

.input-select select {
  padding: 0.55rem 0.8rem;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: inherit;
  height: 40px;
}

.toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.88rem;
  color: color-mix(in oklab, var(--muted), var(--text) 35%);
  min-height: 40px; /* align with select/button height */
}

.toggle input {
  appearance: none;
  width: 42px;
  height: 24px;
  border-radius: 12px;
  background: color-mix(in oklab, var(--border), var(--primary) 15%);
  position: relative;
  cursor: pointer;
  transition: background 0.25s ease;
}

.toggle input:checked {
  background: color-mix(in oklab, var(--primary) 70%, var(--surface));
}

/* Render knob inside the capsule (the input) */
.toggle input::before {
  content: '';
  position: absolute;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--surface);
  top: 2px;
  left: 2px;
  transition: transform 0.25s ease;
  box-shadow: var(--shadow-sm);
}

.toggle input:checked::before {
  transform: translateX(18px);
}

.toggle-label {
  font-weight: 600;
  color: color-mix(in oklab, var(--text), var(--primary) 20%);
}

/* The extra span used previously for the knob is no longer needed */
.toggle .toggle-switch { display: none; }

/* Disabled toggle state (web search not yet available) */
.toggle.disabled,
.toggle input:disabled,
.toggle.disabled .toggle-switch,
.toggle.disabled .toggle-label {
  cursor: not-allowed !important;
}
.toggle input:disabled {
  opacity: 0.6;
}

.btn.ghost {
  background: transparent;
  border: 1px solid color-mix(in oklab, var(--border), var(--primary) 20%);
  border-radius: 16px;
  padding: 0.52rem 1rem;
  display: inline-flex;
  gap: 0.45rem;
  align-items: center;
  font-weight: 600;
  color: color-mix(in oklab, var(--text), var(--primary) 20%);
  min-height: 40px; /* consistent control height */
}

.chat-messages {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 1rem;
  max-height: clamp(320px, 55vh, 520px);
  overflow-y: auto;
  scroll-behavior: smooth;
}

.message {
  display: grid;
  gap: 0.5rem;
  padding: 1rem 1.1rem;
  border-radius: 20px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.message-body {
  white-space: normal;
}

.message-user {
  background: color-mix(in oklab, var(--primary) 26%, var(--surface));
  justify-self: end;
  border-top-right-radius: 6px;
  color: color-mix(in oklab, var(--text), white 15%);
}

.message-assistant {
  background: color-mix(in oklab, var(--surface-2) 25%, transparent);
  border-top-left-radius: 6px;
  border: 1px solid color-mix(in oklab, var(--border), var(--primary) 12%);
  box-shadow: var(--shadow-sm);
}

/* Markdown content styling */
.message-assistant .message-body {
  line-height: 1.68;
}
.message-body p { margin: 0.35rem 0; }
.message-body h1, .message-body h2, .message-body h3 {
  margin: 0.6rem 0 0.35rem;
  line-height: 1.25;
}
.message-body h1 { font-size: 1.5rem; }
.message-body h2 { font-size: 1.28rem; }
.message-body h3 { font-size: 1.12rem; }
.message-body ul, .message-body ol { margin: 0.4rem 0 0.6rem 1.25rem; }
.message-body li { margin: 0.2rem 0; }
.message-body code {
  background: color-mix(in oklab, var(--surface-2), var(--primary) 6%);
  border: 1px solid color-mix(in oklab, var(--border), var(--primary) 16%);
  padding: 0.1rem 0.35rem;
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
}
.message-body pre {
  background: color-mix(in oklab, var(--surface-2), var(--primary) 8%);
  border: 1px solid color-mix(in oklab, var(--border), var(--primary) 20%);
  border-radius: 12px;
  padding: 0.8rem 1rem;
  overflow: auto;
  margin: 0.6rem 0;
}
.message-body pre code { background: transparent; border: 0; padding: 0; }
.message-body blockquote {
  margin: 0.6rem 0;
  padding: 0.6rem 0.9rem;
  border-left: 4px solid color-mix(in oklab, var(--primary), var(--text) 20%);
  background: color-mix(in oklab, var(--surface-2), var(--primary) 6%);
  border-radius: 8px;
}
.message-body a { color: color-mix(in oklab, var(--primary) 70%, var(--text)); text-decoration: underline; }

/* KaTeX math rendering adjustments */
.message-body .katex { font-size: 1.02em; }
.message-body .katex-display { margin: 0.65rem 0; overflow-x: auto; }

.message.assistant-streaming {
  border-style: dashed;
  border-color: color-mix(in oklab, var(--primary) 45%, var(--border));
}

.message small {
  font-size: 0.78rem;
  opacity: 0.66;
}

.chat-form {
  display: grid;
  gap: 0.75rem;
}

.input-group {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 0.8rem;
}

#chat-input {
  width: 100%;
  border-radius: 18px;
  border: 1px solid color-mix(in oklab, var(--border), var(--primary) 10%);
  padding: 0.9rem 1.1rem;
  font: inherit;
  min-height: 52px;
  resize: none;
  background: var(--surface);
}

.input-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.upload {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px dashed color-mix(in oklab, var(--border), var(--primary) 30%);
  color: color-mix(in oklab, var(--text), var(--primary) 25%);
  cursor: pointer;
  transition: border-color 0.2s ease, color 0.2s ease;
}

.upload:hover {
  border-color: color-mix(in oklab, var(--primary) 60%, var(--border));
}

.upload input {
  display: none;
}

.attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.attachment-chip {
  padding: 0.4rem 0.75rem;
  border-radius: 999px;
  background: color-mix(in oklab, var(--surface-2), var(--primary) 10%);
  border: 1px solid color-mix(in oklab, var(--border), var(--primary) 20%);
  font-size: 0.8rem;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.attachment-chip button {
  appearance: none;
  border: none;
  background: transparent;
  color: inherit;
  padding: 0;
  cursor: pointer;
}

.side-panel {
  display: grid;
  gap: 1.6rem;
}

.side-card {
  background: var(--cath-card-bg);
  border-radius: 24px;
  border: 1px solid var(--cath-card-border);
  padding: clamp(1.4rem, 3vw, 1.9rem);
  box-shadow: var(--shadow-sm);
  display: grid;
  gap: 1rem;
}

.prompt-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 0.75rem;
}

.prompt-list li {
  padding: 0.8rem 1rem;
  background: color-mix(in oklab, var(--surface-2), white 4%);
  border-radius: 16px;
  border: 1px solid color-mix(in oklab, var(--border), var(--primary) 18%);
  cursor: pointer;
  transition: border-color 0.2s ease, transform 0.2s ease;
}

.prompt-list li:hover,
.prompt-list li:focus-visible {
  border-color: color-mix(in oklab, var(--primary) 55%, var(--border));
  transform: translateY(-2px);
}

.info-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 0.7rem;
}

.info-list li {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  color: color-mix(in oklab, var(--muted), var(--text) 45%);
}

.info-list i {
  color: color-mix(in oklab, var(--primary), var(--text) 30%);
}

.section.tips h2 {
  text-align: center;
  margin-bottom: clamp(1.6rem, 4vw, 2.4rem);
}

.tips-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: clamp(1.2rem, 3vw, 2.2rem);
}

.tip {
  background: var(--cath-card-bg);
  border-radius: 20px;
  padding: clamp(1.3rem, 3vw, 1.8rem);
  border: 1px solid var(--cath-card-border);
  box-shadow: var(--shadow-sm);
}

.mini-footer {
  padding: 2rem 1rem 3rem;
  text-align: center;
  background: transparent;
  color: color-mix(in oklab, var(--muted), var(--text) 40%);
}

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

  .side-panel {
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  }
}

@media (max-width: 720px) {
  .cath-ai-hero {
    grid-template-columns: 1fr;
    border-bottom-left-radius: 32px;
    border-bottom-right-radius: 32px;
    padding: clamp(4.5rem, 10vw, 6rem) clamp(1.2rem, 5vw, 2.5rem);
  }

  .hero-illustration {
    display: none;
  }

  .chat-panel {
    border-radius: 20px;
  }

  .input-group {
    grid-template-columns: 1fr;
  }

  .input-actions {
    justify-content: flex-end;
  }
}

@media (max-width: 480px) {
  .feature-card,
  .side-card,
  .tip {
    border-radius: 16px;
  }

  .chat-messages {
    max-height: 60vh;
  }
}

:root[data-theme="dark"] body.cath-ai-page {
  background: color-mix(in oklab, var(--surface), rgba(15,23,42,0.35));
}

:root[data-theme="dark"] .feature-card,
:root[data-theme="dark"] .side-card,
:root[data-theme="dark"] .tip {
  background: color-mix(in oklab, var(--surface), rgba(130,106,237,0.12));
  border-color: color-mix(in oklab, var(--border), rgba(130,106,237,0.32));
}

:root[data-theme="dark"] .chat-panel {
  background: color-mix(in oklab, var(--surface), rgba(130,106,237,0.1));
  border-color: color-mix(in oklab, var(--border), rgba(130,106,237,0.26));
}

:root[data-theme="dark"] .message-user {
  color: white;
}

/* --- Dark theme contrast tuning for readability --- */
:root[data-theme="dark"] .hero-content .intro {
  color: #cfd7ee; /* increase contrast on hero intro text */
}

:root[data-theme="dark"] .chat-status {
  color: #b8c4e6; /* clearer status text */
}
:root[data-theme="dark"] .chat-status[data-tone="success"] {
  color: #7be6b1;
}
:root[data-theme="dark"] .chat-status[data-tone="error"] {
  color: #ff8097;
}

:root[data-theme="dark"] .input-select {
  color: #cfd7ee;
}
:root[data-theme="dark"] .input-select select {
  background: #0f1218;
  border-color: #2b2f3a;
  color: #e6edff;
}

:root[data-theme="dark"] .toggle {
  color: #c7d1ef;
}
:root[data-theme="dark"] .toggle input {
  background: #2a2f3a;
}
:root[data-theme="dark"] .toggle input:checked {
  background: linear-gradient(135deg, #7a66e9, #9a86ff);
}
:root[data-theme="dark"] .toggle-label {
  color: #e0e7ff;
}

:root[data-theme="dark"] .btn.ghost {
  color: #e0e7ff;
  border-color: #424a61;
}

:root[data-theme="dark"] .prompt-list li {
  background: rgba(148,163,184,0.08);
  border-color: #3a4157;
  color: #d9e2ff;
}

:root[data-theme="dark"] .message-assistant {
  color: #e8eeff; /* ensure assistant text is bright */
  border-color: #3d4460;
}
:root[data-theme="dark"] .message-body code {
  background: rgba(148,163,184,0.12);
  border-color: #4a516b;
}
:root[data-theme="dark"] .message-body pre {
  background: rgba(12,16,28,0.9);
  border-color: #3d4460;
}
:root[data-theme="dark"] .message-body a {
  color: #a9b8ff;
}

:root[data-theme="dark"] .info-list li {
  color: #c7d1ef;
}
:root[data-theme="dark"] .info-list i {
  color: #a9b8ff;
}
