/* Barcode editors keep the controls close and the preview in view. */
.barcode-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 10px; }
.barcode-form label { justify-content: flex-end; }
.full { grid-column: 1 / -1; }
.studio-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(260px, 1fr); gap: 14px; align-items: start; }
.studio-grid .create-panel { margin-bottom: 12px; }
.design-options { border: 0; min-width: 0; margin: 8px 0 0; padding: 0; }
.design-options[hidden] { display: none; }
.design-options legend { font-size: .8125rem; font-weight: 600; padding: 0 0 6px; }
.qr-extras { margin: 0; }
.advanced-options { padding-bottom: 4px; }
.barcode-form .checkbox { justify-content: flex-start; }
.barcode-form .checkbox, .barcode-form > .fine-print { grid-column: 1 / -1; }
.studio-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.barcode-design[data-initialized]:not(.preview-failed) [data-preview] { display: none; }

/* Customize drawer & subtabs */
.customize-drawer { margin-top: 10px; border-top: 1px solid var(--line); }
.customize-summary { display: flex; align-items: center; justify-content: space-between; min-height: 40px; padding: 8px 0; font-size: .8125rem; font-weight: 600; color: var(--ink); list-style: none; }
.customize-summary::-webkit-details-marker { display: none; }
.customize-summary::after { content: "▾"; color: var(--green); font-size: .75rem; margin-left: 8px; }
.customize-drawer[open] > .customize-summary::after { content: "▴"; }
.customize-body { padding-top: 4px; }
.option-tabs { display: none; gap: 4px; border-bottom: 1px solid var(--line); padding-bottom: 8px; margin-bottom: 10px; overflow-x: auto; }
html[data-js] .option-tabs { display: flex; }
.option-tab { border: 1px solid transparent; background: transparent; color: var(--muted); font-size: .75rem; font-weight: 600; padding: 6px 10px; border-radius: 5px; white-space: nowrap; min-height: 34px; }
.option-tab:hover { color: var(--ink); background: var(--soft); }
.option-tab.active { background: var(--soft); color: var(--green); border-color: #355b43; }
.option-tab[hidden] { display: none; }
html[data-js] .option-panel.tab-hidden { display: none; }

/* Segmented radio pills */
.field-block { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field-title { font-size: .75rem; font-weight: 600; color: var(--ink); }
.pill-group { display: grid; grid-template-columns: repeat(auto-fit, minmax(64px, 1fr)); gap: 4px; background: #0b1711; border: 1px solid #315040; border-radius: 6px; padding: 3px; }
.pill-option { position: relative; display: flex; flex-direction: row; align-items: center; justify-content: center; margin: 0; cursor: pointer; min-height: 36px; }
.pill-option input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; min-height: 0; }
.pill-option span { display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; min-height: 34px; padding: 4px 6px; border-radius: 4px; font-size: .75rem; font-weight: 500; color: var(--muted); text-align: center; transition: background .12s, color .12s; }
.pill-option input:checked + span { background: var(--soft); color: var(--green); font-weight: 600; box-shadow: inset 0 0 0 1px #355b43; }
.pill-option input:focus-visible + span { outline: 2px solid var(--green); outline-offset: 1px; }

/* Live preview panel */
.studio-preview { position: sticky; top: 8px; }
.design-canvas { display: grid; place-items: center; min-height: 240px; padding: 14px; border: 1px solid var(--line); border-radius: 6px; background: #0b1711; }
.design-canvas > img { width: auto; height: auto; max-width: 100%; max-height: 260px; object-fit: contain; }
.design-canvas [hidden], .saved-live-preview [hidden] { display: none; }
.preview-caption { min-width: 0; margin-top: 8px; }
.preview-caption .fine-print { margin: 0; }
.preview-error { color: var(--red); }
.summary-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.summary-chips:empty { display: none; }
.summary-chip { font-size: .7rem; padding: 2px 6px; border-radius: 4px; background: var(--soft); color: var(--muted); border: 1px solid var(--line); }
.mobile-save { display: none; }

input[type=color] { padding: 4px; height: 44px; }
input[type=file] { font-size: .875rem; padding: 7px; }
input[type=file]::file-selector-button { background: var(--soft); border: 1px solid var(--line); border-radius: 4px; color: var(--ink); padding: 4px 8px; margin-right: 6px; }

/* Saved barcodes list */
.barcode-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
.barcode-card { display: grid; grid-template-columns: 72px minmax(0, 1fr); align-items: center; gap: 0 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--white); }
.barcode-preview { display: grid; place-items: center; min-height: 72px; width: 72px; background: #0b1711; border: 1px solid var(--line); border-radius: 6px; padding: 4px; }
.barcode-preview img { width: auto; height: auto; max-width: 62px; max-height: 62px; object-fit: contain; }
.barcode-info, .barcode-description { min-width: 0; }
.barcode-summary { display: flex; gap: 12px; align-items: center; justify-content: space-between; }
.barcode-title-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.barcode-meta { font-size: .75rem; }
.payload { font-family: monospace; font-size: .75rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 3px; }
.barcode-card-actions { display: flex; align-items: center; flex-shrink: 0; gap: 6px; }
.download-form { display: flex; align-items: center; gap: 5px; margin: 0; }
.download-form select { width: 76px; min-height: 38px; padding: 6px 8px; font-size: .78rem; }
.barcode-editor, .barcode-print { grid-column: 1 / -1; }
.barcode-print { margin-top: 10px; }
.print-form { margin-top: 12px; }
html[data-js] .barcode-editor > summary,
html[data-js] .barcode-print > summary { display: none; }
html[data-js] .barcode-editor:not([open]),
html[data-js] .barcode-print:not([open]) { margin-top: 0; border-top: 0; }
html[data-js] .barcode-editor[open],
html[data-js] .barcode-print[open] { padding-top: 12px; margin-top: 10px; }
.draft-status { grid-column: 1 / -1; }
.draft-status:empty { position: absolute; width: 1px; height: 1px; margin: 0; overflow: hidden; clip: rect(0,0,0,0); }

/* Saved barcode editor with large preview */
.saved-editor-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(240px, 1fr); gap: 14px; align-items: start; }
.saved-editor-payload { min-width: 0; margin-bottom: 8px; }
.payload-full { font-family: monospace; font-size: .75rem; overflow-wrap: anywhere; white-space: pre-wrap; max-height: 100px; overflow: auto; margin: 2px 0 0; }
.saved-design { margin: 0; }
.saved-live-preview { position: sticky; top: 8px; background: var(--paper); border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.saved-live-preview .design-canvas { min-height: 220px; padding: 12px; background: #0b1711; }
.saved-live-preview .design-canvas > img { width: auto; height: auto; max-width: 100%; max-height: 240px; object-fit: contain; }
.saved-live-preview .fine-print { margin: 8px 0 0; }
.editor-danger-row { display: flex; justify-content: flex-end; margin-top: 10px; padding-top: 8px; border-top: 1px dashed var(--line); }

@media (max-width: 900px) {
  html { scroll-padding-top: 180px; }
  .studio-grid, .saved-editor-grid { display: flex; flex-direction: column; gap: 10px; }
  .studio-grid > *, .saved-editor-grid > * { width: 100%; }
  .studio-preview { order: -1; z-index: 2; display: grid; grid-template-columns: 148px minmax(0, 1fr); align-items: center; gap: 12px; padding: 10px; box-shadow: 0 4px 12px #0004; }
  .studio-preview .design-canvas { min-height: 148px; height: 148px; padding: 8px; grid-row: 1 / span 2; }
  .studio-preview .design-canvas > img { max-height: 132px; }
  .preview-caption { margin: 0; align-self: end; }
  .mobile-save { display: inline-flex; justify-self: start; align-self: start; }
  .saved-live-preview { order: -1; z-index: 2; display: grid; grid-template-columns: 148px minmax(0, 1fr); align-items: center; gap: 12px; padding: 10px; box-shadow: 0 4px 12px #0004; }
  .saved-live-preview .design-canvas { min-height: 148px; height: 148px; padding: 8px; }
  .saved-live-preview .design-canvas > img { max-height: 132px; }
  .saved-live-preview .fine-print { margin: 0; }
}
@media (max-width: 600px) {
  .barcode-form { grid-template-columns: 1fr; }
  #barcode-studio > .studio-actions > .button { flex: 1; }
  .studio-actions > * { min-width: 0; white-space: normal; }
  .studio-preview, .saved-live-preview { grid-template-columns: 136px minmax(0, 1fr); gap: 10px; }
  .studio-preview .design-canvas, .saved-live-preview .design-canvas { min-height: 136px; height: 136px; padding: 6px; }
  .studio-preview .design-canvas > img, .saved-live-preview .design-canvas > img { max-height: 124px; }
  .barcode-card { grid-template-columns: 60px minmax(0, 1fr); gap: 8px 10px; }
  .barcode-preview { min-height: 60px; width: 60px; }
  .barcode-preview img { max-width: 50px; max-height: 50px; }
  .barcode-info, .barcode-summary { display: contents; }
  .barcode-description { grid-column: 2; }
  .barcode-card-actions { grid-column: 1 / -1; width: 100%; justify-content: space-between; }
  .download-form { flex: 1; }
  .download-form select { flex: 0 0 72px; }
  .download-form .outline-button { flex: 1; }
  .barcode-editor, .barcode-print { margin-top: 0; }
}
@media (max-width: 900px) and (max-height: 500px) {
  html { scroll-padding-top: 8px; }
  .studio-preview, .saved-live-preview { position: static; }
}
