/* RHAAFS v1 — Stylesheet */
:root {
  --font-size: 16px;
  --transition: 0.2s ease;
}

/* Dark Theme (default) */
[data-theme="dark"] {
  --bg-primary: #1e1e2e;
  --bg-secondary: #252536;
  --bg-sidebar: #16161e;
  --bg-input: #2a2a3c;
  --text-primary: #e0e0e0;
  --text-secondary: #a0a0b0;
  --accent: #7c5cfc;
  --accent-hover: #9b7eff;
  --border: #33334a;
  --shadow: 0 2px 8px rgba(0,0,0,0.3);
  --message-user-bg: #2a2a3c;
  --message-ai-bg: #1e1e2e;
  --error: #ff5555;
}

/* Light Theme */
[data-theme="light"] {
  --bg-primary: #ffffff;
  --bg-secondary: #f5f5f7;
  --bg-sidebar: #f0f0f5;
  --bg-input: #e8e8ee;
  --text-primary: #1a1a2e;
  --text-secondary: #5a5a7a;
  --accent: #6c5ce7;
  --accent-hover: #8b7cf0;
  --border: #dddde8;
  --shadow: 0 2px 8px rgba(0,0,0,0.05);
  --message-user-bg: #e8e8ee;
  --message-ai-bg: #f5f5f7;
  --error: #d32f2f;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Inter', 'Poppins', sans-serif;
  font-size: var(--font-size);
  background: var(--bg-primary);
  color: var(--text-primary);
  transition: background var(--transition), color var(--transition);
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* -------- Sidebar -------- */
.sidebar {
  width: 280px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease;
  z-index: 10;
}

.sidebar-header {
  padding: 1.2rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo {
  width: 36px;
  height: 36px;
}

.sidebar-title {
  font-size: 1.2rem;
  font-weight: 600;
}

.new-chat-btn {
  margin: 1rem;
  padding: 0.7rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: background var(--transition);
}

.new-chat-btn:hover {
  background: var(--accent-hover);
}

.chat-history {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
}

.history-item {
  padding: 0.8rem;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--text-secondary);
  transition: background var(--transition);
  margin-bottom: 0.2rem;
}

.history-item:hover,
.history-item.active {
  background: var(--bg-primary);
}

.history-title {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.9rem;
}

.history-actions {
  display: none;
  gap: 0.3rem;
}

.history-item:hover .history-actions {
  display: flex;
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0.3rem;
  border-radius: 4px;
  transition: color var(--transition), background var(--transition);
}

.icon-btn:hover {
  color: var(--accent);
  background: rgba(124, 92, 252, 0.1);
}

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding: 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.sidebar-footer .icon-btn {
  justify-content: flex-start;
  padding: 0.5rem 0.8rem;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
}

/* -------- Main -------- */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.header {
  padding: 0.8rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-secondary);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.menu-btn {
  display: none;
  font-size: 1.4rem;
}

.header-logo {
  width: 32px;
  height: 32px;
}

.model-info {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.model-select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
  color: var(--text-primary);
  font-size: 0.85rem;
  cursor: pointer;
}

.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 2rem;
  scroll-behavior: smooth;
}

.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  gap: 2rem;
  color: var(--text-secondary);
}

.welcome-logo {
  width: 80px;
  opacity: 0.8;
}

.example-prompts {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
  justify-content: center;
  max-width: 600px;
}

.example-prompt {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 0.6rem 1.2rem;
  cursor: pointer;
  transition: background var(--transition);
}

.example-prompt:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* Message bubbles */
.message {
  max-width: 85%;
  margin-bottom: 1.5rem;
  animation: fadeIn 0.3s ease;
}

.message.user {
  margin-left: auto;
}

.message .message-content {
  padding: 0.8rem 1rem;
  border-radius: 16px;
  line-height: 1.6;
  word-wrap: break-word;
}

.message.user .message-content {
  background: var(--message-user-bg);
  border-bottom-right-radius: 4px;
}

.message.assistant .message-content {
  background: var(--message-ai-bg);
  border-bottom-left-radius: 4px;
}

.message.error .message-content {
  background: rgba(255,80,80,0.1);
  color: var(--error);
}

.message-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.3rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.model-badge {
  background: var(--accent);
  color: white;
  padding: 0.1rem 0.5rem;
  border-radius: 10px;
  font-size: 0.7rem;
  text-transform: uppercase;
}

.message-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.3rem;
  opacity: 0;
  transition: opacity 0.2s;
}

.message:hover .message-actions {
  opacity: 1;
}

/* Input area */
.input-area {
  padding: 1rem 2rem;
  border-top: 1px solid var(--border);
  background: var(--bg-secondary);
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.5rem;
}

.prompt-input {
  flex: 1;
  resize: none;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-family: inherit;
  font-size: inherit;
  padding: 0.5rem;
  outline: none;
  max-height: 150px;
}

.send-btn {
  background: var(--accent);
  border: none;
  color: white;
  padding: 0.6rem 0.8rem;
  border-radius: 8px;
  cursor: pointer;
  transition: background var(--transition);
  margin-left: 0.5rem;
}

.send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.send-btn:hover:not(:disabled) {
  background: var(--accent-hover);
}

.char-counter {
  text-align: right;
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 0.3rem;
}

/* Loading dots */
.loading-indicator {
  display: none;
  align-items: center;
  gap: 0.3rem;
  padding: 0.8rem 2rem;
}

.dot {
  width: 8px;
  height: 8px;
  background: var(--accent);
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out;
}

.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-10px); }
}

/* Modals */
.modal {
  display: none;
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.5);
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal.show {
  display: flex;
}

.modal-content {
  background: var(--bg-primary);
  border-radius: 16px;
  padding: 2rem;
  min-width: 320px;
  max-width: 500px;
  box-shadow: var(--shadow);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.font-options {
  display: flex;
  gap: 0.5rem;
  margin: 1rem 0;
}

.font-option {
  padding: 0.4rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  background: var(--bg-secondary);
}

.font-option.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.danger-btn {
  background: var(--error);
  color: white;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  margin-top: 1rem;
  cursor: pointer;
  width: 100%;
}

.danger-btn + .danger-btn {
  margin-top: 0.5rem;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Responsive */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: -280px;
    top: 0;
    bottom: 0;
    transform: translateX(0);
  }

  .sidebar.open {
    transform: translateX(280px);
  }

  .menu-btn {
    display: block;
  }

  .messages {
    padding: 1rem;
  }

  .input-area {
    padding: 0.8rem;
  }
}