/* =============================================================================
   Certificate Builder — Overlay, Steps, Editor
   ============================================================================= */

/* ── Overlay ── */
.cb-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.48);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 10000;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.cb-overlay.is-open {
    display: flex;
}

/* ── Modal (steps 1–3) ── */
.cb-modal {
    position: relative;
    background: #FFFFFF;
    border-radius: 20px;
    padding: 40px 40px 36px;
    width: 100%;
    max-width: 480px;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.22);
    transition: max-width 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94),
                border-radius 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* ── Modal — editor mode (full-screen) ── */
.cb-modal.cb-modal--editor {
    max-width: min(1080px, 97vw);
    height: min(90vh, 820px);
    padding: 0;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.cb-modal.cb-modal--editor .cb-content {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* ── Close button — floats outside the modal on the overlay ── */
.cb-close {
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.18);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1.5px solid rgba(255, 255, 255, 0.35);
    border-radius: 50%;
    font-size: 1.5rem;
    line-height: 1;
    color: #FFFFFF;
    cursor: pointer;
    padding: 0;
    transition: background 0.15s, border-color 0.15s, transform 0.12s;
}

.cb-close:hover {
    background: rgba(255, 255, 255, 0.32);
    border-color: rgba(255, 255, 255, 0.6);
    transform: scale(1.08);
}

/* ── Step badge ── */
.cb-step-badge {
    display: inline-block;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #6E6E73;
    background: #F0F0F5;
    border-radius: 20px;
    padding: 3px 10px;
    margin-bottom: 16px;
}

/* ── Step heading & description ── */
.cb-title {
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: #1D1D1F;
    margin: 0 0 6px;
    line-height: 1.2;
}

.cb-desc {
    font-size: 0.92rem;
    color: #6E6E73;
    margin: 0 0 28px;
    line-height: 1.5;
}

/* ─────────────────────────────────────────────────
   STEP 1 — Orientation
   ───────────────────────────────────────────────── */
.cb-orient-row {
    display: flex;
    gap: 16px;
    justify-content: center;
    margin-bottom: 4px;
}

.cb-orient-btn {
    flex: 1;
    max-width: 180px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    background: #F5F5F7;
    border: 2px solid transparent;
    border-radius: 16px;
    padding: 24px 16px 20px;
    cursor: pointer;
    transition: background 0.18s, border-color 0.18s, transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.cb-orient-btn:hover {
    background: #EBEBED;
    transform: translateY(-2px);
}

.cb-orient-btn.is-selected {
    background: #f3eeff;
    border-color: #845ec2;
}

.cb-orient-icon {
    width: 64px;
    height: 46px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #3A3A3C;
}

.cb-orient-icon--v {
    width: 46px;
    height: 64px;
}

.cb-orient-icon svg {
    width: 100%;
    height: 100%;
}

.cb-orient-btn.is-selected .cb-orient-icon {
    color: #845ec2;
}

.cb-orient-name {
    font-size: 0.94rem;
    font-weight: 600;
    color: #1D1D1F;
}

.cb-orient-sub {
    font-size: 0.78rem;
    color: #98989D;
    margin-top: -6px;
}

/* ─────────────────────────────────────────────────
   STEPS 2 & 3 — Upload areas
   ───────────────────────────────────────────────── */
.cb-upload-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    border: 2px dashed #D1D1D6;
    border-radius: 14px;
    padding: 32px 24px 28px;
    cursor: pointer;
    text-align: center;
    transition: border-color 0.18s, background 0.18s;
    background: #FAFAFA;
    margin-bottom: 16px;
}

.cb-upload-area:hover,
.cb-upload-area.is-dragover {
    border-color: #845ec2;
    background: #f3eeff;
}

.cb-file-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.cb-upload-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    background: #EBEBED;
    border-radius: 12px;
    color: #3A3A3C;
    margin-bottom: 4px;
}

.cb-upload-icon svg {
    width: 24px;
    height: 24px;
}

.cb-upload-text {
    font-size: 0.92rem;
    font-weight: 600;
    color: #1D1D1F;
}

.cb-upload-hint {
    font-size: 0.78rem;
    color: #98989D;
}

.cb-builtin-soon-wrap {
    margin: 8px 0 12px;
    display: flex;
    justify-content: center;
}

.cb-btn--builtin-soon {
    gap: 8px;
    padding: 10px 14px;
    border: 1px solid #D1D1D6;
    border-radius: 10px;
    color: #6E6E73;
    background: #F3F4F6;
    opacity: 1;
    cursor: not-allowed;
}

.cb-btn--builtin-soon:disabled {
    opacity: 1;
    transform: none !important;
}

.cb-builtin-soon-pill {
    display: inline-flex;
    align-items: center;
    padding: 3px 8px;
    border-radius: 999px;
    background: #E5E7EB;
    color: #6B7280;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

/* Image preview after upload */
.cb-preview {
    margin-bottom: 8px;
}

.cb-upload-ok {
    margin: 0;
    padding: 9px 12px;
    border-radius: 9px;
    border: 1px solid color-mix(in srgb, var(--c-green, #A8E000) 45%, #ffffff 55%);
    background: color-mix(in srgb, var(--c-green, #A8E000) 18%, #ffffff 82%);
    color: #2E4A08;
    font-size: 0.84rem;
    line-height: 1.4;
    word-break: break-word;
}

.cb-upload-ok--inline {
    width: 100%;
    text-align: center;
}

.cb-img-thumb {
    display: block;
    max-height: 120px;
    max-width: 100%;
    border-radius: 10px;
    object-fit: contain;
    margin: 0 auto;
    border: 1px solid #EBEBED;
}

/* Excel headings preview */
.cb-headings-found {
    margin-bottom: 8px;
}

.cb-found-label {
    font-size: 0.84rem;
    color: #6E6E73;
    margin: 0 0 8px;
}

.cb-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.cb-chip {
    display: inline-block;
    background: #f3eeff;
    color: #845ec2;
    font-size: 0.78rem;
    font-weight: 600;
    border-radius: 20px;
    padding: 3px 10px;
}

.cb-error-msg {
    font-size: 0.84rem;
    color: #D32F2F;
    background: #FFF5F5;
    border-radius: 8px;
    padding: 8px 12px;
    margin: 0;
}

/* ─────────────────────────────────────────────────
   Step action bar (Back / Next)
   ───────────────────────────────────────────────── */
.cb-step-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 28px;
}

/* ─────────────────────────────────────────────────
   Buttons (shared)
   ───────────────────────────────────────────────── */
.cb-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: inherit;
    font-size: 0.9rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    border-radius: 10px;
    padding: 10px 22px;
    border: none;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1),
                box-shadow 0.15s, opacity 0.15s;
}

.cb-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none !important;
}

.cb-btn--primary {
    background: #1D1D1F;
    color: #FFFFFF;
}

.cb-btn--primary:not(:disabled):hover {
    background: #3A3A3C;
    transform: translateY(-1px) scale(1.02);
}

/* ─────────────────────────────────────────────────
   Themed alert popup (file validation / PDF rules)
   ───────────────────────────────────────────────── */
.cb-theme-alert-overlay {
    position: absolute;
    inset: 0;
    background: rgba( 10, 10, 14, 0.44 );
    backdrop-filter: blur( 4px );
    -webkit-backdrop-filter: blur( 4px );
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 60;
    padding: 18px;
}

.cb-theme-alert {
    width: min( 420px, 100% );
    background: #FFFFFF;
    border-radius: 14px;
    border: 1px solid rgba( 132, 94, 194, 0.20 );
    box-shadow: 0 18px 52px rgba( 0, 0, 0, 0.22 );
    padding: 18px 18px 14px;
}

.cb-theme-alert__title {
    margin: 0 0 8px;
    font-size: 1.02rem;
    line-height: 1.3;
    font-weight: 700;
    color: #1D1D1F;
}

.cb-theme-alert__msg {
    margin: 0;
    font-size: 0.9rem;
    line-height: 1.5;
    color: #3A3A3C;
}

.cb-theme-alert__actions {
    margin-top: 14px;
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.cb-theme-alert__link {
    text-decoration: none;
}

.cb-btn--ghost {
    background: transparent;
    color: #3A3A3C;
    border: 1.5px solid #D1D1D6;
}

.cb-btn--ghost:hover {
    background: #F5F5F7;
    border-color: #B0B0B8;
}

.cb-btn--sm {
    font-size: 0.84rem;
    padding: 8px 16px;
    border-radius: 8px;
}

.cb-btn--export {
    background: #845ec2;
    color: #FFFFFF;
    font-size: 0.84rem;
    padding: 8px 18px;
    border-radius: 8px;
}

.cb-btn--export:hover {
    background: #6b48a8;
    transform: translateY(-1px);
}

/* Snap grid toggle button */
.cb-grid-toggle-label {
    gap: 0;
}

.cb-grid-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 32px;
    padding: 0 12px;
    background: #FFFFFF;
    border: 1.5px solid #D1D1D6;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 600;
    color: #6E6E73;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.cb-grid-toggle svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.cb-grid-toggle:hover {
    background: #F5F5F7;
    border-color: #B0B0B8;
    color: #1D1D1F;
}

.cb-grid-toggle.is-on {
    background: #f3eeff;
    border-color: #845ec2;
    color: #845ec2;
}

.cb-grid-toggle.is-on svg {
    color: #845ec2;
}

/* Preview button */
.cb-btn--preview {
    background: #FFFFFF;
    color: #1D1D1F;
    font-size: 0.84rem;
    padding: 8px 18px;
    border-radius: 8px;
    border: 1.5px solid #D1D1D6;
}

.cb-btn--preview:hover {
    background: #F5F5F7;
    border-color: #B0B0B8;
    transform: translateY(-1px);
}

/* ─────────────────────────────────────────────────
   EDITOR
   ───────────────────────────────────────────────── */
.cb-editor {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

/* Toolbar */
.cb-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: nowrap;
    gap: 10px;
    padding: 12px 20px;
    background: #F5F5F7;
    border-bottom: 1px solid #EBEBED;
    flex-shrink: 0;
    overflow-x: auto;
}

.cb-toolbar-left,
.cb-toolbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap;
    flex-shrink: 0;
}

.cb-select {
    height: 36px;
    padding: 0 12px;
    border: 1.5px solid #D1D1D6;
    border-radius: 8px;
    background: #FFFFFF;
    font-family: inherit;
    font-size: 0.86rem;
    color: #1D1D1F;
    cursor: pointer;
    min-width: 180px;
    outline: none;
    transition: border-color 0.15s;
}

.cb-select:focus {
    border-color: #845ec2;
}

.cb-tool-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    color: #6E6E73;
    font-weight: 500;
}

.cb-num-input {
    width: 58px;
    height: 32px;
    padding: 0 8px;
    border: 1.5px solid #D1D1D6;
    border-radius: 7px;
    font-family: inherit;
    font-size: 0.86rem;
    text-align: center;
    color: #1D1D1F;
    outline: none;
    transition: border-color 0.15s;
}

.cb-num-input:focus {
    border-color: #845ec2;
}

.cb-color-input {
    width: 32px;
    height: 32px;
    padding: 2px;
    border: 1.5px solid #D1D1D6;
    border-radius: 7px;
    background: none;
    cursor: pointer;
}

/* Canvas wrap — scrollable */
.cb-canvas-wrap {
    flex: 1;
    overflow: auto;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    background: #EBEBED;
    padding: 24px;
}

/* Canvas — the actual certificate area */
.cb-canvas {
    position: relative;
    flex-shrink: 0;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.18);
    border-radius: 4px;
    overflow: hidden;
    cursor: default;
    user-select: none;
    background: #FFFFFF;
    margin: auto;
}

.cb-canvas-bg {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    pointer-events: none;
}

/* Grid overlay canvas — sits between bg image and field labels */
.cb-grid-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    opacity: 1;
}

.cb-fields {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

/* ── Field box ── */
.cb-field {
    position: absolute;
    pointer-events: all;
    cursor: grab;
    border-radius: 6px;
    background: transparent;
    box-sizing: border-box;
    overflow: hidden;
    transition: box-shadow 0.15s;
    display: flex;
    flex-direction: column;
}

.cb-field.has-border {
    outline: 2px solid var(--field-border-color, #1D1D1F);
}

.cb-field.is-active {
    box-shadow: 0 0 0 2px rgba(132, 94, 194, 0.7), 0 4px 16px rgba(0, 0, 0, 0.12);
    z-index: 10;
}

.cb-field.cb-field--merge-target {
    box-shadow: 0 0 0 3px #22C55E, 0 4px 16px rgba(34, 197, 94, 0.25);
}

.cb-field:active {
    cursor: grabbing;
}

/* ── Field text (wraps inside box) ── */
.cb-field-text {
    display: block;
    width: 100%;
    padding: 6px 32px 6px 16px;
    box-sizing: border-box;
    line-height: 1.25;
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: pre-wrap;
    pointer-events: none;
    overflow: hidden;
}

/* ── Settings gear button ── */
.cb-field-settings-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.92);
    border: 1.5px solid rgba(132, 94, 194, 0.25);
    border-radius: 7px;
    cursor: pointer;
    padding: 0;
    opacity: 0;
    transition: opacity 0.15s, background 0.15s, border-color 0.15s;
    z-index: 2;
}

.cb-field:hover .cb-field-settings-btn,
.cb-field.is-active .cb-field-settings-btn {
    opacity: 1;
}

.cb-field-settings-btn:hover {
    background: #f3eeff;
}

.cb-field-settings-btn svg {
    width: 15px;
    height: 15px;
    color: #845ec2;
    display: block;
}

/* ── 8-point resize handles ── */
.cb-resize-handle {
    position: absolute;
    width: 10px;
    height: 10px;
    background: #FFFFFF;
    border: 2px solid #845ec2;
    border-radius: 2px;
    z-index: 3;
    opacity: 0;
    transition: opacity 0.15s;
}

.cb-field.is-active .cb-resize-handle {
    opacity: 1;
}

.rh-nw { top: -5px;  left: -5px;              cursor: nw-resize; }
.rh-n  { top: -5px;  left: calc(50% - 5px);   cursor: n-resize;  }
.rh-ne { top: -5px;  right: -5px;             cursor: ne-resize; }
.rh-e  { top: calc(50% - 5px); right: -5px;   cursor: e-resize;  }
.rh-se { bottom: -5px; right: -5px;           cursor: se-resize; }
.rh-s  { bottom: -5px; left: calc(50% - 5px); cursor: s-resize;  }
.rh-sw { bottom: -5px; left: -5px;            cursor: sw-resize; }
.rh-w  { top: calc(50% - 5px); left: -5px;    cursor: w-resize;  }

/* ── Floating field settings panel ── */
.cb-field-panel {
    display: none;
    position: fixed;
    width: 240px;
    max-height: min(500px, calc(100vh - 40px));
    background: #FFFFFF;
    border: 1px solid #E0E0E5;
    border-radius: 14px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.16);
    z-index: 20000;
    overflow: hidden;
    flex-direction: column;
}

.cb-field-panel.is-open {
    display: flex;
}

.cb-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px 10px;
    border-bottom: 1px solid #F0F0F5;
    background: #FAFAFA;
}

.cb-panel-title {
    font-size: 0.84rem;
    font-weight: 700;
    color: #1D1D1F;
    letter-spacing: -0.01em;
}

.cb-panel-close {
    background: none;
    border: none;
    font-size: 1.1rem;
    color: #98989D;
    cursor: pointer;
    padding: 2px 5px;
    border-radius: 6px;
    line-height: 1;
}

.cb-panel-close:hover {
    background: #F0F0F5;
    color: #1D1D1F;
}

.cb-panel-body {
    padding: 12px 14px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
    flex: 1;
}

.cb-panel-label {
    font-size: 0.74rem;
    font-weight: 600;
    color: #6E6E73;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 2px;
    display: block;
}

.cb-panel-select {
    width: 100%;
    height: 34px;
    padding: 0 8px;
    border: 1.5px solid #D1D1D6;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.86rem;
    color: #1D1D1F;
    background: #FFFFFF;
    cursor: pointer;
    outline: none;
}

.cb-panel-select:focus {
    border-color: #845ec2;
}

.cb-panel-row {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.cb-panel-row--border {
    align-items: center;
    justify-content: space-between;
}

.cb-panel-col {
    flex: 1;
}

.cb-panel-num {
    width: 100%;
    height: 34px;
    padding: 0 8px;
    border: 1.5px solid #D1D1D6;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.86rem;
    text-align: center;
    color: #1D1D1F;
    outline: none;
    box-sizing: border-box;
}

.cb-panel-num:focus {
    border-color: #845ec2;
}

.cb-panel-color {
    width: 34px;
    height: 34px;
    padding: 2px;
    border: 1.5px solid #D1D1D6;
    border-radius: 8px;
    background: none;
    cursor: pointer;
    flex-shrink: 0;
}

/* ── Alignment buttons ── */
.cb-pos-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 3px;
    margin-bottom: 8px;
}

.cb-align-btn {
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #F5F5F7;
    border: 1.5px solid transparent;
    border-radius: 7px;
    cursor: pointer;
    padding: 0;
    transition: background 0.12s, border-color 0.12s;
}

.cb-align-btn svg {
    width: 14px;
    height: 14px;
    color: #6E6E73;
}

.cb-align-btn:hover {
    background: #EBEBED;
}

.cb-align-btn.is-active {
    background: #f3eeff;
    border-color: #845ec2;
}

.cb-align-btn.is-active svg {
    color: #845ec2;
}

/* ── Border toggle ── */
.cb-toggle-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.84rem;
    font-weight: 500;
    color: #3A3A3C;
    cursor: pointer;
}

.cb-panel-checkbox {
    width: 16px;
    height: 16px;
    accent-color: #845ec2;
    cursor: pointer;
}

/* ── Delete button in panel ── */
.cb-panel-delete-btn {
    display: flex;
    align-items: center;
    gap: 7px;
    width: 100%;
    padding: 8px 10px;
    background: #FFF5F5;
    border: 1px solid #FECACA;
    border-radius: 8px;
    color: #DC2626;
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    margin-top: 4px;
    transition: background 0.12s;
}

.cb-panel-delete-btn:hover {
    background: #FEE2E2;
}

.cb-panel-delete-btn svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

/* ── Merge popup ── */
.cb-merge-popup {
    position: absolute;
    background: #FFFFFF;
    border: 1px solid #E0E0E5;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
    padding: 14px 16px;
    width: 240px;
    z-index: 15000;
}

.cb-merge-msg {
    font-size: 0.86rem;
    color: #1D1D1F;
    margin: 0 0 4px;
    line-height: 1.4;
}

.cb-merge-sub {
    font-size: 0.78rem;
    color: #6E6E73;
    margin: 0 0 12px;
}

.cb-merge-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

/* ── Panel divider ── */
.cb-panel-divider {
    height: 1px;
    background: #F0F0F5;
    margin: 2px 0;
}

/* ── Export size dialog (fixed overlay) ── */
.cb-size-dialog {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.48);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 25000;
}

.cb-size-dialog-inner {
    background: #FFFFFF;
    border-radius: 18px;
    padding: 32px 36px 28px;
    text-align: center;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.28);
    min-width: 280px;
}

.cb-size-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: #1D1D1F;
    margin: 0 0 6px;
    letter-spacing: -0.02em;
}

.cb-size-desc {
    font-size: 0.86rem;
    color: #6E6E73;
    margin: 0 0 22px;
}

.cb-size-options {
    display: flex;
    gap: 14px;
    justify-content: center;
    margin-bottom: 18px;
}

.cb-size-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 18px 26px 16px;
    border: 2px solid #D1D1D6;
    border-radius: 14px;
    background: #FFFFFF;
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
    min-width: 100px;
}

.cb-size-btn:hover {
    border-color: #845ec2;
    box-shadow: 0 0 0 3px rgba(132, 94, 194, 0.12);
    background: #F9F9FF;
}

.cb-size-name {
    font-size: 1.4rem;
    font-weight: 700;
    color: #1D1D1F;
    line-height: 1;
}

.cb-size-sub {
    font-size: 0.72rem;
    color: #6E6E73;
    line-height: 1;
}

/* Paper size icon shapes */
.cb-size-icon {
    display: block;
    background: #F5F5F7;
    border: 1.5px solid #C7C7CC;
    border-radius: 2px;
}

.cb-size-icon--a4 {
    width: 30px;
    height: 42px;
}

.cb-size-icon--a5 {
    width: 42px;
    height: 30px;
}

/* Hint bar */
.cb-hint {
    flex-shrink: 0;
    padding: 8px 20px;
    font-size: 0.78rem;
    color: #98989D;
    background: #FAFAFA;
    border-top: 1px solid #EBEBED;
    text-align: center;
    line-height: 1.4;
}

.cb-hint kbd {
    display: inline-block;
    padding: 1px 5px;
    background: #EBEBED;
    border-radius: 4px;
    font-family: inherit;
    font-size: 0.75rem;
    color: #3A3A3C;
}

/* ── Panel textarea (custom text field) ── */
.cb-panel-textarea {
    width: 100%;
    min-height: 64px;
    padding: 8px 10px;
    border: 1.5px solid #D1D1D6;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.86rem;
    color: #1D1D1F;
    background: #FFFFFF;
    resize: vertical;
    outline: none;
    box-sizing: border-box;
    transition: border-color 0.15s;
    margin-bottom: 6px;
    line-height: 1.45;
}

.cb-panel-textarea:focus {
    border-color: #845ec2;
}

.cb-panel-textarea.is-error {
    border-color: #DC2626;
}

/* ── Custom text popup ── */
.cb-custom-popup {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #FFFFFF;
    border: 1px solid #E0E0E5;
    border-radius: 16px;
    box-shadow: 0 16px 60px rgba(0, 0, 0, 0.24);
    padding: 22px 22px 18px;
    width: min(340px, 90vw);
    z-index: 25000;
}

.cb-custom-popup-title {
    font-size: 1rem;
    font-weight: 700;
    color: #1D1D1F;
    margin: 0 0 4px;
    letter-spacing: -0.01em;
}

.cb-custom-popup-sub {
    font-size: 0.8rem;
    color: #6E6E73;
    margin: 0 0 12px;
    line-height: 1.4;
}

.cb-custom-popup-textarea {
    width: 100%;
    min-height: 80px;
    padding: 10px 12px;
    border: 1.5px solid #D1D1D6;
    border-radius: 10px;
    font-family: inherit;
    font-size: 0.9rem;
    color: #1D1D1F;
    background: #FAFAFA;
    resize: vertical;
    outline: none;
    box-sizing: border-box;
    transition: border-color 0.15s, background 0.15s;
    line-height: 1.5;
    display: block;
    margin-bottom: 14px;
}

.cb-custom-popup-textarea:focus {
    border-color: #845ec2;
    background: #FFFFFF;
}

.cb-custom-popup-textarea.is-error {
    border-color: #DC2626;
    animation: cb-shake 0.3s ease;
}

@keyframes cb-shake {
    0%, 100% { transform: translateX(0); }
    25%       { transform: translateX(-6px); }
    75%       { transform: translateX(6px); }
}

.cb-custom-popup-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

/* =============================================================================
   Responsive — Tablet ≤ 768 px
   ============================================================================= */
@media (max-width: 768px) {

    /* Steps 1–3 modal: centred, full width, tighter padding */
    .cb-overlay {
        padding: 12px;
    }

    .cb-modal {
        max-width: 100%;
        padding: 28px 24px 32px;
        border-radius: 16px;
    }

    /* Editor: full-screen */
    .cb-modal.cb-modal--editor {
        max-width: 100%;
        width: 100%;
        height: 100vh;      /* fallback */
        height: 100svh;     /* avoids mobile browser chrome overlap */
        border-radius: 0;
    }

    /* Toolbar: each side becomes a full row */
    .cb-toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
        padding: 10px 14px;
    }

    .cb-toolbar-left,
    .cb-toolbar-right {
        width: 100%;
        flex-wrap: wrap;
    }

    .cb-toolbar-right {
        justify-content: flex-end;
    }

    .cb-select {
        flex: 1;
        min-width: 0;
    }

    /* Canvas wrap: tighter padding so canvas gets more space */
    .cb-canvas-wrap {
        padding: 12px;
        align-items: flex-start;
        justify-content: flex-start;
    }

    /* Field settings panel: full-width bottom drawer */
    .cb-field-panel {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        top: auto !important;
        right: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        max-height: 65vh !important;
        border-radius: 16px 16px 0 0;
        box-shadow: 0 -4px 32px rgba(0, 0, 0, 0.20);
    }

    /* Drag-handle pill at top of bottom drawer */
    .cb-panel-header::before {
        content: '';
        display: block;
        position: absolute;
        top: 8px;
        left: 50%;
        transform: translateX(-50%);
        width: 36px;
        height: 4px;
        background: #D1D1D6;
        border-radius: 2px;
        pointer-events: none;
    }

    .cb-panel-header {
        position: relative; /* needed for ::before */
        padding-top: 20px;
    }

    /* Keyboard-shortcut hint is irrelevant on touch */
    .cb-hint {
        display: none;
    }
}

/* =============================================================================
   Responsive — Phone ≤ 480 px
   ============================================================================= */
@media (max-width: 480px) {

    .cb-overlay {
        padding: 0;
        align-items: flex-end; /* modal slides up from bottom */
    }

    .cb-modal {
        border-radius: 20px 20px 0 0;
        padding: 22px 18px 36px; /* extra bottom padding for thumb safety */
    }

    .cb-title {
        font-size: 1.2rem;
    }

    .cb-desc {
        font-size: 0.86rem;
        margin-bottom: 20px;
    }

    .cb-orient-btn {
        padding: 18px 10px 14px;
    }

    .cb-upload-area {
        padding: 22px 16px 18px;
    }

    .cb-toolbar {
        padding: 8px 12px;
        gap: 6px;
    }

    .cb-btn--export,
    .cb-btn--preview {
        font-size: 0.78rem;
        padding: 7px 12px;
    }

    .cb-btn--sm {
        font-size: 0.78rem;
        padding: 7px 11px;
    }

    .cb-canvas-wrap {
        padding: 8px;
    }

    .cb-size-dialog-inner {
        padding: 24px 18px 20px;
        min-width: 0;
        width: min(300px, 92vw);
    }

    .cb-size-options {
        gap: 10px;
    }

    .cb-size-btn {
        padding: 14px 18px 12px;
        min-width: 0;
    }

    .cb-custom-popup {
        width: min(300px, 94vw);
        padding: 18px 16px 14px;
    }

    .cb-merge-popup {
        width: min(230px, 88vw);
    }
}

/* =============================================================================
   Touch devices — always-visible gear, larger resize handles
   ============================================================================= */
@media (hover: none) and (pointer: coarse) {

    /* Gear button always visible (no hover on touch screens) */
    .cb-field-settings-btn {
        opacity: 1;
        width: 34px;
        height: 34px;
    }

    .cb-field-settings-btn svg {
        width: 18px;
        height: 18px;
    }

    /* Bigger resize handles for fat fingers */
    .cb-resize-handle {
        width: 18px;
        height: 18px;
    }

    .rh-nw { top:  -9px; left:  -9px; }
    .rh-n  { top:  -9px; left:  calc(50% - 9px); }
    .rh-ne { top:  -9px; right: -9px; }
    .rh-e  { top:  calc(50% - 9px); right: -9px; }
    .rh-se { bottom: -9px; right: -9px; }
    .rh-s  { bottom: -9px; left:  calc(50% - 9px); }
    .rh-sw { bottom: -9px; left:  -9px; }
    .rh-w  { top:  calc(50% - 9px); left:  -9px; }

    /* Remove hover-only transforms that feel wrong on touch */
    .cb-orient-btn:hover  { transform: none; }
    .cb-btn--primary:not(:disabled):hover { transform: none; }
    .cb-btn--export:hover { transform: none; }
    .cb-btn--preview:hover { transform: none; }
}

/* ============================================================
   Certificate Preview Overlay  (freemium watermark preview)
============================================================ */

.cb-cert-preview-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.55);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    box-sizing: border-box;
}

.cb-prev-panel {
    background: #fff;
    border-radius: 14px;
    display: flex;
    flex-direction: column;
    max-width: 900px;
    width: 100%;
    max-height: 90vh;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    overflow: hidden;
}

.cb-prev-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #E5E7EB;
    flex-shrink: 0;
}

.cb-prev-title {
    font-size: 1rem;
    font-weight: 700;
    color: #1D1D1F;
    margin: 0;
}

.cb-prev-close {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.4rem;
    color: #6B7280;
    line-height: 1;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background 0.15s, color 0.15s;
}

.cb-prev-close:hover {
    background: #F3F4F6;
    color: #1D1D1F;
}

.cb-prev-scroll {
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.cb-prev-item {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.cb-prev-item-num {
    font-size: 0.75rem;
    font-weight: 600;
    color: #6B7280;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.cb-prev-img {
    width: 100%;
    border-radius: 8px;
    border: 1px solid #E5E7EB;
    display: block;
}

.cb-prev-more {
    font-size: 0.8rem;
    color: #6B7280;
    text-align: center;
    margin: 0;
}

/* ─ Subscribe banner at top of cert preview panel ─ */
.cb-prev-banner {
    display: flex;
    align-items: center;
    gap: 16px;
    background: #fff;
    border: 1.5px solid #E5E7EB;
    border-radius: 16px;
    padding: 18px 20px;
    flex-shrink: 0;
    box-shadow: 0 2px 10px rgba(0,0,0,0.06);
}

.cb-prev-banner__body {
    display: flex;
    flex-direction: column;
    gap: 5px;
    min-width: 0;
}

.cb-prev-banner__title {
    font-size: 0.9375rem;
    font-weight: 700;
    color: #1D1D1F;
    line-height: 1.25;
}

.cb-prev-banner__msg {
    font-size: 0.8rem;
    color: #6B7280;
    line-height: 1.5;
}

.cb-prev-banner__btn {
    margin-top: 6px;
    display: inline-block;
    background: linear-gradient(135deg, #845ec2 0%, #c94b8a 60%, #ff6f91 100%);
    color: #fff;
    font-weight: 700;
    font-size: 0.825rem;
    padding: 7px 16px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    transition: filter 0.15s, transform 0.12s;
    align-self: flex-start;
    letter-spacing: 0.01em;
    box-shadow: 0 2px 8px rgba(201,75,138,0.35);
}
.cb-prev-banner__btn:hover {
    filter: brightness(1.08);
    transform: translateY(-1px);
}

/* ============================================================
   Save / Load Layout buttons in toolbar
   ============================================================ */

.cb-btn--layout-save,
.cb-btn--layout-load {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 32px;
    padding: 0 10px;
    font-family: inherit;
    font-size: 0.78rem;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.12s;
    white-space: nowrap;
    flex-shrink: 0;
}

.cb-btn--layout-save {
    background: #f3eeff;
    border: 1.5px solid #845ec2;
    color: #845ec2;
}
.cb-btn--layout-save:hover {
    background: #845ec2;
    color: #fff;
    transform: translateY(-1px);
}
.cb-btn--layout-save:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.cb-btn--layout-load {
    background: #fff;
    border: 1.5px solid #D1D1D6;
    color: #3a3a3c;
}
.cb-btn--layout-load:hover {
    background: #f5f5f7;
    border-color: #845ec2;
    color: #845ec2;
    transform: translateY(-1px);
}

/* Danger variant reuse */
.cb-btn--danger {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: transparent;
    border: 1.5px solid #ff3b30;
    color: #ff3b30;
    border-radius: 6px;
    padding: 5px 10px;
    font-size: 0.78rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.cb-btn--danger:hover { background: #ff3b30; color: #fff; }

/* ── Saved layout info banner (below toolbar) ── */
.cb-layout-saved-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    background: #f3eeff;
    border-bottom: 1.5px solid #845ec2;
    font-size: 0.82rem;
    color: #3a3a3c;
    flex-wrap: wrap;
}
.cb-layout-saved-banner strong { color: #845ec2; }
.cb-layout-banner-close {
    margin-left: auto;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
    color: #6e6e73;
    line-height: 1;
    padding: 0 2px;
}
.cb-layout-banner-close:hover { color: #1D1D1F; }

/* ── Layout picker overlay (overwrite / load) ── */
.cb-layout-picker-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    border-radius: inherit;
}

.cb-layout-picker {
    background: #fff;
    border-radius: 16px;
    padding: 28px 24px;
    width: min(460px, 92vw);
    box-shadow: 0 12px 48px rgba(0,0,0,0.22);
}

.cb-picker-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: #1D1D1F;
    margin: 0 0 6px;
}

.cb-picker-sub {
    font-size: 0.84rem;
    color: #6e6e73;
    margin: 0 0 18px;
}

.cb-picker-slots {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 18px;
}

/* Overwrite picker — simple slot buttons */
.cb-picker-slot-btn {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    width: 100%;
    padding: 12px 14px;
    background: #F5F5F7;
    border: 1.5px solid #E5E5EA;
    border-radius: 10px;
    cursor: pointer;
    text-align: left;
    transition: background 0.14s, border-color 0.14s;
}
.cb-picker-slot-btn:hover {
    background: #f3eeff;
    border-color: #845ec2;
}
.cb-picker-slot-name {
    font-size: 0.92rem;
    font-weight: 600;
    color: #1D1D1F;
}
.cb-picker-slot-date {
    font-size: 0.76rem;
    color: #6e6e73;
}

/* Load picker — slot rows with apply + delete */
.cb-load-slot {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    background: #F5F5F7;
    border: 1.5px solid #E5E5EA;
    border-radius: 10px;
}
.cb-load-slot-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}
.cb-load-slot-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.cb-picker-cancel {
    display: block;
    width: 100%;
    padding: 9px;
    background: none;
    border: 1.5px solid #D1D1D6;
    border-radius: 8px;
    font-size: 0.84rem;
    font-weight: 500;
    color: #6e6e73;
    cursor: pointer;
    transition: background 0.14s;
}
.cb-picker-cancel:hover { background: #F5F5F7; }
