@import url("brand.css");

html, body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
}

body {
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--lavender);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.wa-shell {
  width: 100%;
  max-width: 100%;
  height: 100%;
  height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--lavender);
  /* iPhone notch / home indicator */
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

.wa-header {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem 0.7rem;
  min-height: 56px;
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-soft) 100%);
  color: var(--white);
  flex-shrink: 0;
  position: relative;
}

.wa-header::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--gold-deep), var(--gold), var(--gold-deep));
}

.back {
  color: var(--white);
  text-decoration: none;
  font-size: 1.75rem;
  line-height: 1;
  min-width: 44px;
  min-height: 44px;
  display: grid;
  place-items: center;
  opacity: 0.92;
  flex-shrink: 0;
}

.back:hover,
.back:active { color: var(--gold); }

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--brand-deep);
  border: 2px solid var(--gold);
  display: grid;
  place-items: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.7rem;
  letter-spacing: 0.02em;
  color: var(--gold);
  flex-shrink: 0;
}

.meta {
  min-width: 0;
  flex: 1;
}

.meta .name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.92rem;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.meta .status {
  font-size: 0.75rem;
  color: var(--gold);
  opacity: 0.95;
}

.wa-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 0.75rem 0.7rem 0.4rem;
  background-color: var(--lavender);
  background-image:
    radial-gradient(circle at 12% 18%, rgba(215, 166, 71, 0.12) 0 2px, transparent 3px),
    radial-gradient(circle at 78% 42%, rgba(75, 23, 105, 0.08) 0 1.5px, transparent 2.5px),
    radial-gradient(circle at 40% 80%, rgba(215, 166, 71, 0.1) 0 2px, transparent 3px);
  background-size: 48px 48px, 36px 36px, 52px 52px;
}

.row {
  display: flex;
  margin-bottom: 0.45rem;
  animation: rise 0.28s ease;
}

.row.bot { justify-content: flex-start; }
.row.user { justify-content: flex-end; }

.bubble {
  max-width: min(78%, 28rem);
  padding: 0.45rem 0.6rem 0.3rem;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(75, 23, 105, 0.1);
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  font-size: 0.9rem;
  line-height: 1.45;
  text-align: justify;
  text-justify: inter-word;
  hyphens: auto;
  -webkit-hyphens: auto;
  position: relative;
}

.bubble .msg-p {
  margin: 0 0 0.7em;
  text-align: justify;
  text-justify: inter-word;
  hyphens: auto;
  -webkit-hyphens: auto;
}

.bubble .msg-p:last-of-type {
  margin-bottom: 0.15em;
}

.bubble .msg-list {
  margin: 0.35em 0 0.75em;
  padding-left: 1.25em;
  text-align: left;
  list-style-type: disc;
}

.bubble .msg-list li {
  margin: 0.35em 0;
  padding-left: 0.15em;
  text-align: left;
  line-height: 1.4;
}

.bubble .msg-list li::marker {
  color: var(--brand);
}

/* Bolha do vídeo: acompanha o tamanho do card */
.bubble:has(.yt-card) {
  max-width: min(240px, 75%);
  padding: 0.4rem 0.45rem 0.25rem;
  font-size: 0.82rem;
  text-align: left;
}

.bubble:has(.yt-card) .msg-p {
  text-align: left;
}

.bubble.align-left,
.bubble.align-left .msg-p {
  text-align: left;
  text-justify: auto;
  hyphens: manual;
}

.bubble.align-left .msg-list {
  text-align: left;
}

.row.bot .bubble {
  background: var(--white);
  color: var(--ink);
  border: 1px solid var(--lavender-mid);
  border-top-left-radius: 4px;
}

.bubble a {
  color: var(--brand);
  font-weight: 600;
  text-decoration: underline;
  word-break: break-all;
}

.row.user .bubble a {
  color: var(--gold);
}

.yt-card {
  display: block;
  margin: 0.35rem 0 0.2rem;
  border-radius: 8px;
  overflow: hidden;
  border: 1.5px solid var(--lavender-mid);
  background: var(--lavender);
  text-decoration: none !important;
  color: var(--brand) !important;
  width: 100%;
  max-width: 100%;
  box-shadow: 0 3px 10px rgba(75, 23, 105, 0.12);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.yt-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 14px rgba(75, 23, 105, 0.18);
}

.yt-thumb {
  display: block;
  position: relative;
  aspect-ratio: 16 / 9;
  background: #1a0828;
}

.yt-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.yt-play {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 1.1rem;
  color: #fff;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
  background: rgba(75, 23, 105, 0.25);
}

.yt-label {
  display: block;
  padding: 0.35rem 0.5rem;
  font-size: 0.72rem;
  font-weight: 700;
  font-family: var(--font-display);
}

.row.user .bubble {
  background: linear-gradient(145deg, var(--brand) 0%, var(--brand-soft) 100%);
  color: var(--white);
  border-top-right-radius: 4px;
}

.bubble time {
  display: block;
  text-align: right;
  font-size: 0.68rem;
  margin-top: 0.25rem;
  opacity: 0.65;
}

.row.user .bubble time {
  color: var(--gold);
  opacity: 0.9;
}

.row.bot .bubble time {
  color: var(--ink-muted);
}

.wa-typing {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.9rem 0.45rem;
  color: var(--ink-muted);
  font-size: 0.8rem;
  background: transparent;
  flex-shrink: 0;
}

.wa-typing[hidden] { display: none; }

.wa-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--brand-soft);
  animation: blink 1.2s infinite ease-in-out;
}

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

.wa-typing em {
  font-style: normal;
  color: var(--brand);
}

.wa-composer {
  display: flex;
  gap: 0.45rem;
  padding: 0.55rem 0.6rem;
  background: var(--white);
  border-top: 1px solid var(--lavender-mid);
  flex-shrink: 0;
  align-items: center;
}

.wa-composer input {
  flex: 1;
  min-width: 0;
  border: 1.5px solid var(--lavender-mid);
  border-radius: 22px;
  padding: 0.7rem 1rem;
  /* 16px evita zoom automático no iOS */
  font-size: 16px;
  font-family: var(--font-body);
  outline: none;
  background: var(--lavender);
  color: var(--ink);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  -webkit-appearance: none;
  appearance: none;
}

.wa-composer input:focus {
  border-color: var(--brand-soft);
  box-shadow: 0 0 0 3px rgba(75, 23, 105, 0.12);
  background: var(--white);
}

.wa-composer input::placeholder {
  color: var(--ink-muted);
  opacity: 0.7;
}

.wa-composer button {
  width: 48px;
  height: 48px;
  flex-shrink: 0;
  border: none;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--brand) 0%, var(--brand-soft) 100%);
  color: var(--gold);
  font-size: 1.1rem;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(75, 23, 105, 0.28);
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.wa-composer button:hover:not(:disabled) {
  transform: scale(1.05);
}

.wa-composer button:disabled {
  opacity: 0.45;
  cursor: default;
}

@keyframes blink {
  0%, 80%, 100% { opacity: 0.25; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-2px); }
}

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Tablets e desktop: centraliza com margem leve */
@media (min-width: 768px) {
  body {
    background:
      radial-gradient(ellipse 60% 40% at 10% 0%, rgba(234, 203, 128, 0.22) 0%, transparent 55%),
      radial-gradient(ellipse 50% 45% at 100% 100%, rgba(75, 23, 105, 0.18) 0%, transparent 55%),
      linear-gradient(165deg, #2a0d3d 0%, var(--brand-deep) 45%, #1a0828 100%);
    padding: 0.5rem 0.75rem;
  }

  .wa-shell {
    max-width: 1100px;
    height: calc(100dvh - 1rem);
    border-radius: 16px;
    overflow: hidden;
    border: 1px solid rgba(234, 203, 128, 0.35);
    box-shadow: var(--shadow);
    padding-top: 0;
    padding-bottom: 0;
    padding-left: 0;
    padding-right: 0;
  }

  .wa-header {
    padding: 0.7rem 0.95rem;
  }

  .meta .name {
    font-size: 0.98rem;
  }

  .wa-messages {
    padding: 1rem 1rem 0.5rem;
  }

  .bubble {
    max-width: min(68%, 28rem);
    font-size: 0.92rem;
  }

  .bubble:has(.yt-card) {
    max-width: 240px;
  }

  .wa-composer {
    padding: 0.65rem 0.75rem;
  }

  .wa-composer input {
    font-size: 0.95rem;
  }
}

/* Telas bem estreitas */
@media (max-width: 360px) {
  .avatar { display: none; }

  .meta .name {
    font-size: 0.85rem;
  }

  .bubble {
    max-width: 92%;
    font-size: 0.9rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .row { animation: none; }
  .wa-typing span { animation: none; }
}
