/**
 * RFG Studios Documentation - Mobile Responsiveness Fixes
 * Prevents horizontal scrolling and stabilizes UI on mobile devices
 */

/* Global fixes for horizontal scroll issues */
html, body {
  overflow-x: hidden;
  position: relative;
  width: 100%;
  max-width: 100vw;
}

/* Ensure all content is constrained within viewport */
.md-grid {
  max-width: 100%;
}

.md-content__inner {
  overflow-x: hidden;
  max-width: 100%;
}

/* Force all images and media to be responsive */
img, svg, video, canvas, audio, iframe, embed, object {
  max-width: 100%;
  height: auto;
}

/* Adjust typography for small screens */
@media screen and (max-width: 599px) {
  .md-typeset {
    font-size: 0.85rem;
  }
  
  .md-typeset h1 {
    font-size: 1.5rem;
  }
  
  .md-typeset h2 {
    font-size: 1.3rem;
  }
  
  .md-typeset h3 {
    font-size: 1.1rem;
  }
  
  .md-typeset pre {
    font-size: 0.7rem;
  }
  
  .md-typeset code {
    font-size: 0.7rem;
  }
}

/* Fix table display on small screens */
.md-typeset table:not([class]) {
  display: block;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Ensure code blocks don't cause horizontal scroll */
.md-typeset pre > code {
  max-width: 100%;
  overflow-x: auto;
}

/* Fix diagram display */
.mermaid {
  overflow-x: auto;
  max-width: 100%;
  display: block;
}

.mermaid svg {
  max-width: 100% !important;
  height: auto !important;
}

/* Fix popup modal for diagrams */
.diagram-modal-content {
  width: 95%;
  max-width: 95%;
  max-height: 90vh;
  margin: 2% auto;
}

.diagram-modal-body {
  max-height: 60vh;
  overflow: auto;
}

#diagram-modal-container {
  max-width: 100%;
  overflow-x: auto;
}

/* Adjust buttons on small screens */
@media screen and (max-width: 599px) {
  .diagram-modal-controls {
    flex-wrap: wrap;
  }
  
  .diagram-control-button {
    flex: 1 0 40%;
    margin-bottom: 5px;
    font-size: 0.75rem;
    padding: 6px;
  }
}

/* Ensure header elements don't overflow */
.md-header__inner {
  overflow-x: hidden;
}

.md-header__title {
  max-width: 50%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Improved Mobile/iPad Sidebar */
@media screen and (max-width: 1024px) {
  /* Ensure the sidebar toggle is visible */
  .md-header__button[for="__drawer"] {
    display: inline-block !important;
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    margin: 0.4rem;
    padding: 0.4rem;
  }
  
  /* Improve sidebar styling */
  .md-sidebar {
    width: 16rem;
    transition: transform 0.25s ease-in-out, width 0.25s ease-in-out;
  }
  
  /* Sidebar content improvements */
  .md-sidebar__scrollwrap {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }
  
  /* Make sidebar slightly wider on iPad for better touch targets */
  @media screen and (min-width: 768px) and (max-width: 1024px) {
    .md-sidebar {
      width: 18rem;
    }
  }
  
  /* Improve scroll behavior */
  .md-sidebar::-webkit-scrollbar {
    width: 4px;
  }
  
  .md-sidebar::-webkit-scrollbar-thumb {
    background-color: rgba(0, 0, 0, 0.1);
    border-radius: 4px;
  }
  
  /* Add slide animation when opening sidebar */
  .md-sidebar--primary:not([hidden]) {
    box-shadow: 0 0 12px rgba(0, 0, 0, 0.1);
  }
}

/* Fix buttons and navigation on mobile/tablet */
@media screen and (max-width: 1024px) {
  .md-header__button {
    margin: 0.3rem;
    padding: 0.3rem;
  }
  
  /* Make navigation tabs scrollable on mobile/tablet */
  .md-tabs {
    overflow-x: visible;
    width: 100%;
    display: block;
  }
  
  .md-tabs__list {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
    white-space: nowrap;
    display: flex;
    padding-bottom: 5px; /* Extra padding for better touch experience */
  }
  
  .md-tabs__item {
    float: none;
    display: inline-block;
    flex-shrink: 0;
  }
  
  .md-tabs__link {
    font-size: 0.8rem;
    padding: 0.9rem 0.5rem;
  }
  
  /* Add shadow indicator for scrollable area */
  .md-tabs::after {
    content: "";
    position: absolute;
    right: 0;
    top: 0;
    height: 100%;
    width: 24px;
    background: linear-gradient(to right, transparent, var(--md-primary-fg-color));
    pointer-events: none;
  }
}

/* Ensure popup elements don't cause horizontal scroll */
.md-dialog {
  max-width: 95vw;
}

/* Hide certain elements on small screens to save space */
@media screen and (max-width: 599px) {
  .md-header__button--print,
  .md-header-nav__button--print {
    display: none !important;
  }
  
  .md-footer-copyright__highlight::after {
    content: "";
  }
  
  .md-footer-copyright {
    font-size: 0.7rem;
  }
}

/* Make sidebar slightly wider on iPad for better touch targets */
@media screen and (min-width: 768px) and (max-width: 1024px) {
  .md-sidebar {
    width: 18rem;
  }
  
  /* iPad-specific sidebar enhancements */
  .md-sidebar--primary {
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.15);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    background-color: rgba(255, 255, 255, 0.95);
  }
  
  /* Larger tap targets on iPad */
  .md-nav__link {
    padding: 0.7rem 0.6rem;
    border-radius: 4px;
    margin: 0.1rem 0;
    transition: background-color 0.2s;
  }
  
  .md-nav__link:hover,
  .md-nav__link:focus {
    background-color: rgba(0, 0, 0, 0.05);
  }
  
  /* Improve nav item spacing */
  .md-nav__item {
    padding: 0 0.3rem;
  }
  
  /* Improve sidebar header spacing */
  .md-nav__title {
    padding: 1rem 0.8rem;
    font-size: 1.1rem;
  }
  
  /* Style active section indicator */
  .md-nav__link--active {
    font-weight: bold;
    border-left: 3px solid var(--md-primary-fg-color);
    padding-left: calc(0.6rem - 3px);
    background-color: rgba(0, 0, 0, 0.03);
  }
  
  /* Add scroll indicators to sidebar */
  .md-sidebar__scrollwrap::after {
    content: "";
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 24px;
    background: linear-gradient(to bottom, transparent, rgba(255, 255, 255, 0.9));
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s;
  }
  
  .md-sidebar__scrollwrap.can-scroll-down::after {
    opacity: 1;
  }
} 