  :root {
    --lety-green: #0d9488;
    --lety-green-dark: #0a7a70;
    --lety-green-light: #ccfbf1;
    --lety-coral: #0d9488;
    --lety-coral-dark: #0a7a70;
    --ink: #1a1a1a;
    --ink-soft: #4b5563;
    --ink-faint: #9ca3af;
    --bot-bubble: #f1f3f4;
    --bot-text: #1a1a1a;
    --surface: #ffffff;
    --surface-alt: #f7f8f9;
    --border: #ececef;
    --radius: 18px;
    --shadow: 0 1px 3px rgba(0,0,0,0.04), 0 8px 24px rgba(0,0,0,0.05);
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", sans-serif;
  }

  * { box-sizing: border-box; }

  html, body {
    margin: 0;
    height: 100%;
    font-family: var(--font);
    color: var(--ink);
    background: var(--surface-alt);
    -webkit-font-smoothing: antialiased;
  }

  /* ===== Layout shell ===== */
  .app {
    height: 100dvh;
    display: flex;
    flex-direction: column;
    max-width: 880px;
    margin: 0 auto;
    background: var(--surface);
    box-shadow: var(--shadow);
  }

  /* ===== Header ===== */
  .header {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 18px 24px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
  }
  .bot-avatar {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--lety-green), var(--lety-green-dark));
    display: grid;
    place-items: center;
    color: #fff;
    flex-shrink: 0;
  }
  .bot-avatar svg { width: 24px; height: 24px; }
  .header-text h1 {
    margin: 0;
    font-size: 1.02rem;
    font-weight: 650;
    letter-spacing: -0.01em;
  }
  .header-text p {
    margin: 2px 0 0;
    font-size: 0.82rem;
    color: var(--ink-soft);
  }
  .status {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 0.8rem;
    color: var(--lety-green-dark);
    font-weight: 550;
  }
  .status .dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--lety-green);
    box-shadow: 0 0 0 0 rgba(13,148,136,0.5);
    animation: pulse 2s infinite;
  }
  @keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(13,148,136,0.45); }
    70% { box-shadow: 0 0 0 6px rgba(13,148,136,0); }
    100% { box-shadow: 0 0 0 0 rgba(13,148,136,0); }
  }

  /* ===== Messages ===== */
  .messages {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 28px 24px 8px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    scroll-behavior: smooth;
  }
  .intro-banner {
    align-self: center;
    text-align: center;
    max-width: 460px;
    margin-bottom: 8px;
  }
  .intro-banner h2 {
    margin: 0 0 6px;
    font-size: 1.45rem;
    font-weight: 700;
    letter-spacing: -0.02em;
  }
  .intro-banner p {
    margin: 0;
    color: var(--ink-soft);
    font-size: 0.92rem;
    line-height: 1.5;
  }

  .row { display: flex; gap: 10px; align-items: flex-end; max-width: 100%; }
  .row.bot { justify-content: flex-start; }
  .row.user { justify-content: flex-end; }

  .msg-avatar {
    width: 30px; height: 30px;
    border-radius: 9px;
    flex-shrink: 0;
    display: grid; place-items: center;
    background: var(--lety-green);
    color: #fff;
    margin-bottom: 2px;
  }
  .msg-avatar svg { width: 16px; height: 16px; }

  .bubble {
    max-width: min(560px, 78%);
    padding: 12px 16px;
    font-size: 0.94rem;
    line-height: 1.5;
    border-radius: var(--radius);
    word-wrap: break-word;
    white-space: pre-wrap;
    animation: rise 0.28s ease both;
  }
  @keyframes rise {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
  }
  .row.bot .bubble {
    background: var(--bot-bubble);
    color: var(--bot-text);
    border-bottom-left-radius: 5px;
  }
  .row.user .bubble {
    background: var(--lety-coral);
    color: #fff;
    border-bottom-right-radius: 5px;
  }

  /* typing indicator */
  .typing { display: inline-flex; gap: 4px; align-items: center; padding: 4px 2px; }
  .typing span {
    width: 7px; height: 7px; border-radius: 50%;
    background: rgba(0,0,0,0.35);
    animation: blink 1.3s infinite both;
  }
  .typing span:nth-child(2) { animation-delay: 0.18s; }
  .typing span:nth-child(3) { animation-delay: 0.36s; }
  @keyframes blink {
    0%, 60%, 100% { opacity: 0.25; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-2px); }
  }

  /* ===== Composer ===== */
  .composer {
    flex: 0 0 auto;
    padding: 14px 18px 20px;
    border-top: 1px solid var(--border);
    background: var(--surface);
  }
  .composer-inner {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 8px 8px 8px 16px;
    transition: border-color 0.18s, box-shadow 0.18s;
  }
  .composer-inner:focus-within {
    border-color: var(--lety-green);
    box-shadow: 0 0 0 3px rgba(13,148,136,0.12);
  }
  #input {
    flex: 1;
    border: none;
    outline: none;
    resize: none;
    background: transparent;
    font-family: var(--font);
    font-size: 0.95rem;
    line-height: 1.45;
    color: var(--ink);
    max-height: 140px;
    padding: 6px 0;
  }
  #input::placeholder { color: var(--ink-faint); }
  #send {
    flex-shrink: 0;
    width: 40px; height: 40px;
    border: none;
    border-radius: 11px;
    background: var(--lety-green);
    color: #fff;
    cursor: pointer;
    display: grid; place-items: center;
    transition: background 0.18s, transform 0.1s;
  }
  #send:hover:not(:disabled) { background: var(--lety-green-dark); }
  #send:active:not(:disabled) { transform: scale(0.94); }
  #send:disabled { opacity: 0.4; cursor: not-allowed; }
  #send svg { width: 18px; height: 18px; }
  .footer-note {
    text-align: center;
    margin-top: 10px;
    font-size: 0.72rem;
    color: var(--ink-faint);
  }
  .footer-note b { color: var(--ink-soft); font-weight: 600; }

  /* scrollbar */
  .messages::-webkit-scrollbar { width: 8px; }
  .messages::-webkit-scrollbar-thumb { background: #dcdce0; border-radius: 8px; }
  .messages::-webkit-scrollbar-track { background: transparent; }

  @media (max-width: 640px) {
    .app { box-shadow: none; }
    .header { padding: 14px 16px; }
    .messages { padding: 20px 16px 6px; }
    .bubble { max-width: 84%; }
    .intro-banner h2 { font-size: 1.25rem; }
  }

  @media (prefers-reduced-motion: reduce) {
    .bubble, .status .dot, .typing span { animation: none !important; }
    .messages { scroll-behavior: auto; }
    .local-greeting { transition: none !important; }
  }

  /* ===== Pantalla de formulario inicial ===== */
  .gate {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 32px 24px;
    text-align: center;
  }
  .gate.hidden { display: none; }
  .gate-icon {
    width: 64px; height: 64px;
    border-radius: 18px;
    background: linear-gradient(135deg, var(--lety-green), var(--lety-green-dark));
    display: grid; place-items: center;
    color: #fff;
    margin-bottom: 20px;
  }
  .gate-icon svg { width: 34px; height: 34px; }
  .gate h2 {
    margin: 0 0 8px;
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
  }
  .gate p {
    margin: 0 0 26px;
    color: var(--ink-soft);
    font-size: 0.95rem;
    line-height: 1.55;
    max-width: 380px;
  }
  .gate-form {
    width: 100%;
    max-width: 360px;
    display: flex;
    flex-direction: column;
    gap: 14px;
  }
  .field { text-align: left; }
  .field label {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--ink);
    margin-bottom: 6px;
  }
  .field input {
    width: 100%;
    padding: 12px 14px;
    font-family: var(--font);
    font-size: 0.95rem;
    color: var(--ink);
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: 12px;
    outline: none;
    transition: border-color 0.18s, box-shadow 0.18s;
  }
  .field input::placeholder { color: var(--ink-faint); }
  .field input:focus {
    border-color: var(--lety-green);
    box-shadow: 0 0 0 3px rgba(13,148,136,0.12);
  }
  .field input.invalid {
    border-color: #dc6868;
    box-shadow: 0 0 0 3px rgba(220,104,104,0.12);
  }
  .gate-error {
    font-size: 0.8rem;
    color: #c0392b;
    min-height: 1em;
    text-align: left;
    margin: -4px 0 0;
  }
  .gate-btn {
    margin-top: 4px;
    width: 100%;
    padding: 13px;
    font-family: var(--font);
    font-size: 0.95rem;
    font-weight: 600;
    color: #fff;
    background: var(--lety-green);
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.18s, transform 0.1s;
  }
  .gate-btn:hover:not(:disabled) { background: var(--lety-green-dark); }
  .gate-btn:active:not(:disabled) { transform: scale(0.99); }
  .gate-btn:disabled { opacity: 0.55; cursor: not-allowed; }
  .gate-privacy {
    margin-top: 14px;
    font-size: 0.72rem;
    color: var(--ink-faint);
    max-width: 320px;
  }

  /* ocultar el chat hasta que se envíe el formulario */
  .chat-area.hidden { display: none; }

  /* fade-out suave del saludo local al llegar la respuesta real */
  .local-greeting {
    transition: opacity 0.4s ease, transform 0.4s ease, max-height 0.4s ease, margin 0.4s ease;
    overflow: hidden;
    max-height: 300px;
  }
  .local-greeting.fading {
    opacity: 0;
    transform: translateY(-6px);
    max-height: 0;
    margin: 0;
    pointer-events: none;
  }