/* ===========================
   Havor Chat - Styles
   =========================== */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #818cf8;
  --bg-dark: #ffffff;
  --bg-card: #f8f9fa;
  --bg-card-hover: #e9ecef;
  --bg-sidebar: #f3f4f6;
  --text-primary: #1a1a2e;
  --text-secondary: #495057;
  --text-muted: #6c757d;
  --border: #dee2e6;
  --success: #10b981;
  --error: #ef4444;
  --warning: #f59e0b;
  --gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #d946ef 100%);
  --message-user: #6366f1;
  --message-assistant: var(--bg-card);
  --thinking-bg: #fef3c7;
}

[data-theme='dark'] {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #818cf8;
  --bg-dark: #0f0f23;
  --bg-card: #1a1a2e;
  --bg-card-hover: #252542;
  --bg-sidebar: #151528;
  --text-primary: #ffffff;
  --text-secondary: #a0a0b8;
  --text-muted: #6b6b80;
  --border: #2a2a40;
  --message-user: #4f46e5;
  --message-assistant: #1a1a2e;
  --thinking-bg: #422006;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg-dark);
  color: var(--text-primary);
  line-height: 1.6;
  height: 100vh;
  overflow: hidden;
}

/* ==================== Layout ==================== */

.chat-app {
  display: flex;
  height: 100vh;
}

/* ==================== Sidebar ==================== */

.sidebar {
  width: 280px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid var(--border);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 20px;
  font-weight: 700;
  text-decoration: none;
  color: var(--text-primary);
  margin-bottom: 15px;
}

.logo-icon {
  font-size: 24px;
}

.logo-dot {
  color: var(--primary);
}

.btn-new-chat {
  width: 100%;
  justify-content: center;
}

.sidebar-search {
  padding: 10px 20px;
}

.sidebar-search input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 14px;
}

.sidebar-search input:focus {
  outline: none;
  border-color: var(--primary);
}

.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
}

.chat-item {
  display: flex;
  align-items: center;
  padding: 12px 14px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s;
  margin-bottom: 4px;
}

.chat-item:hover {
  background: var(--bg-card-hover);
}

.chat-item.active {
  background: var(--primary);
  color: white;
}

.chat-item-icon {
  margin-right: 10px;
  font-size: 16px;
}

.chat-item-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.chat-item-delete {
  opacity: 0;
  background: none;
  border: none;
  color: var(--error);
  cursor: pointer;
  padding: 4px;
  font-size: 14px;
}

.chat-item:hover .chat-item-delete {
  opacity: 1;
}

.sidebar-footer {
  padding: 15px 20px;
  border-top: 1px solid var(--border);
}

.user-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.user-credits {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  background: var(--bg-card);
  border-radius: 16px;
  font-size: 13px;
  font-weight: 500;
}

.user-email {
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100px;
}

.sidebar-actions {
  display: flex;
  gap: 10px;
  justify-content: space-between;
  align-items: center;
}

.sidebar-toggle {
  display: none;
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 100;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 18px;
  cursor: pointer;
}

/* ==================== Main Area ==================== */

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* Welcome Screen */
.welcome-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}

.welcome-content {
  text-align: center;
  max-width: 500px;
}

.welcome-icon {
  font-size: 64px;
  margin-bottom: 20px;
}

.welcome-title {
  font-size: 36px;
  font-weight: 700;
  margin-bottom: 16px;
  background: var(--gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.welcome-subtitle {
  font-size: 16px;
  color: var(--text-secondary);
  margin-bottom: 30px;
}

.welcome-features {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-bottom: 30px;
  flex-wrap: wrap;
}

.feature {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--bg-card);
  border-radius: 20px;
  font-size: 14px;
}

.feature-icon {
  font-size: 18px;
}

/* Auth Required Screen */
.auth-required {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}

.auth-content {
  text-align: center;
}

.auth-icon {
  font-size: 64px;
  margin-bottom: 20px;
}

.auth-content h2 {
  font-size: 28px;
  margin-bottom: 10px;
}

.auth-content p {
  color: var(--text-secondary);
  margin-bottom: 30px;
}

/* Chat View */
.chat-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-dark);
  gap: 15px;
  flex-wrap: wrap;
}

/* Chat Stats */
.chat-stats {
  display: flex;
  gap: 15px;
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--bg-card);
  border-radius: 20px;
  font-size: 13px;
}

.stat-icon {
  font-size: 14px;
}

.stat-value {
  font-weight: 600;
  color: var(--primary-light);
}

.stat-label {
  color: var(--text-muted);
  font-size: 11px;
}

.chat-title-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-title {
  font-size: 18px;
  font-weight: 600;
}

.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  opacity: 0.6;
  transition: opacity 0.2s;
}

.btn-icon:hover {
  opacity: 1;
}

/* Messages Container */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.messages {
  max-width: 800px;
  margin: 0 auto;
}

.message {
  display: flex;
  margin-bottom: 20px;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message-user {
  justify-content: flex-end;
}

.message-assistant {
  justify-content: flex-start;
}

.message-bubble {
  max-width: 80%;
  padding: 14px 18px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.6;
}

.message-user .message-bubble {
  background: var(--message-user);
  color: white;
  border-bottom-right-radius: 4px;
}

.message-assistant .message-bubble {
  background: var(--message-assistant);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

/* Message content styling */
.message-content {
  word-break: break-word;
}

.message-content p {
  margin-bottom: 10px;
}

.message-content p:last-child {
  margin-bottom: 0;
}

.message-content pre {
  background: rgba(0, 0, 0, 0.1);
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 10px 0;
}

.message-content code {
  font-family: 'Fira Code', 'Consolas', monospace;
  font-size: 13px;
}

.message-content ul,
.message-content ol {
  margin-left: 20px;
  margin-bottom: 10px;
}

.message-content a {
  color: var(--primary-light);
}

/* Thinking block */
.thinking-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--warning);
  cursor: pointer;
  margin-bottom: 10px;
  padding: 6px 10px;
  background: var(--thinking-bg);
  border-radius: 6px;
  border: none;
  width: fit-content;
}

.thinking-toggle:hover {
  opacity: 0.8;
}

/* Message images */
.message-images {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.message-images img {
  max-width: 200px;
  max-height: 200px;
  border-radius: 8px;
  cursor: pointer;
}

/* Message meta */
.message-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 8px;
  display: flex;
  gap: 10px;
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 0;
}

.typing-dot {
  width: 8px;
  height: 8px;
  background: var(--primary);
  border-radius: 50%;
  animation: typing 1.4s infinite;
}

.typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing {
  0%,
  100% {
    opacity: 0.3;
    transform: scale(0.8);
  }
  50% {
    opacity: 1;
    transform: scale(1);
  }
}

/* ==================== Input Area ==================== */

.input-area {
  padding: 16px 24px 20px;
  background: var(--bg-dark);
}

.input-form {
  max-width: 800px;
  margin: 0 auto;
}

.input-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 8px 8px 8px 16px;
  transition: border-color 0.2s, box-shadow 0.2s;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

.input-wrapper:focus-within {
  border-color: var(--primary);
  box-shadow: 0 2px 12px rgba(102, 126, 234, 0.15);
}

.input-options {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.option-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  cursor: pointer;
  font-size: 18px;
  opacity: 0.6;
  transition: opacity 0.2s, background 0.2s;
  border-radius: 50%;
}

.option-btn:hover {
  opacity: 1;
  background: var(--bg-card-hover);
}

.option-checkbox {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 6px 10px;
  border-radius: 18px;
  transition: background 0.2s, color 0.2s;
  white-space: nowrap;
}

.option-checkbox:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

.option-checkbox input {
  margin: 0;
  width: 14px;
  height: 14px;
  accent-color: var(--primary);
}

.input-wrapper textarea {
  flex: 1;
  border: none;
  background: none;
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.5;
  resize: none;
  max-height: 150px;
  min-height: 24px;
  font-family: inherit;
  padding: 6px 0;
}

.input-wrapper textarea:focus {
  outline: none;
}

.input-wrapper textarea::placeholder {
  color: var(--text-muted);
}

.btn-send {
  width: 40px;
  height: 40px;
  min-width: 40px;
  padding: 0;
  font-size: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.15s, opacity 0.2s;
}

.btn-send:hover:not(:disabled) {
  transform: scale(1.05);
}

.btn-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.input-hint {
  display: flex;
  justify-content: center;
  gap: 16px;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 10px;
  padding: 0 4px;
}

/* Image Preview */
.image-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
  max-width: 800px;
  margin-left: auto;
  margin-right: auto;
}

.preview-item {
  position: relative;
}

.preview-item img {
  width: 80px;
  height: 80px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.preview-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  background: var(--error);
  color: white;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ==================== Thinking Modal ==================== */

.thinking-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;
}

.thinking-content {
  background: var(--bg-card);
  border-radius: 16px;
  width: 90%;
  max-width: 600px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
}

.thinking-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 20px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}

.thinking-body {
  padding: 20px;
  overflow-y: auto;
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.7;
  white-space: pre-wrap;
}

.btn-close {
  background: none;
  border: none;
  font-size: 24px;
  color: var(--text-muted);
  cursor: pointer;
}

/* ==================== Buttons ==================== */

.btn {
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  border: none;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
}

.btn-outline {
  background: transparent;
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-outline:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.btn-small {
  padding: 6px 12px;
  font-size: 12px;
}

.btn-large {
  padding: 14px 28px;
  font-size: 16px;
}

.theme-toggle {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-primary);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 16px;
  transition: all 0.2s;
}

.theme-toggle:hover {
  background: var(--bg-card-hover);
  border-color: var(--primary);
}

/* ==================== Empty State ==================== */

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.empty-state-icon {
  font-size: 48px;
  margin-bottom: 15px;
}

/* ==================== Loading ==================== */

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ==================== Responsive ==================== */

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 50;
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-toggle {
    display: block;
  }

  .message-bubble {
    max-width: 90%;
  }

  .welcome-features {
    flex-direction: column;
    align-items: center;
  }
}

/* ==================== Scrollbar ==================== */

::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ==================== Error State ==================== */

.error-message {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid var(--error);
  color: var(--error);
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 15px;
  font-size: 14px;
}

/* ==================== Toast Notifications ==================== */

.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 1001;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 20px;
  margin-top: 10px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  animation: slideIn 0.3s ease;
}

.toast.error {
  border-color: var(--error);
}

.toast.success {
  border-color: var(--success);
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}
