/*
 * EncodeLabel kit: the barcode-type picker, the smart box and the size meter
 * (assets/js/kit-symbol.js). Only what those three need on top of site.css.
 * Every colour is one of site.css's names, so light and dark both work; the
 * little barcode samples are always black on white, like a printed label.
 */

/* ==========================================================================
   1. The smart box: one box to type in, with the barcode type along its foot
   ========================================================================== */
.ksym-input { margin: 0 0 16px; }
.ksym-box {
  border: 1px solid var(--field-line); border-radius: var(--radius-small);
  background: var(--field);
  transition: border-color .15s, box-shadow .15s;
}
/* The whole box lights up while the text part has the keyboard (kit-symbol.js sets is-focus). */
.ksym-box.is-focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 28%, transparent);
}
.ksym-box.is-error { border-color: var(--error); }
.ksym-box.is-error.is-focus { box-shadow: 0 0 0 3px color-mix(in srgb, var(--error) 24%, transparent); }
.ksym-field {
  display: block; width: 100%; min-height: 50px; max-height: 13.5em; margin: 0; padding: 13px 12px 11px;
  border: 0; border-radius: var(--radius-small) var(--radius-small) 0 0;
  background: transparent; color: var(--ink);
  font: inherit; font-size: max(16px, 1rem); line-height: 1.45; /* 16px or more stops iPhones zooming in */
  resize: none; overflow-y: auto; overflow-wrap: anywhere;
}
.ksym-field:focus-visible { border: 0; box-shadow: none; outline: 2px solid transparent; } /* the box around it shows the focus */
.ksym-foot {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; padding: 6px;
  border-top: 1px solid var(--line); border-radius: 0 0 var(--radius-small) var(--radius-small);
  background: color-mix(in srgb, var(--ink) 3%, var(--field));
}
/* The chip that names the type. It is a button: tap it to choose another. */
.ksym-chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%; min-height: 36px; margin: 0; padding: 4px 8px 4px 10px;
  border: 1px solid var(--field-line); border-radius: var(--radius-small);
  background: var(--card); color: var(--ink);
  font: 600 .92rem/1.2 var(--body); text-align: left; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color .15s, border-color .15s;
}
.ksym-chip:hover { border-color: var(--ink); }
.ksym-chip-icon, .ksym-chip-more { display: inline-flex; flex: none; }
.ksym-chip-more { color: var(--muted); }
.ksym-chip-more .icon { width: 1.05em; height: 1.05em; }
.ksym-chip-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ksym-chip-guess { flex: none; vertical-align: 0; }
.ksym-foot-note { color: var(--muted); font-size: .85rem; }
.ksym-auto { display: inline-flex; align-items: center; min-height: 36px; margin-left: auto; padding: 0 6px; font-size: .85rem; }
@media (pointer: coarse) {
  .ksym-chip, .ksym-auto { min-height: 44px; }
}

/* The line under the box, and the one-tap repair beside it. */
.ksym-status { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; min-height: 1.4rem; margin: 8px 0 0; }
/* Nothing to say: the line takes no room, so a suggestion sits at the left edge. It stays in the page for screen readers. */
.ksym-status .status-line:empty { flex: 0 0 0; min-height: 0; margin-right: -12px; padding-left: 0; }
/* A block, not the shell's one-line flex row: these sentences can run to two or three lines. */
.ksym-status .status-line { position: relative; display: block; flex: 1 1 15rem; min-width: 0; margin: 0; padding-left: 16px; }
.ksym-status .status-line::before { position: absolute; top: .52em; left: 0; }
.ksym-encoded { margin-left: .4em; color: var(--muted); font-weight: 400; overflow-wrap: anywhere; }
.ksym-encoded-value { font-family: var(--mono); font-size: .95em; color: var(--ink); }
.ksym-fix { flex: 0 1 auto; max-width: 100%; height: auto; white-space: normal; text-align: left; overflow-wrap: anywhere; }
/* A copy of that line which is never seen or read out. kit-symbol.js writes a sentence into it to learn how many
   lines it would take at this width, and so picks a wording that stays on one line (nothing under the box moves). */
.ksym-status { position: relative; }
.ksym-status .status-line.ksym-ruler {
  position: absolute; top: 0; right: 0; left: 0; flex: none; min-height: 0; margin: 0;
  visibility: hidden; pointer-events: none;
}

/* ==========================================================================
   2. The picker (a pop-up from EL.ui.dialog; a bottom sheet on phones)
   ========================================================================== */
/* A steady height, so the pop-up does not jump when a tab has fewer types in it. */
.ksym-dialog { height: min(88dvh, 780px); }
.ksym-dialog .dialog-body { display: flex; flex-direction: column; padding: 0; overflow: hidden; }
.ksym-pick { display: flex; flex: 1 1 auto; flex-direction: column; min-height: 0; }
.ksym-top { flex: none; padding: 14px 20px 6px; }
.ksym-search { position: relative; }
.ksym-search-icon {
  position: absolute; top: 0; bottom: 0; left: 12px; display: flex; align-items: center;
  color: var(--muted); pointer-events: none;
}
.ksym-search > input { padding-left: 42px; }
/* The row of tabs is wider than the pop-up, so it scrolls sideways. A soft shade at an
   edge says "there is more this way". No script is needed. Each side has two layers:
   a shade that stays at the edge of the strip ("scroll"), and a patch of the pop-up's own
   colour that travels with the tabs ("local") and covers the shade once that end of the
   row has been reached. So at the start only the right edge is shaded, at the end only
   the left, and when every tab fits neither is. */
.ksym-pick > .ksym-tabs {
  position: relative; flex: none; padding: 0 12px;
  --ksym-more: color-mix(in srgb, var(--ink) 17%, transparent);
  --ksym-more-soft: color-mix(in srgb, var(--ink) 5%, transparent);
  background:
    linear-gradient(to right, var(--card) 28px, transparent) left / 64px 100% no-repeat local,
    linear-gradient(to left, var(--card) 28px, transparent) right / 64px 100% no-repeat local,
    linear-gradient(to right, var(--ksym-more), var(--ksym-more-soft) 45%, transparent) left / 28px 100% no-repeat scroll,
    linear-gradient(to left, var(--ksym-more), var(--ksym-more-soft) 45%, transparent) right / 28px 100% no-repeat scroll;
}
/* The list scrolls here; the search box and the tabs stay where they are. */
.ksym-scroll { flex: 1 1 auto; min-height: 0; padding: 16px 20px 22px; overflow-y: auto; overscroll-behavior: contain; }
.ksym-panel { padding-top: 0; }
.ksym-blurb { margin: 0 0 14px; max-width: 46rem; color: var(--muted); font-size: .9rem; }
.ksym-count { margin: 0 0 12px; color: var(--muted); font-size: .9rem; }
.ksym-results > .empty-note { margin: 4px 0 0; }

.ksym-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(196px, 1fr)); gap: 12px;
  margin: 0; padding: 0; list-style: none;
}
.ksym-grid > li { display: flex; min-width: 0; }
/* One barcode type: a real sample, its name, and where it is used. The whole card is the button. */
.ksym-card {
  display: flex; flex: 1 1 auto; flex-direction: column; gap: 10px; width: 100%; min-width: 0; margin: 0; padding: 10px 10px 12px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--card); color: var(--ink);
  font: inherit; text-align: left; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: border-color .15s, background-color .15s;
}
.ksym-card:hover { border-color: var(--ink); }
.ksym-card[aria-current="true"] { border-color: var(--brand); background: var(--soft); box-shadow: inset 0 0 0 1px var(--brand); }
.ksym-card-words { display: block; min-width: 0; }
.ksym-card-name { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; font-weight: 650; line-height: 1.25; }
.ksym-card-name .badge { vertical-align: 0; }
.ksym-card-uses { display: block; margin-top: 4px; color: var(--muted); font-size: .85rem; line-height: 1.4; }
/* "Text only" sits above the tabs' lists as one wide row. */
.ksym-card-row { flex-direction: row; align-items: center; gap: 14px; margin-bottom: 16px; padding: 10px 12px 10px 10px; }
.ksym-card-row > .ksym-sample { flex: none; width: 132px; height: 64px; }

/* The sample: a small white label, in both themes. */
.ksym-sample {
  position: relative; display: block; height: 96px; padding: 10px;
  border: 1px solid var(--line); border-radius: 3px;
  background: var(--sheet); color: var(--sheet-ink); color-scheme: light;
  overflow: hidden;
}
.ksym-sample > svg { display: block; width: 100%; height: 100%; }
/* Until the sample is drawn (the barcode maker loads the first time): a faint ghost of one. */
.ksym-sample:not([data-ks-state="drawn"])::before {
  content: ""; position: absolute; top: 50%; left: 50%; width: 56%; height: 52%; transform: translate(-50%, -50%);
  --ghost: color-mix(in srgb, var(--sheet-ink) 9%, var(--sheet));
  background: repeating-linear-gradient(90deg, var(--ghost) 0 3px, transparent 3px 5px, var(--ghost) 5px 6px, transparent 6px 9px, var(--ghost) 9px 11px, transparent 11px 12px);
}
.ksym-sample[data-ks-dims="2d"]:not([data-ks-state="drawn"])::before {
  width: auto; height: 62%; aspect-ratio: 1;
  background:
    repeating-linear-gradient(90deg, var(--ghost) 0 4px, transparent 4px 8px),
    repeating-linear-gradient(0deg, var(--ghost) 0 4px, transparent 4px 8px);
}

@media (max-width: 560px) {
  .ksym-dialog { height: 92dvh; }
  .ksym-top { padding: 12px 16px 4px; }
  .ksym-pick > .ksym-tabs { padding: 0 8px; }
  .ksym-scroll { padding: 14px 16px calc(20px + env(safe-area-inset-bottom)); }
  /* On a phone the types are a list: sample on the left, words on the right. */
  .ksym-grid { grid-template-columns: minmax(0, 1fr); gap: 8px; }
  .ksym-card { flex-direction: row; align-items: center; gap: 12px; padding: 8px 12px 8px 8px; }
  .ksym-card > .ksym-sample, .ksym-card-row > .ksym-sample { flex: none; width: 104px; height: 68px; padding: 6px; }
  .ksym-card-row { margin-bottom: 12px; }
}

/* ==========================================================================
   3. The size meter: green, amber or red, with one honest sentence
   ========================================================================== */
.ksym-meter {
  --ksym-tone: var(--ok); --ksym-wash: var(--ok-soft);
  margin: 0 0 16px; padding: 12px 14px 13px;
  border: 1px solid var(--line); border-left: 4px solid var(--ksym-tone); border-radius: var(--radius-small);
  background: var(--card); color: var(--ink);
}
.ksym-meter.is-small { --ksym-tone: var(--warn); --ksym-wash: var(--warn-soft); }
.ksym-meter.is-too-small { --ksym-tone: var(--error); --ksym-wash: var(--error-soft); }
.ksym-meter > :last-child { margin-bottom: 0; }
.ksym-meter-state { display: flex; align-items: center; gap: 8px; margin: 0 0 10px; color: var(--ksym-tone); line-height: 1.25; }
.ksym-meter-mark {
  display: grid; flex: none; place-items: center; width: 26px; height: 26px; border-radius: var(--radius-small);
  background: var(--ksym-wash); color: var(--ksym-tone);
}
.ksym-meter-mark .icon { width: 16px; height: 16px; stroke-width: 2.6; }
.ksym-meter-figures { display: flex; flex-wrap: wrap; gap: 10px 28px; margin: 0 0 10px; }
.ksym-meter-figures > div { min-width: 0; }
.ksym-meter-figures dt { margin: 0 0 1px; color: var(--muted); font-size: .75rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; }
.ksym-meter-figures dd { margin: 0; font-size: 1.05rem; font-weight: 650; line-height: 1.3; }
.ksym-meter-also { margin-left: 2px; color: var(--muted); font-size: .85rem; font-weight: 400; white-space: nowrap; }
.ksym-meter-say { margin: 0 0 6px; font-size: .92rem; }
.ksym-meter-note { margin: 0; color: var(--muted); font-size: .85rem; }

@media (forced-colors: active) {
  .ksym-sample { forced-color-adjust: none; } /* the sample keeps its real black and white */
  .ksym-card[aria-current="true"] { outline: 2px solid Highlight; }
}
@media (prefers-reduced-motion: reduce) {
  .ksym-box, .ksym-chip, .ksym-card { transition: none; }
}
