:root {
  --bg-dark: #0b0d14;
  --bg-sidebar: #111422;
  --bg-card: #181b2e;
  --bg-card-hover: #22263d;
  --bg-input: #151828;
  --border-color: rgba(255, 255, 255, 0.08);
  --border-color-glow: rgba(99, 102, 241, 0.4);
  
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-glow: rgba(99, 102, 241, 0.25);
  --secondary: #8b5cf6;
  --accent: #38bdf8;
  
  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  --text-dim: #6b7280;

  --user-msg-bg: #272848;
  --assistant-msg-bg: #16192b;
  
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4);
  --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.3);
  
  --font-main: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-code: 'Fira Code', monospace;
}

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

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

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

/* Sidebar Styles */
.sidebar {
  width: 300px;
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease, margin-left 0.3s ease;
  z-index: 100;
  flex-shrink: 0;
}

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

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 1.1rem;
  box-shadow: var(--shadow-glow);
}

.brand-title {
  font-weight: 700;
  font-size: 1.25rem;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, #ffffff, #a5b4fc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.badge-tag {
  font-size: 0.7rem;
  font-weight: 600;
  background: rgba(99, 102, 241, 0.15);
  color: var(--primary);
  border: 1px solid rgba(99, 102, 241, 0.3);
  padding: 2px 8px;
  border-radius: var(--radius-full);
}

.sidebar-actions {
  padding: 16px 20px;
}

.new-chat-btn {
  width: 100%;
  padding: 12px 16px;
  font-weight: 600;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.search-box {
  padding: 0 20px 12px 20px;
  position: relative;
}

.search-icon {
  position: absolute;
  left: 32px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
  font-size: 0.85rem;
}

.search-box input {
  width: 100%;
  padding: 8px 12px 8px 36px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.2s ease;
}

.search-box input:focus {
  border-color: var(--primary);
}

.history-section {
  flex: 1;
  overflow-y: auto;
  padding: 0 12px;
}

.history-label {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-dim);
  letter-spacing: 1px;
  padding: 12px 12px 6px 12px;
}

.conversation-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.conv-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.2s ease;
  text-decoration: none;
  font-size: 0.9rem;
  position: relative;
}

.conv-item:hover {
  background: var(--bg-card-hover);
  color: var(--text-main);
}

.conv-item.active {
  background: rgba(99, 102, 241, 0.15);
  color: #ffffff;
  border: 1px solid rgba(99, 102, 241, 0.3);
}

.conv-item-left {
  display: flex;
  align-items: center;
  gap: 10px;
  overflow: hidden;
  flex: 1;
}

.conv-item-left i {
  font-size: 0.85rem;
  color: var(--text-dim);
}

.conv-item.active .conv-item-left i {
  color: var(--primary);
}

.conv-title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-actions {
  display: none;
  align-items: center;
  gap: 4px;
}

.conv-item:hover .conv-actions {
  display: flex;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.footer-item-btn {
  width: 100%;
  padding: 10px 12px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.88rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.footer-item-btn:hover {
  background: var(--bg-card-hover);
  color: var(--text-main);
}

.footer-btn-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.glow-brain {
  color: var(--secondary);
  filter: drop-shadow(0 0 6px var(--secondary));
}

.badge {
  background: var(--primary);
  color: white;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius-full);
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: #ef4444;
  box-shadow: 0 0 8px #ef4444;
}

.status-dot.online {
  background-color: #10b981;
  box-shadow: 0 0 8px #10b981;
}

/* Chat Main Area */
.chat-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  background-color: var(--bg-dark);
  position: relative;
  overflow: hidden;
}

.chat-header {
  height: 64px;
  padding: 0 24px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(17, 20, 34, 0.7);
  backdrop-filter: blur(12px);
  z-index: 10;
}

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

.chat-title-container {
  display: flex;
  flex-direction: column;
}

.chat-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-main);
}

.chat-subtitle {
  font-size: 0.75rem;
  color: var(--text-dim);
}

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

.model-select-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 6px 12px;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  color: var(--text-muted);
}

.custom-select {
  background: transparent;
  border: none;
  color: var(--text-main);
  font-weight: 600;
  font-size: 0.85rem;
  outline: none;
  cursor: pointer;
  font-family: inherit;
}

.custom-select option {
  background: var(--bg-sidebar);
  color: var(--text-main);
}

.memory-pill-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: var(--radius-full);
  font-size: 0.85rem;
}

.pill-badge {
  background: rgba(255, 255, 255, 0.15);
  padding: 2px 6px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
}

/* Chat Messages Container */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  scroll-behavior: smooth;
}

/* Welcome Screen */
.welcome-screen {
  max-width: 800px;
  margin: 40px auto;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
}

.welcome-icon {
  width: 72px;
  height: 72px;
  border-radius: 24px;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.2rem;
  color: white;
  margin: 0 auto 16px auto;
  box-shadow: var(--shadow-glow);
}

.welcome-hero h2 {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.welcome-hero p {
  color: var(--text-muted);
  font-size: 1.05rem;
}

.features-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 16px;
  width: 100%;
}

.feature-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  text-align: left;
  cursor: pointer;
  transition: all 0.25 ease;
}

.feature-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-color-glow);
  transform: translateY(-2px);
}

.feature-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  color: var(--primary);
}

.feature-card-header h3 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-main);
}

.feature-card p {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.4;
}

/* Message Item */
.message-row {
  display: flex;
  gap: 16px;
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
  animation: fadeIn 0.3s ease;
}

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

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

.avatar {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}

.message-row.user .avatar {
  background: #3b82f6;
  color: white;
}

.message-row.assistant .avatar {
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: white;
  box-shadow: 0 0 12px rgba(99, 102, 241, 0.4);
}

.message-bubble {
  background: var(--assistant-msg-bg);
  border: 1px solid var(--border-color);
  padding: 14px 18px;
  border-radius: var(--radius-lg);
  color: var(--text-main);
  font-size: 0.95rem;
  line-height: 1.6;
  max-width: 80%;
  overflow-wrap: break-word;
  position: relative;
}

.message-row.user .message-bubble {
  background: var(--user-msg-bg);
  border-color: rgba(99, 102, 241, 0.3);
  border-top-right-radius: 4px;
}

.message-row.assistant .message-bubble {
  border-top-left-radius: 4px;
}

/* Markdown Content Styling */
.message-bubble p {
  margin-bottom: 12px;
}

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

.message-bubble code {
  font-family: var(--font-code);
  font-size: 0.88rem;
  background: rgba(0, 0, 0, 0.3);
  padding: 2px 6px;
  border-radius: 4px;
  color: #a5b4fc;
}

.message-bubble pre {
  margin: 12px 0;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: #0f111d !important;
  border: 1px solid var(--border-color);
}

.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #181b2b;
  padding: 6px 14px;
  font-size: 0.75rem;
  color: var(--text-dim);
  font-family: var(--font-code);
  border-bottom: 1px solid var(--border-color);
}

.copy-code-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  gap: 4px;
}

.copy-code-btn:hover {
  color: var(--text-main);
}

.message-bubble pre code {
  background: transparent;
  padding: 14px;
  display: block;
  overflow-x: auto;
}

/* Message Actions */
.message-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  font-size: 0.75rem;
  color: var(--text-dim);
}

.action-icon-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
}

.action-icon-btn:hover {
  color: var(--text-main);
  background: var(--bg-card-hover);
}

/* Typing Indicator Pulsing Cursor */
.typing-cursor {
  display: inline-block;
  width: 8px;
  height: 16px;
  background: var(--primary);
  margin-left: 4px;
  vertical-align: middle;
  animation: blink 0.8s infinite;
}

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

/* Scroll Bottom Button */
.scroll-bottom-btn {
  position: absolute;
  bottom: 90px;
  right: 32px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  display: none;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  z-index: 5;
  transition: all 0.2s ease;
}

.scroll-bottom-btn:hover {
  background: var(--primary);
  transform: translateY(-2px);
}

/* Chat Input Area */
.chat-input-area {
  padding: 16px 24px 20px 24px;
  background: var(--bg-dark);
}

.input-form {
  max-width: 860px;
  margin: 0 auto;
}

.textarea-container {
  position: relative;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 12px 16px;
  display: flex;
  align-items: flex-end;
  gap: 12px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.textarea-container:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 16px var(--primary-glow);
}

.textarea-container textarea {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-main);
  font-family: inherit;
  font-size: 0.95rem;
  resize: none;
  max-height: 180px;
  line-height: 1.5;
}

.send-btn {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  background: var(--primary);
  border: none;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

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

.send-btn:disabled {
  background: var(--bg-card);
  color: var(--text-dim);
  cursor: not-allowed;
  transform: none;
}

.input-disclaimer {
  text-align: center;
  margin-top: 10px;
  font-size: 0.72rem;
  color: var(--text-dim);
}

/* Buttons and UI Elements */
.btn {
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  border: none;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: white;
  box-shadow: 0 4px 14px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
  opacity: 0.92;
  transform: translateY(-1px);
}

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

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

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  width: 34px;
  height: 34px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

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

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}

.modal-overlay.active {
  display: flex;
}

.modal-card {
  background: var(--bg-sidebar);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.modal-large {
  max-width: 700px;
}

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

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

.modal-title h2 {
  font-size: 1.15rem;
  font-weight: 700;
}

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

.modal-description {
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.5;
}

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

/* Form inputs in Modals */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
}

.form-group small {
  font-size: 0.75rem;
  color: var(--text-dim);
}

.input-password-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.input-password-wrapper input {
  width: 100%;
  padding: 10px 40px 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-size: 0.9rem;
  outline: none;
}

.input-password-wrapper .icon-btn {
  position: absolute;
  right: 4px;
}

.width-full {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-main);
}

/* Add Memory Box */
.add-memory-box {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;

  display: flex;
  flex-direction: column;
  gap: 10px;
}

.add-memory-box h3 {
  font-size: 0.85rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.add-memory-row {
  display: flex;
  gap: 10px;
}

.add-memory-row select {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  padding: 8px 12px;
  font-size: 0.85rem;
}

.add-memory-row input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  padding: 8px 12px;
  font-size: 0.88rem;
  outline: none;
}

.memory-list-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.memory-list-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-dim);
  letter-spacing: 0.5px;
}

.memory-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 260px;
  overflow-y: auto;
}

.memory-item {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.memory-cat-pill {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background: rgba(99, 102, 241, 0.2);
  color: var(--primary);
  border: 1px solid rgba(99, 102, 241, 0.3);
}

.memory-fact {
  flex: 1;
  font-size: 0.88rem;
  color: var(--text-main);
}

.status-banner {
  padding: 10px 14px;
  border-radius: var(--radius-md);
  background: rgba(99, 102, 241, 0.1);
  border: 1px solid rgba(99, 102, 241, 0.3);
  font-size: 0.85rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Responsive Styles */
@media (max-width: 768px) {
  .sidebar {
    position: absolute;
    left: -300px;
    height: 100%;
  }

  .sidebar.open {
    transform: translateX(300px);
  }

  .chat-header {
    padding: 0 16px;
  }

  .message-bubble {
    max-width: 90%;
  }

  .add-memory-row {
    flex-direction: column;
  }
}
