.cfp-app {
    --cfp-primary: #2563eb;
    --cfp-secondary: #1e40af;
    --cfp-btn: #2563eb;
    --cfp-btn-text: #ffffff;
    --cfp-sbtn: #6b7280;
    --cfp-sbtn-text: #ffffff;
    --cfp-accent: #f59e0b;
    --cfp-text: #111827;
    --cfp-guide-oval: #f59e0b;
    --cfp-guide-oval-width: 2;
    --cfp-guide-eye: #2563eb;
    --cfp-guide-eye-width: 3;
    max-width: 760px;
    margin: 0 auto;
    color: var(--cfp-text);
    font-family: inherit;
    position: relative;
}

/* El atributo hidden debe ganar siempre, incluso sobre display:flex/grid */
.cfp-app [hidden] {
    display: none !important;
}

.cfp-card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 16px;
    padding: 28px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, .06);
}

.cfp-title { margin: 0 0 6px; font-size: 22px; font-weight: 700; }
.cfp-subtitle { margin: 0 0 10px; font-size: 16px; font-weight: 600; }
.cfp-muted { color: #6b7280; font-size: 14px; margin: 0 0 16px; }
.cfp-error { color: #dc2626; font-size: 14px; font-weight: 600; margin: 10px 0 0; }
.cfp-error a { color: var(--cfp-primary); text-decoration: underline; }

/* Botones */
.cfp-btn {
    display: inline-flex; align-items: center; justify-content: center;
    gap: 6px; padding: 12px 20px; border-radius: 10px;
    font-size: 15px; font-weight: 600; cursor: pointer;
    border: 2px solid transparent; text-decoration: none; transition: opacity .15s, transform .05s;
    line-height: 1;
}
.cfp-btn:active { transform: translateY(1px); }
.cfp-btn-primary { background: var(--cfp-btn); color: var(--cfp-btn-text); border-color: var(--cfp-btn); }
.cfp-btn-primary:hover { opacity: .92; color: var(--cfp-btn-text); }
.cfp-btn-secondary { background: var(--cfp-sbtn); color: var(--cfp-sbtn-text); border-color: var(--cfp-sbtn); }
.cfp-btn-secondary:hover { opacity: .92; }
.cfp-btn-outline { background: #fff; color: var(--cfp-primary); border-color: var(--cfp-primary); }
.cfp-btn-outline.cfp-active { background: var(--cfp-primary); color: #fff; }
.cfp-btn-tiny { padding: 6px 12px; font-size: 13px; background: #f3f4f6; color: #374151; }
.cfp-btn-block { width: 100%; }
.cfp-btn.cfp-disabled { opacity: .45; cursor: not-allowed; filter: grayscale(.4); }

.cfp-actions { display: flex; justify-content: space-between; gap: 12px; margin-top: 22px; }
.cfp-actions-center { justify-content: center; flex-wrap: wrap; }

/* Paso 1 carga */
.cfp-upload-card { text-align: center; position: relative; }
.cfp-upload-icon { font-size: 52px; margin-bottom: 8px; }
.cfp-upload-btn { cursor: pointer; margin-top: 6px; }
.cfp-upload-dropzone {
    position: absolute; inset: 0; border: 3px dashed transparent; border-radius: 16px;
    pointer-events: none; /* no debe interceptar los clics del botón */
}
.cfp-upload-dropzone.cfp-drag { border-color: var(--cfp-primary); background: rgba(37, 99, 235, .04); }

/* Paso 2 formatos */
.cfp-formats { display: grid; gap: 12px; margin: 16px 0; }
.cfp-format {
    display: flex; align-items: center; gap: 12px; padding: 14px 16px;
    border: 2px solid #e5e7eb; border-radius: 12px; cursor: pointer; transition: border-color .15s, background .15s;
}
.cfp-format:hover { border-color: var(--cfp-primary); }
.cfp-format.cfp-selected { border-color: var(--cfp-primary); background: rgba(37, 99, 235, .05); }
.cfp-format input { width: 18px; height: 18px; accent-color: var(--cfp-primary); }
.cfp-format-body { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.cfp-format-name { font-weight: 600; }
.cfp-badge {
    display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 700;
    background: var(--cfp-accent); color: #fff; padding: 3px 9px; border-radius: 999px;
}
.cfp-custom-dims { display: flex; align-items: flex-end; gap: 12px; margin: 4px 0 0; }
.cfp-custom-dims .cfp-x { font-size: 20px; padding-bottom: 8px; color: #6b7280; }
.cfp-field { display: flex; flex-direction: column; gap: 4px; }
.cfp-field label { font-size: 13px; color: #6b7280; }
.cfp-field input { width: 100px; padding: 8px 10px; border: 1px solid #d1d5db; border-radius: 8px; }

/* Paso 3 editor */
.cfp-editor-grid { display: grid; grid-template-columns: auto 1fr; gap: 28px; }
.cfp-preview-col { display: flex; flex-direction: column; align-items: center; }
.cfp-stage { position: relative; margin: 36px 0 8px; }
.cfp-preview-col .cfp-subtitle { margin-bottom: 18px; }
.cfp-crop {
    position: absolute; left: 40px; top: 0; overflow: hidden;
    border: 2px solid var(--cfp-primary); background: #fff; cursor: grab; touch-action: none;
    box-shadow: 0 0 0 4000px rgba(0,0,0,.02);
}
.cfp-crop.cfp-dragging { cursor: grabbing; }
.cfp-guide { position: absolute; left: 0; top: 0; pointer-events: none; z-index: 2; }
.cfp-guide ellipse { fill: none; stroke: var(--cfp-guide-oval); stroke-width: var(--cfp-guide-oval-width); stroke-dasharray: 6 5; opacity: .9; }
.cfp-guide .cfp-guide-dash { stroke: var(--cfp-guide-oval); stroke-width: var(--cfp-guide-oval-width); stroke-dasharray: 5 4; opacity: .75; }
.cfp-guide .cfp-guide-eye { stroke: var(--cfp-guide-eye); stroke-width: var(--cfp-guide-eye-width); stroke-dasharray: 3 3; opacity: .9; }
.cfp-check { display: flex; align-items: center; gap: 8px; font-size: 14px; margin-top: 8px; cursor: pointer; }
.cfp-check input { width: 16px; height: 16px; accent-color: var(--cfp-primary); }
.cfp-face-hint { margin-top: 6px; font-size: 12px; }
.cfp-crop img {
    position: absolute; left: 50%; top: 50%; user-select: none; pointer-events: none;
    /* El tema suele imponer img{max-width:100%}; debe respetarse el ancho real
       calculado por JS para que la vista previa coincida con el PDF generado. */
    max-width: none !important;
    max-height: none !important;
    height: auto !important;
}

/* Reglas en cm */
.cfp-ruler-top, .cfp-ruler-left {
    position: absolute; color: var(--cfp-secondary); font-size: 12px; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
}
.cfp-ruler-top { left: 40px; top: -22px; height: 18px; border-top: 2px solid var(--cfp-secondary); }
.cfp-ruler-top::before, .cfp-ruler-top::after {
    content: ''; position: absolute; top: -4px; width: 2px; height: 8px; background: var(--cfp-secondary);
}
.cfp-ruler-top::before { left: 0; } .cfp-ruler-top::after { right: 0; }
.cfp-ruler-left { left: 0; top: 0; width: 30px; writing-mode: vertical-rl; transform: rotate(180deg); border-right: 2px solid var(--cfp-secondary); }
.cfp-ruler-left::before, .cfp-ruler-left::after {
    content: ''; position: absolute; right: -4px; height: 2px; width: 8px; background: var(--cfp-secondary);
}
.cfp-ruler-left::before { top: 0; } .cfp-ruler-left::after { bottom: 0; }
.cfp-hint { margin-top: 14px; text-align: center; max-width: 240px; }

/* Controles */
.cfp-controls-col { display: flex; flex-direction: column; gap: 16px; }
.cfp-control { display: flex; flex-direction: column; gap: 6px; }
.cfp-control > label { font-size: 14px; font-weight: 600; display: flex; justify-content: space-between; }
.cfp-control output { color: var(--cfp-primary); font-weight: 700; }
.cfp-control input[type="range"] { width: 100%; accent-color: var(--cfp-primary); }
.cfp-zoom-row, .cfp-copies-row { display: flex; align-items: center; gap: 8px; }
.cfp-zoom-btn {
    width: 34px; height: 34px; border-radius: 8px; border: 2px solid var(--cfp-btn);
    background: var(--cfp-btn); color: var(--cfp-btn-text); font-size: 20px; cursor: pointer; line-height: 1; flex: none;
}
.cfp-zoom-btn:hover { opacity: .9; }
.cfp-copies-row input { width: 80px; text-align: center; padding: 8px; border: 1px solid #d1d5db; border-radius: 8px; font-size: 16px; }
/* Blindado contra temas (OceanWP fija height/line-height y corta el texto) */
.cfp-app .cfp-select {
    width: 100% !important;
    height: auto !important;
    min-height: 46px !important;
    margin: 0 !important;
    padding: 12px 38px 12px 14px !important;
    line-height: 1.4 !important;
    border: 1px solid #d1d5db !important;
    border-radius: 8px !important;
    font-size: 15px !important;
    color: var(--cfp-text) !important;
    background-color: #fff !important;
    box-sizing: border-box !important;
    -webkit-appearance: menulist !important;
    -moz-appearance: menulist !important;
    appearance: menulist !important;
    max-width: 100% !important;
}
.cfp-app input[type="number"],
.cfp-app input[type="text"] {
    box-sizing: border-box !important;
    height: auto !important;
    min-height: 40px !important;
    line-height: 1.3 !important;
    margin: 0 !important;
}
.cfp-bg-color-row { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 14px; }
.cfp-bg-color-row input[type="color"] { width: 40px; height: 30px; border: 1px solid #d1d5db; border-radius: 6px; padding: 0; cursor: pointer; }
.cfp-edge-row { margin-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.cfp-edge-row label { font-size: 14px; font-weight: 600; display: flex; justify-content: space-between; }
.cfp-edge-row output { color: var(--cfp-primary); font-weight: 700; }
.cfp-edge-row input[type="range"] { width: 100%; accent-color: var(--cfp-primary); }

/* Paso 4 finish */
.cfp-finish-grid { display: grid; grid-template-columns: auto 1fr; gap: 28px; align-items: start; }
.cfp-finish-preview img { max-width: 180px; max-height: 240px; border: 1px solid #e5e7eb; border-radius: 8px; box-shadow: 0 3px 10px rgba(0,0,0,.08); }
.cfp-finish-form { display: flex; flex-direction: column; gap: 18px; }
.cfp-cost-box { background: #f9fafb; border: 1px solid #e5e7eb; border-radius: 12px; padding: 14px 16px; }
.cfp-cost-line { display: flex; justify-content: space-between; padding: 4px 0; }
.cfp-cost-balance { border-top: 1px dashed #d1d5db; margin-top: 6px; padding-top: 10px; color: #6b7280; }

/* Paso 5 done */
.cfp-done-card { text-align: center; }
.cfp-done-icon { font-size: 56px; margin-bottom: 6px; }

/* Editor de recorte por zonas */
.cfp-mask-editor {
    position: fixed; inset: 0; z-index: 100000;
    background: rgba(17, 24, 39, .6);
    display: flex; align-items: center; justify-content: center; padding: 16px;
}
.cfp-mask-panel {
    background: #fff; border-radius: 16px; width: 100%; max-width: 620px;
    max-height: 95vh; overflow: auto; padding: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .35);
}
.cfp-mask-head h3 { margin: 0 0 4px; font-size: 18px; font-weight: 700; }
.cfp-mask-tools { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }
.cfp-tool {
    flex: 1 1 calc(50% - 8px); padding: 10px; border-radius: 10px; cursor: pointer;
    border: 2px solid #e5e7eb; background: #f9fafb; font-weight: 600; font-size: 14px;
}
.cfp-tool:hover { border-color: var(--cfp-primary); }
.cfp-tool.cfp-tool-active { border-color: var(--cfp-primary); background: rgba(37, 99, 235, .08); color: var(--cfp-primary); }
.cfp-mask-sliders { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.cfp-mask-slider { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; }
.cfp-mask-slider output { color: var(--cfp-primary); }
.cfp-mask-slider input[type="range"] { width: 100%; accent-color: var(--cfp-primary); }
.cfp-mask-zoom { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.cfp-mask-zoom-hint { margin: 0 0 0 4px; font-size: 12px; }
.cfp-mask-canvas-wrap {
    position: relative;
    display: flex; align-items: center; justify-content: center;
    background:
        linear-gradient(45deg, #e5e7eb 25%, transparent 25%, transparent 75%, #e5e7eb 75%) 0 0/20px 20px,
        linear-gradient(45deg, #e5e7eb 25%, #fff 25%, #fff 75%, #e5e7eb 75%) 10px 10px/20px 20px;
    background-color: #fff; border: 1px solid #e5e7eb; border-radius: 10px; padding: 6px; overflow: hidden;
}
#cfp-mask-canvas { max-width: 100%; touch-action: none; cursor: crosshair; display: block; }
.cfp-brush-cursor {
    position: absolute; border-radius: 50%; pointer-events: none;
    transform: translate(-50%, -50%);
    border: 2px solid var(--cfp-primary);
    box-shadow: 0 0 0 1px rgba(255, 255, 255, .9), inset 0 0 0 1px rgba(255, 255, 255, .9);
    background: rgba(37, 99, 235, .12);
}
.cfp-mask-bar { display: flex; gap: 8px; margin: 12px 0; }
.cfp-mask-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* Overlay */
.cfp-overlay {
    position: fixed; inset: 0; background: rgba(17, 24, 39, .55); z-index: 99999;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; color: #fff;
}
.cfp-spinner {
    width: 48px; height: 48px; border: 5px solid rgba(255,255,255,.3);
    border-top-color: #fff; border-radius: 50%; animation: cfp-spin 1s linear infinite;
}
@keyframes cfp-spin { to { transform: rotate(360deg); } }

@media (max-width: 640px) {
    .cfp-editor-grid, .cfp-finish-grid { grid-template-columns: 1fr; }
    .cfp-preview-col { margin-bottom: 8px; }
    .cfp-card { padding: 20px; }
}
