/* ─────────────────────────────────────────────
   Galaxy Atende — Widget V2
   Visual espelhando o widget mirror SalesMartly,
   sem dependência do bundle minificado.
   ───────────────────────────────────────────── */

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #eee;
  color: #1f2937;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px 16px;
}

.widget {
  width: 100%;
  max-width: 800px;
  height: min(585px, calc(100vh - 48px));
  background: #fff;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* ─── HEADER — espec original: bg #242529, padding 18px 20px, h:44 ─── */
.head {
  background: #242529;
  color: #fff;
  position: relative;
  flex-shrink: 0;
}
.head-inner {
  padding: 18px 20px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}
.brand-logo {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  background: #444;
}
.brand-text h1 {
  font-size: 17px;
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -.01em;
}
.brand-text p {
  font-size: 13px;
  font-weight: 400;
  opacity: .55;
  margin-top: 3px;
}

/* ─── BULLETIN BAR (fixo no topo da área de mensagens) ─── */
.bulletin {
  display: flex;
  align-items: center;
  gap: 10px;
  position: sticky;
  top: 12px;
  z-index: 5;
  margin: 0 12px 12px 12px;
  padding: 11px 14px;
  border-radius: 8px;
  color: #fff;
  text-decoration: none;
  font-size: 13px;
  box-shadow: 0 4px 12px rgba(246, 110, 91, .25);
}
.bulletin-text {
  flex: 1;
  text-decoration: underline;
  text-underline-offset: 2px;
  font-weight: 500;
}
.bulletin-close {
  background: transparent;
  border: 0;
  color: #fff;
  cursor: pointer;
  opacity: .7;
  display: flex;
  align-items: center;
  padding: 2px;
  border-radius: 4px;
  flex-shrink: 0;
}
.bulletin-close:hover { opacity: 1; }

/* ─── MENSAGENS ──────────────────────────── */
.msgs {
  flex: 1;
  overflow-y: auto;
  padding: 12px 0;
  background: #fff;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}
.msgs::-webkit-scrollbar { width: 6px; }
.msgs::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 4px; }
.msgs > .row { padding: 0 16px; }

.row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  max-width: 100%;
}
.row-bot, .row-agent { justify-content: flex-start; }
.row-visitor {
  justify-content: flex-end;
  align-items: flex-end;
}
.row-system {
  justify-content: center;
  align-items: center;
}

.msg-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  flex-shrink: 0;
  object-fit: cover;
  background: #ddd;
  align-self: flex-end;
}
.msg-avatar.avatar-hidden { visibility: hidden; }
.row-visitor .msg-avatar { display: none; }
.row-system .msg-avatar { display: none; }

.bubble-col {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: calc(100% - 56px);
  min-width: 0;
}
.row-visitor .bubble-col { align-items: flex-end; max-width: 78%; }

.sender-name {
  font-size: 11px;
  color: #6b7280;
  margin-bottom: -2px;
  padding: 0 6px;
}

.bubble {
  padding: 12px 20px;
  font-size: 14px;
  line-height: 1.55;
  word-wrap: break-word;
  word-break: break-word;
  white-space: normal;
}
.bubble a { color: #2563eb; text-decoration: underline; }
.bubble strong { font-weight: 600; }
.bubble em { font-style: italic; }
.bubble code {
  background: rgba(0,0,0,.06);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: 'Courier New', monospace;
  font-size: 13px;
}
.bubble ol, .bubble ul { padding-left: 20px; margin: 4px 0; }
.bubble p { margin: 0; }
.bubble p + p { margin-top: 6px; }

/* espec original: rgba(84,152,243,.08), radius 12 12 12 3 */
.bubble-bot,
.bubble-agent {
  background: rgba(84, 152, 243, 0.08);
  color: #252525;
  border-radius: 12px 12px 12px 3px;
}
/* visitor é à direita: canto inferior direito puxado */
.bubble-visitor {
  background: #1a1d23;
  color: #fff;
  border-radius: 12px 12px 3px 12px;
}
.bubble-visitor a { color: #93c5fd; }

/* attachments */
.att-wrap {
  padding: 4px;
  border-radius: 12px;
  display: inline-block;
  max-width: 100%;
}
.att-wrap.bubble-bot   { background: #eaf1fb; }
.att-wrap.bubble-agent { background: #fff; border: 1px solid #e5e7eb; }
.att-wrap.bubble-visitor { background: #1f2937; }
.att-img {
  max-width: 100%;
  max-height: 240px;
  border-radius: 8px;
  display: block;
  cursor: zoom-in;
}
.att-video, .att-audio { max-width: 100%; max-height: 240px; border-radius: 8px; display: block; }
.att-file {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  color: inherit;
  text-decoration: none;
  font-size: 13px;
}

/* botões DENTRO do balão. espec original: bg #fff, h:30, radius:30, padding:0 10, font:14 */
.bubble-text + .btns,
.btns:not(:first-child) { margin-top: 12px; }
.btns {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.btn-bot {
  background: #fff;
  border: 0;
  border-radius: 30px;
  height: 30px;
  padding: 0 10px;
  cursor: pointer;
  font-size: 14px;
  color: #252525;
  transition: background-color .12s;
  text-align: center;
  font-family: inherit;
  width: 100%;
  box-shadow: none;
}
.btn-bot:hover { background: #f5f7fa; }
.btn-bot:active { background: #ebeef2; }

/* system event */
.sys-event {
  font-size: 12px;
  color: #9ca3af;
  font-style: italic;
  text-align: center;
  padding: 4px 8px;
}

/* typing */
/* typing — usa .row .row-bot, herda alinhamento das msgs (avatar 40 + bolha) */
.typing-dots {
  width: max-content;
  padding: 5px 10px;
  border-radius: 12px;
  background: rgba(84, 152, 243, .08);
  box-shadow: rgba(0, 0, 0, .02) 0 2px 12px;
  line-height: 26px;
  text-align: left;
  white-space: nowrap;
}
.typing-dots span {
  display: inline-block;
  height: 4px;
  width: 4px;
  margin: 11px 1px 0;
  border-radius: 50%;
  background-color: #000;
  opacity: .4;
  animation: typing-blink 1.3s linear infinite;
}
.typing-dots span:first-child { margin-left: 4px; }
.typing-dots span:nth-child(2) { animation-delay: -1.1s; }
.typing-dots span:nth-child(3) { animation-delay: -0.9s; }
@keyframes typing-blink {
  0%, 60%, 100% { transform: none; }
  30% { transform: translateY(-5px); }
}

/* ─── INPUT BAR — espec original: bg transparente, padding 0 20px 10px, sem border ─── */
.input-bar {
  background: #fff;
  border-top: 0;
  padding: 0 20px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex-shrink: 0;
  position: relative;
}
.input-bar.disabled { opacity: .6; pointer-events: none; }

.att-preview {
  width: 100%;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding-bottom: 6px;
}
.att-thumb {
  position: relative;
  width: 56px;
  height: 56px;
  border-radius: 8px;
  overflow: hidden;
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
  display: flex;
  align-items: center;
  justify-content: center;
}
.att-thumb img { width: 100%; height: 100%; object-fit: cover; }
.att-icon { font-size: 24px; }
.att-remove {
  position: absolute;
  top: -6px; right: -6px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: #1f2937;
  color: #fff;
  border: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  line-height: 1;
}
.att-loading { animation: pulse 1.2s infinite; font-size: 22px; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .5; } }

/* input no topo, fica em uma linha sozinho */
.input-text {
  width: 100%;
  border: 0;
  padding: 14px 0 8px;
  font-size: 14px;
  color: #252525;
  background: transparent;
  outline: none;
  font-family: inherit;
}
.input-text::placeholder { color: #9ca3af; }

/* action-row: 4 ícones à ESQUERDA + send à DIREITA, na mesma linha */
.action-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0 4px;
}
.action-left {
  display: flex;
  gap: 22px;
  align-items: center;
}

/* ─── Emoji popover (espec original: 328×240, bg #fff, radius 21, shadow azul) ─── */
.emoji-wrap {
  position: relative;
  display: inline-flex;
}
.emoji-popover {
  position: absolute;
  bottom: calc(100% + 12px);
  left: 0;
  width: 328px;
  height: 240px;
  background: #fff;
  border-radius: 21px;
  box-shadow: rgb(108, 129, 167) 0 4px 20px 0;
  padding: 15px;
  z-index: 50;
}
.emoji-grid {
  width: 100%;
  height: 100%;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0;
}
.emoji-grid::-webkit-scrollbar { width: 4px; }
.emoji-grid::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 2px; }
.emoji-item {
  width: 46px;
  height: 46px;
  background: transparent;
  border: 0;
  cursor: pointer;
  font-size: 22px;
  border-radius: 6px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color .12s, transform .08s;
  font-family: 'Apple Color Emoji', 'Segoe UI Emoji', 'Noto Color Emoji', 'Twemoji Mozilla', sans-serif;
  line-height: 1;
}
.emoji-item:hover { transform: scale(1.3); }
.action-btn {
  position: relative;
  width: 22px;
  height: 30px;
  border: 0;
  background: transparent;
  color: #000;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: opacity .12s;
}
.action-btn::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(0, 69, 176, 0.15);
  transform: translate(-50%, -50%) scale(0);
  transition: transform .2s;
  z-index: 0;
}
.action-btn:hover::before { transform: translate(-50%, -50%) scale(1); }
.action-btn svg { position: relative; z-index: 1; width: 22px; height: 22px; stroke-width: 1.6; opacity: .55; }
.action-btn:hover svg { opacity: 1; color: rgb(0, 69, 176); }
.action-btn:disabled { opacity: .4; cursor: not-allowed; }
.action-btn:disabled::before { display: none; }

/* send: espec original 60×32 line-height, bg #242529, radius 40, shadow sutil, ícone diagonal */
.send-btn {
  width: 60px;
  height: 32px;
  border-radius: 40px;
  border: 0;
  background: #242529;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  margin-left: 5px;
  flex-shrink: 0;
  box-shadow: rgba(0, 0, 0, .02) 0 2px 12px;
}
.send-btn:disabled { opacity: .4; cursor: not-allowed; }
.send-btn .send-icon {
  width: 18px;
  height: 18px;
  transform: rotate(-45deg) translateX(1px);
  transition: transform .3s ease-in;
}
.send-btn:hover:not(:disabled) .send-icon { transform: rotate(-45deg) translateX(1px) scale(1.4); }

/* ─── MOBILE ─────────────────────────────── */
@media (max-width: 820px) {
  .page { padding: 0; }
  .widget {
    border-radius: 0;
    height: 100vh;
    max-width: 100%;
  }
  .bubble-col { max-width: calc(100% - 56px); }
  .row-visitor .bubble-col { max-width: 80%; }
}
