/* CSS Variables - Light Theme (Default) */
:root {
  --sidebar-width: 280px;
  --sidebar-collapsed-width: 0px;
  --header-height: 60px;
  --input-height: 100px;
  --primary-color: #10a37f;
  --primary-hover: #0d8c6d;
  --primary-light: rgba(16, 163, 127, 0.1);
  --bg-primary: #ffffff;
  --bg-secondary: #f7f7f8;
  --bg-tertiary: #f0f0f1;
  --bg-sidebar: #202123;
  --bg-sidebar-hover: #2d2d30;
  --bg-sidebar-active: #353540;
  --text-primary: #343541;
  --text-secondary: #6e6e80;
  --text-tertiary: #8e8ea0;
  --text-light: #ececf1;
  --border-color: #d9d9e3;
  --border-light: #e5e5e5;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --transition-fast: 0.15s ease;
  --transition-normal: 0.2s ease;
  --transition-slow: 0.3s ease;
}

/* Dark Theme */
[data-theme="dark"] {
  --bg-primary: #343541;
  --bg-secondary: #444654;
  --bg-tertiary: #3e3f4b;
  --text-primary: #ececf1;
  --text-secondary: #8e8ea0;
  --text-tertiary: #6e6e80;
  --border-color: #4a4b53;
  --border-light: #4a4b53;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
}

/* Reset & Base */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-primary);
  overflow: hidden;
  transition: background-color var(--transition-normal), color var(--transition-normal);
}

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

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  color: var(--text-light);
  display: flex;
  flex-direction: column;
  transition: width var(--transition-slow), transform var(--transition-slow);
  flex-shrink: 0;
  position: relative;
  z-index: 100;
}

.sidebar.collapsed {
  width: 0;
  overflow: hidden;
}

.sidebar-header {
  padding: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  gap: 8px;
}

.new-chat-btn {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-md);
  color: var(--text-light);
  font-size: 14px;
  cursor: pointer;
  transition: var(--transition-normal);
}

.new-chat-btn:hover {
  background: var(--bg-sidebar-hover);
  border-color: rgba(255, 255, 255, 0.3);
  transform: translateY(-1px);
}

.new-chat-btn:active {
  transform: translateY(0);
}

.sidebar-toggle {
  padding: 8px;
  background: transparent;
  border: none;
  color: var(--text-light);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: var(--transition-normal);
}

.sidebar-toggle:hover {
  background: var(--bg-sidebar-hover);
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.search-container {
  position: relative;
  margin-bottom: 8px;
}

.search-input {
  width: 100%;
  padding: 10px 12px 10px 36px;
  background: var(--bg-sidebar-hover);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-md);
  color: var(--text-light);
  font-size: 14px;
  outline: none;
  transition: var(--transition-normal);
}

.search-input:focus {
  border-color: var(--primary-color);
  background: var(--bg-sidebar-active);
}

.search-input::placeholder {
  color: rgba(255, 255, 255, 0.4);
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: rgba(255, 255, 255, 0.4);
  pointer-events: none;
}

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

.chat-history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition-normal);
  font-size: 14px;
  color: var(--text-light);
  animation: slideIn 0.3s ease;
}

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

.chat-history-item:hover {
  background: var(--bg-sidebar-hover);
}

.chat-history-item.active {
  background: var(--bg-sidebar-active);
  border-left: 3px solid var(--primary-color);
}

.chat-history-item svg {
  flex-shrink: 0;
  opacity: 0.7;
}

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

.chat-history-item .delete-btn {
  opacity: 0;
  padding: 6px;
  background: transparent;
  border: none;
  color: var(--text-light);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: var(--transition-normal);
}

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

.chat-history-item .delete-btn:hover {
  background: rgba(239, 68, 68, 0.2);
  color: #ef4444;
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

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

.model-selector label {
  display: block;
  font-size: 11px;
  color: rgba(255, 255, 255, 0.5);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

.model-select {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-sidebar-hover);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-md);
  color: var(--text-light);
  font-size: 14px;
  cursor: pointer;
  outline: none;
  transition: var(--transition-normal);
}

.model-select:focus {
  border-color: var(--primary-color);
}

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

.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px;
  margin-bottom: 12px;
  background: var(--bg-sidebar-hover);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition-normal);
}

.theme-toggle:hover {
  background: var(--bg-sidebar-active);
}

.theme-toggle svg {
  color: var(--text-light);
  opacity: 0.7;
  transition: var(--transition-normal);
}

.theme-toggle:hover svg {
  opacity: 1;
}

[data-theme="dark"] .sun-icon,
[data-theme="light"] .moon-icon {
  display: none;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition-normal);
}

.user-info:hover {
  background: var(--bg-sidebar-hover);
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary-color);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  color: white;
}

/* Main Content */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
  position: relative;
  transition: background-color var(--transition-normal);
}

/* Mobile Header */
.mobile-header {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-light);
  height: var(--header-height);
  transition: background-color var(--transition-normal), border-color var(--transition-normal);
}

.mobile-menu-btn,
.mobile-new-chat {
  padding: 8px;
  background: transparent;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: var(--transition-normal);
}

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

.mobile-title {
  font-weight: 600;
  font-size: 16px;
  color: var(--text-primary);
}

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

/* Welcome Screen */
.welcome-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
  animation: fadeIn 0.5s ease;
}

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

.welcome-content {
  max-width: 800px;
  width: 100%;
  text-align: center;
}

.welcome-title {
  font-size: 48px;
  font-weight: 700;
  margin-bottom: 12px;
  background: linear-gradient(135deg, var(--primary-color), #2dd4bf);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: gradientShift 3s ease infinite;
}

@keyframes gradientShift {
  0%, 100% { filter: hue-rotate(0deg); }
  50% { filter: hue-rotate(10deg); }
}

.welcome-subtitle {
  font-size: 18px;
  color: var(--text-secondary);
  margin-bottom: 48px;
}

.welcome-examples {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  max-width: 700px;
  margin: 0 auto;
}

.example-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 20px;
  cursor: pointer;
  transition: var(--transition-normal);
  text-align: left;
}

.example-card:hover {
  background: var(--bg-primary);
  border-color: var(--primary-color);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.example-icon {
  font-size: 24px;
  margin-bottom: 12px;
}

.example-text {
  font-size: 14px;
  color: var(--text-primary);
  line-height: 1.5;
}

/* Messages Container */
.messages-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0;
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
}

.message {
  display: flex;
  gap: 16px;
  padding: 24px 0;
  border-bottom: 1px solid var(--border-light);
  animation: messageSlideIn 0.3s ease;
  transition: background-color var(--transition-normal);
}

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

.message:last-child {
  border-bottom: none;
}

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

.message-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  flex-shrink: 0;
  transition: transform var(--transition-normal);
}

.message:hover .message-avatar {
  transform: scale(1.05);
}

.message.user .message-avatar {
  background: var(--primary-color);
  color: white;
}

.message.assistant .message-avatar {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border-light);
}

.message-content {
  flex: 1;
  min-width: 0;
}

.message-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.message-author {
  font-weight: 600;
  font-size: 14px;
  color: var(--text-primary);
}

.message-time {
  font-size: 12px;
  color: var(--text-tertiary);
}

.message-status {
  font-size: 12px;
  color: var(--primary-color);
  opacity: 0;
  transition: opacity var(--transition-normal);
}

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

.message-text {
  font-size: 15px;
  line-height: 1.6;
  color: var(--text-primary);
  white-space: pre-wrap;
  word-wrap: break-word;
}

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

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

.message-text code {
  background: var(--bg-tertiary);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
  font-size: 13px;
  color: var(--text-primary);
}

.message-text pre {
  background: #1e1e1e;
  color: #d4d4d4;
  padding: 16px;
  border-radius: var(--radius-md);
  overflow-x: auto;
  margin: 12px 0;
  position: relative;
}

.message-text pre code {
  background: transparent;
  padding: 0;
  color: inherit;
  font-size: 13px;
  line-height: 1.5;
}

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

.message-text li {
  margin: 4px 0;
}

.message-text strong {
  font-weight: 600;
}

.message-text em {
  font-style: italic;
}

.message-text a {
  color: var(--primary-color);
  text-decoration: none;
}

.message-text a:hover {
  text-decoration: underline;
}

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

/* Code block styling */
.code-block {
  position: relative;
  margin: 12px 0;
  border-radius: var(--radius-md);
  overflow: hidden;
}

.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: #2d2d30;
  border-bottom: 1px solid #3e3e42;
  font-size: 12px;
  color: #858585;
}

.code-language {
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.copy-code-btn {
  padding: 4px 12px;
  background: transparent;
  border: 1px solid #4a4b53;
  color: #858585;
  cursor: pointer;
  font-size: 12px;
  border-radius: var(--radius-sm);
  transition: var(--transition-normal);
}

.copy-code-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border-color: #6e6e80;
}

.code-block pre {
  margin: 0;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
}

/* Streaming cursor */
.streaming-cursor {
  display: inline-block;
  width: 8px;
  height: 18px;
  background: var(--primary-color);
  margin-left: 4px;
  animation: blink 1s infinite;
  vertical-align: middle;
  border-radius: 1px;
}

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

/* Typing indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 0;
}

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

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

@keyframes typingBounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

/* Skeleton loading */
.skeleton {
  background: linear-gradient(90deg, var(--bg-secondary) 25%, var(--bg-tertiary) 50%, var(--bg-secondary) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-text {
  height: 16px;
  margin-bottom: 8px;
}

.skeleton-text:last-child {
  width: 60%;
}

/* Input Container */
.input-container {
  padding: 16px 20px 20px;
  background: var(--bg-primary);
  border-top: 1px solid var(--border-light);
  transition: background-color var(--transition-normal), border-color var(--transition-normal);
}

.input-wrapper {
  max-width: 900px;
  margin: 0 auto;
  position: relative;
  display: flex;
  align-items: flex-end;
  gap: 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: 12px 16px;
  transition: var(--transition-normal);
}

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

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

.message-input::placeholder {
  color: var(--text-tertiary);
}

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

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

.send-btn:active:not(:disabled) {
  transform: scale(0.95);
}

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

.input-footer {
  max-width: 900px;
  margin: 8px auto 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--text-tertiary);
}

.disclaimer {
  text-align: center;
  flex: 1;
}

.char-count {
  font-variant-numeric: tabular-nums;
  transition: color var(--transition-normal);
}

.char-count.warning {
  color: #ef4444;
}

/* Loading Overlay */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

[data-theme="dark"] .loading-overlay {
  background: rgba(52, 53, 65, 0.95);
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border-light);
  border-top-color: var(--primary-color);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Error Toast */
.error-toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #ef4444;
  color: white;
  padding: 12px 20px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow-lg);
  z-index: 1001;
  max-width: 90%;
  width: auto;
  opacity: 0;
  transition: transform 0.3s ease, opacity 0.3s ease;
}

.error-toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.error-message {
  font-size: 14px;
}

.error-close {
  background: transparent;
  border: none;
  color: white;
  font-size: 20px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  transition: opacity var(--transition-normal);
}

.error-close:hover {
  opacity: 0.7;
}

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

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

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

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

/* Responsive Design */
@media (max-width: 768px) {
  :root {
    --sidebar-width: 100%;
  }

  .sidebar {
    position: fixed;
    left: -100%;
    top: 0;
    bottom: 0;
    z-index: 100;
    width: 80%;
    max-width: 300px;
    box-shadow: var(--shadow-lg);
  }

  .sidebar.open {
    left: 0;
  }

  .sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
    display: none;
    opacity: 0;
    transition: opacity var(--transition-normal);
  }

  .sidebar-overlay.open {
    display: block;
    opacity: 1;
  }

  .mobile-header {
    display: flex;
  }

  .chat-container {
    padding: 16px;
  }

  .welcome-title {
    font-size: 32px;
  }

  .welcome-subtitle {
    font-size: 16px;
  }

  .welcome-examples {
    grid-template-columns: 1fr;
  }

  .message {
    padding: 16px 0;
    gap: 12px;
  }

  .message-avatar {
    width: 32px;
    height: 32px;
    font-size: 12px;
  }

  .message-text {
    font-size: 14px;
  }

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

@media (max-width: 480px) {
  .welcome-title {
    font-size: 28px;
  }

  .example-card {
    padding: 16px;
  }

  .input-footer {
    flex-direction: column;
    gap: 8px;
    text-align: center;
  }
}

/* Print styles */
@media print {
  .sidebar,
  .input-container,
  .mobile-header {
    display: none;
  }

  .main-content {
    margin: 0;
  }

  .message {
    break-inside: avoid;
  }
}

/* Focus visible for accessibility */
*:focus-visible {
  outline: 2px solid var(--primary-color);
  outline-offset: 2px;
}

/* Selection styling */
::selection {
  background: var(--primary-light);
  color: var(--primary-color);
}