/* Apple-Inspired Multi-Model Chat UI */
/* SF Pro Font - System font fallback */

:root {
  /* ChatGPT-Inspired Low-Saturation Colors */
  --primary: #10a37f;
  --primary-hover: #0d8a6a;
  --primary-light: #e7f5f1;

  --gray-50: #f7f7f8;
  --gray-100: #ececf1;
  --gray-200: #d9d9e3;
  --gray-300: #c5c5d2;
  --gray-400: #acacbe;
  --gray-500: #8e8ea0;
  --gray-600: #565869;
  --gray-700: #40414f;
  --gray-800: #343541;
  --gray-900: #202123;

  --white: #FFFFFF;
  --text-primary: #2d333a;
  --text-secondary: #6e6e80;
  --border-light: #e5e5e5;
  --border-medium: #c5c5d2;

  /* Spacing */
  --spacing-xs: 4px;
  --spacing-sm: 8px;
  --spacing-md: 16px;
  --spacing-lg: 24px;
  --spacing-xl: 32px;

  /* Border radius */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 2px 4px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 4px 6px rgba(0, 0, 0, 0.07);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--gray-50);
  color: var(--text-primary);
  line-height: 1.6;
  overflow: hidden;
}

/* ===== LOGIN PAGE ===== */
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, var(--gray-100) 0%, var(--gray-200) 100%);
}

.login-card {
  background: var(--white);
  padding: var(--spacing-xl);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  width: 90%;
  max-width: 400px;
  text-align: center;
}

.login-card h1 {
  font-size: 32px;
  font-weight: 600;
  margin-bottom: var(--spacing-md);
  color: var(--text-primary);
}

.login-card p {
  color: var(--text-secondary);
  margin-bottom: var(--spacing-lg);
  font-size: 15px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-md);
}

.input-group {
  text-align: left;
}

.input-group label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: var(--spacing-xs);
}

.input-group input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  font-size: 16px;
  transition: all 0.2s;
  outline: none;
}

.input-group input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(16, 163, 127, 0.1);
}

.btn-primary {
  background: var(--primary);
  color: var(--white);
  border: none;
  padding: 14px;
  border-radius: var(--radius-md);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

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

.btn-primary:active {
  transform: scale(0.98);
}

.error-message {
  background: #FFE5E5;
  color: #D32F2F;
  padding: var(--spacing-sm) var(--spacing-md);
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-top: var(--spacing-md);
}

/* ===== MAIN CHAT APP ===== */
.app-container {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: 280px;
  background: var(--gray-900);
  border-right: 1px solid var(--gray-800);
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.sidebar-header {
  padding: var(--spacing-md);
  border-bottom: 1px solid var(--gray-800);
}

.sidebar-header h2 {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: var(--spacing-sm);
  color: var(--white);
}

.btn-new-chat {
  width: 100%;
  background: transparent;
  color: var(--white);
  border: 1px solid var(--gray-600);
  padding: 10px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--spacing-sm);
  transition: all 0.2s;
}

.btn-new-chat:hover {
  background: var(--gray-800);
}

.conversations-list {
  flex: 1;
  overflow-y: auto;
  padding: var(--spacing-sm);
}

.conversation-item {
  padding: 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
  margin-bottom: var(--spacing-xs);
}

.conversation-item:hover {
  background: var(--gray-800);
}

.conversation-item.active {
  background: var(--gray-700);
}

.conversation-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.conversation-title {
  font-size: 14px;
  font-weight: 400;
  color: var(--white);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.btn-delete-conversation {
  background: transparent;
  border: none;
  color: var(--gray-500);
  cursor: pointer;
  padding: 4px;
  font-size: 14px;
  opacity: 0;
  transition: all 0.2s;
  flex-shrink: 0;
}

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

.btn-delete-conversation:hover {
  color: #ef4444;
  transform: scale(1.1);
}

.conversation-time {
  font-size: 12px;
  color: var(--gray-400);
}

/* Main Chat Area */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--white);
}

.chat-header {
  background: var(--white);
  border-bottom: 1px solid var(--border-light);
  padding: var(--spacing-md);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.model-selector {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

.model-selector label {
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 500;
}

.model-selector select {
  padding: 8px 12px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  font-size: 14px;
  background: var(--white);
  cursor: pointer;
  outline: none;
  color: var(--text-primary);
}

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

.btn-logout {
  background: transparent;
  border: 1px solid var(--border-light);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-primary);
  transition: all 0.2s;
}

.btn-logout:hover {
  background: var(--gray-100);
}

/* Messages */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: var(--spacing-lg);
  display: flex;
  flex-direction: column;
  gap: var(--spacing-md);
}

.message {
  display: flex;
  gap: var(--spacing-sm);
  max-width: 70%;
  animation: messageSlideIn 0.3s ease-out;
}

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

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

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

.message.assistant .message-avatar {
  background: var(--gray-600);
}

.message-bubble {
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  line-height: 1.6;
  font-size: 15px;
  word-wrap: break-word;
}

.message.user .message-bubble {
  background: var(--gray-100);
  color: var(--text-primary);
  border: 1px solid var(--border-light);
}

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

.message-time {
  font-size: 11px;
  color: var(--text-secondary);
  margin-top: 4px;
  padding-left: 4px;
}

.message.user .message-time {
  color: var(--text-secondary);
}

/* Input Area */
.input-area {
  background: var(--white);
  border-top: 1px solid var(--border-light);
  padding: var(--spacing-md);
}

.input-container {
  display: flex;
  gap: var(--spacing-sm);
  align-items: flex-end;
}

.input-container textarea {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  font-size: 15px;
  font-family: inherit;
  resize: none;
  outline: none;
  max-height: 120px;
  min-height: 44px;
  transition: all 0.2s;
  background: var(--white);
  color: var(--text-primary);
}

.input-container textarea:focus {
  border-color: var(--border-medium);
  box-shadow: 0 0 0 1px var(--border-medium);
}

.btn-send {
  background: var(--primary);
  color: var(--white);
  border: none;
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  height: 44px;
}

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

.btn-send:active {
  transform: scale(0.98);
}

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

/* Loading */
.loading {
  display: flex;
  gap: 6px;
  padding: var(--spacing-sm);
}

.loading-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--gray-500);
  animation: loadingBounce 1.4s infinite ease-in-out both;
}

.loading-dot:nth-child(1) {
  animation-delay: -0.32s;
}

.loading-dot:nth-child(2) {
  animation-delay: -0.16s;
}

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

/* Empty State */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  gap: var(--spacing-md);
}

.empty-state h3 {
  font-size: 24px;
  font-weight: 600;
  color: var(--text-primary);
}

.empty-state p {
  font-size: 15px;
  color: var(--text-secondary);
}

/* Responsive */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: -280px;
    transition: left 0.3s;
    z-index: 100;
  }

  .sidebar.open {
    left: 0;
  }

  .message {
    max-width: 85%;
  }
}

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

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

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

::-webkit-scrollbar-thumb:hover {
  background: var(--gray-400);
}

/* Generated Images in Chat */
.message-bubble img.generated-image {
  max-width: 100%;
  width: auto;
  height: auto;
  max-height: 600px;
  border-radius: var(--radius-md);
  display: block;
  margin: 4px 0;
  box-shadow: var(--shadow-md);
  cursor: pointer;
  transition: transform 0.2s;
}

.message-bubble img.generated-image:hover {
  transform: scale(1.02);
}

.image-actions {
  margin-top: var(--spacing-sm);
  display: flex;
  gap: var(--spacing-sm);
  justify-content: flex-end;
}

.btn-download-inline {
  background: var(--gray-100);
  border: 1px solid var(--border-light);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-primary);
  text-decoration: none;
  display: inline-block;
  transition: all 0.2s;
}

.btn-download-inline:hover {
  background: var(--gray-200);
}

/* Markdown styling in messages */
.markdown-content h1,
.markdown-content h2,
.markdown-content h3 {
  margin-top: 16px;
  margin-bottom: 8px;
  font-weight: 600;
}

.markdown-content h1 {
  font-size: 24px;
}

.markdown-content h2 {
  font-size: 20px;
}

.markdown-content h3 {
  font-size: 18px;
}

.markdown-content p {
  margin-bottom: 12px;
}

.markdown-content ul,
.markdown-content ol {
  margin-left: 24px;
  margin-bottom: 12px;
}

.markdown-content pre {
  background: var(--gray-900);
  border-radius: var(--radius-sm);
  padding: 12px;
  overflow-x: auto;
  margin: 12px 0;
  position: relative;
}

.markdown-content code {
  font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
  font-size: 14px;
}

.markdown-content pre code {
  background: transparent;
  padding: 0;
  color: #e6edf3;
}

.markdown-content :not(pre) > code {
  background: var(--gray-100);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
  color: var(--primary);
}

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

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

.markdown-content a:hover {
  text-decoration: underline;
}

.markdown-content table {
  border-collapse: collapse;
  width: 100%;
  margin: 12px 0;
}

.markdown-content th,
.markdown-content td {
  border: 1px solid var(--border-light);
  padding: 8px 12px;
  text-align: left;
}

.markdown-content th {
  background: var(--gray-50);
  font-weight: 600;
}

/* Copy button for code blocks */
.copy-button {
  position: absolute;
  top: 8px;
  right: 8px;
  background: var(--gray-600);
  color: var(--white);
  border: none;
  padding: 4px 12px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  opacity: 0.7;
}

.copy-button:hover {
  opacity: 1;
  background: var(--gray-500);
}

/* Blinking cursor for streaming */
.cursor-blink {
  animation: blink 1s infinite;
  color: var(--primary);
  font-weight: bold;
}

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