/* 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');

/* Prevent horizontal overflow on mobile */
html, body {
  overflow-x: hidden;
  width: 100%;
  max-width: 100vw;
}

/* 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 */
.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;
}

/* 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;
}

/* Prevent code blocks and pre elements from overflowing */
.prose pre,
.prose code {
  overflow-x: auto;
  max-width: 100%;
  word-break: normal;
}

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

/* 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;
}

/* Main header background color */
#mainHeader {
  background-color: #feedeb;
}

/* 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;
  margin-bottom: 0.5rem;
}

.skeleton-title {
  height: 1.5rem;
  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;
}
