/*
 * EncodeLabel: the Address labels page (goes with address.php and
 * assets/js/page-address.js).
 *
 * The page uses the shell's two-column tool layout (site.css: .tool): the
 * four numbered steps on the left, the preview and the Print buttons on the
 * right. On a phone the preview is pinned to the top, the steps scroll under
 * it and the buttons stay at the bottom edge. This file only adds what is
 * particular to this page:
 *   .ad-head, .ad-top      the heading with Open and Save beside it
 *   .ad-starts, .ad-start  the three big ways to add a list
 *   .ad-summary, .ad-notes what was added and what was repaired
 *   .ad-orders             "One label per order" (order exports only)
 *   .ad-first, .ad-pager   the first label, drawn large, with arrows
 *   .ad-columns            "Which column is which"
 *   .ad-look, .ad-qr       typeface, size, switches, the small QR code
 *   .ad-label-desk         one label, large, in the big preview
 *   .ad-about              the words under the tool
 *   .ad-guide              the how-to text and the questions under those
 *
 * Colours come from the design tokens only, so light and dark both work.
 * The label and the sheet are always black on white (site.css: .sheet-paper),
 * because that is what the printer makes.
 */

/* ---- The heading ------------------------------------------------------------- */
.ad-head { align-items: center; margin-bottom: 14px; }
.ad-head h1 { font-size: clamp(1.5rem, 1.2rem + 1.2vw, 2rem); }
.ad-head .ad-lead { margin-top: 4px; font-size: 1rem; }
.ad-top { flex-wrap: nowrap; min-width: 0; }
.ad-save { display: inline-flex; min-width: 0; }
.ad-notice { margin: 0 0 14px; }

/* address.php sends the tool hidden and page-address.js shows it once every script has run.
   Until then its place is held (a screen high, with nothing in it to see, press or read out),
   so the text under the tool is not shown first and then pushed down the page. !important
   because the shell hides every [hidden] thing with !important. The place is given back when
   it will never be filled: the "Part of this page could not load" note is showing, JavaScript
   is off (two ways of telling, for older and newer browsers), or 15 seconds have gone by and
   the scripts have still not run (a dropped connection): the place then closes by itself. */
.ad[hidden] { display: block !important; visibility: hidden; height: 100dvh; overflow: hidden; animation: ad-give-back 15s step-end forwards; }
@keyframes ad-give-back { to { height: 0; } }
[data-ad-broken]:not([hidden]) ~ .ad[hidden] { display: none !important; }
@media (scripting: none) { .ad[hidden] { display: none !important; } }
noscript:has(> .alert) ~ .ad[hidden] { display: none !important; }

/* ---- Step 1, empty: three big ways in ------------------------------------------ */
.ad-starts { display: grid; gap: 8px; }
.ad-start {
  display: flex; flex-direction: row; align-items: center; gap: 14px;
  width: 100%; min-height: 68px; margin: 0; padding: 12px 14px;
  border: 1px solid var(--field-line); border-radius: var(--radius);
  background: var(--card); color: var(--ink); font: inherit; text-align: left; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
/* The first one is also a place to drop a file: the shell's dashed edge says so. */
.ad-start.dropzone { padding: 11px 13px; border: 2px dashed var(--field-line); }
.ad-start:hover { border-color: var(--ink); }
.ad-start:focus-visible, .ad-start:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }
.ad-start .ad-start-icon {
  display: grid; place-items: center; flex: none; width: 42px; height: 42px; padding: 10px;
  border-radius: var(--radius-small); background: var(--soft); color: var(--ink);
}
.ad-start-text { display: grid; gap: 2px; min-width: 0; }
.ad-start-text strong { font-size: 1rem; line-height: 1.25; }
.ad-start-text span { color: var(--muted); font-size: .88rem; line-height: 1.35; }
.ad-also { margin: 12px 0 0; font-size: .95rem; }
.ad-also .link-button { min-height: 32px; }
.ad-private { display: flex; align-items: flex-start; gap: 6px; margin: 10px 0 0; }
.ad-private [data-icon] { margin-top: .1em; }
@media (pointer: coarse) {
  .ad-also .link-button { min-height: 44px; }
}

/* ---- Step 1, with a list ------------------------------------------------------ */
.ad-summary {
  display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 12px;
  border: 1px solid var(--line); border-radius: var(--radius-small); background: var(--soft);
}
.ad-summary-icon { color: var(--muted); }
.ad-summary-text { flex: 1 1 auto; min-width: 0; margin: 0; font-weight: 600; line-height: 1.35; overflow-wrap: anywhere; }
.ad-change { flex: none; }

.ad-notes { display: grid; gap: 6px; margin: 10px 0 0; padding: 0; list-style: none; }
.ad-note { display: flex; align-items: flex-start; gap: 8px; font-size: .9rem; line-height: 1.45; }
.ad-note-icon { flex: none; margin-top: .1em; color: var(--muted); }
.ad-note-icon .icon { width: 1.1em; height: 1.1em; }
.ad-note.is-ok .ad-note-icon { color: var(--ok); }
.ad-note.is-warn .ad-note-icon { color: var(--warn); }
.ad-note-text { min-width: 0; overflow-wrap: anywhere; }

/* "One label per order": a choice about the whole list, so it sits in a box of its own under the notes. */
.ad-orders { margin: 12px 0 0; padding: 2px 12px 10px; border: 1px solid var(--line); border-radius: var(--radius-small); }
.ad-orders .switch { font-weight: 600; }
.ad-orders-hint { margin: -6px 0 0 58px; }

/* The first label, drawn by the same engine that prints it. */
.ad-first { margin-top: 14px; }
.ad-first-desk { height: 168px; min-height: 0; padding: 16px; }
.ad-pager { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 36px; margin-top: 8px; }
.ad-pager-text { min-width: 8.5em; color: var(--muted); font-size: .9rem; font-variant-numeric: tabular-nums; text-align: center; }
.ad-pager.is-single .btn { visibility: hidden; }
/* "(order #1003)" or "(row 7 of your list)" after "Label 3 of 12": left off on a phone, where the line sits in
   the narrow bar pinned to the top of the screen and would otherwise take two lines. */
@media (max-width: 600px) {
  .ad-pager-more { display: none; }
}

/* "Which column is which": folds away once it has been checked. */
.ad-columns { margin: 12px 0 0; border-top: 1px solid var(--line); }
.ad-columns > summary {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; min-height: 44px; padding: 11px 0;
  list-style: none; cursor: pointer;
}
.ad-columns > summary::-webkit-details-marker { display: none; }
.ad-columns > summary::after {
  content: ""; flex: none; align-self: center; width: 8px; height: 8px; margin: 0 4px 3px auto;
  border: solid var(--muted); border-width: 0 2px 2px 0; transform: rotate(45deg);
}
.ad-columns[open] > summary::after { margin-bottom: -3px; transform: rotate(225deg); }
.ad-columns-title { font-weight: 650; }
.ad-columns-brief { flex: 1 1 8em; min-width: 0; color: var(--muted); font-size: .88rem; }
.ad-columns.is-unmatched .ad-columns-brief { color: var(--warn); font-weight: 600; }
.ad-columns-hint { margin: 0 0 12px; }

/* ---- Step 2 -------------------------------------------------------------------- */
.ad-paper-note { margin: 10px 0 0; }

/* ---- Step 3: the look ------------------------------------------------------------ */
.ad-look > .field-label { margin-top: 16px; }
.ad-look > .field-label:first-child { margin-top: 0; }
/* Each typeface is shown in itself (the same three families the label engine prints with). */
.ad-fonts .ad-font-sans { font-family: Helvetica, Arial, "Liberation Sans", sans-serif; }
.ad-fonts .ad-font-serif { font-family: "Times New Roman", Times, "Liberation Serif", serif; font-size: 1rem; }
.ad-fonts .ad-font-mono { font-family: "Courier New", Courier, "Liberation Mono", monospace; }
.ad-fonts > label > span { padding-left: 8px; padding-right: 8px; }

.ad-size { margin-top: 12px; }
.ad-size-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 12px; margin-top: 2px; }
.ad-size-row .field-label { margin: 0; }
.ad-size-box { display: flex; align-items: center; gap: 8px; }
.ad-size-box .stepper > input { width: 4.2em; }
.ad-unit { color: var(--muted); font-size: .92rem; }
.ad-size-status { margin-top: 6px; align-items: flex-start; }
.ad-size-status::before { align-self: flex-start; margin-top: .5em; }
.ad-size-status:empty { display: none; }

.ad-switches { display: grid; margin-top: 10px; }
.ad-switch-hint { margin: -8px 0 4px 58px; }
/* "Print the order number" comes with its hint in one box, shown only for a list with order numbers. */
.ad-orderline { display: grid; }
/* "Postcode before the town (most of Europe)" takes two lines on a phone. Its hint is then not tucked up under
   the switch (the other switches are one line, and leave room there). */
@media (max-width: 520px) {
  .ad-zipfirst-hint { margin-top: 0; }
}

.ad-qr { margin: 16px 0 0; padding: 16px 0 0; border-top: 1px solid var(--line); }
.ad-qr > legend { float: left; width: 100%; margin: 0 0 8px; font-size: 1rem; font-weight: 700; }
.ad-qr > legend + * { clear: both; }
.ad-qr-why { margin: 8px 0 0; }
.ad-qr-body { margin-top: 14px; }
.ad-qr-body .field { margin-bottom: 12px; }
.ad-qr-body .status-line { align-items: flex-start; }
.ad-qr-body .status-line::before { align-self: flex-start; margin-top: .5em; }
.ad-qr-body .status-line:empty { display: none; }
.ad-qr-meter { margin-top: 14px; }
.ad-qr-meter:empty { display: none; }
.ad-qr-note { margin: 8px 0 0; }
.ad-qr-note.is-warn { color: var(--warn); }

/* ---- Step 4 and what follows it ---------------------------------------------------- */
.ad-print-wait { margin: 0; font-size: .95rem; }
.ad-more { margin: 4px 0 0; padding: 4px 2px 0; }
.ad-more .hint { margin-top: 8px; }

/* ---- The big preview ---------------------------------------------------------------- */
/* Two views of the same job: the whole sheet (the print panel's own picture) and one label, large. */
.ad-view-label > .kpr-desk, .ad-view-label > .kpr-preview-bar { display: none; }
.ad-view-sheet > .ad-label-desk, .ad-view-sheet > .ad-label-bar { display: none; }
.ad-label-desk .sheet-paper { max-width: 680px; }
.ad-label-bar { display: flex; flex: none; align-items: center; justify-content: center; gap: 8px; min-height: 36px; margin-top: 8px; }
.ad-label-bar .ad-pager { flex: 1 1 auto; min-height: 0; margin: 0; }
.ad-view-button { flex: none; }
.ad-fold { display: none; flex: none; }
/* On a wide screen the arrows stay in the middle, under the picture, and the view button sits at the right-hand
   end. An empty box as wide as that button balances it on the left. In a narrow column (a tablet held upright)
   the empty box gives way first, so the button never lies on top of the arrows. */
@media (min-width: 761px) {
  .tool-preview > .kpr-preview-bar::before, .ad-label-bar::before { content: ""; flex: 0 9999 86px; }
  .ad-label-bar .ad-pager { min-width: 0; }
}
/* The example sheet shown before any address is added. */
.ad-example .sheet-paper { opacity: .92; }

/* The table editor in its pop-up. */
.ad-grid-hint { margin: 0 0 12px; }

/* ---- The words under the tool -------------------------------------------------------- */
.ad-about { max-width: 980px; margin: 44px auto 0; }
.ad-about h2 { margin: 0 0 14px; }
.ad-about-list {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 32px;
  margin: 0 0 16px; padding: 0; list-style: none; color: var(--muted);
}
.ad-about-list strong { display: block; color: var(--ink); }

/* The how-to text under that: four short sections, two by two where there is room,
   then the questions at a comfortable line length. */
.ad-guide { max-width: 980px; margin: 44px auto 0; padding-top: 28px; border-top: 1px solid var(--line); }
.ad-guide h2 { margin: 0 0 12px; font-size: 1.25rem; }
.ad-guide p { margin: 0 0 12px; }
.ad-guide-uses { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 32px 40px; }
.ad-guide-uses > section > :last-child { margin-bottom: 0; }
.ad-guide .step-list { gap: 12px; margin: 0 0 12px; }
.ad-guide .step-list p { color: var(--ink); }
.ad-guide-link { display: inline-flex; align-items: center; min-height: 44px; font-weight: 600; }
.ad-guide-questions { max-width: 46rem; margin-top: 40px; }
.ad-guide-questions .faq-list { margin-bottom: 0; }

/* ---- Phones --------------------------------------------------------------------------- */
@media (max-width: 760px) {
  .ad-head { margin-bottom: 10px; }
  .ad-head .ad-lead { font-size: .95rem; }
  /* Nothing to preview or print yet: the three ways in come first. */
  .ad.is-empty .tool-preview, .ad.is-empty .tool-actions { display: none; }
  /* The label is already pinned to the top of the screen, so it is not shown a second time in step 1. */
  .ad-first { display: none; }
  .tool-preview > .ad-label-desk { height: clamp(112px, 22dvh, 190px); padding: 10px; }
  .ad-fold { display: inline-flex; }
  .ad-about { margin-top: 32px; }
  .ad-about-list { grid-template-columns: 1fr; gap: 14px; }
  .ad-guide { margin-top: 32px; padding-top: 24px; }
  .ad-guide-uses { grid-template-columns: 1fr; gap: 28px; }
  .ad-guide-questions { margin-top: 32px; }
}
@media (max-width: 560px) {
  /* The heading and its two buttons share one line; the buttons show their pictures only (each still has its name for a screen reader). */
  .ad-head { flex-wrap: nowrap; align-items: flex-start; gap: 10px; }
  .ad-head > div:first-child { flex: 1 1 auto; min-width: 0; }
  .ad-top { flex: none; gap: 6px; }
  .ad-top .ad-word, .ad-top .ksv-save-word { display: none; }
  .ad-top .ksv-save { flex-direction: column; align-items: flex-end; gap: 2px; }
  .ad-top .ksv-state { font-size: .75rem; }
  .ad-columns-brief { flex-basis: 100%; order: 3; }
}
@media (max-width: 400px) {
  .ad-fonts > label > span { padding-left: 4px; padding-right: 4px; font-size: .88rem; }
  .ad-fonts .ad-font-serif { font-size: .95rem; }
  .ad-qr-modes > label > span { padding-left: 6px; padding-right: 6px; font-size: .88rem; }
}

@media (prefers-reduced-motion: no-preference) {
  .ad-start { transition: border-color .15s; }
}

/* The print panel offers "Use a quantity column" whenever there is a list. The labels here are printed from
   two columns of the page's own making (the address block and the QR code), neither of which is a quantity,
   so that one choice is left out on this page. */
.ad-print [data-kpr-choice="column"] { display: none; }
