/* =================== GLOBAL STYLES =================== */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", "Roboto",
    "Oxygen", "Ubuntu", "Cantarell", sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: #1f2937;
  background-color: #f9fafb;
}

.dark body {
  color: #f3f4f6;
  background-color: #111827;
}

/* Smooth transitions for theme changes */
html,
body,
* {
  transition-property: background-color, border-color, color, fill, stroke;
  transition-duration: 200ms;
  transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
}

/* Disable transitions during page load */
body.preload * {
  transition: none !important;
}

/* =================== SCROLLBAR CUSTOMIZATION =================== */

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background-color: rgba(0, 0, 0, 0.15);
  border-radius: 6px;
  transition: background-color 0.2s;
}

::-webkit-scrollbar-thumb:hover {
  background-color: rgba(0, 0, 0, 0.25);
}

.dark ::-webkit-scrollbar-thumb {
  background-color: rgba(255, 255, 255, 0.15);
}

.dark ::-webkit-scrollbar-thumb:hover {
  background-color: rgba(255, 255, 255, 0.25);
}

/* Firefox scrollbar */
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 0, 0, 0.15) transparent;
}

.dark * {
  scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}

/* =================== ANIMATIONS =================== */

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes bounce {
  0%,
  80%,
  100% {
    transform: translateY(0);
  }
  40% {
    transform: translateY(-8px);
  }
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

@keyframes shimmer {
  0% {
    background-position: -1000px 0;
  }
  100% {
    background-position: 1000px 0;
  }
}

.animate-fadeIn {
  animation: fadeIn 0.4s ease-out;
}

.animate-slideIn {
  animation: slideIn 0.3s ease-out;
}

.animate-slideInRight {
  animation: slideInRight 0.3s ease-out;
}

.animate-bounce {
  animation: bounce 1s ease-in-out infinite;
}

.animate-pulse {
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

/* =================== CHAT BUBBLES =================== */

#chat-box .message {
  animation: fadeIn 0.3s ease-out;
}

/* User message styling */
#chat-box .user div {
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  color: #fff;
  border-radius: 1.25rem 1.25rem 0.25rem 1.25rem;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1),
    0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

/* Bot message styling */
#chat-box .bot div {
  background-color: #ffffff;
  color: #111827;
  border-radius: 1.25rem 1.25rem 1.25rem 0.25rem;
}

.dark #chat-box .bot div {
  background-color: #374151;
  color: #f3f4f6;
}

/* Unified Message Styling */
.message-text {
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.message-text p:first-child {
  margin-top: 0;
}

.message-text p:last-child {
  margin-bottom: 0;
}

.message-text img {
  border-radius: 8px;
  margin: 10px 0;
  max-width: 100%;
}


/* =================== MARKDOWN CONTENT STYLING =================== */

#chat-box h1,
#chat-box h2,
#chat-box h3,
#chat-box h4,
#chat-box h5,
#chat-box h6 {
  font-weight: 700;
  margin: 16px 0 10px 0;
  line-height: 1.4;
  color: inherit;
}

#chat-box h1 {
  font-size: 1.75rem;
  border-bottom: 2px solid rgba(0, 0, 0, 0.1);
  padding-bottom: 8px;
}

.dark #chat-box h1 {
  border-bottom-color: rgba(255, 255, 255, 0.1);
}

#chat-box h2 {
  font-size: 1.5rem;
}

#chat-box h3 {
  font-size: 1.25rem;
}

#chat-box h4 {
  font-size: 1.1rem;
}

#chat-box p {
  margin: 10px 0;
  line-height: 1.7;
}

#chat-box ul,
#chat-box ol {
  margin: 12px 0;
  padding-left: 28px;
}

#chat-box li {
  margin: 6px 0;
  line-height: 1.7;
}

#chat-box ul li {
  list-style-type: disc;
}

#chat-box ol li {
  list-style-type: decimal;
}

#chat-box strong {
  font-weight: 600;
  color: inherit;
}

#chat-box em {
  font-style: italic;
}

#chat-box code {
  background: rgba(0, 0, 0, 0.06);
  padding: 3px 8px;
  border-radius: 5px;
  font-family: "Monaco", "Menlo", "Consolas", "Courier New", monospace;
  font-size: 0.9em;
  color: #e11d48;
}

.dark #chat-box code {
  background: rgba(255, 255, 255, 0.1);
  color: #fb7185;
}

#chat-box pre {
  background: #f5f5f5;
  padding: 16px;
  border-radius: 10px;
  overflow-x: auto;
  margin: 16px 0;
  border: 1px solid #e5e7eb;
}

.dark #chat-box pre {
  background: #1f2937;
  border-color: #374151;
}

#chat-box pre code {
  background: transparent;
  padding: 0;
  color: inherit;
  font-size: 0.875rem;
}

#chat-box blockquote {
  border-left: 4px solid #3b82f6;
  padding-left: 20px;
  margin: 16px 0;
  color: #6b7280;
  font-style: italic;
  background: rgba(59, 130, 246, 0.05);
  padding: 12px 20px;
  border-radius: 0 8px 8px 0;
}

.dark #chat-box blockquote {
  border-left-color: #60a5fa;
  color: #9ca3af;
  background: rgba(59, 130, 246, 0.1);
}

#chat-box a {
  color: #2563eb;
  text-decoration: underline;
  transition: color 0.2s;
}

#chat-box a:hover {
  color: #1d4ed8;
}

.dark #chat-box a {
  color: #60a5fa;
}

.dark #chat-box a:hover {
  color: #93c5fd;
}

#chat-box hr {
  border: none;
  border-top: 2px solid #e5e7eb;
  margin: 20px 0;
}

.dark #chat-box hr {
  border-top-color: #374151;
}

/* Tables */
#chat-box table {
  border-collapse: collapse;
  width: 100%;
  margin: 16px 0;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  overflow: hidden;
}

.dark #chat-box table {
  border-color: #374151;
}

#chat-box th,
#chat-box td {
  border: 1px solid #e5e7eb;
  padding: 10px 14px;
  text-align: left;
}

.dark #chat-box th,
.dark #chat-box td {
  border-color: #4b5563;
}

#chat-box th {
  background: #f9fafb;
  font-weight: 600;
  color: #374151;
}

.dark #chat-box th {
  background: #1f2937;
  color: #f3f4f6;
}

#chat-box tr:nth-child(even) {
  background: #f9fafb;
}

.dark #chat-box tr:nth-child(even) {
  background: #1f2937;
}

/* =================== TYPING INDICATOR =================== */

.typing-dots {
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 4px 0;
}

.typing-dots span {
  width: 8px;
  height: 8px;
  background-color: #9ca3af;
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(1) {
  animation-delay: 0s;
}

.typing-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

/* =================== SESSION ITEMS =================== */

.session-item {
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  animation: slideIn 0.3s ease-out;
}

.session-item:hover {
  transform: translateX(4px);
}

.session-item.active {
  border-left: 4px solid #2563eb;
}

/* =================== BUTTONS =================== */

button {
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  user-select: none;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
}

button:active:not(:disabled) {
  transform: translateY(0);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

/* =================== INPUT FOCUS =================== */

input:focus,
textarea:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.dark input:focus,
.dark textarea:focus {
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

/* =================== PROFILE HOVER =================== */

#profile {
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

#profile:hover {
  transform: scale(1.02);
}

/* =================== WELCOME MESSAGE =================== */

#welcome-message {
  animation: fadeIn 0.6s ease-out;
}

.dark #welcome-message h1 {
  color: #ffffff;
}

.dark #welcome-message p {
  color: #9ca3af;
}

/* =================== LOADING SKELETON =================== */

.skeleton {
  background: linear-gradient(
    90deg,
    rgba(0, 0, 0, 0.06) 25%,
    rgba(0, 0, 0, 0.15) 37%,
    rgba(0, 0, 0, 0.06) 63%
  );
  background-size: 1000px 100%;
  animation: shimmer 1.5s infinite;
}

.dark .skeleton {
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.05) 25%,
    rgba(255, 255, 255, 0.1) 37%,
    rgba(255, 255, 255, 0.05) 63%
  );
  background-size: 1000px 100%;
}

/* =================== TOAST NOTIFICATIONS =================== */

@keyframes slideInFromRight {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.animate-slideInFromRight {
  animation: slideInFromRight 0.3s ease-out;
}

/* =================== RESPONSIVE DESIGN =================== */

@media (max-width: 768px) {
  #sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 40;
    width: 280px;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
  }

  #sidebar.open {
    transform: translateX(0);
  }

  #chat-box {
    padding: 16px;
  }

  #chat-box .bot div,
  #chat-box .user div {
    max-width: 90%;
    min-width: 150px;
  }

  /* Mobile menu toggle */
  .mobile-menu-btn {
    display: block;
  }
}

@media (min-width: 769px) {
  .mobile-menu-btn {
    display: none;
  }
}

/* =================== ACCESSIBILITY =================== */

/* Focus visible for keyboard navigation */
*:focus-visible {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

/* Reduced motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* =================== PRINT STYLES =================== */

@media print {
  #sidebar,
  #input-area,
  button {
    display: none !important;
  }

  #chat-box {
    height: auto !important;
    overflow: visible !important;
  }
}

/* =================== CUSTOM UTILITIES =================== */

.text-balance {
  text-wrap: balance;
}

.glass-effect {
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.dark .glass-effect {
  background: rgba(0, 0, 0, 0.3);
  border-color: rgba(255, 255, 255, 0.1);
}

.gradient-text {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}