.detail-dialog:has(.voucher-print-dialog),
.detail-dialog:has(.voucher-profile-dialog) { width: min(1080px, calc(100vw - 28px)); }

.voucher-print-controls { margin-bottom: 14px; }
.voucher-print-controls fieldset,
.voucher-profile-grid fieldset { min-width: 0; margin: 0; border: 0; padding: 0; }
.voucher-print-controls legend,
.voucher-profile-grid legend { margin-bottom: 7px; color: var(--color-text-muted); font-size: 12px; }
.voucher-paper-picker { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.voucher-qr-settings .switch-field { display: flex; min-height: 42px; align-items: center; gap: 8px; border: 1px solid var(--color-border-strong); border-radius: var(--radius-control); background: var(--color-surface); padding: 8px 10px; color: var(--color-text); font-size: 12px; }
.voucher-qr-settings .switch-field input { width: 16px; height: 16px; flex: 0 0 16px; margin: 0; accent-color: var(--color-primary); }
.voucher-paper-option, .voucher-choice, .voucher-template-choice { position: relative; min-width: 0; border: 1px solid var(--color-border-strong); border-radius: var(--radius-control); background: var(--color-surface); cursor: pointer; }
.voucher-paper-option, .voucher-choice { display: grid; grid-template-columns: 16px minmax(0, 1fr); gap: 2px 7px; min-height: 55px; align-content: center; padding: 8px 9px; }
.voucher-paper-option input, .voucher-choice input { grid-row: 1 / span 2; align-self: center; }
.voucher-paper-option strong, .voucher-choice strong { color: var(--color-text-strong); font-size: 12px; }
.voucher-paper-option span, .voucher-choice span { color: var(--color-text-muted); font-size: 10px; line-height: 1.3; }
.voucher-paper-option:has(input:checked), .voucher-choice:has(input:checked), .voucher-template-choice:has(input:checked) { border-color: var(--color-primary); box-shadow: inset 0 0 0 1px var(--color-primary); }
.voucher-template-choice { display: grid; grid-template-columns: 42px minmax(0, 1fr); grid-template-rows: auto auto; gap: 2px 8px; align-items: center; min-height: 58px; padding: 7px; }
.voucher-template-choice input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.voucher-template-choice strong { align-self: end; color: var(--color-text-strong); font-size: 12px; }
.voucher-template-choice small { align-self: start; overflow: hidden; color: var(--color-text-muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.voucher-print-preview { max-height: 46vh; overflow: auto; border: 1px solid var(--color-border); border-radius: var(--radius-control); background: var(--color-surface-subtle); padding: 14px; }
.voucher-sheet { display: grid; grid-template-columns: repeat(4, 50mm); gap: 8px; width: max-content; max-width: 100%; margin: 0 auto; }
.voucher-sheet[data-print-format="pos"], .voucher-sheet[data-voucher-profile-preview] { grid-template-columns: 50mm; }
.voucher-sheet[data-print-format="folio"] { grid-template-columns: repeat(4, 50mm); }
.voucher-sheet[data-print-format="a4"][data-a4-columns="5"] { grid-template-columns: repeat(5, 50mm); }

.voucher-card { --voucher-bg: #0a1730; --voucher-fg: #f8fbff; --voucher-muted: #b6c8e7; --voucher-accent: #2f75ff; --voucher-soft: rgba(255, 255, 255, 0.1); position: relative; isolation: isolate; display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto auto; gap: 2px; box-sizing: border-box; width: 50mm; height: 35mm; min-width: 50mm; overflow: hidden; border: 1px solid var(--voucher-accent); border-radius: 3px; background: var(--voucher-bg); padding: 2mm; color: var(--voucher-fg); text-align: left; break-inside: avoid; print-color-adjust: exact; }
.voucher-card::after { position: absolute; inset: 0 0 auto; z-index: -1; height: 1.5mm; background: var(--voucher-accent); content: ""; }
.voucher-sheet[data-template="coral"] .voucher-card { --voucher-bg: #fff7f3; --voucher-fg: #17213a; --voucher-muted: #5f687b; --voucher-accent: #ff594d; --voucher-soft: rgba(20, 36, 75, 0.08); border-color: #14244b; }
.voucher-sheet[data-template="emerald"] .voucher-card { --voucher-bg: #06312e; --voucher-fg: #f5fffc; --voucher-muted: #a9d9d0; --voucher-accent: #1ec9a4; --voucher-soft: rgba(255, 255, 255, 0.1); border-color: #1ec9a4; }
.voucher-sheet[data-template="custom"] .voucher-card { --voucher-bg: #10182a; --voucher-fg: #ffffff; --voucher-muted: #e1e8f5; --voucher-accent: #ffffff; --voucher-soft: rgba(0, 0, 0, 0.38); background-color: var(--voucher-bg); background-image: linear-gradient(rgba(4, 8, 18, 0.5), rgba(4, 8, 18, 0.5)), var(--voucher-custom-image); background-position: center; background-size: cover; }
.voucher-sheet[data-card-size="mini"] .voucher-card { height: 25mm; padding: 1.5mm 1.8mm; }
.voucher-card-business { display: flex; align-items: center; gap: 1.4mm; min-width: 0; padding-top: 0.6mm; }
.voucher-card-business > span:last-child { min-width: 0; overflow: hidden; color: var(--voucher-fg); font-size: 7.5pt; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }
.voucher-business-mark { width: 5mm; height: 5mm; flex: 0 0 5mm; display: grid; place-items: center; overflow: hidden; border-radius: 2px; background: var(--voucher-soft); color: var(--voucher-fg); font-size: 6pt; font-weight: 800; }
.voucher-business-mark img { width: 100%; height: 100%; object-fit: contain; }
.voucher-card-title { color: var(--voucher-muted); font-size: 5.8pt; font-weight: 750; text-transform: uppercase; }
.voucher-card-main { display: grid; grid-template-columns: minmax(0, 1fr); align-items: center; gap: 1.5mm; min-width: 0; }
.voucher-sheet[data-show-qr="true"] .voucher-card-main { grid-template-columns: minmax(0, 1fr) 13mm; }
.voucher-code-block { display: grid; gap: 0.4mm; min-width: 0; text-align: left; }
.voucher-code-block span, .voucher-credentials span, .voucher-card-details span { color: var(--voucher-muted); font-size: 5.4pt; }
.voucher-code-block strong { overflow: hidden; color: var(--voucher-fg); font-family: var(--font-mono); font-size: 13pt; line-height: 1.05; text-overflow: ellipsis; white-space: nowrap; }
.voucher-credentials { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1mm; min-width: 0; }
.voucher-credentials > div { display: grid; gap: 0.3mm; min-width: 0; border-radius: 2px; background: var(--voucher-soft); padding: 1mm; }
.voucher-credentials strong { overflow: hidden; color: var(--voucher-fg); font-family: var(--font-mono); font-size: 7pt; text-overflow: ellipsis; white-space: nowrap; }
.voucher-sheet[data-credential-mode="code"] .voucher-credentials,
.voucher-sheet[data-credential-mode="credentials"] .voucher-code-block { display: none; }
.voucher-qr-wrap { display: grid; gap: 0.4mm; justify-items: center; }
.voucher-qr { display: grid; width: 12mm; height: 12mm; place-items: center; overflow: hidden; border-radius: 1px; background: #ffffff; color: #111111; font-size: 6pt; }
.voucher-qr svg { display: block; width: 100%; height: 100%; }
.voucher-qr-wrap small { color: var(--voucher-muted); font-size: 4.8pt; }
.voucher-sheet[data-show-qr="false"] .voucher-qr-wrap { display: none; }
.voucher-card-details { display: flex; gap: 1.8mm; min-width: 0; margin: 0; padding: 0; list-style: none; }
.voucher-card-details li { display: flex; gap: 0.7mm; min-width: 0; }
.voucher-card-details strong { overflow: hidden; color: var(--voucher-fg); font-size: 5.4pt; text-overflow: ellipsis; white-space: nowrap; }
.voucher-card-footer { overflow: hidden; color: var(--voucher-muted); font-size: 5pt; line-height: 1.15; text-overflow: ellipsis; white-space: nowrap; }
.voucher-sheet[data-card-size="mini"] .voucher-card-footer { display: none; }
.voucher-sheet[data-card-size="mini"] .voucher-business-mark { width: 4mm; height: 4mm; flex-basis: 4mm; }
.voucher-sheet[data-card-size="mini"] .voucher-code-block strong { font-size: 11pt; }
.voucher-sheet[data-card-size="mini"] .voucher-card-details { gap: 1mm; }

.voucher-profile-grid { align-items: start; }
.voucher-template-gallery, .voucher-template-preview-field { grid-column: 1 / -1; }
.voucher-template-gallery { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.voucher-template-gallery > legend, .voucher-template-gallery-help { grid-column: 1 / -1; }
.voucher-template-gallery-help { margin-top: -3px; color: var(--color-text-muted); font-size: 10px; }
.voucher-template-gallery .voucher-template-choice { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto; gap: 7px; padding: 8px; }
.voucher-template-choice-heading { display: grid; gap: 1px; }
.voucher-template-choice-heading strong { color: var(--color-text-strong); font-size: 12px; }
.voucher-template-choice-heading small { overflow: hidden; color: var(--color-text-muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.voucher-template-option-preview { display: grid; min-width: 0; min-height: 105px; place-items: center; overflow: hidden; border: 1px solid var(--color-border); border-radius: 4px; background: var(--color-surface-subtle); padding: 5px; }
.voucher-template-option-preview .voucher-sheet { transform: scale(.82); }
.voucher-custom-upload > div { display: flex; align-items: center; gap: 9px; min-width: 0; }
.voucher-custom-upload .secondary-button { min-height: 34px; }
.voucher-custom-upload input[type="file"] { position: absolute; width: 1px; height: 1px; opacity: 0; }
.voucher-custom-upload [data-voucher-template-filename] { min-width: 0; overflow: hidden; color: var(--color-text-muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.voucher-custom-upload > small { color: var(--color-text-faint); font-size: 10px; }
.voucher-setting-group { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
.voucher-template-options { align-content: start; }
.voucher-qr-settings { align-content: start; }
.voucher-qr-settings > label:last-child { display: grid; gap: 6px; color: var(--color-text-muted); font-size: 11px; }
.voucher-qr-settings > small { color: var(--color-text-faint); font-size: 10px; line-height: 1.45; }
.voucher-template-preview { min-height: 160px; display: grid; place-items: center; overflow: auto; border: 1px solid var(--color-border); border-radius: var(--radius-control); background: var(--color-surface-subtle); padding: 14px; }

@media (max-width: 860px) {
  .detail-dialog:has(.voucher-print-dialog), .detail-dialog:has(.voucher-profile-dialog) { width: 100%; height: 100%; max-width: none; max-height: none; border: 0; border-radius: 0; margin: 0; }
  .voucher-print-dialog > .dialog-content { min-height: 0; flex: 1; overflow-y: auto; }
  .voucher-paper-picker { grid-template-columns: 1fr; }
  .voucher-print-preview { max-height: none; overflow: visible; padding: 10px; }
  .voucher-print-preview .voucher-sheet { grid-template-columns: 50mm; }
  .voucher-template-gallery { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .voucher-template-preview { min-height: 140px; }
}

@media (max-width: 520px) {
  .voucher-template-gallery { grid-template-columns: 1fr; }
  .voucher-custom-upload > div { align-items: flex-start; flex-direction: column; }
}

@media print {
  .voucher-print-dialog { padding: 0 !important; }
  .voucher-print-dialog > .dialog-content { padding: 0 !important; }
  .voucher-print-controls { display: none !important; }
  .voucher-print-preview { max-height: none !important; overflow: visible !important; border: 0 !important; background: #ffffff !important; padding: 0 !important; }
  .voucher-sheet { max-width: none !important; column-gap: 0 !important; row-gap: 1mm !important; justify-content: start; margin: 0 !important; }
  html[data-voucher-print-format="pos"] .voucher-sheet { grid-template-columns: 50mm !important; width: 50mm !important; }
  html[data-voucher-print-format="folio"] .voucher-sheet { grid-template-columns: repeat(4, 50mm) !important; }
  html[data-voucher-print-format="a4"][data-voucher-a4-columns="4"] .voucher-sheet { grid-template-columns: repeat(4, 50mm) !important; }
  html[data-voucher-print-format="a4"][data-voucher-a4-columns="5"] .voucher-sheet { grid-template-columns: repeat(5, 50mm) !important; }
}
