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

:root {
  --bg-primary: #0f0f13;
  --bg-secondary: #16161e;
  --bg-tertiary: #1e1e2a;
  --bg-input: #1a1a24;
  --border: #2a2a3a;
  --accent: #7c6fe0;
  --accent-hover: #9585f5;
  --accent-glow: rgba(124, 111, 224, 0.3);
  --text-primary: #e8e8f0;
  --text-secondary: #8888aa;
  --text-muted: #555570;
  --msg-user-bg: #1e1e35;
  --msg-ai-bg: #16161e;
  --success: #4ade80;
  --danger: #f87171;
  --sidebar-width: 280px;
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.2s ease;
}

html, body {
  height: 100%;
  font-family: "Inter", sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
}

/* ── App Layout ── */
.app {
  display: flex;
  height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 16px 16px;
  border-bottom: 1px solid var(--border);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.logo-icon {
  width: 34px;
  height: 34px;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  box-shadow: 0 0 14px var(--accent-glow);
}

.logo-text { color: var(--text-primary); }

.btn-new-chat {
  width: 34px;
  height: 34px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 1.4rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  line-height: 1;
}

.btn-new-chat:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  box-shadow: 0 0 12px var(--accent-glow);
}

.sessions-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px 8px;
}

.sessions-list::-webkit-scrollbar { width: 4px; }
.sessions-list::-webkit-scrollbar-track { background: transparent; }
.sessions-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.sessions-empty {
  color: var(--text-muted);
  font-size: 0.8rem;
  text-align: center;
  padding: 24px 10px;
  line-height: 1.6;
}

.session-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  margin-bottom: 2px;
}

.session-item:hover { background: var(--bg-tertiary); }
.session-item.active { background: var(--bg-tertiary); border: 1px solid var(--accent); }

.session-title {
  font-size: 0.82rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.session-item.active .session-title { color: var(--text-primary); }

.session-delete {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 2px 4px;
  border-radius: 4px;
  opacity: 0;
  transition: var(--transition);
  flex-shrink: 0;
}

.session-item:hover .session-delete { opacity: 1; }
.session-delete:hover { color: var(--danger); background: rgba(248, 113, 113, 0.1); }

/* ── Chat Main ── */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-primary);
}

.chat-container {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.chat-container::-webkit-scrollbar { width: 5px; }
.chat-container::-webkit-scrollbar-track { background: transparent; }
.chat-container::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Chat Empty State ── */
.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 40px;
  text-align: center;
}

.chat-empty-icon {
  width: 72px;
  height: 72px;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.2rem;
  box-shadow: 0 0 40px var(--accent-glow);
  animation: pulse 3s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 30px var(--accent-glow); }
  50% { box-shadow: 0 0 60px var(--accent-glow); }
}

.chat-empty h1 {
  font-size: 1.8rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, #e8e8f0, var(--accent-hover));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.chat-empty p {
  color: var(--text-secondary);
  font-size: 0.95rem;
  max-width: 340px;
  line-height: 1.6;
}

.btn-start-chat {
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  color: white;
  border: none;
  padding: 12px 28px;
  border-radius: 100px;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: 0 4px 20px var(--accent-glow);
}

.btn-start-chat:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 28px var(--accent-glow);
}

/* ── Messages ── */
.messages {
  flex: 1;
  padding: 24px 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.message {
  padding: 18px 48px;
  animation: fadeIn 0.3s ease;
}

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

.message.user { background: var(--msg-user-bg); }
.message.assistant { background: var(--msg-ai-bg); }

.message-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.message-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
}

.message.user .message-avatar {
  background: linear-gradient(135deg, #4ade80, #22c55e);
  color: white;
}

.message.assistant .message-avatar {
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  color: white;
}

.message-author {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.message-content {
  font-size: 0.92rem;
  line-height: 1.75;
  color: var(--text-primary);
  white-space: pre-wrap;
  word-break: break-word;
}

/* ── Typing indicator ── */
.typing-indicator {
  padding: 18px 48px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.typing-dots {
  display: flex;
  gap: 5px;
}

.typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  animation: bounce 1.2s ease-in-out infinite;
}

.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-8px); opacity: 1; }
}

/* ── Chat Input ── */
.chat-input-area {
  border-top: 1px solid var(--border);
  padding: 16px 48px 20px;
  background: var(--bg-primary);
}

.chat-input-wrapper {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  transition: var(--transition);
}

.chat-input-wrapper:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

textarea#messageInput {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.92rem;
  line-height: 1.6;
  resize: none;
  max-height: 200px;
  overflow-y: auto;
}

textarea#messageInput::placeholder { color: var(--text-muted); }

.btn-send {
  width: 36px;
  height: 36px;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: var(--transition);
}

.btn-send:hover {
  background: var(--accent-hover);
  box-shadow: 0 0 14px var(--accent-glow);
}

.btn-send:disabled {
  background: var(--bg-tertiary);
  color: var(--text-muted);
  cursor: not-allowed;
  box-shadow: none;
}

.input-hint {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 8px;
  text-align: center;
}

/* ── Responsive ── */
@media (max-width: 640px) {
  .sidebar { display: none; }
  .message { padding: 16px 20px; }
  .chat-input-area { padding: 12px 20px 16px; }
  .typing-indicator { padding: 16px 20px; }
}

/* ── Sidebar Footer ── */
.sidebar-footer {
  padding: 12px 8px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.btn-personality {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}

.btn-personality:hover {
  background: var(--bg-tertiary);
  border-color: var(--accent);
  color: var(--accent-hover);
}

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 540px;
  max-width: calc(100vw - 40px);
  max-height: calc(100vh - 60px);
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5);
  transform: translateY(12px);
  transition: transform 0.2s ease;
}

.modal-overlay.open .modal {
  transform: translateY(0);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1rem;
  cursor: pointer;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.modal-close:hover { background: var(--bg-tertiary); color: var(--text-primary); }

.modal-body {
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
}

.modal-description {
  font-size: 0.82rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

#personalityInput {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.88rem;
  line-height: 1.65;
  padding: 12px 14px;
  resize: vertical;
  outline: none;
  transition: var(--transition);
  min-height: 140px;
}

#personalityInput:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

#personalityInput::placeholder { color: var(--text-muted); }

.modal-presets {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.presets-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  flex-shrink: 0;
}

.preset-btn {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 100px;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 500;
  padding: 4px 12px;
  cursor: pointer;
  transition: var(--transition);
}

.preset-btn:hover {
  border-color: var(--accent);
  color: var(--accent-hover);
  background: rgba(124, 111, 224, 0.08);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
}

.btn-modal-cancel {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.85rem;
  padding: 8px 18px;
  cursor: pointer;
  transition: var(--transition);
}

.btn-modal-cancel:hover { background: var(--bg-tertiary); }

.btn-modal-save {
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  border: none;
  border-radius: var(--radius-sm);
  color: white;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 8px 20px;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: 0 2px 12px var(--accent-glow);
}

.btn-modal-save:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 18px var(--accent-glow);
}

/* Badge indicando personalidade ativa */
.btn-personality.active {
  border-color: var(--accent);
  color: var(--accent-hover);
  background: rgba(124, 111, 224, 0.08);
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-size: 0.84rem;
  font-family: inherit;
  padding: 10px 20px;
  border-radius: 100px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 200;
  white-space: nowrap;
}

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


