/**
 * Central de Atendimento — Área do Cliente
 * Layout WhatsApp · Mobile First · CSS isolado
 */

html:has(body.leeh-chat-active),
body.leeh-chat-active {
  overflow: hidden;
  height: 100dvh;
  max-height: 100dvh;
}

body.leeh-chat-active #app {
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
}

body.leeh-chat-active .portal-views {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

body.leeh-chat-active .portal-header {
  display: none;
}

body.leeh-chat-active .portal-shell {
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

body.leeh-chat-active .portal-main {
  flex: 1;
  min-height: 0;
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

body.leeh-chat-active #portalView-atendimento {
  flex: 1;
  min-height: 0;
  display: flex !important;
  flex-direction: column;
  overflow: hidden;
}

body.leeh-chat-active #portalView-atendimento[hidden] {
  display: none !important;
}

body.leeh-chat-active .portal-nav {
  display: none !important;
}

body.leeh-chat-active .portal-view:not([data-route="atendimento"]) {
  display: none !important;
}

body.leeh-chat-active .portal-shell {
  max-width: none;
  margin: 0;
  width: 100%;
}

/* Root */
.leeh-chat {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #0a0618;
  color: #f5f6fb;
}

.leeh-chat-screen {
  flex: 1;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* Header fixo (topo) */
.leeh-chat-header {
  flex: 0 0 auto;
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: auto auto 1fr;
  align-items: center;
  gap: 10px;
  height: 59px;
  min-height: 59px;
  padding: 0 12px 0 4px;
  background: rgba(12, 7, 28, 0.98);
  border-bottom: 1px solid rgba(124, 92, 255, 0.12);
}

.leeh-chat-back,
.leeh-chat-menu {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: #f5f6fb;
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}

.leeh-chat-menu {
  display: none;
}

.leeh-chat-header-avatar {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: rgba(124, 92, 255, 0.22);
  font-size: 18px;
}

.leeh-chat-header-info {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

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

.leeh-chat-header-status {
  font-size: 13px;
  color: #9d7bff;
  text-transform: lowercase;
}

.leeh-chat-header.is-admin {
  grid-template-columns: auto auto 1fr auto;
  height: auto;
  min-height: 64px;
  padding: 8px 8px 8px 4px;
  align-items: center;
}

.leeh-chat-header-meta {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.leeh-chat-header-phone {
  font-size: 12px;
  color: rgba(245, 246, 251, 0.78);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.leeh-chat-header-phone.is-empty {
  color: rgba(245, 246, 251, 0.45);
}

.leeh-chat.is-admin .leeh-chat-header-status {
  text-transform: none;
  color: #9d7bff;
  font-size: 12px;
}

.leeh-chat-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.leeh-chat-action-btn {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  color: #f5f6fb;
  font-size: 16px;
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
}

.leeh-chat-action-btn:active {
  transform: scale(0.94);
  background: rgba(124, 92, 255, 0.28);
}

.leeh-chat-action-btn.is-copied {
  background: rgba(46, 204, 113, 0.28);
}

/* Mensagens — único scroll */
.container-messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 2px;
  padding: 8px 12px 12px;
  scroll-behavior: smooth;
  background:
    radial-gradient(circle at 20% 20%, rgba(124, 92, 255, 0.06), transparent 35%),
    radial-gradient(circle at 80% 0%, rgba(157, 123, 255, 0.05), transparent 40%),
    #0a0618;
}

.container-messages > * {
  flex-shrink: 0;
  min-height: 0;
}

/* Balões */
.atendimento-bubble {
  max-width: 65%;
  padding: 6px 8px 8px 9px;
  border-radius: 8px;
  border: 0;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.12);
  animation: leehChatFade 0.18s ease;
}

.atendimento-bubble.is-media-image {
  max-width: min(85vw, 420px);
  width: fit-content;
  padding: 4px;
  line-height: 0;
  flex-shrink: 0;
}

.atendimento-bubble.is-media-image.is-mine {
  border-bottom-right-radius: 6px;
}

.atendimento-bubble.is-media-image.is-theirs {
  border-bottom-left-radius: 6px;
}

.atendimento-bubble.is-mine {
  align-self: flex-end;
  background: linear-gradient(180deg, rgba(124, 92, 255, 0.42), rgba(106, 78, 230, 0.36));
  border-bottom-right-radius: 2px;
  margin-left: auto;
}

.atendimento-bubble.is-theirs {
  align-self: flex-start;
  background: rgba(22, 14, 38, 0.92);
  border-bottom-left-radius: 2px;
  margin-right: auto;
}

.atendimento-bubble.is-system-welcome {
  max-width: min(92%, 420px);
}

.atendimento-bubble.is-grouped {
  margin-top: 1px;
}

.atendimento-bubble.is-grouped .atendimento-meta {
  display: none;
}

.atendimento-text {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14.2px;
  line-height: 19px;
  color: #f5f6fb;
}

.atendimento-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 2px;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.55);
}

.atendimento-ticks {
  font-size: 11px;
  letter-spacing: -2px;
  color: rgba(255, 255, 255, 0.45);
}

.atendimento-ticks.is-read {
  color: #9d7bff;
}

.atendimento-day-separator,
.wa-day-separator {
  align-self: center;
  margin: 10px 0 6px;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.72);
  background: rgba(18, 10, 38, 0.88);
  padding: 5px 12px 6px;
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.18);
}

.leeh-chat-empty {
  margin: auto;
  text-align: center;
  color: #a3adc9;
  font-size: 13px;
  padding: 24px;
}

/* Upload */
.leeh-chat-upload {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  align-items: center;
  padding: 8px 12px;
  background: rgba(124, 92, 255, 0.12);
  border-top: 1px solid rgba(124, 92, 255, 0.2);
  font-size: 12px;
}

.leeh-chat-upload[hidden] {
  display: none !important;
}

.leeh-chat-upload-track {
  grid-column: 1 / -1;
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.leeh-chat-upload-track span {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #7c5cff, #22c98b);
  transition: width 0.15s ease;
}

.leeh-chat-upload-cancel {
  border: 0;
  background: transparent;
  color: #ffb3c0;
  cursor: pointer;
  font-size: 12px;
}

/* Composer fixo (rodapé) */
.leeh-chat-footer {
  flex: 0 0 auto;
  position: sticky;
  bottom: 0;
  z-index: 5;
  background: rgba(12, 7, 28, 0.98);
  border-top: 1px solid rgba(124, 92, 255, 0.1);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
}

.leeh-chat-composer {
  display: block;
  margin: 0;
}

.leeh-chat-composer-row {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  width: 100%;
}

.leeh-chat-composer-main {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: flex-end;
  gap: 2px;
}

.leeh-chat-composer-main[hidden] {
  display: none !important;
}

.leeh-chat-voice {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 24px;
  margin: 0 2px;
}

.leeh-chat-voice-cancel {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 90, 122, 0.16);
  color: #ff8fa3;
  cursor: pointer;
}

.leeh-chat-voice-cancel:active {
  transform: scale(0.96);
}

.leeh-chat-send.is-voice-send {
  background: linear-gradient(135deg, #7c5cff, #9d7bff);
}

.leeh-chat-voice[hidden] {
  display: none !important;
}

.leeh-chat-voice-dot {
  flex-shrink: 0;
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: #ff5a7a;
  animation: leehVoicePulse 1s ease infinite;
}

.leeh-chat-voice-timer {
  flex-shrink: 0;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  color: #f5f6fb;
  min-width: 36px;
}

.leeh-chat-voice-wave {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 20px;
  flex-shrink: 0;
}

.leeh-chat-voice-wave span {
  display: block;
  width: 3px;
  height: 8px;
  border-radius: 2px;
  background: #9d7bff;
  animation: leehVoiceBar 0.9s ease-in-out infinite;
}

.leeh-chat-voice-wave span:nth-child(2) { animation-delay: 0.12s; }
.leeh-chat-voice-wave span:nth-child(3) { animation-delay: 0.24s; }
.leeh-chat-voice-wave span:nth-child(4) { animation-delay: 0.36s; }
.leeh-chat-voice-wave span:nth-child(5) { animation-delay: 0.48s; }

.leeh-chat-voice-hint {
  flex: 1;
  min-width: 0;
  text-align: right;
  font-size: 13px;
  color: #a3adc9;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.leeh-chat-voice-hint.is-cancel {
  color: #ff8fa3;
}

.leeh-chat-mic {
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.leeh-chat-mic.is-recording {
  background: rgba(255, 90, 122, 0.18);
  color: #ff8fa3;
  transform: scale(1.06);
}

.leeh-chat-composer-btn {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: #c4b5fd;
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 22px;
  padding: 0;
}

.leeh-chat-input-wrap {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: flex-end;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 24px;
  padding: 8px 12px;
  margin: 0 2px;
}

.leeh-chat-input-wrap textarea {
  width: 100%;
  border: 0;
  background: transparent;
  color: #f5f6fb;
  font: inherit;
  font-size: 15px;
  line-height: 20px;
  resize: none;
  min-height: 22px;
  max-height: 120px;
  outline: none;
}

.leeh-chat-send {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(135deg, #7c5cff, #9d7bff);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
}

.leeh-chat-send[hidden],
.leeh-chat-mic[hidden] {
  display: none !important;
}

/* Anexos sheet */
.leeh-chat-attach-sheet {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: grid;
  align-items: end;
}

.leeh-chat-attach-sheet[hidden] {
  display: none !important;
}

.leeh-chat-attach-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}

.leeh-chat-attach-menu {
  position: relative;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  background: rgba(15, 7, 35, 0.98);
  border-top-left-radius: 18px;
  border-top-right-radius: 18px;
  border-top: 1px solid rgba(124, 92, 255, 0.2);
  animation: leehChatSlideUp 0.22s ease;
}

.leeh-chat-attach-menu button {
  border: 1px solid rgba(124, 92, 255, 0.18);
  background: rgba(255, 255, 255, 0.04);
  color: #f5f6fb;
  border-radius: 14px;
  padding: 14px 12px;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

/* Mídia (reutilizado por atendimento-media.mjs) */
.atendimento-image,
.atendimento-video {
  display: block;
  cursor: pointer;
}

.atendimento-image.is-loading {
  opacity: 0;
}

.atendimento-media {
  position: relative;
  max-width: min(280px, 100%);
}

.atendimento-media-image {
  position: relative;
  max-width: min(85vw, 420px);
  width: fit-content;
  margin: 0;
  flex-shrink: 0;
}

.atendimento-media-image .atendimento-media-skeleton {
  width: min(72vw, 320px);
  height: min(52vw, 240px);
  border-radius: 6px;
}

.atendimento-image-tap {
  display: block;
  position: relative;
  padding: 0;
  margin: 0;
  border: 0;
  background: transparent;
  cursor: zoom-in;
  line-height: 0;
  width: 100%;
  overflow: hidden;
  border-radius: 6px;
}

.atendimento-media-image .atendimento-image {
  display: block;
  width: auto;
  max-width: min(85vw, 420px);
  max-height: min(72vh, 560px);
  height: auto;
  object-fit: contain;
  border-radius: 6px;
  vertical-align: top;
}

.atendimento-image-meta {
  position: absolute;
  right: 6px;
  bottom: 6px;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px 3px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.48);
  color: rgba(255, 255, 255, 0.94);
  font-size: 11px;
  line-height: 1;
  pointer-events: none;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.18);
}

.atendimento-image-meta time {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.atendimento-image-meta .atendimento-ticks {
  color: rgba(255, 255, 255, 0.88);
}

.atendimento-image-meta .atendimento-ticks.is-read {
  color: #c4b5fd;
}

.atendimento-video-poster {
  display: block;
  width: 100%;
  max-width: 300px;
  height: auto;
  border-radius: 8px;
  cursor: pointer;
}

.atendimento-media-skeleton {
  height: 160px;
  border-radius: 8px;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0.04));
  background-size: 200% 100%;
  animation: leehChatShimmer 1.2s infinite;
}

.atendimento-video-preview {
  position: relative;
  display: block;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  max-width: 300px;
}

.atendimento-video-play {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 28px;
  color: #fff;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 8px;
  pointer-events: none;
}

.atendimento-audio-player {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: min(260px, 100%);
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.22);
}

.atendimento-audio-play {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 999px;
  background: rgba(124, 92, 255, 0.22);
  color: #c4b5fd;
  cursor: pointer;
  flex-shrink: 0;
}

.atendimento-audio-track {
  position: relative;
  flex: 1;
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  cursor: pointer;
  overflow: hidden;
}

.atendimento-audio-fill {
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #7c5cff, #9d7bff);
  border-radius: 999px;
}

.atendimento-audio-time {
  font-size: 11px;
  color: #a3adc9;
  white-space: nowrap;
  min-width: 72px;
  text-align: right;
}

.atendimento-doc-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.22);
  max-width: min(320px, 100%);
}

.atendimento-doc-icon {
  font-size: 22px;
  flex-shrink: 0;
}

.atendimento-doc-info {
  display: grid;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.atendimento-doc-info strong {
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.atendimento-doc-info span {
  font-size: 11px;
  color: #a3adc9;
}

.atendimento-doc-download {
  border: 0;
  border-radius: 8px;
  padding: 8px 10px;
  background: rgba(124, 92, 255, 0.18);
  color: #c4b5fd;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

.atendimento-media-fallback {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
  color: #a3adc9;
  font-size: 13px;
}

.atendimento-lightbox {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  background: rgba(0, 0, 0, 0.92);
  padding: 0;
}

.atendimento-lightbox[hidden] {
  display: none !important;
}

.atendimento-lightbox-close {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  z-index: 2;
  border: 0;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
}

.atendimento-lightbox-viewport {
  flex: 1;
  width: 100%;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: none;
  padding: max(56px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
}

.atendimento-lightbox-img {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  transform-origin: center center;
  will-change: transform;
  user-select: none;
  -webkit-user-drag: none;
}

/* Skeleton */
.leeh-chat-skeleton {
  display: grid;
  gap: 8px;
  padding: 8px 0;
}

.leeh-chat-skeleton-line {
  height: 42px;
  border-radius: 16px;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.04));
  background-size: 200% 100%;
  animation: leehChatShimmer 1.2s infinite;
}

.leeh-chat-skeleton-line.short {
  width: 55%;
}

@keyframes leehChatFade {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

@keyframes leehChatShimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

@keyframes leehChatSlideUp {
  from { transform: translateY(100%); }
  to { transform: none; }
}

@keyframes leehVoicePulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.55; transform: scale(0.86); }
}

@keyframes leehVoiceBar {
  0%, 100% { height: 8px; }
  50% { height: 18px; }
}

@media (min-width: 768px) {
  body.leeh-chat-active .portal-shell {
    max-width: 720px;
    margin: 0 auto;
  }
}
