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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
  background: #f0f2f5;
  color: #1a1a2e;
  height: 100vh;
  overflow: hidden;
}

/* Auth pages */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.auth-card {
  background: white;
  border-radius: 16px;
  padding: 40px;
  width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

.auth-header {
  text-align: center;
  margin-bottom: 24px;
}

.auth-header h1 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 4px;
}

.auth-header p {
  color: #666;
  font-size: 14px;
}

.auth-form .form-group {
  margin-bottom: 16px;
}

.auth-form label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: #333;
}

.auth-form input {
  width: 100%;
  padding: 10px 14px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  font-size: 15px;
  transition: border-color 0.2s;
}

.auth-form input:focus {
  outline: none;
  border-color: #667eea;
}

.btn-primary {
  width: 100%;
  padding: 12px;
  background: #667eea;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-primary:hover {
  background: #5a6fd6;
}

.auth-link {
  text-align: center;
  margin-top: 20px;
  font-size: 14px;
  color: #666;
}

.auth-link a {
  color: #667eea;
  text-decoration: none;
  font-weight: 600;
}

.flash {
  background: #fff3cd;
  color: #856404;
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 14px;
}

/* App layout */
.app-layout {
  display: flex;
  height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 280px;
  background: #1a1a2e;
  color: white;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-header h2 {
  font-size: 18px;
  margin-bottom: 12px;
}

.new-chat-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.model-select {
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(255,255,255,0.1);
  color: white;
  font-size: 13px;
  cursor: pointer;
}

.model-select option {
  background: #1a1a2e;
  color: white;
}

.btn-new-chat {
  padding: 8px 16px;
  background: #667eea;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-new-chat:hover {
  background: #5a6fd6;
}

.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.chat-item {
  display: block;
  padding: 10px 12px;
  border-radius: 8px;
  text-decoration: none;
  color: rgba(255,255,255,0.8);
  margin-bottom: 2px;
  transition: background 0.2s;
}

.chat-item:hover {
  background: rgba(255,255,255,0.1);
}

.chat-item.active {
  background: rgba(102, 126, 234, 0.3);
}

.chat-item-title {
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item-meta {
  font-size: 11px;
  color: rgba(255,255,255,0.4);
  margin-top: 2px;
}

.empty-state {
  padding: 20px;
  text-align: center;
  color: rgba(255,255,255,0.4);
  font-size: 13px;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,0.1);
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13px;
}

.sidebar-footer-links {
  display: flex;
  gap: 12px;
}

.sidebar-footer-links a {
  color: rgba(255,255,255,0.6);
  text-decoration: none;
  font-size: 12px;
  transition: color 0.2s;
}

.sidebar-footer-links a:hover {
  color: white;
}

.sidebar-footer-user {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.btn-logout {
  padding: 6px 12px;
  background: rgba(255,255,255,0.1);
  color: white;
  text-decoration: none;
  border-radius: 6px;
  font-size: 12px;
  transition: background 0.2s;
}

.btn-logout:hover {
  background: rgba(255,255,255,0.2);
}

/* Main content */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: white;
}

.chat-header {
  padding: 14px 20px;
  border-bottom: 1px solid #e0e0e0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fafafa;
}

.chat-title-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-title-display {
  font-weight: 600;
  font-size: 16px;
}

.btn-rename {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  color: #999;
  padding: 2px 4px;
}

.btn-rename:hover {
  color: #667eea;
}

.rename-form {
  display: flex;
  gap: 6px;
  align-items: center;
}

.rename-form input {
  padding: 6px 10px;
  border: 2px solid #667eea;
  border-radius: 6px;
  font-size: 14px;
  outline: none;
}

.rename-form button {
  padding: 6px 12px;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
}

.rename-form button[type="submit"] {
  background: #667eea;
  color: white;
}

.rename-form button[type="button"] {
  background: #e0e0e0;
}

.btn-delete {
  padding: 6px 14px;
  background: #e74c3c;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-delete:hover {
  background: #c0392b;
}

.hidden {
  display: none !important;
}

/* Messages */
.message-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.message {
  display: flex;
  gap: 12px;
  max-width: 800px;
}

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

.message-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}

.message.user .message-avatar {
  background: #667eea;
  color: white;
}

.message.assistant .message-avatar {
  background: #1a1a2e;
  color: white;
}

.message-content {
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 15px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.message.user .message-content {
  background: #667eea;
  color: white;
  border-bottom-right-radius: 4px;
}

.message.assistant .message-content {
  background: #f0f2f5;
  color: #1a1a2e;
  border-bottom-left-radius: 4px;
}

.empty-chat {
  text-align: center;
  color: #999;
  margin-top: 80px;
}

.empty-chat p {
  font-size: 16px;
}

/* Thinking block */
.thinking-block {
  font-style: italic;
  color: #888;
  font-size: 14px;
  white-space: pre-wrap;
  word-wrap: break-word;
  padding: 8px 12px;
  margin-bottom: 8px;
  background: #f7f7f8;
  border-radius: 8px;
  border-left: 3px solid #667eea;
  display: none;
}

.thinking-block:not(:empty) {
  display: block;
}

.content-block {
  white-space: pre-wrap;
  word-wrap: break-word;
}

.message.streaming .thinking-block:empty ~ .content-block:empty::after {
  content: '▊';
  animation: blink 1s step-end infinite;
  color: #667eea;
}

@keyframes blink {
  50% { opacity: 0; }
}

/* Code blocks */
.code-block {
  margin: 8px 0;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #e0e0e0;
  background: #1a1a2e;
}

.code-header {
  padding: 6px 12px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #aaa;
  background: #22223a;
  border-bottom: 1px solid #333;
}

.code-block pre {
  margin: 0;
  padding: 14px 16px;
  overflow-x: auto;
}

.code-block code {
  font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  font-size: 13px;
  line-height: 1.6;
  color: #e8e8e8;
  white-space: pre;
}

.content-block {
  white-space: pre-wrap;
  word-wrap: break-word;
}

.content-block .code-block {
  white-space: normal;
}

/* Input area */
.input-area {
  padding: 14px 20px;
  border-top: 1px solid #e0e0e0;
  display: flex;
  gap: 10px;
  align-items: flex-end;
  background: #fafafa;
}

.input-area textarea {
  flex: 1;
  padding: 10px 14px;
  border: 2px solid #e0e0e0;
  border-radius: 10px;
  font-size: 15px;
  resize: none;
  outline: none;
  transition: border-color 0.2s;
  max-height: 200px;
  font-family: inherit;
}

.input-area textarea:focus {
  border-color: #667eea;
}

/* Thinking toggle */
.thinking-toggle {
  position: relative;
  width: 36px;
  height: 20px;
  flex-shrink: 0;
  cursor: pointer;
  margin-bottom: 4px;
}

.thinking-toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: #ccc;
  border-radius: 20px;
  transition: background 0.2s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  left: 2px;
  bottom: 2px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s;
}

.thinking-toggle input:checked + .toggle-slider {
  background: #667eea;
}

.thinking-toggle input:checked + .toggle-slider::before {
  transform: translateX(16px);
}

.btn-image {
  padding: 8px 10px;
  background: #e8e8e8;
  color: #555;
  border: none;
  border-radius: 8px;
  font-size: 18px;
  cursor: pointer;
  transition: background 0.2s;
  height: fit-content;
  line-height: 1;
}

.btn-image:hover {
  background: #d0d0d0;
}

.image-preview {
  position: relative;
  display: inline-flex;
  align-items: center;
  padding: 4px;
  background: #f0f0f0;
  border-radius: 8px;
  border: 1px solid #ddd;
}

.image-preview img {
  max-height: 48px;
  max-width: 80px;
  border-radius: 4px;
  object-fit: cover;
}

.btn-remove-image {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #e74c3c;
  color: white;
  border: 2px solid white;
  font-size: 12px;
  line-height: 14px;
  cursor: pointer;
  text-align: center;
  padding: 0;
}

.user-image {
  max-width: 240px;
  max-height: 240px;
  border-radius: 8px;
  display: block;
  margin-bottom: 6px;
  border: 1px solid rgba(255,255,255,0.3);
}

.message.user .message-content {
  background: #667eea;
  color: white;
  border-bottom-right-radius: 4px;
}

.btn-send {
  padding: 10px 24px;
  background: #667eea;
  color: white;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  height: fit-content;
}

.btn-send:hover {
  background: #5a6fd6;
}

.btn-send:disabled {
  background: #999;
  cursor: not-allowed;
}

.empty-state-main {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #999;
}

.empty-state-main h2 {
  font-size: 28px;
  margin-bottom: 8px;
  color: #333;
}

.empty-state-main p {
  font-size: 16px;
}

.error-msg {
  color: #e74c3c !important;
  margin-top: 16px;
  font-size: 14px !important;
  text-align: center;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
}

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

::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: #999;
}
