#certificateModal { backdrop-filter: none; padding: 16px; }
#certificateModal .certificate-modal {
    width: min(1300px, 100%); max-width: none; margin: 18px auto;
    height: min(900px, calc(100vh - 68px)); max-height: calc(100vh - 68px); padding-bottom: 0;
    overflow: hidden; border-radius: 8px; background: #fff;
    box-shadow: 0 20px 64px rgba(12, 38, 31, .24); color: #203b31;
}
#certificateApp, #certificateApp * { box-sizing: border-box; }
#certificateApp { display: flex; flex-direction: column; height: 100%; min-height: 0; }
#certificateApp button, #certificateApp input, #certificateApp select, #certificateApp textarea { font: inherit; }
#certificateApp button { cursor: pointer; }
#certificateApp button:disabled { opacity: .48; cursor: not-allowed; }
#certificateCanvas[hidden], #certificatePreviewEmpty[hidden], #certificateQrOption[hidden] { display: none !important; }
#certificateApp button:focus-visible, #certificateApp input:focus-visible,
#certificateApp select:focus-visible, #certificateApp textarea:focus-visible {
    outline: 2px solid #087855; outline-offset: 2px;
}
.cert-header { display: flex; flex: none; align-items: center; justify-content: space-between; padding: 20px 27px; border-bottom: 1px solid #e6ece7; }
.cert-eyebrow { display: block; color: #0c7956; font-size: 12px; font-weight: 700; }
.cert-header h2 { margin: 4px 0 0; color: #183d31; font-size: 25px; line-height: 1.2; }
.cert-close { width: 36px; height: 36px; border: 0; background: transparent; color: #60756b; font-size: 29px !important; line-height: 1; }
.cert-close:hover { color: #1e4738; }
.cert-workspace { display: grid; flex: 1; grid-template-columns: minmax(325px, 370px) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); min-height: 0; }
.cert-controls { min-height: 0; max-height: none; overflow-y: auto; overscroll-behavior-y: contain; padding: 0 23px 18px; border-right: 1px solid #e8ece8; }
.cert-control-section { padding: 20px 0; border-bottom: 1px solid #e9eeea; }
.cert-control-section:last-child { border-bottom: 0; }
.cert-section-heading { display: flex; align-items: center; gap: 10px; margin-bottom: 13px; }
.cert-step { display: grid; place-items: center; width: 23px; height: 23px; border-radius: 50%; background: #e4f2e9; color: #157856; font-size: 12px; font-weight: 800; }
.cert-section-heading h3 { margin: 0; color: #1c392f; font-size: 15px; }
.cert-section-heading small { margin-left: auto; color: #71847a; font-size: 12px; }
.cert-filter-row { display: grid; grid-template-columns: 126px minmax(0, 1fr); gap: 8px; }
.cert-filter-row select, .cert-filter-row input, .cert-control-section > input, .cert-control-section textarea {
    width: 100%; min-width: 0; min-height: 38px; padding: 8px 11px;
    border: 1px solid #d6e1d9; border-radius: 5px; background: #fff;
    color: #1e3c32; font-size: 13px;
}
.cert-control-section textarea { min-height: 96px; resize: vertical; line-height: 1.55; }
.cert-selection-actions { display: flex; gap: 16px; margin: 11px 0 7px; }
.cert-selection-actions button { padding: 0; border: 0; background: transparent; color: #0b7254; font-size: 12px; font-weight: 700; }
.cert-student-list { max-height: 150px; overflow-y: auto; border: 1px solid #e2e9e3; border-radius: 6px; }
.cert-student-row { display: flex; align-items: center; gap: 10px; min-height: 51px; padding: 6px 10px; border-bottom: 1px solid #edf1ed; cursor: pointer; }
.cert-student-row:last-child { border-bottom: 0; }
.cert-student-row.is-preview { background: #f3faf5; }
.cert-student-row input { accent-color: #0c805b; width: 16px; height: 16px; flex: none; }
.cert-student-initial { display: grid; place-items: center; width: 29px; height: 29px; flex: none; border-radius: 50%; background: #e4efe8; color: #315d47; font-size: 13px; font-weight: 700; }
.cert-student-meta { display: flex; flex: 1; min-width: 0; flex-direction: column; line-height: 1.3; }
.cert-student-meta strong { color: #273e34; font-size: 13px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.cert-student-meta small { color: #819188; font-size: 11px; }
.cert-preview-pick { padding: 4px 6px; border: 0; background: transparent; color: #0a7553; font-size: 12px !important; }
.cert-presets { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 5px; margin-bottom: 15px; }
.cert-presets button, .cert-format-row button { min-height: 34px; padding: 5px 4px; border: 1px solid #d8e4db; border-radius: 5px; background: #fff; color: #456155; font-size: 12px; font-weight: 600; }
.cert-presets button.is-active, .cert-format-row button.is-active { border-color: #0e8a61; background: #eaf7ef; color: #075b41; }
.cert-label { display: block; margin: 10px 0 6px; color: #4d6759; font-size: 12px; font-weight: 700; }
.cert-template-heading { display: flex; align-items: center; justify-content: space-between; margin: 16px 0 9px; }
.cert-template-heading strong { font-size: 13px; color: #304b40; }
.cert-template-heading span { font-size: 12px; color: #7a8b80; }
.cert-template-row { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.cert-template-row button { display: flex; flex-direction: column; align-items: stretch; gap: 7px; min-width: 0; padding: 5px 5px 8px; border: 1px solid #d9e4dc; border-radius: 5px; background: #fff; text-align: center; }
.cert-template-row button.is-active { border-color: #0c8a62; box-shadow: inset 0 0 0 1px #0c8a62; }
.cert-template-row button:hover { border-color: #79ae96; }
.cert-template-row canvas { display: block; width: 100%; height: auto; aspect-ratio: 1400 / 990; background: #f4f6f3; }
.cert-template-row b { color: #243d31; font-size: 12px; line-height: 1.3; font-weight: 600; }
.cert-format-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.cert-qr-option { display: flex; align-items: center; gap: 8px; margin-top: 12px; color: #49695a; font-size: 12px; cursor: pointer; }
.cert-qr-option input { accent-color: #0c805b; }
.cert-preview-side { display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow-y: auto; overscroll-behavior-y: contain; scrollbar-gutter: stable; padding: 18px 24px 22px; background: #f2f6f2; }
.cert-preview-side > * { flex-shrink: 0; }
.cert-preview-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.cert-preview-toolbar > div { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; min-width: 0; }
.cert-preview-toolbar strong { color: #253b30; font-size: 14px; white-space: nowrap; }
.cert-preview-toolbar small { color: #7a8b80; font-size: 12px; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; }
.cert-preview-toolbar > span { color: #5c8069; font-size: 11px; white-space: nowrap; }
.cert-preview-stage { display: grid; place-items: center; min-height: 0; padding: 12px; border: 1px solid #e0e8e1; border-radius: 6px; background: #e9eeea; }
.cert-preview-stage.is-empty { min-height: 150px; }
#certificateCanvas { display: block; width: 100%; max-width: 100%; height: auto; aspect-ratio: 1400 / 990; background: #fff; box-shadow: 0 6px 23px rgba(25, 48, 37, .12); }
.cert-empty { color: #829186; text-align: center; font-size: 13px; padding: 24px; }
.cert-message { min-height: 20px; margin: 8px 0 5px; color: #087453; font-size: 12px; }
.cert-actions { display: flex; justify-content: flex-end; gap: 8px; }
.cert-actions button { min-height: 39px; padding: 7px 17px; border-radius: 5px; font-size: 13px; font-weight: 700; }
.cert-secondary { border: 1px solid #bdd5c5; background: #fff; color: #1e674b; }
.cert-primary { border: 1px solid #067851; background: #067851; color: #fff; }
.cert-primary:hover { background: #086b4b; }
.cert-batch-entry { min-height: 38px; padding: 7px 12px; border: 1px solid #b8d1c1; border-radius: 5px; background: #f1faf4; color: #12714f; font-size: 12px; font-weight: 700; }
@media (max-width: 820px) {
    #certificateModal { padding: 0; }
    #certificateModal .certificate-modal { width: 100%; height: auto; max-height: none; min-height: 100%; margin: 0; border-radius: 0; overflow: visible; }
    #certificateApp { height: auto; }
    .cert-workspace { display: flex; flex: none; flex-direction: column; }
    .cert-controls { order: 2; max-height: none; overflow: visible; padding: 0 18px 18px; border-right: 0; }
    .cert-preview-side { order: 1; overflow: visible; scrollbar-gutter: auto; padding: 14px 18px; }
    .cert-preview-stage { padding: 7px; }
    .cert-preview-stage.is-empty { min-height: 100px; }
    .cert-template-row { grid-template-columns: repeat(5, minmax(108px, 1fr)); overflow-x: auto; padding: 2px 2px 7px; }
    .cert-actions button { flex: 1; }
    .cert-header { padding: 17px 18px 12px; }
    .cert-student-list { max-height: 190px; }
}
@media (max-width: 390px) {
    .cert-filter-row { grid-template-columns: 108px minmax(0, 1fr); }
    .cert-presets { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .cert-actions button { padding-inline: 5px; font-size: 12px; }
}
