:root {
  color-scheme: dark;
  --bg: #0b1016;
  --bubble: #26282f;
  --muted: #a2a4ad;
  --text: #f4f4f6;
  --purple: #8432f6;
  --accent: #8432f6;
  --accent-gradient: linear-gradient(120deg, #a52bed 0%, #8432f6 100%);
  --camera-accent: #5950fa;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }

body {
  background: #07090e;
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; }
button:disabled { cursor: default; }
button:focus-visible, a:focus-visible { outline: 3px solid #ba8dff; outline-offset: 4px; }
svg { display: block; width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }

/* === Shell === */
.chat-shell {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100dvh;
  max-width: 560px;
  margin: auto;
  background: var(--bg);
  overflow: hidden;
}

/* === Header === */
.chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  min-height: 90px;
  padding: calc(14px + env(safe-area-inset-top)) 17px 14px;
  background: linear-gradient(180deg, #080b0f, #0b1016);
  z-index: 5;
}

.round-action {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  background: #0d1217;
  border: 1px solid #292c34;
  border-radius: 50%;
  width: 43px;
  height: 43px;
  padding: 9px;
}

.back-action svg { width: 26px; height: 26px; }
.tag-action { margin-left: auto; }

.profile-button {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  background: none;
  padding: 0;
  text-align: left;
  flex: 1;
}

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
  isolation: isolate;
  background: linear-gradient(150deg, #565967, #30313b);
  color: #fff;
  font-weight: 600;
  letter-spacing: .02em;
}

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

.header-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 2px solid #9ea5b3;
  box-shadow: inset 0 0 0 2px #0b1016;
  font-size: 14px;
}

.profile-copy { min-width: 0; flex: 1; }

.profile-identity {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.profile-identity .profile-name {
  min-width: 0;
  flex: 0 1 auto;
}

.profile-name {
  display: block;
  font-size: 19px;
  font-weight: 700;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 240px;
}

.profile-status {
  display: block;
  color: #dfdfe5;
  font-size: 14px;
  font-weight: 400;
  line-height: 1.4;
  margin-top: 2px;
}

.profile-status.is-typing { color: #b0acbf; }

.verified-badge {
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
}

/* === Conversation === */
.conversation {
  flex: 1;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: none;
  padding: 8px 10px 16px;
  scroll-behavior: smooth;
}

.conversation::-webkit-scrollbar { display: none; }

.date-label {
  text-align: center;
  color: #858791;
  font-size: 12px;
  line-height: 1.5;
  margin: 8px 0 27px;
  letter-spacing: .035em;
}

/* === Messages === */
.message-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  margin-top: 4px;
  animation: message-in .23s ease-out both;
}

.message-row.group-start { margin-top: 19px; }
.message-row.received { padding-left: 3px; }

.mini-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 10px;
  margin-bottom: 1px;
}

.message-row:not(.group-end) .mini-avatar { visibility: hidden; }

.bubble {
  font-size: 16px;
  line-height: 1.32;
  font-weight: 400;
  padding: 12px 15px;
  max-width: calc(100% - 54px);
  overflow-wrap: anywhere;
  white-space: pre-line;
  background: var(--bubble);
  border-radius: 24px 24px 24px 5px;
}

.received:not(.group-start) .bubble { border-top-left-radius: 5px; }

.sent {
  justify-content: flex-end;
  margin-left: 52px;
}

.sent .bubble {
  max-width: 100%;
  background: var(--accent-gradient);
  border-radius: 24px 24px 5px 24px;
}

.sent.group-start { margin-top: 19px; }
.sent:not(.group-start) .bubble { border-top-right-radius: 5px; }

.receipt {
  color: #999ba6;
  font-size: 12px;
  text-align: right;
  margin: 7px 5px 2px;
}

/* === Typing indicator === */
.typing-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding-left: 3px;
  margin-top: 5px;
  min-height: 42px;
}

.typing-bubble {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  background: var(--bubble);
  border-radius: 22px 22px 22px 5px;
  width: 65px;
  height: 39px;
}

.typing-bubble span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #aeb0b8;
  animation: typing 1.15s infinite ease-in-out;
}

.typing-bubble span:nth-child(2) { animation-delay: .16s; }
.typing-bubble span:nth-child(3) { animation-delay: .32s; }

/* === Choices === */
.choices {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  padding: 20px 7px 2px 42px;
}

.choices:empty { display: none; }

.choice-label {
  font-size: 12px;
  text-align: center;
  color: #8b8d98;
  margin: 0 0 3px;
}

.choice {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 12px 16px;
  border: 1px solid #62419b;
  border-radius: 15px;
  background: #181322;
  font-weight: 600;
  font-size: 15px;
  line-height: 1.35;
  text-align: center;
  animation: message-in .25s ease-out;
}

.choice.primary {
  background: linear-gradient(110deg, #9b2cf2, #7439fa);
  border-color: transparent;
}

.choice.secondary {
  background: transparent;
  border-color: #37303e;
  color: #c5b0e2;
  font-weight: 400;
}

.choice:hover { filter: brightness(1.15); }

.choice.primary.is-nudge { animation: nudge 1.1s ease-in-out 3; }

@keyframes nudge {
  0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(155, 44, 242, .55); }
  50% { transform: scale(1.03); box-shadow: 0 0 0 10px rgba(155, 44, 242, 0); }
}

.composer { cursor: pointer; }
.choice:active { transform: scale(.985); }
.choice svg { width: 19px; height: 19px; flex-shrink: 0; }

/* === Photo messages === */
.photo-message {
  padding: 0;
  overflow: hidden;
  max-width: calc(100% - 44px);
  width: 380px;
  background: #20232b;
  border-radius: 24px 24px 24px 5px;
}

.photo-message button {
  display: block;
  padding: 0;
  width: 100%;
  border: 0;
  background: none;
}

.photo-message img {
  display: block;
  height: auto;
  width: 100%;
  object-fit: contain;
}

.photo-missing {
  padding: 22px 16px;
  text-align: center;
  white-space: normal;
  color: #acafb9;
  background: linear-gradient(125deg, #2b2d35, #22242b);
}

.photo-missing svg {
  width: 27px;
  height: 27px;
  margin: 0 auto 10px;
  color: #9792a7;
}

.photo-missing strong {
  display: block;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.4;
  color: #dcdce4;
}

.photo-missing small {
  display: block;
  font-size: 12px;
  line-height: 1.4;
  margin-top: 4px;
}

/* === WhatsApp Print === */
.wpp-print {
  padding: 0 !important;
  overflow: hidden;
  max-width: calc(100% - 54px);
  width: 290px;
  background: #eae2d7;
  border-radius: 24px 24px 24px 5px !important;
}

.wpp-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  background: #075E54;
  color: rgba(255,255,255,.85);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .02em;
}

.wpp-chat {
  padding: 10px 8px 10px 10px;
}

.wpp-bubble {
  background: #fff;
  border-radius: 0 8px 8px 8px;
  padding: 6px 10px 4px;
  box-shadow: 0 1px 1px rgba(0,0,0,.06);
  max-width: 96%;
}

.wpp-sender {
  font-size: 12px;
  font-weight: 600;
  color: #1FA855;
  margin-bottom: 1px;
}

.wpp-text {
  font-size: 13.5px;
  line-height: 1.35;
  color: #111b21;
  white-space: pre-line;
}

.wpp-meta {
  display: flex;
  justify-content: flex-end;
  font-size: 10.5px;
  color: #8696a0;
  margin-top: 2px;
}

/* === Footer / Composer === */
.chat-footer {
  padding: 9px 9px calc(9px + env(safe-area-inset-bottom));
  flex-shrink: 0;
  background: var(--bg);
  z-index: 5;
}

.composer {
  height: 49px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: 30px;
  background: #222229;
  padding: 5px 12px 5px 5px;
}

.camera-decoration {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 39px;
  height: 39px;
  border-radius: 50%;
  background: var(--camera-accent);
}

.camera-decoration svg { width: 26px; height: 26px; color: #fff; }

.composer-placeholder {
  color: #a5a4ad;
  font-size: 17px;
  flex: 1;
  min-width: 0;
}

.composer-icons {
  display: flex;
  align-items: center;
  gap: 13px;
}

.composer-icons svg {
  width: 23px;
  height: 23px;
  stroke-width: 1.9;
}

/* === Scroll to bottom === */
.scroll-bottom {
  position: absolute;
  right: 18px;
  bottom: 88px;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid #3e414b;
  background: #f9f9fc;
  color: #11131a;
  box-shadow: 0 3px 15px #0004;
  z-index: 4;
}

.scroll-bottom svg { width: 25px; height: 25px; }

/* === Dialogs === */
.chat-dialog {
  border: 1px solid #37343f;
  background: #202128;
  color: #f6f4fb;
  border-radius: 24px;
  padding: 32px 25px 23px;
  width: min(350px, calc(100% - 40px));
  text-align: center;
  box-shadow: 0 24px 100px #0009;
}

.chat-dialog::backdrop,
.photo-dialog::backdrop {
  background: #000a;
  backdrop-filter: blur(6px);
}

.chat-dialog h2 {
  font-size: 21px;
  margin: 13px 0 10px;
}

.chat-dialog p {
  font-size: 15px;
  color: #b5b3bf;
  line-height: 1.55;
  margin: 0 0 24px;
}

.dialog-avatar {
  width: 70px;
  height: 70px;
  font-size: 22px;
  border-radius: 50%;
}

.dialog-close {
  position: absolute;
  top: 12px;
  right: 12px;
  border: 0;
  background: none;
  padding: 4px;
  color: #aaa7b6;
}

.dialog-primary,
.dialog-secondary {
  width: 100%;
  border: 0;
  border-radius: 13px;
  padding: 13px 10px;
  font-size: 15px;
  font-weight: 600;
}

.dialog-primary {
  background: var(--purple);
  color: white;
}

.dialog-secondary {
  margin-top: 7px;
  background: transparent;
  color: #b6a8ce;
  font-weight: 400;
}

.photo-dialog {
  border: 0;
  padding: 0;
  background: #111319;
  max-width: 90vw;
  max-height: 90dvh;
  border-radius: 16px;
  overflow: hidden;
}

.photo-dialog img {
  display: block;
  width: 100%;
  max-height: 86dvh;
  object-fit: contain;
}

.photo-dialog .dialog-close {
  background: #0008;
  color: white;
  border-radius: 50%;
}

/* === Animations === */
@keyframes typing {
  0%, 60%, 100% { transform: translateY(0); opacity: .55; }
  30% { transform: translateY(-4px); opacity: 1; }
}

@keyframes message-in {
  from { opacity: 0; transform: translateY(7px) scale(.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* === Desktop === */
@media (min-width: 650px) {
  body {
    display: grid;
    place-items: center;
    padding: 24px;
  }

  .chat-shell {
    height: calc(100dvh - 48px);
    max-height: 980px;
    border: 1px solid #282a33;
    border-radius: 25px;
    box-shadow: 0 30px 100px #0005;
  }

  .chat-header { padding: 20px; min-height: 95px; }
  .conversation { padding: 8px 18px 20px; }
  .bubble { max-width: calc(100% - 75px); font-size: 17px; padding: 12px 15px; }
  .message-row { gap: 12px; }
  .mini-avatar { width: 29px; height: 29px; }
  .choices { padding-left: 44px; padding-right: 16px; }
  .chat-footer { padding: 12px 14px 13px; }
  .composer { height: 54px; }
  .composer-icons { gap: 16px; }
  .scroll-bottom { right: 26px; }
}

/* === Small phones === */
@media (max-width: 420px) {
  .profile-name { font-size: 16px; }
  .chat-header { gap: 8px; }
  .profile-button { gap: 8px; }
  .verified-badge { width: 18px; height: 18px; flex-basis: 18px; }
  .profile-identity { gap: 5px; }
}

@media (max-width: 360px) {
  .chat-header { padding-left: 11px; padding-right: 11px; gap: 8px; }
  .round-action { width: 36px; height: 36px; padding: 7px; }
  .header-avatar { width: 37px; height: 37px; }
  .profile-button { gap: 7px; }
  .profile-name { font-size: 17px; max-width: 170px; }
  .profile-status { font-size: 12px; }
  .composer-icons { gap: 9px; }
  .composer-icons svg { width: 21px; height: 21px; }
  .composer-placeholder { font-size: 16px; }
  .bubble { padding: 11px 13px; }
  .choices { padding-left: 36px; }
  .choice { font-size: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition: none !important;
  }
  .typing-bubble span { opacity: .7; }
}
