:root {
  --bg-primary: #202124;
  --bg-secondary: #303134;
  --bg-search: #303134;
  --text-primary: #e8eaed;
  --text-secondary: #9aa0a6;
  --border-color: #5f6368;
  --hover-bg: #303134;
  --result-bg: #303134;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
  --accent: #7174ff; /* Premium indigo accent */
  --accent-rgb: 99, 102, 241;
  --chat-green: #10b981;
}

[data-theme="light"] {
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-search: #f1f5f9;
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --border-color: #e2e8f0;
  --hover-bg: #f1f5f9;
  --shadow: 0 4px 20px rgba(148, 163, 184, 0.15);
  --accent: #4f46e5;
  --accent-rgb: 79, 70, 229;
  --chat-green: #059669;
}

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

body {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  transition: background-color 0.3s ease, color 0.3s ease;
  min-height: 100vh;
}

/* Font Assignments based on language */
body.lang-ur {
  font-family: "Noto Nastaliq Urdu", serif;
}
body.lang-en,
body.lang-roman_urdu {
  font-family: "Outfit", "Inter", sans-serif;
}
[dir="rtl"] body {
  line-height: 2.2;
}

.theme-toggle,
.translator-toggle {
  position: fixed;
  top: 1.25rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 50%;
  width: 2.75rem;
  height: 2.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s ease;
  z-index: 1001;
  font-size: 1.25rem;
  color: var(--text-primary);
  box-shadow: var(--shadow);
}

.theme-toggle {
  left: 1.25rem;
}

.translator-toggle {
  left: 5rem;
}

.theme-toggle:hover,
.translator-toggle:hover {
  background: var(--hover-bg);
  transform: scale(1.1);
  box-shadow: var(--shadow);
}

/* Chat Page Outer Container */
.chat-page {
  min-height: 100vh;
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
}

/* Chat Header */
.chat-header {
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-color);
  padding: 1rem 1.875rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 1rem;
  line-height: 2.2;
  box-shadow: var(--shadow);
}

.chat-logo {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-primary);
  text-align: center;
  flex: 1;
}

.api-toggle {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.3s ease;
  font-size: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  position: fixed;
  top: 1.25rem;
  right: 1.25rem;
  z-index: 1001;
  box-shadow: var(--shadow);
}

.api-toggle:hover {
  background: var(--hover-bg);
  border-color: var(--accent);
}

/* AI Generated Warning Notice Banner */
.ai-warning-banner {
  background: #fef3c7; /* Light amber */
  border-bottom: 1px solid #fde68a;
  color: #92400e; /* Dark amber text */
  padding: 0.65rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
  line-height: 1.5;
  font-weight: 500;
  gap: 1rem;
  z-index: 99;
}

[data-theme="dark"] .ai-warning-banner {
  background: #78350f; /* Dark amber background */
  border-bottom: 1px solid #92400e;
  color: #fef3c7; /* Light amber text */
}

.warning-icon {
  font-size: 1.1rem;
}

.warning-text {
  flex: 1;
}

.warning-close {
  background: none;
  border: none;
  color: inherit;
  font-size: 1rem;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 0.2s;
}

.warning-close:hover {
  opacity: 1;
}

/* Chat Messages Area */
.chat-container {
  flex: 1;
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  padding: 1.25rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* Chat message alignments */
.message {
  display: flex;
  gap: 1rem;
  align-items: flex-start;
  animation: slideIn 0.3s ease-out;
}

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

/* English / LTR message directions */
body.lang-en .message.model,
body.lang-roman_urdu .message.model {
  align-self: flex-start;
}

body.lang-en .message.user,
body.lang-roman_urdu .message.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

/* Urdu / RTL message directions */
body.lang-ur .message.model {
  align-self: flex-start;
}

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

.message-avatar {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  flex-shrink: 0;
}

.message.user .message-avatar {
  background: linear-gradient(135deg, var(--accent), #4285f4);
}

.message.model .message-avatar {
  background: linear-gradient(135deg, var(--chat-green), #0f9d58);
}

.message-content {
  flex: 1;
}

.message-bubble {
  background: var(--result-bg);
  border: 1px solid var(--border-color);
  border-radius: 1rem;
  padding: 1rem 1.25rem;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.message.user .message-bubble {
  background: linear-gradient(135deg, #e3f2fd, #bbdefb);
  border-color: #90caf9;
}

[data-theme="dark"] .message.user .message-bubble {
  background: linear-gradient(135deg, #1565c0, #1976d2);
  border-color: #1976d2;
}

.message-text {
  font-size: 1.05rem;
  line-height: 2.2;
  color: var(--text-primary);
  white-space: pre-wrap;
  word-wrap: break-word;
}

.message-actions {
  display: flex;
  gap: 0.625rem;
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border-color);
  flex-wrap: wrap;
}

/* Context / References Panel */
.context-toggle {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  padding: 0.5rem 1rem;
  border-radius: 0.375rem;
  font-family: "Noto Nastaliq Urdu", serif;
  font-size: 0.8125rem;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 0.375rem;
}

.context-toggle:hover {
  background: var(--hover-bg);
  border-color: var(--accent);
}

.context-panel {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  padding: 1rem;
  margin-top: 0.625rem;
  display: none;
  animation: fadeIn 0.2s ease;
}

.context-panel.active {
  display: block;
}

/* Book Context Note Box (Explanation Note) */
.book-note-callout {
  background: rgba(var(--accent-rgb), 0.08) !important;
  border: 1px solid rgba(var(--accent-rgb), 0.25) !important;
  border-radius: 0.5rem;
  padding: 0.75rem 1rem;
  margin-bottom: 0.85rem;
}

.book-note-callout strong {
  color: var(--accent);
  font-size: 0.85rem;
  display: block;
  margin-bottom: 0.25rem;
}

.book-note-text {
  font-size: 0.85rem !important;
  color: var(--text-primary) !important;
  line-height: 1.5 !important;
}

.lang-ur .book-note-text {
  font-size: 0.95rem !important;
  line-height: 2.0 !important;
}

.context-title {
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 0.625rem;
  color: var(--text-primary);
}

.context-item {
  background: var(--result-bg);
  border: 1px solid var(--border-color);
  border-radius: 0.375rem;
  padding: 0.625rem;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
  font-size: 1rem;
  line-height: 2.0;
  font-family: "Noto Nastaliq Urdu", serif !important;
}

.context-item:last-child {
  margin-bottom: 0;
}

/* Copy Small Button */
.copy-btn-small {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0.4rem 0.65rem;
  border-radius: 0.5rem;
  font-size: 0.8rem;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.copy-btn-small:hover {
  background: var(--hover-bg);
  color: var(--text-primary);
}

/* Typing indicator dot styles */
.typing-indicator {
  display: flex;
  gap: 0.375rem;
  padding: 0.625rem;
}

.typing-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--text-secondary);
  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%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

/* Chat Input Bar */
.chat-input-container {
  position: sticky;
  bottom: 0;
  background: var(--bg-primary);
  border-top: 1px solid var(--border-color);
  padding: 1.25rem;
}

.chat-input-wrapper {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  gap: 0.625rem;
  align-items: center;
}

.chat-input-box {
  flex: 1;
  display: flex;
  align-items: center;
  background: var(--bg-search);
  border: 1px solid var(--border-color);
  border-radius: 1.5rem;
  padding: 0.75rem 1.25rem;
  box-shadow: var(--shadow);
  transition: all 0.3s ease;
}

.chat-input-box:focus-within {
  box-shadow: 0 2px 12px rgba(32, 33, 36, 0.2);
  border-color: var(--accent);
}

.chat-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-family: inherit;
  font-size: 1rem;
  color: var(--text-primary);
  resize: none;
  max-height: 120px;
  min-height: 24px;
  line-height: 2.2;
  padding: 1rem;
}

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

.send-btn {
  background: var(--chat-green);
  color: white;
  border: none;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  transition: all 0.3s ease;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.send-btn:hover:not(:disabled) {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.send-btn:disabled {
  background: var(--border-color);
  color: var(--text-secondary);
  cursor: not-allowed;
  box-shadow: none;
  opacity: 0.5;
}

/* Language selector modal styling */
.lang-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(10, 11, 15, 0.8);
  backdrop-filter: blur(8px);
  z-index: 10000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.lang-modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 1.5rem;
  padding: 2.5rem 2rem;
  max-width: 440px;
  width: 100%;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
  animation: modalZoom 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.lang-modal-content h2 {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 1.75rem;
  color: var(--accent);
}

.lang-buttons-grid {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.lang-select-btn {
  padding: 0.95rem;
  font-size: 1.1rem;
  font-weight: 600;
  line-height: 2.2;
  border: 1px solid var(--border-color);
  border-radius: 0.75rem;
  background: var(--bg-primary);
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.3s ease;
}

.lang-select-btn:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
  background: var(--hover-bg);
}

.lang-select-btn.font-urdu {
  font-family: "Noto Nastaliq Urdu", serif;
}
.lang-select-btn.font-roman,
.lang-select-btn.font-english {
  font-family: "Outfit", sans-serif;
}

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

/* Scrollbar styling */
.chat-container::-webkit-scrollbar {
  width: 6px;
}

.chat-container::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

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

.chat-container::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}

/* Responsive Overrides */
@media (max-width: 768px) {
  .theme-toggle,
  .api-toggle,
  .translator-toggle {
    width: 2.5rem;
    height: 2.5rem;
    font-size: 1.125rem;
    top: 1rem;
  }

  .theme-toggle {
    left: 1rem;
  }

  .translator-toggle {
    left: 4rem;
  }

  .chat-header {
    padding: 0.75rem 1rem;
  }

  .chat-logo {
    font-size: 1.25rem;
  }

  .ai-warning-banner {
    padding: 0.5rem 1rem;
    font-size: 0.75rem;
  }

  .chat-container {
    padding: 1rem;
  }

  .message {
    max-width: 92%;
  }

  .message-avatar {
    width: 2rem;
    height: 2rem;
    font-size: 0.95rem;
  }

  .message-bubble {
    padding: 0.875rem 1rem;
  }

  .message-text {
    font-size: 0.9375rem;
  }

  .chat-input-container {
    padding: 1rem;
  }

  .chat-input-wrapper {
    gap: 0.5rem;
  }

  .chat-input-box {
    padding: 0.625rem 1rem;
  }

  .chat-input {
    font-size: 0.9375rem;
  }

  .send-btn {
    width: 2.5rem;
    height: 2.5rem;
    font-size: 1.125rem;
  }

  .sidebar {
    max-width: 100%;
    z-index: 1001;
  }

  .sidebar-content {
    padding: 1.25rem;
  }

  textarea {
    min-height: 100px;
  }
}

@media (max-width: 576px) {
  .message-content {
    max-width: 90%;
  }

  .message-actions {
    flex-direction: column;
    gap: 0.5rem;
  }

  .context-toggle,
  .copy-btn-small {
    width: 100%;
    justify-content: center;
  }

  .chat-input-wrapper {
    flex-direction: row;
  }

  .chat-input {
    font-size: 0.875rem;
  }
}

@media (max-width: 400px) {
  .chat-container {
    padding: 0.75rem;
  }

  .message-bubble {
    padding: 0.75rem 0.875rem;
  }

  .chat-input-container {
    padding: 0.75rem;
  }

  .send-btn {
    width: 2.25rem;
    height: 2.25rem;
  }
}

/* Scrollbar */
.chat-container::-webkit-scrollbar {
  width: 8px;
}

.chat-container::-webkit-scrollbar-track {
  background: var(--bg-secondary);
}

.chat-container::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

.chat-container::-webkit-scrollbar-thumb:hover {
  background: var(--text-secondary);
}
