/* Import Tailwind CSS via CDN or use your own styles */
@import url('https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css');

.w-fit {
  width: fit-content;
}

/* Prevent horizontal overflow on mobile & set global app background */
html, body {
  overflow-x: hidden;
  width: 100%;
  max-width: 100vw;
  background-color: #f7f4ed !important;
}

.bg-gray-50 {
  background-color: #f7f4ed !important;
}

/* Ensure all elements respect viewport width */
* {
  box-sizing: border-box;
}

/* Ensure main layout containers don't overflow */
#mainContent,
#articlePageContent,
#categoryViewContent,
#categoryView {
  overflow-x: hidden;
}

/* Ensure articles and major content blocks don't overflow */
article,
.bg-white,
.bg-gray-50 {
  max-width: 100%;
  overflow-wrap: break-word;
}

/* Specifically target article elements */
article {
  overflow-x: hidden;
  word-wrap: break-word;
}

/* Ensure divs inside articles respect bounds */
article > div {
  max-width: 100%;
  overflow-x: hidden;
}

/* Don't apply max-width to lists inside articles - they need space for markers */
article ol,
article ul {
  max-width: none;
  overflow-x: visible;
}

/* Custom styles */
.bg-brand-primary {
  background-color: #BA5A5A !important;
}

.hero-topo-bg {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image: url('/assets/hero-bg.svg');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  opacity: 0.3;
  mix-blend-mode: screen;
  filter: invert(1);
  -webkit-filter: invert(1);
  pointer-events: none;
}

.prose img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  margin: 1.5rem 0;
}

.prose a {
  color: #4f46e5;
  text-decoration: underline;
  word-break: break-word;
  overflow-wrap: break-word;
}

.prose a:hover {
  color: #4338ca;
}

/* Ensure prose content wraps properly on mobile */
.prose {
  word-wrap: break-word;
  overflow-wrap: break-word;
  max-width: 100%;
}

.prose * {
  max-width: 100%;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/* Heading styles for article content */
.prose h1 {
  font-size: 2.25rem;
  font-weight: 700;
  line-height: 1.2;
  margin-top: 2rem;
  margin-bottom: 1rem;
  color: #111827;
}

.prose h2 {
  font-size: 1.875rem;
  font-weight: 600;
  line-height: 1.3;
  margin-top: 1.5rem;
  margin-bottom: 0.75rem;
  color: #1f2937;
}

.prose p {
  font-size: 1.125rem;
  line-height: 1.75;
  margin-top: 1rem;
  margin-bottom: 1rem;
  color: #374151;
}

/* Ensure list items don't hide their markers */
.prose li {
  max-width: none;
  display: list-item;
  list-style-position: outside;
  padding-left: 0.5em;
}

/* Ordered lists - ensure numbering is visible */
.prose ol {
  list-style-type: decimal;
  list-style-position: outside;
  padding-left: 1.5em;
  margin-left: 0;
  margin-right: 0;
  max-width: none;
  overflow-x: visible;
}

.prose ol li {
  padding-left: 0.5em;
  margin-left: 0;
}

/* Unordered lists - ensure bullets are visible */
.prose ul {
  list-style-type: disc;
  list-style-position: outside;
  padding-left: 1.5em;
  margin-left: 0;
  margin-right: 0;
  max-width: none;
  overflow-x: visible;
}

.prose ul li {
  padding-left: 0.5em;
  margin-left: 0;
}

/* Nested lists */
.prose ul ul,
.prose ol ol,
.prose ul ol,
.prose ol ul {
  margin-top: 0.5em;
  margin-bottom: 0.5em;
}

/* Code block styling - matches screenshot design */
.prose pre,
.prose code,
pre.ql-syntax,
pre code {
  font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', monospace;
}

.prose pre,
pre.ql-syntax {
  background: #f5f5f5;
  border: 1px solid #e5e7eb;
  border-radius: 0.375rem;
  padding: 1rem;
  overflow-x: auto;
  color: #333333;
  margin: 1rem 0;
  word-break: normal;
}

.prose code,
pre code {
  overflow-x: auto;
  max-width: 100%;
  word-break: normal;
}

.prose pre {
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* Autocomplete Dropdown Styles */
#searchAutocomplete,
#categorySearchAutocomplete,
#articleSearchAutocomplete {
  position: absolute;
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 0.5rem;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  max-height: 24rem;
  overflow-y: auto;
  z-index: 1000;
}

#searchForm .relative,
#categorySearchForm .relative,
#searchForm.relative {
  position: relative;
}

.autocomplete-item {
  padding: 0.75rem 1rem;
  cursor: pointer;
  transition: background-color 0.15s ease-in-out;
  text-align: left;
}

.autocomplete-item:hover {
  background-color: #f3f4f6;
}

.autocomplete-item:last-child {
  border-bottom: none;
}

.autocomplete-item .text-sm {
  text-align: left;
  line-height: 1.25rem;
}

/* Allow full autocomplete text to show - wrap long titles instead of truncating */
.autocomplete-item .text-sm,
.autocomplete-item div {
  white-space: normal;
  word-wrap: break-word;
  overflow-wrap: break-word;
  overflow: visible;
}

/* Custom scrollbar for autocomplete */
#searchAutocomplete::-webkit-scrollbar,
#categorySearchAutocomplete::-webkit-scrollbar,
#articleSearchAutocomplete::-webkit-scrollbar {
  width: 6px;
}

#searchAutocomplete::-webkit-scrollbar-track,
#categorySearchAutocomplete::-webkit-scrollbar-track,
#articleSearchAutocomplete::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 3px;
}

#searchAutocomplete::-webkit-scrollbar-thumb,
#categorySearchAutocomplete::-webkit-scrollbar-thumb,
#articleSearchAutocomplete::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 3px;
}

#searchAutocomplete::-webkit-scrollbar-thumb:hover,
#categorySearchAutocomplete::-webkit-scrollbar-thumb:hover,
#articleSearchAutocomplete::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8;
}

/* Image optimization - lazy loading is handled via HTML loading attribute */

/* Category view article cards */
.category-article-card {
  position: relative;
}

.category-article-card .star-icon {
  position: absolute;
  top: 1rem;
  right: 1rem;
  z-index: 10;
}



/* Adjust header padding when content is hidden */
#mainHeader:has(#headerContent[style*="display: none"]) {
  padding-bottom: 1.5rem;
}

/* Category view layout - force two column layout */
#categoryViewContent.category-view-grid,
.category-view-grid {
  display: grid !important;
  grid-template-columns: 280px 1fr !important;
  gap: 2rem !important;
  overflow: hidden;
}

/* Ensure grid children are in correct order */
#categoryViewContent.category-view-grid > aside {
  grid-column: 1;
}

#categoryViewContent.category-view-grid > div {
  grid-column: 2;
}

/* Article page layout - same sidebar structure */
.article-layout-grid,
#categoryViewContent.article-layout-grid,
#articlePageContent.article-layout-grid {
  display: grid !important;
  grid-template-columns: 280px 1fr !important;
  gap: 2rem !important;
  overflow: hidden;
}

/* Ensure skeleton is completely hidden when not displayed */
#articlePageSkeleton[style*="display: none"],
#categoryViewSkeleton[style*="display: none"] {
  height: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  overflow: hidden !important;
}

/* Mobile sidebar overlay and styles */
#mobileMenuOverlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 40;
}

#sidebar.mobile-open {
  display: block !important;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  width: 280px;
  z-index: 50;
  overflow-y: auto;
  box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
}

/* Close button for mobile sidebar */
.mobile-sidebar-close {
  display: none;
}

@media (max-width: 1024px) {
  #sidebar.mobile-open .mobile-sidebar-close {
    display: flex !important;
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: white;
    border: none;
    border-radius: 50%;
    width: 2rem;
    height: 2rem;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    z-index: 10;
  }
}

/* Responsive adjustments */
@media (max-width: 1024px) {
  /* Force single column layout on mobile - with high specificity to override base styles */
  .category-view-grid,
  .article-layout-grid,
  #categoryViewContent.category-view-grid,
  #categoryViewContent.article-layout-grid,
  #articlePageContent.article-layout-grid {
    grid-template-columns: 1fr !important;
    gap: 1rem !important;
  }
  
  /* Ensure sidebar is hidden by default on mobile */
  #sidebar {
    display: none;
  }
  
  /* Responsive text sizes */
  #mainHeader h1 {
    font-size: 2rem;
  }
  
  #mainHeader p {
    font-size: 1rem;
  }
  
  /* Responsive header padding */
  #mainHeader .max-w-7xl {
    padding-top: 1.5rem;
    padding-bottom: 1.5rem;
  }
  
  #headerContent {
    margin-top: 1rem;
  }
}

/* Mobile-specific viewport fixes - applies to screens below sm breakpoint (640px) */
@media (max-width: 639px) {
  /* Force all Tailwind px-8 to be px-4 on mobile */
  .px-8 {
    padding-left: 1rem !important;
    padding-right: 1rem !important;
  }
  
  /* Force all Tailwind sm:px-6 to be px-4 on mobile */
  .sm\:px-6 {
    padding-left: 1rem !important;
    padding-right: 1rem !important;
  }
  
  /* Force all Tailwind lg:px-8 to be px-4 on mobile */
  .lg\:px-8 {
    padding-left: 1rem !important;
    padding-right: 1rem !important;
  }
  
  /* Reduce article content padding on mobile */
  article > div {
    padding-left: 1rem !important;
    padding-right: 1rem !important;
  }
  
  /* Reduce header padding on very small screens */
  #mainHeader .max-w-7xl {
    padding-top: 1rem !important;
    padding-bottom: 1rem !important;
  }
  
  /* Reduce grid gap on mobile - with high specificity */
  .article-layout-grid,
  .category-view-grid,
  #categoryViewContent.category-view-grid,
  #categoryViewContent.article-layout-grid,
  #articlePageContent.article-layout-grid {
    gap: 0.75rem !important;
  }
  
  /* Ensure search input doesn't overflow */
  input[type="text"] {
    max-width: 100%;
    box-sizing: border-box;
  }
  
  /* Ensure buttons and interactive elements fit */
  button {
    max-width: 100%;
    box-sizing: border-box;
  }
  
  /* Ensure cards don't overflow */
  .skeleton-card,
  .category-article-card {
    max-width: 100%;
    overflow: hidden;
  }
  
  /* Reduce prose font size on mobile for better fit */
  .prose.prose-lg {
    font-size: 1rem !important;
    line-height: 1.75 !important;
  }
  
  /* Ensure tables don't overflow */
  .prose table {
    display: block;
    overflow-x: auto;
    width: 100%;
    max-width: 100%;
  }
  
  /* Ensure lists maintain proper spacing and numbering on mobile */
  .prose ol,
  .prose ul {
    padding-left: 1.25em;
  }
  
  .prose li {
    padding-left: 0.5em;
  }
  
  /* Ensure all rounded corners don't cause layout issues */
  .rounded-lg {
    border-radius: 0.5rem;
  }
  
  /* Reduce spacing between elements */
  .space-x-6 > * + * {
    margin-left: 0.5rem !important;
  }
  
  /* Ensure flex items wrap */
  .flex {
    flex-wrap: wrap;
  }
  
  /* Reduce margin-bottom values */
  .mb-8 {
    margin-bottom: 1.5rem !important;
  }
  
  .mb-12 {
    margin-bottom: 2rem !important;
  }
}

/* Skeleton Loading Styles */
@keyframes skeleton-shimmer {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}

.skeleton {
  background: linear-gradient(
    90deg,
    #f0f0f0 25%,
    #e0e0e0 50%,
    #f0f0f0 75%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s ease-in-out infinite;
  border-radius: 4px;
}

.skeleton-text {
  height: 1rem;
  width: 100%;
  margin-bottom: 0.5rem;
}

.skeleton-title {
  height: 1.5rem;
  width: 80%;
  margin-bottom: 1rem;
}

.skeleton-heading {
  height: 2rem;
  margin-bottom: 1rem;
}

.skeleton-image {
  height: 200px;
  width: 100%;
}

.skeleton-card {
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 1.5rem;
}

.skeleton-button {
  height: 2.5rem;
  width: 6rem;
  border-radius: 6px;
}

/* Custom Confirmation Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal-backdrop.active {
  opacity: 1;
  visibility: visible;
}

.modal-content {
  background: white;
  border-radius: 1.5rem;
  padding: 2.5rem;
  max-width: 440px;
  width: 90%;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  transform: scale(0.9) translateY(20px);
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  text-align: center;
}

.modal-backdrop.active .modal-content {
  transform: scale(1) translateY(0);
}

.modal-icon {
  width: 64px;
  height: 64px;
  background: #fee2e2;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1.5rem;
  color: #dc2626;
}

.modal-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: #111827;
  margin-bottom: 0.75rem;
}

.modal-body {
  color: #4b5563;
  font-size: 1.125rem;
  line-height: 1.6;
  margin-bottom: 2rem;
}

.modal-actions {
  display: flex;
  gap: 1rem;
  justify-content: center;
}

.modal-btn {
  padding: 0.875rem 2rem;
  border-radius: 0.75rem;
  font-weight: 600;
  font-size: 1rem;
  transition: all 0.2s;
  cursor: pointer;
  border: none;
  flex: 1;
}

.modal-btn-cancel {
  background: #f3f4f6;
  color: #4b5563;
}

.modal-btn-cancel:hover {
  background: #e5e7eb;
}

.modal-btn-confirm {
  background: #dc2626;
  color: white;
}

.modal-btn-confirm:hover {
  background: #b91c1c;
  transform: translateY(-1px);
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  pointer-events: none;
}

.toast {
  padding: 0.625rem 1.25rem;
  border-radius: 9999px;
  background: #1f2937;
  color: white;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  display: flex;
  align-items: center;
  gap: 0.625rem;
  min-width: fit-content;
  max-width: 90vw;
  pointer-events: auto;
  animation: toast-in 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  transition: all 0.3s ease;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

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

.toast.toast-out {
  opacity: 0;
  transform: translateY(10px) scale(0.95);
}

.toast-icon-success {
  color: #34d399;
}

.toast-icon-error {
  color: #f87171;
}

.toast-content {
  flex-grow: 1;
  font-weight: 500;
  color: white;
  font-size: 0.875rem;
  white-space: nowrap;
}
