/*
 * EncodeLabel: the RFID page (goes with rfid.php and assets/js/page-rfid.js).
 *
 * Only what is special to this page lives here. Buttons, boxes, tabs, tables,
 * pop-ups and form parts are the shell's (assets/css/site.css). Every colour
 * is a design token, so the light and the dark theme both work; the one thing
 * that is always black on white is the sketch of the printed label.
 *
 * Contents: the note at the top · the two-column work area · the form ·
 * the result (tag code, the coloured strip, the table, the buttons) ·
 * the bar at the bottom of a narrow screen ·
 * the printer-file pop-up · the spreadsheet and NFC tabs ·
 * how the codes are made (the worked example, filters, partitions, ZPL).
 */

/* ---- The note at the top: what this page does and does not do ---------------- */
.rf-head { margin-bottom: 16px; }
.rf-note { display: flex; align-items: flex-start; gap: 12px; max-width: 62rem; }
.rf-note p { margin: 0; }
.rf-note-icon { width: 24px; height: 24px; margin-top: 1px; color: var(--link); }
/* On a phone the heading, the lead and the note used to fill the whole first
   screen, with the form out of sight below them. There the heading is smaller,
   the lead is left out (the note's first sentence says the same) and the note
   is tighter, so the tabs and the first box are in view when the page opens. */
@media (max-width: 760px) {
  .rf-head { margin-bottom: 10px; }
  .rf-head .kicker { margin-bottom: 4px; }
  .rf-head h1 { font-size: 1.45rem; line-height: 1.2; }
  .rf-head .lead { display: none; }
  .rf-note { gap: 10px; margin-bottom: 10px; padding: 9px 12px 10px; font-size: .88rem; line-height: 1.4; }
  .rf-note-icon { width: 20px; height: 20px; margin-top: 0; }
  .rf-tabs .tab-panel { padding-top: 14px; }
}

/* ---- The work area: the form on the left, the answer on the right ------------ */
.rf-tabs { margin-bottom: 8px; }
/* All four tabs must be in sight on a phone, so the long name has a short form there. */
.rf-tab-short { display: none; }
@media (max-width: 480px) {
  .rf-tab-long { display: none; }
  .rf-tab-short { display: inline; }
  .rf-tabs .tab { padding-left: 9px; padding-right: 9px; font-size: .9rem; }
}
.rf-work { display: grid; grid-template-columns: minmax(300px, 400px) minmax(0, 1fr); gap: 20px; align-items: start; }
.rf-work > * { min-width: 0; margin-bottom: 0; }
.rf-work-even { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 900px) {
  .rf-work, .rf-work-even { grid-template-columns: minmax(0, 1fr); }
}

/* ---- The form -------------------------------------------------------------------- */
.rf-form > :last-child { margin-bottom: 0; }
.rf-form > .field:last-child { margin-bottom: 0; }
.rf-form .status-line:empty { display: none; }
.rf-form .status-line { align-items: flex-start; min-height: 0; margin-top: 6px; }
.rf-form .status-line::before { align-self: flex-start; margin-top: .5em; }
.rf-form .status-line.is-error { font-weight: 500; }
.rf-form .status-line .link-button { font-weight: 600; white-space: nowrap; }
.rf-form textarea { min-height: 88px; }
.rf-form textarea.mono { font-size: max(16px, 1rem); letter-spacing: .02em; }
.rf-form .stepper { display: flex; }
.rf-form .stepper > input { flex: 1; min-width: 0; }
.rf-card-title { margin: 0 0 6px; font-size: 1.15rem; }
.rf-gap { margin-top: 16px; }
.rf-run { margin-bottom: 0; }
.rf-run-msg { margin: -8px 0 16px; }
.rf-help-link { margin: 2px 0 0; font-size: .9rem; }
.rf-help-link .link-button { min-height: 32px; }
.rf-random { margin: -4px 0 0; }
.rf-random .hint { margin: 0 0 10px; }
.rf-random p:last-child { margin: 0; }

/* The three big choices: what goes in the tag. */
.rf-kinds { margin-bottom: 18px; }
.rf-kind {
  display: flex; align-items: flex-start; gap: 12px; min-height: 44px; margin: 0 0 8px; padding: 11px 12px;
  border: 1px solid var(--field-line); border-radius: var(--radius-small);
  background: var(--field); cursor: pointer;
}
.rf-kind:last-child { margin-bottom: 0; }
.rf-kind:hover { border-color: var(--ink); }
.rf-kind:has(input:checked) { border-color: var(--ink); background: var(--soft); box-shadow: inset 0 0 0 1px var(--ink); }
.rf-kind:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }
.rf-kind input { margin-top: 1px; }
.rf-kind input:focus-visible { outline: none; }
.rf-kind > span { display: block; min-width: 0; }
.rf-kind strong { display: block; line-height: 1.3; }
.rf-kind small { display: block; margin-top: 2px; color: var(--muted); font-size: .85rem; line-height: 1.4; }

/* A barcode number cut into its parts: your company | this product | check digit. */
.rf-split { display: flex; flex-wrap: wrap; gap: 4px; margin: 8px 0 0; }
.rf-split-part {
  display: flex; flex-direction: column; gap: 1px; min-width: 0; padding: 5px 9px 6px;
  border-radius: 3px; background: var(--rf-bg); color: var(--rf-fg);
}
.rf-split-part b { font: 700 .98rem/1.3 var(--mono); letter-spacing: .04em; }
.rf-split-part small { font-size: .7rem; line-height: 1.2; white-space: nowrap; }   /* full strength: any fading takes the small words on the blue part under 4.5:1 in the dark theme */

/* ---- The colours of the parts of a tag code -------------------------------------- */
/* Two families made from the tokens: greys for the housekeeping bits, blues for
   who and what the tag names. Each piece also carries its name in words, so
   colour is never the only clue. */
.rf-part-header    { --rf-bg: var(--ink); --rf-fg: var(--paper); }
.rf-part-filter    { --rf-bg: color-mix(in srgb, var(--ink) 62%, var(--card)); --rf-fg: var(--paper); }
.rf-part-partition { --rf-bg: color-mix(in srgb, var(--ink) 28%, var(--card)); --rf-fg: var(--ink); }
.rf-part-company   { --rf-bg: var(--brand); --rf-fg: var(--brand-ink); }
.rf-part-item      { --rf-bg: color-mix(in srgb, var(--brand) 52%, var(--card)); --rf-fg: var(--ink); }
.rf-part-serial    { --rf-bg: color-mix(in srgb, var(--brand) 20%, var(--card)); --rf-fg: var(--ink); }
.rf-part-unused    { --rf-bg: color-mix(in srgb, var(--ink) 7%, var(--card)); --rf-fg: var(--muted); }

/* ---- The result ---------------------------------------------------------------------- */
.rf-out { padding: 0; overflow: hidden; }
.rf-out-section { padding: 20px 24px; border-top: 1px solid var(--line); }
.rf-out-section:first-child { border-top: 0; }
.rf-out-section > :last-child { margin-bottom: 0; }
.rf-out-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 16px; margin: 0 0 14px; }
.rf-out-head h2 { margin: 0; font-size: 1.15rem; }
.rf-sum { margin: 0; color: var(--muted); font-size: .92rem; }
.rf-sub { margin: 0 0 10px; color: var(--muted); font: 600 .75rem/1.3 var(--mono); letter-spacing: .1em; text-transform: uppercase; }
@media (max-width: 560px) {
  .rf-out-section { padding: 16px; }
}

/* Nothing to show yet. */
.rf-empty { margin: 0; }
.rf-empty p { max-width: 30em; margin-left: auto; margin-right: auto; }

/* The buttons under the heading. */
.rf-actions { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.rf-actions .btn { width: 100%; padding-left: 10px; padding-right: 10px; }
.rf-labels { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; margin: 14px 0 0; color: var(--muted); font-size: .92rem; }
.rf-labels .btn { margin: 0; }
.rf-actions-note { margin: 10px 0 0; }
.rf-out .usage-meter { margin-top: 12px; }
@media (max-width: 700px) {
  .rf-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 480px) {
  /* Four buttons, two by two: the words matter more than the little pictures. */
  .rf-actions .btn > svg { display: none; }
}

/* The code itself, large, in groups of four so it can be read out. */
.rf-code { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin: 0 0 16px; }
.rf-hex { display: flex; flex-wrap: wrap; gap: 2px .5em; min-width: 0; font: 700 1.3rem/1.3 var(--mono); letter-spacing: .03em; }
.rf-hex > span { white-space: nowrap; }
@media (max-width: 560px) {
  .rf-hex { font-size: 1.12rem; }
}

/* The strip: one piece for each part of the code, as wide as its share of the bits. */
.rf-strip { display: flex; gap: 2px; margin: 0 0 12px; }
.rf-strip-part {
  display: grid; place-items: center; flex: var(--rf-bits) 1 0; min-width: 28px; height: 40px;
  background: var(--rf-bg); color: var(--rf-fg);
  font: 700 .78rem/1 var(--mono); overflow: hidden;
}
.rf-strip-part:first-child { border-radius: var(--radius-small) 0 0 var(--radius-small); }
.rf-strip-part:last-child { border-radius: 0 var(--radius-small) var(--radius-small) 0; }
.rf-strip-note { margin: -4px 0 12px; color: var(--muted); font-size: .8rem; }

/* What each piece holds, in the same order and colours. */
.rf-legend { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 0 0 16px; padding: 0; list-style: none; }
.rf-legend[data-rf-parts="4"] { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 560px) {
  .rf-legend, .rf-legend[data-rf-parts="4"] { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.rf-legend > li {
  min-width: 0; margin: 0; padding: 9px 12px 10px;
  border: 1px solid var(--line); border-top: 5px solid var(--rf-bg); border-radius: var(--radius-small);
  background: var(--card);
}
.rf-legend-name { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; font-size: .8rem; font-weight: 600; }
.rf-legend-name span { color: var(--muted); font: 500 .72rem/1.2 var(--mono); white-space: nowrap; }
.rf-legend-value { display: block; margin: 3px 0 2px; font: 700 1rem/1.3 var(--mono); overflow-wrap: anywhere; }
.rf-legend-what { display: block; color: var(--muted); font-size: .8rem; line-height: 1.35; }

/* Plain text: one little box per letter, with its two hex characters underneath. */
.rf-bytes { display: flex; flex-wrap: wrap; gap: 2px; margin: 0 0 12px; padding: 0; list-style: none; }
.rf-bytes > li {
  display: flex; flex: 1 1 0; flex-direction: column; align-items: center; gap: 2px; min-width: 26px; max-width: 48px; margin: 0; padding: 6px 0 5px;
  border-radius: 3px; background: var(--rf-bg); color: var(--rf-fg);
}
.rf-bytes b { font: 700 1.05rem/1.2 var(--mono); }
.rf-bytes small { font: 500 .7rem/1.2 var(--mono); opacity: .9; }

/* The same code written other ways. */
.rf-forms { margin: 0; }
.rf-forms > summary { display: inline-flex; align-items: center; min-height: 36px; color: var(--link); font-size: .92rem; font-weight: 600; cursor: pointer; }
.rf-forms dl { margin: 8px 0 0; }
.rf-forms dl > div { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 2px 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.rf-forms dt { grid-column: 1; color: var(--muted); font-size: .8rem; }
.rf-forms dd { grid-column: 1; margin: 0; font: 500 .9rem/1.4 var(--mono); overflow-wrap: anywhere; }
.rf-forms dd + .btn { grid-column: 2; grid-row: 1 / span 2; }

/* What a decoded code says, as a short list. */
.rf-facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px 20px; margin: 0 0 16px; }
.rf-facts > div { min-width: 0; }
.rf-facts dt { color: var(--muted); font-size: .8rem; }
.rf-facts dd { margin: 1px 0 0; font-weight: 600; overflow-wrap: anywhere; }
.rf-facts dd.mono { font-size: 1rem; }
.rf-kindline { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0 0 12px; font-size: 1.05rem; font-weight: 700; }
.rf-also { margin: 0 0 16px; }

/* Notes and problems. */
.rf-notes { margin: 0; padding: 0; list-style: none; }
.rf-notes > li { margin: 0 0 10px; }
.rf-notes > li:last-child { margin-bottom: 0; }
.rf-notes .alert { margin: 0; }
.rf-problems { margin: 0; }
.rf-problems h3 { margin: 0 0 6px; font-size: 1rem; }
.rf-problems ul { margin: 8px 0 0; padding-left: 1.2em; }
.rf-problems li { margin: 0 0 4px; }

/* The table of every tag. */
.rf-table-wrap { margin: 0 0 12px; }
.rf-table td { vertical-align: middle; }
.rf-table .mono { font-size: .9rem; white-space: nowrap; }
.rf-table .rf-td-n { width: 1%; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.rf-table .rf-td-epc > span { display: inline-flex; align-items: center; gap: 8px; }
.rf-table .rf-td-uri { min-width: 16ch; color: var(--muted); white-space: normal; overflow-wrap: anywhere; }
.rf-table .rf-td-text { white-space: pre; }
.rf-pager { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; }
.rf-pager p { margin: 0; color: var(--muted); font-size: .9rem; }
/* On a narrow screen each tag is a little block instead of a table row. */
@media (max-width: 640px) {
  .rf-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .rf-table, .rf-table tbody { display: block; }
  .rf-table tr { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 14px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
  .rf-table tr:last-child { border-bottom: 0; }
  .rf-table td { display: block; width: auto; min-width: 0; padding: 0; border: 0; }
  .rf-table td[data-label]::before { content: attr(data-label) " "; margin-right: 4px; color: var(--muted); font: 600 .68rem/1.3 var(--body); letter-spacing: .05em; text-transform: uppercase; }
  .rf-table .rf-td-n { width: auto; color: var(--ink); font-weight: 700; }
  /* The code and its address each get a line of their own; they need no label. */
  .rf-table .rf-td-epc, .rf-table .rf-td-uri { flex: 0 0 100%; }
  .rf-table .rf-td-epc::before, .rf-table .rf-td-uri::before { content: none !important; }
  .rf-table .rf-td-epc > span { display: flex; justify-content: space-between; gap: 8px; }
  .rf-table .mono { white-space: normal; overflow-wrap: anywhere; }
  .rf-table .rf-td-epc .mono { font-size: .88rem; letter-spacing: 0; }
  .rf-table .rf-td-uri { min-width: 0; font-size: .78rem; }
}

/* ---- The bar at the bottom of a narrow screen ------------------------------------------ */
/* When the form and the answer are one above the other (900px and narrower)
   the answer is out of sight while the form is filled in. This bar stays at
   the bottom of the screen: what has been worked out, a jump to it, and the two
   things people take away most. It is the shell's .tool-actions (site.css),
   which on a phone already sticks to the bottom edge, keeps clear of the
   phone's home bar and sits above the cookie question while that shows.
   page-rfid.js makes it (see viewOf) and gives it "hidden" until there is an
   answer; on wide screens the answer is beside the form and the bar is not used. */
.rf-bar { display: none; }
@media (max-width: 900px) {
  .rf-bar { display: flex; margin-top: 16px; transition: opacity .15s, visibility .15s; }
  /* It steps aside while the answer's own buttons are on the screen. It keeps its room, so nothing jumps. */
  .rf-bar.is-away { visibility: hidden; opacity: 0; pointer-events: none; }
  .rf-bar-info { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .rf-bar-info strong { color: var(--ink); }
  .rf-bar-code { margin-left: .5em; letter-spacing: .02em; }
  .rf-bar .btn { white-space: nowrap; }
  /* A box reached with the Tab key stops above the bar, not underneath it. */
  :root:has(.rf-bar:not([hidden]):not(.is-away)) { scroll-padding-bottom: calc(104px + var(--banner-space, 0px)); }
}
@media (min-width: 761px) and (max-width: 900px) {
  /* Wider than a phone but still one column: the shell leaves its bar in the page here, so it is made to stay in view. */
  .rf-bar {
    position: sticky; bottom: calc(12px + env(safe-area-inset-bottom) + var(--banner-space, 0px)); z-index: var(--z-sticky);
    flex-wrap: nowrap; box-shadow: var(--shadow-float);
  }
  .rf-bar .btn { flex: none; }
  body:has(.rf-bar) .toasts { bottom: calc(92px + env(safe-area-inset-bottom) + var(--banner-space, 0px)); }
}
@media (max-width: 760px) {
  /* Three buttons in a row: each as wide as its words need, sharing what is left over. */
  .rf-bar .btn { flex: 1 1 auto; padding-left: 10px; padding-right: 10px; }
}
@media (max-width: 480px) {
  .rf-bar .btn > svg { display: none; } /* the words matter more than the little pictures */
}

/* ---- The printer-file pop-up ----------------------------------------------------------- */
.rf-zpl { display: grid; grid-template-columns: minmax(260px, 340px) minmax(0, 1fr); gap: 24px; align-items: start; }
.rf-zpl > * { min-width: 0; }
.rf-zpl .status-line:empty { display: none; }
.rf-zpl-size { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; gap: 0 8px; align-items: end; }
.rf-zpl-size .field { margin-bottom: 16px; }
.rf-zpl-lines input + input { margin-top: 6px; }
.rf-zpl-more > summary { display: inline-flex; align-items: center; min-height: 36px; color: var(--link); font-size: .92rem; font-weight: 600; cursor: pointer; }
.rf-zpl-more[open] > summary { margin-bottom: 8px; }
.rf-zpl-facts { margin: 0 0 12px; font-weight: 600; }
.rf-zpl-pre {
  max-height: 190px; margin: 0 0 12px; padding: 12px 14px; overflow: auto;
  border: 1px solid var(--line); border-radius: var(--radius-small); background: var(--field);
  font-size: .8rem; line-height: 1.5; white-space: pre; tab-size: 2;
}
.rf-zpl-more-labels { margin: -6px 0 12px; color: var(--muted); font-size: .85rem; }
.rf-zpl-how { margin: 0 0 8px; font-size: .9rem; }
.rf-zpl-how:last-child { margin-bottom: 0; }
@media (max-width: 760px) {
  .rf-zpl { grid-template-columns: minmax(0, 1fr); gap: 8px; }
  .rf-zpl-pre { max-height: 200px; }
}

/* A sketch of the printed label: always black on white, like the label itself. */
.rf-sketch { display: grid; place-items: center; margin: 0 0 12px; padding: 16px; border-radius: var(--radius-small); background: var(--desk); }
.rf-sketch svg { display: block; width: auto; max-width: 100%; height: auto; max-height: 210px; border-radius: 4px; background: var(--sheet, #fff); box-shadow: var(--shadow); }
.rf-sketch-note { margin: -4px 0 12px; color: var(--muted); font-size: .8rem; }

/* ---- From a spreadsheet ------------------------------------------------------------------ */
.rf-start { max-width: 40rem; margin: 8px auto 0; padding: 36px 28px; text-align: center; }
.rf-start .bars { display: block; margin: 0 auto 16px; opacity: .45; }
.rf-start h2 { margin: 0 0 8px; }
.rf-start p { margin-left: auto; margin-right: auto; }
.rf-source { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; margin: 0 0 18px; padding: 0 0 16px; border-bottom: 1px solid var(--line); }
.rf-source > div:first-child { min-width: 0; }
.rf-source strong { display: block; overflow-wrap: anywhere; }
.rf-source p { margin: 2px 0 0; }
.rf-what { margin-bottom: 0; }
.rf-what-hint { margin: 6px 0 16px; }

/* ---- NFC ------------------------------------------------------------------------------------- */
.rf-nfc-can .status-line:empty { display: none; }
.rf-nfc-can .status-line { margin: 12px 0 8px; }
.rf-nfc-can, .rf-nfc-cannot { margin-top: 16px; }
.rf-nfc-cannot { margin-bottom: 0; }
.rf-compare .table-wrap { margin: 16px 0 12px; }
.rf-compare th { white-space: normal; }
.rf-compare tbody th { color: var(--ink); font-size: .85rem; letter-spacing: 0; text-transform: none; }
@media (max-width: 560px) {
  .rf-compare th, .rf-compare td { padding: 8px 8px; font-size: .88rem; }
  .rf-compare tbody th { font-size: .8rem; }
}

/* ---- The explainer pop-up and the questions at the bottom -------------------------------------- */
.rf-help h3 { margin: 20px 0 8px; font-size: 1rem; }
.rf-help ul { margin: 0 0 12px; padding-left: 1.2em; }
.rf-help li { margin: 0 0 8px; }
.rf-help .table-wrap { margin-bottom: 12px; }
.rf-help td.mono { white-space: nowrap; }
.rf-know { margin-bottom: 0; }

/* ---- How the codes are made: the worked example, filter values, partitions and ZPL ------------- */
.rf-learn { margin: 40px 0; }
.rf-learn h2 { margin: 0 0 12px; }
.rf-learn p { margin: 0 0 14px; }
.rf-learn .step-list { margin-bottom: 20px; }
.rf-learn .table-wrap { margin-bottom: 16px; }
.rf-learn tbody th { color: var(--ink); font-size: .85rem; letter-spacing: 0; text-transform: none; white-space: normal; }
.rf-learn td.mono { overflow-wrap: anywhere; word-break: break-all; }
.rf-answer code, .rf-uri { overflow-wrap: anywhere; }
.rf-answer { font-size: 1.05rem; }
.rf-zpl-sample { margin: 0 0 14px; font-size: .88rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.rf-zpl-notes { margin: 0 0 14px; padding-left: 1.2em; }
.rf-zpl-notes li { margin: 0 0 6px; }
@media (max-width: 560px) {
  .rf-learn { margin: 32px 0; }
  .rf-learn th, .rf-learn td { padding: 8px 8px; }
}
