* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #ededed;
  --phone-bg: #f5f5f5;
  --header: #2e2e2e;
  --header-text: #fff;
  --ai-bubble: #fff;
  --user-bubble: #95ec69;
  --text: #111;
  --muted: #888;
  --warn: #fff3cd;
  --warn-border: #ffc107;
  --accent: #07c160;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", sans-serif;
  background: #d8d8d8;
  color: var(--text);
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
}

.hidden {
  display: none !important;
}

.phone {
  width: 100%;
  max-width: 420px;
  height: min(820px, 100dvh - 24px);
  background: var(--phone-bg);
  border-radius: 16px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
}

.chat-header {
  background: var(--header);
  color: var(--header-text);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.header-center {
  flex: 1;
  text-align: center;
}

.header-center h1 {
  font-size: 17px;
  font-weight: 600;
}

.icon-btn {
  background: none;
  border: none;
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: 8px;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #666;
}

.status-dot.ready { background: #07c160; }
.status-dot.error { background: #fa5151; }

.warn-banner {
  background: var(--warn);
  border-bottom: 1px solid var(--warn-border);
  padding: 8px 12px;
  font-size: 12px;
  line-height: 1.5;
  flex-shrink: 0;
}

.warn-banner code {
  background: rgba(0, 0, 0, 0.06);
  padding: 1px 4px;
  border-radius: 4px;
}

.chat-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  background: var(--bg);
  scroll-behavior: smooth;
}

.time-divider {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  margin: 8px 0 16px;
}

.msg-row {
  display: flex;
  margin-bottom: 10px;
  align-items: flex-start;
  gap: 8px;
}

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

.avatar {
  width: 38px;
  height: 38px;
  border-radius: 6px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
}

.avatar.ai {
  background: linear-gradient(135deg, #4a6fa5, #2c5282);
}

.avatar.user {
  background: linear-gradient(135deg, #e879a9, #db2777);
}

.bubble-group {
  max-width: 72%;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.msg-row.user .bubble-group {
  align-items: flex-end;
}

.bubble {
  padding: 9px 12px;
  border-radius: 6px;
  font-size: 15px;
  line-height: 1.45;
  word-break: break-word;
}

.msg-row.ai .bubble {
  background: var(--ai-bubble);
  border: 1px solid #e0e0e0;
}

.msg-row.user .bubble {
  background: var(--user-bubble);
}

.name-tag {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 2px;
  padding: 0 2px;
}

.msg-row.user .name-tag {
  text-align: right;
}

.typing {
  display: flex;
  gap: 4px;
  padding: 12px 14px;
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  width: fit-content;
}

.typing span {
  width: 6px;
  height: 6px;
  background: #bbb;
  border-radius: 50%;
  animation: bounce 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 bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-5px); opacity: 1; }
}

.error-toast {
  background: #fee;
  color: #c00;
  font-size: 13px;
  padding: 8px 12px;
  border-radius: 8px;
  margin: 8px 0;
  text-align: center;
}

.chat-footer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  background: #f7f7f7;
  border-top: 1px solid #ddd;
  flex-shrink: 0;
}

#inputBox {
  flex: 1;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 15px;
  font-family: inherit;
  resize: none;
  max-height: 100px;
  line-height: 1.4;
  background: #fff;
}

#inputBox:focus {
  outline: none;
  border-color: var(--accent);
}

#sendBtn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 15px;
  cursor: pointer;
  flex-shrink: 0;
}

#sendBtn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

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