/* stage-plot-maker editor styles. Relies on :root variables from style.css; fallbacks below. */
.spm-root, .spm-modal-back, .spm-toast, .spm-ghost {
  --spm-on-accent: var(--on-accent, #fff);
}
.spm-root { font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Helvetica, Arial, sans-serif; color: var(--ink, #0A0A0A); max-width: 100%; overflow-x: clip; display: flex; flex-direction: column; }
.spm-root *, .spm-root *::before, .spm-root *::after, .spm-modal-back *, .spm-modal-back *::before, .spm-modal-back *::after { box-sizing: border-box; }
.spm-sr { position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* buttons: primary solid accent, secondary 1px line, text */
.spm-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 32px; padding: 0 12px; border: 1px solid transparent; border-radius: 4px; font: inherit; font-weight: 500; line-height: 1; color: var(--ink, #0A0A0A); background: transparent; cursor: pointer; white-space: nowrap; }
.spm-btn-pri { background: var(--accent, #1F3FBF); border-color: var(--accent, #1F3FBF); color: var(--spm-on-accent); }
.spm-btn-sec { border-color: var(--line, #E3E3DF); background: var(--surface, #fff); }
.spm-btn-sec:hover:not(:disabled) { border-color: var(--mute, #6B6B66); }
.spm-btn-text { color: var(--ink-2, #44443F); padding: 0 8px; }
.spm-btn-text:hover:not(:disabled) { color: var(--ink, #0A0A0A); text-decoration: underline; }
.spm-btn-pri:hover:not(:disabled) { filter: brightness(1.1); }
.spm-btn-sq { min-width: 32px; padding: 0 8px; }
.spm-btn:disabled { opacity: .45; cursor: not-allowed; }
.spm-root :focus-visible, .spm-modal-back :focus-visible { outline: 2px solid var(--accent, #1F3FBF); outline-offset: 2px; }
.spm-item:focus { outline: none; }

/* form controls */
.spm-input, .spm-select { min-height: 32px; padding: 0 8px; border: 1px solid var(--line, #E3E3DF); border-radius: 4px; background: var(--surface, #fff); color: var(--ink, #0A0A0A); font: inherit; min-width: 0; }
.spm-input { width: 100%; }
.spm-input::placeholder { color: var(--mute, #6B6B66); }
.spm-area { padding: 6px 8px; resize: vertical; min-height: 72px; line-height: 1.45; }
.spm-num { width: 64px; }
.spm-select { max-width: 100%; }
.spm-chk { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2, #44443F); cursor: pointer; min-height: 32px; }
.spm-chk input { width: 16px; height: 16px; accent-color: var(--accent, #1F3FBF); margin: 0; }
.spm-hint { color: var(--mute, #6B6B66); font-size: 13px; margin: 4px 0 0; }

/* top bar + tabs */
.spm-bar { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line, #E3E3DF); }
.spm-bargroup { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; min-width: 0; }
.spm-barright { margin-left: auto; }
.spm-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line, #E3E3DF); background: var(--paper, #F7F7F5); }
.spm-tab { min-height: 36px; padding: 0 14px; background: none; border: 0; border-bottom: 2px solid transparent; color: var(--mute, #6B6B66); font: inherit; font-weight: 500; cursor: pointer; margin-bottom: -1px; }
.spm-tab[aria-selected="true"] { color: var(--ink, #0A0A0A); border-bottom-color: var(--accent, #1F3FBF); }
.spm-tab:hover { color: var(--ink, #0A0A0A); }
.spm-t-m { display: none; }

/* body layout (desktop) */
.spm-body { display: grid; gap: 16px; padding: 12px 0; grid-template-columns: minmax(220px, 280px) minmax(0, 1fr); grid-template-areas: "lib canvas"; align-items: start; }
.spm-lib { grid-area: lib; max-height: min(78vh, 760px); overflow: auto; min-width: 0; padding-right: 4px; }
.spm-canvaswrap { grid-area: canvas; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.spm-pane { grid-column: 1 / -1; min-width: 0; max-width: 900px; }
.spm-root[data-view="stage"] .spm-pane { display: none; }
.spm-root[data-view="input"] .spm-lib, .spm-root[data-view="input"] .spm-canvaswrap, .spm-root[data-view="input"] .spm-pane-rider,
.spm-root[data-view="rider"] .spm-lib, .spm-root[data-view="rider"] .spm-canvaswrap, .spm-root[data-view="rider"] .spm-pane-input { display: none; }
.spm-root:not([data-view="stage"]) .spm-body { grid-template-columns: minmax(0, 1fr); grid-template-areas: none; }

/* canvas */
.spm-ctools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.spm-labelinput { flex: 1 1 160px; width: auto; max-width: 280px; }
.spm-sep { flex: 1 1 0; }
.spm-zoomlabel { min-width: 40px; text-align: center; color: var(--mute, #6B6B66); font-variant-numeric: tabular-nums; }
.spm-stagesize { display: inline-flex; align-items: center; gap: 4px; color: var(--ink-2, #44443F); }
.spm-canvasarea { position: relative; height: min(70vh, 640px); min-height: 360px; border: 1px solid var(--line, #E3E3DF); background: var(--paper, #F7F7F5); }
.spm-scroll { position: absolute; inset: 0; overflow: auto; display: flex; }
.spm-svg { display: block; margin: auto; flex: none; user-select: none; -webkit-user-select: none; }
.spm-item { touch-action: none; }
.spm-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; padding: 24px; pointer-events: none; color: var(--mute, #6B6B66); }
.spm-empty[hidden] { display: none; }
.spm-empty p { max-width: 280px; margin: 0; background: var(--paper, #F7F7F5); padding: 8px; }

/* library */
.spm-presets h3 { margin: 0 0 6px; font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--mute, #6B6B66); font-weight: 600; }
.spm-presetgrid { display: grid; gap: 6px; }
.spm-preset { justify-content: flex-start; text-align: left; white-space: normal; line-height: 1.25; }
.spm-search { margin: 12px 0 8px; }
.spm-cat { margin: 0 0 8px; }
.spm-cat[hidden], .spm-tile[hidden] { display: none; }
.spm-cat summary { cursor: pointer; font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--mute, #6B6B66); font-weight: 600; padding: 6px 0; list-style-position: inside; }
.spm-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 6px; }
.spm-tile { display: flex; flex-direction: column; align-items: center; gap: 4px; min-height: 76px; padding: 6px 4px; background: var(--surface, #fff); border: 1px solid var(--line, #E3E3DF); border-radius: 4px; color: var(--ink, #0A0A0A); font: inherit; cursor: grab; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.spm-tile:hover { border-color: var(--mute, #6B6B66); }
.spm-tile-ic { display: block; width: 40px; height: 40px; flex: none; }
.spm-tile-ic svg { width: 100%; height: 100%; display: block; }
.spm-tile-lb { font-size: 11px; line-height: 1.2; color: var(--ink-2, #44443F); text-align: center; overflow-wrap: anywhere; }
.spm-nomatch { color: var(--mute, #6B6B66); }
.spm-ghost { position: fixed; z-index: 2000; width: 56px; height: 56px; transform: translate(-50%, -50%); pointer-events: none; color: var(--ink, #0A0A0A); opacity: .85; }
.spm-ghost svg { width: 100%; height: 100%; display: block; }

/* panes: input list + rider */
.spm-panehead h2 { margin: 0; font-size: 18px; font-weight: 600; letter-spacing: 0; }
.spm-chtable { margin-top: 12px; border-top: 1px solid var(--line, #E3E3DF); }
.spm-chrow { display: grid; grid-template-columns: 36px minmax(140px, 1.4fr) minmax(120px, 1fr) 64px minmax(120px, 1.2fr) auto; gap: 8px; align-items: start; padding: 8px 0; border-bottom: 1px solid var(--line, #E3E3DF); }
.spm-chhead { font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--mute, #6B6B66); font-weight: 600; align-items: center; padding: 6px 0; }
.spm-chhead[hidden], .spm-chempty[hidden] { display: none; }
.spm-chnum { min-height: 32px; display: flex; align-items: center; justify-content: center; font-weight: 700; color: var(--accent, #1F3FBF); font-variant-numeric: tabular-nums; }
.spm-chsrc { display: block; margin-top: 2px; font-size: 11px; color: var(--mute, #6B6B66); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spm-chact { display: flex; gap: 4px; }
.spm-panefoot { margin-top: 12px; }
.spm-chempty { margin-top: 12px; }
.spm-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; margin-top: 12px; }
.spm-field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.spm-field label { font-size: 13px; color: var(--ink-2, #44443F); font-weight: 500; }
.spm-field-wide { grid-column: 1 / -1; }

/* modal + toast (the only place a shadow is allowed) */
.spm-modal-back { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(10, 10, 10, .5); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Helvetica, Arial, sans-serif; }
.spm-modal { width: 100%; max-width: 560px; max-height: 90vh; overflow: auto; padding: 20px; background: var(--surface, #fff); color: var(--ink, #0A0A0A); border: 1px solid var(--line, #E3E3DF); border-radius: 8px; box-shadow: 0 12px 40px rgba(0, 0, 0, .25); }
.spm-mtitle { margin: 0 0 8px; font-size: 18px; font-weight: 600; }
.spm-mbody p { margin: 0 0 12px; }
.spm-mact { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.spm-mact-wrap { flex-wrap: wrap; }
.spm-exp-prev { border: 1px solid var(--line, #E3E3DF); background: var(--paper, #F7F7F5); padding: 8px; margin-bottom: 12px; }
.spm-exp-prev svg { display: block; width: 100%; height: auto; max-height: 240px; }
.spm-exp-opt { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.spm-toast { position: fixed; left: 50%; bottom: 72px; transform: translateX(-50%); z-index: 1100; max-width: calc(100% - 32px); padding: 8px 14px; border-radius: 4px; background: var(--ink, #0A0A0A); color: var(--surface, #fff); font: 14px/1.4 system-ui, sans-serif; opacity: 0; pointer-events: none; transition: opacity .15s; }
.spm-toast.is-on { opacity: 1; }

@media (prefers-reduced-motion: reduce) {
  .spm-root *, .spm-modal-back *, .spm-toast { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

/* phone: canvas on top, bottom tabs Gear / Channels / Rider */
@media (max-width: 760px) {
  .spm-bar { padding: 8px 0; gap: 8px; }
  .spm-bargroup { gap: 6px; }
  .spm-barright { margin-left: 0; }
  .spm-g-band { width: 100%; flex-wrap: nowrap; }
  .spm-g-band [data-act="del-band"], .spm-bar [data-spm-pdf] { display: none; }
  .spm-g-hist, .spm-barright { display: contents; }
  .spm-bar .spm-btn { flex: 1 1 auto; padding: 0 8px; }
  .spm-g-band .spm-select { flex: 1 1 0; }
  .spm-canvaswrap, .spm-lib, .spm-pane { grid-area: auto; }
  .spm-btn { min-height: 44px; padding: 0 12px; }
  .spm-btn-sq { min-width: 44px; }
  .spm-input, .spm-select { min-height: 44px; font-size: 16px; }
  .spm-area { min-height: 96px; }
  .spm-chk { min-height: 44px; }
  .spm-chk input { width: 22px; height: 22px; }
  .spm-select { max-width: 100%; flex: 1 1 140px; }
  .spm-num { width: 72px; }
  .spm-body { grid-template-columns: minmax(0, 1fr); grid-template-areas: none; gap: 12px; padding: 8px 0 12px; }
  .spm-canvaswrap { order: -1; }
  .spm-root[data-view] .spm-canvaswrap { display: flex; }
  .spm-lib, .spm-pane { grid-area: auto; grid-column: 1; max-height: none; overflow: visible; padding-right: 0; }
  .spm-canvasarea { height: 42vh; min-height: 240px; }
  .spm-labelinput { max-width: none; flex-basis: 100%; }
  .spm-sep { display: none; }
  .spm-tiles { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); }
  .spm-presetgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .spm-cat summary { min-height: 44px; display: flex; align-items: center; }
  .spm-tabs { order: 3; position: sticky; bottom: 0; z-index: 20; border-bottom: 0; border-top: 1px solid var(--line, #E3E3DF); background: var(--surface, #fff); gap: 0; }
  .spm-tab { flex: 1; min-height: 52px; border-bottom: 0; border-top: 2px solid transparent; margin: 0; font-size: 15px; }
  .spm-tab[aria-selected="true"] { border-top-color: var(--accent, #1F3FBF); }
  .spm-t-d { display: none; }
  .spm-t-m { display: inline; }
  .spm-chhead { display: none; }
  .spm-chrow { grid-template-columns: 36px minmax(0, 1fr) minmax(0, 1fr); grid-template-areas: "num name name" "mic mic chk" "note note note" "act act act"; gap: 8px; padding: 12px 0; }
  .spm-chrow > :nth-child(1) { grid-area: num; min-height: 44px; }
  .spm-chrow > :nth-child(2) { grid-area: name; }
  .spm-chrow > :nth-child(3) { grid-area: mic; }
  .spm-chrow > :nth-child(4) { grid-area: chk; justify-self: end; }
  .spm-chrow > :nth-child(5) { grid-area: note; }
  .spm-chrow > :nth-child(6) { grid-area: act; justify-content: flex-end; }
  .spm-form { grid-template-columns: minmax(0, 1fr); }
  .spm-toast { bottom: 76px; }
  .spm-mact { flex-wrap: wrap; }
}

/* print: page 1 stage plot + legend, page 2 input list + rider. All app UI hidden. */
.spm-print { display: none; }
@page { size: A4 portrait; margin: 12mm; }
@media print {
  html, body { background: #fff !important; }
  body > *:not(.spm-print) { display: none !important; }
  .spm-print { display: block !important; color: #0A0A0A; background: #fff; font: 9.5pt/1.4 system-ui, -apple-system, "Segoe UI", Helvetica, Arial, sans-serif; }
  .spm-print * { box-sizing: border-box; }
  .spm-pp1 { break-after: page; page-break-after: always; }
  .spm-pp-head h1 { margin: 0 0 1mm; font-size: 20pt; line-height: 1.15; }
  .spm-pp-head p { margin: 0 0 3mm; color: #44443F; }
  .spm-pp-plot { margin: 2mm 0 4mm; }
  .spm-pp-plot svg { display: block; width: 100%; height: auto; max-height: 160mm; }
  .spm-print h2 { margin: 0 0 2mm; font-size: 11pt; text-transform: uppercase; letter-spacing: .05em; }
  .spm-pp2 h2 + .spm-pp-table, .spm-pp2 h2 + .spm-pp-mute { margin-bottom: 6mm; }
  .spm-pp-leg { list-style: none; margin: 0 0 2mm; padding: 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: 1.5mm 4mm; }
  .spm-pp-leg li { display: flex; align-items: center; gap: 2mm; break-inside: avoid; }
  .spm-pp-ic { flex: none; width: 8mm; height: 8mm; color: #0A0A0A; }
  .spm-pp-ic svg { width: 100%; height: 100%; display: block; }
  .spm-pp-mute { color: #6B6B66; margin: 1mm 0; }
  .spm-pp-table { width: 100%; border-collapse: collapse; font-size: 9pt; }
  .spm-pp-table th { text-align: left; font-weight: 600; border-bottom: .4mm solid #0A0A0A; padding: 1mm 2mm; }
  .spm-pp-table td { border-bottom: .2mm solid #D9D9D4; padding: 1mm 2mm; vertical-align: top; }
  .spm-pp-table thead { display: table-header-group; }
  .spm-pp-table tr { break-inside: avoid; }
  .spm-pp-dl { display: grid; grid-template-columns: 38mm 1fr; gap: 1.5mm 4mm; margin: 0; }
  .spm-pp-dl dt { color: #6B6B66; }
  .spm-pp-dl dd { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
  .spm-pp-foot { position: fixed; left: 0; right: 0; bottom: 0; text-align: center; font-size: 7.5pt; line-height: 1; color: #6B6B66; }
  .spm-pp { padding-bottom: 6mm; }
}

/* small renderings keep a constant line weight */
.spm-tile-ic svg, .spm-pp-ic svg, .spm-ghost svg { stroke-width: 1.5; }
.spm-tile-ic svg *, .spm-pp-ic svg *, .spm-ghost svg * { vector-effect: non-scaling-stroke; }
