:root {
  /* Pastel Palette - Light */
  --bg-primary: #faf8f5;
  --bg-secondary: #f5f0eb;
  --bg-tertiary: #ebe5de;
  --surface: #ffffff;
  --surface-hover: #f9f7f4;
  
  --text-primary: #2d2a26;
  --text-secondary: #6b6560;
  --text-muted: #9a9590;
  
  --accent: #b8a5e3;
  --accent-hover: #a48fd6;
  --accent-light: #ede7f9;
  
  --user-bubble: #d4e4ed;
  --user-bubble-text: #1e3a4f;
  --ai-bubble: #f5f0eb;
  --ai-bubble-text: #2d2a26;
  
  --border: #e8e3dc;
  --border-light: #f0ece6;
  
  --success: #a8d5ba;
  --warning: #f5d89a;
  --error: #e8a5a5;
  
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.08);
  
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  
  --sidebar-width: 280px;
  --header-height: 60px;
  
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
  --transition-slow: 350ms ease;
}

[data-theme="dark"] {
  --bg-primary: #1a1918;
  --bg-secondary: #242220;
  --bg-tertiary: #2e2b28;
  --surface: #2a2725;
  --surface-hover: #333028;
  
  --text-primary: #f0ece6;
  --text-secondary: #a8a29e;
  --text-muted: #78716c;
  
  --accent: #c4b5fd;
  --accent-hover: #d4c8fe;
  --accent-light: #3b3654;
  
  --user-bubble: #3d5a6e;
  --user-bubble-text: #e8f0f5;
  --ai-bubble: #2e2b28;
  --ai-bubble-text: #f0ece6;
  
  --border: #3d3a36;
  --border-light: #2e2b28;
  
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.4);
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  overflow: hidden;
}

/* App Container */
.app-container {
  display: flex;
  height: 100vh;
  width: 100vw;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: transform var(--transition-normal);
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid var(--border-light);
}

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

.logo-mark {
  width: 52px;
  height: 52px;
  object-fit: contain;
  filter: drop-shadow(0 6px 16px rgba(0, 0, 0, 0.12));
}

.logo-wordmark {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.logo-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
}

.logo-subtitle {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.18em;
}

.new-chat-btn {
  margin: 16px;
  padding: 12px 16px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all var(--transition-fast);
}

.new-chat-btn:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.new-chat-btn .icon {
  font-size: 1.2rem;
  font-weight: 400;
}

.chat-history {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.chat-history-item {
  padding: 12px 16px;
  margin-bottom: 4px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: all var(--transition-fast);
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.chat-history-item:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.chat-history-item.active {
  background: var(--accent-light);
  color: var(--text-primary);
}

.chat-history-item .chat-icon {
  width: 28px;
  height: 28px;
  border-radius: 10px;
  background: rgba(184, 165, 227, 0.14);
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.chat-history-item .chat-title {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-history-item .delete-chat {
  opacity: 0;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: all var(--transition-fast);
}

.chat-history-item:hover .delete-chat {
  opacity: 1;
}

.chat-history-item .delete-chat:hover {
  color: var(--error);
  background: rgba(232, 165, 165, 0.2);
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border-light);
}

.model-selector {
  margin-bottom: 12px;
}

.model-selector label {
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.model-selector select {
  width: 100%;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.875rem;
  color: var(--text-primary);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.model-selector select:hover {
  border-color: var(--accent);
}

.model-selector select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.settings-btn {
  width: 100%;
  padding: 10px 16px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.875rem;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all var(--transition-fast);
}

.settings-btn:hover {
  background: var(--surface);
  border-color: var(--accent);
  color: var(--text-primary);
}

/* Main Chat Area */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-header {
  height: var(--header-height);
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
}

.mobile-menu-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius-sm);
}

.mobile-menu-btn:hover {
  background: var(--bg-secondary);
}

.chat-title {
  flex: 1;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.icon-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.icon-btn:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

/* Messages Area */
.messages-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
}

.messages {
  max-width: 800px;
  margin: 0 auto;
  padding: 24px;
}

/* Welcome Screen */
.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 40px 24px;
  text-align: center;
  animation: fadeIn var(--transition-slow);
}

.welcome-screen.hidden {
  display: none;
}

.welcome-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  margin-bottom: 12px;
}

.welcome-logo {
  width: clamp(120px, 22vw, 170px);
  height: auto;
  filter: drop-shadow(0 14px 24px rgba(0, 0, 0, 0.14));
  animation: float 3s ease-in-out infinite;
}

.welcome-copy {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.welcome-screen h2 {
  font-size: 1.75rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.welcome-screen p {
  color: var(--text-secondary);
  margin-bottom: 32px;
}

.api-key-card {
  width: min(100%, 560px);
  margin-bottom: 24px;
  padding: 20px;
  background:
    linear-gradient(135deg, rgba(184, 165, 227, 0.16), rgba(255, 255, 255, 0.78)),
    var(--surface);
  border: 1px solid rgba(184, 165, 227, 0.28);
  border-radius: 22px;
  box-shadow: var(--shadow-md);
  text-align: left;
  backdrop-filter: blur(12px);
}

.api-key-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.api-key-card-header h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.api-key-card-header p,
.api-key-note {
  margin-bottom: 0;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.api-key-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 88px;
  padding: 8px 12px;
  border-radius: var(--radius-full);
  background: rgba(232, 165, 165, 0.18);
  color: #a45151;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.api-key-status.saved {
  background: rgba(168, 213, 186, 0.22);
  color: #3c7f57;
}

.api-key-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.api-key-form input,
.setting-group input[type="password"] {
  width: 100%;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--border);
  border-radius: 14px;
  font-family: var(--font-mono);
  font-size: 0.9rem;
  color: var(--text-primary);
  transition: all var(--transition-fast);
}

.api-key-form input:focus,
.setting-group input[type="password"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.api-key-actions {
  display: flex;
  gap: 10px;
}

.quick-prompts {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  max-width: 500px;
  width: 100%;
}

.quick-prompt {
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 0.875rem;
  color: var(--text-secondary);
  cursor: pointer;
  text-align: left;
  transition: all var(--transition-fast);
}

.quick-prompt:hover {
  background: var(--surface-hover);
  border-color: var(--accent);
  color: var(--text-primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

/* Message Bubbles */
.message {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
  animation: slideIn var(--transition-normal);
}

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

.message-avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  flex-shrink: 0;
  border: 1px solid rgba(0, 0, 0, 0.05);
}

.message.user .message-avatar {
  background: var(--user-bubble);
  color: var(--user-bubble-text);
}

.message.assistant .message-avatar {
  background: var(--accent-light);
  color: var(--accent);
}

.message-content {
  max-width: 75%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.message.user .message-content {
  align-items: flex-end;
}

.message-bubble {
  padding: 14px 18px;
  border-radius: var(--radius-lg);
  line-height: 1.6;
  word-wrap: break-word;
}

.message.user .message-bubble {
  background: var(--user-bubble);
  color: var(--user-bubble-text);
  border-bottom-right-radius: var(--radius-sm);
}

.message.assistant .message-bubble {
  background: var(--ai-bubble);
  color: var(--ai-bubble-text);
  border-bottom-left-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
}

.message-bubble p {
  margin-bottom: 12px;
}

.message-bubble p:last-child {
  margin-bottom: 0;
}

.message-bubble code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: rgba(0,0,0,0.06);
  padding: 2px 6px;
  border-radius: 4px;
}

[data-theme="dark"] .message-bubble code {
  background: rgba(255,255,255,0.1);
}

.message-bubble pre {
  background: #1e1e1e;
  color: #d4d4d4;
  padding: 16px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: 12px 0;
  font-size: 0.875rem;
}

.message-bubble pre code {
  background: none;
  padding: 0;
  color: inherit;
}

.message-bubble ul, .message-bubble ol {
  margin: 12px 0;
  padding-left: 24px;
}

.message-bubble li {
  margin-bottom: 6px;
}

.message-bubble blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 16px;
  margin: 12px 0;
  color: var(--text-secondary);
}

.message-actions {
  display: flex;
  gap: 8px;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.message:hover .message-actions {
  opacity: 1;
}

.message-action-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all var(--transition-fast);
}

.message-action-btn:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.message-time {
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* Typing Indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 8px 0;
}

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

.typing-indicator span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
  animation-delay: 0.4s;
}

/* Input Area */
.input-area {
  padding: 16px 24px 24px;
  background: var(--bg-primary);
  border-top: 1px solid var(--border-light);
}

.input-container {
  max-width: 800px;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: flex-end;
  padding: 12px 16px;
  transition: all var(--transition-fast);
  box-shadow: var(--shadow-sm);
}

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

.input-container textarea {
  flex: 1;
  background: none;
  border: none;
  font-family: inherit;
  font-size: 1rem;
  color: var(--text-primary);
  resize: none;
  line-height: 1.5;
  max-height: 200px;
  overflow-y: auto;
}

.input-container textarea:focus {
  outline: none;
}

.input-container textarea::placeholder {
  color: var(--text-muted);
}

.input-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: 12px;
}

.char-count {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.send-btn {
  background: var(--accent);
  border: none;
  color: white;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.send-btn:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: scale(1.05);
}

.send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

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

.input-hint kbd {
  background: var(--bg-secondary);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: inherit;
  font-size: 0.7rem;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-normal);
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 480px;
  max-height: 90vh;
  overflow: hidden;
  transform: scale(0.9) translateY(20px);
  transition: transform var(--transition-normal);
  box-shadow: var(--shadow-lg);
}

.modal-overlay.active .modal {
  transform: scale(1) translateY(0);
}

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

.modal-header h2 {
  font-size: 1.25rem;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  line-height: 1;
  transition: color var(--transition-fast);
}

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

.modal-body {
  padding: 24px;
  overflow-y: auto;
  max-height: 60vh;
}

.setting-group {
  margin-bottom: 20px;
}

.setting-group:last-child {
  margin-bottom: 0;
}

.setting-group label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.setting-group input[type="text"],
.setting-group input[type="password"],
.setting-group input[type="number"],
.setting-group textarea,
.setting-group select {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--text-primary);
  transition: all var(--transition-fast);
}

.setting-group input:focus,
.setting-group textarea:focus,
.setting-group select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.setting-group input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.checkbox-label {
  display: flex !important;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.setting-hint {
  margin-top: 8px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

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

.btn-primary, .btn-secondary {
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-primary {
  background: var(--accent);
  border: none;
  color: white;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.btn-secondary:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 1001;
}

.toast {
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 14px 20px;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 12px;
  animation: slideInRight var(--transition-normal);
  max-width: 360px;
}

.toast.success {
  border-left: 4px solid var(--success);
}

.toast.error {
  border-left: 4px solid var(--error);
}

.toast.warning {
  border-left: 4px solid var(--warning);
}

.toast-message {
  flex: 1;
  font-size: 0.9rem;
  color: var(--text-primary);
}

.toast-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  font-size: 1.2rem;
  line-height: 1;
}

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(100%);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

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

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

/* Scrollbar Styling */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* Mobile Responsive */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 100;
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .mobile-menu-btn {
    display: block;
  }

  .quick-prompts {
    grid-template-columns: 1fr;
  }

  .api-key-card-header,
  .api-key-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .logo-mark {
    width: 44px;
    height: 44px;
  }

  .message-content {
    max-width: 85%;
  }

  .input-area {
    padding: 12px 16px 16px;
  }

  .messages {
    padding: 16px;
  }
}
