/* =========================================
   1. VARIABLES & THEME SETTINGS
   ========================================= */
:root {
  --background: white;
  --textcolor: black;
  --linkcolor: blue;
  --menubackground: lightgrey;
  --navbar-height: 40px;
  
  /* PARAMETER: Full Sidebar Width */
  --quarto-sidebar-width: 235px; 
  
  /* PARAMETER: Mini (Collapsed) Sidebar Width */
  --quarto-sidebar-mini-width: 60px;
}

/* =========================================
   2. GLOBAL TYPOGRAPHY & LAYOUT
   ========================================= */
body {
  padding: 0;
  margin: 0;
  margin-top: 30px; 
  background: var(--background);
  font-family: Helvetica, Arial, sans-serif;
  font-size: 16px;
  font-weight: normal;
  color: var(--textcolor);
  line-height: 1.5em;
  text-align: justify;
}

/* Kill Quarto's stubborn background grid system globally */
.page-columns, 
.page-layout-article,
.quarto-container {
  display: block !important;
  grid-template-columns: none !important;
}

main.content, 
#quarto-content {
  padding-right: 2rem;
  padding-left: 2rem; 
  padding-bottom: 60px;
  box-sizing: border-box !important;
}

p { margin: 0.2em 0; }

a {
  color: #007bff;
  text-decoration: none;
}
a:hover { text-decoration: underline; }

/* =========================================
   3. HEADINGS
   ========================================= */
h1 { font-size: 2em; font-weight: bold; }

h2 {
  padding-top: 20px;
  font-size: 1.5em;
  font-weight: bold;
  border-bottom: 2px solid blue;
  padding-bottom: 5px;
}

h3 { font-size: 1.2em; font-weight: bold; }

h2.anchored, h3.anchored, h4.anchored, h5.anchored, h6.anchored {
  display: flex;
  align-items: baseline;
  gap: .4em;
  flex-wrap: nowrap;
  white-space: normal;
  overflow-wrap: anywhere;
}
h2 .header-section-number, h3 .header-section-number { flex: 0 0 auto; }
h2.anchored .anchorjs-link, h3.anchored .anchorjs-link { margin-left: auto; flex: 0 0 auto; }

/* =========================================
   4. LISTS & NUMBERING (Scoped to Main Content)
   ========================================= */
#quarto-content ol {
  margin: 0.2em 0;
  padding-left: 1.5em;
  list-style-type: none;
}

#quarto-content ul {
  margin: 0.2em 0;
  padding-left: 1.5em;
}

#quarto-content ol > li::marker {
  content: "(" counter(list-item) ") ";
  font-weight: bold;
}

#quarto-content ol ol > li::marker {
  content: "(" counter(list-item, lower-alpha) ") ";
  font-weight: normal;
}

/* =========================================
   5. IMAGES & RESPONSIVENESS
   ========================================= */
main img:not(.logo),
.contents img:not(.logo),
#main img:not(.logo) {
  max-width: 100% !important;
  width: 90% !important;
  height: auto;
  margin: 1em auto;
  display: block;
}

.navbar .logo, .navbar-brand img,
.col-md-3 img, .sidebar img {
  width: auto !important;
  max-width: 100% !important;
  display: inline-block;
}

figcaption, caption { text-align: center; }

/* =========================================
   6. BUTTONS
   ========================================= */
.btn {
  color: royalblue;
  font-weight: bold;
  font-size: 1.1rem;
  background-color: var(--menubackground);
  border: 0;
  border-radius: 5px;
  padding: 5px 10px;
  min-width: 50px;
  text-align: center;
  cursor: pointer;
}
.btn:hover {
  color: var(--linkcolor);
  background-color: var(--background);
  text-decoration: underline;
}
.btn.active { color: var(--linkcolor); }

.button {
  color: black;
  border: 0;
  padding: 5px;
  background-color: lightgrey;
  border-radius: 5px;
  font-weight: bold;
  font-size: 0.8rem;
  min-width: 100px;
}
.button:hover {
  color: var(--linkcolor);
  text-decoration: underline;
  background-color: lightcyan;
}

/* =========================================
   7. SIDEBAR STYLING (GLOBAL COLORS)
   ========================================= */
#quarto-sidebar {
  background-color: #f0f4f8 !important; 
  border-right: 1px solid #dbe2e8 !important;
}

#quarto-sidebar .sidebar-link,
#quarto-sidebar .sidebar-title {
  color: #485663 !important; 
  text-align: left !important;
}

#quarto-sidebar .sidebar-link:hover,
ul.injected-page-toc a:hover {
  color: #2c3e50 !important;
}

#quarto-sidebar .sidebar-link.active {
  color: #007bff !important;
  background-color: transparent !important;
  font-weight: 800 !important;
}

ul.injected-page-toc a.toc-active {
  color: #0056b3 !important;       
  font-weight: 600 !important;     
  border-left: 3px solid #007bff;  
  padding-left: 8px;               
  background-color: rgba(0, 123, 255, 0.05); 
}

/* =========================================
   8. TOC MERGING & LAYOUT LOGIC (DESKTOP)
   ========================================= */
@media (min-width: 992px) {
  nav[role="doc-toc"],
  #quarto-margin-sidebar,
  .quarto-secondary-nav .toc {
      position: fixed; 
      left: -9999px;
      top: -9999px;
      width: 0; height: 0;
      overflow: hidden; visibility: hidden;
  }

  .sidebar-item-toggle { display: none !important; }

  #quarto-sidebar .sidebar-menu-container {
    opacity: 0;
    transition: opacity 0.2s ease-in;
  }
  
  #quarto-sidebar .sidebar-menu-container.loaded { opacity: 1; }

  #quarto-sidebar .sidebar-menu-container > ul {
    padding-left: 0 !important;
    margin-left: 0 !important;
    list-style: none !important;
  }

  #quarto-sidebar .sidebar-item-container { 
    padding-left: 0 !important; 
  }

  ul.injected-page-toc, ul.injected-page-toc ul {
    list-style: none !important;
    padding-left: 0 !important;
    margin-left: 0 !important;
  }

  ul.injected-page-toc {
    padding-left: 12px !important; 
    border-left: 1px solid #dee2e6;
    margin-left: 1.0em !important; 
    margin-top: 5px !important;
    margin-bottom: 10px !important;
  }
  ul.injected-page-toc ul { padding-left: 15px !important; }

  #quarto-sidebar .sidebar-link,
  ul.injected-page-toc a {
    display: flex !important;
    align-items: baseline;
    text-decoration: none !important;
    color: #6c757d;
    padding: 6px 0;
    border: none !important;
    width: 100%;
    position: relative;
    transition: all 0.2s ease;
    text-align: left; 
  }

  #quarto-sidebar .sidebar-link .menu-text { display: flex; width: 100%; text-align: left; }

  .toc-num {
    flex: 0 0 auto;
    min-width: 1.8em;
    padding-right: 0.5em;
    font-weight: 500;
    text-align: left; 
    margin-right: 5px;
  }
  
  .toc-text { 
    flex: 1 1 auto; 
    display: block; 
    text-align: left; 
  }

  a.has-children::after {
    content: "›"; 
    display: inline-block;
    margin-left: auto;
    margin-right: 5px;
    font-weight: bold;
    font-family: monospace; 
    transform: rotate(90deg);
    transition: transform 0.2s ease;
    color: #adb5bd;
  }
  a.has-children.collapsed::after { transform: rotate(0deg); }
}

/* =========================================
   9. CUSTOM LAYOUT: RESPONSIVE BEHAVIOR
   ========================================= */

/* --- A. SMALL SCREENS (< 992px) --- */
@media (max-width: 991.98px) {
  /* Maintain true horizontal centering for text */
  #quarto-content {
    display: flex !important;
    justify-content: center !important;
    width: 100% !important;
    margin-left: 0 !important;
  }
  
  main.content {
    display: block !important;
    width: 100% !important;
    padding-top: 1rem !important;
    margin: 0 !important;
  }
  
  /* EXPLICITLY HIDE CUSTOM TOGGLE ON MOBILE */
  #custom-sidebar-toggle {
    display: none !important;
  }
  
  /* Quarto's native mobile navigation handles the rest! */
}

/* --- B. DESKTOP SCREENS (992px+) --- */
@media (min-width: 992px) {
  
  /* Force Flexbox centering on the parent container */
  #quarto-content {
    display: flex !important;
    justify-content: center !important; 
    align-items: flex-start !important; 
    transition: margin-left 0.3s ease, width 0.3s ease;
  }

  /* Constrain main text width */
  main.content {
    width: 100% !important;
    max-width: 900px !important; 
    margin: 0 !important; 
    padding-top: 2rem !important;
    padding-bottom: 4rem !important;
  }

  /* Desktop sidebar fixed positioning */
  #quarto-sidebar {
    position: fixed !important;
    padding: 60px 10px 20px 10px !important;
    top: 0 !important;
    bottom: 0 !important;
    height: 100vh !important;
    z-index: 1100 !important;
    overflow-x: hidden !important; 
    overflow-y: auto !important;
    transition: all 0.3s ease;
    left: 0 !important; 
  }

  /* --- DEFAULT STATE: ALWAYS OPEN --- */
  body:not(.sidebar-closed) #quarto-sidebar {
    width: var(--quarto-sidebar-width) !important;
    box-shadow: none !important;
  }

  body:not(.sidebar-closed) #quarto-content {
    margin-left: var(--quarto-sidebar-width) !important;
    width: calc(100% - var(--quarto-sidebar-width)) !important; 
  }

  body:not(.sidebar-closed) #quarto-sidebar .sidebar-menu-container,
  body:not(.sidebar-closed) #quarto-sidebar .sidebar-title,
  body:not(.sidebar-closed) #quarto-sidebar .sidebar-header {
    opacity: 1 !important; 
    visibility: visible !important;
  }

  /* --- TOGGLED STATE: CLOSED / MINI --- */
  body.sidebar-closed #quarto-sidebar {
    width: var(--quarto-sidebar-mini-width) !important;
  }

  body.sidebar-closed #quarto-content {
    margin-left: var(--quarto-sidebar-mini-width) !important;
    width: calc(100% - var(--quarto-sidebar-mini-width)) !important;
  }

  body.sidebar-closed #quarto-sidebar .sidebar-menu-container,
  body.sidebar-closed #quarto-sidebar .sidebar-title,
  body.sidebar-closed #quarto-sidebar .sidebar-header {
     opacity: 0 !important;
     visibility: hidden !important;
  }
}

/* =========================================
   10. THE HAMBURGER TOGGLE BUTTON
   ========================================= */
#custom-sidebar-toggle {
  position: fixed;
  top: 5px;
  left: 7px;
  z-index: 1200; 
  display: flex; /* Will be overridden to 'none' on mobile via media query above */
  align-items: center;
  justify-content: center;
  width: 45px;
  height: 45px;
  border-radius: 50%;
  background-color: rgba(255,255,255, 0.7); 
  border: 1px solid transparent;
  color: #6c757d;
  font-size: 30px;
  cursor: pointer;
  transition: all 0.2s ease;
}

#custom-sidebar-toggle:hover {
  color: #007bff;
  background-color: rgba(255,255,255, 0.95);
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
  border: 1px solid #cccfd2;
}

/* =========================================
   11. HIDE QUARTO PAGE NAVIGATION (PREV/NEXT)
   ========================================= */
.page-navigation, 
.nav-page, 
.quarto-page-navigation,
.margin-nav {
  display: none !important;
  width: 0 !important;
  height: 0 !important;
  visibility: hidden !important;
}

#quarto-margin-sidebar {
  display: none !important;
}
