/* Widget de chat da Rubia: botão flutuante + banner (ambos no index.html, abrem via JS) e a janela de
   conversa (montada em runtime por js/rubia-widget.js). Usa as cores e fontes do site (ver :root em
   css/style.css), com valores de reserva caso as variáveis não existam. */

.rubia-launcher,
.rubia-chat,
.rubia-teaser {
  --rb-orange: var(--orange, #ff790f);
  --rb-orange-2: var(--orange-2, #ff9a3d);
  --rb-orange-border: var(--orange-border, rgba(255, 121, 15, 0.8));
  --rb-bg: #0b0b0b;
  --rb-surface: #161616;
  --rb-surface-2: #1d1d1d;
  --rb-line: rgba(255, 255, 255, 0.09);
  --rb-text: #f4f4f4;
  --rb-muted: #9a9a9a;
}

/* ---------- Botão flutuante ---------- */
.rubia-launcher {
  position: fixed;
  right: 20px;
  bottom: 20px;
  /* Abaixo do .modal-overlay (z-index: 100 em css/style.css) de propósito: o modal de
     Termos/Privacidade precisa cobrir o widget quando aberto, não o contrário. */
  z-index: 90;
  width: 84px;
  height: 84px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  background: none;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.45);
  transition: transform 0.22s ease, box-shadow 0.22s ease;
}
.rubia-launcher:hover { transform: translateY(-3px) scale(1.04); box-shadow: 0 14px 32px rgba(0, 0, 0, 0.55); }
.rubia-launcher:focus-visible { outline: 3px solid var(--rb-orange); outline-offset: 3px; }
.rubia-launcher img { display: block; width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.rubia-launcher.is-hidden { display: none; }
@media (max-width: 640px) {
  .rubia-launcher { width: 64px; height: 64px; right: 14px; bottom: 14px; }
}

/* Convite que aparece uma vez, perto do botão, para quem ainda não abriu o chat */
.rubia-teaser {
  position: fixed;
  right: 20px;
  bottom: 116px;
  z-index: 90;
  max-width: 250px;
  padding: 12px 34px 12px 14px;
  background: #fff;
  color: #151515;
  border-radius: 14px 14px 4px 14px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
  font-family: Inter, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.4;
  cursor: pointer;
  animation: rubia-pop 0.3s ease both;
}
.rubia-teaser strong { color: #d85f00; }
.rubia-teaser__close {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 28px;
  height: 28px;
  border: 0;
  background: transparent;
  color: #777;
  font-size: 18px;
  line-height: 1;
  border-radius: 50%;
  cursor: pointer;
}
.rubia-teaser__close:hover { background: rgba(0, 0, 0, 0.08); }
@media (max-width: 640px) {
  .rubia-teaser { right: 12px; bottom: 90px; max-width: calc(100vw - 100px); }
}
.rubia-open .rubia-teaser { display: none; }

/* ---------- Banner ---------- */
.rubia-banner {
  display: block;
  width: 100%;
  margin-top: 32px;
  padding: 0;
  border: 0;
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  background: none;
  transition: transform 0.22s ease, box-shadow 0.22s ease;
}
.rubia-banner:hover { transform: translateY(-2px); box-shadow: 0 16px 34px rgba(0, 0, 0, 0.35); }
.rubia-banner img { display: block; width: 100%; height: auto; }

/* ---------- Janela de chat ---------- */
.rubia-chat {
  position: fixed;
  right: 20px;
  bottom: 116px;
  /* Mesmo raciocínio do .rubia-launcher: fica abaixo do .modal-overlay de propósito. */
  z-index: 90;
  width: 384px;
  max-width: calc(100vw - 28px);
  height: 640px;
  height: min(640px, calc(100dvh - 140px));
  max-height: calc(100vh - 140px);
  background: var(--rb-bg);
  border: 1px solid var(--rb-line);
  border-radius: 18px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.6);
  display: none;
  flex-direction: column;
  overflow: hidden;
  font-family: Inter, Arial, sans-serif;
  color: var(--rb-text);
}
.rubia-chat.is-open { display: flex; animation: rubia-pop 0.22s ease both; }
.rubia-chat *, .rubia-chat *::before, .rubia-chat *::after { box-sizing: border-box; }

@keyframes rubia-pop {
  from { opacity: 0; transform: translateY(10px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

/* Cabeçalho */
.rubia-chat__header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 12px 12px 14px;
  background: linear-gradient(135deg, var(--rb-orange), #e45a05);
  color: #fff;
  flex-shrink: 0;
}
.rubia-chat__header img { width: 42px; height: 42px; border-radius: 50%; object-fit: cover; flex-shrink: 0; border: 2px solid rgba(255, 255, 255, 0.85); }
.rubia-chat__who { flex: 1; min-width: 0; }
.rubia-chat__who strong { display: block; font-size: 15px; line-height: 1.2; letter-spacing: 0.2px; }
.rubia-chat__who span { display: flex; align-items: center; gap: 6px; font-size: 11.5px; opacity: 0.92; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rubia-chat__who i { width: 8px; height: 8px; border-radius: 50%; background: #5ff29a; box-shadow: 0 0 0 3px rgba(95, 242, 154, 0.25); flex-shrink: 0; }
.rubia-chat__secretary,
.rubia-chat__close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  border: 0;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.22);
  color: #fff;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.18s ease;
}
.rubia-chat__secretary { padding: 0 11px; }
.rubia-chat__close { width: 36px; font-size: 22px; line-height: 1; }
.rubia-chat__secretary:hover,
.rubia-chat__close:hover { background: rgba(0, 0, 0, 0.38); }
.rubia-chat__secretary svg { width: 15px; height: 15px; fill: currentColor; }
.rubia-chat button:focus-visible,
.rubia-chat a:focus-visible,
.rubia-chat input:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

/* Mensagens */
.rubia-chat__messages {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background:
    radial-gradient(120% 60% at 100% 0%, rgba(255, 121, 15, 0.07), transparent 60%),
    var(--rb-bg);
  scroll-behavior: smooth;
}
.rubia-chat__messages::-webkit-scrollbar { width: 6px; }
.rubia-chat__messages::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.14); border-radius: 6px; }

.rubia-row { display: flex; align-items: flex-end; gap: 8px; animation: rubia-in 0.22s ease both; }
.rubia-row--user { justify-content: flex-end; }
@keyframes rubia-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.rubia-avatar { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.rubia-avatar--ghost { visibility: hidden; }
.rubia-avatar--secretary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #0a91cc;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}

.rubia-msg {
  max-width: 82%;
  padding: 9px 12px 7px;
  border-radius: 16px;
  font-size: 14.5px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}
.rubia-msg__text { white-space: pre-wrap; }
.rubia-msg__time { display: block; margin-top: 3px; font-size: 10.5px; opacity: 0.55; text-align: right; }
.rubia-msg--bot { background: var(--rb-surface-2); border: 1px solid var(--rb-line); border-bottom-left-radius: 4px; }
.rubia-msg--secretary { background: #10202b; border: 1px solid rgba(10, 145, 204, 0.45); border-bottom-left-radius: 4px; }
.rubia-msg__who { display: block; margin-bottom: 2px; font-size: 11px; font-weight: 700; color: #5cc3ee; text-transform: uppercase; letter-spacing: 0.4px; }
.rubia-msg--user { background: linear-gradient(135deg, var(--rb-orange), #ec6408); color: #fff; border-bottom-right-radius: 4px; }
.rubia-msg--user .rubia-msg__time { opacity: 0.8; }

.rubia-note-msg {
  align-self: center;
  max-width: 92%;
  padding: 6px 10px;
  color: var(--rb-muted);
  font-size: 12.5px;
  text-align: center;
  line-height: 1.4;
}
.rubia-retry {
  display: block;
  margin: 8px auto 0;
  padding: 7px 14px;
  border: 1px solid var(--rb-orange-border);
  border-radius: 999px;
  background: transparent;
  color: #fff;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.rubia-retry:hover { background: var(--rb-orange); }

/* Digitando */
.rubia-typing { display: inline-flex; gap: 4px; padding: 13px 14px; }
.rubia-typing span { width: 7px; height: 7px; border-radius: 50%; background: #8d8d8d; animation: rubia-blink 1.2s infinite ease-in-out; }
.rubia-typing span:nth-child(2) { animation-delay: 0.18s; }
.rubia-typing span:nth-child(3) { animation-delay: 0.36s; }
@keyframes rubia-blink {
  0%, 80%, 100% { opacity: 0.25; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

/* Cartão de resumo (confirmação de dados, pedido registrado, aula confirmada) */
.rubia-card {
  width: 100%;
  max-width: 88%;
  padding: 14px;
  background: var(--rb-surface);
  border: 1px solid var(--rb-line);
  border-left: 3px solid var(--rb-orange);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
}
.rubia-card__head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.rubia-card__title { font-size: 15px; font-weight: 700; line-height: 1.25; }
.rubia-card__badge { flex-shrink: 0; padding: 3px 9px; border-radius: 999px; background: rgba(255, 121, 15, 0.16); color: #ffb06b; font-size: 11px; font-weight: 700; }
.rubia-card__badge--ok { background: rgba(46, 204, 113, 0.16); color: #6ee7a3; }
.rubia-card dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 7px 12px; font-size: 14px; }
.rubia-card dt { color: var(--rb-muted); font-size: 12.5px; padding-top: 1px; }
.rubia-card dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.rubia-card__footer { margin: 12px 0 0; padding-top: 11px; border-top: 1px solid var(--rb-line); color: #d6d6d6; font-size: 13.5px; line-height: 1.45; }

/* Opções de resposta (ficam no fluxo da conversa, abaixo da última mensagem) */
.rubia-chips { display: flex; flex-direction: column; align-items: stretch; gap: 8px; padding: 6px 0 4px 36px; animation: rubia-in 0.25s ease both; }
.rubia-chip {
  min-height: 44px;
  padding: 10px 14px;
  background: transparent;
  border: 1px solid var(--rb-orange-border);
  border-radius: 12px;
  color: #fff;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.3;
  text-align: left;
  cursor: pointer;
  transition: background 0.16s ease, border-color 0.16s ease, transform 0.12s ease;
}
.rubia-chip:hover { background: var(--rb-orange); border-color: var(--rb-orange); }
.rubia-chip:active { transform: scale(0.985); }
.rubia-chip:disabled { opacity: 0.5; cursor: default; }

/* Campo de mensagem */
.rubia-chat__form {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--rb-surface);
  border-top: 1px solid var(--rb-line);
  flex-shrink: 0;
}
.rubia-chat__input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 0 16px;
  background: var(--rb-bg);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 22px;
  color: #fff;
  /* 16px evita o zoom automático do iPhone ao focar o campo */
  font-size: 16px;
  font-family: inherit;
}
.rubia-chat__input::placeholder { color: #7d7d7d; }
.rubia-chat__input:focus { outline: none; border-color: var(--rb-orange); box-shadow: 0 0 0 3px rgba(255, 121, 15, 0.2); }
.rubia-chat.is-input-focus .rubia-chat__input { border-color: var(--rb-orange-border); }
.rubia-chat__send {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border: 0;
  border-radius: 50%;
  background: var(--rb-orange);
  color: #fff;
  cursor: pointer;
  transition: background 0.16s ease, transform 0.12s ease;
}
.rubia-chat__send:hover:not(:disabled) { background: var(--rb-orange-2); }
.rubia-chat__send:active:not(:disabled) { transform: scale(0.94); }
.rubia-chat__send:disabled { opacity: 0.4; cursor: default; }
.rubia-chat__send svg { width: 20px; height: 20px; fill: currentColor; }

.rubia-chat__note {
  padding: 0 14px 10px;
  background: var(--rb-surface);
  color: var(--rb-muted);
  font-size: 11px;
  line-height: 1.4;
  text-align: center;
  flex-shrink: 0;
}
.rubia-chat__note a { color: #c4c4c4; text-decoration: underline; }
.rubia-chat__note a:hover { color: var(--rb-orange); }

/* ---------- Celular: tela cheia ---------- */
@media (max-width: 640px) {
  .rubia-chat {
    /* Acima do botão do menu do site (z-index 201): em tela cheia o chat não pode ficar por baixo dele. */
    z-index: 300;
    top: var(--rubia-top, 0px);
    right: 0;
    left: 0;
    bottom: auto;
    width: 100%;
    max-width: none;
    height: var(--rubia-vh, 100dvh);
    max-height: none;
    border: 0;
    border-radius: 0;
  }
  .rubia-chat__header { padding-top: calc(12px + env(safe-area-inset-top, 0px)); }
  .rubia-chat__form { padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }
  .rubia-chat__note { padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }
  .rubia-msg { max-width: 86%; }
  .rubia-card { max-width: 92%; }
  .rubia-open .rubia-launcher { display: none; }
  html.rubia-open, html.rubia-open body { overflow: hidden; }
}

@media (prefers-reduced-motion: reduce) {
  .rubia-chat, .rubia-chat *, .rubia-teaser, .rubia-launcher { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
