/* Biodiversity Dashboard, phase 2 lane X: the Export control and dialog, the share block, the site
   map panel, the shared-links page, and the print block (BTX-484 sub-issue 6).
   Colour comes from the .bd tokens (biodiversity_dashboard.css), so light and dark both work.
   No em dashes in this file. */

/* ================================ EXPORT CONTROL ================================ */
.bd .tg-export{margin-left:auto;}
.bd .expbtn{display:inline-flex;align-items:center;gap:6px;font-family:var(--label);font-weight:500;font-size:.78rem;
  color:var(--ink);background:var(--seg);border:none;border-radius:999px;padding:.34rem .85rem;cursor:pointer;line-height:1.15;}
.bd .expbtn:hover{background:var(--teal);color:var(--on-teal);}
.bd .expbtn:focus-visible{outline:2px solid var(--teal-2);outline-offset:2px;}

/* The dialog is a native <dialog> (showModal: focus trap, Escape and a backdrop for free). It sits
   inside .bd, so the tokens and the theme reach it in the top layer. */
/* margin:auto is the UA centring that Tailwind's preflight resets. */
.bd .expdlg{margin:auto;width:min(640px,calc(100vw - 32px));max-height:calc(100vh - 48px);overflow:auto;padding:0;
  background:var(--surface);color:var(--ink);border:1px solid var(--rule);border-radius:14px;
  box-shadow:0 18px 48px rgba(0,0,0,.28);}
.bd .expdlg::backdrop{background:rgba(15,46,51,.42);}
.bd .expinner{padding:18px 20px 16px;}
.bd .expdlg h3{margin:0 0 2px;font-family:var(--display);font-weight:400;font-size:1.25rem;}
.bd .expsub{margin:0 0 14px;font-size:.8rem;color:var(--ink-3);}
.bd .expcols{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:18px;}
@media (max-width:560px){ .bd .expcols{grid-template-columns:minmax(0,1fr);} }
.bd .exphead{display:flex;align-items:center;justify-content:space-between;gap:.5rem;font-family:var(--label);font-size:.68rem;
  font-weight:500;letter-spacing:.08em;text-transform:uppercase;color:var(--ink-3);margin:0 0 6px;
  border-bottom:1px solid var(--rule);padding-bottom:5px;}
.bd .exphead.expyr{margin-top:14px;}
.bd .expall{display:inline-flex;align-items:center;gap:5px;text-transform:none;letter-spacing:0;font-size:.74rem;cursor:pointer;color:var(--ink-2);}
.bd .expbox{max-height:210px;overflow:auto;display:flex;flex-direction:column;gap:2px;}
.bd .exprow{display:flex;align-items:center;gap:7px;font-size:.82rem;cursor:pointer;padding:3px 2px;border-radius:4px;min-width:0;}
.bd .exprow span{min-width:0;overflow-wrap:anywhere;}
.bd .exprow:hover{background:var(--surface-2);}
.bd .expdlg input[type=checkbox]{accent-color:var(--teal-2);flex:none;}
.bd .expyears{display:flex;align-items:center;gap:7px;font-size:.82rem;}
.bd .expyears select{font:inherit;font-size:.82rem;padding:3px 6px;border:1px solid var(--rule-strong);border-radius:6px;
  background:var(--surface);color:var(--ink);}
.bd .experr{margin:12px 0 0;font-size:.8rem;color:var(--loss);}
.bd .expprint{margin:16px 0 0;font-size:.76rem;color:var(--ink-3);}
.bd .expfoot{display:flex;justify-content:flex-end;gap:8px;margin-top:18px;}
.bd .expghost,.bd .expgo{font-family:var(--label);font-weight:500;font-size:.8rem;padding:.42rem 1rem;border-radius:999px;
  cursor:pointer;border:1px solid var(--rule-strong);line-height:1.15;}
.bd .expghost{background:transparent;color:var(--ink);}
.bd .expghost:hover:not(:disabled){border-color:var(--ink);}
.bd .expghost:disabled{opacity:.45;cursor:not-allowed;}
.bd .expgo{background:var(--teal);color:var(--on-teal);border-color:var(--teal);}
.bd .expghost:focus-visible,.bd .expgo:focus-visible,.bd .explink:focus-visible{outline:2px solid var(--amber);outline-offset:2px;}

/* Share block */
.bd .expshare{margin-top:18px;}
.bd .expshare .expsub{margin-bottom:10px;}
.bd .expsharerow{display:flex;align-items:center;gap:12px;flex-wrap:wrap;}
.bd .explink{font-size:.8rem;color:var(--ink-2);text-decoration:underline;}
.bd .exphint{margin:8px 0 0;font-size:.78rem;color:var(--loss);}
.bd .exphint.ok{color:var(--ink-2);}
.bd .expsharelink{display:flex;gap:8px;margin-top:8px;min-width:0;}
.bd .expsharelink input{flex:1 1 auto;min-width:0;font-size:.78rem;padding:.38rem .6rem;border:1px solid var(--rule-strong);
  border-radius:8px;background:var(--surface-2);color:var(--ink);}

/* ================================ SITE MAP PANEL ================================ */
/* The technical dashboard's map partial is Tailwind-styled. The dashboard's own reset (.bd button,
   .bd a, .bd p ...) is unlayered, so it would beat Tailwind's layered utilities inside the map: hand
   those properties back to the layers for the map only. The segment name labels are styled by an
   unlayered rule (.segment-label-tooltip__text: white text on a dark box), which revert-layer would
   skip too, leaving dark text on the dark box (BTX-526/532), so they are left out. */
.bd .bd-mapframe{display:block;}
/* The map's room is kept while its frame loads, so the sections below do not drop 560px when it
   arrives (BTX-536 follow-up). The frame's own .bd-mapbox has the same height. */
.bd .bd-mapframe:not(:has(.bd-mapbox)){min-height:560px;border-radius:18px;background:var(--surface);}
.bd .bd-mapbox{height:560px;border-radius:18px;overflow:hidden;background:#fff;box-shadow:var(--shadow);color:#111;}
.bd .bd-mapbox :is(button,a,p,h3,h4,select,span):not(.segment-label-tooltip__text){color:revert-layer;font:revert-layer;margin:revert-layer;padding:revert-layer;}
@media (max-width:640px){ .bd .bd-mapbox{height:420px;} .bd .bd-mapframe:not(:has(.bd-mapbox)){min-height:420px;} }

/* ================================ SHARED LINKS PAGE ================================ */
.bd-shares{width:100%;max-width:64rem;margin:0 auto;padding:1.6rem 0 4rem;color:#0f2e33;font-size:.9rem;}
.bd-shares h1{font-size:1.6rem;font-weight:600;margin:.4rem 0 .5rem;letter-spacing:.02em;}
.bd-shares h2{font-size:1.15rem;font-weight:600;margin:2.2rem 0 .4rem;letter-spacing:.02em;}
.bd-shares-back a{font-size:.82rem;color:#3f5a5e;text-decoration:underline;}
.bd-shares-lede{color:#3f5a5e;max-width:44rem;margin:0 0 1.4rem;}
.bd-shares-empty{color:#627d81;}
.bd-shares-tablewrap{overflow-x:auto;}
.bd-shares-table{width:100%;border-collapse:collapse;}
.bd-shares-table th{text-align:left;font-size:.72rem;letter-spacing:.06em;text-transform:uppercase;color:#627d81;font-weight:600;
  padding:.5rem .6rem;border-bottom:1px solid #c9d6d2;}
.bd-shares-table td{padding:.6rem;border-bottom:1px solid #e4ebe8;vertical-align:top;}
.bd-shares-status{display:inline-block;padding:.1rem .5rem;border-radius:999px;font-size:.72rem;font-weight:600;white-space:nowrap;}
.bd-shares-status.on{background:#dcfce7;color:#166534;}
.bd-shares-status.off{background:#f1f5f3;color:#627d81;}
.bd-shares-revoke{font-size:.8rem;color:#b91c1c;text-decoration:underline;background:none;border:none;cursor:pointer;padding:0;}

/* ================================ PAPER LAYOUT ================================ */
/* Applied by bd_export_controller.js BEFORE the re-render that precedes printing. Every chart draws
   at its own measured pixel width: ~1400px on screen, while A4 (794px) or Letter (816px) less the
   side margins leaves 698px. Narrowing the column first makes every chart measure the paper column.
   698px fits both papers, so the print dialog's paper choice is left to the user (@page sets no
   size). */
.bd.bd-printing .bd-topbar,
.bd.bd-printing .sidenav,
.bd.bd-printing .ctlbar{display:none;}
.bd.bd-printing .pagelayout{display:block;}
.bd.bd-printing .maincol{width:698px;max-width:698px;margin:0 auto;}
/* Breakpoints a paper-width viewport crosses (max-width 820 to 1100px) and a desktop screen does
   not. Restated here so the grid a chart is measured in on screen is the grid it is printed in;
   otherwise a donut drawn for a 3-up row prints in a 2-up row at the wrong scale. Keep in step with
   any new max-width rule above 820px in the dashboard sheets. */
.bd.bd-printing .donutgrid{grid-template-columns:repeat(2,minmax(0,1fr));}
.bd.bd-printing .plantgrid{grid-template-columns:minmax(0,1fr);}
.bd.bd-printing .wrow{grid-template-columns:minmax(0,1fr);gap:.35rem;}
/* The blooming calendar stacks below 760px (name above its bar), and paper lays it out stacked.
   Measured unstacked, its rows read about a third shorter than they print, so each page's share of
   rows (print_layout.js) ran past the page and the repeated month header fell a few rows into the
   next page, leaving most of a page blank (BTX-516 QA, 2026-11-02). Keep in step with the 760px
   block in biodiversity_dashboard.css. */
.bd.bd-printing .bcal-row{grid-template-columns:minmax(0,1fr) 4.4rem;gap:.35rem .5rem;}
.bd.bd-printing .bcal-track{grid-column:1 / -1;}
.bd.bd-printing .bcal-head .bcal-months{display:none;}
.bd.bd-printing .bcal-val{grid-column:2;grid-row:1;}
.bd.bd-printing .bcal-total .bcal-tot{grid-column:1 / -1;grid-row:2;}
.bd.bd-printing .bcal-tot .btotn{font-size:.5rem;}
/* Species inventories: a single column on paper, as the print viewport (under 900px) lays it out.
   A PDF cannot scroll, so each card keeps the fifteen rows a reader sees unscrolled, and the line
   beneath says so and names the section with the full list (sections/inventory.js). */
.bd.bd-printing .invgrid{grid-template-columns:minmax(0,1fr);}
.bd.bd-printing .invrows{max-height:none;overflow:visible;}
.bd.bd-printing .invrow:nth-child(n+16){display:none;}
.bd.bd-printing .invmore .sc{display:none;}
.bd.bd-printing .invmore .pr{display:inline;}
/* Plant characterization has to fit one page (BTX-516, SPEC §1): at full size each site's card is
   a little taller than a page, so it split with its donuts on the next sheet. The donuts scale from
   their viewBox, so a smaller box costs no redraw. Under .bd-printing, not @media print, so the page
   is measured (print_layout.js) at the size it prints. */
.bd.bd-printing .pccard .dnut{max-width:min(100%,200px);}
.bd.bd-printing .pccard .pcpanel{padding:.35rem .45rem .4rem;}
.bd.bd-printing .pccard .pcgrid{gap:.45rem;margin-top:.45rem;}
/* A scrolling box has no scrollbar on paper: it clips. */
.bd.bd-printing .tablecard,
.bd.bd-printing .listwrap,
.bd.bd-printing .expbox{overflow:visible;max-height:none;}

/* ================================ PRINT ================================ */
/* The page box (BTX-516, SPEC §1). Defining a margin box is what keeps Chrome's own header and
   footer (date, title, URL) off the report, and counter(page) / counter(pages) only work in one, so
   nothing in JavaScript counts pages. The side margins stay 0: the print viewport is then the full
   794px paper width and none of the dashboard's narrow-screen rules fire on paper; the column's own
   698px centring is the side margin. A system font, not one of the page's: a margin box waiting on a
   web font prints its glyphs invisibly. The print dialog's Margins: None removes the margin and the
   number with it; the export dialog says so. A named page, so no other page in the app prints with
   it. The paper (A4 or Letter) stays the user's choice in the print dialog; the orientation does
   not. Every page break (print_layout.js PAGE_BUDGET) and every chart width is measured for a
   portrait page, so a landscape print (shorter page) overflowed the cover onto a page holding only
   its "Generated" line and broke the rest early (BTX-516 QA, Joe 11/6: page 2 blank on every
   export, Chrome on Windows set to Landscape). size:portrait names an orientation only, so Chrome
   drops the Layout choice from its dialog and keeps the paper size choice. The name is on the whole
   document, not on .bd: Chrome starts a new page wherever the page name changes, so with it on .bd
   any box after the dashboard (one a browser extension adds to the page, even an empty one) printed
   a last page of its own, blank and unnumbered (BTX-516 QA, Lowell 11/10: page 38 of 38). */
html:has(.bd){page:bdreport;}
@page bdreport{
  size:portrait;
  margin:11mm 0 9mm;
  @top-right{
    content:counter(page) " / " counter(pages);
    font-family:Helvetica,Arial,sans-serif;font-size:9pt;letter-spacing:.04em;color:#000;
    margin-right:13mm;vertical-align:bottom;
  }
  /* Chrome leaves out its own header on an edge where the page defines a margin box, edge by edge:
     with only @top-right it still printed its footer (the page URL and "1/31") along the bottom
     (BTX-516 QA, 2026-11-02). An empty box on each bottom slot keeps the bottom edge ours too. */
  @bottom-left{content:"";}
  @bottom-center{content:"";}
  @bottom-right{content:"";}
}

/* The cover's additions, built by print_layout.js and only ever printed. */
.bd .printtoc,.bd .printgen,.bd .printsrc,.bd .printbrand,.bd .printsites,.bd .printmeta{display:none;}

@media print{
  html,body,body:has(.bd){background:#fff !important;}
  /* Chrome drops background colours unless this is set, which removes the legend swatches. */
  *,*::before,*::after{-webkit-print-color-adjust:exact !important;print-color-adjust:exact !important;}
  /* A soft box-shadow prints as a flat grey rectangle; cards get a hairline instead. An OUTLINE,
     not a border: a border would take 2px from the width every chart inside was measured at. */
  *,*::before,*::after{box-shadow:none !important;text-shadow:none !important;}
  .bd .card,.bd .abundcard,.bd .bpanel,.bd .lcard,.bd .callout,.bd .tablecard,.bd .statstrip .st{
    outline:1px solid var(--rule-strong) !important;outline-offset:-1px;}

  /* The app around the dashboard (nav bar, banners, the shared page's header and footer) is not
     part of the report. The wordmark comes back on the column so a printed report says whose it is. */
  body:has(.bd) > :not(main){display:none !important;}
  /* What a browser extension adds around the report is not part of it either. */
  html:has(.bd) > :not(head):not(body),body:has(.bd) > main > :not(.bd){display:none !important;}
  body:has(.bd) > main{max-width:none !important;width:auto !important;padding:0 !important;margin:0 !important;display:block !important;}
  .bd{padding:0 !important;background:#fff !important;}
  /* The cover's wordmark is .printbrand (print_layout.js), as Lowell's export design draws it. */
  .bd .printbrand{display:block;margin:0 0 16mm;color:var(--ink);}
  .bd .printbrand-word{display:block;font-family:var(--wordmark);font-weight:700;font-size:1.45rem;letter-spacing:.22em;line-height:1.1;}
  .bd .printbrand-tag{display:block;font-family:var(--wordmark);font-weight:700;font-size:.78rem;letter-spacing:.01em;}
  .bd .printsites{display:block;margin:.35rem 0 .25rem;font-family:var(--display);font-size:1.15rem;color:var(--ink);}
  .bd .printmeta{display:block;margin:0 0 .9rem;font-family:var(--label);font-size:.72rem;font-weight:500;letter-spacing:.1em;
    text-transform:uppercase;color:var(--ink-3);}

  /* Controls that mean nothing on paper. The footer's sources line prints on the cover instead. */
  .bd .bd-topbar,.bd .sidenav,.bd .ctlbar,.bd .navtoggle,.bd .themepick,.bd .tg-help,.bd .infobtn,.bd .infopop,
  .bd .expdlg,.bd .tooltip,.bd .bd-loading,.bd footer.page{display:none !important;}
  .bd .pagelayout{display:block !important;}
  .bd .maincol{width:698px !important;max-width:698px !important;margin:0 auto !important;padding:0 !important;}
  /* Sections left out in the dialog, and the site map (Leaflet tiles do not print). */
  .bd .gridsec.bd-noprint,.bd #sec-map{display:none !important;}
  .bd .tablecard,.bd .listwrap{overflow:visible !important;max-height:none !important;}

  /* Controls print as their values (SPEC §7): YEAR 2022 2023 [2024] prints as YEAR 2024, and the
     site pick rows, the projection switch and the year-mix drawer drop out. */
  .bd .yeartoggle{background:none !important;padding:0 !important;gap:0 !important;}
  .bd .yeartoggle button{display:none !important;}
  .bd .yeartoggle button.active{display:inline-flex !important;background:none !important;color:var(--ink) !important;
    padding:0 !important;font-weight:600;}
  .bd .pickbanner,.bd .projbar,.bd .mixyr,.bd .hoveronly,.bd .scalepick{display:none !important;}

  /* ---- The cover (SPEC §8): page 1 is the header, plus the contents, date and sources. ---- */
  .bd header.page{break-after:page;}
  .bd .printtoc{display:block;margin-top:9mm;break-inside:avoid;}
  .bd .printtoc-h{font-family:var(--label);font-size:.68rem;font-weight:500;letter-spacing:.08em;text-transform:uppercase;
    color:var(--ink-3);border-bottom:1px solid var(--rule);padding-bottom:5px;margin:0 0 8px;}
  .bd .printtoc ol{columns:2;column-gap:10mm;margin:0;padding-left:1.4rem;font-size:.86rem;line-height:1.7;}
  .bd .printtoc li{break-inside:avoid;}
  .bd .printgen{display:block;margin-top:9mm;font-size:.78rem;color:var(--ink-3);}
  .bd .printsrc{display:block;margin-top:2mm;font-size:.72rem;color:var(--ink-3);}

  /* ---- Pagination (SPEC §3). ---- */
  /* Every numbered section starts a new page. A section that runs long continues on the next. */
  .bd section.gridsec{break-before:page;margin-top:0 !important;padding-top:0 !important;}

  /* Figures may never be cut. */
  .bd .chartbox,.bd svg,.bd .dnut,.bd .pcpanel,.bd .legendkey,.bd .lk,.bd tr,.bd .bcal-row,.bd .wrow,.bd .bp-row,
  .bd .divtablewrap,.bd .statstrip,.bd .invrow{break-inside:avoid !important;}

  /* Cards move whole, unless print_layout.js measured one taller than a page (.maybreak): keeping
     that whole only pushes it on and leaves a blank page behind. */
  .bd .card,.bd .abundcard,.bd .bpanel,.bd .lcard,.bd .tablecard,.bd .sitegrid > *,.bd .donutgrid > *{break-inside:avoid;}
  .bd :is(.card,.abundcard,.bpanel,.lcard,.tablecard).maybreak{break-inside:auto !important;}

  /* Headings stay with what they introduce. These are hints Chrome may decline; the binding that it
     does not decline is .keepnext below. */
  .bd h2.sec,.bd .sowhat,.bd .secnote,.bd .seclegend,.bd .chead,.bd h3.subhead,.bd .bcal-head{break-after:avoid;}
  .bd h2.sec,.bd .sowhat,.bd .secnote{break-inside:avoid;}
  .bd .sourcenote,.bd .invfoot,.bd .invmore,.bd .dnutcap,.bd .axisnote{break-before:avoid;}
  .bd .keepnext{break-inside:avoid !important;}

  /* Nothing after the last line of a page run (print_layout.js printMarkEnds marks every box that
     ends on the last line of the cover, of each section and of the file): trailing padding or border
     that crosses the page's end becomes a page of its own, blank, before the next forced break or at
     the end of the file. The body's Tailwind min-h-screen goes too. */
  body:has(.bd),body:has(.bd) > main{min-height:0 !important;}
  .bd .printend{margin-bottom:0 !important;padding-bottom:0 !important;border-bottom-width:0 !important;}

  /* No line of a paragraph left alone on a page. */
  .bd p,.bd li{orphans:3;widows:3;}

  /* The IUCN ledger in one column: a card in a multi-column grid can be sliced in half even with
     break-inside:avoid, because Chrome fragments a grid row that does not fit. The ledger holds no
     charts, so one column costs nothing. */
  .bd .ledger{display:block !important;}
  .bd .ledger > .lcard + .lcard{margin-top:4mm;}

  /* The calendar's month header, cloned in front of each page's first row by print_layout.js. */
  .bd .bcal-head.cont{break-before:page;}
}
