/* Shakk / Fluqxo -- tokens de marca extraídos do documento de branding */
:root {
  --ink: #101923;
  --fluqxo-teal: #1e6f68;
  --signal: #4cb8b2;
  --sand: #d9c6a5;
  --ivory: #f7f4ed;
  --slate: #52606d;
  --border: #d8dee3;
  --danger: #b3432b;
  --surface: #ffffff;
  /* fixo -- cor de marca da sidebar, nunca muda com o tema (ao contrário
     de --ink, que é reaproveitado como cor de texto e se inverte no
     modo escuro; usar --ink na sidebar deixava o fundo dela claro
     quando o tema ficava escuro) */
  --brand-ink: #101923;

  --font-ui: "Inter", system-ui, -apple-system, sans-serif;
  --font-brand: "Manrope", var(--font-ui);
  --font-mono: "JetBrains Mono", "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
/* touch-action (não o "user-scalable=no" da viewport, que o iOS ignora
   de propósito desde o iOS 10) é o jeito de verdade de bloquear
   pinça-zoom no Safari -- omitir "pinch-zoom" da lista de gestos
   permitidos desativa especificamente esse gesto, mantendo o pan
   normal (rolagem) funcionando. O listener de gesturestart/gesturechange
   em script.js fica como reforço, mas sozinho não bastou. */
html, body { height: 100%; overflow: hidden; touch-action: pan-y; }
body {
  margin: 0;
  font-family: var(--font-ui);
  background: var(--ivory);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

/* 100dvh (com fallback 100vh) -- no PWA instalado (standalone, sem
   barra de endereço) o 100vh "clássico" não bate com a área visível
   de verdade em todo aparelho, e sem overflow controlado aqui a
   página inteira rolava (cabeçalho e composer se moviam junto) em vez
   de só a lista de mensagens rolar internamente. */
.view {
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
}
.view[hidden] { display: none !important; }

/* ---------- marca ---------- */
.brand {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}
.brand-name {
  font-family: var(--font-brand);
  font-weight: 800;
  font-size: 1.35rem;
  letter-spacing: -0.01em;
}
.brand-endorse {
  font-size: 0.78rem;
  color: var(--slate);
  font-weight: 500;
}
.brand-compact .brand-name { font-size: 1.05rem; }
.brand-mark { width: 1.4rem; height: 1.4rem; border-radius: 24%; align-self: center; flex-shrink: 0; }
.brand-compact .brand-mark { width: 1.15rem; height: 1.15rem; }

/* ---------- botões genéricos ---------- */
.btn {
  font-family: var(--font-ui);
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: 9px;
  border: 1px solid transparent;
  padding: 0.65rem 1.1rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}
.btn-block { width: 100%; }
.btn-primary { background: var(--fluqxo-teal); color: #fff; }
.btn-primary:hover { background: #185f59; }
.btn-secondary { background: var(--ivory); color: var(--ink); border-color: var(--border); }
.btn-secondary:hover { border-color: var(--fluqxo-teal); }
.btn-ghost { background: transparent; color: var(--slate); border-color: transparent; }
.btn-ghost:hover { color: var(--ink); text-decoration: underline; }

.icon-btn {
  width: 34px; height: 34px;
  display: inline-flex; align-items: center; justify-content: center;
  border: none; background: transparent; color: var(--slate);
  border-radius: 8px; cursor: pointer;
}
.icon-btn:hover { background: rgba(16, 25, 35, 0.06); color: var(--ink); }
.icon-btn-mobile { display: none; }

/* ---------- landing / login (mesmo padrão de /login no site institucional) ---------- */
.login-split { display: flex; min-height: 100%; }
.login-split-brand { text-decoration: none; position: absolute; top: 2rem; left: 2rem; }
.login-split-copy {
  flex: 1; background: var(--brand-ink); color: #fff; position: relative;
  display: flex; align-items: center; justify-content: center; padding: 4rem 3vw;
}
.login-split-copy .brand-name { color: #fff; }
.login-split-copy-inner { max-width: 440px; }
.login-split-copy-inner h1 {
  font-family: var(--font-brand); font-weight: 800; font-size: clamp(2rem, 3vw, 2.7rem);
  line-height: 1.15; letter-spacing: -0.02em; margin: 0 0 1.1rem; color: #fff; text-wrap: balance;
}
.login-split-copy-inner > p { color: rgba(255, 255, 255, 0.68); font-size: 1.02rem; line-height: 1.6; margin: 0 0 2.5rem; max-width: 40ch; }
.login-split-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 1.4rem; }
.login-split-list li { border-top: 1px solid rgba(255, 255, 255, 0.14); padding-top: 1.1rem; }
.login-split-list strong { display: block; font-family: var(--font-brand); font-size: 1rem; margin-bottom: 0.3rem; color: var(--signal); }
.login-split-list span { display: block; color: rgba(255, 255, 255, 0.65); font-size: 0.92rem; line-height: 1.5; }

.login-split-form { flex: 1; display: flex; align-items: center; justify-content: center; padding: 3rem 2rem; background: var(--ivory); }
.login-split-form-inner { width: 100%; max-width: 380px; }
.login-split-form-inner h2 { font-family: var(--font-brand); font-weight: 800; font-size: 1.8rem; margin: 0 0 0.5rem; letter-spacing: -0.01em; }
.login-split-form-lede { color: var(--slate); margin: 0 0 1.75rem; }
.login-split-brand-mobile { display: none; position: static; margin-bottom: 2rem; }

.login-box { position: relative; background: var(--surface); border-radius: 16px; padding: 2rem; max-width: 380px; width: 100%; text-align: left; }
.login-box-page { box-shadow: 0 1px 2px rgba(16, 25, 35, 0.04); border: 1px solid var(--border); max-width: 100%; }
#btn-google { width: 100%; }
.login-divider { display: flex; align-items: center; gap: 0.7rem; color: var(--slate); font-size: 0.8rem; margin: 1rem 0; }
.login-divider::before, .login-divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
#form-email { display: flex; flex-direction: column; gap: 0.6rem; }
#form-email input {
  /* 16px (1rem), nunca menos -- abaixo disso o iOS Safari dá zoom
     automático na página inteira ao focar o campo. */
  font-family: var(--font-ui); font-size: 1rem; padding: 0.6rem 0.75rem;
  border: 1px solid var(--border); border-radius: 8px; background: var(--ivory); color: var(--ink);
}
#form-email input:focus { outline: 2px solid var(--signal); outline-offset: 1px; }
#form-email input[hidden],
.login-divider[hidden],
.login-forgot[hidden],
.login-password-wrap[hidden],
#btn-google[hidden] { display: none; }
.login-password-wrap { position: relative; }
/* Sem "width: 100%" aqui, o input de senha não é filho direto do flex
   #form-email (fica dentro do wrap), então NÃO herda o stretch
   automático que o input de e-mail recebe -- ficava com a largura
   padrão do navegador em vez de acompanhar o card, e o ícone nativo
   de senha do iOS (credentials-auto-fill-button) ainda por cima
   brigava com o botão de mostrar/ocultar próprio, vazando pra fora
   do card. */
#form-email .login-password-wrap input { width: 100%; padding-right: 2.6rem; }
#form-email .login-password-wrap input::-webkit-credentials-auto-fill-button,
#form-email .login-password-wrap input::-webkit-strong-password-auto-fill-button {
  visibility: hidden; pointer-events: none; position: absolute; right: 0;
}
.login-password-toggle {
  position: absolute; top: 50%; right: 0.5rem; transform: translateY(-50%);
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; padding: 0.35rem; margin: 0;
  color: var(--slate); cursor: pointer; border-radius: 6px;
}
.login-password-toggle:hover { color: var(--ink); }
.login-password-toggle:disabled { opacity: 0.6; cursor: default; }
.login-forgot { display: flex; justify-content: flex-end; margin: -0.15rem 0 0.2rem; }
.link-btn {
  background: none; border: none; padding: 0; margin: 0; font: inherit;
  color: var(--fluqxo-teal); cursor: pointer; text-decoration: underline; text-underline-offset: 2px;
}
.link-btn:hover { color: var(--ink); }
.link-btn:disabled { opacity: 0.6; cursor: default; }
.login-switch { font-size: 0.88rem; color: var(--slate); margin: 1.25rem 0 0; text-align: center; }
.login-feedback { font-size: 0.85rem; margin: 0.9rem 0 0; }
.login-feedback.is-error { color: var(--danger); }
.login-feedback.is-success { color: var(--fluqxo-teal); }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

@media (max-width: 860px) {
  .login-split { flex-direction: column; }
  .login-split-copy { display: none; }
  .login-split-form { min-height: 100%; padding: calc(2.5rem + env(safe-area-inset-top)) 1.5rem 3rem; align-items: flex-start; }
  .login-split-brand-mobile { display: inline-flex; }
}

/* ---------- layout do chat ---------- */
#view-chat {
  display: grid;
  grid-template-columns: 264px 1fr;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  position: relative;
}
#view-chat.sidebar-collapsed { grid-template-columns: 0 1fr; }

.sidebar {
  background: var(--brand-ink);
  color: #fff;
  padding: calc(1.1rem + env(safe-area-inset-top)) 0.85rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  overflow: hidden;
  transition: padding 0.15s ease;
}
#view-chat.sidebar-collapsed .sidebar { padding: 1.1rem 0; }
.sidebar-header { display: flex; align-items: center; justify-content: space-between; padding: 0 0.25rem; }
.sidebar .brand-name { color: #fff; }
.sidebar .brand-endorse { color: rgba(255, 255, 255, 0.55); }
.sidebar .icon-btn { color: rgba(255, 255, 255, 0.7); }
.sidebar .icon-btn:hover { background: rgba(255, 255, 255, 0.1); color: #fff; }
.sidebar .btn-secondary {
  background: rgba(255, 255, 255, 0.08); color: #fff; border-color: rgba(255, 255, 255, 0.14);
}
.sidebar .btn-secondary:hover { border-color: var(--signal); }

.sidebar-heading {
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase;
  color: rgba(255, 255, 255, 0.4); padding: 0.4rem 0.4rem 0;
}
.conversation-list { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 0.15rem; }
.conversation-item {
  position: relative;
  display: flex; align-items: center; gap: 0.35rem;
  padding: 0.55rem 0.35rem 0.55rem 0.6rem; border-radius: 7px; font-size: 0.88rem;
  color: rgba(255, 255, 255, 0.78);
}
.conversation-item:hover { background: rgba(255, 255, 255, 0.06); }
.conversation-item.is-active { background: rgba(76, 184, 178, 0.18); color: #fff; }
.conversation-item-title {
  flex: 1; min-width: 0; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conversation-item-title-input {
  flex: 1; min-width: 0; font: inherit; color: var(--ink);
  background: #fff; border: 1px solid var(--fluqxo-teal); border-radius: 5px; padding: 0.1rem 0.35rem;
}
.conversation-item-menu-btn {
  flex-shrink: 0; width: 24px; height: 24px; display: flex; align-items: center; justify-content: center;
  border: none; background: transparent; color: rgba(255, 255, 255, 0.55); border-radius: 6px; cursor: pointer;
}
.conversation-item-menu-btn:hover { background: rgba(255, 255, 255, 0.14); color: #fff; }
.conversation-item-menu {
  position: absolute; top: calc(100% + 2px); right: 0.35rem; z-index: 25;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(16, 25, 35, 0.25); padding: 0.3rem; width: 160px;
}
.conv-menu-option {
  display: flex; align-items: center; gap: 0.5rem; width: 100%;
  background: none; border: none; text-align: left; color: var(--ink);
  font-family: var(--font-ui); font-size: 0.85rem; padding: 0.45rem 0.5rem; border-radius: 7px; cursor: pointer;
}
.conv-menu-option:hover { background: var(--ivory); }
.conv-menu-option.is-danger { color: var(--danger); }

.confirm-overlay {
  position: fixed; inset: 0; z-index: 50; background: rgba(16, 25, 35, 0.5);
  display: flex; align-items: center; justify-content: center; padding: 1.5rem;
}
.confirm-box {
  background: var(--surface); border-radius: 14px; padding: 1.25rem; max-width: 340px;
  box-shadow: 0 12px 32px rgba(16, 25, 35, 0.3);
}
.confirm-box p { margin: 0 0 1rem; color: var(--ink); font-size: 0.92rem; line-height: 1.5; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 0.5rem; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #962f1f; }

.sidebar-footer { border-top: 1px solid rgba(255, 255, 255, 0.1); padding-top: 0.6rem; display: flex; flex-direction: column; gap: 0.1rem; }
.sidebar-footer-row {
  display: flex; align-items: center; gap: 0.6rem;
  background: none; border: none; color: rgba(255, 255, 255, 0.7);
  font-family: var(--font-ui); font-size: 0.88rem; padding: 0.5rem 0.4rem;
  border-radius: 7px; cursor: pointer; text-align: left; width: 100%;
}
.sidebar-footer-row:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
.sidebar-footer-icon { width: 1.1rem; text-align: center; flex-shrink: 0; }
.sidebar-chevron { margin-left: auto; flex-shrink: 0; transition: transform 0.15s ease; }
.account-panel { display: flex; flex-direction: column; gap: 0.1rem; padding-top: 0.2rem; }
.account-panel[hidden] { display: none; }
.account-panel-row {
  display: flex; align-items: center; gap: 0.6rem; padding: 0.5rem 0.4rem;
  color: rgba(255, 255, 255, 0.55); font-size: 0.8rem;
}
.account-email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sidebar-backdrop {
  position: fixed; inset: 0; background: rgba(16, 25, 35, 0.5); z-index: 20;
}
.sidebar-backdrop[hidden] { display: none; }

/* ---------- chat principal ---------- */
/* grid-column explícito: no mobile a sidebar vira position:fixed (gaveta)
   e sai do fluxo do grid, deixando .chat-main como único item -- sem
   isso ele é auto-posicionado na coluna 1 (a da sidebar) em vez da 2. */
.chat-main { display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; grid-column: 2; }
.chat-header {
  display: flex; align-items: center; gap: 0.75rem;
  padding: calc(0.75rem + env(safe-area-inset-top)) 1.25rem 0.75rem; border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.chat-title { font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.mode-button {
  display: flex; align-items: center; gap: 0.4rem;
  font-family: var(--font-ui); font-size: 0.85rem; font-weight: 600;
  background: var(--ivory); border: 1px solid var(--border); color: var(--ink);
  border-radius: 999px; padding: 0.4rem 0.85rem; cursor: pointer;
}
.mode-button:hover { border-color: var(--fluqxo-teal); }

.mode-backdrop { position: fixed; inset: 0; z-index: 29; }
.mode-backdrop[hidden] { display: none; }
.mode-popover {
  position: absolute; top: 3.4rem; right: 1.25rem; z-index: 30;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 8px 24px rgba(16, 25, 35, 0.12);
  width: 280px; padding: 0.5rem;
}
.mode-popover[hidden] { display: none; }
.mode-popover-title {
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--slate); margin: 0.4rem 0.6rem 0.3rem;
}
.mode-option {
  display: flex; align-items: center; justify-content: space-between; gap: 0.5rem;
  width: 100%; background: none; border: none; text-align: left;
  padding: 0.55rem 0.6rem; border-radius: 8px; cursor: pointer;
  font-family: var(--font-ui);
}
.mode-option:hover { background: var(--ivory); }
.mode-option.is-active { background: rgba(30, 111, 104, 0.08); }
.mode-option-copy strong { display: block; font-size: 0.9rem; color: var(--ink); }
.mode-option-copy small { color: var(--slate); font-size: 0.78rem; }
.mode-check { color: var(--fluqxo-teal); font-weight: 700; }
.mode-popover-divider { height: 1px; background: var(--border); margin: 0.35rem 0.6rem; }
.mode-option-title { display: flex !important; align-items: center; gap: 0.4rem; color: var(--fluqxo-teal) !important; }

/* ---------- mensagens ---------- */
.messages { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; }
.empty-state {
  max-width: 560px; margin: 8vh auto 0; padding: 0 1.5rem; text-align: center;
}
.empty-state h1 {
  font-family: var(--font-brand); font-weight: 800; font-size: 1.8rem;
  margin: 0 0 0.6rem; text-wrap: balance;
}
.empty-state em { font-style: normal; color: var(--fluqxo-teal); }
.empty-state p { color: var(--slate); line-height: 1.5; margin: 0 0 2rem; }

.suggestion-grid { display: grid; gap: 0.6rem; }
.suggestion-card {
  display: flex; align-items: center; gap: 0.75rem; text-align: left;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 0.85rem 1rem; cursor: pointer; font-family: var(--font-ui); font-size: 0.9rem;
  color: var(--ink);
}
.suggestion-card:hover { border-color: var(--fluqxo-teal); }
.suggestion-num { font-family: var(--font-mono); color: var(--signal); font-size: 0.8rem; font-weight: 500; }

.message-list { padding: 1.5rem; display: flex; flex-direction: column; gap: 0.9rem; max-width: 760px; margin: 0 auto; }
.message-list[hidden] { display: none; }

.message { max-width: 100%; padding: 0.7rem 1rem; border-radius: 12px; line-height: 1.55; }
.message p { margin: 0 0 0.6rem; }
.message p:last-child { margin-bottom: 0; }
.message code {
  font-family: var(--font-mono); font-size: 0.85em; background: rgba(16, 25, 35, 0.06);
  padding: 0.1em 0.35em; border-radius: 4px;
}
.message pre {
  font-family: var(--font-mono); font-size: 0.83rem; background: var(--ink); color: var(--ivory);
  padding: 0.85rem 1rem; border-radius: 8px; overflow-x: auto; margin: 0.5rem 0;
}
.message pre code { background: none; padding: 0; }

.code-block { position: relative; }
.code-block-actions {
  position: absolute; top: 0.55rem; right: 0.55rem; z-index: 1;
  display: flex; gap: 0.4rem;
}
.code-preview-btn, .code-download-btn {
  font-family: var(--font-ui); font-size: 0.75rem; font-weight: 600;
  background: rgba(255, 255, 255, 0.12); color: var(--ivory);
  border: 1px solid rgba(255, 255, 255, 0.22); border-radius: 6px;
  padding: 0.3rem 0.6rem; cursor: pointer; display: flex; align-items: center;
}
.code-preview-btn:hover, .code-download-btn:hover { background: rgba(255, 255, 255, 0.22); }

.code-preview-panel {
  position: fixed; inset: 4vh 4vw; z-index: 40;
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: 0 12px 32px rgba(16, 25, 35, 0.35);
}
.code-preview-panel[hidden] { display: none; }
.code-preview-header {
  display: flex; align-items: center; gap: 0.6rem; padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.code-preview-header strong { flex: 1; }
/* iframe sandboxed (allow-scripts, sem allow-same-origin) -- o código
   roda isolado, sem acesso a cookies/storage/DOM do resto do app. */
.code-preview-frame { flex: 1; width: 100%; border: none; background: #fff; }

.message-row { display: flex; flex-direction: column; }
.message-row.role-user { align-items: flex-end; }
.message-row.role-assistant, .message-row.role-error, .message-row.role-search { align-items: flex-start; }
.message.role-user { background: var(--fluqxo-teal); color: #fff; border-bottom-right-radius: 4px; max-width: min(70ch, 100%); }
.message.role-assistant { background: none; border: none; padding: 0.7rem 0; max-width: min(70ch, 100%); font-size: 1.08rem; }
.think-block {
  margin-bottom: 0.6rem; border: 1px solid var(--border); border-radius: 10px;
  background: var(--ivory); font-size: 0.92rem;
}
.think-block summary {
  cursor: pointer; padding: 0.5rem 0.8rem; color: var(--slate); font-weight: 600;
  list-style: none; user-select: none;
}
.think-block summary::-webkit-details-marker { display: none; }
.think-block summary::before { content: "▸ "; }
.think-block[open] summary::before { content: "▾ "; }
.think-body { padding: 0 0.8rem 0.8rem; color: var(--slate); }
.think-final { padding-top: 0.1rem; }
.message.role-error { background: #fdf1ee; border: 1px solid var(--danger); color: var(--danger); max-width: min(70ch, 100%); }
.message.role-search { background: var(--surface); border: 1px solid var(--border); width: 100%; }

/* ---------- ações de mensagem ---------- */
.msg-actions { display: flex; align-items: center; gap: 0.15rem; margin-top: 0.3rem; }
.msg-action-btn { width: 28px; height: 28px; }
.icon-btn-danger:hover { color: var(--danger); background: rgba(179, 67, 43, 0.1); }
.msg-action-btn.active-vote { color: var(--fluqxo-teal); }
.msg-action-btn.loading svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.message.editing { width: min(100%, 480px); padding: 0.6rem; }
.edit-textarea {
  width: 100%; min-height: 1.4rem; max-height: 16rem; padding: 0.2rem 0.3rem;
  background: transparent; border: none; outline: none; resize: none;
  font: inherit; color: inherit; line-height: 1.55;
}
.edit-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 0.5rem; }
.edit-cancel-btn, .edit-save-btn { padding: 0.4rem 0.85rem; font-size: 0.85rem; }

.search-heading {
  display: flex; align-items: center; gap: 0.4rem;
  font-size: 0.78rem; font-weight: 700; color: var(--signal);
  text-transform: uppercase; letter-spacing: 0.03em; margin-bottom: 0.6rem;
}
.source-list { display: flex; flex-direction: column; gap: 0.5rem; }
.source-card { display: block; padding: 0.6rem 0.7rem; border: 1px solid var(--border); border-radius: 8px; text-decoration: none; color: inherit; }
.source-card:hover { border-color: var(--fluqxo-teal); }
.source-title { font-size: 0.88rem; font-weight: 600; color: var(--ink); margin-bottom: 0.15rem; }
.source-meta { display: flex; align-items: center; gap: 0.4rem; font-size: 0.76rem; color: var(--slate); margin-bottom: 0.3rem; }
.source-favicon { width: 14px; height: 14px; border-radius: 3px; }
.source-snippet { font-size: 0.82rem; color: var(--slate); line-height: 1.4; }

/* chip de fonte anexado a uma resposta do assistente */
.source-chips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.6rem; }
.source-chip {
  display: inline-flex; align-items: center; gap: 0.3rem;
  font-size: 0.75rem; color: var(--slate); background: var(--ivory);
  border: 1px solid var(--border); border-radius: 999px; padding: 0.2rem 0.6rem;
  text-decoration: none;
}
.source-chip:hover { border-color: var(--fluqxo-teal); color: var(--ink); }
.source-chip img { width: 12px; height: 12px; border-radius: 2px; }

.activity-indicator-row {
  font-size: 0.85rem; color: var(--signal); font-weight: 600;
  display: flex; align-items: center; gap: 0.4rem; padding: 0.3rem 0;
}
.activity-mark { width: 16px; height: 16px; flex-shrink: 0; animation: activity-spin 1.1s linear infinite; }
@keyframes activity-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .activity-mark { animation: activity-pulse 1.4s ease-in-out infinite; }
}
@keyframes activity-pulse { 0%, 100% { opacity: 0.35; } 50% { opacity: 1; } }

/* ---------- composer ---------- */
.composer-area { border-top: 1px solid var(--border); flex-shrink: 0; padding-bottom: env(safe-area-inset-bottom); }
.composer {
  display: flex; align-items: flex-end; gap: 0.5rem;
  max-width: 760px; margin: 0 auto; padding: 0.85rem 1.5rem 0.4rem;
}
.composer textarea {
  /* 16px (1rem), nunca menos -- abaixo disso o iOS Safari dá zoom
     automático na página inteira ao focar o campo. */
  flex: 1; font-family: var(--font-ui); font-size: 1rem;
  padding: 0.6rem 0.2rem; border: none; resize: none; max-height: 8rem;
  background: transparent; color: var(--ink);
}
.composer textarea:focus { outline: none; }
.composer-send { width: 40px; height: 40px; padding: 0; border-radius: 10px; flex-shrink: 0; }
.composer-send:disabled { opacity: 0.4; cursor: not-allowed; }
.disclaimer { max-width: 760px; margin: 0 auto; padding: 0 1.5rem 0.75rem; font-size: 0.72rem; color: var(--slate); text-align: center; }
.composer-icon.is-active { background: rgba(30, 111, 104, 0.12); color: var(--fluqxo-teal); }

.refino-banner {
  display: flex; align-items: center; gap: 0.5rem;
  max-width: 760px; margin: 0 auto; padding: 0.5rem 1.5rem;
  color: var(--fluqxo-teal); font-size: 0.78rem; font-weight: 600;
  background: rgba(30, 111, 104, 0.08); border-bottom: 1px solid var(--border);
}
.refino-banner button { margin-left: auto; background: none; border: none; color: inherit; cursor: pointer; display: flex; padding: 0.2rem; }
.refino-banner[hidden] { display: none; }

.attachment-preview { max-width: 760px; margin: 0 auto; padding: 0.6rem 1.5rem 0; }
.attachment-chip {
  display: inline-flex; align-items: center; gap: 0.5rem;
  background: var(--ivory); border: 1px solid var(--border); border-radius: 10px;
  padding: 0.4rem 0.6rem; font-size: 0.85rem; color: var(--ink);
}
.attachment-thumb { width: 32px; height: 32px; border-radius: 6px; object-fit: cover; }
.attachment-name { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-chip button { background: none; border: none; color: var(--slate); cursor: pointer; display: flex; padding: 0.15rem; }
.attachment-chip button:hover { color: var(--danger); }

.message-attachment-image { display: block; max-width: 100%; max-height: 320px; border-radius: 10px; margin-bottom: 0.5rem; }
.message-attachment-file {
  display: inline-flex; align-items: center; gap: 0.4rem;
  color: var(--fluqxo-teal); font-size: 0.85rem; font-weight: 600;
  text-decoration: none; margin-bottom: 0.5rem;
}
.message-attachment-file:hover { text-decoration: underline; }

/* ---------- tema escuro ---------- */
:root[data-theme="dark"], :root:not([data-theme="light"]) {
  --surface-dark: #1b2027;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ivory: #14181d; --surface: #1b2027; --border: #2a313a; --ink: #eef2f4; --slate: #93a0ac;
  }
}
:root[data-theme="dark"] {
  --ivory: #14181d; --surface: #1b2027; --border: #2a313a; --ink: #eef2f4; --slate: #93a0ac;
}

@media (max-width: 760px) {
  #view-chat { grid-template-columns: 1fr; }
  .chat-main { grid-column: 1 / -1; }
  .sidebar {
    position: fixed; inset: 0 30% 0 0; z-index: 21; max-width: 280px;
    transform: translateX(-100%); transition: transform 0.2s ease;
  }
  #view-chat:not(.sidebar-collapsed) .sidebar { transform: translateX(0); }
  #view-chat.sidebar-collapsed .sidebar { padding: 1.1rem 0.85rem; }
  .icon-btn-mobile { display: inline-flex; }
  .mode-popover { right: 0.75rem; left: 0.75rem; width: auto; }
}
@media (min-width: 761px) {
  .sidebar-backdrop { display: none !important; }
}

/* ---------- Shakk Code (agente de terminal) ---------- */
.agent-panel {
  position: fixed; top: 8vh; left: 1rem; right: 1rem; max-width: 480px; margin: 0 auto;
  max-height: 82vh; z-index: 31; display: flex; flex-direction: column; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: 0 12px 32px rgba(16, 25, 35, 0.3);
}
.agent-panel[hidden] { display: none; }
.agent-panel-header {
  display: flex; align-items: center; gap: 0.6rem; padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.agent-panel-header strong { flex: 1; }
.agent-status-pill { display: flex; align-items: center; gap: 0.4rem; font-size: 0.78rem; color: var(--slate); }
.agent-status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--slate); flex-shrink: 0; }
.agent-status-dot.is-online { background: var(--signal); box-shadow: 0 0 0 3px rgba(76, 184, 178, 0.2); }

.agent-pairing { padding: 1.1rem; overflow-y: auto; }
.agent-pairing p { color: var(--slate); font-size: 0.9rem; line-height: 1.5; margin: 0 0 1rem; }
.agent-code-box { margin-top: 1rem; text-align: center; }
.agent-code { font-family: var(--font-mono); font-size: 1.8rem; font-weight: 700; letter-spacing: 0.2em; color: var(--fluqxo-teal); margin-bottom: 0.6rem; }
.agent-code-hint { font-size: 0.8rem; color: var(--slate); margin-bottom: 0.4rem; }
.agent-code-command { display: block; background: var(--ivory); border: 1px solid var(--border); border-radius: 8px; padding: 0.5rem 0.75rem; font-family: var(--font-mono); font-size: 0.85rem; }

.agent-chat { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.agent-chat[hidden], .agent-pairing[hidden] { display: none; }
.agent-messages { flex: 1; min-height: 200px; max-height: 45vh; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: 0.7rem; }
.agent-composer { padding: 0.75rem 1rem 1rem; border-top: 1px solid var(--border); }

/* ---------- refino (Refinaria de Intenções) ---------- */
.refine-bubble {
  width: 100%;
  max-width: 760px;
  margin: 0 auto 0.6rem;
  display: flex;
  flex-direction: column;
  max-height: 45vh;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(16, 25, 35, 0.12);
  overflow: hidden;
}
.refine-bubble-header {
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0; padding: 0.6rem 0.85rem 0.5rem; border-bottom: 1px solid var(--border);
}
.refine-bubble-label {
  display: flex; align-items: center; gap: 0.4rem;
  color: var(--fluqxo-teal); font-size: 0.72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.05em;
}
.refine-bubble-close {
  width: 24px; height: 24px; display: flex; align-items: center; justify-content: center;
  padding: 0; color: var(--slate); background: transparent; border: 0; border-radius: 6px; cursor: pointer;
}
.refine-bubble-close:hover { color: var(--ink); background: rgba(16, 25, 35, 0.06); }
.refine-bubble-text {
  flex: 1; padding: 0.7rem 0.85rem; overflow-y: auto;
  color: var(--ink); font-size: 0.92rem; line-height: 1.6; white-space: pre-wrap;
}
.refine-bubble-text:empty::before { content: "Refinando..."; color: var(--slate); font-style: italic; }
.refine-bubble-acts { display: flex; align-items: center; gap: 0.5rem; flex-shrink: 0; padding: 0.5rem 0.85rem 0.75rem; border-top: 1px solid var(--border); }
.refine-use-btn, .refine-copy-btn { padding: 0.45rem 0.9rem; font-size: 0.83rem; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 1.5rem; transform: translate(-50%, 8px);
  background: var(--brand-ink); color: #fff; font-size: 0.85rem; font-weight: 500;
  padding: 0.6rem 1.1rem; border-radius: 999px; box-shadow: 0 8px 24px rgba(16, 25, 35, 0.25);
  z-index: 40; opacity: 0; transition: opacity 0.2s ease, transform 0.2s ease; pointer-events: none;
}
.toast[hidden] { display: none; }
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

/* ======================================================================
   Native-quality refinement — 2026-09
   Mantém identidade visual, cores e tipografia originais. A intervenção
   abaixo atua em composição, densidade, interação, responsividade e
   ergonomia do PWA para aproximá-lo do comportamento de um app nativo.
   ====================================================================== */

:root {
  --app-height: 100dvh;
  --content-width: 820px;
  --composer-width: 820px;
  --radius-xs: 8px;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --radius-xl: 24px;
  --shadow-soft: 0 1px 2px rgba(16, 25, 35, 0.04), 0 8px 30px rgba(16, 25, 35, 0.06);
  --shadow-float: 0 12px 40px rgba(16, 25, 35, 0.13), 0 2px 8px rgba(16, 25, 35, 0.06);
  --tap-size: 44px;
}

html {
  color-scheme: light dark;
  background: var(--ivory);
}

body {
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  text-rendering: optimizeLegibility;
}

button,
[role="button"],
a {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible,
textarea:focus-visible,
input:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--signal);
  outline-offset: 2px;
}

#view-chat {
  height: var(--app-height);
  grid-template-columns: 272px minmax(0, 1fr);
  background: var(--ivory);
}

/* ----- Sidebar: densidade e navegação de app, sem alterar a marca ----- */
.sidebar {
  padding: calc(0.95rem + env(safe-area-inset-top)) 0.75rem calc(0.75rem + env(safe-area-inset-bottom));
  gap: 0.72rem;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  contain: layout paint;
}

.sidebar-header {
  min-height: 42px;
  padding: 0 0.35rem;
}

.sidebar .brand-compact {
  min-width: 0;
}

.sidebar .brand-compact .brand-name {
  font-size: 1.08rem;
}

.sidebar .btn-secondary {
  min-height: 42px;
  justify-content: flex-start;
  padding: 0.62rem 0.72rem;
  border-radius: 11px;
  font-size: 0.87rem;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04);
}

.sidebar-home-row {
  width: 100%;
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: .62rem;
  padding: .56rem .68rem;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: rgba(255,255,255,.72);
  font: inherit;
  font-size: .87rem;
  text-align: left;
  cursor: pointer;
  transition: background-color .12s ease, color .12s ease;
}
.sidebar-home-row:hover {
  background: rgba(255,255,255,.06);
  color: #fff;
}
.sidebar-home-row.is-active {
  background: rgba(76,184,178,.16);
  color: #fff;
  box-shadow: inset 2px 0 0 rgba(76,184,178,.85);
}
.sidebar-home-row svg { flex: 0 0 auto; }

.sidebar-heading {
  padding: 0.55rem 0.55rem 0.1rem;
  font-size: 0.68rem;
  letter-spacing: 0.065em;
}

.conversation-list {
  gap: 2px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.14) transparent;
  -webkit-overflow-scrolling: touch;
}

.conversation-item {
  min-height: 38px;
  padding: 0.52rem 0.35rem 0.52rem 0.65rem;
  border-radius: 9px;
  font-size: 0.86rem;
  transition: background-color .12s ease, color .12s ease;
}

.conversation-item.is-active {
  background: rgba(76, 184, 178, 0.16);
  box-shadow: inset 2px 0 0 rgba(76, 184, 178, 0.85);
}

@media (hover: hover) {
  .conversation-item-menu-btn {
    opacity: 0;
    transition: opacity .12s ease, background-color .12s ease;
  }
  .conversation-item:hover .conversation-item-menu-btn,
  .conversation-item:focus-within .conversation-item-menu-btn,
  .conversation-item.is-active .conversation-item-menu-btn {
    opacity: 1;
  }
}

.conversation-item-menu {
  border-radius: 12px;
  box-shadow: var(--shadow-float);
  padding: 0.35rem;
}

.sidebar-footer {
  padding-top: 0.55rem;
}

.sidebar-footer-row {
  min-height: 38px;
  padding: 0.48rem 0.5rem;
  border-radius: 9px;
  font-size: 0.85rem;
}

/* ----- Conteúdo principal ----- */
.chat-main {
  background: var(--ivory);
  isolation: isolate;
}

.chat-header {
  position: relative;
  z-index: 10;
  min-height: 58px;
  padding: calc(0.55rem + env(safe-area-inset-top)) 1rem 0.55rem;
  gap: 0.5rem;
  border-bottom: 0;
  background: rgba(247, 244, 237, 0.92);
  -webkit-backdrop-filter: blur(18px) saturate(1.2);
  backdrop-filter: blur(18px) saturate(1.2);
}

.chat-header::after {
  content: "";
  position: absolute;
  left: 1rem;
  right: 1rem;
  bottom: 0;
  height: 1px;
  background: var(--border);
  opacity: .55;
}

.chat-title {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--slate);
  text-align: center;
  padding: 0 0.5rem;
}

.chat-header .icon-btn,
.mode-button {
  min-width: 40px;
  min-height: 40px;
}

.mode-button {
  padding: 0.42rem 0.72rem;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 11px;
  font-size: 0.82rem;
  transition: background-color .12s ease, border-color .12s ease;
}

.mode-button:hover,
.mode-button[aria-expanded="true"] {
  background: var(--surface);
  border-color: var(--border);
}

.mode-popover,
.agent-panel,
.code-preview-panel,
.confirm-box {
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-float);
}

.mode-popover {
  top: calc(3.55rem + env(safe-area-inset-top));
  right: 1rem;
  width: 292px;
  padding: 0.45rem;
  overflow: hidden;
}

.mode-option {
  min-height: 54px;
  border-radius: 11px;
  padding: 0.58rem 0.7rem;
}

.mode-option-copy small {
  display: block;
  margin-top: 2px;
  line-height: 1.35;
}

/* ----- Área de conversa ----- */
.messages {
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: rgba(82,96,109,.22) transparent;
  padding-bottom: 0.25rem;
}

.messages::-webkit-scrollbar,
.conversation-list::-webkit-scrollbar {
  width: 7px;
}
.messages::-webkit-scrollbar-thumb {
  background: rgba(82,96,109,.2);
  border-radius: 999px;
}

.empty-state {
  width: min(100%, 720px);
  max-width: 720px;
  min-height: calc(100% - 1rem);
  margin: 0 auto;
  padding: clamp(3.2rem, 12vh, 7rem) 1.5rem 2rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  text-align: left;
}

.empty-state[hidden] {
  display: none !important;
}

.empty-state h1 {
  max-width: 620px;
  font-size: clamp(2rem, 4vw, 2.7rem);
  line-height: 1.08;
  letter-spacing: -0.035em;
  margin: 0 0 0.8rem;
}

.empty-state p {
  max-width: 590px;
  font-size: 0.98rem;
  line-height: 1.65;
  margin: 0 0 2rem;
}

.suggestion-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.65rem;
}

.suggestion-card {
  min-height: 108px;
  align-items: flex-start;
  flex-direction: column;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 0.95rem;
  border-radius: 14px;
  background: var(--surface);
  border-color: var(--border);
  box-shadow: 0 1px 2px rgba(16,25,35,.025);
  line-height: 1.35;
  transition: transform .14s ease, box-shadow .14s ease, border-color .14s ease;
}

@media (hover: hover) {
  .suggestion-card:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-soft);
  }
}

.suggestion-num {
  font-size: 0.72rem;
  opacity: .9;
}

.message-list {
  width: min(100%, var(--content-width));
  max-width: var(--content-width);
  margin: 0 auto;
  padding: 1.7rem 1.5rem 2.4rem;
  gap: 1.25rem;
}

.message-row {
  min-width: 0;
}

.message {
  line-height: 1.62;
}

.message.role-user {
  max-width: min(78%, 640px);
  padding: 0.7rem 0.95rem;
  border-radius: 17px;
  border-bottom-right-radius: 6px;
  font-size: 0.97rem;
  font-weight: 500;
  box-shadow: 0 1px 1px rgba(16,25,35,.04);
}

.message.role-assistant {
  width: 100%;
  max-width: 100%;
  padding: 0.1rem 0;
  font-size: 1rem;
  font-weight: 500;
  line-height: 1.72;
}

.message.role-assistant p {
  margin-bottom: 0.8rem;
}

.message.role-assistant ul,
.message.role-assistant ol {
  padding-left: 1.45rem;
  margin-top: 0.35rem;
  margin-bottom: 0.9rem;
}

.message.role-assistant li + li {
  margin-top: 0.35rem;
}

.message code {
  border-radius: 6px;
  padding: 0.12em 0.34em;
}

.message pre {
  margin: 0.8rem 0 1rem;
  padding: 1rem 1.05rem;
  border-radius: 12px;
  line-height: 1.55;
  -webkit-overflow-scrolling: touch;
}

.think-block {
  border-radius: 12px;
  overflow: hidden;
}

.message.role-search {
  border-radius: 14px;
  padding: 0.9rem;
  box-shadow: 0 1px 2px rgba(16,25,35,.025);
}

.msg-actions {
  min-height: 30px;
  margin-top: 0.28rem;
  gap: 0.08rem;
}

.msg-action-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
}

@media (hover: hover) {
  .message-row .msg-actions {
    opacity: 0;
    transition: opacity .14s ease;
  }
  .message-row:hover .msg-actions,
  .message-row:focus-within .msg-actions {
    opacity: 1;
  }
}

.activity-indicator-row {
  min-height: 40px;
  font-size: 0.82rem;
  padding: 0.4rem 0;
}

.activity-mark {
  width: 18px;
  height: 18px;
}

.source-list {
  gap: 0.55rem;
}

.source-card {
  padding: 0.72rem 0.78rem;
  border-radius: 11px;
  transition: background-color .12s ease, border-color .12s ease;
}

.source-card:hover {
  background: var(--ivory);
}

/* ----- Composer: superfície única, semelhante a um controle nativo ----- */
.composer-area {
  position: relative;
  z-index: 12;
  flex-shrink: 0;
  border-top: 0;
  padding: 0 0 env(safe-area-inset-bottom);
  background: linear-gradient(to bottom, rgba(247,244,237,0), var(--ivory) 18%, var(--ivory) 100%);
}

.chat-composer {
  display: block;
  width: min(100%, var(--composer-width));
  max-width: var(--composer-width);
  margin: 0 auto;
  padding: 0.45rem 1.25rem 0.25rem;
}

.composer-surface {
  display: flex;
  flex-direction: column;
  min-height: 92px;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
  transition: border-color .14s ease, box-shadow .14s ease;
  overflow: hidden;
}

.composer-surface:focus-within {
  border-color: rgba(30, 111, 104, .55);
  box-shadow: 0 0 0 3px rgba(30,111,104,.08), var(--shadow-soft);
}

.chat-composer textarea {
  display: block;
  width: 100%;
  min-height: 48px;
  max-height: 164px;
  flex: none;
  padding: 0.95rem 1rem 0.55rem;
  border: 0;
  resize: none;
  background: transparent;
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 1rem;
  line-height: 1.5;
  scrollbar-width: thin;
  overscroll-behavior: contain;
}

.chat-composer textarea::placeholder {
  color: var(--slate);
  opacity: .82;
}

.composer-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  min-height: 46px;
  padding: 0.2rem 0.45rem 0.42rem 0.5rem;
}

.composer-tools {
  display: flex;
  align-items: center;
  gap: 0.12rem;
}

.chat-composer .composer-icon {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  color: var(--slate);
}

.chat-composer .composer-icon:hover {
  background: var(--ivory);
}

.chat-composer .composer-send {
  width: 40px;
  height: 40px;
  min-width: 40px;
  border-radius: 12px;
  box-shadow: none;
  transition: transform .12s ease, opacity .12s ease, background-color .12s ease;
}

.chat-composer .composer-send:not(:disabled):active {
  transform: scale(.94);
}

.chat-composer .composer-send:disabled {
  opacity: .3;
  background: var(--slate);
}

.attachment-preview-inline {
  width: auto;
  max-width: none;
  margin: 0;
  padding: 0.72rem 0.8rem 0;
}

.attachment-preview-inline .attachment-chip {
  max-width: 100%;
  border-radius: 12px;
  padding: 0.42rem 0.55rem;
  background: var(--ivory);
}

.refino-banner {
  width: min(calc(100% - 2.5rem), calc(var(--composer-width) - 2.5rem));
  max-width: calc(var(--composer-width) - 2.5rem);
  margin: 0 auto 0.15rem;
  padding: 0.52rem 0.72rem;
  border: 1px solid rgba(30,111,104,.18);
  border-radius: 12px;
  background: rgba(30,111,104,.075);
  font-size: 0.76rem;
  line-height: 1.35;
}

.disclaimer {
  max-width: var(--composer-width);
  margin: 0 auto;
  padding: 0.22rem 1.25rem 0.55rem;
  font-size: 0.68rem;
  line-height: 1.35;
  opacity: .9;
}

.refine-bubble {
  width: min(calc(100% - 2.5rem), calc(var(--composer-width) - 2.5rem));
  max-width: calc(var(--composer-width) - 2.5rem);
  margin-bottom: 0.5rem;
  border-radius: 16px;
  box-shadow: var(--shadow-float);
}

/* ----- Diálogos/painéis ----- */
.confirm-overlay,
.sidebar-backdrop,
.mode-backdrop {
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}

.confirm-box {
  width: min(100%, 360px);
  padding: 1.3rem;
}

.agent-panel {
  top: max(6vh, calc(env(safe-area-inset-top) + 12px));
  max-height: min(84vh, 720px);
}

.agent-panel-header,
.code-preview-header {
  min-height: 54px;
}

/* ----- Tema escuro: mantém exatamente os tokens cromáticos existentes ----- */
:root[data-theme="dark"] .chat-header,
:root[data-theme="dark"] .composer-area {
  background-color: transparent;
}

:root[data-theme="dark"] .chat-header {
  background: rgba(20, 24, 29, 0.9);
}

:root[data-theme="dark"] .composer-area {
  background: linear-gradient(to bottom, rgba(20,24,29,0), var(--ivory) 18%, var(--ivory) 100%);
}

/* ----- Responsividade / comportamento de app instalado ----- */
@media (max-width: 900px) and (min-width: 761px) {
  #view-chat { grid-template-columns: 246px minmax(0, 1fr); }
}

@media (max-width: 760px) {
  :root {
    --content-width: 100%;
    --composer-width: 100%;
  }

  #view-chat {
    height: var(--app-height);
  }

  .sidebar {
    inset: 0 auto 0 0;
    width: min(86vw, 320px);
    max-width: 320px;
    padding: calc(0.9rem + env(safe-area-inset-top)) 0.75rem calc(0.7rem + env(safe-area-inset-bottom));
    box-shadow: 16px 0 42px rgba(16,25,35,.28);
    transition: transform .22s cubic-bezier(.2,.8,.2,1);
  }

  .sidebar-backdrop {
    background: rgba(16,25,35,.46);
  }

  .sidebar .icon-btn-mobile {
    width: 40px;
    height: 40px;
  }

  .chat-header {
    min-height: 54px;
    padding: calc(0.42rem + env(safe-area-inset-top)) 0.5rem 0.42rem;
  }

  .chat-header::after {
    left: 0.75rem;
    right: 0.75rem;
  }

  .chat-header .icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 11px;
  }

  .chat-title {
    font-size: 0.82rem;
    padding: 0 0.2rem;
  }

  .mode-button {
    min-width: auto;
    padding: 0.38rem 0.52rem;
    font-size: 0.78rem;
  }

  .mode-popover {
    top: calc(3.25rem + env(safe-area-inset-top));
    left: 0.65rem;
    right: 0.65rem;
    width: auto;
    border-radius: 16px;
  }

  .empty-state {
    min-height: 100%;
    justify-content: flex-end;
    padding: 2rem 1rem 1rem;
  }

  .empty-state h1 {
    font-size: clamp(1.8rem, 8.8vw, 2.4rem);
    max-width: 92%;
  }

  .empty-state p {
    font-size: 0.92rem;
    margin-bottom: 1.35rem;
  }

  .suggestion-grid {
    grid-template-columns: 1fr;
    gap: 0.48rem;
  }

  .suggestion-card {
    min-height: 0;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    padding: 0.72rem 0.8rem;
    border-radius: 13px;
    gap: 0.65rem;
    font-size: 0.86rem;
  }

  .message-list {
    padding: 1.15rem 0.9rem 1.9rem;
    gap: 1.05rem;
  }

  .message.role-user {
    max-width: 86%;
    padding: 0.65rem 0.85rem;
    border-radius: 16px;
    border-bottom-right-radius: 5px;
    font-size: 0.95rem;
  }

  .message.role-assistant {
    font-size: 0.98rem;
    line-height: 1.68;
  }

  .message pre {
    margin-left: -0.1rem;
    margin-right: -0.1rem;
    border-radius: 11px;
  }

  .msg-actions {
    opacity: 1 !important;
  }

  .composer-area {
    padding-left: 0;
    padding-right: 0;
  }

  .chat-composer {
    padding: 0.35rem 0.55rem 0.18rem;
  }

  .composer-surface {
    min-height: 86px;
    border-radius: 20px;
  }

  .chat-composer textarea {
    min-height: 46px;
    max-height: min(142px, 28vh);
    padding: 0.85rem 0.9rem 0.45rem;
    font-size: 16px; /* evita auto-zoom do iOS */
  }

  .composer-toolbar {
    min-height: 44px;
    padding: 0.12rem 0.35rem 0.34rem 0.38rem;
  }

  .chat-composer .composer-icon,
  .chat-composer .composer-send {
    width: 40px;
    height: 40px;
    min-width: 40px;
  }

  .attachment-preview-inline {
    padding: 0.62rem 0.65rem 0;
  }

  .refino-banner,
  .refine-bubble {
    width: calc(100% - 1.1rem);
    max-width: none;
  }

  .disclaimer {
    padding: 0.16rem 0.8rem 0.38rem;
    font-size: 0.64rem;
  }

  .agent-panel {
    top: calc(env(safe-area-inset-top) + 8px);
    bottom: calc(env(safe-area-inset-bottom) + 8px);
    left: 8px;
    right: 8px;
    max-height: none;
    border-radius: 18px;
  }

  .code-preview-panel {
    inset: calc(env(safe-area-inset-top) + 8px) 8px calc(env(safe-area-inset-bottom) + 8px);
    border-radius: 18px;
  }

  .toast {
    bottom: calc(1rem + env(safe-area-inset-bottom));
    max-width: calc(100vw - 2rem);
    white-space: normal;
    text-align: center;
  }
}

@media (max-width: 390px) {
  #mode-button-label {
    max-width: 74px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .chat-title {
    display: none;
  }
}

@media (hover: none) {
  .icon-btn,
  .mode-button,
  .conversation-item,
  .sidebar-footer-row,
  .suggestion-card {
    touch-action: manipulation;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

/* ======================================================================
   v1.2 — correções complementares após teste real no iPhone
   - remove a sombra residual do drawer quando o menu está fechado
   - contém textos/códigos longos dentro da bolha do usuário
   - transforma as sugestões iniciais em chips de ação, não campos
   - usa a mesma superfície clara do app também no menu lateral
   ====================================================================== */

/* 1) Conteúdo do usuário nunca pode aumentar a largura da conversa.
   `overflow-wrap:anywhere` cobre CSS/URLs/data-URIs sem espaços; blocos
   fenced continuam roláveis horizontalmente quando preservar código é útil. */
.message,
.message > div,
.message p,
.message li,
.message code,
.message pre,
.message pre code,
.code-block {
  min-width: 0;
  max-width: 100%;
}

.message {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.message.role-user {
  overflow: hidden;
}

.message.role-user > div,
.message.role-user p,
.message.role-user li,
.message.role-user code {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.message.role-user .code-block {
  width: 100%;
  overflow: hidden;
}

.message.role-user pre {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  white-space: pre;
  overscroll-behavior-inline: contain;
}

/* Texto colado sem fence (como CSS/HTML bruto) também quebra dentro da bolha. */
.message.role-user p,
.message.role-user p code {
  white-space: normal;
}

/* 2) Sugestões de início: chips preenchidos e leves, com ícones semânticos.
   Em vez de três caixas brancas com aparência de formulário, as ações passam
   a fazer parte da superfície do assistente. */
.suggestion-grid {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem;
}

.suggestion-card {
  position: relative;
  display: inline-flex;
  width: auto;
  max-width: 100%;
  min-height: 46px;
  align-items: center;
  justify-content: flex-start;
  gap: 0.62rem;
  padding: 0.58rem 0.82rem 0.58rem 0.62rem;
  border: 1px solid rgba(30,111,104,.10);
  border-radius: 999px;
  background: rgba(30,111,104,.065);
  color: var(--ink);
  box-shadow: none;
  font-size: 0.86rem;
  font-weight: 600;
  line-height: 1.25;
  transition: transform .14s ease, background-color .14s ease, border-color .14s ease;
}

.suggestion-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  border-radius: 999px;
  background: rgba(30,111,104,.10);
  color: var(--fluqxo-teal);
}

.suggestion-icon svg {
  display: block;
}

@media (hover: hover) {
  .suggestion-card:hover {
    transform: translateY(-1px);
    border-color: rgba(30,111,104,.18);
    background: rgba(30,111,104,.095);
    box-shadow: none;
  }
}

.suggestion-card:active {
  transform: scale(.985);
  background: rgba(30,111,104,.12);
}

/* Mantém compatibilidade caso uma versão antiga do HTML ainda esteja em cache. */
.suggestion-num {
  display: none;
}

/* 3) Menu lateral: no tema claro, mesma superfície do restante do app. */
:root[data-theme="light"] .sidebar {
  background: var(--ivory);
  color: var(--ink);
  border-right: 1px solid rgba(82,96,109,.12);
}

:root[data-theme="light"] .sidebar .brand-name {
  color: var(--ink);
}

:root[data-theme="light"] .sidebar .brand-endorse,
:root[data-theme="light"] .sidebar-heading,
:root[data-theme="light"] .account-panel-row,
:root[data-theme="light"] .sidebar-footer-row,
:root[data-theme="light"] .sidebar .icon-btn,
:root[data-theme="light"] .sidebar-home-row,
:root[data-theme="light"] .conversation-item,
:root[data-theme="light"] .conversation-item-menu-btn {
  color: var(--slate);
}

:root[data-theme="light"] .sidebar-heading {
  color: rgba(82,96,109,.72);
}

:root[data-theme="light"] .sidebar .icon-btn:hover,
:root[data-theme="light"] .sidebar-footer-row:hover,
:root[data-theme="light"] .sidebar-home-row:hover,
:root[data-theme="light"] .conversation-item:hover,
:root[data-theme="light"] .conversation-item-menu-btn:hover {
  background: rgba(16,25,35,.045);
  color: var(--ink);
}

:root[data-theme="light"] .conversation-item.is-active {
  background: rgba(30,111,104,.085);
  color: var(--ink);
  box-shadow: inset 2px 0 0 rgba(30,111,104,.8);
}

:root[data-theme="light"] .sidebar-home-row.is-active {
  background: rgba(30,111,104,.085);
  color: var(--ink);
  box-shadow: inset 2px 0 0 rgba(30,111,104,.8);
}

:root[data-theme="light"] .sidebar .btn-secondary {
  background: rgba(255,255,255,.50);
  color: var(--ink);
  border-color: rgba(82,96,109,.16);
  box-shadow: none;
}

:root[data-theme="light"] .sidebar .btn-secondary:hover {
  background: rgba(30,111,104,.055);
  border-color: rgba(30,111,104,.24);
}

:root[data-theme="light"] .sidebar-footer {
  border-top-color: rgba(82,96,109,.14);
}

:root[data-theme="light"] .sidebar-backdrop {
  background: rgba(16,25,35,.18);
}

/* 4) A sombra da gaveta só existe enquanto ela está realmente aberta.
   Antes, a sidebar traduzida para fora da tela continuava projetando a
   sombra para dentro do viewport, criando a faixa cinza vista à esquerda. */
@media (max-width: 760px) {
  .sidebar {
    box-shadow: none;
  }

  #view-chat:not(.sidebar-collapsed) .sidebar {
    box-shadow: 14px 0 36px rgba(16,25,35,.22);
  }

  :root[data-theme="light"] #view-chat:not(.sidebar-collapsed) .sidebar {
    box-shadow: 12px 0 34px rgba(16,25,35,.14);
  }

  .suggestion-grid {
    gap: 0.5rem;
  }

  .suggestion-card {
    min-height: 44px;
    padding: 0.54rem 0.78rem 0.54rem 0.58rem;
    font-size: 0.84rem;
  }

  .suggestion-icon {
    width: 28px;
    height: 28px;
    flex-basis: 28px;
  }
}

:root[data-theme="dark"] .suggestion-card {
  background: rgba(76,184,178,.075);
  border-color: rgba(76,184,178,.10);
}

:root[data-theme="dark"] .suggestion-icon {
  background: rgba(76,184,178,.11);
  color: var(--signal);
}

/* ======================================================================
   v1.3 — teclado virtual sem "empurrar" a interface no iPhone

   O shell permanece na altura original do app quando o teclado abre.
   Apenas o composer sobe pela altura real do teclado, sobrepondo a área
   de conversa. Isso evita o reflow que fazia título, sugestões e mensagens
   saltarem para cima ao tocar no campo de texto.
   ====================================================================== */

/* O PWA inteiro já usa rolagem interna por view/mensagens. Fixar o body
   bloqueia o "document scroll" que o Safari tenta criar ao focar inputs. */
body {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
}

@media (max-width: 760px) {
  #view-chat {
    height: var(--app-height);
    max-height: var(--app-height);
  }

  /* O composer sai visualmente do rodapé e repousa logo acima do teclado,
     mas continua ocupando seu espaço original no flex. Assim a lista e o
     empty-state NÃO são recalculados nem "empurrados" para cima. */
  html.composer-keyboard-open .composer-area {
    transform: translate3d(0, calc(-1 * var(--keyboard-inset)), 0);
    will-change: transform;
    transition: none;
    z-index: 30;
  }

  /* Durante a digitação, o gradiente deve continuar cobrindo a conversa
     atrás do composer deslocado, como uma barra de entrada nativa. */
  html.composer-keyboard-open .composer-area::before {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    height: var(--keyboard-inset);
    background: var(--ivory);
    pointer-events: none;
  }

  :root[data-theme="dark"].composer-keyboard-open .composer-area::before {
    background: var(--ivory);
  }

  /* Não permita que o navegador tente deslocar o documento por conta
     própria; somente .messages continua sendo a superfície rolável. */
  html.composer-keyboard-open,
  html.composer-keyboard-open body {
    overflow: hidden !important;
    overscroll-behavior: none;
  }

  /* Em conversas existentes, garante espaço rolável suficiente para que a
     última mensagem possa ser trazida acima do composer sem mover o shell. */
  html.composer-keyboard-open .message-list:not([hidden]) {
    padding-bottom: calc(1.9rem + var(--keyboard-inset));
  }
}


/* ======================================================================
   v1.5 — Shakk Code como tela nativa do app

   O agente deixa de abrir em modal flutuante. Ele ocupa a área principal
   abaixo do header como uma aba de chat normal, mantendo sidebar, tema,
   safe areas e comportamento de teclado do restante da PWA.
   ====================================================================== */

/* Enquanto o Shakk Code está aberto, a conversa comum e seu composer saem
   do fluxo. O header permanece como chrome compartilhado do aplicativo. */
.chat-main.agent-view-open > .messages,
.chat-main.agent-view-open > .composer-area {
  display: none !important;
}

/* O painel deixa de ser um diálogo flutuante e vira a superfície principal. */
.agent-panel {
  position: relative;
  inset: auto;
  top: auto;
  left: auto;
  right: auto;
  bottom: auto;
  z-index: 10;
  display: flex;
  flex: 1 1 auto;
  width: 100%;
  max-width: none;
  min-width: 0;
  min-height: 0;
  max-height: none;
  margin: 0;
  overflow: hidden;
  background: var(--ivory);
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.agent-panel[hidden] {
  display: none;
}

.agent-panel-header {
  min-height: 58px;
  padding: 0.72rem 1.35rem;
  background: var(--ivory);
  border-bottom: 1px solid var(--border);
}

.agent-panel-header strong {
  font-family: var(--font-brand);
  font-size: 0.96rem;
  font-weight: 800;
}

#btn-agente.is-active {
  color: var(--fluqxo-teal);
  background: rgba(30,111,104,.08);
}

/* Pareamento funciona como empty state da aba, não como conteúdo de modal. */
.agent-pairing {
  flex: 1 1 auto;
  min-height: 0;
  padding: clamp(1.5rem, 5vw, 4rem) 1.5rem 2rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.agent-pairing[hidden] {
  display: none;
}

.agent-pairing > p,
.agent-pairing > .agent-code-box {
  width: min(100%, 620px);
}

.agent-pairing > p {
  margin-bottom: 1.25rem;
  text-align: center;
  font-size: 0.96rem;
  line-height: 1.65;
}

#btn-agent-generate {
  min-height: 46px;
  padding-inline: 1rem;
}

.agent-code-box {
  margin-top: 1.35rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.agent-code-command {
  overflow-x: auto;
  white-space: nowrap;
  -webkit-overflow-scrolling: touch;
}

/* Chat do Shakk Code usa a mesma largura de leitura do chat principal. */
.agent-chat {
  min-height: 0;
  background: var(--ivory);
}

.agent-messages {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  width: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1.7rem max(1.25rem, calc((100% - var(--content-width)) / 2 + 1.5rem)) 2.2rem;
  gap: 1.25rem;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

/* Composer do agente segue a mesma linguagem de superfície do chat comum. */
.agent-composer {
  position: relative;
  flex: 0 0 auto;
  display: block;
  width: min(100%, var(--composer-width));
  max-width: var(--composer-width);
  margin: 0 auto;
  padding: 0.45rem 1.25rem calc(0.65rem + env(safe-area-inset-bottom));
  border: 0;
  background: linear-gradient(to bottom, rgba(247,244,237,0), var(--ivory) 22%, var(--ivory) 100%);
}

.agent-composer-surface {
  display: flex;
  align-items: flex-end;
  gap: 0.55rem;
  min-height: 58px;
  padding: 0.46rem 0.5rem 0.46rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
  transition: border-color .14s ease, box-shadow .14s ease;
}

.agent-composer-surface:focus-within {
  border-color: rgba(30,111,104,.55);
  box-shadow: 0 0 0 3px rgba(30,111,104,.08), var(--shadow-soft);
}

.agent-composer textarea {
  flex: 1 1 auto;
  width: 100%;
  min-width: 0;
  min-height: 42px;
  max-height: 160px;
  padding: 0.62rem 0.1rem 0.45rem;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 1rem;
  line-height: 1.5;
}

.agent-composer textarea::placeholder {
  color: var(--slate);
  opacity: .82;
}

.agent-composer .composer-send {
  width: 40px;
  height: 40px;
  min-width: 40px;
  padding: 0;
  flex: 0 0 40px;
  border-radius: 12px;
  box-shadow: none;
}

.agent-composer .composer-send:disabled {
  opacity: .3;
  background: var(--slate);
}

:root[data-theme="dark"] .agent-panel,
:root[data-theme="dark"] .agent-chat {
  background: var(--ivory);
}

:root[data-theme="dark"] .agent-panel-header {
  background: rgba(20,24,29,.92);
}

:root[data-theme="dark"] .agent-composer {
  background: linear-gradient(to bottom, rgba(20,24,29,0), var(--ivory) 22%, var(--ivory) 100%);
}

@media (max-width: 760px) {
  .agent-panel {
    inset: auto;
    top: auto;
    left: auto;
    right: auto;
    bottom: auto;
    max-height: none;
    border-radius: 0;
  }

  .agent-panel-header {
    min-height: 54px;
    padding: 0.62rem 0.9rem;
  }

  .agent-pairing {
    justify-content: flex-start;
    padding: 2.2rem 1.1rem 1.5rem;
  }

  .agent-messages {
    padding: 1.25rem 1rem 1.6rem;
  }

  .agent-composer {
    width: 100%;
    max-width: none;
    padding: 0.42rem 0.8rem calc(0.55rem + env(safe-area-inset-bottom));
  }

  .agent-composer-surface {
    border-radius: 18px;
  }

  /* O mesmo comportamento anti-reflow do composer principal vale aqui. */
  html.composer-keyboard-open .chat-main.agent-view-open .agent-composer {
    transform: translate3d(0, calc(-1 * var(--keyboard-inset)), 0);
    will-change: transform;
    transition: none;
    z-index: 30;
  }

  html.composer-keyboard-open .chat-main.agent-view-open .agent-messages {
    padding-bottom: calc(1.6rem + var(--keyboard-inset));
  }
}


/* ----- Fontes consultadas: compacto e recolhido (a resposta fica em destaque) ----- */
.source-details { width: 100%; }
.source-summary {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.2rem 0.6rem;
  cursor: pointer; list-style: none; padding: 0.1rem 0;
}
.source-summary::-webkit-details-marker { display: none; }
.source-summary::after {
  content: "▾"; margin-left: auto; color: var(--slate); font-size: 0.8rem; transition: transform .15s ease;
}
.source-details[open] .source-summary::after { transform: rotate(180deg); }
.source-summary-label {
  display: inline-flex; align-items: center; gap: 0.4rem;
  font-size: 0.78rem; font-weight: 700; color: var(--signal);
  text-transform: uppercase; letter-spacing: 0.03em;
}
.source-summary-domains {
  font-size: 0.76rem; color: var(--slate);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1 1 8rem;
}
.source-details[open] .source-list { margin-top: 0.5rem; gap: 0; max-height: 16rem; overflow-y: auto; }
.source-row {
  display: flex; align-items: center; gap: 0.5rem; min-width: 0;
  padding: 0.42rem 0.2rem; border-top: 1px solid var(--border);
  text-decoration: none; color: inherit; font-size: 0.85rem;
}
.source-row:first-child { border-top: 0; }
.source-row:hover { background: var(--ivory); }
.source-row-title { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; color: var(--ink); }
.source-row-domain { flex: 0 0 auto; max-width: 38%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.74rem; color: var(--slate); }
