/* ========== RESET & BASE ========== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  /* Colors - ChatGPT Style */
  --bg-primary: #212121;
  --bg-secondary: #2f2f2f;
  --bg-elevated: #3a3a3a;
  --bg-hover: #424242;

  --text-primary: #ececec;
  --text-secondary: #b4b4b4;
  --text-muted: #8e8e8e;

  --accent: #19c37d;
  --accent-hover: #1a9f6a;

  --border: #4e4e4e;
  --border-subtle: #3a3a3a;

  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;

  /* Typography */
  --font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;

  /* Transitions */
  --transition: 200ms cubic-bezier(0.4, 0, 0.2, 1);

  /* Radii */
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.5);
}

body {
  font-family: var(--font-family);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  height: 100vh;
}

/* ========== LAYOUT ========== */
.app-container {
  display: flex;
  height: 100vh;
  width: 100%;
}

/* ========== SIDEBAR ========== */
.sidebar {
  width: 260px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  padding: var(--space-md);
  transition: transform var(--transition);
  position: relative;
  z-index: 100;
}

.sidebar-header {
  margin-bottom: var(--space-md);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-collapse {
  margin-left: auto;
}

/* New Chat Button */
.new-chat-btn {
  width: 100%;
  padding: var(--space-md);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: var(--space-md);
  transition: all var(--transition);
  margin-bottom: var(--space-md);
}

.new-chat-btn:hover {
  background: var(--bg-hover);
}

.new-chat-btn svg {
  flex-shrink: 0;
}

/* Search Box */
.search-box {
  position: relative;
  margin-bottom: var(--space-md);
}

.search-box svg {
  position: absolute;
  left: var(--space-md);
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.search-box input {
  width: 100%;
  padding: var(--space-sm) var(--space-md) var(--space-sm) 2.75rem;
  background: var(--bg-primary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
  transition: all var(--transition);
}

.search-box input:focus {
  border-color: var(--border);
  background: var(--bg-elevated);
}

.search-box input::placeholder {
  color: var(--text-muted);
}

/* Chat History */
.chat-history {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  margin: 0 calc(var(--space-md) * -1);
  padding: 0 var(--space-md);
}

.chat-history::-webkit-scrollbar {
  width: 4px;
}

.chat-history::-webkit-scrollbar-track {
  background: transparent;
}

.chat-history::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 10px;
}

.history-section h3 {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: var(--space-sm);
  padding: 0 var(--space-sm);
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.history-item {
  padding: var(--space-md);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
  color: var(--text-secondary);
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-sm);
}

.history-item:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.history-item.active {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.history-item-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-item-actions {
  display: none;
  align-items: center;
  gap: var(--space-xs);
}

.history-item:hover .history-item-actions {
  display: flex;
}

/* Sidebar Footer */
.sidebar-footer {
  margin-top: auto;
  padding-top: var(--space-md);
  border-top: 1px solid var(--border-subtle);
}

.sidebar-footer-btn {
  width: 100%;
  padding: var(--space-md);
  background: transparent;
  border: none;
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: var(--space-md);
  transition: all var(--transition);
}

.sidebar-footer-btn:hover {
  background: var(--bg-hover);
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.user-avatar svg {
  color: white;
}

.sidebar-footer-btn .chevron {
  margin-left: auto;
  color: var(--text-muted);
}

/* ========== MAIN CONTENT ========== */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
  position: relative;
}

/* Top Header */
.top-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) var(--space-xl);
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-primary);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-left,
.header-right {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.mobile-menu-btn {
  display: none;
}

.model-selector {
  padding: var(--space-sm) var(--space-md);
  background: transparent;
  border: none;
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  transition: all var(--transition);
}

.model-selector:hover {
  background: var(--bg-hover);
}

/* ========== MESSAGES ========== */
.messages-wrapper {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

.messages-wrapper::-webkit-scrollbar {
  width: 8px;
}

.messages-wrapper::-webkit-scrollbar-track {
  background: transparent;
}

.messages-wrapper::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 10px;
}

.messages-container {
  max-width: 48rem;
  margin: 0 auto;
  padding: var(--space-xl);
}

/* Welcome Screen */
.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  text-align: center;
}

.welcome-screen h1 {
  font-size: 2rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--space-xl);
}

/* Message */
.message {
  display: flex;
  gap: var(--space-lg);
  margin-bottom: var(--space-xl);
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 18px;
  background: var(--bg-elevated);
}

.message.assistant .message-avatar {
  background: var(--accent);
  color: white;
}

.message-content {
  flex: 1;
  color: var(--text-primary);
  line-height: 1.7;
  font-size: 15px;
}

.message-content p {
  margin-bottom: var(--space-md);
}

.message-content p:last-child {
  margin-bottom: 0;
}

.message-content code {
  background: var(--bg-elevated);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-family: "Monaco", "Menlo", monospace;
  font-size: 0.9em;
  color: var(--accent);
}

.message-content pre {
  background: var(--bg-secondary);
  padding: var(--space-md);
  border-radius: var(--radius-md);
  overflow-x: auto;
  margin: var(--space-md) 0;
  position: relative;
}

.message-content pre code {
  background: transparent;
  padding: 0;
  color: var(--text-primary);
  font-size: 13px;
}

/* Message Actions */
.message-actions {
  display: flex;
  gap: var(--space-sm);
  margin-top: var(--space-md);
  opacity: 0;
  transition: opacity var(--transition);
}

.message:hover .message-actions {
  opacity: 1;
}

/* Copy Code Button */
.copy-code-btn {
  position: absolute;
  top: var(--space-sm);
  right: var(--space-sm);
  padding: var(--space-xs) var(--space-md);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  transition: all var(--transition);
}

.copy-code-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* Typing Indicator */
.typing-indicator {
  display: flex;
  gap: var(--space-lg);
  margin-bottom: var(--space-xl);
}

.typing-dots {
  display: flex;
  gap: 6px;
  padding: var(--space-md) 0;
}

.typing-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typing 1.4s infinite;
}

.typing-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.5;
  }

  30% {
    transform: translateY(-10px);
    opacity: 1;
  }
}

/* ========== INPUT AREA ========== */
.input-wrapper {
  padding: var(--space-xl);
  background: var(--bg-primary);
  border-top: 1px solid var(--border-subtle);
}

.input-container {
  max-width: 48rem;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: var(--space-md);
  padding: var(--space-md);
  background: var(--bg-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  transition: all var(--transition);
}

.input-container:focus-within {
  border-color: var(--border);
  box-shadow: 0 0 0 1px var(--border);
}

.input-actions-left,
.input-actions-right {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

#messageInput {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 15px;
  resize: none;
  max-height: 200px;
  line-height: 1.5;
  font-family: var(--font-family);
}

#messageInput::placeholder {
  color: var(--text-muted);
}

.send-btn {
  background: var(--bg-elevated);
  padding: var(--space-sm);
}

.send-btn:not(:disabled) {
  background: white;
  color: var(--bg-primary);
}

.send-btn:not(:disabled):hover {
  background: #e8e8e8;
}

.input-footer {
  max-width: 48rem;
  margin: var(--space-md) auto 0;
  text-align: center;
}

.input-footer p {
  font-size: 12px;
  color: var(--text-muted);
}

/* ========== BUTTONS ========== */
.icon-btn {
  padding: var(--space-sm);
  background: transparent;
  border: none;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  transition: all var(--transition);
  font-size: 13px;
}

.icon-btn:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.icon-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ========== MODALS ========== */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal.active {
  display: flex;
}

.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  width: 90%;
  max-width: 600px;
  max-height: 90vh;
  overflow: hidden;
  animation: modalIn 0.2s ease;
}

.modal-content.small {
  max-width: 320px;
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: scale(0.95);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-lg);
  border-bottom: 1px solid var(--border-subtle);
}

.modal-header h2 {
  font-size: 18px;
  font-weight: 600;
}

.modal-body {
  padding: var(--space-lg);
  max-height: 60vh;
  overflow-y: auto;
}

.modal-footer {
  padding: var(--space-lg);
  border-top: 1px solid var(--border-subtle);
}

/* Model Options */
.model-option {
  padding: var(--space-lg);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-md);
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
}

.model-option:hover {
  border-color: var(--border);
  background: var(--bg-hover);
}

.model-option.active {
  border-color: var(--accent);
  background: rgba(25, 195, 125, 0.1);
}

.model-info h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: var(--space-xs);
}

.model-info p {
  font-size: 13px;
  color: var(--text-secondary);
}

.model-badge {
  padding: var(--space-xs) var(--space-md);
  background: var(--accent);
  color: white;
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Settings */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) 0;
  font-size: 14px;
}

.slider-container {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.slider-container input[type="range"] {
  width: 120px;
}

.slider-container span {
  min-width: 30px;
  color: var(--accent);
  font-weight: 600;
}

.toggle {
  width: 42px;
  height: 24px;
  position: relative;
  appearance: none;
  background: var(--bg-elevated);
  border-radius: 12px;
  cursor: pointer;
  transition: all var(--transition);
}

.toggle:checked {
  background: var(--accent);
}

.toggle::before {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background: white;
  border-radius: 50%;
  transition: transform var(--transition);
}

.toggle:checked::before {
  transform: translateX(18px);
}

/* Menu */
.menu-list {
  display: flex;
  flex-direction: column;
}

.menu-item {
  padding: var(--space-md);
  background: transparent;
  border: none;
  border-radius: var(--radius-md);
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: var(--space-md);
  text-decoration: none;
  font-size: 14px;
  transition: all var(--transition);
}

.menu-item:hover {
  background: var(--bg-hover);
}

.menu-divider {
  height: 1px;
  background: var(--border-subtle);
  margin: var(--space-sm) 0;
}

/* ========== TOASTS ========== */
.toast-container {
  position: fixed;
  bottom: var(--space-xl);
  right: var(--space-xl);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.toast {
  padding: var(--space-md) var(--space-lg);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: var(--space-md);
  min-width: 300px;
  animation: toastIn 0.3s ease;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateX(100%);
  }

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.toast.success {
  border-left: 3px solid var(--accent);
}

.toast.error {
  border-left: 3px solid #ef4444;
}

/* ========== RESPONSIVE ========== */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: -100%;
    top: 0;
    height: 100vh;
    z-index: 200;
    box-shadow: var(--shadow-lg);
  }

  .sidebar.active {
    left: 0;
  }

  .mobile-menu-btn {
    display: flex;
  }

  .messages-container,
  .input-container {
    max-width: 100%;
  }

  .input-wrapper {
    padding: var(--space-md);
  }

  .message {
    gap: var(--space-md);
  }

  .top-header {
    padding: var(--space-md);
  }
}
