/* certs: Certificates of insurance, version 6 (../../old/explore/DIRECTION-v6.md section 4). Markup: app/certs.js.
   Every class starts with ce-. Two columns (the form, the preview) from 1280, one under it with the preview after
   the form; Your certificates full width under them. The preview is a stylized certificate on an A4-proportioned
   sheet: its smallest text is 14, like the rest of the page, and it grows past A4 when her policies need the room.
   No font-size inside a media or container query: narrow widths change padding, gaps and columns only. */

.ce-cols {
  --ce-well-pad: var(--s-6);     /* the gray well around the sheet */
  --ce-sheet-pad: var(--s-6);
  --ce-sheet-max: 480px;
  --ce-sheet-r: 4px;             /* paper corners */
  --ce-seal: 44px;               /* the Issued seal; also the top row's height, so the seal replaces the Preview mark without a jump */
  --ce-qr: 69px;                 /* the drawn mark: 23 units of 3px, so its squares stay crisp */
  --ce-seg-pad: 3px;             /* the segmented control's track around its thumb */
  --ce-seg-h: 34px;
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--col-gap); align-items: start;
}
@media (max-width: 1279px) {
  .ce-cols { grid-template-columns: minmax(0, 1fr); gap: var(--s-7); }
  .ce-new, .ce-well { max-width: 560px; }   /* the form and its preview read as one column; the list below takes the page's width */
}
/* push: also answers to the page area's width (branch ai-drawer README, the push layout) */
@container app (max-width: 1279px) {
  .ce-cols { grid-template-columns: minmax(0, 1fr); gap: var(--s-7); }
  .ce-new, .ce-well { max-width: 560px; }}
@media (max-width: 639px) { .ce-cols { --ce-well-pad: var(--s-4); --ce-sheet-pad: var(--s-5); gap: var(--s-6); } }
@media (max-width: 479px) { .ce-cols { --ce-well-pad: var(--s-3); --ce-sheet-pad: var(--s-4); } }

/* =================================================================
   New certificate: the form
   ================================================================= */
.ce-new > h2 { margin-bottom: var(--s-5); }
.ce-form { display: grid; gap: var(--s-6); }
.ce-set legend { font-weight: 700; line-height: var(--lh-ui); }
.ce-hint { margin-top: 2px; color: var(--ink-2); font-size: var(--fs-small); line-height: var(--lh-small); }
.ce-set .err { margin-top: var(--s-2); }

/* The policies she holds: the DS checkbox, the name, the number under it; rows open on white with hairlines */
.ce-opts { margin-top: var(--s-2); }
.ce-opt { display: grid; grid-template-columns: var(--icon-lg) minmax(0, 1fr); gap: var(--s-3); align-items: start; padding: var(--s-3) 0; cursor: pointer; }
.ce-opt + .ce-opt { border-top: 1px solid var(--line); }
.ce-opt .cbox { margin-top: -1px; }                         /* centered on the name's first line */
.ce-opt:hover .cbox:not(:checked) { box-shadow: inset 0 0 0 1px var(--ink); }
.ce-ot { display: grid; min-width: 0; }
.ce-ot .n { line-height: var(--lh-ui); }
.ce-ot .s { margin-top: 2px; color: var(--ink-2); font-size: var(--fs-small); line-height: var(--lh-small); }
/* A policy bought today that starts later: listed, not available, its line says from when */
.ce-opt.is-later { cursor: default; }
.ce-opt.is-later .n { color: var(--ink-2); }
.ce-opt.is-later .cbox, .ce-opt.is-later:hover .cbox:not(:checked) { background: var(--sunk); box-shadow: inset 0 0 0 1px var(--line-2); cursor: default; }

/* Who is it for: the label, the hint under it, then the field */
.ce-field { gap: 0; }
.ce-field input { margin-top: var(--s-3); }
.ce-optl { font-weight: 400; color: var(--ink-2); }

/* The segmented control (DIRECTION.md 4.13): a --fill track, a white thumb that slides to the chosen language, a Bold label.
   Native radios underneath, so the arrow keys move the choice */
.ce-seg { position: relative; display: inline-grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); margin-top: var(--s-3); padding: var(--ce-seg-pad); border-radius: var(--r-md); background: var(--fill); }
.ce-seg label { position: relative; z-index: 1; display: grid; place-items: center; min-height: var(--ce-seg-h); padding: 0 var(--s-4); border-radius: calc(var(--r-md) - var(--ce-seg-pad)); color: var(--ink-2); font-size: var(--fs-small); line-height: var(--lh-small); cursor: pointer; transition: color var(--t-hover); }
.ce-seg label > span { display: inline-grid; justify-items: center; }
.ce-seg label > span::after { content: attr(data-t); font-weight: 700; visibility: hidden; height: 0; overflow: hidden; }   /* the Bold copy keeps the width */
.ce-seg label:hover { color: var(--ink); }
.ce-seg label:has(input:checked) { color: var(--ink); font-weight: 700; }
.ce-seg label:has(input:focus-visible) { outline: var(--v8-focus); outline-offset: 0; box-shadow: var(--v8-focus-glow); }
.ce-thumb { position: absolute; top: var(--ce-seg-pad); bottom: var(--ce-seg-pad); left: var(--ce-seg-pad); width: calc((100% - 2 * var(--ce-seg-pad)) / 3); border-radius: calc(var(--r-md) - var(--ce-seg-pad)); background: var(--canvas); box-shadow: 0 0 0 1px var(--line-2); transition: transform var(--dur-2, 200ms) var(--ease-out, var(--ease)); }
.ce-seg:has(label:nth-child(2) input:checked) .ce-thumb { transform: translateX(100%); }
.ce-seg:has(label:nth-child(3) input:checked) .ce-thumb { transform: translateX(200%); }

/* Under the form: Create certificate, or the certificate's actions once it's made. The primary keeps the Create button's place */
.ce-foot { margin-top: var(--s-2); }
.ce-ready { display: flex; align-items: flex-start; gap: var(--s-2); line-height: var(--lh-ui); }
.ce-ready svg.i { margin-top: 1px; color: var(--green); }
.ce-ready .ce-t2 { color: var(--ink-2); }   /* two-tone, as the overview's hero: what happened in ink, what she can do next in gray */
.ce-acts { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-3) var(--s-5); margin-top: var(--s-4); }
.ce-live { margin-top: var(--s-4); max-width: 56ch; color: var(--ink-2); font-size: var(--fs-small); line-height: var(--lh-small); }
.btn.ce-copied svg.i { color: var(--green); }
.link.ce-copied { gap: var(--s-1); }
.link.ce-copied svg.i { width: 16px; height: 16px; margin: 0; color: var(--green); stroke-width: 1.75; }
@media (max-width: 639px) { .ce-acts > .btn, .ce-foot > .btn { flex: 1 1 100%; width: 100%; } }

/* =================================================================
   The preview: a white sheet on the rail's gray, a hairline edge, no shadow
   ================================================================= */
.ce-well { padding: var(--ce-well-pad); border-radius: var(--r-lg); background: var(--rail-bg); }
/* push: also answers to the page area's width (branch ai-drawer README, the push layout) */
@media (min-width: 1280px) { @container app (min-width: 1280px) { .ce-well { position: sticky; top: var(--s-6); } } }   /* beside a long form, the certificate stays in view */

.ce-sheet {
  container: ce-sheet / inline-size;
  display: flex; flex-direction: column; width: 100%; max-width: var(--ce-sheet-max); aspect-ratio: 1 / 1.414; margin-inline: auto;
  padding: var(--ce-sheet-pad); border: 1px solid var(--rail-line); border-radius: var(--ce-sheet-r); background: var(--canvas);
  color: var(--ink); font-size: var(--fs-small); line-height: var(--lh-small); overflow-wrap: anywhere;
}

/* The sheet's words carry their language (lang on this wrapper) while the sheet itself, role="img", keeps its English name;
   the wrapper takes no box, so the sheet's column layout reaches its parts */
.ce-words { display: contents; }

/* The logo, and in its corner the Preview mark or the Issued seal */
.ce-top { display: flex; align-items: center; justify-content: space-between; gap: var(--s-4); min-height: var(--ce-seal); }
.ce-logo { flex: none; }
.ce-mark { display: inline-flex; align-items: center; padding: var(--s-1) var(--s-3); border: 1px dashed var(--field); border-radius: var(--r-pill); color: var(--ink-2); white-space: nowrap; }   /* dashed, like the slots: not real yet */
.ce-seal { display: inline-flex; align-items: center; gap: var(--s-2); }
.ce-seal svg { width: var(--ce-seal); height: var(--ce-seal); flex: none; overflow: visible; }
.ce-seal .ring { fill: none; stroke: var(--g-40); stroke-width: 1; }
.ce-seal .disc { fill: var(--green); }
.ce-seal .tick { fill: none; stroke: var(--inverse-ink); stroke-width: 2.25; stroke-linecap: round; stroke-linejoin: round; }
.ce-seal-t { display: grid; white-space: nowrap; }
.ce-seal-t b { font-weight: 700; }
.ce-seal-t span { color: var(--ink-2); font-variant-numeric: tabular-nums; }

/* The title (Section size), the number under it, the sentence that makes it a certificate */
.ce-ttl { margin-top: var(--s-5); }
.ce-t1 { font-size: var(--fs-section); line-height: var(--lh-section); font-weight: 700; }
.ce-no { margin-top: 2px; color: var(--ink-2); }
.ce-code { font-variant-numeric: tabular-nums; white-space: nowrap; }   /* never broken at its hyphen */
.ce-code.ce-mask { color: var(--ink-2); }
.ce-conf { margin-top: var(--s-3); max-width: 46ch; }

/* For and Policyholder: labels beside their values (never above them); in a narrow sheet, "Label: value" runs inline */
.ce-kv { display: grid; grid-template-columns: auto minmax(0, 1fr); column-gap: var(--s-5); row-gap: var(--s-2); margin: var(--s-4) 0 0; padding-top: var(--s-4); border-top: 1px solid var(--line); }
.ce-kv > div { display: grid; grid-column: 1 / -1; grid-template-columns: subgrid; }
.ce-kv dt { color: var(--ink-2); }
.ce-kv dd { margin: 0; min-width: 0; }
.ce-kv dd > span { display: block; }
@container ce-sheet (max-width: 320px) {
  .ce-kv, .ce-kv > div { display: block; }
  .ce-kv > div + div { margin-top: var(--s-2); }
  .ce-kv dt, .ce-kv dd, .ce-kv dd > span { display: inline; }
  .ce-kv dt::after { content: ": "; }
  .ce-kv dd > span + span::before { content: ", "; }
}

/* A policy: its name and number, then its period and limits, as label and value rows; values right, tabular */
.ce-pols { display: grid; gap: var(--s-4); margin: var(--s-4) 0 var(--s-5); padding-top: var(--s-4); border-top: 1px solid var(--line); }
.ce-pol { display: grid; gap: 2px; }
.ce-r { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; column-gap: var(--s-4); }
.ce-r .k { color: var(--ink-2); }
.ce-r .v { margin-left: auto; text-align: right; font-variant-numeric: tabular-nums; }
.ce-r1 .k { color: var(--ink); font-size: var(--fs-body); line-height: var(--lh-ui); font-weight: 700; }
.ce-r1 .v { color: var(--ink-2); }
.ce-none { padding: var(--s-4); border: 1px dashed var(--field); border-radius: var(--r-md); color: var(--ink-2); text-align: center; }

/* The foot of the sheet: when it's valid and where to check it, with the drawn mark */
.ce-end { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s-4); margin-top: auto; padding-top: var(--s-4); border-top: 1px solid var(--line); }
.ce-endt { min-width: 0; }
.ce-valid { font-size: var(--fs-body); line-height: var(--lh-ui); font-weight: 700; }
.ce-chk { margin-top: var(--s-1); }
.ce-note { margin-top: var(--s-1); max-width: 34ch; color: var(--ink-2); }
@container ce-sheet (max-width: 280px) { .ce-end { flex-direction: column; align-items: flex-start; } }   /* a narrow sheet: the mark under the words, not beside them */
.ce-qr { width: var(--ce-qr); height: var(--ce-qr); flex: none; color: var(--line-2); }
.ce-qr path { fill: currentColor; }
.ce-sheet.is-issued .ce-qr { color: var(--ink); }

/* =================================================================
   Your certificates: one container, a row per certificate
   ================================================================= */
.ce-list { margin-top: var(--gap-section, 80px); }   /* a section gap under the form and its preview */
.ce-list > h2 + .ce-rows { margin-top: var(--s-4); }
.ce-rows { list-style: none; margin: 0; container-type: inline-size; }
.ce-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: var(--s-2) var(--s-7); padding: var(--s-4) var(--s-5); }
.ce-row + .ce-row { border-top: 1px solid var(--line); }
.ce-rw { min-width: 0; }
.ce-rt { line-height: var(--lh-ui); }
.ce-rs { margin-top: 2px; color: var(--ink-2); font-size: var(--fs-small); line-height: var(--lh-small); }
.ce-row.is-off .ce-rt { color: var(--ink-2); }
.ce-rstate { display: grid; justify-items: start; gap: var(--s-2); font-size: var(--fs-small); line-height: var(--lh-small); white-space: nowrap; }
/* The link's state is the one status look, the badge: a green dot for on, a hollow gray dot for off */
.ce-rstate .badge.ce-off::before { background: var(--canvas); box-shadow: inset 0 0 0 1.5px #767676; }
.ce-views { color: var(--ink-2); }
.ce-racts { display: flex; justify-content: flex-end; gap: var(--s-5); white-space: nowrap; }
@container (max-width: 639px) {
  .ce-row { grid-template-columns: minmax(0, 1fr); gap: var(--s-2); }
  .ce-rstate { display: flex; flex-wrap: wrap; gap: var(--s-1) var(--s-4); }
  .ce-racts { justify-content: flex-start; }
}
@media (max-width: 639px) { .ce-row { padding-inline: var(--s-4); } }

/* =================================================================
   Motion (2.3). The issued seal, its check and the number are motion.js's (data-mo-pop, data-mo-draw, data-mo-type). Here:
   a changed part of the sheet fades in (--dur-1), and an issued certificate's mark inks in from the preview's gray.
   Reduced motion (styles.css) and "Motion: off" show the end state at once, except the changed parts' opacity fade
   ================================================================= */
@keyframes ce-fade { from { opacity: 0; } }
@keyframes ce-ink { from { color: var(--line-2); } }
.ce-sheet .ce-fade { animation: ce-fade var(--dur-1, 120ms) var(--ease-out, var(--ease)) both; }
.ce-sheet.is-new .ce-qr { animation: ce-ink var(--dur-3, 280ms) var(--ease-out, var(--ease)) calc(120ms * var(--mo-k, 1)) both; }
.ce-seal svg { transform-origin: 50% 50%; }
html[data-motion="off"] :is(.ce-sheet, .ce-sheet *, .ce-thumb, .ce-seg label), html.mo-still :is(.ce-sheet, .ce-sheet *, .ce-thumb, .ce-seg label) { animation: none !important; transition: none !important; }
/* ...except the changed parts' fade, opacity only: with reduced motion or "Motion: off" the change is still signalled (2.4) */
@media (prefers-reduced-motion: reduce) { .ce-sheet .ce-fade { animation: ce-fade var(--dur-1, 120ms) linear both !important; } }
html[data-motion="off"] .ce-sheet .ce-fade, html.mo-still .ce-sheet .ce-fade { animation: ce-fade var(--dur-1, 120ms) linear both !important; }

/* Forced colors (Windows High Contrast) drop fills and box-shadow edges: the chosen language keeps a system outline, and the
   sheet its edge */
@media (forced-colors: active) {
  .ce-seg { border: 1px solid ButtonText; }
  .ce-seg label:has(input:checked) { outline: 2px solid Highlight; outline-offset: -2px; }
  .ce-sheet { border-color: CanvasText; }
}
