*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --green: #075e54;
  --green-2: #128c7e;
  --bubble-in: #ffffff;
  --bubble-out: #dcf8c6;
  --bg: #e5ddd5;
  --text: #111b21;
  --muted: #667781;
}

html, body { height: 100%; }

body {
  font-family: "Plus Jakarta Sans", system-ui, sans-serif;
  color: var(--text);
  background: #0b141a;
}

.app {
  width: min(480px, 100%);
  height: 100dvh;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: var(--bg);
  background-image:
    linear-gradient(rgba(229, 221, 213, 0.92), rgba(229, 221, 213, 0.92)),
    url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='%23cbbfb3' fill-opacity='0.35'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/svg%3E");
  overflow: hidden;
}

.top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  padding-top: max(10px, env(safe-area-inset-top, 0px));
  background: linear-gradient(180deg, var(--green), var(--green-2));
  color: #fff;
}

.back {
  width: 36px;
  height: 36px;
  border: 0;
  background: transparent;
  color: #fff;
  font-size: 1.8rem;
  cursor: pointer;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  object-position: 15% center;
  border: 2px solid rgba(255,255,255,0.35);
}

.who { display: flex; flex-direction: column; min-width: 0; }
.who strong { font-size: 0.98rem; font-weight: 800; }
.who span { font-size: 0.75rem; opacity: 0.9; }

.chat {
  overflow-y: auto;
  padding: 14px 12px 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  -webkit-overflow-scrolling: touch;
}

.row { display: flex; width: 100%; }
.row.in { justify-content: flex-start; }
.row.out { justify-content: flex-end; }

.bubble {
  max-width: min(88%, 360px);
  padding: 8px 10px 6px;
  border-radius: 10px;
  font-size: 0.92rem;
  line-height: 1.4;
  font-weight: 600;
  box-shadow: 0 1px 1px rgba(0,0,0,0.08);
  white-space: pre-wrap;
}

.row.in .bubble {
  background: var(--bubble-in);
  border-top-left-radius: 2px;
}

.row.out .bubble {
  background: var(--bubble-out);
  border-top-right-radius: 2px;
}

.time {
  display: block;
  text-align: right;
  font-size: 0.65rem;
  color: var(--muted);
  margin-top: 4px;
  font-weight: 500;
}

.typing {
  display: inline-flex;
  gap: 4px;
  padding: 10px 12px;
  background: #fff;
  border-radius: 10px;
  border-top-left-radius: 2px;
  box-shadow: 0 1px 1px rgba(0,0,0,0.08);
}

.typing i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #90a4ae;
  animation: blink 1.2s infinite ease-in-out;
}
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }

@keyframes blink {
  0%, 80%, 100% { opacity: .35; }
  40% { opacity: 1; }
}

.media {
  margin: 6px 0 2px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid #e5e7eb;
  background: #0f172a;
}

.media img,
.media video {
  display: block;
  width: 100%;
  max-height: 280px;
  object-fit: contain;
  background: #0f172a;
}

.media-gallery img {
  border-bottom: 1px solid #1e293b;
  max-height: 320px;
}

.media-gallery img:last-of-type {
  border-bottom: none;
}

.media-caption {
  padding: 8px 10px;
  font-size: 0.78rem;
  color: #334155;
  background: #f8fafc;
  font-weight: 600;
}

.btn-stack {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

.bot-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  color: #0f172a;
  font-family: inherit;
  font-weight: 800;
  font-size: 0.88rem;
  cursor: pointer;
  text-align: center;
}

.bot-btn:hover { background: #eef2ff; border-color: #93c5fd; }
.bot-btn.primary {
  background: #25d366;
  border-color: #25d366;
  color: #fff;
}
.bot-btn.blue {
  background: #2563eb;
  border-color: #2563eb;
  color: #fff;
}

.composer {
  padding: 8px 10px max(10px, env(safe-area-inset-bottom, 0px));
  background: #f0f2f5;
  border-top: 1px solid rgba(0,0,0,0.06);
}

#reply-form {
  display: flex;
  gap: 8px;
  align-items: center;
}

#reply-input {
  flex: 1;
  min-width: 0;
  border: 0;
  border-radius: 22px;
  padding: 12px 14px;
  font: inherit;
  font-weight: 600;
  background: #fff;
  outline: none;
}

#reply-input:disabled,
#reply-send:disabled { opacity: 0.55; cursor: not-allowed; }

#reply-send {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--green-2);
  color: #fff;
  cursor: pointer;
}

.hint {
  margin-top: 6px;
  font-size: 0.72rem;
  color: var(--muted);
  text-align: center;
  font-weight: 600;
}
