/* ============================================
   Custom Forms Modal – Client-facing
   ============================================ */

.cfm-modal {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 9999;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(2px);
    padding: 16px;
    align-items: center;
    justify-content: center;
}

.cfm-modal * { box-sizing: border-box; }
.cfm-modal.open { display: flex; }

.cfm-backdrop {
    position: absolute;
    inset: 0;
}

.cfm-content {
    position: relative;
    background: white;
    border-radius: 16px;
    width: 100%;
    max-width: 540px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    animation: cfmIn 0.2s ease;
    z-index: 1;
    box-shadow: 0 20px 60px rgba(0,0,0,0.15);
    overflow: hidden;
}

@keyframes cfmIn {
    from { opacity: 0; transform: scale(0.95) translateY(-10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.cfm-header {
    display: grid;
    grid-template-columns: 32px 1fr 32px;
    align-items: center;
    padding: 18px 20px;
    border-bottom: 1px solid #e5e7eb;
    gap: 8px;
}

.cfm-header h3 {
    font-size: 18px;
    font-weight: 700;
    color: #111827;
    margin: 0;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cfm-back {
    background: none;
    border: none;
    color: #6b7280;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: background 0.15s;
    width: 32px;
    height: 32px;
}

.cfm-back[style*="display: none"],
.cfm-back[style*="display:none"] {
    display: flex !important;
    visibility: hidden;
}

.cfm-back:hover { background: #f3f4f6; color: #111827; }

.cfm-close {
    background: none;
    border: none;
    color: #6b7280;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: background 0.15s;
    width: 32px;
    height: 32px;
}

.cfm-close:hover { background: #f3f4f6; color: #111827; }

/* Body */
.cfm-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

/* Form Picker */
.cfm-form-option {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 16px;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    cursor: pointer;
    text-align: left;
    transition: all 0.15s;
    margin-bottom: 10px;
    font-family: inherit;
}

.cfm-form-option:last-child { margin-bottom: 0; }

.cfm-form-option:hover {
    border-color: #0088CC;
    background: #f0f9ff;
    box-shadow: 0 2px 8px rgba(0,136,204,0.1);
}

.cfm-form-option-info { flex: 1; min-width: 0; }

.cfm-form-option-info h4 {
    font-size: 15px;
    font-weight: 600;
    color: #111827;
    margin: 0 0 2px;
}

.cfm-form-option-info p {
    font-size: 13px;
    color: #6b7280;
    margin: 0;
    line-height: 1.4;
}

.cfm-form-option svg {
    color: #9ca3af;
    flex-shrink: 0;
}

/* Form Fields */
.cfm-form-desc {
    font-size: 14px;
    color: #6b7280;
    margin: 0 0 20px;
    line-height: 1.5;
}

.cfm-form-group {
    margin-bottom: 16px;
}

.cfm-form-group:last-child { margin-bottom: 0; }

.cfm-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #374151;
    margin-bottom: 6px;
}

.cfm-help {
    font-size: 12px;
    color: #9ca3af;
    margin: -2px 0 8px;
}

.cfm-input, .cfm-textarea, .cfm-select {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid #cbd5e1;
    border-radius: 8px;
    font-size: 14px;
    color: #111827;
    background: #fff;
    font-family: inherit;
    transition: border-color 0.15s, box-shadow 0.15s;
    -webkit-appearance: none;
}

.cfm-input::placeholder,
.cfm-textarea::placeholder {
    color: #9ca3b8;
}

.cfm-input:focus, .cfm-textarea:focus, .cfm-select:focus {
    outline: none;
    border-color: #0088CC;
    box-shadow: 0 0 0 3px rgba(0,136,204,0.08);
}

.cfm-textarea {
    resize: vertical;
    min-height: 80px;
}

.cfm-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 10px center;
    background-repeat: no-repeat;
    background-size: 20px;
    padding-right: 36px;
}

.cfm-checkbox-group {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: #374151;
}

.cfm-checkbox {
    width: 18px;
    height: 18px;
    accent-color: #0088CC;
}

/* File Upload */
.cfm-file-upload { position: relative; }

.cfm-file-input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    overflow: hidden;
}

.cfm-file-label {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border: 1.5px dashed #cbd5e1;
    border-radius: 8px;
    cursor: pointer;
    color: #6b7280;
    font-size: 14px;
    transition: all 0.15s;
}

.cfm-file-label:hover {
    border-color: #0088CC;
    color: #0088CC;
    background: #f0f9ff;
}

.cfm-file-text { flex: 1; }

/* Errors */
.cfm-error {
    display: block;
    font-size: 12px;
    color: #ef4444;
    margin-top: 4px;
    min-height: 0;
    line-height: 1.4;
}

.cfm-error:empty {
    display: none;
}

/* Footer */
.cfm-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 16px 20px;
    border-top: 1px solid #e5e7eb;
}

.cfm-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: inherit;
}

.cfm-btn-primary {
    background: #0088CC;
    color: #fff;
}

.cfm-btn-primary:hover { background: #006699; }

.cfm-btn-primary:disabled {
    background: #a3d4ed;
    cursor: not-allowed;
}

.cfm-btn-secondary {
    background: #fff;
    color: #374151;
    border: 1.5px solid #cbd5e1;
}

.cfm-btn-secondary:hover {
    background: #f3f4f6;
    border-color: #94a3b8;
}

/* Success */
.cfm-success {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 24px;
    text-align: center;
}

.cfm-success svg {
    color: #22c55e;
    margin-bottom: 16px;
}

.cfm-success h3 {
    font-size: 20px;
    font-weight: 700;
    color: #111827;
    margin: 0 0 8px;
}

.cfm-success p {
    font-size: 14px;
    color: #6b7280;
    margin: 0;
    max-width: 320px;
    line-height: 1.5;
}

/* Spinner */
.cfm-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: cfmSpin 0.6s linear infinite;
}

@keyframes cfmSpin {
    to { transform: rotate(360deg); }
}

/* Responsive */
@media (max-width: 640px) {
    .cfm-content {
        max-width: 100%;
        max-height: 100vh;
        max-height: 100dvh;
        border-radius: 16px 16px 0 0;
        margin-top: auto;
    }

    .cfm-modal {
        padding: 0;
        align-items: flex-end;
    }
}
