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

:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #818cf8;
  --bg: #ffffff;
  --bg-secondary: #f8fafc;
  --bg-tertiary: #f1f5f9;
  --text: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --border-light: #f1f5f9;
  --success: #10b981;
  --error: #ef4444;
  --warning: #f59e0b;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08);
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

.page {
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

.auth-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  box-shadow: var(--shadow-lg);
}

.auth-header {
  text-align: center;
  margin-bottom: 2rem;
}

.auth-logo {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 1rem;
}

.auth-logo i {
  font-size: 2rem;
  color: var(--primary);
}

.auth-logo span {
  font-size: 1.5rem;
  font-weight: 700;
}

.auth-header h1 {
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
}

.auth-header p {
  color: var(--text-muted);
}

.auth-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 1.5rem;
}

.tab-btn {
  flex: 1;
  padding: 10px;
  border: none;
  background: var(--bg-secondary);
  border-radius: 8px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.tab-btn.active {
  background: var(--primary);
  color: white;
}

.auth-form {
  display: none;
}

.auth-form.active {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

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

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

.form-group input, .form-group select, .form-group textarea {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  transition: all 0.2s;
}

.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.auth-btn {
  padding: 14px;
  background: var(--text);
  color: white;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  margin-top: 0.5rem;
}

.auth-btn:hover {
  background: #1e293b;
}

.auth-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: var(--error);
  padding: 12px;
  border-radius: 8px;
  font-size: 0.85rem;
  margin-top: 1rem;
  display: none;
}

.auth-error.show {
  display: block;
}

#main-page {
  display: flex;
  height: 100vh;
}

.sidebar {
  width: 280px;
  background: var(--bg);
  border-right: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

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

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.1rem;
}

.logo i {
  color: var(--primary);
  font-size: 1.25rem;
}

.sidebar-section {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-light);
}

.sidebar-section h3 {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
  letter-spacing: 0.05em;
}

.chat-list {
  max-height: 200px;
  overflow-y: auto;
  margin-bottom: 0.75rem;
}

.chat-item {
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.2s;
}

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

.chat-item.active {
  background: var(--bg-tertiary);
}

.new-chat-btn, .sidebar-btn {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s;
}

.new-chat-btn:hover, .sidebar-btn:hover {
  background: var(--bg-secondary);
  border-color: var(--primary);
  color: var(--primary);
}

.model-select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.85rem;
  background: var(--bg);
  cursor: pointer;
}

.workspace-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--bg-secondary);
  border-radius: 8px;
  margin-top: 0.5rem;
}

.workspace-info span {
  font-size: 0.85rem;
  font-weight: 500;
}

.icon-btn {
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.icon-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.sidebar-footer {
  margin-top: auto;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border-light);
}

.logout-btn {
  width: 100%;
  padding: 10px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  transition: color 0.2s;
}

.logout-btn:hover {
  color: var(--error);
}

.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.main-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-title h2 {
  font-size: 1.1rem;
  font-weight: 600;
}

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

.chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
}

.chat-messages {
  max-width: 800px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.message {
  display: flex;
  gap: 12px;
}

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

.message-avatar {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.message.assistant .message-avatar {
  background: linear-gradient(135deg, var(--primary-light), var(--primary));
  color: white;
}

.message.user .message-avatar {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
}

.message-content {
  max-width: 70%;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 0.95rem;
  line-height: 1.6;
}

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

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

.message-content pre {
  background: var(--text);
  color: #e2e8f0;
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  font-family: 'Ubuntu Mono', monospace;
  font-size: 0.85rem;
  margin: 12px 0;
}

.message-content code {
  font-family: 'Ubuntu Mono', monospace;
  background: var(--bg-tertiary);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.85rem;
}

.message.user .message-content code {
  background: rgba(255,255,255,0.2);
}

.input-container {
  padding: 1rem 1.5rem 1.5rem;
  border-top: 1px solid var(--border-light);
}

.input-wrapper {
  max-width: 800px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 12px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
}

.input-wrapper:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.input-actions {
  display: flex;
  gap: 4px;
}

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

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

#message-input {
  flex: 1;
  border: none;
  resize: none;
  font-size: 0.95rem;
  line-height: 1.5;
  max-height: 200px;
  font-family: inherit;
}

#message-input:focus {
  outline: none;
}

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

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

.send-btn:disabled {
  background: var(--text-muted);
  cursor: not-allowed;
}

.attached-files {
  max-width: 800px;
  margin: 0.5rem auto 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.attached-file {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--bg-secondary);
  border-radius: 6px;
  font-size: 0.85rem;
}

.attached-file button {
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px;
}

.attached-file button:hover {
  color: var(--error);
}

.files-panel, .github-panel {
  width: 300px;
  background: var(--bg);
  border-left: 1px solid var(--border-light);
  display: flex;
  flex-direction: column;
}

.panel-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.panel-header h3 {
  font-size: 1rem;
  font-weight: 600;
}

.files-tree {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
}

.file-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.2s;
}

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

.file-item i {
  color: var(--text-muted);
}

.file-item.folder > i {
  color: var(--warning);
}

.panel-actions {
  padding: 1rem;
  border-top: 1px solid var(--border-light);
  display: flex;
  gap: 8px;
}

.panel-btn {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.2s;
}

.panel-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.panel-btn.full {
  width: 100%;
  margin-bottom: 8px;
}

.panel-select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  margin-bottom: 12px;
}

.github-content {
  padding: 1rem;
}

.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content {
  background: var(--bg);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 500px;
  max-height: 90vh;
  overflow: hidden;
}

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

.modal-header h3 {
  font-size: 1.1rem;
  font-weight: 600;
}

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

.file-editor {
  position: fixed;
  top: 0;
  right: 0;
  width: 50%;
  height: 100vh;
  background: var(--bg);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 100;
}

.editor-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.editor-header span {
  font-weight: 600;
}

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

.editor-textarea {
  flex: 1;
  border: none;
  padding: 1rem;
  font-family: 'Ubuntu Mono', monospace;
  font-size: 0.9rem;
  line-height: 1.6;
  resize: none;
}

.editor-textarea:focus {
  outline: none;
}

.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 8px 12px;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typing 1.4s infinite;
}

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

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

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: -280px;
    top: 0;
    bottom: 0;
    z-index: 50;
    transition: left 0.3s;
  }
  
  .sidebar.open {
    left: 0;
  }
  
  .files-panel, .github-panel, .file-editor {
    width: 100%;
  }
}
