:root {
  --wa-header: #075e54;
  --wa-header-dark: #054640;
  --wa-accent: #25d366;
  --wa-bg: #e5ddd5;
  --wa-bg-pattern: #d1c8bc;
  --wa-incoming: #ffffff;
  --wa-outgoing: #d9fdd3;
  --wa-text: #111b21;
  --wa-muted: #667781;
  --wa-time: #667781;
  --wa-input-bg: #f0f2f5;
  --wa-border: rgba(0, 0, 0, 0.08);
  --wa-shadow: 0 1px 0.5px rgba(11, 20, 26, 0.13);
  --font: "Segoe UI", "Helvetica Neue", system-ui, sans-serif;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font);
  background: #0b141a;
  color: var(--wa-text);
}

.chat-app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 480px;
  margin: 0 auto;
  background: var(--wa-bg);
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.35);
}

@media (min-width: 520px) {
  body {
    padding: 1rem 0;
    height: auto;
    min-height: 100%;
    overflow: auto;
  }

  .chat-app {
    height: calc(100dvh - 2rem);
    min-height: 640px;
    border-radius: 12px;
    overflow: hidden;
  }
}

/* Header */
.chat-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 1rem;
  background: var(--wa-header);
  color: #fff;
  flex-shrink: 0;
}

.chat-header__avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  background: #fff;
  flex-shrink: 0;
}

.chat-header__info {
  flex: 1;
  min-width: 0;
}

.chat-header__name {
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-header__status {
  font-size: 0.78rem;
  opacity: 0.85;
}

.chat-header__status.is-typing {
  color: #a7f3d0;
}

/* Messages area */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 0.85rem 0.5rem;
  background-color: var(--wa-bg);
  background-image:
    radial-gradient(circle at 20% 30%, rgba(255, 255, 255, 0.35) 0, transparent 45%),
    radial-gradient(circle at 80% 70%, rgba(255, 255, 255, 0.25) 0, transparent 40%),
    linear-gradient(135deg, var(--wa-bg) 0%, #ece5dd 100%);
  scroll-behavior: smooth;
}

.chat-messages__inner {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-height: 100%;
}

.chat-date {
  align-self: center;
  margin: 0.5rem 0 0.75rem;
  padding: 0.35rem 0.75rem;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--wa-muted);
  background: rgba(255, 255, 255, 0.92);
  border-radius: 8px;
  box-shadow: var(--wa-shadow);
}

/* Bubbles */
.msg {
  display: flex;
  max-width: 85%;
  animation: msg-in 0.28s ease-out both;
}

@keyframes msg-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.msg--in {
  align-self: flex-start;
}

.msg--out {
  align-self: flex-end;
}

.msg__bubble {
  position: relative;
  padding: 0.45rem 0.65rem 0.3rem;
  border-radius: 8px;
  box-shadow: var(--wa-shadow);
  font-size: 0.92rem;
  line-height: 1.45;
  word-wrap: break-word;
  white-space: pre-wrap;
  overflow: hidden;
}

.msg__bubble--media {
  padding: 0;
  min-width: 220px;
  max-width: 280px;
}

.msg__media-link {
  display: block;
  line-height: 0;
}

.msg__image {
  display: block;
  width: 100%;
  max-height: 220px;
  object-fit: cover;
  background: #f0f2f5;
}

.msg__caption {
  padding: 0.45rem 0.65rem 0;
  font-size: 0.88rem;
  line-height: 1.4;
  white-space: pre-wrap;
}

.msg__bubble--media .msg__meta {
  padding: 0.15rem 0.65rem 0.35rem;
}

.msg--in .msg__bubble {
  background: var(--wa-incoming);
  border-top-left-radius: 0;
}

.msg--out .msg__bubble {
  background: var(--wa-outgoing);
  border-top-right-radius: 0;
}

.msg__meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.2rem;
  margin-top: 0.15rem;
  font-size: 0.68rem;
  color: var(--wa-time);
}

.msg__check {
  width: 16px;
  height: 11px;
  color: #53bdeb;
}

/* Typing indicator */
.typing {
  align-self: flex-start;
  display: flex;
  padding: 0.65rem 0.85rem;
  background: var(--wa-incoming);
  border-radius: 8px;
  border-top-left-radius: 0;
  box-shadow: var(--wa-shadow);
  gap: 0.28rem;
}

.typing[hidden] {
  display: none !important;
}

.typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--wa-muted);
  animation: typing-dot 1.2s infinite ease-in-out;
}

.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes typing-dot {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.45; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* Quick replies */
.quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  padding: 0.65rem 0.85rem 0.25rem;
  justify-content: flex-end;
}

.quick-replies[hidden] {
  display: none !important;
}

.quick-replies__btn {
  padding: 0.5rem 0.85rem;
  border: 1px solid var(--wa-accent);
  border-radius: 999px;
  background: #fff;
  color: #008069;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.quick-replies__btn:hover {
  background: #ecfdf5;
}

.quick-replies__btn:active {
  transform: scale(0.97);
}

.quick-replies__btn--link {
  background: var(--wa-accent);
  color: #fff;
  border-color: var(--wa-accent);
}

.quick-replies__btn--link:hover {
  background: #20bd5a;
}

/* Input bar */
.chat-input {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.55rem 0.65rem calc(0.55rem + env(safe-area-inset-bottom));
  background: var(--wa-input-bg);
  border-top: 1px solid var(--wa-border);
  flex-shrink: 0;
}

.chat-input__field {
  flex: 1;
  min-height: 42px;
  max-height: 120px;
  padding: 0.65rem 0.85rem;
  border: none;
  border-radius: 24px;
  background: #fff;
  font-family: inherit;
  font-size: 0.92rem;
  line-height: 1.35;
  resize: none;
  outline: none;
}

.chat-input__field::placeholder {
  color: var(--wa-muted);
}

.chat-input__send {
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 50%;
  background: var(--wa-accent);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
}

.chat-input__send:hover {
  background: #20bd5a;
}

.chat-input__send:active {
  transform: scale(0.95);
}

.chat-input__send svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.chat-input__send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
