/* ============================================================================
   J.A.R.V.I.S. · Conversa: bolhas e modo compacto
   ----------------------------------------------------------------------------
   As bolhas de vidro (o Jarvis fala em vidro claro, tu no violeta da casa) e a
   janelinha só-reator do Mac.
   ========================================================================== */

/* ===== Conversa ===== */
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 860px;       /* no Mac a conversa não estica de lado a lado */
  /* Sobe por trás do painel de vidro do reator: o topo visível do scroll fica
     SOB a .reactor-zone (que tem backdrop blur) e o padding-top devolve a
     altura dela (--hud-pad, medida ao vivo no app.js) — em repouso a conversa
     está abaixo do vidro; ao fazer scroll, o texto passa desfocado por trás. */
  margin: 0 auto;
  position: relative;
  z-index: 1;
  scroll-behavior: smooth;
  -webkit-user-select: text;
  user-select: text;
}
.chat::-webkit-scrollbar { width: 4px; }
.chat::-webkit-scrollbar-thumb { background: rgba(63, 220, 255, 0.22); border-radius: 4px; }
.chat::-webkit-scrollbar-track { background: transparent; }

/* Rasto de execução das ações — prova do que foi mesmo feito e onde. */
.msg.trace {
  align-self: center;
  max-width: 94%;
  padding: 4px 12px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  line-height: 1.5;
  color: var(--text-dim);
  background: rgba(63, 220, 255, 0.03);
  border: 1px dashed rgba(126, 222, 255, 0.2);
  border-radius: 8px;
  word-break: break-word;
}

/* Espaço no fim da conversa quando a barra de texto (fixed) está aberta — item
   flex real porque o WebKit ignora padding-bottom em contentores com scroll.
   Altura definida pelo app.js (syncChatBottom) na variável --chat-pad. */
.chat::after {
  content: '';
  flex: 0 0 var(--chat-pad, 0px);
}

/* Bolhas: cartões de vidro com gradiente vertical e canto "de origem" reto. */
.msg {
  position: relative;
  max-width: 86%;
  padding: 11px 15px;
  font-size: 15px;
  line-height: 1.5;
  border-radius: var(--r-lg);
  white-space: pre-wrap;
  word-break: break-word;
  animation: msgIn 0.28s cubic-bezier(0.2, 0.9, 0.3, 1);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.32);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  /* Explícito (não só herdado): o iOS ignora a herança dentro de um ancestral
     user-select:none — sem isto o longo-toque não seleciona nas bolhas. */
  -webkit-user-select: text;
  user-select: text;
}
.msg .copy-btn {
  position: absolute;
  top: 5px;
  right: 7px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 14px;
  line-height: 1;
  padding: 4px 6px;
  cursor: pointer;
  opacity: 0.6;
  transition: opacity 0.15s, color 0.15s;
  -webkit-user-select: none;
  user-select: none;
}
.msg .copy-btn:hover { opacity: 1; color: var(--cyan); }
.msg .copy-btn:active { color: var(--cyan); }
@keyframes msgIn {
  from { opacity: 0; transform: translateY(10px) scale(0.985); }
  to { opacity: 1; transform: none; }
}
.msg.user {
  align-self: flex-end;
  background: linear-gradient(150deg, rgba(160, 107, 255, 0.34), rgba(227, 100, 216, 0.20));
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-bottom-right-radius: 6px;
  color: #fff;
  box-shadow: 0 12px 32px rgba(160, 107, 255, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.22);
}
.msg.jarvis {
  align-self: flex-start;
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.085), rgba(255, 255, 255, 0.035));
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-bottom-left-radius: 6px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.14);
}
/* Suportes de canto das bolhas: SAÍRAM no redesenho v4 (ver .app::after). */
.msg.jarvis::before,
.msg.user::before {
  content: none;
  position: absolute;
  width: 13px; height: 13px;
  pointer-events: none;
}
.msg.jarvis::before {
  top: -1px; left: -1px;
  border-top: 2px solid var(--cyan);
  border-left: 2px solid var(--cyan);
  border-top-left-radius: 6px;
  filter: drop-shadow(0 0 4px var(--cyan-glow));
  opacity: 0.75;
}
.msg.user::before {
  top: -1px; right: -1px;
  border-top: 2px solid var(--gold);
  border-right: 2px solid var(--gold);
  border-top-right-radius: 6px;
  filter: drop-shadow(0 0 4px var(--gold-glow));
  opacity: 0.7;
}
.msg.jarvis.streaming::after {
  content: "▊";
  color: var(--cyan);
  animation: blink 0.8s step-start infinite;
}
@keyframes blink { 50% { opacity: 0; } }
/* Cabeçalho técnico de cada mensagem: marcador ▮ + nome + linha de dados
   a esvair — cada bolha lê-se como um módulo de consola FUI. */
.msg .who {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 1.4px;
  margin-bottom: 6px;
  color: var(--text-dim);
  text-transform: uppercase;
  opacity: 0.75;
}
.msg .who::before {
  content: "";
  width: 5px; height: 10px;
  flex-shrink: 0;
}
/* A linha de dados a atravessar o cabeçalho da bolha saiu (v4): era ruído. */
.msg .who::after {
  content: none;
  flex: 1;
  height: 1px;
  min-width: 22px;
  margin-right: 18px; /* a linha não passa por baixo do botão copiar */
}
.msg.jarvis .who { color: rgba(200, 246, 255, 0.72); }
.msg.jarvis .who::before { background: linear-gradient(180deg, var(--cyan), rgba(63, 220, 255, 0.25)); box-shadow: 0 0 6px var(--cyan-glow); }
.msg.jarvis .who::after { background: linear-gradient(90deg, rgba(63, 220, 255, 0.35), transparent); }
.msg.user .who { color: rgba(255, 255, 255, 0.8); }
.msg.user .who::before { background: linear-gradient(180deg, var(--gold), rgba(201, 167, 255, 0.25)); box-shadow: 0 0 6px var(--gold-glow); }
.msg.user .who::after { background: linear-gradient(90deg, rgba(201, 167, 255, 0.35), transparent); }

/* Imagem enviada no chat */
.msg img.thumb {
  display: block;
  max-width: min(240px, 70%);
  border-radius: 10px;
  border: 1px solid var(--edge-strong);
  margin-top: 6px;
}

/* ===== Modo compacto (Mac): só o reator, janela pequena ===== */
.mini-toggle {
  position: fixed;
  top: calc(10px + var(--safe-top));
  right: 12px;
  z-index: 30;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid var(--edge);
  background: var(--glass);
  color: var(--cyan);
  font-size: 13px;
  cursor: pointer;
  opacity: 0.5;
  transition: opacity 0.15s, box-shadow 0.15s;
}
.mini-toggle:hover { opacity: 1; box-shadow: 0 0 12px rgba(63, 220, 255, 0.25); }
/* Corpo da janelinha PiP: só o reator, centrado. */
.pip-body {
  margin: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #08061a;
}
.pip-body .reactor { width: 130px; height: 130px; }
.pip-body .hint { text-align: center; padding: 5px 10px; }
