@media print {
  /* ── Ensure background colors (like watershed highlights) print ── */
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color-adjust: exact !important;
  }

  body,
  html {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: visible;
  }

  /* Remove any extra top padding/margin so the map shifts to the very top */
  body,
  #mainContent,
  #mainContentInner {
    margin-top: 0 !important;
    padding-top: 0 !important;
  }

  @page {
    size: 11in 8.5in; /* Landscape orientation */
    margin: 0.5in;
  }

  /* ── Hide all UI chrome, navigation, headers, footers, and lookup elements ── */
  header,
  footer,
  nav,
  .skip-link,
  #mainHeader,
  #partnersRow,
  #mainFooter,
  #mainFooterMobile,
  #printButtonSection,
  #adjacentHuc8List,
  #adjacentWatershedsPlaceholder,
  #adjacentResultsDivider,
  #adjacentHuc8SeeMoreLink,
  #adjacentHuc8Error,
  .homeHeader,
  #mobileSelectedWatershed,
  #huc8ResultRow,
  #adjacentWatershedsHeader {
    display: none !important;
  }

  /* Hide the page title block (Home icon, "HUC8 Lookup", Info icon) */
  #mainContentInner
    > .d-flex.justify-content-between.align-items-center.mb-4.pb-2.border-bottom {
    display: none !important;
  }

  /* Hide all lookup UI while keeping the print-only result row above the map */
  #huc8LookupSection,
  #huc8LookupSection > * {
    display: none !important;
  }

  /* Hide the copy button — not needed in print */
  #copyHuc8Button {
    display: none !important;
  }

  /* ── Flexbox Layout Reordering ── */
  #content {
    display: flex !important;
    flex-direction: column;
  }

  /* ── Remove any layout containers that might interfere ── */
  #mainContent,
  #mainContentInner,
  #textContent {
    display: block !important;
    width: 100% !important;
    height: auto !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
    position: static !important;
  }

  #mapAndSidebar {
    display: contents !important; /* Unwraps children to be flex items of #content */
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    overflow: visible !important;
  }

  #mapPane {
    order: 3; /* Places map third */
    border-left: 0 !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    width: 100% !important;
    position: static !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  #adjacentWatershedsBody {
    overflow: visible;
    scrollbar-gutter: auto;
  }

  /* ── PAGE 1: Logo, Result Row, Map, URL Row ── */

  /* Print-only GLANSIS logo row — Centered at the top */
  #printLogoRow {
    display: flex !important;
    justify-content: center !important; /* Centers the logo horizontally */
    align-items: center !important;
    width: 100% !important; /* Forces row to span full page width */
    margin: 0 0 12px 0 !important;
    padding: 0 !important;
    order: 1; /* Places logo first */
  }

  #printLogoRow img {
    height: 40px;
    width: auto;
    margin: 0 auto !important;
  }

  /* Selected HUC8 result label — Centered above the map */
  #printHuc8ResultRow {
    display: block !important;
    align-self: center !important; /* Tells flex layout to center this specific box */
    margin: 0 auto 12px auto !important; /* Fallback centering */
    text-align: center !important; /* Centers the text inside */
    padding: 8px 12px !important;
    background: white;
    border: 2px solid #333;
    border-radius: 6px;
    width: auto !important; /* Let it shrink to text size */
    max-width: 90% !important;
    page-break-after: avoid;
    break-after: avoid;
    order: 2; /* Places HUC box second */
  }

  #printHuc8Result h2 {
    font-size: 18px;
    font-weight: bold;
    margin: 0;
    padding: 0;
  }

  #map {
    display: block !important;
    /* width: intentionally not !important so JS inline 960px wins in print */
    width: 100%;
    height: 4in !important;
    position: relative !important;
    margin: 0 !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
    page-break-after: auto !important;
    break-after: auto !important;
    overflow: hidden !important;
  }

  /* PC/desktop (mouse + fine pointer): taller map */
  @media (hover: hover) and (pointer: fine) {
    #map {
      height: 5.25in !important; /* Reduced slightly to guarantee it fits with top headers */
    }
  }

  /* Print-only URL row — Placed beneath the map */
  #printUrlRow {
    display: flex !important;
    justify-content: center !important; /* Centered to match the logo and box */
    align-items: center !important;
    gap: 6px;
    width: 100% !important; /* Forces row to span full page width */
    margin: 12px 0 24px 0 !important;
    padding: 0 !important;
    font-size: 11px;
    color: #333;
    order: 4; /* Places link fourth (below the map) */
    page-break-after: always !important;
    break-after: page !important;
  }

  #printUrlLabel {
    font-style: italic;
    white-space: nowrap;
  }

  #printUrlLink {
    color: #012a52;
    word-break: break-all; /* long URLs wrap rather than overflow */
  }

  .leaflet-control-zoom {
    display: none !important;
  }

  /* Map code labels */
  .huc8-code-map-label,
  .adjacent-huc8-code-map-label {
    font-size: 18px !important;
    background: white !important;
    border: 1px solid #333 !important;
    color: #222 !important;
    padding: 4px 8px;
    border-radius: 4px;
  }

  /* ── Legend print overrides ── */
  #mapLegend {
    background: #ffffff !important;
    border: 1px solid #000 !important;
    padding: 10px 15px !important;
  }

  .legend-color {
    border: 1px solid #333 !important;
  }

  #focused-legend {
    background: var(--color-focused) !important;
    border-color: var(--stroke-focused) !important;
  }

  #adjacent-legend {
    background: #ead59a !important;
    border-color: var(--stroke-adjacent) !important;
    background-image: repeating-linear-gradient(
      -45deg,
      rgba(123, 94, 17, 0.18) 0 3px,
      rgba(123, 94, 17, 0) 3px 8px
    ) !important;
  }

  #default-legend {
    background: var(--color-default) !important;
    border-color: var(--stroke-default) !important;
  }

  /* ── Map label print overrides ── */
  .huc8-code-map-label span {
    background: #ffffff !important;
    border: 1px solid var(--stroke-focused) !important;
    color: #011d39 !important;
  }

  .adjacent-huc8-code-map-label span {
    background: #fef9ef !important;
    border: 1px solid var(--stroke-adjacent) !important;
    color: #6e560e !important;
  }

  .adjacent-huc8-pattern {
    fill: url(#adjacentHuc8Pattern) !important;
    fill-opacity: 0.72 !important;
  }

  /* ── PAGE 2: Adjacent Watersheds ── */
  #adjacentWatershedsSection {
    display: block !important;
    position: static !important;
    width: 100% !important;
    max-height: none;
    opacity: 1;
    overflow: visible;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent !important;
    transform: none;
    box-sizing: border-box;
    order: 5; /* Places table last */
    page-break-before: auto !important;
    break-before: auto !important;
  }

  #adjacentWatershedsSection.print-hidden {
    display: none !important;
  }

  #adjacentWatershedsSection h2 {
    background: transparent !important;
    padding: 0 0 8px;
    border-bottom: 0;
    border-radius: 0;
  }

  #printAdjacentWatershedsTitle {
    display: block !important;
    font-size: 20px;
    font-weight: bold;
    margin-bottom: 0.15in;
    border-bottom: 2px solid #333;
    padding-bottom: 6px;
  }

  /* Table: 4 columns to fit long lists on one page */
  #adjacentHuc8Table {
    display: table !important;
    width: 100% !important;
    border-collapse: collapse;
    font-size: 12px;
    table-layout: fixed;
  }

  #adjacentHuc8Table thead th {
    background: #f0f0f0;
    font-weight: bold;
    border: 1px solid #bbb;
    padding: 5px 10px;
    text-align: left;
  }

  #adjacentHuc8Table td {
    border: 1px solid #ccc;
    padding: 5px 10px;
    vertical-align: top;
    word-break: break-word;
  }

  #adjacentHuc8Table tr:nth-child(odd) td {
    background: #f7f7f7;
  }

  /* Keep rows intact across pages */
  #adjacentHuc8Table tr {
    page-break-inside: avoid;
    break-inside: avoid;
  }

  /* Plain text links in print */
  #adjacentHuc8Table a {
    color: #000 !important;
    text-decoration: none !important;
    pointer-events: none;
  }
}
