@media print {
  body, html {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: visible;
  }

  @page {
    size: 11in 8.5in landscape;
    margin: 0.5in;
  }

  /* ── Hide all UI chrome ── */
  #mainHeader,
  #partnersRow,
  #mainFooter,
  #mainFooterMobile,
  #printButtonSection,
  #adjacentHuc8List,
  .homeHeader {
    display: none !important;
  }

  /* Hide all children of the lookup section except the result row —
     this lets #huc8ResultRow remain visible above the map while
     hiding the search form, radio buttons, and other lookup UI */
  #huc8LookupSection > *:not(#huc8ResultRow) {
    display: none !important;
  }

  /* Hide the copy button — not needed in print */
  #copyHuc8Button {
    display: none !important;
  }

  /* ── Remove any layout containers that might interfere ── */
  #mainContent,
  #mainContentInner,
  #textContent,
  #content,
  #mapAndSidebar,
  #mapPane {
    display: block !important;
    width: 100% !important;
    height: auto !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
    position: static !important;
  }

  /* ── PAGE 1: Map ── */

  /* Print-only GLANSIS logo row — hidden on screen, shown in print */
  #printLogoRow {
    display: flex !important;
    align-items: center;
    margin-bottom: 6px;
  }

  #printLogoRow img {
    height: 40px;
    width: auto;
  }

  /* Selected HUC8 result label — sits above the map;
     reduced map height to 6in (from 6.5in) to make room for this row */
  #huc8ResultRow {
    display: flex !important;
    align-items: center;
    gap: 8px;
    margin: 0 auto 8px auto;  /* auto left/right centers the block */
    padding: 8px 12px;
    background: white;
    border: 2px solid #333;
    border-radius: 6px;
    width: fit-content;
    page-break-after: avoid;
    break-after: avoid;
  }

  #huc8ResultRow #huc8Result h2 {
    font-size: 18px;
    font-weight: bold;
    margin: 0;
    padding: 0;
  }

  #map {
    display: block !important;
    width: 100% !important;
    height: 5.85in !important;   /* leave room for logo, result row, and legend on page 1 */
    position: relative !important;
    margin: 0 !important;
    page-break-after: always;
    break-after: page;
    overflow: hidden !important;
  }

  .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;
  }

  /* ── PAGE 2: Adjacent Watersheds ── */
  #adjacentWatershedsSection {
    display: block !important;
    position: static !important;
    width: 100% !important;
    page-break-before: always;
    break-before: page;
    padding: 0;
    box-sizing: border-box;
  }

  #adjacentWatershedsSection.print-hidden {
    display: none !important;
    page-break-before: auto;
    break-before: auto;
  }

  #adjacentWatershedsSection h2 {
    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 {
    break-inside: avoid;
  }

  /* Plain text links in print */
  #adjacentHuc8Table a {
    color: #000 !important;
    text-decoration: none !important;
    pointer-events: none;
  }
}
