/* =============================================================================
   Accessibility CSS - Party Onbici
   WCAG 2.1 AA compliant focus indicators and accessibility enhancements
   ============================================================================= */

/* =============================================================================
   1. FOCUS INDICATORS (WCAG 2.4.7 - Focus Visible)
   High-contrast focus rings for keyboard navigation
   ============================================================================= */

/* Global focus indicator - enhanced visibility */
:focus-visible {
  outline: 3px solid #e03537 !important;  /* Party Onbici brand red */
  outline-offset: 2px !important;
  box-shadow: 0 0 0 4px rgba(224, 53, 55, 0.25) !important;
}

/* Ensure focus is visible on all interactive elements */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[role="button"]:focus-visible,
[role="link"]:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid #e03537 !important;
  outline-offset: 2px !important;
  box-shadow: 0 0 0 4px rgba(224, 53, 55, 0.25) !important;
}

/* Dark mode focus indicators */
[data-bs-theme="dark"] :focus-visible,
[data-bs-theme="dark"] a:focus-visible,
[data-bs-theme="dark"] button:focus-visible,
[data-bs-theme="dark"] input:focus-visible,
[data-bs-theme="dark"] select:focus-visible,
[data-bs-theme="dark"] textarea:focus-visible {
  outline-color: #ff6b6b !important;
  box-shadow: 0 0 0 4px rgba(255, 107, 107, 0.3) !important;
}

/* Bootstrap dropdown items focus */
.dropdown-item:focus-visible,
.dropdown-toggle:focus-visible {
  outline: 3px solid #e03537 !important;
  outline-offset: -2px !important;
  background-color: rgba(224, 53, 55, 0.1) !important;
}

/* Navbar links focus */
.navbar .nav-link:focus-visible {
  outline: 3px solid #e03537 !important;
  outline-offset: 2px !important;
  border-radius: 4px !important;
}

/* Fix theme's dropdown caret icons: theme.min.css references Feather font
   glyphs (\e931, \e930, \e92f) which are not loaded. Override with correct
   Bootstrap Icons code points. */
.dropup .dropdown-toggle::after {
  content: "\f286" !important; /* bi-chevron-up */
  font-family: bootstrap-icons !important;
}
.dropend .dropdown-toggle::after {
  content: "\f285" !important; /* bi-chevron-right */
  font-family: bootstrap-icons !important;
}
.dropstart .dropdown-toggle::before {
  content: "\f284" !important; /* bi-chevron-left */
  font-family: bootstrap-icons !important;
}

/* Prevent navbar dropdown toggles from wrapping caret to new line */
.navbar .nav-link.dropdown-toggle,
.navbar .btn.dropdown-toggle {
  white-space: nowrap !important;
  display: inline-flex !important;
  align-items: center !important;
  flex-wrap: nowrap !important;
}
/* Ensure caret stays inline */
.navbar .nav-link.dropdown-toggle::after,
.navbar .btn.dropdown-toggle::after {
  flex-shrink: 0 !important;
  margin-left: 0.255em !important;
}

/* Button focus states - Bootstrap override */
.btn:focus-visible {
  outline: 3px solid #e03537 !important;
  outline-offset: 2px !important;
  box-shadow: 0 0 0 4px rgba(224, 53, 55, 0.25) !important;
}

/* Form control focus - enhance Bootstrap defaults */
.form-control:focus-visible,
.form-select:focus-visible {
  outline: none !important;
  border-color: #e03537 !important;
  box-shadow: 0 0 0 3px rgba(224, 53, 55, 0.25) !important;
}

/* Checkbox and radio focus */
.form-check-input:focus-visible {
  outline: 3px solid #e03537 !important;
  outline-offset: 2px !important;
  box-shadow: 0 0 0 4px rgba(224, 53, 55, 0.25) !important;
}

/* Card and modal close button focus */
.btn-close:focus-visible {
  outline: 3px solid #e03537 !important;
  outline-offset: 2px !important;
  box-shadow: 0 0 0 4px rgba(224, 53, 55, 0.25) !important;
  opacity: 1 !important;
}

/* Footer social links focus */
.footer_social a:focus-visible {
  outline: 3px solid #e03537 !important;
  outline-offset: 4px !important;
  border-radius: 50% !important;
}

/* =============================================================================
   2. SKIP LINKS (WCAG 2.4.1 - Bypass Blocks)
   ============================================================================= */

/* Skip link - visible on focus */
.skip-link {
  position: absolute !important;
  top: -40px !important;
  left: 0 !important;
  background: #e03537 !important;
  color: #fff !important;
  padding: 8px 16px !important;
  z-index: 9999 !important;
  text-decoration: none !important;
  font-weight: 600 !important;
  border-radius: 0 0 4px 0 !important;
  transition: top 0.2s ease !important;
}

.skip-link:focus,
.skip-link:focus-visible {
  top: 0 !important;
  outline: 3px solid #fff !important;
  outline-offset: -3px !important;
}

/* Stack multiple skip links vertically */
.skip-link + .skip-link:focus,
.skip-link + .skip-link:focus-visible {
  top: 36px !important;
}

/* =============================================================================
   3. REDUCED MOTION (WCAG 2.3.3 - Animation from Interactions)
   ============================================================================= */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* =============================================================================
   4. HIGH CONTRAST MODE SUPPORT
   ============================================================================= */

@media (forced-colors: active) {
  :focus-visible {
    outline: 3px solid CanvasText !important;
    outline-offset: 2px !important;
  }

  a:focus-visible,
  button:focus-visible {
    outline: 3px solid LinkText !important;
  }
}

/* =============================================================================
   5. SCREEN READER ONLY UTILITIES
   ============================================================================= */

/* Bootstrap's sr-only equivalent - for older templates */
.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* Show on focus for skip links */
.sr-only-focusable:focus,
.sr-only-focusable:focus-visible {
  position: absolute !important;
  width: auto !important;
  height: auto !important;
  padding: 8px 16px !important;
  margin: 0 !important;
  overflow: visible !important;
  clip: auto !important;
  white-space: normal !important;
}

/* =============================================================================
   6. TOUCH TARGET SIZE (WCAG 2.5.5 - Target Size)
   Minimum 44x44px touch targets
   ============================================================================= */

@media (pointer: coarse) {
  /* Ensure minimum touch target size on touch devices */
  a,
  button,
  .btn,
  .nav-link,
  .dropdown-item,
  input[type="checkbox"],
  input[type="radio"] {
    min-height: 44px;
    min-width: 44px;
  }

  /* Dropdown items need more padding on touch */
  .dropdown-item {
    padding: 12px 16px;
  }
}

/* =============================================================================
   7. TEXT SPACING (WCAG 1.4.12 - Text Spacing)
   Support for user text spacing preferences
   ============================================================================= */

/* Ensure content doesn't break with increased text spacing */
body {
  line-height: 1.5;
  letter-spacing: normal;
  word-spacing: normal;
}

/* Allow text to reflow properly */
p, li, dd, dt {
  max-width: 100%;
  overflow-wrap: break-word;
  word-wrap: break-word;
  hyphens: auto;
}

/* =============================================================================
   8. LINK DISTINGUISHABILITY (WCAG 1.4.1 - Use of Color)
   ============================================================================= */

/* Ensure links are distinguishable by more than color throughout the site */
a:not(.btn):not(.nav-link):not(.navbar-brand):not(.dropdown-item):not(.dropdown-toggle):not(.text-reset):not(.partner-logo):not(.js-go-to):not(.skip-link):not(.text-inverse) {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

a:not(.btn):not(.nav-link):not(.navbar-brand):not(.dropdown-item):not(.dropdown-toggle):not(.text-reset):not(.partner-logo):not(.js-go-to):not(.skip-link):not(.text-inverse):hover {
  text-decoration-thickness: 2px;
}

/* =============================================================================
   9. FORM ERROR STATES (WCAG 3.3.1 - Error Identification)
   ============================================================================= */

/* Ensure form errors are visible with more than just color */
.is-invalid,
.form-control.is-invalid,
.form-select.is-invalid {
  border-width: 2px !important;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' width='12' height='12' fill='none' stroke='%23dc3545'%3e%3ccircle cx='6' cy='6' r='4.5'/%3e%3cpath stroke-linejoin='round' d='M5.8 3.6h.4L6 6.5z'/%3e%3ccircle cx='6' cy='8.2' r='.6' fill='%23dc3545' stroke='none'/%3e%3c/svg%3e") !important;
  background-repeat: no-repeat !important;
  background-position: right calc(0.375em + 0.1875rem) center !important;
  background-size: calc(0.75em + 0.375rem) calc(0.75em + 0.375rem) !important;
  padding-right: calc(1.5em + 0.75rem) !important;
}

/* Error message styling */
.invalid-feedback {
  font-weight: 500;
}

/* =============================================================================
   10. MODAL ACCESSIBILITY ENHANCEMENTS
   ============================================================================= */

/* Ensure modals trap focus properly */
.modal[aria-modal="true"] {
  /* Additional styling if needed */
}

/* Modal backdrop - increased opacity for better visual contrast (WCAG) */
/* Bootstrap default is 0.5; using 0.7 for stronger content separation */
.modal-backdrop.show {
  opacity: 0.7;
}

/* =============================================================================
   11. COLOR CONTRAST FIXES (WCAG 1.4.3 - Contrast Minimum)
   Ensure 4.5:1 contrast ratio for normal text
   ============================================================================= */

/* Footer text-body-secondary needs higher contrast against dark background (#0f0f0f) */
/* Original #4f5b6c has 2.77 ratio, #9ca3af provides 5.3:1 ratio */
/* Using higher specificity to override global rules */
footer .text-body-secondary,
footer p.text-body-secondary,
footer div.text-body-secondary,
footer span.text-body-secondary,
footer .text-body-secondary a {
  color: #9ca3af !important;
}

/* Ensure links in footer secondary text have sufficient contrast */
footer .text-body-secondary a:hover {
  color: #d1d5db !important;
}

/* Global text-body-secondary fix for light backgrounds */
/* Bootstrap's default #6c757d has ~4.5:1 but theme overrides may reduce it */
/* Using #595959 for reliable 7:1 contrast ratio */
.text-body-secondary,
div.text-body-secondary,
p.text-body-secondary,
span.text-body-secondary {
  color: #595959 !important;
}

/* Dark mode: lighter secondary text for dark backgrounds */
[data-bs-theme="dark"] .text-body-secondary,
[data-bs-theme="dark"] div.text-body-secondary,
[data-bs-theme="dark"] p.text-body-secondary,
[data-bs-theme="dark"] span.text-body-secondary {
  color: #9ca3af !important;
}

/* Bootstrap text-warning has poor contrast (1.32-1.63) on white */
/* Using #8a5700 (darker gold) for 5.2:1 contrast on white */
.text-warning,
span.text-warning,
div.text-warning {
  color: #8a5700 !important;
}

/* Dark mode: original warning color is fine on dark backgrounds */
[data-bs-theme="dark"] .text-warning,
[data-bs-theme="dark"] span.text-warning,
[data-bs-theme="dark"] div.text-warning {
  color: #ffc107 !important;
}

/* Bootstrap text-success barely fails (4.16) - needs slight darkening */
/* Using #006644 for 5.8:1 contrast ratio */
.text-success,
span.text-success,
div.text-success {
  color: #006644 !important;
}

/* Dark mode: lighter green for dark backgrounds */
[data-bs-theme="dark"] .text-success,
[data-bs-theme="dark"] span.text-success,
[data-bs-theme="dark"] div.text-success {
  color: #20c997 !important;
}

/* btn-primary has 4.43 contrast - needs slight adjustment for AAA */
/* Using #0052cc for 4.68:1 contrast */
.btn-primary,
a.btn-primary {
  background-color: #0052cc !important;
  border-color: #0052cc !important;
}

.btn-primary:hover,
a.btn-primary:hover {
  background-color: #003d99 !important;
  border-color: #003d99 !important;
}

/* btn-outline-primary text needs adjustment */
.btn-outline-primary {
  color: #0052cc !important;
  border-color: #0052cc !important;
}

.btn-outline-primary:hover {
  background-color: #0052cc !important;
  border-color: #0052cc !important;
  color: #fff !important;
}

/* Party details list text (ul.list-unstyled spans) */
/* Theme uses #647486 which has 4.34 contrast - need darker */
.card-body ul.list-unstyled li span {
  color: #4a5568 !important;
}

[data-bs-theme="dark"] .card-body ul.list-unstyled li span {
  color: #9ca3af !important;
}

/* Footer always has dark background (#0f0f0f) regardless of theme mode */
/* All footer text needs light colors for sufficient contrast */
footer {
  background-color: #0f0f0f !important;
}

/* Footer headings (p.h4) - need light text on dark background */
footer p.h4,
footer .h4 {
  color: #e5e7eb !important;
}

/* Footer text-reset links - need light text on dark background */
/* Using #d1d5db for 10.8:1 contrast ratio on #0f0f0f */
footer a.text-reset,
footer .text-reset {
  color: #d1d5db !important;
}

footer a.text-reset:hover,
footer .text-reset:hover {
  color: #f3f4f6 !important;
}

/* Footer text-body-secondary already handled above with #9ca3af */

/* Elevation stats secondary color fix */
.elevation-stats,
.elevation-stats .elevation-stat span {
  color: #595959 !important;
}

[data-bs-theme="dark"] .elevation-stats,
[data-bs-theme="dark"] .elevation-stats .elevation-stat span {
  color: #9ca3af !important;
}

/* Health index cards text fix */
.health-index-card .small.fw-medium {
  color: #595959 !important;
}

[data-bs-theme="dark"] .health-index-card .small.fw-medium {
  color: #9ca3af !important;
}

/* Detail content paragraphs (party details sidebar) */
.detail-content p {
  color: #595959 !important;
}

[data-bs-theme="dark"] .detail-content p {
  color: #9ca3af !important;
}

/* btn-outline-light on light backgrounds has terrible contrast (1.09) */
/* Add visible border and darker text */
.btn-outline-light {
  color: #495057 !important;
  border-color: #6c757d !important;
}

.btn-outline-light:hover {
  color: #212529 !important;
  background-color: #e9ecef !important;
  border-color: #6c757d !important;
}

/* Footer btn-outline-light needs light text (footer always has dark bg) */
footer .btn-outline-light {
  color: #f8f9fa !important;
  border-color: #9ca3af !important;
}

footer .btn-outline-light:hover {
  color: #212529 !important;
  background-color: #f8f9fa !important;
  border-color: #f8f9fa !important;
}

/* Dark mode: restore original light outline button style */
[data-bs-theme="dark"] .btn-outline-light {
  color: #f8f9fa !important;
  border-color: #f8f9fa !important;
}

[data-bs-theme="dark"] .btn-outline-light:hover {
  color: #212529 !important;
  background-color: #f8f9fa !important;
  border-color: #f8f9fa !important;
}

/* =============================================================================
   12. BTN-OUTLINE-SECONDARY CONTRAST FIX
   Theme overrides make secondary text nearly invisible on light backgrounds
   ============================================================================= */

/* Light mode: btn-outline-secondary needs visible text and border */
.btn-outline-secondary {
  color: #495057 !important;
  border-color: #6c757d !important;
}

.btn-outline-secondary:hover {
  color: #212529 !important;
  background-color: #e9ecef !important;
  border-color: #6c757d !important;
}

/* Dark mode: restore lighter colors for dark backgrounds */
[data-bs-theme="dark"] .btn-outline-secondary {
  color: #adb5bd !important;
  border-color: #6c757d !important;
}

[data-bs-theme="dark"] .btn-outline-secondary:hover {
  color: #f8f9fa !important;
  background-color: #495057 !important;
  border-color: #adb5bd !important;
}

/* =============================================================================
   13. FRONT CHAT WIDGET ACCESSIBILITY (Third-party widget)
   Note: Internal iframe styling must be configured in Front's dashboard
   ============================================================================= */

/* Front Chat launcher button - ensure focus visibility */
#front-chat-container,
#front-chat-iframe,
[id^="fc-"] {
  /* Ensure widget doesn't interfere with page focus order */
}

/* Front Chat launcher focus state */
#front-chat-container button:focus-visible,
[id^="fc-"] button:focus-visible {
  outline: 3px solid #e03537 !important;
  outline-offset: 2px !important;
  box-shadow: 0 0 0 4px rgba(224, 53, 55, 0.25) !important;
}

/* Ensure Front Chat widget respects reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
  #front-chat-container,
  #front-chat-container *,
  [id^="fc-"],
  [id^="fc-"] * {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* Front Chat widget minimum touch target size */
@media (pointer: coarse) {
  #front-chat-container button,
  [id^="fc-"] button {
    min-height: 44px !important;
    min-width: 44px !important;
  }
}

/* =============================================================================
   14. CHAT WIDGET & SCROLL-TO-TOP LIGHT/DARK MODE
   Custom floating buttons should adapt to current theme
   ============================================================================= */

/* Light mode: use light background with subtle shadow */
.front-chat-launcher,
.btn-scroll-top {
  background-color: #ffffff !important;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15), inset 0 0 0 2px rgba(224, 53, 55, 0.3) !important;
}

.front-chat-launcher:hover,
.btn-scroll-top:hover {
  background-color: #f8f9fa !important;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2), inset 0 0 0 2px rgba(224, 53, 55, 0.5) !important;
}

/* Dark mode: use dark background */
[data-bs-theme="dark"] .front-chat-launcher,
[data-bs-theme="dark"] .btn-scroll-top {
  background-color: #1a1a2e !important;
  box-shadow: inset 0 0 0 2px rgba(224, 53, 55, 0.3) !important;
}

[data-bs-theme="dark"] .front-chat-launcher:hover,
[data-bs-theme="dark"] .btn-scroll-top:hover {
  background-color: #252542 !important;
  box-shadow: inset 0 0 0 2px rgba(224, 53, 55, 0.5) !important;
}

/* Also support system preference when no explicit theme is set */
@media (prefers-color-scheme: dark) {
  :root:not([data-bs-theme="light"]) .front-chat-launcher,
  :root:not([data-bs-theme="light"]) .btn-scroll-top {
    background-color: #1a1a2e !important;
    box-shadow: inset 0 0 0 2px rgba(224, 53, 55, 0.3) !important;
  }

  :root:not([data-bs-theme="light"]) .front-chat-launcher:hover,
  :root:not([data-bs-theme="light"]) .btn-scroll-top:hover {
    background-color: #252542 !important;
    box-shadow: inset 0 0 0 2px rgba(224, 53, 55, 0.5) !important;
  }
}

/* =============================================================================
   15. AUTH PAGES DARK MODE FIX
   Ensure auth pages (login, logout, signup) properly adapt to dark mode
   ============================================================================= */

/* Dark mode: bg-light should use darker background */
[data-bs-theme="dark"] .bg-light {
  background-color: var(--bs-secondary-bg, #343a40) !important;
}

/* Dark mode: text-muted should be readable */
[data-bs-theme="dark"] .text-muted {
  color: #9ca3af !important;
}

/* Dark mode: form-text (help text) should be readable */
[data-bs-theme="dark"] .form-text {
  color: #adb5bd !important;
}

/* Dark mode: ensure auth page body and containers have dark background */
[data-bs-theme="dark"] body {
  background-color: var(--bs-body-bg, #212529) !important;
}

/* Dark mode: icons in bg-light circles should be lighter */
[data-bs-theme="dark"] .bg-light .text-muted,
[data-bs-theme="dark"] .bg-light svg {
  color: #adb5bd !important;
}

/* =============================================================================
   16. DARK MODE LINK COLOR FIX
   Blue links are unreadable on dark backgrounds - use lighter blue
   ============================================================================= */

/* Dark mode: all links should use a lighter, more readable blue */
[data-bs-theme="dark"] a:not(.btn):not(.nav-link):not(.navbar-brand):not(.dropdown-item):not(.text-reset):not(.text-primary):not(.text-danger):not(.text-white) {
  color: #6ea8fe !important;
}

[data-bs-theme="dark"] a:not(.btn):not(.nav-link):not(.navbar-brand):not(.dropdown-item):not(.text-reset):not(.text-primary):not(.text-danger):not(.text-white):hover {
  color: #9ec5fe !important;
}

/* Dark mode: text-primary links should also be lighter */
[data-bs-theme="dark"] .text-primary,
[data-bs-theme="dark"] a.text-primary {
  color: #6ea8fe !important;
}

[data-bs-theme="dark"] a.text-primary:hover {
  color: #9ec5fe !important;
}

/* Dark mode: btn-outline-primary needs readable text */
[data-bs-theme="dark"] .btn-outline-primary {
  color: #6ea8fe !important;
  border-color: #6ea8fe !important;
}

[data-bs-theme="dark"] .btn-outline-primary:hover {
  background-color: #6ea8fe !important;
  border-color: #6ea8fe !important;
  color: #000 !important;
}

/* Dark mode: btn-link should also use lighter blue */
[data-bs-theme="dark"] .btn-link {
  color: #6ea8fe !important;
}

[data-bs-theme="dark"] .btn-link:hover {
  color: #9ec5fe !important;
}

/* =============================================================================
   17a. OFFCANVAS MOBILE NAV WIDTH
   Full-width on mobile, constrained on larger screens
   ============================================================================= */

.offcanvas-nav {
  width: 100% !important;
}

@media (min-width: 576px) {
  .offcanvas-nav {
    width: 20rem !important;
  }
}

/* =============================================================================
   17. NAVBAR HAMBURGER ICON VISIBILITY FIX
   Ensure mobile menu toggle icon is visible on dark navbar backgrounds
   ============================================================================= */

/* Dark navbar (e.g., homepage hero): hamburger icon and border should be white */
.navbar-dark .offcanvas-nav-btn,
.navbar-dark .offcanvas-nav-btn .bi,
.navbar-dark .offcanvas-nav-btn i {
  color: #fff !important;
}

.navbar-dark .offcanvas-nav-btn {
  border: 1px solid rgba(255, 255, 255, 0.5) !important;
  border-radius: 0.375rem;
  padding: 0.25rem 0.5rem;
}

.navbar-dark .offcanvas-nav-btn:hover {
  border-color: #fff !important;
  background-color: rgba(255, 255, 255, 0.1) !important;
}

/* When navbar becomes fixed/sticky on scroll, icon and border should be dark */
.navbar-dark.navbar-stick .offcanvas-nav-btn,
.navbar-dark.navbar-stick .offcanvas-nav-btn .bi,
.navbar-dark.navbar-stick .offcanvas-nav-btn i {
  color: #212529 !important;
}

.navbar-dark.navbar-stick .offcanvas-nav-btn {
  border-color: rgba(33, 37, 41, 0.5) !important;
}

.navbar-dark.navbar-stick .offcanvas-nav-btn:hover {
  border-color: #212529 !important;
  background-color: rgba(0, 0, 0, 0.05) !important;
}

/* ============================================================================
   Print Styles
   Ensures policy pages, party details, and route pages print cleanly
   ============================================================================ */

@media print {
  /* Hide non-essential UI elements */
  header,
  footer,
  nav,
  .navbar,
  .skip-link,
  .btn,
  .form-check,
  .offcanvas,
  .toast-container,
  .cookie-consent-banner,
  #cc_modal_window,
  .back-to-top {
    display: none !important;
  }

  /* Ensure readable text on white background */
  body {
    color: #000 !important;
    background: #fff !important;
    font-size: 12pt;
  }

  /* Show link URLs for printed pages */
  a[href]::after {
    content: " (" attr(href) ")";
    font-size: 0.8em;
    color: #555;
  }

  /* Don't show URLs for internal navigation links */
  a[href^="#"]::after,
  a[href^="javascript"]::after {
    content: "" !important;
  }

  /* Prevent page breaks inside important content */
  h1, h2, h3, h4, h5, h6 {
    page-break-after: avoid;
  }

  table, figure, img {
    page-break-inside: avoid;
  }

  /* Ensure main content fills the page */
  main, .container {
    width: 100% !important;
    max-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
  }
}
