/* KnitLab Pro components ("Machine sheet"), revision 2.
 * Reference implementation of design-system.md. Tokens only: no raw colours here.
 * CSP-safe: pages carry no style="" attributes; per-item values come from classes
 * (yarn slots .y-*, grid columns .cols-*) or data attributes.
 * Layout: grid/flex, container queries, logical properties. No absolute positioning
 * for layout; true overlays only (menus, dialogs, sheets, toasts, viewport labels).
 */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { margin: 0; background: var(--kl-enamel); color: var(--kl-ink); font-family: var(--kl-font); font-size: var(--kl-fs-body); line-height: var(--kl-lh-body); font-variant-numeric: tabular-nums; min-width: 320px; }
[hidden] { display: none !important; }
img, svg { display: block; max-width: 100%; }
svg[aria-hidden="true"] { width: 1.25em; height: 1.25em; flex: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4, p { margin: 0; }
p, li, dd, dt, td, .prose { overflow-wrap: break-word; }
h1 { font-size: var(--kl-fs-heading); line-height: var(--kl-lh-tight); font-weight: var(--kl-fw-bold); }
h2 { font-size: var(--kl-fs-title); line-height: var(--kl-lh-tight); font-weight: var(--kl-fw-bold); }
h3 { font-size: var(--kl-fs-body); line-height: var(--kl-lh-tight); font-weight: var(--kl-fw-bold); }
.small { font-size: var(--kl-fs-small); }
.caption { font-size: var(--kl-fs-caption); color: var(--kl-ink-2); }
.muted { color: var(--kl-ink-2); }
.num { font-variant-numeric: tabular-nums; }
bdi, .ltr { unicode-bidi: isolate; }
.unit { white-space: nowrap; }
a { color: var(--kl-action); text-underline-offset: 3px; }
a:hover { color: var(--kl-action-hover); }
/* Links inside running text keep a 44 px tall hit area without changing the line */
p a:not(.btn), li a:not(.btn), .caption a:not(.btn), .small a:not(.btn), .notice a:not(.btn) { display: inline-block; padding-block: 12px; margin-block: -12px; min-width: 44px; text-align: center; }
td a:not(.btn) { display: inline-flex; align-items: center; min-height: var(--kl-hit); min-width: var(--kl-hit); }
.visually-hidden { clip: rect(0 0 0 0); clip-path: inset(50%); height: 1px; width: 1px; overflow: hidden; position: absolute; white-space: nowrap; }
.skip { position: absolute; inset-inline-start: 8px; top: -80px; z-index: var(--kl-z-toast); background: var(--kl-paper); padding: 12px 16px; border-radius: var(--kl-r-control); min-height: var(--kl-hit); }
.skip:focus { top: 8px; }
ul.plain, ol.plain { margin: 0; padding: 0; list-style: none; display: grid; gap: var(--kl-s-2); }
ul.bullets { margin: 0; padding-inline-start: 1.2em; display: grid; gap: var(--kl-s-1); }

:focus { outline: none; }
:focus-visible { outline: 3px solid var(--kl-focus); outline-offset: 2px; box-shadow: 0 0 0 2px var(--kl-focus-halo); border-radius: var(--kl-r-control); }

.stack { display: flex; flex-direction: column; gap: var(--kl-s-4); min-width: 0; }
.stack-2 { display: flex; flex-direction: column; gap: var(--kl-s-2); min-width: 0; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--kl-s-2); min-width: 0; }
.row--between { justify-content: space-between; }
.row--end { justify-content: flex-end; }
.spacer { flex: 1 1 auto; }
.span-all { grid-column: 1 / -1; }
.start { justify-self: start; align-self: flex-start; }

/* ---------- Yarn slots (classes, CSP-safe). Each sets --c for swatches, tints, cams ---------- */
.y-navy { --c: var(--kl-yarn-navy); } .y-heather { --c: var(--kl-yarn-heather); } .y-white { --c: var(--kl-yarn-white); }
.y-brick { --c: var(--kl-yarn-brick); } .y-mustard { --c: var(--kl-yarn-mustard); } .y-bottle { --c: var(--kl-yarn-bottle); }
.y-black { --c: var(--kl-yarn-black); } .y-ecru { --c: var(--kl-yarn-ecru); } .y-sand { --c: var(--kl-yarn-sand); } .y-sky { --c: var(--kl-yarn-sky); }

/* =====================================================================
   Top bar
   ===================================================================== */
.topbar { display: flex; align-items: center; gap: var(--kl-s-3); min-height: 56px; padding-inline: var(--kl-gutter); background: var(--kl-paper); border-block-end: 1px solid var(--kl-line); min-width: 0; }
.brand { display: inline-flex; align-items: center; gap: 6px; text-decoration: none; color: var(--kl-brand); font-weight: 800; font-size: var(--kl-fs-title); letter-spacing: -0.01em; min-height: var(--kl-hit); flex: none; direction: ltr; }
.brand__plate { display: inline-grid; place-items: center; min-height: 22px; padding-inline: 6px; border-radius: 5px; background: var(--kl-brand); color: var(--kl-on-brand); font-size: 0.8125rem; font-weight: 800; letter-spacing: 0.06em; }
.nav { display: flex; gap: var(--kl-s-1); min-width: 0; }
.nav a { display: inline-flex; align-items: center; min-height: var(--kl-hit); padding-inline: var(--kl-s-3); border-radius: var(--kl-r-control); color: var(--kl-ink-2); text-decoration: none; white-space: nowrap; }
.nav a:hover { background: var(--kl-sunk); color: var(--kl-ink); }
.nav a[aria-current="page"] { color: var(--kl-ink); background: var(--kl-action-soft); font-weight: var(--kl-fw-medium); }
.topbar__end { display: flex; align-items: center; gap: var(--kl-s-2); margin-inline-start: auto; min-width: 0; }
.menu { position: relative; }
.menu > summary { list-style: none; cursor: pointer; }
.menu > summary::-webkit-details-marker { display: none; }
.menu__list { position: absolute; inset-inline-end: 0; top: calc(100% + 6px); z-index: var(--kl-z-popover); min-width: 240px; max-width: min(320px, calc(100vw - 24px)); background: var(--kl-paper); border-radius: var(--kl-r-panel); box-shadow: var(--kl-e2); border: 1px solid var(--kl-line); padding: var(--kl-s-2); display: grid; gap: 2px; }
.menu--start .menu__list { inset-inline-end: auto; inset-inline-start: 0; }
.menu__list a:not(:where(.toast *)), .menu__list button:not(:where(.toast *)) { display: flex; align-items: center; gap: var(--kl-s-2); min-height: var(--kl-hit); padding-inline: var(--kl-s-3); border-radius: var(--kl-r-control); color: var(--kl-ink); text-decoration: none; background: none; border: 0; text-align: start; cursor: pointer; width: 100%; margin: 0; }
.menu__list a:not(:where(.toast *)):hover, .menu__list button:not(:where(.toast *)):hover { background: var(--kl-sunk); }
.menu__list .menu__danger { color: var(--kl-danger); }
.menu__sep { height: 1px; background: var(--kl-line); margin-block: var(--kl-s-1); }
.menu__head { padding: var(--kl-s-2) var(--kl-s-3); font-size: var(--kl-fs-caption); color: var(--kl-ink-2); }
.nav-in-menu { display: none; }
@media (max-width: 899px) { .topbar .nav { display: none; } .nav-in-menu { display: contents; } }
.engine { display: inline-flex; align-items: center; gap: var(--kl-s-2); min-height: var(--kl-hit); padding-inline: var(--kl-s-3); border-radius: var(--kl-r-pill); background: var(--kl-sunk); font-size: var(--kl-fs-small); white-space: nowrap; }
.engine__long { display: inline; } .engine__short { display: none; }
@media (max-width: 599px) { .engine__long { display: none; } .engine__short { display: inline; } .topbar { gap: var(--kl-s-1); } .topbar__end { gap: 2px; } }
.lang-code { font-weight: var(--kl-fw-bold); font-size: var(--kl-fs-small); }

/* =====================================================================
   Buttons
   ===================================================================== */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--kl-s-2); min-height: var(--kl-hit); min-width: var(--kl-hit); padding-inline: var(--kl-s-4); border-radius: var(--kl-r-control); border: 1px solid var(--kl-line-strong); background: var(--kl-paper); color: var(--kl-ink); font-weight: var(--kl-fw-medium); cursor: pointer; text-decoration: none; white-space: nowrap; transition: background var(--kl-dur-1) var(--kl-ease), transform var(--kl-dur-1) var(--kl-ease); }
.btn:hover { background: var(--kl-sunk); color: var(--kl-ink); }
.btn:active { transform: scale(.985); }
.btn svg { width: 20px; height: 20px; flex: none; }
.btn--primary { background: var(--kl-action); border-color: var(--kl-action); color: var(--kl-on-action); }
.btn--primary:hover { background: var(--kl-action-hover); color: var(--kl-on-action); }
.btn--quiet { border-color: transparent; background: transparent; }
.btn--danger { color: var(--kl-danger); border-color: var(--kl-danger); }
.btn--danger-fill { background: var(--kl-danger); border-color: var(--kl-danger); color: var(--kl-paper); }
.btn--floor { min-height: var(--kl-hit-floor); padding-inline: var(--kl-s-5); }
.btn--icon { padding-inline: 0; width: var(--kl-hit); }
.btn--block { width: 100%; }
.btn[disabled], .btn[aria-disabled="true"] { background: var(--kl-sunk); border-color: var(--kl-line); color: var(--kl-ink-3); cursor: not-allowed; transform: none; }
.kbd { font-size: var(--kl-fs-caption); border: 1px solid currentColor; border-radius: 4px; padding-inline: 4px; line-height: 1.4; opacity: .8; }
@media (max-width: 599px) { .btn__label--phone-hide { display: none; } }

/* Simulate (station footer: large; design bar: compact) */
.simulate { display: inline-grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; column-gap: var(--kl-s-3); min-height: var(--kl-hit-floor); padding-inline: var(--kl-s-5); border-radius: var(--kl-r-control); border: 2px solid var(--kl-action); background: var(--kl-action); color: var(--kl-on-action); font-weight: var(--kl-fw-bold); cursor: pointer; text-align: start; min-width: 0; text-decoration: none; white-space: nowrap; }
.simulate:hover { background: var(--kl-action-hover); color: var(--kl-on-action); }
.simulate svg { width: 22px; height: 22px; }
.simulate__sub { display: block; font-weight: var(--kl-fw-regular); font-size: var(--kl-fs-caption); }
.simulate[aria-disabled="true"] { background: var(--kl-paper); color: var(--kl-ink-2); border-color: var(--kl-line-strong); cursor: default; }
.simulate--blocked[aria-disabled="true"], .simulate--blocked { border-color: var(--kl-danger); color: var(--kl-danger); background: var(--kl-danger-soft); }
.simulate--compact { min-height: var(--kl-hit); padding-inline: var(--kl-s-3); column-gap: var(--kl-s-2); border-width: 1px; }
.simulate--compact .tower { padding: 3px; gap: 2px; }
.simulate--compact .tower i { width: 7px; height: 7px; }
.spin { animation: kl-spin 1s linear infinite; }
@keyframes kl-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation: none; } }

/* =====================================================================
   Fields, steppers, selects, segmented, switch
   ===================================================================== */
.field { display: grid; gap: var(--kl-s-1); min-width: 0; align-content: start; }
.field > label, .field__label { font-size: var(--kl-fs-small); font-weight: var(--kl-fw-medium); }
.field__hint { font-size: var(--kl-fs-caption); color: var(--kl-ink-2); }
.field__error { font-size: var(--kl-fs-small); color: var(--kl-danger); display: flex; gap: var(--kl-s-1); align-items: start; }
.field__error svg { margin-top: 2px; }
.input, .select, .textarea { min-height: var(--kl-hit); width: 100%; min-width: 0; padding-inline: var(--kl-s-3); border-radius: var(--kl-r-control); border: 1px solid var(--kl-line-strong); background: var(--kl-paper); color: var(--kl-ink); }
.textarea { padding-block: var(--kl-s-2); min-height: 140px; resize: vertical; }
.select { appearance: none; padding-inline-end: 36px; background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%); background-size: 6px 6px; background-repeat: no-repeat; background-position: right 16px center, right 10px center; }
[dir="rtl"] .select { background-position: left 10px center, left 16px center; }
.input[aria-invalid="true"], .stepper[data-invalid] { border-color: var(--kl-danger); box-shadow: inset 0 0 0 1px var(--kl-danger); }
.input[readonly] { background: var(--kl-sunk); }
.stepper { display: grid; grid-template-columns: var(--kl-hit) minmax(0, 1fr) var(--kl-hit); border: 1px solid var(--kl-line-strong); border-radius: var(--kl-r-control); background: var(--kl-paper); min-width: 0; overflow: hidden; }
.stepper button { border: 0; background: transparent; min-height: var(--kl-hit); min-width: var(--kl-hit); cursor: pointer; font-size: 1.25rem; color: var(--kl-ink); }
.stepper button:hover { background: var(--kl-sunk); }
.stepper button[disabled] { color: var(--kl-ink-3); cursor: not-allowed; }
.stepper__value { display: flex; align-items: center; justify-content: center; gap: 4px; border-inline: 1px solid var(--kl-line); min-width: 0; direction: ltr; }
.stepper__value input { border: 0; background: transparent; width: 100%; min-width: 3ch; text-align: end; padding: 0; min-height: var(--kl-hit); }
/* focus-ring: the design system's focus block. A number field's ring is its box's, the stepper's; the field inside draws none. */
.stepper__value input:focus-visible { outline: none; box-shadow: none; }
.stepper:focus-within { outline: 3px solid var(--kl-focus); outline-offset: 2px; }
/* focus-ring: end */
.stepper__unit { color: var(--kl-ink-2); font-size: var(--kl-fs-small); white-space: nowrap; padding-inline-end: var(--kl-s-2); }
.stepper--changed { border-color: var(--kl-action); box-shadow: inset 0 0 0 1px var(--kl-action); }
/* Segmented: every option is a full hit target; options never wrap; the group wraps as a whole */
.seg { display: inline-flex; flex-wrap: wrap; background: var(--kl-sunk); border: 1px solid var(--kl-line-strong); border-radius: var(--kl-r-control); padding: 2px; gap: 2px; min-width: 0; max-width: 100%; }
.seg > button, .seg > a { flex: 1 0 auto; display: flex; align-items: center; justify-content: center; gap: 6px; min-height: var(--kl-hit); min-width: var(--kl-hit); padding-inline: var(--kl-s-3); border: 0; border-radius: calc(var(--kl-r-control) - 3px); background: transparent; color: var(--kl-ink-2); cursor: pointer; white-space: nowrap; font-weight: var(--kl-fw-medium); text-decoration: none; }
.seg > [aria-pressed="true"], .seg > [aria-selected="true"], .seg > [aria-current="true"] { background: var(--kl-paper); color: var(--kl-ink); box-shadow: 0 0 0 1px var(--kl-line-strong); }
.seg > button[disabled] { color: var(--kl-ink-3); cursor: not-allowed; }
.seg svg { width: 18px; height: 18px; }
.seg--floor > button { min-height: var(--kl-hit-floor); }
.seg--block { display: flex; width: 100%; }
.seg--block > button { flex: 1 0 auto; }
.switch { display: flex; align-items: center; gap: var(--kl-s-3); min-height: var(--kl-hit); cursor: pointer; }
.switch input { appearance: none; width: 48px; height: 28px; border-radius: 14px; background: var(--kl-line-strong); position: relative; flex: none; cursor: pointer; margin: 0; }
.switch input::after { content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 22px; height: 22px; border-radius: 50%; background: var(--kl-paper); transition: inset-inline-start var(--kl-dur-1) var(--kl-ease); }
.switch input:checked { background: var(--kl-action); }
.switch input:checked::after { inset-inline-start: 23px; }
.switch input:disabled { opacity: .5; cursor: not-allowed; }
.choice { display: flex; align-items: center; gap: var(--kl-s-3); min-height: var(--kl-hit); cursor: pointer; }
.choice input { width: 24px; height: 24px; accent-color: var(--kl-action); margin: 0; flex: none; }
progress { appearance: none; -webkit-appearance: none; width: 100%; height: 8px; border: 0; border-radius: 4px; background: var(--kl-sunk); overflow: hidden; display: block; }
progress::-webkit-progress-bar { background: var(--kl-sunk); border-radius: 4px; }
progress::-webkit-progress-value { background: var(--kl-ok-lamp); border-radius: 4px; }
progress::-moz-progress-bar { background: var(--kl-ok-lamp); }
progress.meter::-webkit-progress-value { background: var(--kl-action); }
progress.meter::-moz-progress-bar { background: var(--kl-action); }
.progress-wait { height: 8px; border-radius: 4px; background: repeating-linear-gradient(90deg, var(--kl-caution-lamp) 0 8px, var(--kl-sunk) 8px 16px); }

/* =====================================================================
   Panels, folds, lamps, badges, notices
   ===================================================================== */
.panel { background: var(--kl-paper); border-radius: var(--kl-r-panel); box-shadow: var(--kl-e1); min-width: 0; }
.panel__body { padding: var(--kl-s-4); display: grid; gap: var(--kl-s-4); min-width: 0; }
.panel__body--roomy { padding: var(--kl-s-5); gap: var(--kl-s-5); }
.fold > summary { list-style: none; cursor: pointer; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: var(--kl-s-3); padding: var(--kl-s-2) var(--kl-s-4); min-height: 56px; border-radius: var(--kl-r-panel); }
.fold > summary::-webkit-details-marker { display: none; }
.fold > summary:hover { background: var(--kl-sunk); }
.fold__title { display: flex; flex-wrap: wrap; align-items: baseline; column-gap: var(--kl-s-3); row-gap: 2px; min-width: 0; }
.fold__title h2, .fold__title h3 { font-size: var(--kl-fs-body); }
.fold__summary { font-size: var(--kl-fs-small); color: var(--kl-ink-2); min-width: 0; }
.fold__chev { width: 20px; height: 20px; color: var(--kl-ink-2); transition: transform var(--kl-dur-2) var(--kl-ease); }
.fold[open] > summary .fold__chev { transform: rotate(180deg); }
.fold__body { padding: 0 var(--kl-s-4) var(--kl-s-4); display: grid; gap: var(--kl-s-4); min-width: 0; }
.fold--plain > summary { padding-inline: 0; }
.fold--plain > .fold__body { padding-inline: 0; }
.fold[data-level="danger"] { border-inline-start: 4px solid var(--kl-danger-lamp); }
.fold[data-level="caution"] { border-inline-start: 4px solid var(--kl-caution-lamp); }
.attention { font-weight: var(--kl-fw-bold); color: var(--kl-danger); }
.attention--caution { color: var(--kl-caution); }

.lamp { display: inline-block; width: 12px; height: 12px; border-radius: 50%; background: var(--kl-idle-lamp); box-shadow: 0 0 0 2px var(--kl-paper), 0 0 0 3px var(--kl-line-strong); flex: none; }
.lamp--ok { background: var(--kl-ok-lamp); } .lamp--caution { background: var(--kl-caution-lamp); } .lamp--danger { background: var(--kl-danger-lamp); } .lamp--info { background: var(--kl-action); }
.lamp--pulse { animation: kl-breathe 2.4s ease-in-out infinite; }
@keyframes kl-breathe { 50% { opacity: .45; } }
.tower { display: inline-grid; gap: 3px; padding: 4px; border-radius: 8px; background: var(--kl-tower-housing); flex: none; align-self: center; }
.tower i { width: 10px; height: 10px; border-radius: 50%; background: var(--kl-tower-off); display: block; }
.tower[data-lit="danger"] i:nth-child(1) { background: var(--kl-tower-red); box-shadow: 0 0 8px var(--kl-tower-red); }
.tower[data-lit="caution"] i:nth-child(2), .tower[data-lit="wait"] i:nth-child(2) { background: var(--kl-tower-amber); box-shadow: 0 0 8px var(--kl-tower-amber); }
.tower[data-lit="ok"] i:nth-child(3), .tower[data-lit="run"] i:nth-child(3) { background: var(--kl-tower-green); box-shadow: 0 0 8px var(--kl-tower-green); }
.tower[data-lit="run"] i:nth-child(3) { animation: kl-breathe 1.6s ease-in-out infinite; }
.tower[data-lit="wait"] i:nth-child(2) { animation: kl-breathe 2.4s ease-in-out infinite; }
@media (prefers-reduced-motion: reduce) { .tower i, .lamp--pulse { animation: none !important; } }

.badge { display: inline-flex; align-items: center; gap: 6px; min-height: 28px; padding: 2px 10px; border-radius: var(--kl-r-pill); font-size: var(--kl-fs-small); font-weight: var(--kl-fw-medium); background: var(--kl-sunk); color: var(--kl-ink-2); white-space: nowrap; }
.badge--ok { background: var(--kl-ok-soft); color: var(--kl-ok); } .badge--caution { background: var(--kl-caution-soft); color: var(--kl-caution); } .badge--danger { background: var(--kl-danger-soft); color: var(--kl-danger); } .badge--info { background: var(--kl-info-soft); color: var(--kl-info); }
.badge svg { width: 16px; height: 16px; }
.lvl { display: inline-flex; align-items: center; min-height: 22px; padding-inline: 6px; border-radius: 6px; border: 1px solid var(--kl-line-strong); font-size: var(--kl-fs-caption); font-weight: var(--kl-fw-bold); color: var(--kl-ink-2); white-space: nowrap; }

.notice { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: var(--kl-s-3); padding: var(--kl-s-3) var(--kl-s-4); border-radius: var(--kl-r-control); background: var(--kl-sunk); align-items: start; }
.notice > svg { width: 20px; height: 20px; margin-top: 2px; }
.notice--danger { background: var(--kl-danger-soft); } .notice--danger > svg { color: var(--kl-danger); }
.notice--caution { background: var(--kl-caution-soft); } .notice--caution > svg { color: var(--kl-caution); }
.notice--ok { background: var(--kl-ok-soft); } .notice--ok > svg { color: var(--kl-ok); }
.notice--info { background: var(--kl-info-soft); } .notice--info > svg { color: var(--kl-info); }
.notice__actions { grid-column: 2; display: flex; flex-wrap: wrap; gap: var(--kl-s-2); }

.toast { display: flex; flex-wrap: wrap; align-items: center; gap: var(--kl-s-3); max-width: min(560px, 100%); padding: var(--kl-s-2) var(--kl-s-2) var(--kl-s-2) var(--kl-s-4); border-radius: var(--kl-r-panel); background: var(--kl-ink); color: var(--kl-on-ink); box-shadow: var(--kl-e2); }
.toast .btn { background: transparent; color: var(--kl-on-ink); border-color: var(--kl-on-ink); }
.empty { display: grid; justify-items: center; text-align: center; gap: var(--kl-s-3); padding: var(--kl-s-7) var(--kl-s-4); color: var(--kl-ink-2); }
.empty > svg { width: 56px; height: 56px; color: var(--kl-graph-strong); }
.empty h2 { color: var(--kl-ink); }

/* Dialogs and sheets */
.dialog { border: 0; padding: 0; border-radius: var(--kl-r-sheet); background: var(--kl-paper); color: var(--kl-ink); box-shadow: var(--kl-e3); width: min(520px, calc(100vw - 32px)); max-height: calc(100svh - 32px); }
.dialog::backdrop { background: var(--kl-scrim); }
.dialog__head { padding: var(--kl-s-5) var(--kl-s-5) var(--kl-s-2); }
.dialog__body { padding: var(--kl-s-2) var(--kl-s-5); display: grid; gap: var(--kl-s-4); }
.dialog__foot { padding: var(--kl-s-4) var(--kl-s-5) var(--kl-s-5); display: flex; flex-wrap: wrap-reverse; justify-content: flex-end; gap: var(--kl-s-2); }
.dialog--static { display: block; position: static; margin: 0; width: auto; max-width: 100%; }
.sheet { border-radius: var(--kl-r-sheet) var(--kl-r-sheet) 0 0; background: var(--kl-paper); box-shadow: var(--kl-e3); }
.sheet__grip { width: 40px; height: 5px; border-radius: 3px; background: var(--kl-line-strong); margin: 8px auto; }

/* Tables (cards under 640 px of container) */
.table-wrap { overflow-x: auto; border-radius: var(--kl-r-panel); box-shadow: var(--kl-e1); background: var(--kl-paper); max-width: 100%; container-type: inline-size; }
.table-wrap--flat { box-shadow: none; }
.table { width: 100%; border-collapse: collapse; font-size: var(--kl-fs-small); }
.table th, .table td { text-align: start; padding: var(--kl-s-2) var(--kl-s-3); border-block-end: 1px solid var(--kl-line); vertical-align: middle; }
.table thead th { font-weight: var(--kl-fw-medium); color: var(--kl-ink-2); background: var(--kl-sunk); white-space: nowrap; }
.table .num { text-align: end; white-space: nowrap; }
.table tr:last-child > * { border-block-end: 0; }
.table tbody th { font-weight: var(--kl-fw-medium); min-width: 12ch; }
@container (max-width: 520px) {
  .table--stack table, .table--stack tbody, .table--stack tr, .table--stack td, .table--stack tbody th { display: block; width: 100%; }
  .table--stack thead { display: none; }
  .table--stack tr { padding: var(--kl-s-3) var(--kl-s-4); border-block-end: 1px solid var(--kl-line); display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 120px), 1fr)); gap: var(--kl-s-2) var(--kl-s-3); }
  .table--stack td, .table--stack tbody th { border: 0; padding: 0; text-align: start; min-width: 0; }
  .table--stack td[data-label]::before { content: attr(data-label); display: block; font-size: var(--kl-fs-caption); color: var(--kl-ink-2); font-weight: var(--kl-fw-regular); }
  .table--stack [data-wide] { grid-column: 1 / -1; }
}
.spec { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: var(--kl-s-4); margin: 0; }
.spec dt, .spec dd { margin: 0; padding-block: var(--kl-s-2); border-block-end: 1px solid var(--kl-line); min-width: 0; }
.spec dt { color: var(--kl-ink-2); }
.spec dd { text-align: end; font-weight: var(--kl-fw-medium); max-width: 22ch; }
.spec .unit { color: var(--kl-ink-2); font-weight: var(--kl-fw-regular); }
.spec > :nth-last-child(-n+2) { border-block-end: 0; }
.source { font-size: var(--kl-fs-caption); color: var(--kl-ink-2); display: flex; gap: 6px; align-items: center; }

.gate { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: var(--kl-s-3); padding: var(--kl-s-3); border: 1px dashed var(--kl-line-strong); border-radius: var(--kl-r-control); color: var(--kl-ink-2); background: var(--kl-sunk); }
.gate > svg { width: 20px; height: 20px; }

/* Yarn chips */
.yarn { display: inline-flex; align-items: center; gap: var(--kl-s-2); min-height: var(--kl-hit); padding-inline: 6px var(--kl-s-3); border: 1px solid var(--kl-line-strong); border-radius: var(--kl-r-pill); background: var(--kl-paper); cursor: pointer; white-space: nowrap; min-width: 0; }
.swatch-dot { width: 30px; height: 30px; border-radius: 50%; background: var(--c); box-shadow: inset 0 0 0 1px var(--kl-yarn-edge); flex: none; background-image: repeating-linear-gradient(-55deg, var(--kl-veil) 0 1px, transparent 1px 6px); background-blend-mode: soft-light; }
.yarn__name { font-weight: var(--kl-fw-medium); }
.yarn__count { color: var(--kl-ink-2); font-size: var(--kl-fs-small); }
.yarn[aria-pressed="true"] { border-color: var(--kl-action); box-shadow: inset 0 0 0 1px var(--kl-action); }
.slots { display: flex; flex-wrap: wrap; gap: 4px; }
.slot { width: var(--kl-hit); height: var(--kl-hit); border-radius: 50%; border: 2px solid transparent; display: grid; place-items: center; background: none; cursor: pointer; padding: 0; }
.slot[aria-pressed="true"] { border-color: var(--kl-action); }
.slot[disabled] { cursor: not-allowed; opacity: .35; }

/* =====================================================================
   Member page shell
   ===================================================================== */
.page { display: grid; grid-template-columns: minmax(0, 1fr); max-width: 1120px; margin-inline: auto; padding: var(--kl-s-6) var(--kl-gutter) var(--kl-s-8); gap: var(--kl-s-5); }
.page--narrow { max-width: 520px; }
.page__head { display: grid; gap: var(--kl-s-2); }
.page__lede { color: var(--kl-ink-2); max-width: var(--kl-measure); }
.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: var(--kl-s-4); }
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); gap: var(--kl-s-4); align-items: start; }
.two-col--wide { grid-template-columns: repeat(auto-fit, minmax(min(100%, 400px), 1fr)); }
.form-grid { display: grid; gap: var(--kl-s-4); grid-template-columns: repeat(auto-fill, minmax(min(100%, 200px), 1fr)); align-items: start; }
.foot { padding: var(--kl-s-5) var(--kl-gutter); color: var(--kl-ink-2); font-size: var(--kl-fs-small); display: flex; flex-wrap: wrap; gap: var(--kl-s-2) var(--kl-s-4); justify-content: center; align-items: center; }
.foot a { display: inline-flex; align-items: center; min-height: var(--kl-hit); }
.pcard { display: grid; grid-template-rows: auto 1fr auto; background: var(--kl-paper); border-radius: var(--kl-r-panel); box-shadow: var(--kl-e1); overflow: hidden; min-width: 0; }
.pcard__media { aspect-ratio: 16 / 9; background: var(--kl-table); display: grid; grid-template-columns: 1fr 1fr; overflow: hidden; }
.pcard__media > svg { width: 100%; height: 100%; max-width: none; }
.pcard__media--one { grid-template-columns: 1fr; }
.pcard__photo { display: grid; place-items: center; align-content: center; gap: 6px; background: var(--kl-sunk); color: var(--kl-ink-2); font-size: var(--kl-fs-caption); text-align: center; padding: var(--kl-s-2); }
.pcard__body { padding: var(--kl-s-3) var(--kl-s-4); display: grid; gap: 4px; min-width: 0; }
.pcard__actions { display: flex; flex-wrap: wrap; gap: var(--kl-s-2); padding: 0 var(--kl-s-4) var(--kl-s-4); }
.landing-hero { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 360px), 1fr)); gap: var(--kl-s-6); align-items: center; }
.display { font-size: var(--kl-fs-display); line-height: 1.05; }
.steps { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr)); gap: var(--kl-s-4); margin: 0; padding: 0; list-style: none; counter-reset: step; }
.steps li { counter-increment: step; display: grid; gap: var(--kl-s-2); padding: var(--kl-s-4); background: var(--kl-paper); border-radius: var(--kl-r-panel); box-shadow: var(--kl-e1); }
.steps li::before { content: counter(step); display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--kl-action-soft); color: var(--kl-action); font-weight: var(--kl-fw-bold); }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); gap: var(--kl-s-4); align-items: start; }
.specimen { display: grid; gap: var(--kl-s-2); align-content: start; min-width: 0; }
.specimen > h3 { font-size: var(--kl-fs-small); color: var(--kl-ink-2); font-weight: var(--kl-fw-medium); }
.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: var(--kl-s-2); }
.swatch { border-radius: var(--kl-r-control); box-shadow: var(--kl-e1); overflow: hidden; background: var(--kl-paper); font-size: var(--kl-fs-caption); }
.swatch i { display: block; height: 48px; background: var(--sw); }
.swatch div { padding: 6px 8px; }

/* =====================================================================
   EDITOR SHELL
   Rows: top bar / design bar / main / dock. Height = small viewport (svh), so
   the on-screen keyboard never squeezes the shell; the focused field scrolls
   into view inside its own column.
   ===================================================================== */
.app { display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; height: 100vh; height: 100svh; min-height: 0; }
.main { min-height: 0; min-width: 0; overflow-y: auto; display: flex; flex-direction: column; }

/* Design bar */
.docbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--kl-s-2); padding: 6px var(--kl-gutter); background: var(--kl-paper); border-block-end: 1px solid var(--kl-line); min-width: 0; }
.docbar__name { display: flex; align-items: center; gap: var(--kl-s-2); min-width: 0; flex: 1 1 220px; }
.docbar__name .select { max-width: 340px; font-weight: var(--kl-fw-medium); }
.docbar__actions { display: flex; flex-wrap: wrap; gap: var(--kl-s-2); align-items: center; }
.docbar__wide { display: contents; }
.docbar__more-phone { display: none; }
@media (max-width: 599px) {
  .docbar { flex-wrap: nowrap; }
  .docbar__name { flex: 1 1 auto; }
  .docbar__name .badge { display: none; }
  .docbar__wide { display: none; }
  .docbar__more-phone { display: block; }
  .docbar__more-phone > summary .more__word { display: none; }
  .docbar__name .select { min-width: 0; }
}

/* Machine bar: one line; facts scroll sideways; the form expands inline */
.machinebar { background: var(--kl-sunk); border-block-end: 1px solid var(--kl-line); }
.machinebar > summary { list-style: none; cursor: pointer; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: var(--kl-s-2); padding: 4px var(--kl-gutter); min-height: 52px; }
.machinebar > summary::-webkit-details-marker { display: none; }
.facts { display: flex; gap: var(--kl-s-2); min-width: 0; overflow-x: auto; scrollbar-width: none; padding-block: 4px; }
.facts::-webkit-scrollbar { display: none; }
.fact { display: inline-flex; align-items: baseline; gap: 4px; padding: 2px 10px; border-radius: var(--kl-r-pill); background: var(--kl-paper); box-shadow: var(--kl-e1); font-size: var(--kl-fs-small); white-space: nowrap; flex: none; }
.fact--danger { box-shadow: inset 0 0 0 2px var(--kl-danger-lamp); color: var(--kl-danger); font-weight: var(--kl-fw-bold); }
.machinebar__form { padding: var(--kl-s-2) var(--kl-gutter) var(--kl-s-4); container-type: inline-size; }
.mark-danger { border-radius: var(--kl-r-control); box-shadow: 0 0 0 3px var(--kl-danger-lamp); }

/* Workspace columns */
.workspace { flex: 1 1 auto; container-type: inline-size; container-name: ws; padding: var(--kl-s-3) var(--kl-gutter); min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.ws-grid { flex: 1 1 auto; display: grid; gap: var(--kl-s-4); grid-template-columns: minmax(0, 1fr); align-items: start; min-height: 0; }
.pane { min-width: 0; display: grid; gap: var(--kl-s-3); align-content: start; }
.side { min-width: 0; display: grid; gap: var(--kl-s-3); align-content: start; }
.side__scroll { display: grid; gap: var(--kl-s-3); align-content: start; min-width: 0; }
.drawer-handle { display: none; }
.dock { display: none; }

/* --- Phone and short screens: ONE scroller (.main) holding everything --- */
@media (max-width: 599px), (max-height: 559px) {
  .ws-grid { grid-template-areas: "fabric" "foot" "design" "results"; }
  .app .side, .app .side__scroll { display: contents; }
  .app .pane--fabric { grid-area: fabric; } .app .station__foot { grid-area: foot; } .app .pane--design { grid-area: design; } .app .pane--results { grid-area: results; }
}
/* --- A short screen (a phone turned sideways, at most 500 px tall): the page is the one scroller, so the top bar and the
   machine bar scroll away and the design bar (Simulate, Undo) stays on top; under 600 px wide the dock stays at the foot
   (its padding keeps the safe area), and the Fabric pane's footer goes with the page. The work has the screen's height
   but the bars'. The chart's sticky band and strip stick under the design bar, and whatever is scrolled into view stops
   clear of both bars (--kl-bar-h, --kl-dock-h: their heights, pro/Shell.js). UI v2 keeps its own arrangement
   (pro-v2.css). --- */
@media (max-height: 500px) {
  .app:not(.app--v2) { height: auto; min-height: 100svh; }
  .app:not(.app--v2) .main { overflow: visible; }
  .app:not(.app--v2) > .docbar { position: sticky; top: 0; z-index: var(--kl-z-dock); }
  .app:not(.app--v2) > .dock { position: sticky; bottom: 0; z-index: var(--kl-z-dock); }
  .app:not(.app--v2)[data-pane="fabric"] .station__foot { position: static; }
  .app:not(.app--v2) .chart-headband { top: var(--kl-bar-h, 0px); }
  .app:not(.app--v2) .chart-bandstrip { top: calc(var(--kl-bar-h, 0px) + var(--kl-band-h, 0px)); }
  html:has(.app:not(.app--v2)) { scroll-padding-block: calc(var(--kl-bar-h, 0px) + 4px) calc(var(--kl-dock-h, 0px) + 4px); }
}
@media (max-width: 599px) {
  .app[data-pane] .pane--design, .app[data-pane] .pane--fabric, .app[data-pane] .pane--results, .app[data-pane] .station__foot { display: none; }
  .app[data-pane="design"] .pane--design, .app[data-pane="results"] .pane--results { display: grid; }
  .app[data-pane="fabric"] .pane--fabric, .app[data-pane="fabric"] .station__foot { display: grid; }
  .app[data-pane="design"] .machinebar, .app[data-pane="design"] .tools--inline { display: block; }
  .app[data-pane]:not([data-pane="design"]) .machinebar { display: none; }
  .dock { display: grid; gap: 4px; padding: 4px var(--kl-gutter) calc(4px + env(safe-area-inset-bottom)); background: var(--kl-paper); border-block-start: 1px solid var(--kl-line); z-index: var(--kl-z-dock); }
  .dock__panes { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 2px; }
  .dock__panes button { display: flex; align-items: center; justify-content: center; gap: 6px; min-height: var(--kl-hit); border: 0; background: transparent; border-radius: var(--kl-r-control); color: var(--kl-ink-2); font-size: var(--kl-fs-small); cursor: pointer; min-width: var(--kl-hit); white-space: nowrap; }
  .dock__panes button svg { width: 22px; height: 22px; }
  .dock__panes button[aria-pressed="true"] { color: var(--kl-action); background: var(--kl-action-soft); font-weight: var(--kl-fw-bold); }
  .app:not([data-pane="design"]) .dock__tools { display: none; }
  .tools--inline { display: none !important; }
}
@media (max-width: 359px) { .dock__panes .dock__label { display: none; } }

/* --- Tablet portrait (600-959 wide, ≥ 700 tall): chart above, fabric drawer below --- */
@media (min-width: 600px) and (max-width: 959px) and (min-height: 700px) {
  .main { overflow: hidden; }
  .workspace { overflow: hidden; }
  .ws-grid { height: 100%; align-items: stretch; grid-template-rows: minmax(0, 1fr) auto; grid-template-areas: "design" "side"; }
  .pane--design { grid-area: design; overflow-y: auto; min-height: 0; padding-block-end: var(--kl-s-3); }
  .side { grid-area: side; grid-template-rows: auto minmax(0, 1fr) auto; min-height: 0; gap: 0; border-block-start: 1px solid var(--kl-line-strong); background: var(--kl-enamel); }
  .app[data-drawer="half"] .side { height: 46svh; }
  .app[data-drawer="full"] .ws-grid { grid-template-rows: 0 minmax(0, 1fr); }
  .app[data-drawer="full"] .pane--design { visibility: hidden; }
  .side__scroll { overflow-y: auto; min-height: 0; padding-block: var(--kl-s-2); }
  .drawer-handle { display: flex; align-items: center; gap: var(--kl-s-2); padding-block: 4px; flex-wrap: wrap; }
  .dock { display: grid; grid-template-columns: minmax(0, 1fr); padding: 4px var(--kl-gutter) calc(4px + env(safe-area-inset-bottom)); background: var(--kl-paper); border-block-start: 1px solid var(--kl-line); }
  .dock__panes { display: none; }
  .tools--inline { display: none !important; }
  .pane--side-viewport .viewport { aspect-ratio: auto; height: clamp(200px, 26svh, 420px); }
}
@media (min-width: 600px) and (max-width: 959px) and (max-height: 699px) and (min-height: 560px) {
  .ws-grid { grid-template-areas: "fabric" "foot" "design" "results"; }
  .app .side, .app .side__scroll { display: contents; }
  .app .pane--fabric { grid-area: fabric; } .app .station__foot { grid-area: foot; } .app .pane--design { grid-area: design; } .app .pane--results { grid-area: results; }
}

/* --- Wide (≥ 960 × 560): one scroller per column; the station footer is pinned --- */
@media (min-width: 960px) and (min-height: 560px) {
  .main { overflow: hidden; }
  .workspace { overflow: hidden; padding-block: var(--kl-s-3) 0; }
  .ws-grid { height: 100%; align-items: stretch; grid-template-columns: minmax(0, .85fr) minmax(0, 1.15fr); }
  .pane--design { overflow-y: auto; min-height: 0; padding-block-end: var(--kl-s-4); padding-inline-end: 4px; }
  .side { grid-template-rows: minmax(0, 1fr) auto; min-height: 0; gap: 0; }
  .side__scroll { overflow-y: auto; min-height: 0; padding-block-end: var(--kl-s-3); padding-inline-end: 4px; }
}
@container ws (min-width: 1500px) {
  .ws-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1.65fr); }
  .side__scroll { grid-template-columns: minmax(0, 1.1fr) minmax(300px, 380px); align-items: start; }
  .side__scroll > .pane--fabric { position: sticky; top: 0; }
}
@container ws (min-width: 1700px) { .side__scroll { grid-template-columns: minmax(0, 1.25fr) 400px; } }

/* Drawer handle */
.drawer-handle .sheet__grip { margin: 0 var(--kl-s-1); }

/* Dock (phone, tablet portrait): stitch palette + undo/redo; Simulate lives in the design bar */
.dock__tools { display: flex; gap: var(--kl-s-2); min-width: 0; overflow-x: auto; scrollbar-width: none; align-items: center; }

/* Tool palette (brush model, context-switched) */
.tools { display: flex; flex-wrap: wrap; gap: var(--kl-s-2); align-items: center; }
.tool { display: inline-flex; align-items: center; gap: 6px; min-height: var(--kl-hit-floor); min-width: var(--kl-hit-floor); padding-inline: var(--kl-s-3); border-radius: var(--kl-r-control); border: 1px solid var(--kl-line-strong); background: var(--kl-paper); cursor: pointer; font-weight: var(--kl-fw-medium); white-space: nowrap; flex: none; }
.tool svg { width: 26px; height: 26px; }
.tool[aria-pressed="true"] { background: var(--kl-action); color: var(--kl-on-action); border-color: var(--kl-action); }
.tool--swatch .swatch-dot { width: 26px; height: 26px; }
.tools__sep { width: 1px; align-self: stretch; background: var(--kl-line); margin-inline: 2px; flex: none; }
.tools__label { font-size: var(--kl-fs-caption); color: var(--kl-ink-2); white-space: nowrap; }
/* Every stitch brush shows its mark and its word at every width (the column brush under 600 px and in a narrow design
   pane: Finish, below). Needle mode's Stitches shows its icon alone on phones; its word is its spoken name. */
@media (max-width: 599px) { .tool--back .tool__word { display: none; } }

/* ---------- The chart ---------- */
.chart-frame { background: var(--kl-paper); border-radius: var(--kl-r-panel); box-shadow: var(--kl-e1); min-width: 0; display: grid; }
.chart-meta { display: flex; flex-wrap: wrap; gap: var(--kl-s-2); align-items: center; padding: var(--kl-s-2) var(--kl-s-3); border-block-end: 1px solid var(--kl-line); font-size: var(--kl-fs-small); }
/* Horizontal scroll only: the pane is the one vertical scroller */
.chart-scroll { overflow-x: auto; overflow-y: hidden; max-width: 100%; direction: ltr; background:
  linear-gradient(to right, var(--kl-paper) 30%, transparent) left / 24px 100% no-repeat local,
  linear-gradient(to left, var(--kl-paper) 30%, transparent) right / 24px 100% no-repeat local,
  linear-gradient(to right, var(--kl-shadow), transparent) left / 10px 100% no-repeat scroll,
  linear-gradient(to left, var(--kl-shadow), transparent) right / 10px 100% no-repeat scroll; }
.cam { border-collapse: separate; border-spacing: var(--kl-cell-gap); margin: var(--kl-s-2); direction: ltr; }
.cam th, .cam td { padding: 0; text-align: center; vertical-align: middle; }
.cam .stick { position: sticky; z-index: var(--kl-z-sticky); background: var(--kl-paper); }
.cam .stick-1 { left: 0; }
.cam .stick-2 { left: calc(var(--kl-cell) + var(--kl-cell-gap)); }
.cam .head { font-size: var(--kl-fs-caption); color: var(--kl-ink-2); font-weight: var(--kl-fw-medium); white-space: nowrap; padding-inline: 4px; height: 28px; }
.cam .head--split { border-inline-start: 2px solid var(--kl-graph-strong); }
.cam .buttno { height: 28px; font-size: var(--kl-fs-caption); font-weight: var(--kl-fw-bold); color: var(--kl-ink-2); }
.cam .bed { font-size: var(--kl-fs-caption); color: var(--kl-ink-2); }
.cell, .rowhead { width: var(--kl-cell); height: var(--kl-cell); min-width: var(--kl-cell); border-radius: var(--kl-r-cell); border: 1px solid var(--kl-line-strong); background: var(--kl-cell-bg); color: var(--kl-knit); display: grid; place-items: center; cursor: pointer; padding: 0; position: relative; }
.cell > svg { width: calc(var(--kl-cell) * .62); height: calc(var(--kl-cell) * .62); }
/* Marks (the default display): Λ ⊓ − on the 44 grid over the whole cell, in the cell's colour; the cell keeps its tint
   and the yarn stays in the row's swatch */
.cam .cell[data-a] > svg { width: 100%; height: 100%; }
.cams-pieces .cam .cell[data-a] > svg { width: calc(var(--kl-cell) * .62); height: calc(var(--kl-cell) * .62); }
.cell[data-a="K"] { background: var(--kl-tint-knit); }
.cell[data-a="T"] { background: var(--kl-tint-tuck); }
.cell[data-a="M"] { color: var(--kl-miss); }
/* Cam pieces (the other display): the cam in the yarn colour with an ink edge, over the steel rail */
.cams-pieces .cell > svg { fill: var(--c, var(--kl-ink)); stroke: var(--kl-ink); stroke-width: 1.6px; color: var(--kl-line-strong); }
.cams-pieces .cell[data-a="M"] > svg { fill: var(--kl-line-strong); }
.cell--sel { outline: 3px solid var(--kl-action); outline-offset: 1px; }
.cell--warn { box-shadow: inset 0 0 0 3px var(--kl-caution-lamp); }
.cell--danger { box-shadow: inset 0 0 0 3px var(--kl-danger-lamp); }
.cell__flag { position: absolute; top: -7px; right: -7px; width: 18px; height: 18px; border-radius: 50%; background: var(--kl-danger-lamp); color: var(--kl-paper); font-size: var(--kl-fs-caption); font-weight: var(--kl-fw-bold); line-height: 18px; text-align: center; }
.cell--trace { outline: 2px dashed var(--kl-action); outline-offset: -5px; }
.cell--yarn { border-radius: 50%; border-color: transparent; background: none; }
.rowhead { font-weight: var(--kl-fw-bold); font-size: var(--kl-fs-small); color: var(--kl-ink); background: var(--kl-sunk); border-color: var(--kl-line); grid-template-rows: 1fr auto; gap: 0; padding-block: 2px; }
.rowhead svg { width: 16px; height: 16px; color: var(--kl-ink-2); }
.rowhead[aria-expanded="true"], .rowhead--sel { background: var(--kl-action-soft); border-color: var(--kl-action); }
.rowmenu { position: relative; }
.rowmenu > summary { list-style: none; }
.rowmenu > summary::-webkit-details-marker { display: none; }
.rowmenu .menu__list { inset-inline-end: auto; inset-inline-start: calc(100% + 6px); top: 0; }
.gap-col { width: 8px; min-width: 8px; }
/* Needle strips: one per bed; rib gating offsets the dial strip by half a needle */
.strip { display: grid; grid-auto-flow: column; grid-auto-columns: var(--kl-cell); gap: var(--kl-cell-gap); justify-content: start; }
.strip--rib { padding-inline-start: calc((var(--kl-cell) + var(--kl-cell-gap)) / 2); }
.needle { width: var(--kl-cell); height: var(--kl-cell); border-radius: var(--kl-r-cell); border: 1px solid var(--kl-line-strong); background: var(--kl-cell-bg); display: grid; grid-template-rows: 1fr auto; place-items: center; cursor: pointer; padding: 3px 0; font-weight: var(--kl-fw-bold); font-size: var(--kl-fs-small); }
.needle__butt { display: grid; grid-template-rows: repeat(4, 3px); gap: 1px; width: 14px; }
.needle__butt i { background: var(--kl-line); border-radius: 1px; }
.needle__butt i.on { background: var(--kl-ink); }
.needle--empty { color: var(--kl-ink-3); background: var(--kl-sunk); border-style: dashed; }
.needle--echo, .nn--echo { opacity: .55; }
.needle--b, .nn--b { box-shadow: -2px 0 0 var(--kl-graph-strong); }
.nn { width: var(--kl-cell); height: 24px; display: grid; place-items: center; color: var(--kl-ink); }
.nn > svg { width: 22px; height: 22px; }
.nn--empty { color: var(--kl-ink-3); }
.nstack { display: grid; gap: 2px; }
.bedtag { font-size: var(--kl-fs-caption); color: var(--kl-ink-2); width: 52px; text-align: start; }
.chart-foot { display: flex; flex-wrap: wrap; gap: var(--kl-s-2); align-items: center; padding: var(--kl-s-2) var(--kl-s-3); border-block-start: 1px solid var(--kl-line); }
/* The foot: the hidden-butts note, then one legend line of three entries, each an 18 px mark and its word, in the display
   shown (the marks in their cells' colours; the cam pieces with the ink outline on --kl-line-strong). When the entries do
   not share one line the page takes the tight gap, then the short words (Chart.fitLegend). */
.chart-foot__note { flex: 1 1 100%; }
.legend { flex: 1 1 100%; display: flex; flex-wrap: wrap; gap: var(--kl-s-1) var(--kl-s-2); font-size: var(--kl-fs-caption); color: var(--kl-ink-2); align-items: center; }
.legend--tight { column-gap: var(--kl-s-1); }
.legend > span { position: relative; display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.legend > span > svg { width: 18px; height: 18px; flex: none; color: var(--kl-knit); }
.legend > [data-a="M"] > svg { color: var(--kl-miss); }
.legend.cams-pieces > span > svg { fill: var(--kl-line-strong); stroke: var(--kl-ink); color: var(--kl-ink); }
.dir { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }

/* Two-colour grid */
.pgrid { display: grid; gap: var(--kl-cell-gap); direction: ltr; padding: var(--kl-s-2); width: max-content; grid-template-columns: 32px repeat(var(--cols, 8), var(--kl-cell)); }
.cols-8 { --cols: 8; } .cols-32 { --cols: 32; }
.pgrid button { width: var(--kl-cell); height: var(--kl-cell); border-radius: var(--kl-r-cell); border: 1px solid var(--kl-line-strong); background: var(--c1); cursor: pointer; padding: 0; }
.pgrid button.c2 { background: var(--c2); }
.pgrid .lbl { display: grid; place-items: center; font-size: var(--kl-fs-caption); color: var(--kl-ink-2); min-height: 28px; }
.pgrid .col--bad { box-shadow: 0 0 0 3px var(--kl-danger-lamp); }
.colors-ecru-mustard { --c1: var(--kl-yarn-ecru); --c2: var(--kl-yarn-mustard); }
.tiling { display: grid; grid-template-columns: repeat(24, 10px); gap: 0; direction: ltr; border: 1px solid var(--kl-line); width: max-content; }
.tiling i { width: 10px; height: 10px; background: var(--c1); }
.tiling i.c2 { background: var(--c2); }
.limits { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 200px), 1fr)); gap: var(--kl-s-2); }
.limit { display: flex; align-items: center; gap: var(--kl-s-2); padding: var(--kl-s-2) var(--kl-s-3); background: var(--kl-sunk); border-radius: var(--kl-r-control); font-size: var(--kl-fs-small); min-height: var(--kl-hit); }

/* ---------- Fabric station ---------- */
.station { background: var(--kl-paper); border-radius: var(--kl-r-panel); box-shadow: var(--kl-e1); display: grid; min-width: 0; container-type: inline-size; container-name: station; overflow: hidden; }
.station__bar { display: flex; flex-wrap: wrap; gap: var(--kl-s-2); padding: var(--kl-s-2); border-block-end: 1px solid var(--kl-line); }
.station__bar .seg { flex: 1 1 auto; }
/* Viewport: the scale is fixed by --mm (pixels per millimetre): 16 mm across */
.viewport { --mm: calc((100cqw - 28px) / 15.5); display: grid; grid-template-columns: 28px minmax(0, 1fr); grid-template-rows: 28px minmax(0, 1fr); background: var(--kl-table); direction: ltr; aspect-ratio: 4 / 3; max-height: 60svh; overflow: hidden; container-type: inline-size; }
@container station (min-width: 600px) { .viewport { aspect-ratio: 16 / 10; } }
.ruler { background: var(--kl-paper); color: var(--kl-ink-2); font-size: var(--kl-fs-caption); overflow: hidden; display: flex; }
.ruler--x { grid-column: 2; grid-row: 1; background-image: repeating-linear-gradient(90deg, var(--kl-ink-3) 0 1px, transparent 1px var(--mm)); background-size: 100% 6px; background-repeat: no-repeat; background-position: 0 100%; }
.ruler--y { grid-column: 1; grid-row: 2; flex-direction: column; background-image: repeating-linear-gradient(180deg, var(--kl-ink-2) 0 2px, transparent 2px calc(var(--mm) * 5)), repeating-linear-gradient(180deg, var(--kl-ink-3) 0 1px, transparent 1px var(--mm)); background-size: 14px 100%, 6px 100%; background-repeat: no-repeat; background-position: 100% 0, 100% 0; }
.ruler--x span { flex: none; width: calc(var(--mm) * 5); text-align: end; padding-inline-end: 3px; line-height: 20px; border-inline-end: 1px solid var(--kl-ink-2); }

.ruler--corner { grid-column: 1; grid-row: 1; display: grid; place-items: center; background: var(--kl-paper); font-size: var(--kl-fs-caption); color: var(--kl-ink-2); }
.viewport__stage { grid-column: 2; grid-row: 2; display: grid; min-width: 0; min-height: 0; overflow: hidden; }
.viewport__stage > * { grid-area: 1 / 1; min-width: 0; min-height: 0; }
.viewport__stage > svg.fabric { width: calc(var(--mm) * 40); height: auto; max-width: none; }
.viewport__overlay { display: grid; grid-template-rows: auto 1fr auto; justify-items: start; padding: var(--kl-s-2); gap: var(--kl-s-2); pointer-events: none; }
.viewport__overlay > * { pointer-events: auto; }
.viewport__overlay .scalebar { grid-row: 3; }
.viewport__center { display: grid; place-items: center; align-content: center; padding: var(--kl-s-4); text-align: center; gap: var(--kl-s-2); background: var(--kl-table); }
.viewport__center > svg { width: 40px; height: 40px; color: var(--kl-graph-strong); }
.stale-tag { max-width: 100%; display: inline-flex; gap: 6px; align-items: center; padding: 6px 12px; border-radius: var(--kl-r-pill); background: var(--kl-paper); color: var(--kl-caution); font-weight: var(--kl-fw-bold); font-size: var(--kl-fs-small); box-shadow: var(--kl-e2); }
.hatch { background: repeating-linear-gradient(45deg, var(--kl-veil) 0 1.5px, transparent 1.5px 12px); box-shadow: inset 0 0 0 10px var(--kl-veil); }
.scalebar { display: inline-flex; align-items: center; gap: 6px; font-size: var(--kl-fs-caption); color: var(--kl-ink); background: var(--kl-paper); padding: 2px 8px; border-radius: var(--kl-r-pill); }
.scalebar i { display: block; width: calc(var(--mm) * 2); height: 6px; border: 2px solid var(--kl-ink); border-top: 0; }
.station__ctl { display: flex; flex-wrap: wrap; gap: var(--kl-s-2); align-items: center; padding: var(--kl-s-2) var(--kl-s-3); border-block-start: 1px solid var(--kl-line); }
.station__ctl[hidden] { display: none; }
.zoom { display: inline-grid; grid-template-columns: var(--kl-hit) auto var(--kl-hit); align-items: center; border: 1px solid var(--kl-line-strong); border-radius: var(--kl-r-control); overflow: hidden; }
.zoom button { border: 0; background: none; min-height: var(--kl-hit); min-width: var(--kl-hit); cursor: pointer; font-size: 1.2rem; }
.zoom output { padding-inline: var(--kl-s-2); font-size: var(--kl-fs-small); white-space: nowrap; border-inline: 1px solid var(--kl-line); min-height: var(--kl-hit); display: grid; place-items: center; }
/* Pinned footer of the fabric column */
.station__foot { display: grid; gap: var(--kl-s-2); padding: var(--kl-s-3); background: var(--kl-paper); border-radius: var(--kl-r-panel); box-shadow: var(--kl-e1); min-width: 0; container-type: inline-size; }
.station__go { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--kl-s-2); align-items: center; }
@container (min-width: 460px) { .station__go { grid-template-columns: minmax(0, 1fr) auto; } }
/* Beside the status words Simulate takes at most half of the footer's row, so a long second line wraps inside it and the
   title keeps its room (layout check 19). */
@container (min-width: 460px) { .station__go > .simulate:not(.simulate--compact) { max-width: min(24rem, 50cqi); } }
.status { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: var(--kl-s-3); align-items: start; }
.status__text { display: grid; gap: 2px; min-width: 0; }
.status__title { font-weight: var(--kl-fw-bold); }
.status__line { color: var(--kl-ink-2); font-size: var(--kl-fs-small); }
.provenance { font-size: var(--kl-fs-caption); color: var(--kl-ink-2); }
@media (min-width: 600px) and (max-width: 959px) and (min-height: 700px) { .station__foot { border-radius: 0; box-shadow: none; border-block-start: 1px solid var(--kl-line); padding-block: var(--kl-s-2); } }

/* Checks */
.checks { display: grid; gap: var(--kl-s-2); margin: 0; padding: 0; list-style: none; }
.check { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: var(--kl-s-2) var(--kl-s-3); padding: var(--kl-s-3); border-radius: var(--kl-r-control); background: var(--kl-sunk); }
.check--danger { background: var(--kl-danger-soft); } .check--caution { background: var(--kl-caution-soft); }
.check__icon { width: 22px; height: 22px; margin-top: 1px; }
.check--danger .check__icon { color: var(--kl-danger); } .check--caution .check__icon { color: var(--kl-caution); }
.check__level { font-size: var(--kl-fs-caption); font-weight: var(--kl-fw-bold); }
.check--danger .check__level { color: var(--kl-danger); } .check--caution .check__level { color: var(--kl-caution); }
.check__fix { grid-column: 2; display: flex; flex-wrap: wrap; gap: var(--kl-s-2); }

/* Loop diagram */
.loopdiag { overflow-x: auto; overflow-y: hidden; direction: ltr; background: var(--kl-paper); border-radius: var(--kl-r-control); box-shadow: inset 0 0 0 1px var(--kl-line); }
.loopdiag svg { max-width: none; }
.ld-needle { fill: var(--kl-ink-2); }
.ld-label { fill: var(--kl-ink-2); font-size: 13px; font-family: var(--kl-font); }
.ld-boundary { stroke: var(--kl-graph-strong); }
.ld-yarn { stroke: var(--c, var(--kl-ink)); }
.ld-bw .ld-yarn { stroke: var(--kl-ink); }

/* Compare mode */
.compare { display: grid; gap: var(--kl-s-3); }
.variants { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(170px, 1fr); gap: var(--kl-s-2); overflow-x: auto; overflow-y: hidden; padding-block-end: 4px; }
.variant { display: grid; gap: 4px; padding: var(--kl-s-2); border-radius: var(--kl-r-control); border: 1px solid var(--kl-line-strong); background: var(--kl-paper); cursor: pointer; text-align: start; min-width: 0; color: var(--kl-ink); }
.variant[aria-pressed="true"] { border-color: var(--kl-action); box-shadow: inset 0 0 0 2px var(--kl-action); }
.variant[aria-disabled="true"] { opacity: .6; cursor: not-allowed; }
.variant svg { width: 100%; height: 56px; border-radius: 6px; }
.wipe { display: grid; grid-template-columns: minmax(0, 55fr) var(--kl-hit) minmax(0, 45fr); direction: ltr; border-radius: var(--kl-r-panel); overflow: hidden; box-shadow: var(--kl-e1); aspect-ratio: 16 / 10; background: var(--kl-table); }
.wipe > div { display: grid; min-width: 0; overflow: hidden; }
.wipe > div > * { grid-area: 1 / 1; }
.wipe svg.fabric { width: 100%; height: 100%; max-width: none; }
.wipe__label { align-self: start; justify-self: start; margin: 8px; background: var(--kl-paper); }
.wipe__grip { display: grid; place-items: center; background: var(--kl-paper); border-inline: 2px solid var(--kl-ink); cursor: ew-resize; min-height: var(--kl-hit); color: var(--kl-ink); border-block: 0; padding: 0; }
.wipe__grip svg { width: 20px; height: 20px; }
.delta { font-weight: var(--kl-fw-bold); white-space: nowrap; }
.delta--up { color: var(--kl-ok); } .delta--down { color: var(--kl-danger); } .delta--same { color: var(--kl-ink-3); font-weight: var(--kl-fw-regular); }
.app[data-mode="compare"] .pane--design > :not(.compare) { display: none; }
.app:not([data-mode="compare"]) .compare { display: none; }

/* Spec card (1080 px image, shown scaled) */
.speccard { width: 100%; max-width: 540px; background: var(--kl-card-bg, var(--kl-paper)); color: var(--kl-ink); border-radius: var(--kl-r-panel); box-shadow: var(--kl-e2); overflow: hidden; display: grid; font-size: var(--kl-fs-caption); }
.speccard__head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px var(--kl-s-3); padding: var(--kl-s-3) var(--kl-s-4); border-block-end: 1px solid var(--kl-line); }
.speccard__head b { font-size: var(--kl-fs-body); }
.speccard__top { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.speccard__pic { aspect-ratio: 1 / 1; display: grid; overflow: hidden; background: var(--kl-table); }
.speccard__pic svg { width: 100%; height: 100%; max-width: none; }
.speccard__facts { padding: var(--kl-s-3); display: grid; gap: 4px; align-content: start; }
.speccard__section { padding: var(--kl-s-2) var(--kl-s-4); border-block-start: 1px solid var(--kl-line); display: grid; gap: var(--kl-s-2); }
.speccard__chart { display: flex; flex-wrap: wrap; gap: var(--kl-s-3); direction: ltr; }
.speccard__foot { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: var(--kl-s-3); align-items: center; padding: var(--kl-s-3) var(--kl-s-4); border-block-start: 1px solid var(--kl-line); }
.qr { width: 72px; height: 72px; }
.minichart { border-collapse: separate; border-spacing: 2px; direction: ltr; }
.minichart td, .minichart th { width: 22px; height: 22px; padding: 0; text-align: center; font-size: var(--kl-fs-caption); color: var(--kl-ink-2); font-weight: var(--kl-fw-regular); }
.minichart td { border: 1px solid var(--kl-line-strong); border-radius: 3px; background: var(--kl-cell-bg); }
.minichart td svg { width: 18px; height: 18px; margin: auto; }
.minichart td[data-a="K"] { background: var(--kl-tint-knit); }
.minichart td[data-a="T"] { background: var(--kl-tint-tuck); }
.minichart td[data-a] { color: var(--kl-knit); }
.minichart td[data-a="M"] { color: var(--kl-miss); }
.minichart.cams-pieces td svg { fill: var(--c, var(--kl-ink)); stroke: var(--kl-ink); color: var(--kl-line-strong); }
.minichart.cams-pieces td[data-a="M"] svg { fill: var(--kl-line-strong); }
.legend-yarns { display: grid; gap: 4px; }
.legend-yarns > div { display: flex; align-items: center; gap: var(--kl-s-2); }
.legend-yarns .swatch-dot { width: 18px; height: 18px; }

/* Very narrow phones (320-379): the top bar keeps words but tightens */
@media (max-width: 379px) {
  .topbar { padding-inline: 12px; }
  .brand { font-size: 1.0625rem; }
  .topbar .btn { padding-inline: 8px; }
  .lang-globe { display: none; }
  .seg > button, .seg > a { padding-inline: 10px; }
  .engine { padding-inline: 8px; gap: 6px; }
  .docbar { padding-inline: 12px; }
}

/* Dock palette stays on one line; undo/redo move into the More menu on phones */
.dock .tools { flex-wrap: nowrap; }
@media (max-width: 599px) { .dock__tools > .btn, .dock__tools > .tools__sep { display: none; } }
@media (max-width: 599px) {
  .docbar__actions { flex-wrap: nowrap; }
  .app[data-pane] .ws-grid { grid-template-areas: none; }
  .app[data-pane] .pane--fabric, .app[data-pane] .station__foot, .app[data-pane] .pane--design, .app[data-pane] .pane--results { grid-area: auto; }
}
/* The open machine form never takes the whole column: it scrolls within 45 % of the height */
@media (min-width: 600px) and (min-height: 560px) {
  .machinebar[open] .machinebar__form { max-height: 45svh; overflow-y: auto; }
}
.facts { -webkit-mask-image: linear-gradient(to right, var(--kl-ink) calc(100% - 24px), transparent); mask-image: linear-gradient(to right, var(--kl-ink) calc(100% - 24px), transparent); }
[dir="rtl"] .facts { -webkit-mask-image: linear-gradient(to left, var(--kl-ink) calc(100% - 24px), transparent); mask-image: linear-gradient(to left, var(--kl-ink) calc(100% - 24px), transparent); }
/* Group labels over one-column butt groups may wrap instead of widening the columns */
.cam th.head:not(.head--split):not(.stick), .cam .head[colspan="1"] { white-space: normal; max-width: calc(var(--kl-cell) * 2 + var(--kl-cell-gap)); line-height: 1.25; }
@media (max-width: 599px) {
  .docbar__name { flex: 1 1 0; min-width: 96px; }
  .docbar .simulate--compact { flex: none; }
}

/* ===== Chart band, Simulate, drawer and station ===== */
/* The header band is sticky inside the pane and scrolls sideways with the chart */
.cam { table-layout: fixed; width: max-content; }
.cam col.c-cell { width: var(--kl-cell); } .cam col.c-gap { width: 8px; }
.nn-8 { --nn: 8; } .nn-32 { --nn: 32; }
.cam--rib { --ribpad: calc((var(--kl-cell) + var(--kl-cell-gap)) / 2); }
.cam col.c-strip { width: calc(var(--nn) * var(--kl-cell) + (var(--nn) - 1) * var(--kl-cell-gap) + var(--ribpad, 0px)); }
.chart-headband { position: sticky; top: 0; z-index: calc(var(--kl-z-sticky) + 3); background: var(--kl-paper); overflow-x: auto; overflow-y: hidden; direction: ltr; border-block-end: 1px solid var(--kl-line); scrollbar-width: thin; box-shadow: 0 4px 8px -6px var(--kl-shadow); }
.chart-headband .cam, .chart-scroll .cam { margin-block: 4px; }
.head--setout { text-align: start; }
.cam-mini th, .cam-mini td { height: 26px; font-size: var(--kl-fs-caption); color: var(--kl-ink-2); font-weight: var(--kl-fw-regular); background: var(--kl-sunk); }
.cam-mini .stick { background: var(--kl-sunk); }
.strip--mini span { width: var(--kl-cell); text-align: center; font-size: var(--kl-fs-caption); line-height: 22px; }
/* Compact Simulate = lamp + % under 360 */
.simulate__short { display: none; font-variant-numeric: tabular-nums; }
@media (max-width: 359px) { .docbar .simulate__label { display: none; } .docbar .simulate__short { display: inline; } .docbar .simulate--compact { padding-inline: 8px; } }
.docbar__undo-phone { display: none; }
@media (max-width: 599px) { .docbar__undo-phone { display: inline-flex; } }
/* Peek is a 160 px fabric band plus a one-line footer */
.newfab { display: none; align-items: center; gap: 6px; min-height: var(--kl-hit); padding-inline: var(--kl-s-3); border-radius: var(--kl-r-pill); border: 1px solid var(--kl-action); background: var(--kl-action-soft); color: var(--kl-action); font-weight: var(--kl-fw-bold); cursor: pointer; white-space: nowrap; }
.app[data-newresult] .newfab { display: inline-flex; }
.app[data-newresult] .drawer-handle .sheet__grip { background: var(--kl-action); animation: kl-breathe 1.6s ease-in-out infinite; }
@media (prefers-reduced-motion: reduce) { .app[data-newresult] .drawer-handle .sheet__grip { animation: none; } }
@media (min-width: 600px) and (max-width: 959px) and (min-height: 700px) {
  .app[data-drawer="peek"] .side__scroll { overflow: hidden; padding-block: 0; }
  .app[data-drawer="peek"] .pane--results, .app[data-drawer="peek"] .station__bar, .app[data-drawer="peek"] .station__ctl { display: none; }
  .app[data-drawer="peek"] .station { border-radius: 0; box-shadow: none; }
  .app[data-drawer="peek"] .viewport { aspect-ratio: auto; height: 160px; }
  .app[data-drawer="peek"] .status__line, .app[data-drawer="peek"] .prov { display: none; }
  .station__go { grid-template-columns: minmax(0, 1fr) auto; }
  .app[data-mode="compare"] .wipe { aspect-ratio: 4 / 3; }
}
/* One-row station bar and one-row footer on wide screens; provenance folds to one line */
.station__bar .seg > button { padding-inline: 10px; }
@media (min-width: 960px) { .station__bar { flex-wrap: nowrap; } .station__bar .seg { flex: 1 1 auto; } }
.prov > summary { list-style: none; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-height: var(--kl-hit); display: flex; align-items: center; }
.prov > summary::-webkit-details-marker { display: none; }
.prov[open] > summary { display: none; }
/* Chips wrap from 600 px; the blocking chip takes its own line; sideways scroll only on phones */
@media (min-width: 600px) {
  .facts { flex-wrap: wrap; overflow: visible; -webkit-mask-image: none; mask-image: none; }
  .fact--alarm { flex-basis: 100%; justify-content: flex-start; }
}
@media (max-width: 599px) { .fact--sl { order: -2; } .fact--needles { order: -1; } .fact--alarm { order: -3; } }
/* Vertical ruler numbers (labels end at their tick, never cut) */
.ruler--y span { flex: none; height: calc(var(--mm) * 5); display: flex; align-items: flex-end; justify-content: flex-start; padding-inline-start: 2px; line-height: 1.1; }

/* y-ruler labels: a label that would not fit wraps out of the 28 px column entirely (never half-cut) */
.ruler--y { flex-wrap: wrap; align-content: flex-start; }
.ruler--y span { width: 28px; }
.viewport__overlay > * { max-width: 100%; }
.stale-tag { white-space: normal; }
.station__prov { padding: 0 var(--kl-s-3) var(--kl-s-2); }

.viewport__overlay { grid-template-columns: minmax(0, 1fr); }
.station__bar { padding-block: 6px; }
@container station (max-width: 620px) { .station__bar .seg svg { display: none; } }
@media (min-width: 600px) and (max-width: 959px) and (min-height: 700px) { .app[data-drawer="peek"] .ruler--y span { visibility: hidden; } }
.simulate:not(.simulate--compact) { white-space: normal; max-width: 100%; }
@container station (max-width: 620px) { .station__bar { gap: 4px; padding-inline: 6px; } .station__bar .seg > button { padding-inline: 6px; } .station__bar .seg { gap: 0; } }
.station { grid-template-columns: minmax(0, 1fr); }
@media (min-width: 960px) and (max-height: 760px) {
  .machinebar > summary { min-height: 48px; padding-block: 2px; }
  .workspace { padding-block-start: 8px; }
  .station__bar { padding-block: 4px; }
}
.toast > span { min-width: 0; overflow-wrap: anywhere; flex: 1 1 12ch; }
.viewport__overlay { justify-items: stretch; }
.viewport__overlay > .stale-tag, .viewport__overlay > .scalebar { justify-self: start; min-width: 0; }
.stale-tag { overflow-wrap: break-word; }
.viewport__stage { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }
@media (min-width: 600px) and (max-width: 959px) and (min-height: 700px) {
  .app[data-drawer="peek"] .viewport__center .small, .app[data-drawer="peek"] .scalebar { display: none; }
  .app[data-drawer="peek"] .viewport__center { padding: var(--kl-s-2); gap: 4px; }
}
@media (max-width: 599px) { .docbar .simulate--running .simulate__label { display: none; } .docbar .simulate--running .simulate__short { display: inline; } }

/* ===== Column plan, station labels, palette and bars ===== */
/* Band and body share one column plan; the table width is explicit so text never widens a column */
.nc-2 { --nc: 2; } .nc-4 { --nc: 4; } .nc-6 { --nc: 6; }
.cam { width: calc(var(--kl-cell) * (2 + var(--nc)) + 8px + var(--nn) * var(--kl-cell) + (var(--nn) - 1) * var(--kl-cell-gap) + var(--ribpad, 0px) + (var(--nc) + 5) * var(--kl-cell-gap)); }
.cam .head { white-space: normal; overflow-wrap: normal; }
.cam .buttno--split { box-shadow: inset 2px 0 0 var(--kl-graph-strong); }
.cam .head--setout, .cam .head--setout .dir { text-align: left; justify-content: flex-start; }
.cam .head--setout { white-space: nowrap; }
/* Short station labels where the station is narrow (Farsi; English keeps its words) */
.ls { display: none; }
@container station (max-width: 700px) { [dir="rtl"] .station__bar .lf { display: none; } [dir="rtl"] .station__bar .ls { display: inline; } }
/* One-line running footer: progress becomes the top border */
.station__foot--running progress { order: -1; height: 4px; }
@media (min-width: 960px) and (max-height: 800px) { .station__foot .status__line { display: none; } }
@media (min-width: 600px) and (max-width: 959px) and (min-height: 700px) { .station__foot--running .status__line { display: none; } }
/* Palette in one row on landscape and desktop; the column brush under 520 px of column (Finish, below) */
.pane--design { container-type: inline-size; container-name: dpane; }
@media (min-width: 960px) { .tools--inline, .tools--inline .tools { flex-wrap: nowrap; } }
/* No wrapping in the top bar and machine bar labels */
.topbar__end > * { flex: none; }
.topbar .btn, .topbar .btn > span, .machinebar .btn > span, .engine > span { white-space: nowrap; }
/* Shop floor on narrow phones, in the lab's top bar (brand, engine chip, language and account menus): its two 56 px
   menus need the bar tightened up to 420 px (as standard density does under 380 px). Under 380 px they leave the engine
   chip no room for its words, so the chip shows its lamp and keeps the words as its status text for a screen reader
   (visually hidden, never removed); the lamp then takes a shape per state, so the state is never told by colour alone:
   online a disc, offline two bars (waiting), unavailable a cross, connecting a ring. The member pages' bar has one menu
   and keeps its words. */
@media (max-width: 419px) {
  :root[data-density="floor"] .app > .topbar { padding-inline: 12px; }
  :root[data-density="floor"] .app > .topbar .brand { font-size: 1.0625rem; }
  :root[data-density="floor"] .app > .topbar .btn { padding-inline: 8px; }
  :root[data-density="floor"] .app > .topbar .lang-globe { display: none; }
  :root[data-density="floor"] .app > .topbar .engine { padding-inline: 8px; gap: 6px; }
}
@media (max-width: 379px) {
  :root[data-density="floor"] .app > .topbar .engine { position: relative; padding-inline: var(--kl-s-3); }
  :root[data-density="floor"] .app > .topbar .engine > .engine__short { clip: rect(0 0 0 0); clip-path: inset(50%); height: 1px; width: 1px; overflow: hidden; position: absolute; white-space: nowrap; }
  :root[data-density="floor"] .app > .topbar .engine > .lamp { width: 14px; height: 14px; background: transparent; box-shadow: inset 0 0 0 3px var(--kl-idle-lamp); }
  :root[data-density="floor"] .app > .topbar .engine > .lamp--ok { background: var(--kl-ok-lamp); box-shadow: none; }
  :root[data-density="floor"] .app > .topbar .engine > .lamp--caution { border-radius: 2px; background: linear-gradient(90deg, var(--kl-caution-lamp) 0 36%, transparent 36% 64%, var(--kl-caution-lamp) 64%); box-shadow: none; }
  :root[data-density="floor"] .app > .topbar .engine > .lamp--danger { border-radius: 0; background: linear-gradient(45deg, transparent 38%, var(--kl-danger-lamp) 38% 62%, transparent 62%), linear-gradient(-45deg, transparent 38%, var(--kl-danger-lamp) 38% 62%, transparent 62%); box-shadow: none; }
}

/* ===== Palette reach ===== */
/* The selected cam cell shows only while the chart holds the focus (a needle selected for the palette always shows). */
.chart-grid:not(:focus-within) button.cell.cell--sel { outline: none; }
/* Needle mode: Stitches, the needle's name, the butts as short faces, and the hint on its own line. */
.tools--needle, .dock .tools--needle, .tools--inline .tools--needle { flex-wrap: wrap; row-gap: 2px; }
.tool--butt { justify-content: center; padding-inline: 0; font-variant-numeric: tabular-nums; font-weight: var(--kl-fw-bold); font-size: var(--kl-fs-body); }
.tools__hint { flex-basis: 100%; font-size: var(--kl-fs-caption); color: var(--kl-ink-2); }
@media (max-width: 599px) {
  .dock .tools--needle { gap: 4px; }
  .dock .tools--needle .tools__label { flex-basis: 100%; order: -1; }
  .dock .tool--butt, .dock .tool--back { min-width: var(--kl-hit); padding-inline: 0; justify-content: center; }
}
/* A press that changed nothing under a stitch brush: the brush is ringed for a moment (still under reduced motion). */
.tool--flash { outline: 3px solid var(--kl-caution-lamp); outline-offset: 2px; animation: kl-breathe .35s ease-in-out 2; }
@media (prefers-reduced-motion: reduce) { .tool--flash { animation: none; } }

/* ===== Sheets, forms and toasts ===== */
/* The open machine form scrolls within 45 % of the screen at every size; Close stays at its foot. */
.machinebar[open] .machinebar__form { max-height: 45svh; overflow-y: auto; }
.machinebar__foot { position: sticky; bottom: 0; display: flex; justify-content: flex-end; padding-block: var(--kl-s-2) 0; background: var(--kl-sunk); }
.chev--up { transform: rotate(180deg); }
/* The row menu and yarn picker on a phone: a bottom sheet above everything, scrolling inside. */
.chart-pop.chart-pop--sheet { position: fixed; inset-inline: 0; top: auto; bottom: 0; width: auto; min-width: 0; max-width: none; max-height: 70svh; overflow-y: auto;
  border-radius: var(--kl-r-sheet) var(--kl-r-sheet) 0 0; z-index: var(--kl-z-sheet); padding-block-end: calc(var(--kl-s-3) + env(safe-area-inset-bottom)); box-shadow: var(--kl-e3); }
.chart-pop--sheet .menu__head { position: sticky; top: calc(-1 * var(--kl-s-2)); background: var(--kl-paper); z-index: 1; padding-block: var(--kl-s-2); }
/* A toast shown while a phone sheet is open takes room under the sheet's head (App.placeToasts). */
.chart-pop--sheet > .toasts--flow { padding-block-end: var(--kl-s-2); }
/* The chart's meta line (design §6.2): one line, the repeat badge and the view menu's opener (a --kl-hit square) at its
   end; the fit badge's caution state takes a line of its own under them. */
.chart-meta__view { flex: none; }
.chart-meta__fit { order: 1; flex: 1 0 100%; display: flex; min-width: 0; }
/* The caution sentence is wider than a 320 px phone's meta line in Farsi and at shop floor: there it takes two balanced
   lines inside the line's box instead of widening the pane. */
.chart-meta__fit > .badge { min-width: 0; max-width: 100%; white-space: normal; text-wrap: balance; font-size: var(--kl-fs-caption); border-radius: var(--kl-r-control); }
.chart-meta__fit[hidden] { display: none; }
/* The view menu (design §6.2, frame 13): the row menu's sheet with a grip on a phone, a popover under its opener from
   600 px; the cell display and the orientation as two block segmented controls. */
.chart-pop--view { min-width: min(300px, calc(100vw - 16px)); gap: var(--kl-s-2); }
.chart-pop--view > .sheet__grip { display: none; }
.chart-pop--view.chart-pop--sheet > .sheet__grip { display: block; margin-block: 0; }
.chart-view__group { display: grid; gap: var(--kl-s-1); padding-inline: var(--kl-s-1); padding-block-end: var(--kl-s-1); }
.chart-pop--view .seg > button { width: auto; flex: 1 0 auto; justify-content: center; padding-inline: var(--kl-s-3); }
/* The option icons at the 22 px mark size of design §6.1 (as .nn > svg); the cam piece in its 1.6 px outline (as .cams-pieces). */
.chart-pop--view .seg svg { width: 22px; height: 22px; flex: none; }
.chart-view__piece { fill: var(--kl-line-strong); stroke: var(--kl-ink); stroke-width: 1.6px; color: var(--kl-line-strong); }
/* «↑ Knitting order» in the band's corner (design §6.3): a box of the band over its row-head and yarn columns, outside the
   table that moves sideways, opaque paper above it; the band is laid out left to right, so its inline start is the left
   (Chart.placeCorner sets the width and the height). */
.chart-corner { position: absolute; top: 0; left: 0; z-index: calc(var(--kl-z-sticky) + 1); display: flex; align-items: center; box-sizing: border-box; padding: calc(var(--kl-s-1) / 2) var(--kl-s-1); background: var(--kl-paper); }
.chart-corner__text { display: block; min-width: 0; font-size: var(--kl-fs-caption); line-height: 1.3; font-weight: var(--kl-fw-medium); color: var(--kl-ink-2); }
/* Toasts in the page's flow (the dock's top, or the main column's) take room instead of covering a control. */
.toasts.toasts--flow { position: static; inset: auto; top: auto; padding: 0; z-index: auto; }
.main > .toasts--flow { padding: var(--kl-s-2) var(--kl-gutter) 0; flex: none; }
.dock > .toasts--flow { padding-block-start: 2px; }

/* ===== Compare ===== */
/* The wipe: A and B fill one box at one size; B lies over A, clipped from the grip (--split) to the right edge. */
.wipe { position: relative; grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); --split: 55%; }
.wipe > .wipe__a, .wipe > .wipe__b { grid-area: 1 / 1; min-height: 0; }
.wipe > .wipe__b { clip-path: inset(0 0 0 var(--split)); }
.wipe__b > .wipe__label { justify-self: end; }
.wipe__canvas { object-fit: fill; }
.wipe > .wipe__grip { position: absolute; top: 0; bottom: 0; left: calc(var(--split) - var(--kl-hit) / 2); width: var(--kl-hit); background: transparent; border: 0; touch-action: none; }
.wipe__grip::before { content: ""; position: absolute; top: 0; bottom: 0; left: calc(50% - 1px); width: 2px; background: var(--kl-paper); box-shadow: 0 0 0 1px var(--kl-ink); }
.wipe > .wipe__grip svg { position: relative; width: 32px; height: 32px; padding: 6px; border-radius: var(--kl-r-pill); background: var(--kl-paper); box-shadow: var(--kl-e2); }
/* A variant: its still, its name, then A / B and Remove. */
.variant { cursor: default; }
.variant[data-chosen] { border-color: var(--kl-action); box-shadow: inset 0 0 0 2px var(--kl-action); }
.variant__ctl { display: flex; align-items: center; justify-content: space-between; gap: var(--kl-s-2); }
.variant__ctl .seg > button { min-width: var(--kl-hit); }

/* ===== Chart foot, buttons, design bar ===== */
/* The chart foot: labelled steppers (feeders in the repeat, needles in the set-out), side by side, never ragged. */
.foot-steps { display: flex; flex-wrap: wrap; gap: var(--kl-s-3) var(--kl-s-4); align-items: end; }
.foot-step { display: grid; gap: 4px; }
.foot-step .field__label { font-size: var(--kl-fs-small); color: var(--kl-ink-2); white-space: nowrap; }
.stepper--count { grid-template-columns: var(--kl-hit) minmax(4ch, auto) var(--kl-hit); width: max-content; }
.stepper--count output { display: grid; place-items: center; padding-inline: var(--kl-s-2); border-inline: 1px solid var(--kl-line); font-weight: var(--kl-fw-medium); font-variant-numeric: tabular-nums; }
.stepper--count svg { width: 20px; height: 20px; }
/* A disabled quiet or icon button keeps no fill (design-system §11.1): only the ink lightens. */
.btn--quiet[disabled], .btn--quiet[aria-disabled="true"], .btn--icon[disabled], .btn--icon[aria-disabled="true"] { background: transparent; }
.btn--quiet[disabled], .btn--quiet[aria-disabled="true"] { border-color: transparent; }
/* The structure name ends in an ellipsis when the design bar is narrow. */
.docbar__name .select { text-overflow: ellipsis; white-space: nowrap; overflow: hidden; }
/* The drawer handle drags vertically (its buttons still press). */
.drawer-handle { touch-action: none; cursor: ns-resize; }
.drawer-handle button { cursor: pointer; }

/* ===== Finish ===== */
/* The column brush (design §6.5): in the dock under 600 px and in a design pane under 520 px, a stitch brush is its 26 px
   mark over its word at caption size, no key cap, at least a floor-action square (56 px; 64 px at shop floor), 8 px
   apart: four of them take 248 px (280 px at shop floor) of a 320 px phone's 288. */
@media (max-width: 599px) {
  .dock .tools[data-for="chart"] { gap: var(--kl-s-2); }
  .dock [data-brush] { flex-direction: column; justify-content: center; gap: 2px; padding-inline: 4px; min-width: var(--kl-hit-floor); line-height: 1.2; }
  .dock [data-brush] .tool__word { font-size: var(--kl-fs-caption); }
  .dock [data-brush] .kbd { display: none; }
}
@container dpane (max-width: 520px) {
  .tools--inline .tools[data-for="chart"] { gap: var(--kl-s-2); }
  .tools--inline [data-brush] { flex-direction: column; justify-content: center; gap: 2px; padding-inline: 4px; min-width: var(--kl-hit-floor); line-height: 1.2; }
  .tools--inline [data-brush] .tool__word { font-size: var(--kl-fs-caption); }
  .tools--inline [data-brush] .kbd { display: none; }
}
/* The alarm chip hugs its words; a zero-height break keeps the other chips on the next line. */
@media (min-width: 600px) { .facts .fact--alarm { flex-basis: auto; } .facts__break { flex-basis: 100%; height: 0; } }
@media (max-width: 599px) { .facts__break { display: none; } }
/* The provenance line ends in an ellipsis when it is cut (it opens into the full text). */
.prov > summary > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* The swatch card's values in one weight. */
.pane--results .spec dd, .pane--results .spec dd * { font-weight: var(--kl-fw-medium); }
/* The phone Fabric pane keeps its footer (status and Simulate) on screen, above the dock. */
@media (max-width: 599px) { .app[data-pane="fabric"] .station__foot { position: sticky; bottom: 0; z-index: var(--kl-z-sticky); } }
/* Under reduced motion "running" still differs from "up to date": a ring around the lit lamp. */
@media (prefers-reduced-motion: reduce) { .tower[data-lit="run"] i:nth-child(3) { box-shadow: 0 0 0 2px var(--kl-tower-housing), 0 0 0 4px var(--kl-tower-green); } }

/* ===== Fidelity ===== */
/* The machine form's foot is an opaque band with room left under the last field, so nothing peeks half-visible beside
   Close. (It keeps its 45 svh cap on wide screens too: uncapped, an open form with its helper squeezes the workspace to
   a sliver on a 900 px screen.) */
.machinebar__foot { margin-inline: calc(-1 * var(--kl-gutter)); padding: var(--kl-s-2) var(--kl-gutter); border-block-start: 1px solid var(--kl-line); }
.machinebar__form { scroll-padding-block-end: 64px; }
/* A blocked design on a narrow phone: the compact Simulate shows the tower and "!" (its full name is spoken), and the
   design bar's parts may shrink, so the page never widens. */
@media (max-width: 419px) { .docbar .simulate--blocked .simulate__label { display: none; } .docbar .simulate--blocked .simulate__short { display: inline; } }
.docbar > *, .docbar__actions > * { min-width: 0; }

/* The offer card (pro/OfferCard.js) in the station's footer, above Simulate: the name and one line beside one
   floor button, the reason or the press's outcome under them; a held-back press stays in view, greyed. */
.offer { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: var(--kl-s-1) var(--kl-s-3); padding: var(--kl-s-2) var(--kl-s-3); border-radius: var(--kl-r-control); background: var(--kl-info-soft); min-width: 0; }
.offer[hidden] { display: none; }
.offer--ok { background: var(--kl-ok-soft); }
.offer__text { display: grid; gap: 2px; min-width: 0; }
.offer__name { margin: 0; font-size: var(--kl-fs-body); font-weight: var(--kl-fw-bold); overflow-wrap: anywhere; }
.offer__name:focus { outline: none; }
.offer__name:focus-visible { outline: 2px solid var(--kl-focus); outline-offset: 2px; }
.offer__line, .offer__status { margin: 0; font-size: var(--kl-fs-caption); color: var(--kl-ink-2); overflow-wrap: anywhere; }
.offer__line[hidden], .offer__status[hidden], .offer__go[hidden], .offer__close[hidden] { display: none; }
.offer__go[aria-disabled="true"] { cursor: not-allowed; }
.offer__go.is-greyed { background: var(--kl-sunk); border-color: var(--kl-line); color: var(--kl-ink-3); }
.offer__terms { margin: 0; padding-inline-start: var(--kl-s-5); display: grid; gap: var(--kl-s-2); }
/* The status line stays in the page (a live region that appears from display: none is often not read); empty, it takes
   no height. */
.offer__status:empty { margin: 0; }
/* Phones: the card is one compact row (the name and the press at the plain target height; the pool and days are in the
   dialog), so the pinned footer grows by as little as it can. */
@media (max-width: 599px) {
  .offer { padding: var(--kl-s-1) var(--kl-s-2); }
  .offer .offer__line { display: none; }
  .offer .offer__go { min-height: var(--kl-hit); padding-inline: var(--kl-s-4); }
}
/* The phone's dock: the Fabric button names the offer waiting in the station's footer beside the pane's icon, in place of
   its label (under 390 px, where the name and the icon do not fit together, in place of both), so the button keeps its
   height and width. */
.dock__mark { display: inline-block; min-width: 0; max-width: 100%; padding: 2px 6px; border-radius: 999px; background: var(--kl-action-soft); color: var(--kl-action); font-size: 0.75rem; font-weight: var(--kl-fw-bold); line-height: 1.5; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dock__mark[hidden] { display: none; }
.dock__panes button.is-marked .dock__label { display: none; }
@media (max-width: 389px) { .dock__panes button.is-marked svg { display: none; } }

