/* === Memito Chat — Warm Dark Theme === */

:root {
  --bg-primary: #0f0f1a;
  --bg-secondary: #1a1a2e;
  --bg-tertiary: #252540;
  --accent: #f0a500;
  --accent-soft: #f0a50033;
  --accent-glow: #f0a50066;
  --user-bubble: #2a4a7f;
  --user-text: #e8edf4;
  --bot-bubble: #1e1e35;
  --bot-text: #d4d4e8;
  --text-primary: #e8e8f0;
  --text-secondary: #8888aa;
  --text-muted: #555577;
  --border: #2a2a45;
  --danger: #e74c3c;
  --success: #2ecc71;
  --radius: 16px;
  --radius-sm: 10px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --shadow: 0 4px 20px rgba(0,0,0,0.3);
}

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

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
}

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

/* === Header === */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--accent-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  border: 2px solid var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
}

.header-info h1 {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: 0.5px;
}

.header-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.status-indicator {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
}
.status-indicator.online { background: var(--success); box-shadow: 0 0 6px var(--success); }
.status-indicator.offline { background: var(--danger); }
.status-indicator.connecting { background: var(--accent); animation: pulse 1.5s infinite; }

.status-text {
  font-size: 12px;
  color: var(--text-secondary);
}

.header-center {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  max-width: 200px;
}

.session-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--bg-tertiary);
  border-radius: 20px;
  font-size: 11px;
}

.model-badge {
  font-weight: 600;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: background 0.2s ease;
}

.model-badge:hover {
  background: var(--bg-primary);
}

.model-badge.clickable {
  cursor: pointer;
}

.model-badge.opus {
  color: #a855f7;
}

.model-badge.sonnet {
  color: var(--accent);
}

.thinking-badge {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  background: transparent;
  border: 1px solid var(--border);
  cursor: pointer;
  padding: 2px 8px;
  border-radius: 12px;
  transition: all 0.2s ease;
  margin-left: 4px;
}

.thinking-badge:hover {
  background: var(--bg-primary);
  border-color: var(--accent);
}

.thinking-badge.active {
  color: #22c55e;
  border-color: #22c55e;
  background: rgba(34, 197, 94, 0.1);
}

.context-bar {
  width: 60px;
  height: 6px;
  background: var(--bg-primary);
  border-radius: 3px;
  overflow: hidden;
  position: relative;
  border: 1px solid var(--border);
}

.context-fill {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #ffcc00);
  border-radius: 2px;
  transition: width 0.5s ease, background 0.3s ease;
  width: 0%;
  min-width: 2px;
}

.context-fill.warning {
  background: linear-gradient(90deg, #f39c12, #ffaa00);
}

.context-fill.danger {
  background: linear-gradient(90deg, var(--danger), #ff6b6b);
}

.context-text.warning {
  color: #f39c12;
}

.context-text.danger {
  color: var(--danger);
}

.context-text {
  color: var(--text-secondary);
  min-width: 32px;
  text-align: right;
}

.tokens-text {
  color: var(--text-muted);
  font-size: 10px;
  padding-left: 4px;
  border-left: 1px solid var(--border);
  margin-left: 4px;
}

.header-right {
  display: flex;
  gap: 8px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--bg-tertiary);
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.icon-btn:hover { background: var(--border); transform: scale(1.05); }

/* === Chat Container === */
#chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  scroll-behavior: smooth;
}

#messages {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 100%;
  justify-content: flex-end;
}

/* Welcome */
.welcome-message {
  text-align: center;
  padding: 60px 20px 40px;
  animation: fadeIn 0.6s ease;
}
.welcome-avatar {
  font-size: 72px;
  margin-bottom: 16px;
  animation: bounce 2s infinite;
}
.welcome-message h2 {
  font-size: 24px;
  color: var(--accent);
  margin-bottom: 8px;
}
.welcome-message p {
  color: var(--text-secondary);
  font-size: 15px;
}

/* Message Bubbles */
.message {
  display: flex;
  gap: 10px;
  max-width: 80%;
  animation: slideIn 0.3s ease;
}

.message.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message.bot {
  align-self: flex-start;
}

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.message.bot .msg-avatar {
  background: var(--accent-soft);
}
.message.user .msg-avatar {
  background: var(--user-bubble);
  font-size: 14px;
}

.msg-content {
  padding: 12px 16px;
  border-radius: var(--radius);
  line-height: 1.5;
  font-size: 14px;
  position: relative;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.message.bot .msg-content {
  background: var(--bot-bubble);
  color: var(--bot-text);
  border-bottom-left-radius: 4px;
}

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

.msg-time {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 6px;
  text-align: right;
}
.message.bot .msg-time { text-align: left; }

.msg-content p { margin-bottom: 8px; }
.msg-content p:last-child { margin-bottom: 0; }
.msg-content code {
  background: rgba(255,255,255,0.1);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
}
.msg-content pre {
  background: rgba(0,0,0,0.3);
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 8px 0;
}
.msg-content pre code {
  background: none;
  padding: 0;
}
.msg-content strong { color: var(--accent); }
.msg-content a { color: var(--accent); text-decoration: underline; }
.msg-content ul, .msg-content ol { padding-left: 20px; margin: 8px 0; }
.msg-content li { margin-bottom: 4px; }
.msg-content h1, .msg-content h2, .msg-content h3 {
  color: var(--accent);
  margin: 12px 0 6px;
  font-size: 16px;
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
}
.typing-dots {
  display: flex;
  gap: 4px;
}
.typing-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-secondary);
  animation: typing 1.4s infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

.typing-text {
  color: var(--text-secondary);
  font-size: 13px;
  animation: fadeInOut 2s infinite;
}

@keyframes fadeInOut {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

/* Voice play button in messages */
.voice-play-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid var(--accent-soft);
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  font-size: 12px;
  transition: all 0.2s;
}
.voice-play-btn:hover {
  background: var(--accent-soft);
}

/* === Input Area === */
#input-area {
  padding: 12px 20px 20px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--bg-tertiary);
  border-radius: var(--radius);
  padding: 8px 12px;
  border: 1px solid var(--border);
  transition: border-color 0.2s;
}
.input-wrapper:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
}

#input-text {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 15px;
  resize: none;
  outline: none;
  max-height: 120px;
  line-height: 1.4;
  padding: 6px 0;
}
#input-text::placeholder { color: var(--text-muted); }

.mic-btn, .send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
}

.mic-btn {
  background: var(--bg-secondary);
  color: var(--text-secondary);
}
.mic-btn:hover { background: var(--accent-soft); color: var(--accent); }
.mic-btn.active {
  background: var(--danger);
  color: white;
  animation: pulse 1.5s infinite;
}

.send-btn {
  background: var(--accent);
  color: var(--bg-primary);
}
.send-btn:hover { transform: scale(1.05); filter: brightness(1.1); }
.send-btn:disabled { opacity: 0.3; cursor: default; transform: none; }

/* Voice Indicator */
.voice-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 12px;
  margin-top: 8px;
  background: var(--accent-soft);
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--accent);
}
.voice-indicator.hidden { display: none; }

.pulse-ring {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1s infinite;
}

.stop-voice-btn {
  padding: 4px 12px;
  border-radius: 20px;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  font-size: 12px;
}

/* Typing cursor */
.typing-cursor {
  color: var(--accent);
  animation: blink 0.8s infinite;
  font-size: 14px;
  margin-left: 2px;
}
@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* === Scrollbar === */
#chat-container::-webkit-scrollbar { width: 6px; }
#chat-container::-webkit-scrollbar-track { background: transparent; }
#chat-container::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* === Animations === */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

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

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(1.1); }
}

@keyframes typing {
  0%, 100% { opacity: 0.3; transform: translateY(0); }
  50% { opacity: 1; transform: translateY(-4px); }
}

/* === Attach Button === */
.attach-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.attach-btn:hover {
  color: var(--accent);
  background: var(--accent-soft);
}

/* === Image Preview Overlay === */
.image-preview {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(8px);
}
.image-preview.hidden { display: none; }
.image-preview-content {
  background: var(--bg-secondary);
  border-radius: 16px;
  padding: 16px;
  max-width: 500px;
  width: 90%;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.image-preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--text-secondary);
  font-size: 14px;
}
.image-preview-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  overflow-y: auto;
  max-height: 50vh;
  justify-content: center;
}
.image-preview-grid .preview-item {
  position: relative;
  border-radius: 8px;
  overflow: hidden;
  max-width: 220px;
}
.image-preview-grid .preview-item img {
  width: 100%;
  height: auto;
  display: block;
  border-radius: 8px;
}
.image-preview-grid .preview-item .remove-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(0,0,0,0.7);
  color: white;
  border: none;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  cursor: pointer;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.image-preview-footer {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.image-preview-footer textarea {
  flex: 1;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text-primary);
  padding: 8px 12px;
  font-family: inherit;
  font-size: 14px;
  resize: none;
  outline: none;
}
.image-preview-footer textarea:focus {
  border-color: var(--accent);
}

/* === Drop Zone === */
.drop-zone {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(240, 165, 0, 0.1);
  border: 3px dashed var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  backdrop-filter: blur(4px);
}
.drop-zone.hidden { display: none; }
.drop-zone-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: var(--accent);
  font-size: 20px;
  font-weight: 600;
}
.drop-zone-icon { font-size: 48px; }

/* === Image in messages === */
.msg-image {
  max-width: 280px;
  border-radius: 8px;
  margin-bottom: 8px;
  cursor: pointer;
}
.msg-image:hover { opacity: 0.9; }

/* === Responsive === */
@media (max-width: 600px) {
  #app { max-width: 100%; }
  .message { max-width: 90%; }
  header { padding: 12px 16px; }
  #chat-container { padding: 12px; }
  #input-area { padding: 8px 12px 16px; }
}


/* Toast Notifications */
.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-secondary);
  color: var(--text-primary);
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border);
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 1000;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast-error {
  background: rgba(239, 68, 68, 0.9);
  border-color: #ef4444;
}

.toast-info {
  background: rgba(240, 165, 0, 0.9);
  border-color: var(--accent);
}


/* === Activity / Verbose Mode === */

.activity-mode-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
}

/* Activity indicator (clean mode) */
.activity-msg .activity-status {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  font-size: 0.9em;
  color: var(--text-secondary);
  animation: fadeInUp 0.2s ease;
}

.activity-pulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: activityPulse 1.5s ease-in-out infinite;
}

@keyframes activityPulse {
  0%, 100% { opacity: 0.4; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1.2); }
}

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

.activity-text {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.85em;
  letter-spacing: 0.02em;
}

/* Verbose messages (detailed mode) */
.verbose-msg {
  animation: fadeInUp 0.15s ease;
}

.verbose-msg .msg-avatar {
  font-size: 0.8em;
}

.verbose-content {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.8em;
  color: var(--text-muted);
  padding: 4px 8px !important;
  background: rgba(255,255,255,0.03) !important;
  border-radius: 8px !important;
  border-left: 2px solid var(--accent-soft);
}

.verbose-text {
  color: var(--text-secondary);
}

.verbose-result {
  color: var(--text-muted);
  font-size: 0.9em;
}
