/* Chat lateral das seções com painel (js/dashboard/section-chat.js)
   Botão flutuante "Perguntar à IA" + painel lateral escuro.
   As cores de marca vêm dos tokens do site (--accent-primary, --accent-secondary). */

.ac-root {
  --ac-bg: #0b1d30;
  --ac-surface: #102a43;
  --ac-surface-2: #0d2338;
  --ac-border: #1f4160;
  --ac-text: #e8eef5;
  --ac-muted: #9db2c7;
  --ac-brand: var(--accent-primary, #12528a);
  --ac-brand-2: #1d78c4;
  --ac-gold: var(--accent-secondary, #ca993b);
  --ac-gold-soft: #e7bf6a;
  --ac-ok: #2ecc8f;
  --ac-danger: #ff8a8f;

  /* tabelas markdown das respostas, versão escura */
  --md-table-border: #1f4160;
  --md-table-row-border: #17344f;
  --md-table-head-bg: #0d2338;
  --md-table-head-color: #9db2c7;
  --md-table-even-bg: #0e2740;
  --md-table-hover-bg: #143452;
}

/* ---------- Botão flutuante ---------- */
.ac-fab {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 900;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 46px;
  padding: 0 20px;
  border: 1px solid rgba(202, 153, 59, 0.45);
  border-radius: 999px;
  background: linear-gradient(135deg, #1f86e0, #0f5fae);
  color: #fff;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(15, 95, 174, 0.5), 0 2px 6px rgba(5, 20, 36, 0.25);
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.ac-fab:hover {
  transform: translateY(-2px);
  border-color: var(--ac-gold);
  box-shadow: 0 12px 28px rgba(15, 95, 174, 0.6), 0 2px 6px rgba(5, 20, 36, 0.25);
  filter: brightness(1.08);
}

.ac-fab:focus-visible {
  outline: 2px solid var(--ac-gold);
  outline-offset: 3px;
}

.ac-fab[hidden],
.ac-overlay[hidden] {
  display: none;
}

/* ---------- Fundo e painel ---------- */
.ac-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(3, 12, 22, 0.55);
  opacity: 0;
  transition: opacity 0.2s ease;
}

.ac-root.is-open .ac-overlay {
  opacity: 1;
}

.ac-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 1001;
  width: min(560px, 100vw);
  display: flex;
  flex-direction: column;
  background: var(--ac-bg);
  color: var(--ac-text);
  border-left: 1px solid var(--ac-border);
  /* Fechado, o drawer fica fora da tela (translateX(100%)); a sombra só existe
     quando aberto, senão vaza ~50px de gradiente na borda direita. */
  box-shadow: none;
  transform: translateX(100%);
  transition:
    transform 0.22s ease,
    box-shadow 0.22s ease;
  font-size: 14px;
  line-height: 1.5;
}

.ac-root.is-open .ac-drawer {
  transform: translateX(0);
  box-shadow: -12px 0 40px rgba(0, 0, 0, 0.35);
}

.ac-drawer *,
.ac-drawer *::before,
.ac-drawer *::after {
  box-sizing: border-box;
}

/* ---------- Cabeçalho ---------- */
.ac-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 16px 14px 18px;
  border-bottom: 1px solid var(--ac-border);
  background: var(--ac-surface-2);
}

.ac-avatar {
  position: relative;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 13px;
  color: #fff;
  background: linear-gradient(145deg, var(--ac-brand-2), var(--ac-brand));
  box-shadow: 0 4px 12px rgba(18, 82, 138, 0.45);
}

.ac-online {
  position: absolute;
  right: -3px;
  bottom: -3px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--ac-ok);
  border: 2px solid var(--ac-surface-2);
}

.ac-head-text {
  flex: 1 1 auto;
  min-width: 0;
}

.ac-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.ac-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--ac-text);
}

.ac-badge {
  padding: 1px 8px;
  border: 1px solid rgba(202, 153, 59, 0.5);
  border-radius: 5px;
  background: rgba(202, 153, 59, 0.12);
  color: var(--ac-gold-soft);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.ac-sub {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 3px;
  font-size: 12px;
  color: var(--ac-muted);
}

.ac-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ac-ok);
}

.ac-icon-btn {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ac-muted);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.ac-icon-btn:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--ac-text);
}

.ac-icon-btn:focus-visible,
.ac-chip:focus-visible,
.ac-send:focus-visible {
  outline: 2px solid var(--ac-gold);
  outline-offset: 2px;
}

/* ---------- Conversa ---------- */
.ac-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scrollbar-width: thin;
  scrollbar-color: var(--ac-border) transparent;
}

.ac-messages {
  display: flex;
  flex-direction: column;
  gap: 14px;
  font-size: 14px;
  line-height: 1.55;
  word-wrap: break-word;
}

/* Balões: reaproveitam a estrutura do chat do SophIA, com a aparência do painel. */
.ac-root .ac-drawer .message-wrapper {
  margin: 0;
  gap: 10px;
  align-items: flex-start;
}

.ac-root .ac-drawer .message-wrapper.bot::before {
  content: "✦";
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  margin-top: 2px;
  border: 1px solid var(--ac-border);
  border-radius: 9px;
  background: var(--ac-surface);
  color: var(--ac-gold-soft);
  font-size: 14px;
}

.ac-root .ac-drawer .message-inner {
  max-width: calc(100% - 40px);
  min-width: 0;
}

.ac-root .ac-drawer .message-wrapper.user .message-inner {
  max-width: 86%;
}

.ac-root .ac-drawer .message-header {
  display: none;
}

.ac-root .ac-drawer .message {
  min-width: 0;
  max-width: 100%;
  margin: 0;
  padding: 12px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.55;
}

.ac-root .ac-drawer .message.bot {
  background: var(--ac-surface);
  border: 1px solid var(--ac-border);
  border-bottom-left-radius: 5px;
  box-shadow: none;
  color: var(--ac-text);
}

.ac-root .ac-drawer .message.user {
  background: linear-gradient(135deg, var(--ac-brand-2), var(--ac-brand));
  color: #fff;
  border-bottom-right-radius: 5px;
  box-shadow: 0 4px 14px rgba(18, 82, 138, 0.35);
}

.ac-root .ac-drawer .message.bot p {
  margin: 0 0 8px;
}

.ac-root .ac-drawer .message.bot p:last-child {
  margin-bottom: 0;
}

.ac-root .ac-drawer .message.bot code {
  background: rgba(255, 255, 255, 0.08);
  color: var(--ac-text);
  font-size: 13px;
}

.ac-root .ac-drawer .message.bot pre {
  background: var(--ac-surface-2);
  border-color: var(--ac-border);
  color: var(--ac-text);
}

.ac-root .ac-drawer .message.bot a {
  color: var(--ac-gold-soft);
}

.ac-hl {
  color: var(--ac-danger);
}

/* ---------- Sugestões (5 perguntas, dentro do chat) ---------- */
.ac-suggest {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  padding: 10px 16px 12px;
  border-top: 1px solid var(--ac-border);
  background: var(--ac-bg);
  overflow-x: auto; /* uma única linha, com rolagem lateral */
  scrollbar-width: thin;
  scrollbar-color: var(--ac-border) transparent;
}

.ac-chip {
  flex: 0 0 auto;
  padding: 6px 12px;
  border: 1px solid var(--ac-border);
  border-radius: 10px;
  background: var(--ac-surface-2);
  color: var(--ac-text);
  font: inherit;
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.ac-chip:hover:not(:disabled) {
  border-color: var(--ac-gold);
  background: var(--ac-surface);
}

.ac-chip:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---------- Campo de mensagem ---------- */
.ac-form {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin: 0 16px;
  padding: 8px 8px 8px 14px;
  border: 1.5px solid var(--ac-brand-2);
  border-radius: 14px;
  background: var(--ac-surface-2);
  box-shadow: 0 0 0 3px rgba(29, 120, 196, 0.18);
}

.ac-input {
  flex: 1 1 auto;
  min-height: 38px;
  max-height: 140px;
  padding: 8px 0;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  color: var(--ac-text);
  font: inherit;
  font-size: 14px;
  line-height: 1.4;
}

.ac-input::placeholder {
  color: var(--ac-muted);
}

.ac-input:disabled {
  opacity: 0.6;
}

.ac-attach {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 36px;
  height: 38px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ac-muted);
  cursor: pointer;
}

.ac-attach:hover {
  color: var(--ac-text);
  background: var(--ac-surface);
}

.ac-attach.has-anexos {
  color: var(--ac-gold);
}

.ac-anexos {
  margin: 0 16px;
  padding: 0 0 8px;
}

.ac-drawer.is-dragover {
  outline: 2px dashed var(--ac-brand-2);
  outline-offset: -6px;
}

.ac-send {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 10px;
  background: linear-gradient(145deg, var(--ac-brand-2), var(--ac-brand));
  color: #fff;
  cursor: pointer;
  transition: filter 0.15s ease;
}

.ac-send:hover {
  filter: brightness(1.12);
}

.ac-send.is-stop {
  background: #b3261e;
}

.ac-hint {
  flex: 0 0 auto;
  margin: 0;
  padding: 10px 16px 14px;
  text-align: center;
  font-size: 12px;
  color: var(--ac-muted);
}

.ac-hint kbd {
  padding: 1px 6px;
  border: 1px solid var(--ac-border);
  border-radius: 4px;
  background: var(--ac-surface-2);
  color: var(--ac-text);
  font: inherit;
  font-size: 11px;
}

@media (max-width: 520px) {
  .ac-fab {
    right: 16px;
    bottom: 16px;
  }

  .ac-drawer {
    width: 100vw;
    border-left: 0;
  }

  .ac-hint {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ac-drawer,
  .ac-overlay,
  .ac-fab {
    transition: none;
  }
}

/* ---------- Tabelas nas respostas: compactas, sem rolagem lateral ---------- */
.ac-root .ac-drawer .message.bot:has(.tabela-wrap) {
  padding: 10px;
}

.ac-root .ac-drawer .message.bot .tabela-wrap {
  margin: 8px 0;
  overflow-x: visible; /* a tabela se ajusta à largura do painel */
  border-radius: 8px;
}

.ac-root .ac-drawer .message.bot .tabela-wrap:first-child {
  margin-top: 0;
}

.ac-root .ac-drawer .message.bot .tabela-wrap:last-child {
  margin-bottom: 0;
}

.ac-root .ac-drawer .message.bot table {
  width: 100%;
  table-layout: auto;
  font-size: 11.5px;
  line-height: 1.3;
}

.ac-root .ac-drawer .message.bot th,
.ac-root .ac-drawer .message.bot td {
  padding: 5px 6px;
  white-space: normal; /* o texto quebra em vez de alargar a tabela */
  overflow-wrap: break-word;
  word-break: normal;
  vertical-align: top;
  hyphens: auto;
}

.ac-root .ac-drawer .message.bot th {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

/* valores (números, datas, R$) não quebram no meio, para ler a coluna inteira */
.ac-root .ac-drawer .message.bot td[align="right"],
.ac-root .ac-drawer .message.bot th[align="right"] {
  white-space: nowrap;
}

/* ---------- Anexos (chips do js/chat-anexos.js) no tema da barra lateral ---------- */
.ac-root .anexo-chip {
  background: var(--ac-surface-2);
  color: var(--ac-text);
  border: 1px solid var(--ac-border);
}

.ac-root .anexo-chip-ext {
  background: var(--ac-brand-2);
}

.ac-root .anexo-chip-tam,
.ac-root .anexo-chip-x {
  color: var(--ac-muted);
}

.ac-root .message.user .anexo-chip {
  background: rgba(255, 255, 255, 0.08);
}
