/* ============================================
   COMPONENTES — WhatsApp UI Components
   AG Radiografar — Gra PoC
   ============================================ */

/* === RESET & BASE === */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  font-family: var(--wa-font-family);
  background: var(--wa-bg-desktop);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* === PHONE CONTAINER === */
.phone-container {
  width: 100%;
  max-width: var(--wa-mobile-max-w);
  height: 100vh;
  height: 100dvh;
  max-height: var(--wa-mobile-max-h);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  background: var(--wa-bg-chat);
}

@media (min-width: 481px) {
  .phone-container {
    border-radius: var(--wa-radius-phone);
    box-shadow: var(--wa-shadow-phone);
    margin-top: calc((100vh - var(--wa-mobile-max-h)) / 2);
  }
}

@media (max-width: 480px) {
  .phone-container {
    max-height: none;
    border-radius: 0;
  }
}

/* === HEADER === */
.chat-header {
  display: flex;
  align-items: center;
  height: var(--wa-header-height);
  background: var(--wa-green-dark);
  color: var(--wa-text-header);
  padding: 0 16px;
  box-shadow: var(--wa-shadow-header);
  z-index: var(--wa-z-header);
  flex-shrink: 0;
}

.chat-header__back {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: none;
  border: none;
  color: var(--wa-text-header);
  cursor: pointer;
  flex-shrink: 0;
}

.chat-header__back svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.chat-header__avatar {
  width: var(--wa-avatar-header);
  height: var(--wa-avatar-header);
  border-radius: 50%;
  margin: 0 12px 0 4px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--wa-green-teal);
}

.chat-header__info {
  flex: 1;
  min-width: 0;
  line-height: 1.3;
}

.chat-header__name {
  font-size: var(--wa-font-header);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-header__status {
  font-size: var(--wa-font-subtitle);
  color: var(--wa-text-subtitle);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: opacity var(--wa-anim-fade);
}

.chat-header__actions {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-left: 8px;
}

.chat-header__actions button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  background: none;
  border: none;
  color: var(--wa-text-header);
  cursor: pointer;
}

.chat-header__actions svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

/* === CHAT AREA === */
.chat-area {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--wa-chat-padding);
  scroll-behavior: smooth;
  position: relative;
  background-color: var(--wa-bg-chat);
  background-image: url('../assets/wallpaper-whatsapp.png');
  background-repeat: repeat;
  background-size: 412.5px auto;
}

/* scrollbar personalizada */
.chat-area::-webkit-scrollbar {
  width: 6px;
}
.chat-area::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.2);
  border-radius: 3px;
}

/* === DATE SEPARATOR === */
.date-separator {
  display: flex;
  justify-content: center;
  margin: var(--wa-bubble-gap-diff) auto;
}

.date-separator__label {
  background: rgba(255, 255, 255, 0.9);
  border-radius: var(--wa-radius-date);
  padding: 4px 12px;
  font-size: var(--wa-font-date-sep);
  font-weight: 500;
  color: var(--wa-text-secondary);
  box-shadow: var(--wa-shadow-date);
  text-transform: uppercase;
  letter-spacing: 0.2px;
}

/* === MESSAGE BUBBLES === */
.message {
  display: flex;
  margin-bottom: var(--wa-bubble-gap-same);
  padding: 0 var(--wa-bubble-margin-side);
  animation: bubbleIn var(--wa-anim-bubble);
}

.message + .message--different-sender {
  margin-top: var(--wa-bubble-gap-diff);
}

.message--sent {
  justify-content: flex-end;
}

.message--received {
  justify-content: flex-start;
}

.message__bubble {
  max-width: var(--wa-bubble-max-w);
  padding: var(--wa-bubble-padding);
  box-shadow: var(--wa-shadow-bubble);
  position: relative;
  word-wrap: break-word;
  line-height: var(--wa-line-height);
}

/* Bolha recebida (Gra) */
.message--received .message__bubble {
  background: var(--wa-bubble-recv);
  border-radius: 0 var(--wa-bubble-radius) var(--wa-bubble-radius) var(--wa-bubble-radius);
}

/* Bolha recebida sem tail (mensagem seguida do mesmo remetente) */
.message--received.message--continuation .message__bubble {
  border-radius: var(--wa-bubble-radius);
}

/* Bolha enviada (Paciente) */
.message--sent .message__bubble {
  background: var(--wa-bubble-sent);
  border-radius: var(--wa-bubble-radius) 0 var(--wa-bubble-radius) var(--wa-bubble-radius);
}

/* Bolha enviada sem tail */
.message--sent.message--continuation .message__bubble {
  border-radius: var(--wa-bubble-radius);
}

/* Tail (ponta da bolha) via pseudo-element */
.message--received:not(.message--continuation) .message__bubble::before {
  content: '';
  position: absolute;
  top: 0;
  left: -8px;
  width: 0;
  height: 0;
  border-top: 0 solid transparent;
  border-right: 8px solid var(--wa-bubble-recv);
  border-bottom: 8px solid transparent;
}

.message--sent:not(.message--continuation) .message__bubble::after {
  content: '';
  position: absolute;
  top: 0;
  right: -8px;
  width: 0;
  height: 0;
  border-top: 0 solid transparent;
  border-left: 8px solid var(--wa-bubble-sent);
  border-bottom: 8px solid transparent;
}

/* Texto da mensagem */
.message__text {
  font-size: var(--wa-font-message);
  color: var(--wa-text-primary);
}

/* Metadados (horário + checks) */
.message__meta {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  float: right;
  margin: 4px 0 -4px 8px;
  line-height: 1;
}

.message__time {
  font-size: var(--wa-font-time);
  color: var(--wa-text-time);
}

.message__checks {
  display: inline-flex;
  align-items: center;
}

.message__checks svg {
  width: 16px;
  height: 11px;
}

.message__checks--read svg {
  fill: var(--wa-check-read);
}

.message__checks--sent svg {
  fill: var(--wa-check-sent);
}

/* === BOLHA DE IMAGEM === */
.message__image-wrapper {
  border-radius: var(--wa-bubble-radius);
  overflow: hidden;
  max-width: 300px;
  position: relative;
  cursor: pointer;
}

.message__image {
  display: block;
  width: 100%;
  height: auto;
  border-radius: var(--wa-bubble-radius);
}

.message__image-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 20px 6px 4px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.4));
  display: flex;
  justify-content: flex-end;
}

.message__image-overlay .message__time {
  color: #FFFFFF;
}

.message__image-overlay .message__checks svg {
  fill: #FFFFFF;
}

/* Caption abaixo da imagem */
.message__caption {
  padding: 4px 4px 0;
  font-size: var(--wa-font-message);
  color: var(--wa-text-primary);
}

/* === BOLHA DE ÁUDIO === */
.message__audio {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 220px;
  padding: 4px 0;
}

.message__audio-play {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: none;
  color: var(--wa-green-teal);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.message__audio-play svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.message__audio-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
}

.message__audio-track {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.message__audio-bar {
  width: 100%;
  height: 3px;
  background: var(--wa-icon-default);
  border-radius: 2px;
  position: relative;
  overflow: hidden;
}

.message__audio-bar-fill {
  height: 100%;
  background: var(--wa-green-teal);
  border-radius: 2px;
  width: 0%;
}

.message__audio-duration {
  font-size: 11px;
  color: var(--wa-text-time);
}

/* === BOLHA RESUMO (CARD AGENDAMENTO) === */
.message__summary {
  background: var(--wa-bubble-recv);
  border-left: 4px solid var(--wa-green-dark);
  border-radius: 4px;
  padding: 12px;
  font-size: var(--wa-font-message);
}

.message__summary-title {
  font-weight: 600;
  color: var(--wa-green-dark);
  margin-bottom: 8px;
  font-size: 14.5px;
}

.message__summary-row {
  display: flex;
  gap: 6px;
  padding: 3px 0;
  line-height: 1.4;
}

.message__summary-icon {
  flex-shrink: 0;
  width: 20px;
  text-align: center;
}

.message__summary-label {
  font-weight: 500;
  color: var(--wa-text-secondary);
  min-width: 70px;
}

.message__summary-value {
  color: var(--wa-text-primary);
}

.message__summary-divider {
  border: none;
  border-top: 1px solid #E8E8E8;
  margin: 6px 0;
}

/* === TYPING INDICATOR === */
.typing-indicator {
  display: flex;
  justify-content: flex-start;
  padding: 0 var(--wa-bubble-margin-side);
  margin-bottom: var(--wa-bubble-gap-same);
  animation: bubbleIn var(--wa-anim-bubble);
}

.typing-indicator__bubble {
  background: var(--wa-bubble-recv);
  border-radius: 0 var(--wa-bubble-radius) var(--wa-bubble-radius) var(--wa-bubble-radius);
  box-shadow: var(--wa-shadow-bubble);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 4px;
  position: relative;
}

/* Tail do typing indicator */
.typing-indicator__bubble::before {
  content: '';
  position: absolute;
  top: 0;
  left: -8px;
  width: 0;
  height: 0;
  border-top: 0 solid transparent;
  border-right: 8px solid var(--wa-bubble-recv);
  border-bottom: 8px solid transparent;
}

.typing-indicator__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--wa-text-time);
  animation: typingDot var(--wa-anim-typing);
}

.typing-indicator__dot:nth-child(2) {
  animation-delay: 200ms;
}

.typing-indicator__dot:nth-child(3) {
  animation-delay: 400ms;
}

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

/* === INPUT BAR === */
.input-bar {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 4px 6px;
  background: var(--wa-input-bar-bg);
  z-index: var(--wa-z-input);
  flex-shrink: 0;
}

.input-bar__field-wrapper {
  flex: 1;
  display: flex;
  align-items: flex-end;
  background: var(--wa-input-bg);
  border-radius: var(--wa-radius-input);
  padding: 6px 4px 6px 12px;
  min-height: 42px;
}

.input-bar__input {
  flex: 1;
  border: none;
  outline: none;
  font-size: var(--wa-font-input);
  font-family: var(--wa-font-family);
  color: var(--wa-text-primary);
  line-height: 1.35;
  resize: none;
  background: transparent;
  max-height: 100px;
  min-height: 24px;
  overflow-y: auto;
  padding: 4px 0;
}

.input-bar__input::placeholder {
  color: var(--wa-input-placeholder);
}

.input-bar__attach-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 32px;
  background: none;
  border: none;
  color: var(--wa-icon-default);
  cursor: pointer;
  flex-shrink: 0;
  transform: rotate(45deg);
  padding: 0;
  margin: 0 2px 0 8px;
}

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

.input-bar__camera-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 32px;
  background: none;
  border: none;
  color: var(--wa-icon-default);
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
  margin: 0 8px 0 2px;
}

.input-bar__camera-btn svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

.input-bar__action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: var(--wa-radius-btn);
  border: none;
  background: var(--wa-green-dark);
  color: white;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform var(--wa-anim-fade);
}

.input-bar__action-btn:active {
  transform: scale(0.92);
}

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

/* Troca mic ↔ enviar */
.input-bar__action-btn--mic .icon-send,
.input-bar__action-btn--send .icon-mic {
  display: none;
}
.input-bar__action-btn--mic .icon-mic,
.input-bar__action-btn--send .icon-send {
  display: block;
}

/* === ATTACH MENU (popup) === */
.attach-menu {
  position: absolute;
  bottom: calc(var(--wa-input-height) + 8px);
  left: 12px;
  background: white;
  border-radius: var(--wa-radius-attach);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
  z-index: var(--wa-z-overlay);
  overflow: hidden;
  display: none;
}

.attach-menu--open {
  display: block;
  animation: fadeIn var(--wa-anim-fade);
}

.attach-menu__option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  font-size: 15px;
  color: var(--wa-text-primary);
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  font-family: var(--wa-font-family);
}

.attach-menu__option:hover {
  background: #F5F5F5;
}

.attach-menu__option-icon {
  font-size: 20px;
}

/* === HIDDEN FILE INPUT === */
.hidden-input {
  display: none !important;
}

/* === ANIMATIONS === */
@keyframes bubbleIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* === AUDIO RECORDING BAR === */
.recording-bar {
  display: none;
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--wa-input-height);
  background: var(--wa-bg-input-bar);
  align-items: center;
  padding: 0 8px;
  gap: 8px;
  z-index: var(--wa-z-overlay);
}

.recording-bar--active {
  display: flex;
  animation: fadeIn var(--wa-anim-fade);
}

.recording-bar__delete {
  width: 40px;
  height: 40px;
  border: none;
  background: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.recording-bar__delete svg {
  width: 24px;
  height: 24px;
  fill: var(--wa-icon-default);
}

.recording-bar__indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}

.recording-bar__dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #E53935;
  animation: recordingPulse 1s ease-in-out infinite;
}

.recording-bar__timer {
  font-size: 15px;
  color: var(--wa-text-secondary);
  font-variant-numeric: tabular-nums;
  min-width: 40px;
}

.recording-bar__slide-hint {
  font-size: 13px;
  color: var(--wa-text-secondary);
  opacity: 0.7;
}

.recording-bar__send {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: var(--wa-green-dark);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.recording-bar__send svg {
  width: 22px;
  height: 22px;
  fill: white;
}

@keyframes recordingPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* === AUDIO FALLBACK MODAL (no mic support) === */
.audio-modal {
  position: absolute;
  bottom: calc(var(--wa-input-height) + 8px);
  left: 12px;
  right: 12px;
  background: white;
  border-radius: var(--wa-radius-attach);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
  z-index: var(--wa-z-overlay);
  padding: 16px;
  display: none;
}

.audio-modal--open {
  display: block;
  animation: fadeIn var(--wa-anim-fade);
}

.audio-modal__label {
  font-size: 13px;
  color: var(--wa-text-secondary);
  margin-bottom: 8px;
}

.audio-modal__input {
  width: 100%;
  border: 1px solid var(--wa-input-border);
  border-radius: var(--wa-radius-input);
  padding: 10px 14px;
  font-size: var(--wa-font-input);
  font-family: var(--wa-font-family);
  color: var(--wa-text-primary);
  outline: none;
}

.audio-modal__input:focus {
  border-color: var(--wa-green-teal);
}

.audio-modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 10px;
}

.audio-modal__btn {
  padding: 6px 16px;
  border-radius: 16px;
  border: none;
  font-size: 14px;
  font-family: var(--wa-font-family);
  cursor: pointer;
}

.audio-modal__btn--cancel {
  background: #F0F0F0;
  color: var(--wa-text-secondary);
}

.audio-modal__btn--send {
  background: var(--wa-green-dark);
  color: white;
}

/* === TOAST MESSAGE === */
.toast-msg {
  position: absolute;
  bottom: 70px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.82);
  color: #fff;
  font-size: 13px;
  padding: 8px 16px;
  border-radius: 20px;
  z-index: 200;
  text-align: center;
  max-width: 90%;
  animation: toastIn 0.3s ease;
  pointer-events: none;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}
