:root {
  --wa-header: #075e54;
  --wa-header-dark: #054c44;
  --wa-bg: #e5ddd5;
  --wa-green: #25d366;
  --wa-bubble-out: #dcf8c6;
  --wa-bubble-in: #ffffff;
  --wa-text: #111b21;
  --wa-muted: #667781;
}

* { box-sizing: border-box; }

/* Garante que [hidden] sempre esconda o elemento, mesmo quando alguma
   classe (ex.: .icon-btn, .mic-btn, .recording-indicator) define um
   `display` próprio — sem isso, o `display` da classe vence o `hidden`. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #0b141a;
  color: var(--wa-text);
}

.phone-frame {
  height: 100dvh;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  background: var(--wa-bg);
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

@media (min-width: 481px) {
  body {
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .phone-frame {
    height: min(100dvh, 850px);
    border-radius: 16px;
    margin: 16px auto;
  }
}

.chat-app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* Header */
.chat-header {
  background: var(--wa-header);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  flex-shrink: 0;
}

.icon-btn {
  background: none;
  border: none;
  color: #fff;
  padding: 4px;
  display: flex;
  cursor: pointer;
}

.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: #ffffff33;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  flex-shrink: 0;
  overflow: hidden;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.header-info {
  flex: 1;
  min-width: 0;
}

.header-name {
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-status {
  font-size: 12.5px;
  color: #d9fdd3;
}

.header-icons {
  display: flex;
  gap: 18px;
  opacity: 0.9;
}

/* Messages */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 8% 14px 8%;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background-image: radial-gradient(#00000008 1px, transparent 1px);
  background-size: 18px 18px;
}

.bubble-row {
  display: flex;
  margin: 3px 0;
}

.bubble-row.in { justify-content: flex-start; }
.bubble-row.out { justify-content: flex-end; }

.bubble {
  max-width: 78%;
  padding: 7px 9px 8px 10px;
  border-radius: 8px;
  font-size: 14.5px;
  line-height: 1.35;
  white-space: pre-wrap;
  word-wrap: break-word;
  box-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.13);
  position: relative;
}

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

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

.bubble-time {
  font-size: 10.5px;
  color: var(--wa-muted);
  float: right;
  margin: 4px 0 -3px 8px;
  display: flex;
  align-items: center;
  gap: 2px;
}

.bubble-ticks {
  display: inline-flex;
  color: var(--wa-muted);
}

.bubble-ticks.read {
  color: #4fc3f7;
}

.media-bubble {
  padding: 4px;
  max-width: 78%;
  min-width: 200px;
}

.media-content {
  display: block;
  width: 100%;
  max-height: 320px;
  object-fit: cover;
  border-radius: 5px;
  background: #00000010;
}

video.media-content {
  background: #000;
  object-fit: contain;
}

.media-caption {
  padding: 6px 6px 0 6px;
  font-size: 14.5px;
  line-height: 1.35;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.media-bubble-time {
  display: block;
  text-align: right;
  padding: 3px 6px 2px 6px;
  float: none;
}

.media-error {
  padding: 16px;
  font-size: 13.5px;
  color: var(--wa-muted);
  text-align: center;
}

.audio-bubble {
  padding: 8px 10px;
  min-width: 220px;
}

.audio-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.audio-play-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: var(--wa-header);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
}

.audio-play-btn:disabled {
  background: #b7c4c1;
  cursor: not-allowed;
}

.audio-track {
  flex: 1;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: linear-gradient(to right, var(--wa-header) 0%, var(--wa-header) var(--_progress, 0%), #d7d7d7 var(--_progress, 0%));
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

.audio-track::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--wa-header);
  cursor: pointer;
}

.audio-track::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border: none;
  border-radius: 50%;
  background: var(--wa-header);
  cursor: pointer;
}

.audio-time {
  font-size: 11.5px;
  color: var(--wa-muted);
  flex-shrink: 0;
  min-width: 30px;
  text-align: right;
}

.audio-bubble-time {
  display: block;
  text-align: right;
  margin-top: 4px;
  float: none;
}

.typing-bubble {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 10px 12px;
}

.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #9aa5aa;
  animation: typing-bounce 1s infinite ease-in-out;
}

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

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

.recording-bubble .mic-pulse-icon {
  color: var(--wa-header);
  animation: mic-pulse 1.1s infinite ease-in-out;
}

@keyframes mic-pulse {
  0%, 100% { transform: scale(1); opacity: 0.6; }
  50% { transform: scale(1.2); opacity: 1; }
}

/* Footer / input */
.chat-footer {
  flex-shrink: 0;
  background: #f0f0f0;
}

.quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 12px 0 12px;
}

.quick-reply-btn {
  border: 1.5px solid var(--wa-header);
  color: var(--wa-header);
  background: #fff;
  border-radius: 18px;
  padding: 8px 16px;
  font-size: 14px;
  cursor: pointer;
}

.quick-reply-btn:hover { background: #e9f9f1; }

.chat-input-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
}

.chat-input {
  flex: 1;
  border: none;
  border-radius: 22px;
  padding: 11px 16px;
  font-size: 15px;
  background: #fff;
  outline: none;
}

.chat-input:disabled {
  background: #e9e9e9;
  color: #999;
}

.send-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: var(--wa-header);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

.send-btn:disabled {
  background: #b7c4c1;
  cursor: not-allowed;
}

.mic-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: var(--wa-header);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

.mic-btn.recording {
  background: #e53935;
  animation: mic-btn-pulse 1.3s infinite ease-in-out;
}

@keyframes mic-btn-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(229, 57, 53, 0.45); }
  50% { box-shadow: 0 0 0 8px rgba(229, 57, 53, 0); }
}

.cancel-recording-btn {
  color: var(--wa-muted);
  flex-shrink: 0;
}

.recording-indicator {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 4px;
  color: var(--wa-muted);
  font-size: 14px;
}

.recording-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #e53935;
  animation: recording-dot-blink 1s infinite ease-in-out;
  flex-shrink: 0;
}

@keyframes recording-dot-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.25; }
}

#recordingTimer {
  font-variant-numeric: tabular-nums;
  color: var(--wa-text);
}

.recording-hint {
  color: var(--wa-muted);
}
