/* ============================================================
   ASC — Chat interno (iframe Sofia)
   Moldura com a identidade ASC ao redor do iframe do SAC.

   IMPORTANTE: o iframe aponta para sac1.ascbrazil.com.br, uma origem
   diferente do site. Por isso NENHUM seletor daqui alcanca o conteudo
   interno do chat — a Same-Origin Policy do navegador bloqueia. Tudo
   abaixo estiliza apenas a casca (launcher, painel, header, moldura).
   Para o interior do chat acompanhar a marca, o tema precisa ser
   aplicado no proprio sac1 (ver README do widget).
   ============================================================ */

/*.asc-chat {
  display: none !important;
}*/

.asc-chat, .asc-chat * { box-sizing: border-box; }

.asc-chat {
  /* O iframe tem header proprio; ele fica recortado sob o header do widget. */
  --asc-chat-iframe-head-offset: 72px;
}

/* ─── Launcher flutuante ─── */
.asc-chat-launcher {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 9990; /* abaixo do consent (9999+) para nao cobrir o banner */
  display: inline-flex;
  align-items: center;
  gap: 10px;
  height: 60px;
  padding: 0 22px 0 18px;
  border: 0;
  border-radius: var(--asc-r-pill);
  background: var(--asc-grad-brand);
  color: #fff;
  font-family: var(--asc-font-sans);
  font-weight: var(--asc-fw-bold);
  font-size: 15px;
  letter-spacing: -0.005em;
  cursor: pointer;
  box-shadow: var(--asc-shadow-brand), 0 18px 40px -16px rgba(0, 0, 0, 0.45);
  transition:
    transform var(--asc-dur-base) var(--asc-ease-spring),
    box-shadow var(--asc-dur-base) var(--asc-ease-standard),
    opacity var(--asc-dur-base) var(--asc-ease-standard);
}
.asc-chat-launcher:hover {
  transform: translateY(-2px);
  box-shadow: var(--asc-shadow-brand), 0 24px 50px -16px rgba(0, 0, 0, 0.55);
}
.asc-chat-launcher:focus-visible {
  outline: 3px solid var(--asc-focus-ring);
  outline-offset: 3px;
}
.asc-chat-launcher .asc-chat-launcher-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.16);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.28);
}
.asc-chat-launcher .asc-chat-launcher-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.asc-chat-launcher .asc-chat-launcher-icon {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

/* pulso discreto para chamar atencao na primeira carga */
.asc-chat-launcher::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  border: 2px solid var(--asc-purple-400);
  opacity: 0;
  animation: asc-chat-pulse 3.2s var(--asc-ease-out) infinite;
  pointer-events: none;
}
@keyframes asc-chat-pulse {
  0%   { transform: scale(1);    opacity: .55; }
  70%  { transform: scale(1.18); opacity: 0; }
  100% { transform: scale(1.18); opacity: 0; }
}

/* estado aberto: launcher vira "fechar" */
.asc-chat.is-open .asc-chat-launcher {
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px) scale(.92);
}
.asc-chat.is-open .asc-chat-launcher::after { animation: none; }

/* ─── Painel ─── */
.asc-chat-panel {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 9991;
  width: 420px;
  /* deixa livre o nav sticky (76px) no topo */
  height: min(680px, calc(100vh - 124px));
  display: flex;
  flex-direction: column;
  background: var(--asc-bg-elev);
  border: 1px solid var(--asc-border);
  border-radius: var(--asc-r-xl);
  overflow: hidden;
  box-shadow:
    0 38px 70px -28px rgba(36, 12, 48, .45),
    0 12px 28px -12px rgba(36, 12, 48, .25);
  /* fechado por padrao */
  opacity: 0;
  visibility: hidden;
  transform: translateY(16px) scale(.98);
  transform-origin: bottom right;
  transition:
    opacity var(--asc-dur-base) var(--asc-ease-standard),
    transform var(--asc-dur-slow) var(--asc-ease-out),
    visibility 0s linear var(--asc-dur-slow);
}
.asc-chat.is-open .asc-chat-panel {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
  transition:
    opacity var(--asc-dur-base) var(--asc-ease-standard),
    transform var(--asc-dur-slow) var(--asc-ease-spring),
    visibility 0s;
}

/* ─── Header do painel ─── */
.asc-chat-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--asc-grad-brand);
  color: #fff;
  flex-shrink: 0;
  position: relative;
}
.asc-chat-head::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(80% 120% at 100% 0%, rgba(255,255,255,.14), transparent 60%);
  pointer-events: none;
}
.asc-chat-head-avatar {
  position: relative;
  z-index: 1;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.16);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.28);
}
.asc-chat-head-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.asc-chat-head-info {
  position: relative;
  z-index: 1;
  flex: 1;
  min-width: 0;
}
.asc-chat-head-info b {
  display: block;
  font-size: 15px;
  font-weight: var(--asc-fw-bold);
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.asc-chat-head-info .asc-chat-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.82);
}
.asc-chat-head-info .asc-chat-status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--asc-success-500);
  box-shadow: 0 0 0 3px rgba(18, 183, 106, 0.25);
  flex-shrink: 0;
}
.asc-chat-head-actions {
  position: relative;
  z-index: 1;
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}
.asc-chat-head-actions button {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: var(--asc-r-md);
  background: transparent;
  color: rgba(255, 255, 255, 0.85);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background var(--asc-dur-fast) var(--asc-ease-standard),
              color var(--asc-dur-fast) var(--asc-ease-standard);
}
.asc-chat-head-actions button:hover {
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
}
.asc-chat-head-actions button:focus-visible {
  outline: 2px solid #fff;
  outline-offset: -2px;
}
.asc-chat-head-actions svg { width: 18px; height: 18px; }

/* ─── Corpo / iframe ─── */
.asc-chat-body {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: var(--asc-bg);
}
.asc-chat-body iframe {
  width: 100%;
  height: calc(100% + var(--asc-chat-iframe-head-offset));
  margin-top: -60px;
  border: 0;
  display: block;
  background: #fff;
}

/* Skeleton enquanto o iframe carrega */
.asc-chat-loader {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  gap: 14px;
  background: var(--asc-bg);
  z-index: 2;
  transition: opacity var(--asc-dur-slow) var(--asc-ease-standard),
              visibility 0s linear var(--asc-dur-slow);
}
.asc-chat.is-loaded .asc-chat-loader,
.asc-chat.is-blocked .asc-chat-loader {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.asc-chat-loader-dots {
  display: flex;
  gap: 6px;
}
.asc-chat-loader-dots span {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--asc-purple-300);
  animation: asc-chat-typing 1.2s infinite ease-in-out;
}
.asc-chat-loader-dots span:nth-child(2) { animation-delay: .15s; }
.asc-chat-loader-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes asc-chat-typing {
  0%, 60%, 100% { transform: translateY(0); opacity: .6; }
  30% { transform: translateY(-5px); opacity: 1; }
}
.asc-chat-loader p {
  margin: 0;
  font-size: var(--asc-fs-sm);
  color: var(--asc-fg-muted);
}

/* Fallback quando o iframe nao pode ser exibido (ex.: localhost) */
.asc-chat-fallback {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 28px;
  text-align: center;
  background: var(--asc-bg);
}
.asc-chat.is-blocked .asc-chat-fallback { display: flex; }
/* esconde a pagina de erro do navegador atras do fallback */
.asc-chat.is-blocked .asc-chat-body iframe { visibility: hidden; }
.asc-chat-fallback p {
  margin: 0;
  font-size: var(--asc-fs-sm);
  color: var(--asc-fg-muted);
  line-height: var(--asc-lh-normal);
}
.asc-chat-fallback .asc-chat-fallback-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 42px;
  padding: 0 18px;
  border-radius: var(--asc-r-md);
  background: var(--asc-purple-600);
  color: #fff;
  font-weight: var(--asc-fw-bold);
  font-size: 14px;
}
.asc-chat-fallback .asc-chat-fallback-link:hover {
  filter: brightness(1.12);
  text-decoration: none;
  color: #fff;
}

/* ─── Rodape de marca ─── */
.asc-chat-foot {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 14px;
  border-top: 1px solid var(--asc-divider);
  background: var(--asc-bg-elev);
  font-size: 11px;
  letter-spacing: .04em;
  color: var(--asc-fg-subtle);
}
.asc-chat-trouble {
  border: 0;
  background: none;
  padding: 0;
  font-family: inherit;
  font-size: 11px;
  letter-spacing: .04em;
  color: var(--asc-fg-subtle);
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}
.asc-chat-trouble:hover { color: var(--asc-fg-brand); }
/* uma vez no fallback, o atalho perde a funcao */
.asc-chat.is-blocked .asc-chat-trouble { visibility: hidden; }
.asc-chat-foot b {
  color: var(--asc-fg-brand);
  font-weight: var(--asc-fw-bold);
}

/* ─── Convivencia com o banner de consentimento ─────────────
   Enquanto o banner de cookies estiver visivel (classe aplicada por
   chat-widget.js), o widget sobe para nao ficar coberto por ele. */
/* --asc-chat-consent-h e medido em tempo real pelo chat-widget.js:
   altura real do banner + folga. Fallback de 172px caso o JS nao rode. */
.asc-chat.has-consent .asc-chat-launcher {
  bottom: calc(24px + var(--asc-chat-consent-h, 148px));
}
.asc-chat.has-consent .asc-chat-panel {
  bottom: calc(24px + var(--asc-chat-consent-h, 148px));
  /* 76px do nav sticky + o offset acima + folga */
  height: min(680px, calc(100vh - 124px - var(--asc-chat-consent-h, 148px)));
}

/* ─── Modo expandido ─── */
.asc-chat.is-expanded .asc-chat-panel {
  width: min(980px, calc(100vw - 48px));
  height: calc(100vh - 48px);
}
.asc-chat.is-expanded {
  --asc-chat-iframe-head-offset: 76px;
}
/* expandido ocupa a altura toda: volta para a base e sobrepoe o banner */
.asc-chat.is-expanded.has-consent .asc-chat-panel {
  bottom: 24px;
  height: calc(100vh - 48px);
  z-index: 10002;
}

/* ─── Mobile: painel ocupa a tela toda ─── */
@media (max-width: 640px) {
  .asc-chat-launcher {
    right: 16px;
    bottom: 16px;
    height: 56px;
    padding: 0 18px 0 14px;
  }
  .asc-chat-panel,
  .asc-chat.is-expanded .asc-chat-panel,
  .asc-chat.has-consent .asc-chat-panel,
  .asc-chat.is-expanded.has-consent .asc-chat-panel {
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    border: 0;
    /* em tela cheia o painel cobre o banner de consentimento */
    z-index: 10002;
  }
  /* no mobile o banner ocupa quase metade da tela; o offset medido pelo JS
     ja cobre isso, so reduzimos a folga lateral */
  .asc-chat.has-consent .asc-chat-launcher {
    bottom: calc(16px + var(--asc-chat-consent-h, 148px));
  }
  /* expandir nao faz sentido em telas pequenas — o painel ja e fullscreen.
     Especificidade precisa igualar .asc-chat-head-actions button. */
  .asc-chat-head-actions button.asc-chat-expand { display: none; }
}

@media (min-width: 561px) and (max-width: 640px) {
  .asc-chat {
    --asc-chat-iframe-head-offset: 76px;
  }
}

@media (max-width: 560px) {
  .asc-chat,
  .asc-chat.is-expanded {
    --asc-chat-iframe-head-offset: 72px;
  }
}

/* ─── Dark mode ─── */
:root[data-theme="dark"] .asc-chat-panel,
.asc-dark .asc-chat-panel {
  border-color: var(--asc-border);
  box-shadow:
    0 38px 70px -28px rgba(0, 0, 0, .75),
    0 12px 28px -12px rgba(0, 0, 0, .55);
}

/* ─── Acessibilidade: respeita reducao de movimento ─── */
@media (prefers-reduced-motion: reduce) {
  .asc-chat-launcher,
  .asc-chat-panel,
  .asc-chat-loader {
    transition-duration: .01ms;
  }
  .asc-chat-launcher::after,
  .asc-chat-loader-dots span {
    animation: none;
  }
  .asc-chat-launcher::after { opacity: 0; }
}
