/* ===================================
   CSS Variables & Theme
=================================== */
:root {
  /* Light Theme */
  --bg-primary: #ffffff;
  --bg-secondary: #f8fafc;
  --bg-tertiary: #f1f5f9;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --border-color: #e2e8f0;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-light: #dbeafe;
  --success: #22c55e;
  --error: #ef4444;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  --user-msg-bg: #3b82f6;
  --user-msg-text: #ffffff;
  --bot-msg-bg: #f1f5f9;
  --bot-msg-text: #0f172a;
  --code-bg: #1e293b;
  --code-text: #e2e8f0;
}

[data-theme="dark"] {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --text-primary: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted: #64748b;
  --border-color: #334155;
  --primary: #3b82f6;
  --primary-hover: #60a5fa;
  --primary-light: #1e3a5f;
  --user-msg-bg: linear-gradient(135deg, #3b82f6, #8b5cf6);
  --user-msg-text: #ffffff;
  --bot-msg-bg: #1e293b;
  --bot-msg-text: #f1f5f9;
  --code-bg: #0f172a;
  --code-text: #e2e8f0;
}

/* ===================================
   Base Styles
=================================== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  width: 100%;
  overflow: hidden;
}

body {
  font-family: "Tajawal", sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  transition: background 0.3s ease, color 0.3s ease;
  line-height: 1.6;
}

/* ===================================
   App Container
=================================== */
.app-container {
  display: flex;
  height: 100vh;
  width: 100%;
  position: relative;
}

/* ===================================
   Sidebar
=================================== */
.sidebar {
  width: 280px;
  background: var(--bg-secondary);
  border-left: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  transition: all 0.3s ease;
  z-index: 100;
}

.sidebar-header {
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 18px;
}

.logo-text {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}

.theme-toggle {
  width: 40px;
  height: 40px;
  border: none;
  background: var(--bg-tertiary);
  border-radius: 10px;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: all 0.3s ease;
}

.theme-toggle:hover {
  background: var(--primary);
  color: white;
}

.new-chat-btn {
  margin: 16px;
  padding: 14px 20px;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-family: "Tajawal", sans-serif;
  transition: all 0.3s ease;
}

.new-chat-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(59, 130, 246, 0.3);
}

/* Saved Chats Section */
.saved-chats-section {
  flex: 1;
  padding: 0 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 0;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.chats-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow-y: auto;
  padding-bottom: 10px;
}

.chat-item {
  padding: 12px 14px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.chat-item:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}

.chat-item.active {
  border-color: var(--primary);
  background: var(--primary-light);
}

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

.chat-item-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-item-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  font-size: 11px;
  color: var(--text-muted);
}

.chat-item-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.chat-item:hover .chat-item-actions {
  opacity: 1;
}

.chat-action-btn {
  width: 28px;
  height: 28px;
  border: none;
  background: var(--bg-tertiary);
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  transition: all 0.2s ease;
}

.chat-action-btn:hover {
  background: var(--error);
  color: white;
}

.chat-action-btn.export:hover {
  background: var(--success);
}

.clear-all-btn {
  margin-top: 10px;
  padding: 10px;
  background: transparent;
  border: 1px dashed var(--border-color);
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: "Tajawal", sans-serif;
  transition: all 0.2s ease;
}

.clear-all-btn:hover {
  border-color: var(--error);
  color: var(--error);
  background: rgba(239, 68, 68, 0.1);
}

/* Sidebar Footer */
.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.footer-btn {
  padding: 12px 16px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: "Tajawal", sans-serif;
  text-decoration: none;
  transition: all 0.2s ease;
}

.footer-btn:hover {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
}

.developer-link {
  background: linear-gradient(135deg, #0077b5, #00a0dc);
  border: none;
  color: white;
}

.developer-link:hover {
  background: linear-gradient(135deg, #005885, #0077b5);
  color: white;
  transform: translateY(-1px);
}

/* ===================================
   Mobile Menu Button
=================================== */
.mobile-menu-btn {
  display: none;
  position: fixed;
  top: 16px;
  right: 16px;
  width: 44px;
  height: 44px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  color: var(--text-primary);
  font-size: 18px;
  cursor: pointer;
  z-index: 200;
  align-items: center;
  justify-content: center;
}

/* ===================================
   Chat Main Area
=================================== */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
  min-width: 0;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Welcome Screen */
.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  padding: 20px;
}

.welcome-icon {
  width: 80px;
  height: 80px;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  border-radius: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 36px;
  margin-bottom: 24px;
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-10px);
  }
}

.welcome-screen h1 {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 12px;
}

.welcome-screen p {
  font-size: 16px;
  color: var(--text-secondary);
  max-width: 400px;
  margin-bottom: 32px;
}

.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
}

.quick-btn {
  padding: 12px 20px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  color: var(--text-primary);
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: "Tajawal", sans-serif;
  transition: all 0.2s ease;
}

.quick-btn:hover {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
  transform: translateY(-2px);
}

.quick-btn i {
  color: var(--primary);
}

/* Messages */
.message {
  display: flex;
  gap: 12px;
  max-width: 80%;
  animation: slideIn 0.3s ease;
}

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

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

.message.bot {
  align-self: flex-start;
}

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

.message.user .message-avatar {
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  color: white;
}

.message.bot .message-avatar {
  background: var(--bg-tertiary);
  color: var(--primary);
  border: 1px solid var(--border-color);
}

.message-content {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.message-bubble {
  padding: 12px 16px;
  border-radius: 16px;
  line-height: 1.6;
  word-wrap: break-word;
  font-size: 14px;
}

.message.user .message-bubble {
  background: var(--user-msg-bg);
  color: var(--user-msg-text);
  border-bottom-left-radius: 4px;
}

.message.bot .message-bubble {
  background: var(--bot-msg-bg);
  color: var(--bot-msg-text);
  border: 1px solid var(--border-color);
  border-bottom-right-radius: 4px;
}

/* Code Block in Messages */
.message-code {
  background: var(--code-bg);
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border-color);
}

.message-code pre {
  margin: 0;
  padding: 16px;
  overflow-x: auto;
  color: var(--code-text);
  font-size: 13px;
  line-height: 1.5;
  direction: ltr;
  text-align: left;
}

.message-code code {
  font-family: "Fira Code", "Courier New", monospace;
}

.code-actions {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  background: var(--bg-tertiary);
  border-top: 1px solid var(--border-color);
}

.code-btn {
  padding: 6px 12px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: "Tajawal", sans-serif;
  transition: all 0.2s ease;
}

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

/* Loading Animation */
.loading-dots {
  display: flex;
  gap: 4px;
  padding: 16px;
}

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

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

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

/* ===================================
   Chat Input Area
=================================== */
.chat-input-wrapper {
  padding: 20px 24px;
  border-top: 1px solid var(--border-color);
  background: var(--bg-primary);
}

.chat-input-container {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}

.chat-input {
  flex: 1;
  padding: 14px 18px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  color: var(--text-primary);
  font-size: 14px;
  font-family: "Tajawal", sans-serif;
  resize: none;
  max-height: 150px;
  transition: all 0.2s ease;
}

.chat-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.chat-input::placeholder {
  color: var(--text-muted);
}

.send-btn {
  width: 48px;
  height: 48px;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  border: none;
  border-radius: 14px;
  color: white;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s ease;
}

.send-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(59, 130, 246, 0.3);
}

.send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.input-hint {
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 10px;
}

/* ===================================
   Modals
=================================== */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal.active {
  display: flex;
}

.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  background: var(--bg-primary);
  border-radius: 20px;
  width: 90%;
  max-width: 500px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.3s ease;
  overflow: hidden;
}

.modal-lg {
  max-width: 600px;
}

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

.modal-header {
  padding: 24px;
  border-bottom: 1px solid var(--border-color);
  position: relative;
}

.modal-title {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
}

.modal-title i {
  color: var(--primary);
}

.modal-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
}

.modal-close {
  position: absolute;
  top: 20px;
  left: 20px;
  width: 36px;
  height: 36px;
  background: var(--bg-tertiary);
  border: none;
  border-radius: 10px;
  color: var(--text-secondary);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.modal-close:hover {
  background: var(--error);
  color: white;
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
}

/* Form Styles */
.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.form-group label i {
  color: var(--primary);
}

.form-input {
  width: 100%;
  padding: 14px 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  color: var(--text-primary);
  font-size: 14px;
  font-family: "Tajawal", sans-serif;
  transition: all 0.2s ease;
}

.form-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.form-input::placeholder {
  color: var(--text-muted);
}

.primary-btn {
  padding: 14px 24px;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-family: "Tajawal", sans-serif;
  transition: all 0.2s ease;
}

.primary-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(59, 130, 246, 0.3);
}

.full-width {
  width: 100%;
}

/* API Response Area */
.api-response-area {
  margin-top: 20px;
  display: none;
}

.api-response-area.active {
  display: block;
}

.response-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

.response-header i {
  color: var(--success);
}

.api-response-area pre {
  padding: 16px;
  background: var(--code-bg);
  border-radius: 10px;
  color: var(--code-text);
  font-size: 13px;
  line-height: 1.5;
  overflow-x: auto;
  direction: ltr;
  text-align: left;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Snippets Tabs */
.snippets-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.snippet-tab {
  padding: 10px 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: "Tajawal", sans-serif;
  transition: all 0.2s ease;
}

.snippet-tab:hover {
  border-color: var(--primary);
  color: var(--primary);
}

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

.snippet-tab.active i {
  color: white;
}

.snippets-content {
  margin-bottom: 20px;
}

.snippet-code {
  display: none;
}

.snippet-code.active {
  display: block;
}

.snippet-code pre {
  padding: 16px;
  background: var(--code-bg);
  border-radius: 10px;
  color: var(--code-text);
  font-size: 12px;
  line-height: 1.6;
  overflow-x: auto;
  direction: ltr;
  text-align: left;
}

.snippet-code code {
  font-family: "Fira Code", "Courier New", monospace;
}

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

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

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

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

/* ===================================
   Responsive Design
=================================== */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    right: -300px;
    top: 0;
    bottom: 0;
    width: 280px;
    z-index: 150;
    box-shadow: var(--shadow-lg);
  }

  .sidebar.open {
    right: 0;
  }

  .mobile-menu-btn {
    display: flex;
  }

  .chat-messages {
    padding: 16px;
    padding-top: 70px;
  }

  .message {
    max-width: 90%;
  }

  .welcome-screen h1 {
    font-size: 22px;
  }

  .welcome-screen p {
    font-size: 14px;
  }

  .quick-actions {
    flex-direction: column;
  }

  .quick-btn {
    width: 100%;
    justify-content: center;
  }

  .chat-input-wrapper {
    padding: 16px;
  }

  .modal-content {
    width: 95%;
    max-height: 90vh;
  }
}

@media (max-width: 480px) {
  .message {
    max-width: 95%;
  }

  .message-bubble {
    padding: 10px 14px;
    font-size: 13px;
  }

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