/* ═══════════════════════════════════════════════════════════════
   Corveris Chat — Dual-Theme System
   v2026-03-06u  |  light · dark · follow-system
   Served from: public/theme.css (root-level, Chainlit 2.9.6)

   Chainlit adds html.dark or html.light CSS class.
   We key all dark overrides on html.dark to match.
═══════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Fraunces:ital,opsz,wght@0,9..144,400;0,9..144,600;0,9..144,700;1,9..144,500&family=Inter:wght@400;500;600;700&display=swap');

/* ── Light theme tokens (default) ──────────────────────────── */
:root {
  /* Palette */
  --bg:           #F6F1EA;
  --surface:      #FFFFFF;
  --surface2:     #FAF8F5;
  --text:         #111114;
  --muted:        #6B6F76;
  --placeholder:  #9AA0A6;
  --border:       rgba(17,17,20,.07);
  --border-med:   rgba(17,17,20,.14);
  /* Shadows */
  --shadow-card:  0 6px 16px rgba(0,0,0,.04);
  --shadow-input: 0 8px 30px rgba(17,17,20,.06);
  /* Accent */
  --accent:       #E83F6F;
  --accentDark:   #D93663;
  --accentSoft:   rgba(232,63,111,.10);
  /* Component tokens */
  --header-bg:    rgba(246,241,234,.82);
  --icon-bg:      rgba(0,0,0,.035);
  --icon-color:   rgba(0,0,0,.55);
  --input-border: rgba(0,0,0,.06);
  --send-idle:    rgba(0,0,0,.05);
  --send-idle-fg: #6B6F76;
  --eyebrow-color:rgba(17,17,20,.75);
  /* Shape */
  --radius:       20px;
  --radiusSm:     14px;
  --r-icon:       14px;
  /* Typography */
  --font-ui:      "Inter", ui-sans-serif, -apple-system, BlinkMacSystemFont,
                  "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-disp:    "Fraunces", "Playfair Display", ui-serif, Georgia, serif;
  /* Layout */
  --w-center:     660px;
  --header-h:     56px;
}

/* ── Dark theme token overrides ─────────────────────────────── */
html.dark {
  --bg:           #0F1115;
  --surface:      #161A20;
  --surface2:     #1C2028;
  --text:         #ECEFF4;
  --muted:        #A6ACB6;
  --placeholder:  #6B7280;
  --border:       rgba(255,255,255,.08);
  --border-med:   rgba(255,255,255,.14);
  --shadow-card:  0 6px 16px rgba(0,0,0,.30);
  --shadow-input: 0 8px 30px rgba(0,0,0,.30);
  --accentSoft:   rgba(232,63,111,.18);
  --header-bg:    rgba(15,17,21,.90);
  --icon-bg:      rgba(255,255,255,.07);
  --icon-color:   rgba(255,255,255,.55);
  --input-border: rgba(255,255,255,.10);
  --send-idle:    rgba(255,255,255,.08);
  --send-idle-fg: #A6ACB6;
  --eyebrow-color:rgba(255,255,255,.60);
  color-scheme: dark;
}

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

html, body {
  margin: 0; padding: 0;
  overflow: hidden;
  scrollbar-width: none;
  -ms-overflow-style: none;
  background:
    radial-gradient(900px 500px at 50% 0%, rgba(232,63,111,.05), transparent 55%),
    linear-gradient(180deg, #F6F1EA 0%, #F7F3EE 60%, #F6F1EA 100%) !important;
  background-attachment: fixed !important;
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

/* Dark body background */
html.dark, html.dark body {
  background:
    radial-gradient(900px 500px at 50% 0%, rgba(232,63,111,.07), transparent 55%),
    linear-gradient(180deg, #0F1115 0%, #111519 60%, #0F1115 100%) !important;
  background-attachment: fixed !important;
}

html::-webkit-scrollbar, body::-webkit-scrollbar { display: none; }
#root, main { background: transparent !important; overflow-x: hidden; }
main, #root > div, #root > div > div { background: transparent !important; }

/* ── Suppress Chainlit branding + old starters ─────────────── */
a[href*="chainlit"], img[alt*="Chainlit"], img[src*="chainlit"],
[data-testid*="chainlit"], #readme-button,
#starters, [data-testid="starters"], button[class*="starter"] {
  display: none !important;
}

/* ── Header — FIXED, always on top ────────────────────────── */
#header, header, [data-testid="header"], .MuiAppBar-root {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  width: 100% !important;
  z-index: 500 !important;
  height: var(--header-h) !important;
  min-height: var(--header-h) !important;
  background: var(--header-bg) !important;
  backdrop-filter: blur(14px) saturate(160%) !important;
  -webkit-backdrop-filter: blur(14px) saturate(160%) !important;
  border-bottom: 1px solid var(--border) !important;
  box-shadow: none !important;
  padding: 0 14px !important;
  display: flex !important;
  align-items: center !important;
}

/* Header spacer pushed in by JS to offset fixed header */
#cv-header-spacer {
  display: block !important;
  height: var(--header-h);
  width: 100%;
  flex-shrink: 0;
  pointer-events: none;
}

#header button, header button, [data-testid="header"] button {
  width: 40px !important;
  height: 40px !important;
  min-width: 40px !important;
  flex-shrink: 0 !important;
  border-radius: var(--radiusSm) !important;
  border: 1px solid var(--border-med) !important;
  background: var(--surface) !important;
  color: var(--muted) !important;
  padding: 0 !important;
  box-shadow: var(--shadow-card) !important;
  transition: border-color 120ms, background 120ms;
}

#header button:hover, header button:hover {
  border-color: var(--border-med) !important;
  background: var(--surface2) !important;
}

#header svg, header svg { width: 16px !important; height: 16px !important; }

/* Wordmark is a body-level fixed element — immune to header re-renders */
.cv-wordmark {
  position: fixed !important;
  top: calc(var(--header-h, 56px) / 2) !important;
  left: 62px !important;
  transform: translateY(-50%) !important;
  z-index: 600 !important;
  font-family: var(--font-ui) !important;
  font-size: 16px !important;
  font-weight: 700 !important;
  letter-spacing: -0.02em !important;
  color: #111114 !important;
  white-space: nowrap !important;
  pointer-events: none !important;
  user-select: none !important;
  -webkit-user-select: none !important;
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
}
html.dark .cv-wordmark {
  color: #ECEFF4 !important;
}

/* ── Theme dropdown checkmark ───────────────────────────────── */
.cv-theme-check {
  margin-left: auto;
  padding-left: 10px;
  color: var(--accent);
  font-size: 14px;
  line-height: 1;
  flex-shrink: 0;
}

/* ── Welcome / Hero screen ─────────────────────────────────── */
#welcome-screen, [data-testid="readme"], section[class*="readme"] {
  width: min(var(--w-center), calc(100vw - 24px)) !important;
  max-width: var(--w-center) !important;
  margin: 0 auto !important;
  padding: 32px 20px 28px !important;
  background: transparent !important;
  border: 0 !important;
  box-shadow: none !important;
}

#welcome-screen img, [data-testid="readme"] img {
  width: 44px !important;
  height: 44px !important;
  object-fit: contain !important;
  display: block !important;
  margin: 0 auto 18px !important;
}

#welcome-screen h1:not(.cv-hero-h1),
#welcome-screen h2:not(.cv-hero-h1),
#welcome-screen p:not(.cv-hero-sub),
[data-testid="readme"] h1:not(.cv-hero-h1),
[data-testid="readme"] p:not(.cv-hero-sub),
#welcome-screen ul, [data-testid="readme"] ul { display: none !important; }

/* ── Hero eyebrow label ────────────────────────────────────── */
.cv-hero-eyebrow {
  display: block;
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--eyebrow-color);
  text-align: center;
  margin: 0 auto 8px;
}

/* ── Hero headline — upright display serif ─────────────────── */
.cv-hero-h1 {
  font-family: var(--font-disp);
  font-style: normal;
  font-size: 36px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.05;
  color: var(--text);
  text-align: center;
  margin: 0 0 18px;
}

.cv-hero-sub {
  font-family: var(--font-ui);
  font-size: clamp(14px, 2vw, 16px);
  font-weight: 400;
  line-height: 1.6;
  color: var(--muted);
  text-align: center;
  max-width: min(420px, 100%);
  margin: 0 auto 32px;
}

/* ── Decorative feature cards ──────────────────────────────── */
.cv-cards {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 18px;
  margin: 0 0 22px;
}

.cv-dec-card {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  cursor: default;
  user-select: none;
  -webkit-user-select: none;
  min-height: 72px;
  transition: transform 150ms ease, box-shadow 150ms ease;
}

.cv-dec-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(0,0,0,.08);
}

.cv-dec-card:active {
  transform: translateY(0);
  box-shadow: var(--shadow-card);
}

.cv-dec-icon {
  flex-shrink: 0;
  width: 44px; height: 44px; min-width: 44px;
  border-radius: var(--r-icon);
  background: var(--icon-bg);
  display: flex; align-items: center; justify-content: center;
  color: var(--icon-color);
}

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

.cv-dec-text {
  flex: 1 1 0; min-width: 0;
  display: flex; flex-direction: column; gap: 2px;
}

.cv-dec-title {
  font-size: 15px; font-weight: 600; line-height: 1.3;
  color: var(--text); display: block;
}

.cv-dec-sub {
  font-size: 13px; font-weight: 400; line-height: 1.4;
  color: var(--muted); display: block;
}

/* ── Chat outer bar ─────────────────────────────────────────── */
[data-testid="chat-input-bar"],
[data-testid="chat-footer"] {
  background: transparent !important;
  display: flex !important;
  justify-content: center !important;
  padding: 8px 12px calc(12px + env(safe-area-inset-bottom, 0px)) !important;
  width: 100% !important;
  box-shadow: none !important;
  border: none !important;
}

/* ── Chat composer ─────────────────────────────────────────── */
#message-composer,
[data-testid="chat-input-container"],
form:has([data-testid="chat-input"]),
div:has(> [data-testid="chat-input"]) {
  width: min(628px, calc(100vw - 56px)) !important;
  max-width: 628px !important;
  margin: 0 auto !important;
  margin-bottom: 0 !important;
  display: flex !important;
  flex-direction: row !important;
  align-items: flex-end !important;
  flex-wrap: nowrap !important;
  gap: 8px !important;
  background: var(--surface) !important;
  border: 1px solid var(--input-border) !important;
  border-radius: var(--radius) !important;
  box-shadow: var(--shadow-input) !important;
  padding: 10px 10px 10px 16px !important;
  min-height: 60px !important;
  transition: border-color 150ms, box-shadow 150ms;
}

#message-composer:focus-within,
[data-testid="chat-input-container"]:focus-within {
  border-color: #E83F6F !important;
  box-shadow: var(--shadow-input), 0 0 0 3px rgba(232,63,111,.12) !important;
}

#message-composer > div,
[data-testid="chat-input-container"] > div {
  flex: 1 1 auto !important;
  min-width: 0 !important;
}

/* Textarea */
#message-composer textarea,
[data-testid="chat-input-container"] textarea,
#chat-input,
textarea#chat-input,
[data-testid="chat-input"],
textarea[data-testid="chat-input"] {
  width: 100% !important;
  min-width: 0 !important;
  writing-mode: horizontal-tb !important;
  direction: ltr !important;
  white-space: pre-wrap !important;
  word-break: break-word !important;
  overflow-wrap: break-word !important;
  min-height: 38px !important;
  max-height: 200px !important;
  border: none !important;
  outline: none !important;
  background: transparent !important;
  color: var(--text) !important;
  font-family: var(--font-ui) !important;
  font-size: 16px !important;
  line-height: 1.5 !important;
  padding: 2px 0 !important;
  resize: none !important;
  box-shadow: none !important;
  display: block !important;
  overflow-y: auto;
}

#message-composer textarea::placeholder,
[data-testid="chat-input-container"] textarea::placeholder,
[data-testid="chat-input"]::placeholder,
textarea[data-testid="chat-input"]::placeholder {
  color: var(--placeholder) !important;
  font-size: 16px !important;
  opacity: 1 !important;
}

/* ── Upload / non-send controls — hide everything except send+stop ── */
input[type="file"],
#upload-button-input,
[data-testid="upload-button-input"],
[data-testid="upload-button"],
#ask-button-input,
#chat-settings-open-modal,
#message-composer label,
[data-testid="chat-input-container"] label,
[data-testid="chat-input-container"] .MuiChip-root { display: none !important; }

/* Hide any non-send/stop button inside composer */
[data-testid="chat-input-container"] button:not([data-testid="send-button"]):not([data-testid="submit-button"]):not(button[aria-label*="Send" i]):not(#stop-button):not([data-testid="stop-button"]),
#message-composer button:not([data-testid="send-button"]):not([data-testid="submit-button"]):not(button[aria-label*="Send" i]):not(#stop-button):not([data-testid="stop-button"]) {
  display: none !important;
}

/* Stop button (streaming) */
#stop-button {
  flex: 0 0 40px !important;
  width: 40px !important;
  height: 40px !important;
  min-width: 40px !important;
  border-radius: var(--radiusSm) !important;
  border: 1px solid var(--border) !important;
  background: var(--surface2) !important;
  color: var(--muted) !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  padding: 0 !important;
}

/* ── Send button — ALWAYS visible, crimson when active ──────── */
#chat-submit,
[data-testid="send-button"],
[data-testid="submit-button"],
button[aria-label="Send message"],
button[aria-label="Send"],
[data-testid="chat-input-container"] button[type="submit"] {
  display: inline-flex !important;
  visibility: visible !important;
  opacity: 1 !important;
  flex: 0 0 40px !important;
  width: 40px !important;
  height: 40px !important;
  min-width: 40px !important;
  max-width: 40px !important;
  border-radius: var(--radiusSm) !important;
  border: none !important;
  align-items: center !important;
  justify-content: center !important;
  padding: 0 !important;
  cursor: pointer !important;
  transition: background-color 150ms ease, transform 150ms ease !important;
  background: var(--accent) !important;
  color: #fff !important;
}

/* Idle/disabled */
#chat-submit:disabled,
[data-testid="send-button"]:disabled,
[data-testid="submit-button"]:disabled,
button[aria-label="Send message"]:disabled,
button[aria-label="Send"]:disabled,
[data-testid="chat-input-container"] button[type="submit"]:disabled {
  background: var(--send-idle) !important;
  color: var(--send-idle-fg) !important;
  cursor: default !important;
}

#chat-submit:not(:disabled):hover,
[data-testid="send-button"]:not(:disabled):hover,
button[aria-label="Send message"]:not(:disabled):hover,
[data-testid="chat-input-container"] button[type="submit"]:not(:disabled):hover {
  background: var(--accentDark) !important;
}

#chat-submit:active,
[data-testid="send-button"]:active,
button[aria-label="Send message"]:active { transform: scale(0.96) !important; }

#chat-submit svg,
[data-testid="send-button"] svg,
[data-testid="submit-button"] svg,
button[aria-label="Send message"] svg,
button[aria-label="Send"] svg,
[data-testid="chat-input-container"] button[type="submit"] svg {
  width: 17px !important; height: 17px !important; color: inherit !important;
}

/* ── Messages ──────────────────────────────────────────────── */
[data-testid="message-content"], div[class*="messageContent"] {
  font-size: 15px; line-height: 1.65; color: var(--text);
}
[class*="message"] a, [class*="step"] a {
  color: var(--accent) !important; text-decoration: none !important;
}
[class*="message"] a:hover { text-decoration: underline !important; }

/* ── Footer / watermark ────────────────────────────────────── */
footer p, footer span, [class*="watermark"] {
  font-size: 12px !important; color: var(--placeholder) !important; text-align: center !important;
}

/* ── Focus rings ───────────────────────────────────────────── */
button:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accentSoft) !important;
  outline-offset: 2px !important;
}

/* ── Fix 2: Messages always start below fixed header ───────── */
/* Chainlit's scroll container uses Tailwind utility class overflow-y-auto.
   padding-top pushes content below the fixed header on first paint.
   scroll-padding-top keeps scrollIntoView in sync.                     */
main,
.overflow-y-auto {
  scroll-padding-top: calc(var(--header-h) + 16px) !important;
}

/* Keep empty state fully in-viewport and hide jump/down controls there */
html.cv-empty-thread #welcome-screen,
html.cv-empty-thread [data-testid="readme"],
html.cv-empty-thread section[class*="readme"] {
  max-height: calc(100dvh - var(--header-h) - 92px);
  overflow: hidden;
}

html.cv-empty-thread [data-testid*="scroll"],
html.cv-empty-thread button[aria-label*="bottom" i],
html.cv-empty-thread button[aria-label*="down" i] {
  display: none !important;
}

/* ── Fix 3: Greeting + minimal mode ─────────────────────────── */

/* Greeting: normal-flow element, Copilot-style centrepiece       */
.cv-greeting {
  display: block;
  font-family: var(--font-disp);
  font-size: clamp(26px, 5.5vw, 40px);
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.02em;
  color: var(--text);
  text-align: center;
  margin: 14px 0 22px;
  pointer-events: none;
  width: 100%;
}

/* ── Fix 4: Premium citation / evidence blocks ───────────────── */
.cv-evidence-block {
  margin: 18px 0 4px;
  border: 1px solid var(--border-med);
  border-radius: 14px;
  background: var(--surface2);
  overflow: hidden;
  box-shadow: var(--shadow-card);
}

.cv-evidence-hdr {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 14px 8px;
  border-bottom: 1px solid var(--border);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--muted);
  user-select: none;
}

.cv-ev-icon {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
  color: var(--muted);
}

.cv-cite-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px 11px 12px;
  border-bottom: 1px solid var(--border);
  text-decoration: none !important;
  color: var(--text) !important;
  transition: background 120ms ease;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.cv-cite-row:last-child { border-bottom: none; }

.cv-cite-row:hover { background: var(--surface) !important; }
.cv-cite-row:active { background: var(--icon-bg) !important; }

.cv-cite-num {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: var(--accentSoft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.cv-cite-lbl {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cv-cite-arrow {
  flex-shrink: 0;
  color: var(--muted);
  display: flex;
  align-items: center;
  opacity: 0.6;
  transition: opacity 120ms, transform 120ms;
}

.cv-cite-row:hover .cv-cite-arrow {
  opacity: 1;
  transform: translateX(2px);
}

/* ── Utility ───────────────────────────────────────────────── */
.cv-hide-welcome { display: none !important; }

/* ── Desktop ≥ 720px ───────────────────────────────────────── */
@media (min-width: 720px) {
  :root { --header-h: 60px; }

  #header, header, [data-testid="header"], .MuiAppBar-root {
    padding: 0 20px !important;
  }

  .cv-wordmark { left: 70px !important; }

  #welcome-screen, [data-testid="readme"] { padding: 48px 20px 32px !important; }

  .cv-hero-h1 { font-size: 36px; }
  .cv-hero-sub { font-size: 17px; }

  #message-composer,
  [data-testid="chat-input-container"],
  form:has([data-testid="chat-input"]) {
    padding: 12px 12px 12px 18px !important;
    min-height: 64px !important;
  }
}

/* ── Mobile ≤ 480px ────────────────────────────────────────── */
@media (max-width: 480px) {
  #welcome-screen, [data-testid="readme"] { padding: 24px 16px 20px !important; }

  #welcome-screen img, [data-testid="readme"] img {
    width: 40px !important; height: 40px !important; margin-bottom: 16px !important;
  }

  .cv-hero-h1 { margin-bottom: 12px; }
  .cv-hero-sub { font-size: 14px; margin-bottom: 20px; }
  .cv-cards { gap: 14px; margin-bottom: 16px; }
  .cv-dec-card { padding: 14px 16px; min-height: 64px; gap: 12px; }

  #message-composer,
  [data-testid="chat-input-container"],
  form:has([data-testid="chat-input"]) {
    width: min(628px, calc(100vw - 56px)) !important;
  }
}

/* ── Reduced motion ────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
