:root {
  --bg-primary: #131314;
  --bg-secondary: #1e1f20;
  --bg-tertiary: #282a2c;
  --text-primary: #e3e3e3;
  --text-secondary: #999ea4;
  --border-color: #383a3e;
  --accent-color: #7dacff;
  --accent-hover: #a8c7fa;
  --user-bubble-bg: #2b2c2f;
  --ai-bubble-bg: transparent;
  --sidebar-width: 260px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body.light-theme {
  --bg-primary: #ffffff;
  --bg-secondary: #f0f4f9;
  --bg-tertiary: #e1e7ee;
  --text-primary: #1f1f1f;
  --text-secondary: #575b61;
  --border-color: #e0e3e7;
  --accent-color: #0b57d0;
  --accent-hover: #1b6ef3;
  --user-bubble-bg: #e9eef6;
  --ai-bubble-bg: transparent;
}

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

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

.app-container {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background-color: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  transition: transform 0.25s ease;
  z-index: 100;
}

.sidebar-header {
  padding: 16px;
}

.new-chat-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  border-radius: var(--radius-lg);
  font-weight: 500;
}

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

.history-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-secondary);
  padding: 8px 12px;
}

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

.history-item {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  text-decoration: none;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item:hover, .history-item.active {
  background-color: var(--bg-tertiary);
}

.history-item span {
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.history-delete-btn {
  opacity: 0;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 2px;
}

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

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.sidebar-action-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  color: var(--text-primary);
}

/* Chat Workspace */
.chat-workspace {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
  background-color: var(--bg-primary);
}

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

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

.model-selector-container {
  display: flex;
  align-items: center;
  gap: 8px;
}

.model-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.model-select {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 0.9rem;
  font-weight: 500;
  outline: none;
  cursor: pointer;
}

.status-indicator {
  font-size: 0.78rem;
  color: #34d399;
  background: rgba(52, 211, 153, 0.1);
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid rgba(52, 211, 153, 0.2);
}

/* Messages Container */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
}

/* Welcome Screen */
.welcome-screen {
  text-align: center;
  margin: auto;
  max-width: 600px;
}

.welcome-icon {
  font-size: 3rem;
  margin-bottom: 16px;
}

.welcome-screen h1 {
  font-size: 1.8rem;
  margin-bottom: 8px;
}

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

.suggestion-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
}

.suggestion-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  text-align: left;
  cursor: pointer;
  color: inherit;
  transition: all 0.2s ease;
}

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

.suggestion-card strong {
  display: block;
  font-size: 0.9rem;
  margin-bottom: 4px;
}

.suggestion-card span {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* Message Bubbles */
.message-row {
  display: flex;
  gap: 16px;
  animation: fadeIn 0.2s ease;
}

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

.message-row.user {
  justify-content: flex-end;
}

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
  background: var(--bg-tertiary);
}

.message-bubble {
  max-width: 80%;
  padding: 12px 18px;
  border-radius: var(--radius-lg);
  line-height: 1.6;
  font-size: 0.95rem;
  word-break: break-word;
}

.message-row.user .message-bubble {
  background: var(--user-bubble-bg);
  color: var(--text-primary);
  border-bottom-right-radius: 4px;
}

.message-row.assistant .message-bubble {
  background: var(--ai-bubble-bg);
  color: var(--text-primary);
  max-width: 100%;
  padding-left: 0;
}

/* Markdown styling inside messages */
.message-bubble p {
  margin-bottom: 0.8em;
}
.message-bubble p:last-child {
  margin-bottom: 0;
}
.message-bubble h1, .message-bubble h2, .message-bubble h3 {
  margin: 1em 0 0.5em;
}
.message-bubble ul, .message-bubble ol {
  margin-left: 1.5em;
  margin-bottom: 0.8em;
}
.message-bubble code {
  font-family: monospace;
  background: var(--bg-secondary);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.9em;
}
.message-bubble pre {
  margin: 0.8em 0;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  background: #18191b !important;
  border: 1px solid var(--border-color);
  position: relative;
}
.message-bubble pre code {
  background: transparent;
  padding: 12px;
  display: block;
}

/* Copy button on code blocks */
.code-copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: #fff;
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: opacity 0.2s;
}
.code-copy-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* Chat Input Area */
.chat-input-area {
  padding: 12px 20px 24px;
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
}

.input-box-wrapper {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 24px;
  display: flex;
  align-items: flex-end;
  padding: 8px 12px 8px 20px;
  transition: border-color 0.2s ease;
}

.input-box-wrapper:focus-within {
  border-color: var(--accent-color);
}

.input-box-wrapper textarea {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 1rem;
  resize: none;
  max-height: 200px;
  min-height: 24px;
  line-height: 1.5;
}

.send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent-color);
  color: #fff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: opacity 0.2s;
  flex-shrink: 0;
  margin-left: 8px;
}

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

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

/* Buttons */
.btn {
  border: none;
  outline: none;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}

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

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
}
.btn-ghost:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.btn-icon {
  background: transparent;
  color: var(--text-primary);
  padding: 6px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-icon:hover {
  background: var(--bg-tertiary);
}

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

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

.modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  width: 90%;
  max-width: 520px;
  overflow: hidden;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
}

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

.modal-header h2 {
  font-size: 1.15rem;
}

.modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

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

.form-group small {
  font-size: 0.78rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

.form-control {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 10px 12px;
  font-family: inherit;
  font-size: 0.9rem;
  outline: none;
}
.form-control:focus {
  border-color: var(--accent-color);
}

.slider-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
}

.range-slider {
  width: 100%;
  cursor: pointer;
}

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

  .sidebar.open {
    transform: translateX(0);
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.5);
  }

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