:root {
  --imessage-blue: #0a84ff;
  --imessage-blue-dark: #0066d6;
  --bubble-gray: #e9e9eb;
  --bg-top: #f5f5f7;
  --bg-bottom: #e8e8ed;
  --text-dark: #1c1c1e;
  --text-muted: #86868b;
  --green: #34c759;
  --danger: #ff3b30;
  --radius-lg: 22px;
}

* { box-sizing: border-box; }

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
  background: linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.phone {
  width: 100%;
  max-width: 420px;
  height: min(760px, 92vh);
  background: #ffffff;
  border-radius: 32px;
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.6) inset,
    0 30px 60px -20px rgba(0, 0, 0, 0.35),
    0 0 0 1px rgba(0, 0, 0, 0.04);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  backdrop-filter: blur(20px);
  background: rgba(255, 255, 255, 0.85);
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #7c7cf0, #0a84ff);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
  flex-shrink: 0;
}

.title-block {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
}

.title-block h1 {
  font-size: 15px;
  font-weight: 600;
  margin: 0;
  color: var(--text-dark);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 999px;
  width: fit-content;
  letter-spacing: 0.1px;
}

.badge-online {
  background: rgba(52, 199, 89, 0.12);
  color: #248a3d;
}

.badge-online .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 3px rgba(52, 199, 89, 0.18);
}

.icon-btn {
  border: none;
  background: rgba(0, 0, 0, 0.04);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.icon-btn:hover {
  background: rgba(0, 0, 0, 0.08);
  color: var(--text-dark);
}

/* Thread */
.thread {
  flex: 1;
  overflow-y: auto;
  padding: 18px 14px 6px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scroll-behavior: smooth;
}

.day-badge {
  text-align: center;
  margin: 4px 0 10px;
}

.day-badge span {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  background: rgba(0, 0, 0, 0.04);
  padding: 3px 12px;
  border-radius: 999px;
}

.msg {
  display: flex;
  max-width: 100%;
}

.msg-in { justify-content: flex-start; }
.msg-out { justify-content: flex-end; }

.bubble {
  max-width: 78%;
  padding: 9px 14px;
  border-radius: var(--radius-lg);
  font-size: 15px;
  line-height: 1.35;
  word-wrap: break-word;
  white-space: pre-wrap;
  animation: pop 0.18s ease;
}

@keyframes pop {
  from { transform: scale(0.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.msg-in .bubble {
  background: var(--bubble-gray);
  color: var(--text-dark);
  border-bottom-left-radius: 6px;
}

.msg-out .bubble {
  background: linear-gradient(180deg, var(--imessage-blue), var(--imessage-blue-dark));
  color: #fff;
  border-bottom-right-radius: 6px;
}

.msg-error .bubble {
  background: rgba(255, 59, 48, 0.1);
  color: #b3261e;
  border-bottom-left-radius: 6px;
}

/* Typing indicator */
.typing-row {
  display: flex;
  padding: 0 14px 8px;
}

.bubble-typing {
  background: var(--bubble-gray);
  border-bottom-left-radius: 6px;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
}

.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #a9a9ae;
  animation: bounce 1.2s infinite ease-in-out;
}

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

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* Composer */
.composer {
  padding: 10px 12px 16px;
  border-top: 1px solid rgba(0, 0, 0, 0.06);
  background: rgba(255, 255, 255, 0.9);
}

.composer-form {
  display: flex;
  align-items: center;
  gap: 8px;
}

.composer-input {
  flex: 1;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: 999px;
  padding: 10px 16px;
  font-size: 15px;
  outline: none;
  background: #fff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  font-family: inherit;
}

.composer-input:focus {
  border-color: var(--imessage-blue);
  box-shadow: 0 0 0 3px rgba(10, 132, 255, 0.15);
}

.send-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: var(--imessage-blue);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.12s ease, background 0.15s ease, opacity 0.15s ease;
}

.send-btn:disabled {
  background: #c7c7cc;
  cursor: default;
}

.send-btn:not(:disabled):hover {
  transform: scale(1.06);
}

.send-btn:not(:disabled):active {
  transform: scale(0.94);
}

/* Scrollbar */
.thread::-webkit-scrollbar { width: 6px; }
.thread::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 999px;
}

.hint {
  position: fixed;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 12px;
  color: #b3261e;
  background: #fff;
  padding: 6px 14px;
  border-radius: 999px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15);
  max-width: 90vw;
  text-align: center;
}

@media (max-width: 480px) {
  body { padding: 0; }
  .phone { height: 100vh; border-radius: 0; max-width: 100%; }
}
