/* Route line appearance (appearance-view.js): a legend of sample strokes and one shared symbol editor.
   Every rule is scoped under .nsa. Surfaces and rules derive from the host's own text colour, using Lab / Studio
   tokens where they exist, so Classic, Studio and Lab in light or dark inherit without a new palette.
   Layout-critical rules on native controls carry enough specificity to beat sidebar-wide input rules; cosmetic
   field rules stay light (:where) so a host's own field styling still wins. */

.nsa {
  --nsa-ink-2: color-mix(in oklab, currentColor 72%, transparent);
  --nsa-rule: var(--rule, var(--st-line, color-mix(in oklab, currentColor 14%, transparent)));
  --nsa-rule-2: var(--rule-2, var(--st-line-strong, color-mix(in oklab, currentColor 30%, transparent)));
  --nsa-soft: color-mix(in oklab, currentColor 4%, transparent);
  --nsa-soft-2: color-mix(in oklab, currentColor 8%, transparent);
  --nsa-paper: color-mix(in oklab, currentColor 5%, transparent);
  --nsa-grid: color-mix(in oklab, currentColor 6%, transparent);
  --nsa-ring: var(--ring, var(--st-focus, currentColor));
  --nsa-alert: color-mix(in oklab, #e5484d 70%, currentColor);
  --nsa-ok: color-mix(in oklab, #1f9d55 62%, currentColor);
  --nsa-r: var(--r, var(--st-radius, .375rem));
  --nsa-ease: var(--ease, cubic-bezier(.23, 1, .32, 1));
  --nsa-mono: var(--f-num, var(--st-mono, ui-monospace, "Cascadia Mono", "SF Mono", Consolas, monospace));
  container: nsa / inline-size;
  display: block;
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
  margin: .625rem 0;
  font-family: inherit;
  line-height: 1.4;
}
.nsa *, .nsa *::before, .nsa *::after { box-sizing: border-box; }

/* ---- heading ---------------------------------------------------------------------------------------------- */
.nsa .nsa-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: .25rem .75rem; margin: 0 0 .5rem; }
.nsa .nsa-heading { flex: 1 1 9rem; min-width: 0; }
.nsa .nsa-title { margin: 0; font-size: .875rem; font-weight: 650; line-height: 1.3; overflow-wrap: break-word; }
.nsa .nsa-lead { margin: .125rem 0 0; color: var(--nsa-ink-2); font-size: .75rem; line-height: 1.45; overflow-wrap: break-word; }
.nsa .nsa-head > .nsa-btn { flex: none; margin-inline-start: auto; }

/* ---- buttons ---------------------------------------------------------------------------------------------- */
.nsa .nsa-btn {
  display: inline-flex; align-items: center; gap: .375rem;
  min-width: 0; min-height: 2.25rem; margin: 0; padding: .25rem .625rem;
  border: 1px solid var(--nsa-rule-2); border-radius: var(--nsa-r);
  background: transparent; color: inherit; box-shadow: none;
  font: inherit; font-size: .8125rem; font-weight: 600; line-height: 1.25; letter-spacing: 0; text-align: start; text-transform: none;
  cursor: pointer;
}
.nsa .nsa-btn-quiet { border-color: transparent; padding-inline: .5rem; }
.nsa .nsa-btn-text { font-size: .8125rem; overflow-wrap: break-word; }
.nsa .nsa-btn[aria-disabled="true"] { color: var(--nsa-ink-2); cursor: default; }
.nsa .nsa-btn[aria-disabled="true"] .nsa-icon { opacity: .55; }
.nsa .nsa-btn:not([aria-disabled="true"]):active { transform: scale(.97); }
.nsa .nsa-btn:focus-visible { outline: 2px solid var(--nsa-ring); outline-offset: 2px; }

.nsa .nsa-icon { flex: none; width: 1rem; height: 1rem; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---- legend plate: one continuous strip of symbol samples, like a map key ------------------------------- */
.nsa .nsa-plate { border: 1px solid var(--nsa-rule-2); border-radius: calc(var(--nsa-r) + .125rem); overflow: hidden; overflow: clip; }
.nsa .nsa-legend { --nsa-sw: min(4rem, 24%); display: block; margin: 0; padding: 0; list-style: none; }
.nsa .nsa-item { position: relative; margin: 0; padding: 0; list-style: none; }
.nsa .nsa-item::marker { content: none; }

.nsa .nsa-row {
  position: relative;
  display: grid; grid-template-columns: var(--nsa-sw) minmax(0, 1fr) auto; align-items: stretch; column-gap: .75rem;
  width: 100%; min-height: 3rem; margin: 0; padding: 0;
  border: 0; border-radius: 0; background: transparent; color: inherit; box-shadow: none;
  font: inherit; font-size: .875rem; line-height: 1.3; letter-spacing: 0; text-align: start; text-transform: none;
  cursor: pointer;
}
/* Rules between rows stop at the sample strip so the four symbols read as one comparable column. */
.nsa .nsa-item + .nsa-item > .nsa-row::before { content: ""; position: absolute; top: 0; right: 0; left: var(--nsa-sw); border-top: 1px solid var(--nsa-rule); pointer-events: none; }
.nsa .nsa-row:focus-visible { outline: 2px solid var(--nsa-ring); outline-offset: -2px; }
.nsa .nsa-item[data-open] > .nsa-row { background: var(--nsa-soft-2); box-shadow: inset 3px 0 0 var(--nsa-c, currentColor); }

.nsa .nsa-sample {
  position: relative;
  display: block; align-self: stretch; min-height: 3rem;
  border-right: 1px solid var(--nsa-rule);
  background-color: var(--nsa-paper);
  background-image: linear-gradient(90deg, var(--nsa-grid) 1px, transparent 1px), linear-gradient(var(--nsa-grid) 1px, transparent 1px);
  background-position: -1px -1px;
  background-size: .5rem .5rem;
}
.nsa .nsa-sample > svg { position: absolute; inset: 0; display: block; width: 100%; height: 100%; min-height: 3rem; overflow: visible; }

.nsa .nsa-name { display: flex; flex-direction: column; justify-content: center; gap: .125rem; min-width: 0; padding: .5rem 0; }
.nsa .nsa-name-title { font-size: .8125rem; font-weight: 600; line-height: 1.3; overflow-wrap: break-word; }
.nsa .nsa-meta { display: flex; flex-wrap: wrap; align-items: center; gap: .125rem .375rem; min-width: 0; }
.nsa .nsa-spec { color: var(--nsa-ink-2); font-size: .75rem; line-height: 1.35; font-variant-numeric: tabular-nums; }
.nsa .nsa-tag {
  display: inline-flex; align-items: center; padding: 0 .4375rem;
  border: 1px solid color-mix(in oklab, currentColor 40%, transparent); border-radius: 999px;
  font-size: .75rem; font-weight: 600; line-height: 1.3; white-space: nowrap;
}
.nsa .nsa-chev { align-self: center; margin-inline-end: .625rem; color: var(--nsa-ink-2); transition: transform .2s var(--nsa-ease), color .16s ease; }
.nsa .nsa-item[data-open] .nsa-chev { transform: rotate(180deg); color: inherit; }

/* ---- shared symbol editor --------------------------------------------------------------------------------- */
.nsa .nsa-editor {
  padding: .75rem .75rem .5rem calc(.75rem + 3px);
  border-top: 1px solid var(--nsa-rule-2);
  background: var(--nsa-soft);
  box-shadow: inset 3px 0 0 var(--nsa-c, currentColor);
}
.nsa .nsa-ed-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: .125rem .75rem; margin: 0 0 .375rem; }
.nsa .nsa-ed-title { min-width: 0; margin: 0; font-size: .8125rem; font-weight: 650; line-height: 1.3; overflow-wrap: break-word; }
.nsa .nsa-ed-cap { margin: 0; color: var(--nsa-ink-2); font-size: .75rem; line-height: 1.35; }
.nsa .nsa-preview {
  height: 3.25rem; margin: 0 0 .875rem;
  border: 1px solid var(--nsa-rule); border-radius: var(--nsa-r);
  background-color: var(--nsa-paper);
  background-image: linear-gradient(90deg, var(--nsa-grid) 1px, transparent 1px), linear-gradient(var(--nsa-grid) 1px, transparent 1px);
  background-position: -1px -1px;
  background-size: .5rem .5rem;
}
.nsa .nsa-preview > svg { display: block; width: 100%; height: 100%; }

.nsa .nsa-fields { display: grid; gap: .875rem; min-width: 0; }
.nsa .nsa-field { min-width: 0; margin: 0; padding: 0; border: 0; }
.nsa .nsa-fhead { display: flex; align-items: baseline; justify-content: space-between; gap: .5rem; margin: 0 0 .375rem; }
.nsa .nsa-flabel { color: var(--nsa-ink-2); font-size: .75rem; font-weight: 600; line-height: 1.3; }
.nsa .nsa-fval { font-family: var(--nsa-mono); font-size: .8125rem; font-weight: 600; line-height: 1.3; font-variant-numeric: tabular-nums; }

/* colour: native picker plus a hex field; the line under them always states what is actually applied */
.nsa .nsa-colorrow { display: flex; align-items: stretch; gap: .5rem; min-width: 0; }
.nsa .nsa-colorrow input.nsa-swatch.nsa-swatch {
  display: block; flex: none; width: 3rem; height: auto; min-height: 2.25rem; margin: 0; padding: .1875rem;
  border: 1px solid var(--nsa-rule-2); border-radius: var(--nsa-r); background: transparent; box-shadow: none; cursor: pointer;
}
.nsa .nsa-colorrow input.nsa-swatch::-webkit-color-swatch-wrapper { padding: 0; }
.nsa .nsa-colorrow input.nsa-swatch::-webkit-color-swatch { border: 0; border-radius: calc(var(--nsa-r) - .125rem); }
.nsa .nsa-colorrow input.nsa-swatch::-moz-color-swatch { border: 0; border-radius: calc(var(--nsa-r) - .125rem); }
.nsa .nsa-colorrow input.nsa-hex.nsa-hex {
  display: block; flex: 1 1 6.5rem; width: auto; min-width: 0; max-width: 11rem; margin: 0;
  font-family: var(--nsa-mono); font-variant-numeric: tabular-nums; letter-spacing: .04em; text-transform: uppercase;
}
:where(.nsa) .nsa-hex {
  min-height: 2.25rem; padding: .375rem .5rem;
  border: 1px solid var(--nsa-rule-2); border-radius: var(--nsa-r);
  background: var(--field, transparent); color: inherit; font-size: .875rem; line-height: 1.3;
}
/* Studio's field rules set border-color at higher specificity, so the invalid frame is drawn with shadows instead. */
.nsa .nsa-colorrow input.nsa-hex[aria-invalid="true"] { border-color: var(--nsa-alert); box-shadow: inset 0 0 0 1px var(--nsa-alert), 0 0 0 1px var(--nsa-alert); }
.nsa .nsa-colorrow input:focus-visible { outline: 2px solid var(--nsa-ring); outline-offset: 2px; }

.nsa .nsa-fmsg { display: flex; align-items: flex-start; gap: .3125rem; min-height: 1.35em; margin: .3125rem 0 0; color: var(--nsa-ink-2); font-size: .75rem; line-height: 1.35; overflow-wrap: break-word; }
.nsa .nsa-fmsg > .nsa-icon { width: .875rem; height: .875rem; margin-top: .0625rem; }
.nsa .nsa-fmsg[data-kind="applied"] > .nsa-icon { color: var(--nsa-ok); }
.nsa .nsa-fmsg[data-kind="incomplete"] > .nsa-icon { stroke-width: 3; }
.nsa .nsa-fmsg[data-kind="invalid"], .nsa .nsa-fmsg[data-kind="rejected"] { color: var(--nsa-alert); }

/* pattern: native radios behind drawn glyphs; arrow keys move and apply as usual */
.nsa .nsa-seg { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .25rem; }
.nsa .nsa-seg > label.nsa-opt.nsa-opt {
  position: relative; overflow: hidden;
  display: flex; flex-wrap: wrap; align-items: center; gap: .125rem .5rem;
  min-width: 0; min-height: 2.75rem; margin: 0; padding: .375rem .5rem;
  border: 1px solid var(--nsa-rule-2); border-radius: var(--nsa-r);
  background: transparent; color: inherit; font-weight: 500; line-height: 1.2; cursor: pointer;
  transition: border-color .14s ease, background-color .14s ease, box-shadow .14s ease;
}
.nsa .nsa-seg > label.nsa-opt.nsa-opt[data-on] { border-color: currentColor; background: var(--nsa-soft-2); box-shadow: inset 0 0 0 1px currentColor; }
.nsa .nsa-seg > label.nsa-opt.nsa-opt:has(input:focus-visible) { outline: 2px solid var(--nsa-ring); outline-offset: 2px; }
.nsa .nsa-seg input.nsa-radio {
  position: absolute; inset: 0; width: 100%; height: 100%; min-height: 0; margin: 0; padding: 0;
  border: 0; opacity: 0; cursor: pointer; appearance: none;
}
.nsa .nsa-glyph { display: block; flex: none; width: 1.75rem; height: .75rem; overflow: visible; stroke: currentColor; }
.nsa .nsa-opt-name { min-width: 0; font-size: .75rem; overflow-wrap: break-word; }
.nsa .nsa-seg > label.nsa-opt.nsa-opt[data-on] .nsa-opt-name { font-weight: 650; }

/* width */
.nsa .nsa-field input.nsa-range {
  display: block; width: 100%; min-width: 0; height: auto; min-height: 2.25rem; margin: 0; padding: 0;
  border: 0; border-radius: 0; background: transparent; box-shadow: none;
  accent-color: var(--nsa-c, currentColor); cursor: pointer;
}
.nsa .nsa-field input.nsa-range:focus-visible { outline: 2px solid var(--nsa-ring); outline-offset: 2px; }

.nsa .nsa-ed-foot { display: flex; flex-wrap: wrap; gap: .25rem; margin: .625rem 0 0 -.5rem; }

/* ---- footer: first-use hint, or the latest reset/undo feedback in the same slot ------------------------- */
.nsa .nsa-foot { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem .5rem; min-height: 2.75rem; padding: .375rem .5rem .375rem .75rem; border-top: 1px solid var(--nsa-rule); }
.nsa .nsa-hint, .nsa .nsa-status { flex: 1 1 10rem; min-width: 0; margin: 0; font-size: .75rem; line-height: 1.4; overflow-wrap: break-word; }
.nsa .nsa-hint { color: var(--nsa-ink-2); }
.nsa .nsa-status:empty { flex: 0 0 0; }
.nsa .nsa-foot > .nsa-undo { flex: none; min-height: 2rem; margin-inline-start: auto; }

.nsa .nsa-sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }

/* ---- pointer, container and accessibility adaptations ----------------------------------------------------- */
@media (hover: hover) and (pointer: fine) {
  .nsa .nsa-btn:not([aria-disabled="true"]):hover { background: var(--nsa-soft-2); }
  .nsa .nsa-row:hover { background: var(--nsa-soft); }
  .nsa .nsa-item[data-open] > .nsa-row:hover { background: var(--nsa-soft-2); }
  .nsa .nsa-seg > label.nsa-opt.nsa-opt:hover { border-color: var(--nsa-ink-2); }
  .nsa .nsa-seg > label.nsa-opt.nsa-opt[data-on]:hover { border-color: currentColor; }
}

@media (pointer: coarse) {
  .nsa .nsa-btn { min-height: 2.75rem; }
  .nsa .nsa-foot > .nsa-undo { min-height: 2.75rem; }
  .nsa .nsa-row { min-height: 3.25rem; }
  .nsa .nsa-colorrow input.nsa-swatch.nsa-swatch { width: 3.25rem; min-height: 2.75rem; }
  .nsa .nsa-colorrow input.nsa-hex.nsa-hex { min-height: 2.75rem; font-size: max(1rem, 16px); }
  .nsa .nsa-field input.nsa-range { min-height: 2.75rem; }
}

@container nsa (min-width: 18rem) {
  .nsa .nsa-seg { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .nsa .nsa-seg > label.nsa-opt.nsa-opt { flex-direction: column; flex-wrap: nowrap; justify-content: center; gap: .3125rem; padding: .375rem .1875rem; text-align: center; }
  .nsa .nsa-glyph { width: min(2.25rem, 100%); }
}

@container nsa (min-width: 21rem) {
  .nsa .nsa-legend { --nsa-sw: 5rem; }
}

@container nsa (min-width: 36rem) {
  .nsa .nsa-legend { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .nsa .nsa-item:nth-child(2) > .nsa-row::before { content: none; }
  .nsa .nsa-item:nth-child(even) { border-left: 1px solid var(--nsa-rule); }
  .nsa .nsa-editor { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.35fr); grid-template-areas: "head head" "preview fields" "foot fields"; column-gap: 1.25rem; align-items: start; }
  .nsa .nsa-ed-head { grid-area: head; }
  .nsa .nsa-preview { grid-area: preview; height: 4.5rem; margin-bottom: 0; }
  .nsa .nsa-fields { grid-area: fields; }
  .nsa .nsa-ed-foot { grid-area: foot; }
}

/* ---- motion: state changes only; Studio gives every workbench button a colour-only transition at (0,2,2),
   so the doubled class keeps the press feedback and the open-row bar easing ------------------------------- */
.nsa .nsa-btn.nsa-btn { transition: background-color .14s ease, border-color .14s ease, color .14s ease, transform .12s var(--nsa-ease); }
.nsa .nsa-row.nsa-row { transition: background-color .16s ease, box-shadow .16s ease; }

@media (prefers-reduced-motion: reduce) {
  .nsa .nsa-chev, .nsa .nsa-btn.nsa-btn { transition-property: color, background-color, border-color; }
  .nsa .nsa-btn:not([aria-disabled="true"]):active { transform: none; }
}
html[data-motion="reduced"] .nsa .nsa-chev,
html[data-motion="reduced"] .nsa .nsa-btn.nsa-btn { transition-property: color, background-color, border-color; }
html[data-motion="reduced"] .nsa .nsa-btn:not([aria-disabled="true"]):active,
html[data-motion="static"] .nsa .nsa-btn:not([aria-disabled="true"]):active { transform: none; }
html[data-motion="static"] .nsa .nsa-row.nsa-row,
html[data-motion="static"] .nsa .nsa-chev,
html[data-motion="static"] .nsa .nsa-btn.nsa-btn,
html[data-motion="static"] .nsa .nsa-seg > label.nsa-opt.nsa-opt { transition: none; }

@media (forced-colors: active) {
  .nsa .nsa-sample > svg, .nsa .nsa-preview > svg { forced-color-adjust: none; }
  .nsa .nsa-item[data-open] > .nsa-row { outline: 2px solid Highlight; outline-offset: -2px; }
  .nsa .nsa-editor { border-left: 3px solid CanvasText; }
  .nsa .nsa-seg > label.nsa-opt.nsa-opt[data-on] { border: 2px solid Highlight; }
}

/* The hidden attribute always wins over the display values above. */
.nsa [hidden] { display: none !important; }
