/* ========== base.css ==========
   CSS variables, body, header, messages, bubbles, footer,
   attach menu, context menu, toast, settings panel
   ============================== */

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

:root {
  --bg: #faf6f1;
  --surface: #f3ede6;
  --border: #e2d6ca;
  --text: #3d2f27;
  --text-muted: #9c8070;
  --bubble-user: #c4a58a;
  --bubble-user-text: #fff;
  --bubble-ai: #ede7df;
  --bubble-ai-text: #3d2f27;
  --input-bg: #fff;
  --send-bg: #a07858;
  --send-hover: #8b6445;
  --mic-active: #c0392b;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

header {
  padding: 14px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--bubble-user);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; color: #fff; font-weight: 500;
}

header h1 { font-size: 16px; font-weight: 600; letter-spacing: 0.5px; }
header span { font-size: 12px; color: var(--text-muted); }

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.bubble-wrap {
  display: flex;
  flex-direction: column;
  max-width: 78%;
}

.bubble-wrap.user { align-self: flex-end; align-items: flex-end; }
.bubble-wrap.ai { align-self: flex-start; align-items: flex-start; }

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

.bubble-wrap.user .bubble {
  background: var(--bubble-user);
  color: var(--bubble-user-text);
  border-bottom-right-radius: 4px;
}

.bubble-wrap.ai .bubble {
  background: var(--bubble-ai);
  color: var(--bubble-ai-text);
  border-bottom-left-radius: 4px;
}

.bubble.action {
  background: transparent;
  color: var(--text-muted);
  font-style: italic;
  font-size: 13px;
  padding: 2px 4px;
}

/* Voice bubble */
.voice-bubble {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 18px;
  min-width: 160px;
  cursor: pointer;
  user-select: none;
}

.bubble-wrap.user .voice-bubble {
  background: var(--bubble-user);
  color: var(--bubble-user-text);
  border-bottom-right-radius: 4px;
}

.bubble-wrap.ai .voice-bubble {
  background: var(--bubble-ai);
  color: var(--bubble-ai-text);
  border-bottom-left-radius: 4px;
}

.voice-play-btn {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: rgba(255,255,255,0.25);
  border: none;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.voice-play-btn svg { width: 14px; height: 14px; }

.voice-waveform {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 2px;
  height: 20px;
}

.voice-waveform span {
  display: block;
  width: 3px;
  border-radius: 2px;
  background: currentColor;
  opacity: 0.5;
  animation: none;
}

.voice-bubble.playing .voice-waveform span {
  animation: wave 0.8s ease-in-out infinite alternate;
  opacity: 0.8;
}

.voice-waveform span:nth-child(1) { height: 6px; animation-delay: 0s; }
.voice-waveform span:nth-child(2) { height: 12px; animation-delay: 0.1s; }
.voice-waveform span:nth-child(3) { height: 18px; animation-delay: 0.05s; }
.voice-waveform span:nth-child(4) { height: 10px; animation-delay: 0.15s; }
.voice-waveform span:nth-child(5) { height: 16px; animation-delay: 0.08s; }
.voice-waveform span:nth-child(6) { height: 8px; animation-delay: 0.12s; }
.voice-waveform span:nth-child(7) { height: 14px; animation-delay: 0.03s; }
.voice-waveform span:nth-child(8) { height: 10px; animation-delay: 0.18s; }

@keyframes wave {
  from { transform: scaleY(0.4); }
  to { transform: scaleY(1.2); }
}

.voice-duration {
  font-size: 12px;
  opacity: 0.7;
  min-width: 28px;
}

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

.typing {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  background: var(--bubble-ai);
  border-radius: 18px;
  border-bottom-left-radius: 4px;
  width: fit-content;
}

.typing span {
  width: 6px; height: 6px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: bounce 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }

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

.sys-msg {
  align-self: center;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--surface);
  padding: 4px 12px;
  border-radius: 10px;
}

#voice-preview {
  display: none;
  padding: 10px 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  gap: 10px;
  align-items: center;
  flex-shrink: 0;
}
#voice-preview.show { display: flex; }
#voice-preview .preview-play {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--bubble-user);
  border: none;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  color: #fff;
}
#voice-preview .preview-play svg { width: 14px; height: 14px; }
#voice-preview .preview-text {
  flex: 1;
  font-size: 13px;
  color: var(--text-muted);
  font-style: italic;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#voice-preview .preview-cancel {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: none;
  border: 1px solid var(--border);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
}
#voice-preview .preview-cancel svg { width: 14px; height: 14px; }

footer {
  padding: 12px 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-shrink: 0;
  position: relative;
}

textarea {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 10px 16px;
  font-size: 15px;
  font-family: inherit;
  background: var(--input-bg);
  color: var(--text);
  resize: none;
  outline: none;
  max-height: 120px;
  min-height: 42px;
  line-height: 1.4;
  overflow-y: auto;
}
textarea:focus { border-color: var(--bubble-user); }

.icon-btn {
  width: 42px; height: 42px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, border-color 0.15s;
}
.icon-btn svg { width: 18px; height: 18px; stroke: var(--text-muted); }
.icon-btn:hover { background: var(--border); }

#mic.recording {
  background: var(--mic-active);
  border-color: var(--mic-active);
  animation: pulse 1s ease-in-out infinite;
}
#mic.recording svg { stroke: #fff; }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(192,57,43,0.4); }
  50% { box-shadow: 0 0 0 8px rgba(192,57,43,0); }
}

#send {
  background: var(--send-bg);
  border-color: var(--send-bg);
}
#send svg { stroke: #fff; }
#send:hover { background: var(--send-hover); border-color: var(--send-hover); }
#send:disabled { opacity: 0.5; cursor: default; }

/* Image preview bar */
#image-preview-bar {
  display: none;
  padding: 8px 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
#image-preview-bar.show { display: flex; }
#image-thumb {
  width: 52px; height: 52px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}
#image-preview-name {
  flex: 1;
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#image-preview-cancel {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: none;
  border: 1px solid var(--border);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
  flex-shrink: 0;
}
#image-preview-cancel svg { width: 12px; height: 12px; }

/* Image attachment menu */
#attach-menu {
  display: none;
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.12);
  overflow: hidden;
  z-index: 50;
}
#attach-menu.show { display: block; }
.attach-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
.attach-option:hover { background: var(--surface); }
.attach-option:not(:last-child) { border-bottom: 1px solid var(--border); }
.attach-option svg { width: 18px; height: 18px; stroke: var(--text-muted); }

/* Image bubble */
.img-bubble {
  max-width: 220px;
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
}
.img-bubble img {
  display: block;
  width: 100%;
  max-height: 300px;
  object-fit: cover;
}


/* ========== Responsive (base) ========== */
@media (max-width: 480px) {
  .bubble-wrap { max-width: 88%; }
  header { padding: 10px 14px; }
  footer { padding: 8px 12px; }
}

