/*
 * Leon AI Assistant — production website widget styles (Phase 4A §27).
 * Adapted from the hardened Phase 3.1 local demo
 * (backend/app/demo_assets/assets/style.css), namespaced under
 * `.leon-widget` (instead of `:root`/`#app`) so it never leaks variables or
 * ids into the host page, and can be dropped into an existing site
 * alongside the site's own styles.
 */

.leon-widget {
  --leon-blue: #1f4b7a;
  --leon-blue-dark: #16375a;
  --leon-bg: #f4f6f8;
  --leon-panel-bg: #ffffff;
  --leon-text: #1c2530;
  --leon-muted: #62707d;
  --leon-border: #dfe4e8;
  --leon-user-bubble: #1f4b7a;
  --leon-user-bubble-text: #ffffff;
  --leon-assistant-bubble: #eef1f4;
  --leon-assistant-bubble-text: #1c2530;
  --leon-error: #b3261e;
  --leon-success-bg: #e6f4ea;
  --leon-success-text: #1e4620;

  box-sizing: border-box;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--leon-text);
  background: var(--leon-panel-bg);
  border: 1px solid var(--leon-border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  max-width: 420px;
  max-height: min(760px, 88vh);
  /* Never scrolls itself: .leon-widget-transcript is the ONE scrollable
     region and is the child that shrinks (min-height: 0) when the widget
     hits its height limit, so the header and the message input always stay
     visible. Turnstile, the contact form and the lead-success notice live
     INSIDE the transcript, which is why nothing overflows out here (an
     overflow-y:auto here plus the transcript's own gave two scrollbars). */
  overflow: hidden;
}

.leon-widget *,
.leon-widget *::before,
.leon-widget *::after {
  box-sizing: inherit;
}

.leon-widget-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--leon-border);
  background: var(--leon-panel-bg);
}

.leon-widget-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #ffffff;
  padding: 4px;
  border: 1px solid var(--leon-border);
  object-fit: contain;
  flex-shrink: 0;
}

.leon-widget-header-text {
  flex: 1;
  min-width: 0;
}

/* Own line-height: the host page's much taller h2/p line-height made the
   header eat a quarter of a phone screen. */
.leon-widget-header-text h2,
.leon-widget-header-text p {
  line-height: 1.3;
}

.leon-widget-header-text h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.3px;
}

.leon-widget-subtitle {
  margin: 2px 0 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--leon-text);
}

.leon-widget-identification {
  margin: 1px 0 0;
  font-size: 11px;
  color: var(--leon-muted);
}

.leon-widget-reset-btn {
  border: 1px solid var(--leon-border);
  background: #fff;
  color: var(--leon-text);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
}

.leon-widget-reset-btn:hover {
  background: var(--leon-bg);
}

.leon-widget-transcript {
  flex: 1 1 auto;
  /* Lets this flex child shrink below its content height inside the
     height-capped widget; without it, it grows instead of scrolling. */
  min-height: 0;
  overflow-y: auto;
  /* Reaching the end of the conversation doesn't scroll the page behind. */
  overscroll-behavior: contain;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--leon-bg);
}

.leon-widget-transcript > * {
  flex-shrink: 0;
}

.leon-widget-messages {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.leon-widget-message {
  max-width: 85%;
  padding: 9px 12px;
  border-radius: 14px;
  line-height: 1.5;
  font-size: 14px;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.leon-widget-message-user {
  align-self: flex-end;
  background: var(--leon-user-bubble);
  color: var(--leon-user-bubble-text);
  border-bottom-right-radius: 4px;
}

.leon-widget-message-assistant {
  align-self: flex-start;
  background: var(--leon-assistant-bubble);
  color: var(--leon-assistant-bubble-text);
  border-bottom-left-radius: 4px;
}

/* Structured replies (paragraphs + lists) rebuilt by renderRichText(). */
.leon-widget-message-assistant { white-space: normal; }
.leon-widget-message-assistant p { margin: 0 0 8px; }
.leon-widget-message-assistant p:last-child,
.leon-widget-message-assistant ul:last-child,
.leon-widget-message-assistant ol:last-child { margin-bottom: 0; }
.leon-widget-message-assistant ul,
.leon-widget-message-assistant ol { margin: 0 0 8px; padding-left: 18px; }
.leon-widget-message-assistant li { margin: 0 0 6px; }
.leon-widget-message-assistant li::marker { color: var(--leon-muted); }
.leon-widget-message-assistant strong { font-weight: 600; }

.leon-widget-typing-indicator {
  margin: 0 16px 6px;
  font-size: 12px;
  color: var(--leon-muted);
  font-style: italic;
}

.leon-widget-privacy-notice {
  margin: 0 16px 8px;
  font-size: 11px;
  color: var(--leon-muted);
}

.leon-widget-contact-section {
  /* Inside the transcript: bleed through its 16px side padding so the form
     keeps its full-width panel look. */
  margin: 0 -16px;
  border-top: 1px solid var(--leon-border);
  padding: 14px 16px;
  background: #fafbfc;
}

.leon-widget-contact-section h3 {
  margin: 0 0 8px;
  font-size: 14px;
}

.leon-widget-consent-copy {
  font-size: 11px;
  color: var(--leon-muted);
  margin: 0 0 10px;
}

.leon-widget-privacy-link {
  display: inline-block;
  font-size: 11px;
  color: inherit;
  margin: -6px 0 10px;
}

.leon-widget-field {
  margin-bottom: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.leon-widget-field label {
  font-size: 11px;
  color: var(--leon-muted);
}

.leon-widget-field input {
  padding: 7px 9px;
  border: 1px solid var(--leon-border);
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
}

.leon-widget-field input:focus {
  outline: 2px solid var(--leon-blue);
  outline-offset: 1px;
}

.leon-widget-contact-submit-btn {
  background: var(--leon-blue);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 9px 14px;
  font-size: 13px;
  cursor: pointer;
}

.leon-widget-contact-submit-btn:hover {
  background: var(--leon-blue-dark);
}

.leon-widget-contact-submit-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.leon-widget-error {
  color: var(--leon-error);
  font-size: 12px;
  margin: 8px 0 0;
}

.leon-widget-lead-success {
  margin: 0;
  padding: 10px 12px;
  background: var(--leon-success-bg);
  color: var(--leon-success-text);
  border-radius: 8px;
  font-size: 13px;
}

.leon-widget-message-form {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--leon-border);
}

.leon-widget-message-input {
  flex: 1;
  resize: none;
  padding: 8px 10px;
  border: 1px solid var(--leon-border);
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
}

.leon-widget-message-input:focus {
  outline: 2px solid var(--leon-blue);
  outline-offset: 1px;
}

.leon-widget-send-btn {
  background: var(--leon-blue);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0 16px;
  font-size: 13px;
  cursor: pointer;
}

.leon-widget-send-btn:hover {
  background: var(--leon-blue-dark);
}

.leon-widget-send-btn:disabled,
.leon-widget-message-input:disabled {
  opacity: 0.6;
  cursor: default;
}

.leon-widget-hidden {
  display: none !important;
}

.leon-widget-turnstile-container {
  margin: 0; /* spacing comes from the transcript's padding and gap */
}

@media (max-width: 480px) {
  .leon-widget {
    max-width: 100%;
    max-height: 100%;
    border-radius: 0;
  }
}

/* iOS zooms the whole page into any focused field under 16px, which pushed
   the widget off-screen on phones. Touch devices and small screens get 16px. */
@media (max-width: 480px), (pointer: coarse) {
  .leon-widget-field input,
  .leon-widget-message-input {
    font-size: 16px;
  }
}

@media (prefers-color-scheme: dark) {
  .leon-widget {
    --leon-bg: #14181d;
    --leon-panel-bg: #1b2027;
    --leon-text: #e8ecef;
    --leon-muted: #9aa7b2;
    --leon-border: #2b323b;
    --leon-assistant-bubble: #262d36;
    --leon-assistant-bubble-text: #e8ecef;
    --leon-success-bg: #1c3324;
    --leon-success-text: #b7e2bf;
  }

  .leon-widget-reset-btn {
    background: #1b2027;
    color: var(--leon-text);
  }

  .leon-widget-field input,
  .leon-widget-message-input {
    background: #10141a;
    color: var(--leon-text);
  }

  /* The light #fafbfc panel made the form title and privacy link (light
     text in dark mode) unreadable. */
  .leon-widget-contact-section {
    background: var(--leon-panel-bg);
  }
}
