/* MOBILE-FIRST RESPONSIVE LAYOUT - NO FIXED PIXELS */

.wrapper {
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  padding: 4rem 1rem 0 1rem;
  display: grid !important;
  grid-template-columns: 1fr;
  grid-template-rows: auto 1fr;
  gap: 1.5rem;
  min-height: calc(100dvh - 5rem);
  align-items: start;
}

/* Desktop/Tablet Sidebar */
.sidebar.desktop-only {
  grid-column: 1;
  position: -webkit-sticky; /* Safari support */
  position: sticky;
  top: 100px;
  height: fit-content;
  padding: 1rem;
  align-self: start; /* Ensures proper grid alignment */
}


/* Mobile Ribbon (hidden by default) */
.mobile-ribbon.mobile-only {
  display: none;
}

/* Main content */
main {
  grid-column: 2;
  max-width: none;
  width: auto;
  float: none;
  padding: 1rem;
}

/* DESKTOP-FIRST RESPONSIVE BREAKPOINTS - Mobile to Desktop */

/* Tablet and above - 2-column layout */
@media (min-width: 48rem) { /* 768px equivalent */
  .wrapper {
    max-width: 90%;
    grid-template-columns: minmax(15rem, 20%) 1fr; /* Fluid sidebar */
    gap: 2rem;
    padding: 4rem 2rem 0 2rem;
  }
}

/* Large screens - wider layout with max constraint */
@media (min-width: 64rem) { /* 1024px equivalent */
  .wrapper {
    max-width: 70rem; /* ~1120px equivalent but flexible */
    grid-template-columns: 17rem 1fr; /* ~270px equivalent but flexible */
    gap: 3rem;
  }
}

/* MOBILE LAYOUT - Default mobile-first styles (already defined above) */

/* DESKTOP LAYOUT OVERRIDES */
@media (min-width: 48rem) { /* 768px+ - Tablet and desktop */
  
  /* Show sidebar on desktop, hide on mobile */
  .sidebar.desktop-only {
    display: block !important;
    grid-column: 1 !important;
    position: -webkit-sticky !important;
    position: sticky !important;
    top: 6rem !important;
    height: fit-content !important;
    text-align: left !important;
    padding: 1rem !important;
    border-bottom: none !important;
    margin: 0 !important;
  }
  
  /* Desktop main content positioning */
  main {
    grid-column: 2 !important;
    padding: 1rem !important;
  }
  
  /* Desktop sidebar styling */
  .sidebar.desktop-only header,
  .sidebar header {
    text-align: center !important;
  }
  
  .sidebar.desktop-only .contact-container,
  .sidebar .contact-container {
    display: block !important;
  }
  
  .sidebar.desktop-only hr,
  .sidebar hr {
    display: block !important;
  }
}

/* MOBILE-SPECIFIC STYLES - Applied to mobile screens only */
@media (max-width: 47.99rem) { /* Mobile only - below 768px */
  .sidebar, 
  .sidebar.desktop-only,
  header {
    float: none !important;
    position: static !important;
    width: 100% !important;
    height: auto !important;
    grid-column: 1 !important;
    grid-row: 1 !important;
    text-align: center !important;
    padding: 1rem 0 !important;
    margin: 0 0 1rem 0 !important;
    border-bottom: 1px solid #e5e5e5;
    z-index: auto !important;
  }
}

@media (max-width: 47.99rem) { /* Mobile only - below 768px */
  main,
  section {
    float: none !important;
    position: static !important;
    width: 100% !important;
    height: auto !important;
    grid-column: 1 !important;
    grid-row: 2 !important;
    padding: 0 !important;
    margin: 0 !important;
    border: none !important;
    z-index: auto !important;
  }
}

/* Hide mobile ribbon - use stacked sidebar instead */
.mobile-ribbon.mobile-only {
  display: none !important;
}

/* Compact mobile sidebar styling - mobile only */
@media (max-width: 47.99rem) { /* Mobile only - below 768px */
  .sidebar.desktop-only #profile-pic,
  .sidebar #profile-pic {
    width: 7.5rem !important; /* 120px equivalent but responsive */
    height: 7.5rem !important;
    margin: 0 auto 1rem auto !important;
  }

  .sidebar.desktop-only h1,
  .sidebar h1 {
    font-size: 1.5rem !important; /* 24px equivalent but responsive */
    margin-bottom: 0.5rem !important;
  }

  .sidebar.desktop-only p,
  .sidebar p {
    font-size: 0.875rem !important; /* 14px equivalent but responsive */
    margin-bottom: 0.5rem !important;
  }
}

/* Hide contact details on mobile only for cleaner look */
@media (max-width: 47.99rem) { /* Mobile only - below 768px */
  .sidebar.desktop-only .contact-container,
  .sidebar .contact-container {
    display: none !important;
  }

  .sidebar.desktop-only hr,
  .sidebar hr {
    display: none !important;
  }
}

/* MOBILE-FIRST NAVIGATION */
.navbar nav {
  position: fixed !important;
  z-index: 1000 !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  width: 100% !important;
  background-color: #fff !important;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1) !important;
  padding: 0.75rem 1rem !important;
  display: flex !important;
  justify-content: space-between !important;
  align-items: center !important;
}

/* Mobile navigation improvements */
.navbar nav h3 {
  font-size: 1rem !important;
  margin: 0 !important;
  font-weight: 600 !important;
}

.navbar nav ul {
  display: flex !important;
  list-style: none !important;
  margin: 0 !important;
  padding: 0 !important;
  gap: 0.5rem !important;
}

.navbar nav ul li {
  margin: 0 !important;
}

.navbar nav ul li a {
  display: block !important;
  padding: 0.5rem 0.75rem !important;
  text-decoration: none !important;
  color: #333 !important;
  font-size: 0.875rem !important;
  border-radius: 0.25rem !important;
  transition: background-color 0.2s ease !important;
  min-height: 2.75rem !important; /* Touch-friendly tap target */
  display: flex !important;
  align-items: center !important;
}

.navbar nav ul li a:hover,
.navbar nav ul li a:focus {
  background-color: rgba(0, 0, 0, 0.05) !important;
  text-decoration: none !important;
}

/* Larger screens - more spacing */
@media (min-width: 48rem) {
  .navbar nav {
    padding: 1.25rem 2rem !important;
  }
  
  .navbar nav h3 {
    font-size: 1.125rem !important;
  }
  
  .navbar nav ul {
    gap: 1rem !important;
  }
  
  .navbar nav ul li a {
    font-size: 1rem !important;
    padding: 0.75rem 1rem !important;
  }
}

/* Critical overrides to fix conflicts with style.css */
.wrapper {
  width: 100% !important;
  max-width: 100% !important;
  display: grid !important;
  grid-template-columns: 1fr !important;
  grid-template-rows: auto 1fr !important;
  gap: 1.5rem !important;
  margin: 0 auto !important;
  padding: 4rem 1rem 0 1rem !important;
  min-height: calc(100dvh - 5rem) !important;
}

/* Override old float-based sidebar styles */
.sidebar {
  float: none !important;
  width: auto !important;
  position: -webkit-sticky !important;
  position: sticky !important;
  top: 100px !important;
  grid-column: 1 !important;
  height: fit-content !important;
  padding: 1rem !important;
}

/* Override old float-based main content styles */
section, main {
  float: none !important;
  width: auto !important;
  grid-column: 2 !important;
  padding: 1rem !important;
  max-width: none !important;
  padding-bottom: 50px;
}

/* Global CSS Grid enforcement - overrides ANY float/position conflicts */
.wrapper * {
  box-sizing: border-box;
}

/* Ensure CSS Grid container behavior */
.wrapper {
  display: grid !important;
}

.wrapper > * {
  min-width: 0; /* Prevents grid overflow */
  min-height: 0;
}

/* Override old media query conflicts with mobile-first approach */
@media (min-width: 48rem) {
  .wrapper {
    max-width: 90% !important;
    grid-template-columns: minmax(15rem, 20%) 1fr !important;
    gap: 2rem !important;
    padding: 4rem 2rem 0 2rem !important;
  }
  
  .sidebar {
    float: none !important;
    position: -webkit-sticky !important;
    position: sticky !important;
    width: auto !important;
  }
  
  main {
    float: none !important;
    width: auto !important;
    border: none !important;
    margin: 0 !important;
    padding: 1rem !important;
  }
}

@media (min-width: 64rem) {
  .wrapper {
    max-width: 70rem !important;
    grid-template-columns: 17rem 1fr !important;
    gap: 3rem !important;
  }
}

/* Override header float only when it's not the sidebar */
header:not(.sidebar header) {
  float: none !important;
  position: static !important;
  width: auto !important;
}

/* RESPONSIVE MEDIA CONSTRAINTS - Prevent overflow on mobile */
img, 
video, 
svg, 
canvas, 
iframe,
embed,
object {
  max-width: 100% !important;
  height: auto !important;
  display: block;
}

/* Ensure images in content don't break layout */
main img,
section img,
article img,
.content img {
  max-width: 100% !important;
  height: auto !important;
  width: auto !important;
}

/* Profile picture responsive sizing */
#profile-pic {
  width: 12.5rem; /* ~200px equivalent but responsive */
  max-width: 100%;
  border-radius: 50%;
  margin: 0 auto 1rem;
}

/* Responsive profile picture sizing */
@media (max-width: 48rem) { /* Mobile */
  #profile-pic {
    width: 7.5rem; /* ~120px equivalent but responsive */
  }
}

/* Constrain any embedded content */
iframe,
embed,
object {
  max-width: 100% !important;
  width: 100% !important;
}

/* Responsive video containers */
.video-container {
  position: relative;
  width: 100%;
  height: 0;
  padding-bottom: 56.25%; /* 16:9 aspect ratio */
}

.video-container iframe,
.video-container video {
  position: absolute;
  top: 0;
  left: 0;
  width: 100% !important;
  height: 100% !important;
}

/* Utility classes for responsive visibility */
.desktop-only {
  display: block;
}

.mobile-only {
  display: none;
}

@media (max-width: 768px) {
  .desktop-only {
    display: none !important;
  }
  
  .mobile-only {
    display: block !important;
  }
}

/* ULTRA-HIGH SPECIFICITY OVERRIDES - Must come LAST to override JavaScript-loaded styles */

/* Override sidebar.html font-family conflicts */
html body .wrapper .sidebar,
html body .wrapper .sidebar.desktop-only,
html body .wrapper .sidebar header,
html body .wrapper header {
  font-family: -apple-system, BlinkMacSystemFont, "Roboto", "Segoe UI", "Helvetica Neue", Arial, sans-serif !important;
}

/* Mobile layout overrides with maximum specificity */
@media (max-width: 768px) {
  /* Override ANY potential navbar conflicts */
  html body .navbar nav,
  html body nav[role="navigation"] {
    position: fixed !important;
    z-index: 1000 !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
  }
  
  /* Override ANY potential sidebar conflicts with ultra-high specificity */
  html body .wrapper .sidebar,
  html body .wrapper .sidebar.desktop-only,
  html body .wrapper header,
  html body div.sidebar,
  html body div.sidebar.desktop-only {
    float: none !important;
    position: static !important;
    width: 100% !important;
    height: auto !important;
    top: auto !important;
    left: auto !important;
    right: auto !important;
    bottom: auto !important;
    grid-column: 1 !important;
    grid-row: 1 !important;
    text-align: center !important;
    padding: 1rem 0 !important;
    margin: 0 0 1rem 0 !important;
    z-index: auto !important;
  }
  
  /* Override ANY potential main content conflicts */
  html body .wrapper main,
  html body .wrapper section,
  html body main,
  html body section {
    float: none !important;
    position: static !important;
    width: 100% !important;
    height: auto !important;
    grid-column: 1 !important;
    grid-row: 2 !important;
    padding: 0 !important;
    margin: 0 !important;
    z-index: auto !important;
  }
  
  /* Override positioning conflicts but allow custom display modes for teaching tables */
  html body .wrapper .teaching-table,
  html body .wrapper .comments-table,
  html body .teaching-table,
  html body .comments-table {
    width: 100% !important;
    position: static !important;
    float: none !important;
    /* Remove display: table override to allow mobile card layout */
  }
}

/* RESPONSIVE TABLES AND LONG CONTENT - Prevent horizontal scrolling */

/* Table overflow handling - exclude teaching tables which have custom mobile layout */
table:not(.teaching-table):not(.comments-table) {
  width: 100% !important;
  max-width: 100% !important;
  display: block !important;
  overflow-x: auto !important;
  white-space: nowrap !important;
  -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

/* Reset table display on larger screens */
@media (min-width: 48rem) {
  table:not(.teaching-table):not(.comments-table) {
    display: table !important;
    white-space: normal !important;
  }
}

/* Table cells responsive behavior - exclude teaching tables which have custom mobile layout */
table:not(.teaching-table):not(.comments-table) th,
table:not(.teaching-table):not(.comments-table) td {
  padding: 0.5rem !important;
  text-align: left !important;
  vertical-align: top !important;
  word-wrap: break-word !important;
  overflow-wrap: anywhere !important;
  max-width: 15rem !important; /* Prevent extremely wide cells */
}

/* Specific table classes - Allow teaching.html to handle its own mobile layout */
.teaching-table,
.comments-table {
  width: 100% !important;
  border-collapse: collapse !important;
  margin-bottom: 1rem !important;
  /* Remove conflicting display rules - let teaching.html handle mobile layout */
}

@media (min-width: 48rem) {
  .teaching-table,
  .comments-table {
    display: table !important;
  }
}

/* Long content handling */
pre {
  white-space: pre-wrap !important;
  word-wrap: break-word !important;
  overflow-wrap: anywhere !important;
  overflow-x: auto !important;
  max-width: 100% !important;
}

code {
  word-wrap: break-word !important;
  overflow-wrap: anywhere !important;
}

/* Long URLs and unbreakable content */
.content,
main,
section,
article {
  overflow-wrap: anywhere !important;
  word-break: break-word !important;
  hyphens: auto !important;
}

/* Long URL handling */
a {
  overflow-wrap: break-word !important;
  word-break: break-all !important;
}

/* Prevent code blocks from overflowing */
pre code {
  display: block !important;
  overflow-x: auto !important;
  white-space: pre !important;
  word-wrap: normal !important;
}

/* ABSOLUTE/FIXED POSITIONING FIXES - Prevent mobile layout conflicts */

/* Remove any stray overflow:hidden that could trap scroll */
html,
body {
  overflow-x: auto !important;
  overflow-y: auto !important;
}

/* Ensure proper spacing for fixed navbar */
body {
  margin: 0 !important;
  padding: 0 !important;
}

/* Prevent any floating elements from interfering */
* {
  box-sizing: border-box !important;
}

/* Reset any problematic positioning */
.wrapper > *:not(.navbar) {
  position: static !important;
  float: none !important;
}

/* Only allow fixed positioning for navbar */
.navbar nav {
  /* Already defined above - this is the only allowed fixed element */
}

/* Ensure adequate spacing below fixed navbar */
@media (max-width: 48rem) {
  .wrapper {
    padding-top: 3rem !important; /* Ensure enough space for smaller mobile navbar */
  }
}

@media (min-width: 48rem) {
  .wrapper {
    padding-top: 4rem !important; /* More space for larger desktop navbar */
  }
}

/* Force normal document flow for all content */
main,
section,
article,
.content {
  position: static !important;
  clear: both !important;
  width: 100% !important;
  max-width: 100% !important;
}

/* Paper title styling - prevent word breaks on desktop */
.paper-title {
  hyphens: manual !important;
  word-break: keep-all !important;
  overflow-wrap: normal !important;
}

.paper-title a {
  hyphens: manual !important;
  word-break: keep-all !important;
  overflow-wrap: normal !important;
}

/* Allow word breaks on mobile for better layout */
@media (max-width: 47.99rem) {
  .paper-title {
    hyphens: auto !important;
    word-break: normal !important;
    overflow-wrap: break-word !important;
  }
  
  .paper-title a {
    hyphens: auto !important;
    word-break: normal !important;
    overflow-wrap: break-word !important;
  }
}