/*
 * EncodeLabel: the Label paper page (templates.php, assets/js/page-templates.js).
 *
 * Only what this page needs on top of site.css (and kit-paper.css, which
 * styles the "Your own size" form). Every colour is one of site.css's names,
 * so light and dark both work. Pictures of paper are the exception the whole
 * site makes: a sheet is white with black ink in both themes, on the same
 * grey "desk" the tools use.
 *
 *   .tp-finder     the search box, the three tabs and the line that says what was found
 *   .tp-group      one of the three lists (US Letter sheets, A4 sheets, Rolls)
 *   .tp-grid       a grid of cards        .tp-card   one paper
 *   .tp-own        "Your own size"        .tp-measure  "How to measure your sheet"
 *   .tp-line       "Line it up first"     .tp-close  the last box
 */

/* ==========================================================================
   1. The search box and the tabs
   ========================================================================== */
/* The links in the page's heading that jump further down the page. */
.tp-jump > .chip-list { margin: 0; }

.tp-finder { margin: 0 0 18px; }
.tp-search { position: relative; max-width: 520px; margin: 0 0 6px; }
.tp-search > input { width: 100%; padding-left: 42px; }
.tp-search-icon {
  position: absolute; top: 0; bottom: 0; left: 12px; display: flex; align-items: center;
  color: var(--muted); pointer-events: none;
}
/* How many papers a tab holds (or how many match the search). */
.tp-count {
  display: inline-block; min-width: 1.7em; padding: 1px 6px; border-radius: 999px;
  background: var(--soft); color: var(--ink);
  font: 600 .75rem/1.5 var(--body); font-variant-numeric: tabular-nums; text-align: center;
}
.tab.is-empty .tp-count { background: none; color: var(--muted); }
.tp-status { min-height: 0; margin: 10px 0 0; }
.tp-status::before { display: none; } /* a plain count, not a message: no marker */
.tp-status:empty { margin: 0; }
/* The lists named in that line ("More under A4 sheets (7)") are buttons: give them a little room. */
.tp-status .link-button { display: inline-block; padding: 4px 1px; }

/* On a screen with room, the search box and the tabs stay in view while the list scrolls under them. */
@media (min-width: 761px) and (min-height: 620px) {
  .tp.has-tabs > .tp-finder {
    position: sticky; top: var(--header-h, 60px); z-index: var(--z-sticky, 30);
    margin: 0 calc(-1 * var(--gutter, 20px)) 18px; padding: 12px var(--gutter, 20px) 0;
    background: var(--paper);
  }
  .tp.has-tabs > .tp-finder > .tp-status:not(:empty) { margin: 0; padding: 8px 0; border-bottom: 1px solid var(--line); }
}

/* ==========================================================================
   2. A list and its cards
   ========================================================================== */
.tp-group { margin: 0 0 40px; }
.tp-group-head { margin-bottom: 4px; }
/* With the tabs on, the tab already says which list this is. The heading stays for screen readers. */
.tp.has-tabs .tp-group { margin-bottom: 0; }
.tp.has-tabs .tp-group-head {
  position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}
.tp-blurb { max-width: 46rem; margin: 0 0 16px; color: var(--muted); }
.tp-part { margin: 26px 0 10px; font-size: 1rem; letter-spacing: 0; }
.tp-browse > .tp-part:first-child, .tp-rest > .tp-part:first-child { margin-top: 0; }
.tp-rest { margin-top: 26px; }

.tp-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px;
  margin: 0; padding: 0; list-style: none;
}
.tp-card {
  display: grid; grid-template-columns: 84px minmax(0, 1fr); grid-template-rows: 1fr auto; column-gap: 14px;
  min-width: 0; margin: 0; padding: 12px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--card); box-shadow: var(--shadow);
}
.tp-card:focus { outline: none; }
/* The paper the address asked for (/templates?paper=...). */
.tp-card.is-target { border-color: var(--brand); background: var(--soft); box-shadow: inset 0 0 0 1px var(--brand), var(--shadow); }

/* The little picture of the sheet, on the same grey "desk" the big previews use. */
.tp-thumb {
  display: grid; grid-row: 1 / 3; align-self: start; place-items: center; width: 84px; height: 104px;
  border-radius: var(--radius-small); background: var(--desk); color-scheme: light;
}
.tp-thumb > svg { display: block; }
/* Until the picture is drawn (it is drawn when the card scrolls into view): a blank sheet. */
.tp-thumb:not([data-tp-state="drawn"])::before {
  content: ""; width: 48px; height: 62px; border-radius: 1px;
  background: var(--sheet); box-shadow: 0 0 0 1px var(--desk-line); opacity: .7;
}

.tp-body { min-width: 0; }
.tp-size { margin: 0; font: 700 1.05rem/1.3 var(--display); letter-spacing: 0; overflow-wrap: anywhere; }
/* The size links to the paper's own page (/paper/<id>): it reads as the heading, underlined as a link. */
.tp-size > a { color: inherit; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }
.tp-size > a:hover { color: var(--link); }
.tp-badge { margin-left: 2px; border-color: var(--link); color: var(--link); }
.tp-name { margin: 1px 0 0; color: var(--muted); font-size: .9rem; line-height: 1.35; overflow-wrap: anywhere; }
.tp-layout { margin: 8px 0 0; font-size: .88rem; line-height: 1.6; }
/* How many labels are on the sheet is what tells two sheets of the same size apart, so it is the loudest thing after the size. */
.tp-per {
  display: inline-block; margin-right: 4px; padding: 0 7px; border-radius: 3px;
  background: var(--ink); color: var(--paper); font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap;
}
.tp-across { white-space: nowrap; }
.tp-fine { margin: 4px 0 0; color: var(--muted); font-size: .8rem; line-height: 1.45; overflow-wrap: anywhere; }
.tp-check {
  display: flex; align-items: flex-start; gap: 5px; margin: 6px 0 0;
  color: var(--warn); font-size: .8rem; font-weight: 600; line-height: 1.4;
}
.tp-check .icon { flex: none; width: 1.15em; height: 1.15em; margin-top: .12em; }
/* The rest of the product numbers, folded away under "and 16 more". */
.tp-codes { margin: 0; font-size: .8rem; line-height: 1.45; }
.tp-codes > summary {
  display: inline-block; padding: 3px 0; color: var(--link); cursor: pointer; list-style: none;
  text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 2px;
}
.tp-codes > summary::-webkit-details-marker { display: none; }
.tp-codes > summary:hover { text-decoration-thickness: 2px; }
.tp-codes > .tp-fine { margin-top: 0; }

/* The two buttons run along the bottom of the card, so they line up from card to card. */
.tp-actions {
  display: flex; grid-column: 1 / -1; align-self: end; flex-wrap: wrap; align-items: center; gap: 6px;
  margin: 12px 0 0; padding-top: 10px; border-top: 1px solid var(--line);
}
.tp-actions > .btn { margin: 0; }
.tp-actions > .btn-ghost { padding-right: 8px; padding-left: 8px; }

.tp-more { margin: 18px 0 0; text-align: center; }
.tp-brands { max-width: none; margin: 28px 0 0; padding-top: 14px; border-top: 1px solid var(--line); }

.tp-none { margin: 18px 0 0; }
.tp-none > p { margin: 0 0 10px; }
.tp-none-tip { color: var(--muted); }
.tp-none-actions { justify-content: center; }

/* ==========================================================================
   3. Your own size
   ========================================================================== */
.tp-own .tp-form { margin: 0; }
.tp-changing { margin: 0 0 10px; }
.tp-mine { margin: 28px 0 0; }
.tp-mine > .tp-part { margin-top: 0; }
/* A size of the visitor's own has four buttons, so its card is wider. Change and Remove sit at the far end. */
.tp-mine > .tp-grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 440px), 1fr)); }
.tp-card-own .tp-actions { gap: 4px 6px; }
.tp-card-own .tp-actions > [data-tp-own-edit] { margin-left: auto; }

/* ==========================================================================
   4. How to measure your sheet
   ========================================================================== */
.tp-measure-cols { display: grid; grid-template-columns: minmax(0, 420px) minmax(0, 1fr); gap: 24px 36px; align-items: start; }
.tp-measure-desk {
  padding: 16px 0 0 16px; border: 1px solid var(--desk-line); border-radius: var(--radius);
  background: var(--desk); overflow: hidden; color-scheme: light;
}
.tp-measure-picture { display: block; width: 100%; height: auto; }
.tp-measure-page { fill: var(--sheet); }
.tp-measure-edge { fill: none; stroke: color-mix(in srgb, var(--sheet-ink) 30%, var(--sheet)); stroke-width: 1; }
.tp-measure-labels > rect { fill: var(--sheet); stroke: color-mix(in srgb, var(--sheet-ink) 42%, var(--sheet)); stroke-width: 1.25; }
.tp-measure-lines > path { fill: none; stroke: var(--brand); stroke-width: 2; }
.tp-measure-mark { fill: var(--sheet-ink); }
.tp-measure-number { fill: var(--sheet); font: 700 11px/1 var(--mono); }
.tp-measure .step-list { margin-bottom: 16px; }

/* ==========================================================================
   5. Line it up first
   ========================================================================== */
.tp-causes { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin: 20px 0 0; padding: 0; list-style: none; }
.tp-cause { display: grid; grid-template-columns: 84px minmax(0, 1fr); gap: 14px; align-items: start; margin: 0; padding: 14px; }
.tp-cause h3 { margin: 0 0 6px; font-size: 1.02rem; }
.tp-cause p { margin: 0 0 6px; font-size: .92rem; line-height: 1.5; }
.tp-cause p:last-child { margin-bottom: 0; }
.tp-cause-picture { display: grid; place-items: center; padding: 8px; border-radius: var(--radius-small); background: var(--desk); color-scheme: light; }
.tp-cause-sheet { display: block; width: 100%; height: auto; }
.tp-cause-paper { fill: var(--sheet); }
.tp-cause-labels > rect { fill: color-mix(in srgb, var(--sheet-ink) 16%, var(--sheet)); }
.tp-cause-print > rect { fill: none; stroke: var(--sheet-ink); stroke-width: 1; }

/* ==========================================================================
   6. The last box
   ========================================================================== */
.tp-close-card { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px 32px; margin: 0; }
.tp-close-card > div { flex: 1 1 22rem; max-width: 44rem; }
.tp-close-card > div > :last-child { margin-bottom: 0; }
.tp-close-card h2 { margin-top: 0; }
.tp-close-card > .button-row { margin: 0; }

/* ==========================================================================
   7. Narrower screens
   ========================================================================== */
@media (max-width: 980px) {
  .tp-causes { grid-template-columns: minmax(0, 1fr); gap: 12px; }
}
@media (max-width: 860px) {
  .tp-measure-cols { grid-template-columns: minmax(0, 1fr); }
  .tp-measure-desk { max-width: 420px; }
}
@media (max-width: 560px) {
  /* The jump links become one line that scrolls sideways inside its own box. */
  .tp-jump { width: 100%; min-width: 0; }
  .tp-jump > .chip-list {
    flex-wrap: nowrap; margin: 0 calc(-1 * var(--gutter, 20px)); padding: 4px var(--gutter, 20px);
    overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: none; -webkit-overflow-scrolling: touch;
  }
  .tp-jump > .chip-list::-webkit-scrollbar { display: none; }
  .tp-jump > .chip-list > li { flex: none; }
  .tp-jump .chip { white-space: nowrap; }

  .tp-finder { margin-bottom: 14px; }
  .tp-search { max-width: none; }
  /* The three tabs fit side by side on a phone. */
  .tp-tabs .tab-list { gap: 0; margin: 0 calc(-1 * var(--gutter, 20px)); padding: 0 calc(var(--gutter, 20px) - 8px); }
  .tp-tabs .tab { gap: 5px; padding-right: 8px; padding-left: 8px; font-size: .9rem; }
  .tp-count { min-width: 1.4em; padding: 1px 5px; }

  /* A card is a row: the picture on the left, the words beside it, the two buttons underneath. */
  .tp-grid { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .tp-card { grid-template-columns: 72px minmax(0, 1fr); grid-template-rows: auto auto; column-gap: 12px; padding: 12px 12px 8px; }
  .tp-thumb { grid-row: 1; width: 72px; height: 94px; }
  .tp-actions { margin-top: 10px; padding-top: 8px; }
  .tp-actions > .btn { flex: 1 1 0; white-space: nowrap; }
  .tp-card-own .tp-actions > .btn { flex: 1 1 40%; margin-left: 0; }
  .tp-more > .btn { width: 100%; }
  .tp-own .tp-form { padding: 16px; }
  .tp-cause { grid-template-columns: 72px minmax(0, 1fr); }
  .tp-close-card > .button-row { width: 100%; }
  .tp-close-card > .button-row > .btn { flex: 1 1 auto; }
}

/* On a touch screen the small links inside a card and under the tabs get a finger-sized place to tap. */
@media (pointer: coarse) {
  .tp-codes > summary { padding: 11px 0; }
  .tp-status .link-button { padding: 11px 2px; }
}

/* Without JavaScript there are no pictures to draw: the cards are words only. */
@media (scripting: none) {
  .tp-card { grid-template-columns: minmax(0, 1fr); }
  .tp-thumb, .tp-check > [data-icon] { display: none; }
  .tp-form, .tp-changing { display: none; }
}

@media (forced-colors: active) {
  .tp-thumb, .tp-measure-desk, .tp-cause-picture { forced-color-adjust: none; } /* paper keeps its real black and white */
  .tp-per { border: 1px solid CanvasText; }
  .tp-card.is-target { outline: 2px solid Highlight; }
}

@media print {
  .tp-finder, .tp-actions, .tp-more, .tp-own, .tp-close { display: none; }
}
