/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-primary: #0f0f1a;
  --bg-secondary: #1a1a2e;
  --bg-card: #16213e;
  --bg-input: #1e1e35;
  --accent: #6c63ff;
  --accent-glow: #6c63ff44;
  --accent-2: #ff6584;
  --text-primary: #e8e8f0;
  --text-secondary: #8888aa;
  --text-muted: #555577;
  --bubble-ai: #1e1e38;
  --bubble-user: #6c63ff;
  --success: #43e97b;
  --warning: #f6d365;
  --error: #ff6b6b;
  --border: #2a2a4a;
  --shadow: 0 8px 32px rgba(108,99,255,0.15);
  --radius: 18px;
  --radius-sm: 10px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ===== APP LAYOUT ===== */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
  background: var(--bg-primary);
}

/* ===== HEADER ===== */
.header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 10;
  backdrop-filter: blur(20px);
}

.header-avatar {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
  box-shadow: 0 0 20px var(--accent-glow);
  position: relative;
}

.header-avatar::after {
  content: '';
  position: absolute;
  bottom: 2px; right: 2px;
  width: 10px; height: 10px;
  background: var(--success);
  border-radius: 50%;
  border: 2px solid var(--bg-secondary);
}

.header-info { flex: 1; }
.header-name { font-size: 16px; font-weight: 700; color: var(--text-primary); }
.header-status { font-size: 12px; color: var(--success); display: flex; align-items: center; gap: 4px; }
.header-status::before { content: ''; width: 6px; height: 6px; background: var(--success); border-radius: 50%; display: inline-block; animation: pulse 2s infinite; }

.header-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-size: 16px;
  transition: all 0.2s;
}
.header-btn:hover { background: var(--accent); color: white; border-color: var(--accent); }

/* ===== QUICK ACTIONS ===== */
.quick-actions {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  overflow-x: auto;
  scrollbar-width: none;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}
.quick-actions::-webkit-scrollbar { display: none; }

.quick-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
  flex-shrink: 0;
}
.quick-btn:hover, .quick-btn.active {
  background: var(--accent-glow);
  border-color: var(--accent);
  color: var(--accent);
}
.quick-btn span { font-size: 14px; }

/* ===== CHAT AREA ===== */
.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}
.chat-area::-webkit-scrollbar { width: 4px; }
.chat-area::-webkit-scrollbar-track { background: transparent; }
.chat-area::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ===== MESSAGES ===== */
.msg-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  animation: fadeInUp 0.3s ease;
}
.msg-group.user { align-items: flex-end; }
.msg-group.ai { align-items: flex-start; }

.msg-row { display: flex; align-items: flex-end; gap: 8px; width: 100%; }
.msg-group.user .msg-row { flex-direction: row-reverse; }

.msg-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
  margin-bottom: 2px;
}

.bubble {
  max-width: 78%;
  min-width: 48px;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.6;
  position: relative;
  overflow-wrap: break-word;
  word-break: break-word;
}

.msg-group.ai .bubble {
  background: var(--bubble-ai);
  border: 1px solid var(--border);
  border-bottom-left-radius: 6px;
  color: var(--text-primary);
  white-space: normal;
}
.msg-group.user .bubble {
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  border-bottom-right-radius: 6px;
  color: white;
  box-shadow: 0 4px 20px var(--accent-glow);
  white-space: pre-wrap;
}

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

/* ===== TYPING INDICATOR ===== */
.typing-indicator {
  display: none;
  align-items: flex-end;
  gap: 8px;
}
.typing-indicator.show { display: flex; }

.typing-bubble {
  background: var(--bubble-ai);
  border: 1px solid var(--border);
  border-bottom-left-radius: 6px;
  border-radius: var(--radius);
  padding: 14px 18px;
  display: flex;
  gap: 5px;
  align-items: center;
}
.dot {
  width: 7px; height: 7px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: bounce 1.2s infinite;
}
.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }

/* ===== STATUS CARDS (kết quả workflow) ===== */
.result-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-top: 8px;
  font-size: 13px;
}
.result-card.success { border-left: 3px solid var(--success); }
.result-card.error { border-left: 3px solid var(--error); }
.result-card.processing { border-left: 3px solid var(--warning); }
.result-card .rc-title { font-weight: 600; margin-bottom: 6px; }
.result-card .rc-row { color: var(--text-secondary); margin: 3px 0; }

/* ===== INPUT AREA ===== */
.input-area {
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

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

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

.send-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  border: none;
  color: white;
  font-size: 18px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
  flex-shrink: 0;
  box-shadow: 0 4px 15px var(--accent-glow);
}
.send-btn:hover { transform: scale(1.1); box-shadow: 0 6px 20px var(--accent-glow); }
.send-btn:active { transform: scale(0.95); }
.send-btn:disabled { opacity: 0.5; transform: none; cursor: not-allowed; }

/* ===== SETTINGS PANEL ===== */
.settings-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 100;
  display: none;
  align-items: flex-end;
  backdrop-filter: blur(4px);
}
.settings-overlay.show { display: flex; }

.settings-panel {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  background: var(--bg-secondary);
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 24px 20px;
  border-top: 1px solid var(--border);
  animation: slideUp 0.3s ease;
}
.settings-title {
  font-size: 18px; font-weight: 700;
  margin-bottom: 20px;
  display: flex; align-items: center; justify-content: space-between;
}
.settings-close { cursor: pointer; color: var(--text-secondary); font-size: 20px; }

.setting-group { margin-bottom: 16px; }
.setting-label { font-size: 12px; color: var(--text-secondary); margin-bottom: 6px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.5px; }
.setting-input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  color: var(--text-primary);
  font-size: 14px;
  font-family: var(--font);
  outline: none;
}
.setting-input:focus { border-color: var(--accent); }

.save-btn {
  width: 100%;
  padding: 12px;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  border: none;
  border-radius: var(--radius-sm);
  color: white;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
  transition: opacity 0.2s;
}
.save-btn:hover { opacity: 0.9; }

/* ===== WELCOME MSG ===== */
.welcome {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-secondary);
}
.welcome-icon { font-size: 64px; margin-bottom: 16px; }
.welcome h2 { font-size: 22px; color: var(--text-primary); margin-bottom: 8px; }
.welcome p { font-size: 14px; line-height: 1.6; }

/* ===== ANIMATIONS ===== */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* ===== SAFE AREA (iPhone notch) ===== */
.input-area { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
.header { padding-top: max(16px, env(safe-area-inset-top)); }

/* ===== RESPONSIVE desktop ===== */
@media (min-width: 480px) {
  #app { border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
  body { background: #07070f; }
}

/* ===== NEW UI OVERHAUL ===== */
.header-right { position: relative; }
.settings-dropdown { position: relative; }
.icon-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 16px; transition: all 0.2s;
}
.icon-btn:hover { background: var(--accent); color: white; border-color: var(--accent); }

.dropdown-content {
  display: none; position: absolute; right: 0; top: 44px;
  background: var(--bg-card); min-width: 180px;
  border-radius: 12px; border: 1px solid var(--border);
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  flex-direction: column; padding: 8px; z-index: 50;
}
.dropdown-content.show { display: flex; animation: fadeInUp 0.2s ease; }
.dropdown-item {
  background: transparent; border: none; color: var(--text-primary);
  padding: 10px 12px; text-align: left; font-size: 14px;
  border-radius: 8px; cursor: pointer; display: flex; align-items: center; gap: 8px;
  transition: background 0.2s;
}
.dropdown-item:hover { background: var(--bg-input); }
.dropdown-divider { height: 1px; background: var(--border); margin: 6px 0; }

/* PILL INPUT AREA */
.input-area {
  padding: 12px 16px; background: var(--bg-primary); border-top: none;
}
.pill-container { flex: 1; width: 100%;
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--bg-input); border-radius: 28px;
  padding: 8px 12px; border: 1px solid var(--border);
  transition: border-color 0.2s; position: relative;
}
.pill-container:focus-within { border-color: var(--text-secondary); }

.pill-btn {
  background: transparent; border: none; color: var(--text-secondary);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; border-radius: 50%; transition: all 0.2s;
}
.plus-btn { width: 32px; height: 32px; font-size: 24px; font-weight: 300; }
.plus-btn:hover { background: var(--bg-card); color: var(--text-primary); }

.mode-btn {
  padding: 6px 12px; border-radius: 16px; font-size: 13px; font-weight: 500;
  gap: 4px; color: var(--text-primary); background: var(--bg-card);
}
.mode-btn:hover { background: var(--border); }
.caret { font-size: 10px; opacity: 0.7; }

.pill-send-btn {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent); color: white; border: none;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 14px; transition: transform 0.2s;
}
.pill-send-btn:hover { transform: scale(1.1); }
.pill-send-btn:disabled { background: var(--border); color: var(--text-muted); transform: none; }

#msg-input {
  flex: 1; background: transparent; border: none; color: var(--text-primary);
  font-size: 15px; resize: none; padding: 6px 0; max-height: 120px;
  font-family: var(--font); outline: none; line-height: 1.4;
  scrollbar-width: none; /* Firefox */
}
#msg-input::-webkit-scrollbar { display: none; /* Chrome/Safari */ }
#msg-input::placeholder { color: var(--text-muted); }

/* DROPUP MENUS */
.action-menu-wrapper { position: relative; display: flex; align-items: flex-end; }
.dropup-content {
  display: none; position: absolute; bottom: 100%; left: 0;
  margin-bottom: 8px; background: var(--bg-card);
  border: 1px solid var(--border); border-radius: 12px;
  padding: 8px; box-shadow: 0 -4px 20px rgba(0,0,0,0.5);
  flex-direction: column; min-width: 180px; z-index: 50;
}
.mode-dropup { left: auto; right: 0; min-width: 150px; }
.dropup-content.show { display: flex; animation: slideUpSmall 0.2s ease; }
@keyframes slideUpSmall {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.dropup-item {
  padding: 10px 12px; display: flex; align-items: center; gap: 8px;
  font-size: 14px; color: var(--text-primary); cursor: pointer;
  border-radius: 8px; transition: background 0.2s;
}
.dropup-item:hover { background: var(--bg-input); }
.dropup-item.active { background: var(--accent-glow); color: var(--accent); }
