:root {
  --pink: #f472b6;
  --purple: #a855f7;
  --bg-start: #fdf2f8;
  --bg-end: #f3e8ff;
  --bubble-user: linear-gradient(135deg, #a855f7, #ec4899);
  --bubble-bot: #ffffff;
  --text-primary: #1f1f1f;
  --text-secondary: #6b7280;
  --text-user: #ffffff;
  --input-border: #e9d5ff;
  --input-focus: #c084fc;
  --header-bg: rgba(255, 255, 255, 0.85);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
  --radius: 20px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: linear-gradient(160deg, var(--bg-start), var(--bg-end));
  -webkit-font-smoothing: antialiased;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 600px;
  margin: 0 auto;
}

.header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px 16px;
  background: var(--header-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(168, 85, 247, 0.1);
  position: relative;
  z-index: 10;
}

.header-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--purple), var(--pink));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: white;
  flex-shrink: 0;
}

.header-info {
  text-align: center;
}

.header-name {
  font-size: 16px;
  font-weight: 600;
  color: var(--purple);
}

.header-status {
  font-size: 11px;
  color: var(--text-secondary);
  transition: color 0.3s;
}

.header-status.online { color: #22c55e; }

.chat-area {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 16px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

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

.msg-row {
  display: flex;
  margin-bottom: 4px;
  align-items: flex-end;
  gap: 8px;
  animation: fadeUp 0.25s ease-out;
}

.msg-row.user { flex-direction: row-reverse; }

.msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  align-self: flex-end;
  margin-bottom: 2px;
}

.msg-avatar.bot-av {
  background: linear-gradient(135deg, var(--purple), var(--pink));
  color: white;
}

.msg-avatar.user-av {
  background: linear-gradient(135deg, #ec4899, #f9a8d4);
  color: white;
}

.msg-content { max-width: 75%; }

.bubble {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 15px;
  line-height: 1.6;
  word-break: break-word;
  white-space: pre-wrap;
}

.msg-row.bot .bubble {
  background: var(--bubble-bot);
  color: var(--text-primary);
  border-bottom-left-radius: 6px;
  box-shadow: var(--shadow-sm);
}

.msg-row.user .bubble {
  background: var(--bubble-user);
  color: var(--text-user);
  border-bottom-right-radius: 6px;
  box-shadow: var(--shadow-sm);
}

.msg-time {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 3px;
  padding: 0 4px;
}

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

.thinking {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
}

.thinking span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--purple);
  opacity: 0.4;
  animation: bounce 1.2s infinite;
}

.thinking span:nth-child(2) { animation-delay: 0.2s; }
.thinking span:nth-child(3) { animation-delay: 0.4s; }

.input-area textarea {
  flex: 1;
  border: 2px solid var(--input-border);
  border-radius: var(--radius);
  padding: 10px 16px;
  font-size: 15px;
  font-family: inherit;
  resize: none;
  outline: none;
  max-height: 120px;
  min-height: 42px;
  line-height: 1.4;
  transition: border-color 0.2s;
  background: white;
}

.input-area textarea:focus {
  border-color: var(--input-focus);
}

.send-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--purple), var(--pink));
  color: white;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.15s, opacity 0.2s;
}

.send-btn:active { transform: scale(0.9); }
.send-btn:disabled { opacity: 0.5; cursor: default; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

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

@media (min-width: 601px) {
  #app { border-left: 1px solid #f0e0f8; border-right: 1px solid #f0e0f8; }
}

/* input area layout */
.input-area {
  display: flex;
  flex-direction: column;
  padding: 0 12px calc(10px + var(--safe-bottom));
  background: var(--header-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid rgba(168, 85, 247, 0.1);
}

.input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 10px 0 0;
}

/* image button */
.img-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--purple);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.img-btn:active { opacity: 0.6; }

/* image preview strip */
.img-preview {
  display: flex;
  gap: 8px;
  padding: 10px 0 0;
  overflow-x: auto;
}

.preview-item {
  position: relative;
  width: 64px;
  height: 64px;
  flex-shrink: 0;
  border-radius: 10px;
  overflow: hidden;
}

.preview-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.preview-del {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  background: rgba(0,0,0,0.5);
  color: white;
  border-radius: 50%;
  font-size: 12px;
  line-height: 18px;
  text-align: center;
  cursor: pointer;
}

/* images inside chat bubbles */
.bubble-imgs {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.bubble-imgs img {
  width: 80px;
  height: 80px;
  object-fit: cover;
  border-radius: 8px;
  cursor: pointer;
}

.notification-bubble {
  background: linear-gradient(135deg, #f3e8ff, #fce7f3) !important;
  border: 1px solid rgba(168, 85, 247, 0.25);
}

.notification-bubble.read {
  background: linear-gradient(135deg, #f3f4f6, #e5e7eb) !important;
  border: 1px solid rgba(156, 163, 175, 0.25);
  color: #6b7280;
}

.notif-badge {
  margin-right: 6px;
}

/* full-screen image overlay */
#img-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  z-index: 999;
  align-items: center;
  justify-content: center;
}

#img-overlay img {
  max-width: 90%;
  max-height: 90%;
  border-radius: 8px;
}
