/**
 * Lucy design tokens — the parts theme.json can't express.
 *
 * theme.json maps the Figma design's palette and body font onto Chainlit's
 * own variables. This file adds the rest of the token set (display font,
 * radius/spacing scales, shadows, brand accents) as custom properties, and
 * restyles the chat surface to the design's starting screen and advisor
 * response frames.
 *
 * Source: "Final - AI Advisor UX/UI Screens + Component Library" (Figma).
 * Hook onto ids, data attributes and Chainlit's semantic class names
 * (message-content, ai-message), never its Tailwind utility classes — those
 * change between releases. refs #583 #584
 */

:root {
  --font-display: "Poppins", "IBM Plex Sans", sans-serif;

  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-xl: 12px;
  --radius-4xl: 24px;
  --radius-full: 9999px;

  --spacing-xxs: 2px;
  --spacing-xs: 4px;
  --spacing-sm: 6px;
  --spacing-md: 8px;
  --spacing-lg: 12px;
  --spacing-xl: 16px;
  --spacing-2xl: 20px;
  --spacing-3xl: 24px;

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.05);
  --elevation-01: 0 4px 16px rgba(0, 0, 0, 0.05);

  --text-secondary: #404040;

  /* Brand accents — the semantic ones (primary, ring) live in theme.json. */
  --brand-icon: #3e48d8;
  --success: #16a34a;
  --warning: #facc15;
  --warning-strong: #f97316;
  --warning-surface: #fff7ed;
}

.dark {
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.4);
  --elevation-01: 0 4px 16px rgba(0, 0, 0, 0.4);
  --text-secondary: #d4d4d4;
  --brand-icon: #8a93f8;
  --warning-surface: #2a1d0f;
}

h1,
h2,
h3,
h4 {
  font-family: var(--font-display);
  letter-spacing: 0;
}

/* ── Welcome screen (empty thread) ─────────────────────────────────────────
 * Design: "Advisor Response & Content Design – Starting Screen". The heading
 * block is injected by workspace_toggle.js in place of the logo. refs #584 */

#welcome-screen > img.logo {
  display: none;
}

#lucy-welcome-heading {
  text-align: center;
  margin-bottom: var(--spacing-2xl);
}

#lucy-welcome-heading h1 {
  font-size: 2.25rem;
  line-height: 2.75rem;
  font-weight: 700;
  color: hsl(var(--foreground));
}

#lucy-welcome-heading p {
  margin-top: var(--spacing-md);
  font-size: 1rem;
  line-height: 1.5rem;
  color: var(--text-secondary);
}

/* Starters: pill chips, two to a row as in the design. Wide enough for two
 * of Lucy's questions, which run longer than the design's placeholders. */
#starters {
  max-width: 46rem;
  margin-top: var(--spacing-md);
}

#starters button {
  border-radius: var(--radius-full);
  border-color: hsl(var(--input));
}

#starters button p {
  color: var(--text-secondary);
  font-weight: 400;
}

/* ── Composer ──────────────────────────────────────────────────────────────
 * Design: one row — attach on the left, input, send on the right — on a white
 * card with a light shadow. Chainlit stacks the textarea above a button row;
 * `display: contents` on that row lifts its two button groups into the
 * composer's own flex row so they can sit either side of the input. If
 * Chainlit changes this structure, the fallback is its stock two-row layout. */

#message-composer {
  flex-direction: row;
  align-items: flex-end;
  gap: var(--spacing-md);
  min-height: 0;
  padding: var(--spacing-md) var(--spacing-md) var(--spacing-md) var(--spacing-lg);
  background: hsl(var(--card));
  border: 1px solid hsl(var(--input));
  box-shadow: var(--elevation-01);
}

#message-composer > div:first-child {
  order: 1;
  flex: 1 1 auto;
  align-self: center;
}

#message-composer > div:last-child {
  display: contents;
}

#message-composer > div:last-child > div:first-child {
  order: 0;
  margin-left: 0;
}

#message-composer > div:last-child > div:last-child {
  order: 2;
}

/* Attach: the design's "+" in place of Chainlit's paperclip. The icon is a
 * mask so it takes the button's text colour in both themes. */
#upload-button svg {
  display: none;
}

#upload-button::before {
  content: "";
  width: 1.25rem;
  height: 1.25rem;
  background-color: currentColor;
  -webkit-mask: var(--icon-plus) center / contain no-repeat;
  mask: var(--icon-plus) center / contain no-repeat;
}

#message-composer {
  --icon-plus: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.75' stroke-linecap='round'%3E%3Cpath d='M5 12h14M12 5v14'/%3E%3C/svg%3E");
}

#chat-input {
  min-height: 24px;
  padding-top: var(--spacing-sm);
  padding-bottom: var(--spacing-sm);
}

#chat-submit {
  height: 2.5rem;
  width: 2.5rem;
}

/* ── Messages ──────────────────────────────────────────────────────────────
 * Design: "Advisor Response & Content Design 02". Response headings are
 * Poppins at the design's display-xs / text-xl sizes, with no rule under
 * them. refs #584 */

/* Chainlit's tracking-tight would otherwise win over the global h1–h4 rule. */
[data-step-type="assistant_message"] .message-content :is(h1, h2, h3, h4) {
  letter-spacing: 0;
}

[data-step-type="assistant_message"] .message-content h1 {
  font-size: 1.5rem;
  line-height: 2rem;
  font-weight: 700;
}

[data-step-type="assistant_message"] .message-content h2 {
  font-size: 1.25rem;
  line-height: 1.875rem;
  font-weight: 700;
  border-bottom: 0;
  padding-bottom: 0;
}

[data-step-type="assistant_message"] .message-content h3 {
  font-size: 1.125rem;
  line-height: 1.75rem;
  font-weight: 600;
}

[data-step-type="assistant_message"] .message-content h4 {
  font-size: 1rem;
  line-height: 1.5rem;
  font-weight: 600;
}

/* ── Response components (public/elements/ResponseCards.jsx) ────────────────
 * Design: "Advisor Response & Content Design 02" — sources accordion,
 * confidence card, caveat callout. Plain classes rather than Tailwind:
 * Chainlit's CSS build only contains the utilities it uses itself. refs #585 */

.lucy-cards {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-lg);
  margin-top: var(--spacing-md);
  font-size: 0.875rem;
  line-height: 1.25rem;
}

.lucy-cards-icon {
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
}

.lucy-cards-icon-info {
  color: var(--brand-icon);
}

.lucy-cards-sources {
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-md);
  background: hsl(var(--sidebar-background));
}

.lucy-cards-sources-toggle {
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
  width: 100%;
  padding: var(--spacing-md) var(--spacing-lg);
  font-weight: 600;
  color: hsl(var(--foreground));
  background: none;
  border: 0;
  cursor: pointer;
  text-align: left;
}

.lucy-cards-chevron {
  width: 1rem;
  height: 1rem;
  margin-left: auto;
  color: hsl(var(--muted-foreground));
  transition: transform 0.15s ease;
}

.lucy-cards-sources-list {
  list-style: decimal;
  margin: 0;
  padding: 0 var(--spacing-lg) var(--spacing-lg) calc(var(--spacing-lg) + 1.25rem);
  display: flex;
  flex-direction: column;
  gap: var(--spacing-sm);
  color: var(--text-secondary);
}

.lucy-cards-sources-list a {
  color: hsl(var(--primary));
  text-decoration: underline;
  text-underline-offset: 2px;
}

.lucy-cards-row {
  display: grid;
  grid-template-columns: 11rem 1fr;
  gap: var(--spacing-xl);
  align-items: start;
  padding: var(--spacing-lg) var(--spacing-xl);
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-md);
  background: hsl(var(--card));
}

.lucy-cards-label {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  font-weight: 600;
  font-size: 0.75rem;
  line-height: 1.125rem;
  color: hsl(var(--foreground));
}

.lucy-cards-body {
  font-weight: 500;
  color: hsl(var(--foreground));
}

.lucy-cards-body ul {
  margin: 0;
  padding-left: 1.1rem;
  list-style: disc;
  display: flex;
  flex-direction: column;
  gap: var(--spacing-xs);
}

.lucy-cards-tone-strong .lucy-cards-icon {
  color: var(--success);
}

.lucy-cards-tone-moderate .lucy-cards-icon {
  color: var(--brand-icon);
}

.lucy-cards-tone-weak .lucy-cards-icon,
.lucy-cards-tone-caveat .lucy-cards-icon {
  color: var(--warning-strong);
}

.lucy-cards-tone-none .lucy-cards-icon {
  color: hsl(var(--muted-foreground));
}

@media (max-width: 640px) {
  .lucy-cards-row {
    grid-template-columns: 1fr;
    gap: var(--spacing-sm);
  }
}

/* ── Follow-up cards (public/elements/FollowUps.jsx) ────────────────────────
 * Design: "Conversation CTA card". refs #585 */

.lucy-followups {
  margin-top: var(--spacing-3xl);
}

.lucy-followups-heading {
  font-size: 1.25rem;
  line-height: 1.875rem;
  font-weight: 700;
  margin-bottom: var(--spacing-lg);
  color: hsl(var(--foreground));
}

.lucy-followups-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  gap: var(--spacing-lg);
}

.lucy-followups-card {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-xs);
  padding: var(--spacing-xl);
  text-align: left;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius-xl);
  background: hsl(var(--card));
  box-shadow: var(--shadow-xs);
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.lucy-followups-card:hover:not(:disabled) {
  border-color: hsl(var(--input));
  box-shadow: var(--elevation-01);
}

.lucy-followups-card:disabled {
  cursor: default;
  opacity: 0.6;
}

.lucy-followups-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--spacing-sm);
}

.lucy-followups-bulb {
  width: 1.75rem;
  height: 1.75rem;
  padding: 0.3rem;
  border-radius: var(--radius-full);
  color: var(--warning-strong);
  background: var(--warning-surface);
}

.lucy-followups-arrow {
  width: 1.125rem;
  height: 1.125rem;
  color: hsl(var(--foreground));
}

.lucy-followups-title {
  font-weight: 600;
  font-size: 0.875rem;
  color: hsl(var(--foreground));
}

.lucy-followups-description {
  font-size: 0.875rem;
  line-height: 1.25rem;
  color: var(--text-secondary);
}
