/* Composer público — visual estilo WhatsApp (mobile-first) */

:root {
  --wa-header: #075e54;
  --wa-header-light: #128c7e;
  --wa-bg: #efeae2;
  --wa-bg-pattern: #d9d0c6;
  --wa-incoming: #ffffff;
  --wa-outgoing: #d9fdd3;
  --wa-outgoing-border: #c8f0c0;
  --wa-text: #111b21;
  --wa-text-muted: #667781;
  --wa-input-bg: #ffffff;
  --wa-input-border: #e0e0e0;
  --wa-send: #00a884;
  --wa-send-hover: #008f72;
  --wa-time: rgba(17, 27, 33, 0.45);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  /* No Chrome iOS o safe-area costuma ser 0; garante respiro mínimo. */
  --pad-x: 0.9rem;
  --pad-bar-y: 0.7rem;
  --pad-bar-bottom: calc(var(--pad-bar-y) + max(0.35rem, var(--safe-bottom)));
  --composer-h: 72px;
  --composer-viewport-height: 100%;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  touch-action: none;
}

html {
  position: fixed;
  inset: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--wa-bg);
  color: var(--wa-text);
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.composer-app {
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
  max-width: 720px;
  margin: 0 auto;
  background: var(--wa-bg);
  box-shadow: 0 0 24px rgba(0, 0, 0, 0.08);
  overscroll-behavior: none;
  touch-action: none;
  /* Altura/transform aplicados via JS (visualViewport) no iOS. */
}

/* Área do chat */
.chat-shell {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  background-color: var(--wa-bg);
  background-image:
    radial-gradient(circle at 20% 20%, rgba(0, 0, 0, 0.018) 0 1px, transparent 1px),
    radial-gradient(circle at 80% 40%, rgba(0, 0, 0, 0.018) 0 1px, transparent 1px),
    radial-gradient(circle at 40% 80%, rgba(0, 0, 0, 0.018) 0 1px, transparent 1px);
  background-size: 28px 28px, 32px 32px, 24px 24px;
}

.wa-chat-header {
  flex: 0 0 auto;
  background: var(--wa-header);
  color: #fff;
  padding: calc(0.75rem + var(--safe-top)) var(--pad-x) 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.wa-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #25d366, #128c7e);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  flex-shrink: 0;
}

.wa-chat-meta h1 {
  font-size: 1rem;
  font-weight: 500;
  line-height: 1.2;
}

.wa-chat-meta p {
  font-size: 0.78rem;
  opacity: 0.85;
  margin-top: 0.1rem;
}

.wa-chat-meta p.is-warming {
  opacity: 0.65;
}

.wa-chat-meta p.is-ready {
  opacity: 0.85;
}

.messages-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  padding: 1rem var(--pad-x) 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  -webkit-user-select: text;
  user-select: text;
}

.chat-notice {
  align-self: center;
  width: min(100%, 520px);
  margin: 0.15rem auto 0.45rem;
  padding: 0.55rem 0.7rem;
  border-radius: 7px;
  background: #fff9e2;
  border: 1px solid rgba(218, 178, 55, 0.35);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.04);
}

.chat-notice p {
  font-size: 0.78rem;
  line-height: 1.45;
  color: #3f4f44;
  text-align: center;
}

.chat-notice strong {
  font-weight: 600;
  color: #2f3d34;
}

.chat-notice-icon {
  display: inline-block;
  margin-right: 0.2rem;
  font-size: 0.82rem;
  line-height: 1;
  vertical-align: -0.05em;
}

.msg-row {
  display: flex;
  width: 100%;
}

.msg-row.incoming {
  justify-content: flex-start;
}

.msg-row.outgoing {
  justify-content: flex-end;
}

.bubble {
  max-width: min(88%, 520px);
  padding: 0.45rem 0.65rem 0.35rem;
  border-radius: 8px;
  position: relative;
  font-size: 0.94rem;
  line-height: 1.45;
  word-wrap: break-word;
  box-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.08);
}

.bubble.has-photo {
  padding: 0;
  overflow: hidden;
}

.bubble.has-photo .bubble-content {
  padding: 0.45rem 0.65rem 0.35rem;
}

.bubble-body {
  white-space: pre-wrap;
  word-break: break-word;
}

.bubble a {
  color: #027eb5;
  text-decoration: underline;
  word-break: break-all;
}

.bubble.outgoing a {
  color: #006d5b;
}

.bubble-photo-wrap {
  width: 100%;
  line-height: 0;
  background: rgba(0, 0, 0, 0.04);
}

.bubble-photo {
  display: block;
  width: 100%;
  max-width: none;
  margin: 0;
  border-radius: 0;
  height: auto;
  object-fit: contain;
  background: rgba(0, 0, 0, 0.04);
}

.bubble-share {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.55rem;
  padding-top: 0.5rem;
  border-top: 1px solid rgba(0, 0, 0, 0.06);
}

.share-btn {
  flex: 1 1 calc(50% - 0.2rem);
  min-width: 7.5rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.42rem 0.55rem;
  border: none;
  border-radius: 999px;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  color: #fff;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}

.share-btn:hover:not(:disabled) {
  opacity: 0.92;
}

.share-btn:active:not(:disabled) {
  transform: scale(0.98);
}

.share-btn:disabled {
  opacity: 0.55;
  cursor: wait;
}

.share-btn svg {
  width: 1rem;
  height: 1rem;
  fill: currentColor;
  flex-shrink: 0;
}

.share-btn.telegram {
  background: #229ed9;
}

.share-btn.whatsapp {
  background: #25d366;
}

.bubble.incoming {
  background: var(--wa-incoming);
  border-top-left-radius: 0;
}

.bubble.outgoing {
  background: var(--wa-outgoing);
  border: 1px solid var(--wa-outgoing-border);
  border-top-right-radius: 0;
}

.bubble .time {
  display: block;
  text-align: right;
  font-size: 0.68rem;
  color: var(--wa-time);
  margin-top: 0.2rem;
  line-height: 1;
}

.bubble.welcome {
  background: rgba(255, 255, 255, 0.92);
  max-width: 92%;
  font-size: 0.88rem;
  color: var(--wa-text-muted);
  text-align: center;
  margin: 0.5rem auto;
  border-radius: 10px;
  box-shadow: none;
  border: 1px dashed rgba(0, 0, 0, 0.08);
}

.bubble.welcome code {
  font-size: 0.82em;
  background: rgba(0, 0, 0, 0.05);
  padding: 0.05rem 0.25rem;
  border-radius: 4px;
}

/* Indicador "digitando..." */
.typing-row {
  display: none;
  width: 100%;
  justify-content: flex-start;
}

.typing-row.active {
  display: flex;
}

.typing-bubble {
  background: var(--wa-incoming);
  border-radius: 8px;
  border-top-left-radius: 0;
  padding: 0.55rem 0.85rem;
  display: flex;
  align-items: center;
  gap: 4px;
  box-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.08);
}

.typing-bubble span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #90a4ae;
  animation: wa-typing 1.2s infinite ease-in-out;
}

.typing-bubble span:nth-child(2) { animation-delay: 0.15s; }
.typing-bubble span:nth-child(3) { animation-delay: 0.3s; }

@keyframes wa-typing {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.45; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* Composer inferior */
.composer-bar {
  flex: 0 0 auto;
  background: #f0f2f5;
  padding: var(--pad-bar-y) var(--pad-x) var(--pad-bar-bottom);
  display: flex;
  align-items: flex-end;
  gap: 0.55rem;
  border-top: 1px solid rgba(0, 0, 0, 0.06);
}

.composer-input-wrap {
  flex: 1 1 auto;
  background: var(--wa-input-bg);
  border-radius: 24px;
  border: 1px solid var(--wa-input-border);
  padding: 0.55rem 0.85rem;
  min-height: 42px;
  max-height: 120px;
  overflow-y: auto;
  touch-action: manipulation;
  -webkit-user-select: text;
  user-select: text;
}

.composer-input {
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  font-family: inherit;
  /* 16px evita zoom automático do Chrome/Safari iOS ao focar. */
  font-size: 16px;
  line-height: 1.4;
  background: transparent;
  color: var(--wa-text);
  max-height: 96px;
  touch-action: manipulation;
  -webkit-user-select: text;
  user-select: text;
}

.composer-input::placeholder {
  color: #9aa0a6;
}

.send-btn {
  flex: 0 0 auto;
  width: 46px;
  height: 46px;
  border: none;
  border-radius: 50%;
  background: var(--wa-send);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, opacity 0.15s;
}

.send-btn:hover:not(:disabled) {
  background: var(--wa-send-hover);
}

.send-btn:active:not(:disabled) {
  transform: scale(0.96);
}

.send-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.send-btn svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.error-toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--composer-h) + var(--safe-bottom) + 12px);
  top: auto;
  transform: translateX(-50%) translateY(12px);
  background: #323739;
  color: #fff;
  padding: 0.55rem 0.9rem;
  border-radius: 8px;
  font-size: 0.85rem;
  max-width: min(92%, 420px);
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 50;
}

.error-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (min-width: 721px) {
  .composer-app {
    border-left: 1px solid rgba(0, 0, 0, 0.06);
    border-right: 1px solid rgba(0, 0, 0, 0.06);
  }
}

@media (max-width: 380px) {
  .bubble {
    max-width: 92%;
    font-size: 0.9rem;
  }
}
