// Custom styles for flux9s documentation site

// Homepage hero section - centered content, full width
.homepage-hero {
  min-height: 70vh;
  display: flex;
  align-items: center;
  padding: 4rem 2rem;
  text-align: center;
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  
  [data-bs-theme="dark"] & {
    background-color: #{$dark-bg};
  }
  
  [data-bs-theme="light"] & {
    background-color: #{$light-bg};
  }
  
  .container {
    max-width: 100% !important;
    margin: 0 auto !important;
    text-align: center !important;
    width: 100% !important;
    padding-left: 2rem !important;
    padding-right: 2rem !important;
  }
  
  // Ensure all content is centered
  p, div, h1, h2, h3, .flux9s-logo {
    text-align: center !important;
  }
  
  // Button container - proper flexbox alignment
  .d-flex {
    display: flex !important;
    align-items: center;
    justify-content: center;
    
    &.gap-3 {
      gap: 1rem !important;
    }
  }
  
  // Make content wider - less squashed
  .row {
    max-width: 1200px;
    margin: 0 auto;
  }
}

// ASCII logo styling
.flux9s-logo {
  text-align: center;
  
  pre {
    font-family: 'Courier New', 'Monaco', 'Menlo', 'Consolas', monospace;
    font-weight: bold;
    color: var(--bs-primary);
    line-height: 1.2;
    background: transparent;
    border: none;
    padding: 0;
    margin: 0;
    font-size: 1.2rem;
    letter-spacing: 0.05em;
    white-space: pre;
    overflow: visible;
    
    [data-bs-theme="dark"] & {
      color: #{$purple-400};
    }
    
    // Responsive sizing
    @media (max-width: 768px) {
      font-size: 0.9rem;
    }
    
    @media (max-width: 480px) {
      font-size: 0.7rem;
    }
  }
}

// Button improvements
.btn-primary {
  background-color: var(--bs-primary);
  border-color: var(--bs-primary);
  padding: 0.75rem 2rem;
  
  &:hover {
    background-color: var(--bs-link-hover-color);
    border-color: var(--bs-link-hover-color);
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
  }
}

.btn-outline-primary {
  color: var(--bs-primary);
  border-color: var(--bs-primary);
  padding: 0.75rem 2rem;
  
  &:hover {
    background-color: var(--bs-primary);
    border-color: var(--bs-primary);
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
  }
  
  [data-bs-theme="dark"] & {
    color: #{$purple-400};
    border-color: #{$purple-400};
    
    &:hover {
      background-color: #{$purple-400};
      color: #{$dark};
    }
  }
}

// Sidebar improvements - Flux-like styling (Docsy puts it on left by default)
.td-sidebar {
  background-color: var(--bs-body-bg);
  border-right: 1px solid #e0e0e0;
  padding: 1.5rem 1rem;
  
  [data-bs-theme="dark"] & {
    background-color: #{$dark};
    border-right-color: #404040;
  }
  
  .td-sidebar-nav {
    .td-sidebar-nav__section-title {
      color: var(--bs-body-color);
      font-weight: 600;
      font-size: 0.875rem;
      text-transform: uppercase;
      letter-spacing: 0.05em;
      margin-top: 2rem;
      margin-bottom: 0.75rem;
      padding: 0 0.75rem;
      
      &:first-child {
        margin-top: 0;
      }
    }
    
    a {
      color: var(--bs-body-color);
      transition: all 0.15s ease;
      padding: 0.5rem 0.75rem;
      border-radius: $border-radius-sm;
      display: block;
      text-decoration: none;
      font-size: 0.9rem;
      
      &:hover {
        color: var(--bs-primary);
        background-color: rgba(124, 58, 237, 0.08);
      }
      
      &.active {
        color: var(--bs-primary);
        font-weight: 600;
        background-color: rgba(124, 58, 237, 0.12);
      }
    }
  }
  
  // Search box styling
  .td-sidebar__search {
    margin-bottom: 1.5rem;
    padding: 0 0.75rem;
    
    input {
      width: 100%;
      border-radius: $border-radius-sm;
      border: 1px solid #e0e0e0;
      padding: 0.5rem 0.75rem;
      font-size: 0.9rem;
      transition: border-color 0.15s ease;
      
      [data-bs-theme="dark"] & {
        background-color: #2d2d2d;
        border-color: #404040;
        color: var(--bs-body-color);
      }
      
      &:focus {
        outline: none;
        border-color: var(--bs-primary);
        box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.1);
      }
      
      &::placeholder {
        color: #999;
        
        [data-bs-theme="dark"] & {
          color: #666;
        }
      }
    }
  }
}

// Code blocks - simple light grey styling (like Flux docs)
.highlight {
  margin: 1.5rem 0;
  
  pre {
    background-color: #f5f5f5;
    border-radius: $border-radius;
    padding: 1rem 1.25rem;
    border: 1px solid #e0e0e0;
    overflow-x: auto;
    
    code {
      color: #333;
      font-size: 0.9rem;
      line-height: 1.6;
      font-family: 'Courier New', 'Monaco', 'Menlo', 'Consolas', monospace;
    }
    
    [data-bs-theme="dark"] & {
      background-color: #2d2d2d;
      border-color: #404040;
      
      code {
        color: #e0e0e0;
      }
    }
  }
}

// Code blocks in feature blocks
.feature .highlight pre {
  background-color: #f5f5f5;
  
  [data-bs-theme="dark"] & {
    background-color: #2d2d2d;
  }
}

// Inline code
code:not(pre code) {
  background-color: rgba(124, 58, 237, 0.1);
  color: var(--bs-primary);
  padding: 0.2em 0.4em;
  border-radius: $border-radius-sm;
  font-size: 0.9em;
  
  [data-bs-theme="dark"] & {
    background-color: rgba(168, 85, 247, 0.2);
    color: #{$purple-300};
  }
}

// Buttons
.btn-primary {
  background-color: var(--bs-primary);
  border-color: var(--bs-primary);
  
  &:hover {
    background-color: var(--bs-link-hover-color);
    border-color: var(--bs-link-hover-color);
  }
}

.btn-secondary {
  background-color: var(--bs-secondary);
  border-color: var(--bs-secondary);
  
  [data-bs-theme="dark"] & {
    background-color: #{$purple-700};
    border-color: #{$purple-700};
  }
}

// Cards and blocks in content (merged into main .td-content below)

// Stats section - simplified
.project-stats {
  max-width: 900px;
  margin: 0 auto;
  
  .stat-item {
    padding: 1rem;
    
    h3 {
      color: var(--bs-primary);
      font-size: 2.5rem;
      font-weight: 700;
      margin-bottom: 0.5rem;
      
      [data-bs-theme="dark"] & {
        color: #{$purple-400};
      }
    }
    
    p {
      font-size: 0.9rem;
    }
  }
}

// Navigation improvements - Purple navbar
.navbar, .td-navbar {
  background-color: #{$primary} !important;
  border-bottom: 1px solid #{$purple-600};
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  padding: 0.75rem 0;
  
  [data-bs-theme="dark"] & {
    background-color: #{$purple-800} !important;
    border-bottom-color: #{$purple-900};
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  }
  
  .navbar-brand {
    font-weight: 700;
    color: var(--bs-white) !important;
    font-size: 1.6rem;
    margin-left: 1rem;
    
    &:hover {
      color: rgba(255, 255, 255, 0.9) !important;
    }
  }
  
  .nav-link {
    color: rgba(255, 255, 255, 0.9) !important;
    transition: color 0.15s ease;
    padding: 0.5rem 1rem;
    
    &:hover {
      color: var(--bs-white) !important;
    }
    
    &.active {
      color: var(--bs-white) !important;
      font-weight: 600;
      background-color: rgba(255, 255, 255, 0.1);
      border-radius: $border-radius-sm;
    }
  }
  
  // Dark mode toggle in purple navbar
  .theme-toggle {
    color: var(--bs-white) !important;
    margin-right: 1rem;
    
    &:hover {
      background-color: rgba(255, 255, 255, 0.2);
      color: var(--bs-white) !important;
    }
  }
}

// Dark mode toggle
.theme-toggle {
  cursor: pointer;
  padding: 0.5rem 0.75rem;
  border-radius: $border-radius-sm;
  transition: all 0.2s ease;
  border: none;
  background: transparent;
  color: var(--bs-white);
  font-size: 1.2rem;
  
  &:hover {
    background-color: rgba(255, 255, 255, 0.2);
    color: var(--bs-white);
    transform: scale(1.1);
  }
  
  &:focus {
    outline: 2px solid rgba(255, 255, 255, 0.5);
    outline-offset: 2px;
  }
  
  i {
    transition: transform 0.3s ease;
  }
  
  &:hover i {
    transform: rotate(15deg);
  }
}

// Cover block improvements
.td-cover-block {
  .lead {
    font-size: 1.25rem;
    font-weight: 400;
  }
  
  .btn {
    margin: 0.5rem;
    padding: 0.75rem 1.5rem;
    font-size: 1.1rem;
    border-radius: $border-radius-lg;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
    
    &:hover {
      transform: translateY(-2px);
      box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
    }
  }
}

// Responsive improvements
@media (max-width: 768px) {
  .flux9s-logo {
    font-size: 0.7rem;
    line-height: 1.1;
  }
  
  .td-sidebar {
    position: fixed;
    top: 0;
    left: -100%;
    z-index: 1000;
    transition: left 0.3s ease;
    height: 100vh;
    overflow-y: auto;
    
    &.show {
      left: 0;
    }
  }
  
  .td-main {
    margin-left: 0 !important;
  }
  
  .project-stats {
    .stat-item {
      margin-bottom: 1rem;
      
      h3 {
        font-size: 2rem;
      }
    }
  }
  
  .td-cover-block {
    .btn {
      display: block;
      width: 100%;
      margin: 0.5rem 0;
    }
  }
}

// Mobile menu toggle (if Docsy doesn't provide one)
@media (max-width: 991px) {
  .td-navbar {
    .navbar-toggler {
      border-color: var(--bs-primary);
      color: var(--bs-primary);
    }
  }
}

// Main wrapper - ensure proper width constraints
.td-main {
  background-color: var(--bs-body-bg);
  
  // Ensure main content area uses more width on larger screens
  // Docsy uses Bootstrap grid: col-xl-8 (66.7%), we'll make it wider
  main[role="main"] {
    // On xl screens and above, use more width for better readability
    @media (min-width: 1200px) {
      // Override Docsy's col-xl-8 to use more space
      flex: 0 0 auto;
      width: 70% !important; // Use 70% instead of 66.7%
      max-width: 70% !important;
    }
    
    @media (min-width: 1400px) {
      width: 72% !important;
      max-width: 72% !important;
    }
  }
  
  // Adjust sidebar widths to accommodate wider content
  .td-sidebar {
    @media (min-width: 1200px) {
      flex: 0 0 auto;
      width: 15% !important; // Reduce from 16.67% to 15%
      max-width: 15% !important;
    }
  }
  
  .td-sidebar-toc {
    @media (min-width: 1200px) {
      flex: 0 0 auto;
      width: 15% !important; // Reduce from 16.67% to 15%
      max-width: 15% !important;
    }
  }
  
  [data-bs-theme="dark"] & {
    background-color: #{$dark-bg};
  }
  
  [data-bs-theme="light"] & {
    background-color: #{$light-bg};
  }
}

// Hide page meta links (edit, etc.) but keep TOC
.td-page-meta__edit,
.td-page-meta__links {
  display: none !important;
}

// Ensure TOC is visible (keep toc tree as requested)
.td-toc {
  display: block !important;
}

// Content area - proper width constraints following Hugo/Docsy best practices
.td-content {
  background-color: var(--bs-body-bg);
  padding: 3rem 2rem;
  
  // Docsy wraps content in td-content__inner - ensure it uses available space
  // but doesn't get too wide (readability: ~80-100 chars = ~800-1000px)
  .td-content__inner {
    max-width: 100%;
    
    // On larger screens, allow content to use more width
    @media (min-width: 1200px) {
      max-width: 100%;
    }
  }
  
  // Use Docsy's native max-width system (.td-max-width-on-larger-screens)
  // Docsy automatically applies max-width constraints for readability
  // No need to override unless you have specific requirements
  
  // Container fluid should use full width
  .container-fluid {
    max-width: 100% !important;
    padding-left: 2rem;
    padding-right: 2rem;
    
    @media (min-width: 1400px) {
      padding-left: 3rem;
      padding-right: 3rem;
    }
  }
  
  // Dark/light theme backgrounds
  &[data-bs-theme="dark"] {
    background-color: #{$dark-bg};
  }
  
  &[data-bs-theme="light"] {
    background-color: #{$light-bg};
  }
  
  // Cards and blocks
  .card {
    border-color: var(--bs-border-color);
    transition: box-shadow 0.2s ease;
    
    &:hover {
      box-shadow: 0 4px 6px rgba(124, 58, 237, 0.1);
    }
  }
  
  // Feature blocks
  .feature {
    .feature-icon {
      color: var(--bs-primary);
    }
  }
  
  // Code blocks - simple light grey (override Docsy's default dark theme)
  .highlight {
    margin: 1.5rem 0;
    border-radius: $border-radius-sm;
    overflow: hidden;
    
    pre {
      background-color: #f5f5f5 !important;
      color: #333 !important;
      border: 1px solid #e0e0e0;
      padding: 1rem;
      margin: 0;
      
      code {
        background-color: transparent !important;
        color: #333 !important;
      }
      
      [data-bs-theme="dark"] & {
        background-color: #2d2d2d !important;
        color: #e0e0e0 !important;
        border-color: #404040;
        
        code {
          background-color: transparent !important;
          color: #e0e0e0 !important;
        }
      }
    }
  }
  
  // Inline code
  code:not(pre code) {
    background-color: #f5f5f5;
    color: #d63384;
    padding: 0.2rem 0.4em;
    border-radius: $border-radius-sm;
    font-size: 0.9em;
    
    [data-bs-theme="dark"] & {
      background-color: #2d2d2d;
      color: #e0a0ff;
    }
  }
  
  // Ensure images in content area use full available width
  img.img-fluid {
    max-width: 100%;
    width: 100%;
    height: auto;
    display: block;
  }
  
  // Breadcrumbs
  .td-breadcrumb {
    margin-bottom: 1rem;
    font-size: 0.875rem;
    color: #666;
    
    [data-bs-theme="dark"] & {
      color: #999;
    }
  }
}

// Use Docsy's default layout system
// Docsy handles main content width and sidebar layout automatically
// Only override if you have specific layout requirements

// Homepage specific styling (if needed)
// Docsy handles homepage layout through blocks/cover shortcode
// Use Docsy's native layout system for consistency

// Docsy uses Bootstrap defaults for typography and spacing
// Heading spacing follows Docsy's _content.scss:
// - h1: margin-bottom: 1rem
// - h2: margin-bottom: 1rem, margin-top: 3rem (if not first child)
// - h3-h6: margin-bottom: 1rem, margin-top: 2rem
// All content is left-aligned by default (Bootstrap standard)

// Smooth transitions
* {
  transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

// Font Awesome fallbacks - ensure icons degrade gracefully when fonts are blocked
// Add fallback font stack to prevent invisible icons
.fab, .fas, .far {
  // Ensure icons have minimum width to prevent layout shift
  min-width: 1em;
  display: inline-block;
  text-align: center;
  position: relative;
}

// Text fallbacks for icons - shown when fonts fail to load (via JavaScript detection)
.icon-fallback-text {
  display: none;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 0.9em;
  margin-left: 0.25em;
  
  // Show fallback text when fonts fail
  .fonts-failed & {
    display: inline;
  }
  
  // Hide icon when showing fallback text
  .fonts-failed + & {
    display: inline;
  }
}

// When fonts fail, hide icon and show text
.fonts-failed {
  .fab, .fas, .far {
    // Make icon invisible but keep space
    visibility: hidden;
    width: 0;
    min-width: 0;
    margin: 0;
  }
  
  .icon-fallback-text {
    display: inline;
  }
}

// Specific icon text fallbacks
.fa-github + .icon-fallback-text::before {
  content: '[GitHub]';
}

.fa-arrow-alt-circle-right + .icon-fallback-text::before {
  content: '→';
}

.fa-box + .icon-fallback-text::before {
  content: '[Box]';
}

.fa-beer + .icon-fallback-text::before {
  content: '[Beer]';
}

.fa-moon + .icon-fallback-text::before {
  content: '🌙';
}

.fa-sun + .icon-fallback-text::before {
  content: '☀️';
}
